Port OneUI miscellaneous display settings

This commit is contained in:
ajp_anton
2026-08-30 12:40:31 +00:00
parent 192bdb5381
commit 4ff37e6699
12 changed files with 568 additions and 0 deletions
@@ -0,0 +1,51 @@
package se.ajpanton.notificationsmaster
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.google.android.material.switchmaterial.SwitchMaterial
import se.ajpanton.notificationsmaster.databinding.FragmentMiscellaneousBinding
import se.ajpanton.notificationsmaster.visibility.SystemUiMiscSettings
import se.ajpanton.notificationsmaster.visibility.VisibilityPolicyStore
class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) {
private var binding: FragmentMiscellaneousBinding? = null
private lateinit var store: VisibilityPolicyStore
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = FragmentMiscellaneousBinding.bind(view)
store = VisibilityPolicyStore(requireContext())
val settings = store.load().systemUiMisc
bind(binding!!.keepAodVisibleDuringCalls, settings.keepAodVisibleDuringCalls) { current, checked ->
current.copy(keepAodVisibleDuringCalls = checked)
}
bind(binding!!.showLockscreenBatteryPercent, settings.showLockscreenBatteryPercentWhenUnplugged) {
current, checked ->
current.copy(showLockscreenBatteryPercentWhenUnplugged = checked)
}
bind(binding!!.showAodBatteryPercent, settings.showAodBatteryPercentWhenUnplugged) { current, checked ->
current.copy(showAodBatteryPercentWhenUnplugged = checked)
}
}
override fun onResume() {
super.onResume()
activity?.title = getString(R.string.page_miscellaneous)
}
override fun onDestroyView() {
binding = null
super.onDestroyView()
}
private fun bind(
toggle: SwitchMaterial,
initial: Boolean,
update: (SystemUiMiscSettings, Boolean) -> SystemUiMiscSettings,
) {
toggle.isChecked = initial
toggle.setOnCheckedChangeListener { _, checked ->
store.update { policy -> policy.copy(systemUiMisc = update(policy.systemUiMisc, checked)) }
}
}
}