Compare commits

..

1 commit

View file

@ -34,7 +34,7 @@ open class SettingsFragment: PreferenceFragmentCompat() {
// Show / hide developer preference based on whether it is enabled
lifecycleScope.launch {
preferenceRepository.developerOptionsEnabledFlow
.onEach { developerPref.isVisible = it }
.onEach(developerPref::setVisible)
.collect()
}
@ -100,41 +100,30 @@ open class SettingsFragment: PreferenceFragmentCompat() {
@Suppress("UNUSED_PARAMETER")
private fun onAppVersionClicked(pref: Preference): Boolean {
if (developerPref.isVisible) return false
val now = System.currentTimeMillis()
if (now - lastClickTimestamp >= 1000) {
numClicks = 1
} else {
numClicks++
}
numClicks = if (now - lastClickTimestamp >= 1000) 1 else numClicks + 1
lastClickTimestamp = now
if (numClicks == 7) {
lifecycleScope.launch {
preferenceRepository.developerOptionsEnabledFlow.updatePreference(true)
preferenceRepository.developerOptionsEnabledFlow.updatePreference(numClicks >= 7)
}
val toastText = when {
numClicks == 7 -> getString(R.string.developer_options_enabled)
numClicks > 1 -> getString(R.string.developer_options_steps, 7 - numClicks)
else -> return true
}
lastToast?.cancel()
Toast.makeText(
requireContext(),
R.string.developer_options_enabled,
Toast.LENGTH_SHORT
).show()
}
} else if (numClicks > 1) {
lastToast?.cancel()
lastToast = Toast.makeText(
requireContext(),
getString(R.string.developer_options_steps, 7 - numClicks),
Toast.LENGTH_SHORT
)
lastToast = Toast.makeText(requireContext(), toastText, Toast.LENGTH_SHORT)
lastToast!!.show()
}
return true
}
protected fun CheckBoxPreference.bindBooleanFlow(flow: PreferenceFlowWrapper<Boolean>) {
lifecycleScope.launch {
flow.collect { isChecked = it }
flow.collect(::setChecked)
}
setOnPreferenceChangeListener { _, newValue ->