Skip to content

Commit

Permalink
Merge pull request #69 from arpitmx/Mohit
Browse files Browse the repository at this point in the history
Mohit
  • Loading branch information
arpitmx authored Jan 17, 2024
2 parents be9fb87 + 2fdce02 commit fa52210
Show file tree
Hide file tree
Showing 21 changed files with 526 additions and 53 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 37 additions & 4 deletions app/src/main/java/com/ncs/o2/UI/Auth/AuthScreenActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ class AuthScreenActivity @Inject constructor() : AppCompatActivity(),NetworkChan
private val networkChangeReceiver = NetworkChangeReceiver(this,this)
@Inject
lateinit var utils : GlobalUtils.EasyElements

private val intentFilter by lazy{
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
}
@Issue("Fragment duplicate on configuration change, implement that.")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, intentFilter)
registerReceiver(true)

if (PrefManager.getAppMode()==Endpoints.OFFLINE_MODE){
utils.singleBtnDialog("No network","As network is not available and your were not logged in, you can't proceed further","EXIT") {
finish()
Expand Down Expand Up @@ -108,7 +110,21 @@ class AuthScreenActivity @Inject constructor() : AppCompatActivity(),NetworkChan
}
}
}
private var receiverRegistered = false

fun registerReceiver(flag : Boolean){
if (flag){
if (!receiverRegistered) {
registerReceiver(networkChangeReceiver,intentFilter)
receiverRegistered = true
}
}else{
if (receiverRegistered){
unregisterReceiver(networkChangeReceiver)
receiverRegistered = false
}
}
}
private fun setUpViews() {

}
Expand All @@ -118,11 +134,28 @@ class AuthScreenActivity @Inject constructor() : AppCompatActivity(),NetworkChan
registerReceiver(networkChangeReceiver, intentFilter)
}

override fun onStart() {
super.onStart()
registerReceiver(true)
}

override fun onStop() {
super.onStop()
registerReceiver(false)
}

override fun onPause() {
super.onPause()
unregisterReceiver(networkChangeReceiver)
registerReceiver(false)

}

override fun onDestroy() {
super.onDestroy()
registerReceiver(false)
}


override fun onOnlineModePositiveSelected() {
PrefManager.setAppMode(Endpoints.ONLINE_MODE)
utils.restartApp()
Expand Down
42 changes: 37 additions & 5 deletions app/src/main/java/com/ncs/o2/UI/CreateTask/ChecklistActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ class ChecklistActivity : AppCompatActivity(),CheckListBottomSheet.checkListItem
@Inject
lateinit var utils : GlobalUtils.EasyElements
private val networkChangeReceiver = NetworkChangeReceiver(this,this)

private val intentFilter by lazy{
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, intentFilter)
registerReceiver(true)


listener = ListenerHolder.checkListListener!!
val dataList = intent.getSerializableExtra("checkListArray") as ArrayList<CheckList>?
Expand Down Expand Up @@ -101,7 +103,21 @@ class ChecklistActivity : AppCompatActivity(),CheckListBottomSheet.checkListItem
finish()
}
}

private var receiverRegistered = false

fun registerReceiver(flag : Boolean){
if (flag){
if (!receiverRegistered) {
registerReceiver(networkChangeReceiver,intentFilter)
receiverRegistered = true
}
}else{
if (receiverRegistered){
unregisterReceiver(networkChangeReceiver)
receiverRegistered = false
}
}
}
private fun setCheckListRecyclerView(list: MutableList<CheckList>) {

checkListAdapter = CheckListAdapter(list = list,markwon= markwon,this,true)
Expand Down Expand Up @@ -188,9 +204,25 @@ class ChecklistActivity : AppCompatActivity(),CheckListBottomSheet.checkListItem
override fun onCheckBoxClick(id: String, isChecked: Boolean, position: Int) {

}
override fun onStart() {
super.onStart()
registerReceiver(true)
}

override fun onStop() {
super.onStop()
registerReceiver(false)
}

override fun onPause() {
super.onPause()
unregisterReceiver(networkChangeReceiver)
registerReceiver(false)

}

override fun onDestroy() {
super.onDestroy()
registerReceiver(false)
}

override fun onOnlineModePositiveSelected() {
Expand Down
56 changes: 47 additions & 9 deletions app/src/main/java/com/ncs/o2/UI/CreateTask/CreateTaskActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ class CreateTaskActivity : AppCompatActivity(), ContributorAdapter.OnProfileClic
private val networkChangeReceiver = NetworkChangeReceiver(this,this)



private val intentFilter by lazy{
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
}
// private val viewmodel: CreateTaskViewModel by viewModels()

private val easyElements: GlobalUtils.EasyElements by lazy {
Expand Down Expand Up @@ -336,8 +338,8 @@ class CreateTaskActivity : AppCompatActivity(), ContributorAdapter.OnProfileClic
setContentView(binding.root)
draft=PrefManager.getDraftTask()!!
Log.d("draftissue",draft.toString())
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, intentFilter)
registerReceiver(true)

if (PrefManager.getcurrentUserdetails().ROLE>=3){
manageViewsforModerators()
setDefaultViewsforModerators()
Expand Down Expand Up @@ -1671,10 +1673,7 @@ class CreateTaskActivity : AppCompatActivity(), ContributorAdapter.OnProfileClic
))
}
}
override fun onPause() {
super.onPause()
unregisterReceiver(networkChangeReceiver)
}


override fun onOnlineModePositiveSelected() {
PrefManager.setAppMode(Endpoints.ONLINE_MODE)
Expand All @@ -1686,12 +1685,51 @@ class CreateTaskActivity : AppCompatActivity(), ContributorAdapter.OnProfileClic
PrefManager.setAppMode(Endpoints.OFFLINE_MODE)
}


override fun onOfflineModeNegativeSelected() {
networkChangeReceiver.retryNetworkCheck()
}
private var receiverRegistered = false

fun registerReceiver(flag : Boolean){
if (flag){
if (!receiverRegistered) {
registerReceiver(networkChangeReceiver,intentFilter)
receiverRegistered = true
}
}else{
if (receiverRegistered){
unregisterReceiver(networkChangeReceiver)
receiverRegistered = false
}
}
}
override fun onStart() {
super.onStart()
registerReceiver(true)
}

override fun onStop() {
super.onStop()
registerReceiver(false)
}

override fun onPause() {
super.onPause()
registerReceiver(false)

}

override fun onDestroy() {
super.onDestroy()
registerReceiver(false)
}

override fun onResume() {
super.onResume()
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, intentFilter)
registerReceiver(true)

}


}
41 changes: 37 additions & 4 deletions app/src/main/java/com/ncs/o2/UI/EditProfile/EditProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ class EditProfileActivity : AppCompatActivity() , NetworkChangeReceiver.NetworkC
private var newBio: String?= null
var newUsername: String?= null
private val networkChangeReceiver = NetworkChangeReceiver(this,this)

private val intentFilter by lazy{
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding= ActivityEditProfileBinding.inflate(layoutInflater)
setContentView(binding.root)
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, intentFilter)
registerReceiver(true)

setUpView()

viewModel.getUserDetails()
Expand Down Expand Up @@ -449,10 +451,41 @@ class EditProfileActivity : AppCompatActivity() , NetworkChangeReceiver.NetworkC
}
return bitmap
}
private var receiverRegistered = false

fun registerReceiver(flag : Boolean){
if (flag){
if (!receiverRegistered) {
registerReceiver(networkChangeReceiver,intentFilter)
receiverRegistered = true
}
}else{
if (receiverRegistered){
unregisterReceiver(networkChangeReceiver)
receiverRegistered = false
}
}
}

override fun onStart() {
super.onStart()
registerReceiver(true)
}

override fun onStop() {
super.onStop()
registerReceiver(false)
}

override fun onPause() {
super.onPause()
unregisterReceiver(networkChangeReceiver)
registerReceiver(false)

}

override fun onDestroy() {
super.onDestroy()
registerReceiver(false)
}

override fun onOnlineModePositiveSelected() {
Expand Down
40 changes: 37 additions & 3 deletions app/src/main/java/com/ncs/o2/UI/Logs/LogsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ class LogsActivity : AppCompatActivity() ,NetworkChangeReceiver.NetworkChangeCal
private val networkChangeReceiver = NetworkChangeReceiver(this,this)
@Inject
lateinit var utils : GlobalUtils.EasyElements
private val intentFilter by lazy{
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLogsBinding.inflate(layoutInflater)
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, intentFilter)
registerReceiver(true)


setContentView(binding.root)
setUpViews()
Expand All @@ -52,6 +55,21 @@ class LogsActivity : AppCompatActivity() ,NetworkChangeReceiver.NetworkChangeCal

setRecyclerView(list)
}
private var receiverRegistered = false

fun registerReceiver(flag : Boolean){
if (flag){
if (!receiverRegistered) {
registerReceiver(networkChangeReceiver,intentFilter)
receiverRegistered = true
}
}else{
if (receiverRegistered){
unregisterReceiver(networkChangeReceiver)
receiverRegistered = false
}
}
}
fun setRecyclerView(dataList: List<LogsItem>){
val recyclerView=binding.rvLogs
val adapter = LogsAdapter(dataList.toMutableList())
Expand All @@ -69,9 +87,25 @@ class LogsActivity : AppCompatActivity() ,NetworkChangeReceiver.NetworkChangeCal
val title:String,
val count:String,
)
override fun onStart() {
super.onStart()
registerReceiver(true)
}

override fun onStop() {
super.onStop()
registerReceiver(false)
}

override fun onPause() {
super.onPause()
unregisterReceiver(networkChangeReceiver)
registerReceiver(false)

}

override fun onDestroy() {
super.onDestroy()
registerReceiver(false)
}


Expand Down
Loading

0 comments on commit fa52210

Please sign in to comment.