Jesse Hill
03/31/2021, 12:37 PMmutableStateOf
when the activity hit onPause
but then in the app switcher it still showed the old UI. I also was trying to use the Lifecycle architecture component to update the state but that didn’t work either. Is this something that can be achieved with Compose? The current code is in the thread.Jesse Hill
03/31/2021, 12:38 PM@AndroidEntryPoint
class MainActivity : AppCompatActivity(), LifecycleObserver {
private val termsViewModel by viewModels<TermsOfUseViewModel>()
private val privacyViewModel by viewModels<PrivacyViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
setContent {
when {
privacyViewModel.showPrivacyScreen -> {
PrivacyScreen()
}
!termsViewModel.hasAcceptedTermsOfUse -> {
TermsOfUseScreen(acceptTermsOfUse = { termsViewModel.acceptTermsOfUse() })
}
else -> {
ComposeApp(applicationContext)
}
}
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onAppForegrounded() {
privacyViewModel.updateShowPrivacyScreen(false)
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onAppBackgrounded() {
privacyViewModel.updateShowPrivacyScreen(true)
}
}
@HiltViewModel
class PrivacyViewModel
@Inject
constructor(
val appContext: BaseApplication,
private val sharedPreferences: SharedPreferences
) : ViewModel() {
private val _showPrivacyScreen: Boolean
get() {
val shouldShowPrivacyScreen = sharedPreferences.getBoolean(
appContext.getString(R.string.should_show_privacy_screen),
false
)
return shouldShowPrivacyScreen
}
var showPrivacyScreen by mutableStateOf(_showPrivacyScreen)
fun updateShowPrivacyScreen(value: Boolean) {
showPrivacyScreen = value
with(sharedPreferences.edit()) {
putBoolean(
appContext.getString(R.string.should_show_privacy_screen),
value
)
apply()
}
}
}
Jesse Hill
03/31/2021, 1:46 PMwindow.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
which at least gives the security measure needed but it doesn’t look nice. I would really like to be able to show a custom UI that can hide the sensitive content.Albert Chang
03/31/2021, 1:57 PMZach Klippenstein (he/him) [MOD]
03/31/2021, 3:04 PMJesse Hill
03/31/2021, 3:05 PM