Skip to content

Commit 080e7e7

Browse files
claudeCTLalit
authored andcommitted
fix: Encapsulate showCustomEventDialog as immutable LiveData
Make showCustomEventDialog a private MutableLiveData with a public LiveData getter, following standard MVVM encapsulation. Add resetShowCustomEventDialog() method so the fragment no longer writes directly to the MutableLiveData. https://claude.ai/code/session_01C7qvo8dKQfZ8tkbnWdyKFW
1 parent 6cb0f07 commit 080e7e7

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class HomeScreenFragment : Fragment() {
115115
viewModel.showCustomEventDialog.observe(viewLifecycleOwner) { show ->
116116
if (show == true) {
117117
showCustomEventDialog()
118-
viewModel.showCustomEventDialog.value = false
118+
viewModel.resetShowCustomEventDialog()
119119
}
120120
}
121121
}

sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenViewModel.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.clevertap.demo.ui.main
22

33
import android.os.Looper
44
import android.util.Log
5+
import androidx.lifecycle.LiveData
56
import androidx.lifecycle.MutableLiveData
67
import androidx.lifecycle.ViewModel
78
import com.clevertap.android.sdk.CTInboxStyleConfig
@@ -26,10 +27,16 @@ class HomeScreenViewModel(
2627
) : ViewModel() {
2728

2829
val clickCommand: MutableLiveData<String> by lazy { MutableLiveData<String>() }
29-
val showCustomEventDialog: MutableLiveData<Boolean> by lazy { MutableLiveData<Boolean>() }
30+
31+
private val _showCustomEventDialog: MutableLiveData<Boolean> by lazy { MutableLiveData<Boolean>() }
32+
val showCustomEventDialog: LiveData<Boolean> get() = _showCustomEventDialog
3033

3134
private val exampleVariables by lazy { ExampleVariables() }
3235

36+
fun resetShowCustomEventDialog() {
37+
_showCustomEventDialog.value = false
38+
}
39+
3340
/**
3441
* Handles child item clicks from the expandable list
3542
* @param groupPosition Section index from HomeScreenModel
@@ -78,7 +85,7 @@ class HomeScreenViewModel(
7885
6 -> recordScreenEvent()
7986
7 -> recordAppRatingEvent()
8087
8 -> recordShareEvent()
81-
9 -> showCustomEventDialog.value = true
88+
9 -> _showCustomEventDialog.value = true
8289
}
8390
}
8491

0 commit comments

Comments
 (0)