Port OneUI miscellaneous display settings
This commit is contained in:
@@ -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)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user