Consolidate notification utility settings

This commit is contained in:
ajp_anton
2026-08-31 01:19:58 +00:00
parent dc11e605d1
commit 3289d62ca0
8 changed files with 129 additions and 188 deletions
@@ -1,82 +0,0 @@
package se.ajpanton.notificationsmaster
import android.Manifest
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import se.ajpanton.notificationsmaster.databinding.FragmentDebugNotificationsBinding
import se.ajpanton.notificationsmaster.debug.DebugNotifications
class DebugNotificationsFragment : Fragment(R.layout.fragment_debug_notifications) {
private var binding: FragmentDebugNotificationsBinding? = null
private var pendingCount: Int? = null
private var pendingCycle = false
private var updatingCycle = false
private val permissionRequest = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
val context = context ?: return@registerForActivityResult
if (granted) {
pendingCount?.let { DebugNotifications.setCount(context, it) }
if (pendingCycle) DebugNotifications.setCycling(context, true)
} else {
Toast.makeText(context, R.string.debug_notification_permission_required, Toast.LENGTH_SHORT).show()
}
pendingCount = null
pendingCycle = false
refresh()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = FragmentDebugNotificationsBinding.bind(view)
binding!!.debugMinus10.setOnClickListener { changeCount(-10) }
binding!!.debugMinus1.setOnClickListener { changeCount(-1) }
binding!!.debugPlus1.setOnClickListener { changeCount(1) }
binding!!.debugPlus10.setOnClickListener { changeCount(10) }
binding!!.debugReset.setOnClickListener { setCount(0) }
binding!!.debugCycle.setOnCheckedChangeListener { _, enabled ->
if (updatingCycle) return@setOnCheckedChangeListener
if (enabled && !DebugNotifications.hasPermission(requireContext())) {
pendingCycle = true
permissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS)
} else {
DebugNotifications.setCycling(requireContext(), enabled)
}
}
}
override fun onResume() {
super.onResume()
activity?.title = getString(R.string.page_debug_notifications)
DebugNotifications.apply(requireContext())
refresh()
}
override fun onDestroyView() {
binding = null
super.onDestroyView()
}
private fun changeCount(delta: Int) = setCount(DebugNotifications.count(requireContext()) + delta)
private fun setCount(count: Int) {
val desired = count.coerceIn(0, DebugNotifications.MAX_COUNT)
if (desired > 0 && !DebugNotifications.hasPermission(requireContext())) {
pendingCount = desired
permissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS)
return
}
DebugNotifications.setCount(requireContext(), desired)
refresh()
}
private fun refresh() {
val context = context ?: return
val count = DebugNotifications.count(context)
binding?.debugCount?.text = count.toString()
binding?.debugCycle?.isEnabled = count > 0
updatingCycle = true
binding?.debugCycle?.isChecked = DebugNotifications.isCycling(context)
updatingCycle = false
}
}
@@ -180,7 +180,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
page == Page.APPS -> AppsFragment() page == Page.APPS -> AppsFragment()
page == Page.NOTIFICATION_VISIBILITY -> NotificationVisibilityFragment() page == Page.NOTIFICATION_VISIBILITY -> NotificationVisibilityFragment()
page == Page.CARDS_LAYOUT -> CardsLayoutFragment() page == Page.CARDS_LAYOUT -> CardsLayoutFragment()
page == Page.DEBUG_NOTIFICATIONS -> DebugNotificationsFragment()
page == Page.MISCELLANEOUS -> MiscellaneousFragment() page == Page.MISCELLANEOUS -> MiscellaneousFragment()
page == Page.LOG_DISPLAY -> LogDisplayFragment() page == Page.LOG_DISPLAY -> LogDisplayFragment()
page == Page.FILTER_LOGGING -> FilterLoggingFragment() page == Page.FILTER_LOGGING -> FilterLoggingFragment()
@@ -387,7 +386,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
APPS(R.id.nav_apps, R.string.page_apps), APPS(R.id.nav_apps, R.string.page_apps),
NOTIFICATION_VISIBILITY(R.id.nav_notification_visibility, R.string.page_notification_visibility), NOTIFICATION_VISIBILITY(R.id.nav_notification_visibility, R.string.page_notification_visibility),
CARDS_LAYOUT(R.id.nav_cards_layout, R.string.page_cards_layout), CARDS_LAYOUT(R.id.nav_cards_layout, R.string.page_cards_layout),
DEBUG_NOTIFICATIONS(R.id.nav_debug_notifications, R.string.page_debug_notifications),
MISCELLANEOUS(R.id.nav_miscellaneous, R.string.page_miscellaneous), MISCELLANEOUS(R.id.nav_miscellaneous, R.string.page_miscellaneous),
LOG_DISPLAY(R.id.nav_log_display, R.string.page_log_display), LOG_DISPLAY(R.id.nav_log_display, R.string.page_log_display),
FILTER_LOGGING(R.id.nav_filter_logging, R.string.page_filter_logging), FILTER_LOGGING(R.id.nav_filter_logging, R.string.page_filter_logging),
@@ -1,16 +1,35 @@
package se.ajpanton.notificationsmaster package se.ajpanton.notificationsmaster
import android.Manifest
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.google.android.material.switchmaterial.SwitchMaterial import com.google.android.material.switchmaterial.SwitchMaterial
import se.ajpanton.notificationsmaster.databinding.FragmentMiscellaneousBinding import se.ajpanton.notificationsmaster.databinding.FragmentMiscellaneousBinding
import se.ajpanton.notificationsmaster.debug.DebugNotifications
import se.ajpanton.notificationsmaster.visibility.SystemUiMiscSettings import se.ajpanton.notificationsmaster.visibility.SystemUiMiscSettings
import se.ajpanton.notificationsmaster.visibility.VisibilityPolicyStore import se.ajpanton.notificationsmaster.visibility.VisibilityPolicyStore
class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) { class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) {
private var binding: FragmentMiscellaneousBinding? = null private var binding: FragmentMiscellaneousBinding? = null
private lateinit var store: VisibilityPolicyStore private lateinit var store: VisibilityPolicyStore
private var pendingCount: Int? = null
private var pendingCycle = false
private var updatingCycle = false
private val permissionRequest = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
val context = context ?: return@registerForActivityResult
if (granted) {
pendingCount?.let { DebugNotifications.setCount(context, it) }
if (pendingCycle) DebugNotifications.setCycling(context, true)
} else {
Toast.makeText(context, R.string.debug_notification_permission_required, Toast.LENGTH_SHORT).show()
}
pendingCount = null
pendingCycle = false
refreshDebugNotifications()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = FragmentMiscellaneousBinding.bind(view) binding = FragmentMiscellaneousBinding.bind(view)
@@ -26,11 +45,27 @@ class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) {
bind(binding!!.showAodBatteryPercent, settings.showAodBatteryPercentWhenUnplugged) { current, checked -> bind(binding!!.showAodBatteryPercent, settings.showAodBatteryPercentWhenUnplugged) { current, checked ->
current.copy(showAodBatteryPercentWhenUnplugged = checked) current.copy(showAodBatteryPercentWhenUnplugged = checked)
} }
binding!!.debugMinus10.setOnClickListener { changeDebugCount(-10) }
binding!!.debugMinus1.setOnClickListener { changeDebugCount(-1) }
binding!!.debugPlus1.setOnClickListener { changeDebugCount(1) }
binding!!.debugPlus10.setOnClickListener { changeDebugCount(10) }
binding!!.debugReset.setOnClickListener { setDebugCount(0) }
binding!!.debugCycle.setOnCheckedChangeListener { _, enabled ->
if (updatingCycle) return@setOnCheckedChangeListener
if (enabled && !DebugNotifications.hasPermission(requireContext())) {
pendingCycle = true
permissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS)
} else {
DebugNotifications.setCycling(requireContext(), enabled)
}
}
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
activity?.title = getString(R.string.page_miscellaneous) activity?.title = getString(R.string.page_miscellaneous)
DebugNotifications.apply(requireContext())
refreshDebugNotifications()
} }
override fun onDestroyView() { override fun onDestroyView() {
@@ -48,4 +83,27 @@ class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) {
store.update { policy -> policy.copy(systemUiMisc = update(policy.systemUiMisc, checked)) } store.update { policy -> policy.copy(systemUiMisc = update(policy.systemUiMisc, checked)) }
} }
} }
private fun changeDebugCount(delta: Int) = setDebugCount(DebugNotifications.count(requireContext()) + delta)
private fun setDebugCount(count: Int) {
val desired = count.coerceIn(0, DebugNotifications.MAX_COUNT)
if (desired > 0 && !DebugNotifications.hasPermission(requireContext())) {
pendingCount = desired
permissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS)
return
}
DebugNotifications.setCount(requireContext(), desired)
refreshDebugNotifications()
}
private fun refreshDebugNotifications() {
val context = context ?: return
val count = DebugNotifications.count(context)
binding?.debugCount?.text = count.toString()
binding?.debugCycle?.isEnabled = count > 0
updatingCycle = true
binding?.debugCycle?.isChecked = DebugNotifications.isCycling(context)
updatingCycle = false
}
} }
@@ -12,7 +12,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="These settings apply only to OneUI Cards mode. Icons mode remains rendered by Android or StatusBarTweak." android:text="These settings apply only to OneUI Cards mode. Icons mode remains rendered by Android."
android:textAppearance="?attr/textAppearanceBody2" /> android:textAppearance="?attr/textAppearanceBody2" />
<TextView <TextView
@@ -1,79 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/page_padding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/debug_notifications_description"
android:textSize="14sp" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/debug_cycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/debug_cycle_notifications" />
<TextView
android:id="@+id/debug_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="0"
android:textSize="32sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<Button
android:id="@+id/debug_minus_10"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="-10" />
<Button
android:id="@+id/debug_minus_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="-1" />
<Button
android:id="@+id/debug_plus_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="+1" />
<Button
android:id="@+id/debug_plus_10"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="+10" />
</LinearLayout>
<Button
android:id="@+id/debug_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/debug_reset_notifications" />
</LinearLayout>
</ScrollView>
@@ -15,13 +15,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/keep_aod_visible_during_calls" /> android:text="@string/keep_aod_visible_during_calls" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/keep_aod_visible_during_calls_hint"
android:textAppearance="?attr/textAppearanceBody2" />
<com.google.android.material.switchmaterial.SwitchMaterial <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/show_lockscreen_battery_percent" android:id="@+id/show_lockscreen_battery_percent"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -29,13 +22,6 @@
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:text="@string/show_lockscreen_battery_percent" /> android:text="@string/show_lockscreen_battery_percent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/show_lockscreen_battery_percent_hint"
android:textAppearance="?attr/textAppearanceBody2" />
<com.google.android.material.switchmaterial.SwitchMaterial <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/show_aod_battery_percent" android:id="@+id/show_aod_battery_percent"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -43,11 +29,79 @@
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:text="@string/show_aod_battery_percent" /> android:text="@string/show_aod_battery_percent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:text="Debug icons"
android:textAppearance="?attr/textAppearanceHeadline6" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:text="@string/show_aod_battery_percent_hint" android:text="@string/debug_notifications_description"
android:textAppearance="?attr/textAppearanceBody2" /> android:textSize="14sp" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/debug_cycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/debug_cycle_notifications" />
<TextView
android:id="@+id/debug_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="0"
android:textSize="32sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<Button
android:id="@+id/debug_minus_10"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="-10" />
<Button
android:id="@+id/debug_minus_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="-1" />
<Button
android:id="@+id/debug_plus_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="+1" />
<Button
android:id="@+id/debug_plus_10"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="0dp"
android:text="+10" />
</LinearLayout>
<Button
android:id="@+id/debug_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/debug_reset_notifications" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
-3
View File
@@ -26,9 +26,6 @@
<item <item
android:id="@+id/nav_cards_layout" android:id="@+id/nav_cards_layout"
android:title="@string/navigation_indented_cards_layout" /> android:title="@string/navigation_indented_cards_layout" />
<item
android:id="@+id/nav_debug_notifications"
android:title="@string/navigation_indented_debug_notifications" />
<item <item
android:id="@+id/nav_miscellaneous" android:id="@+id/nav_miscellaneous"
android:title="@string/navigation_indented_miscellaneous" /> android:title="@string/navigation_indented_miscellaneous" />
-5
View File
@@ -18,7 +18,6 @@
<string name="page_rules">Rules</string> <string name="page_rules">Rules</string>
<string name="page_apps">Apps</string> <string name="page_apps">Apps</string>
<string name="page_notification_visibility">Notifications</string> <string name="page_notification_visibility">Notifications</string>
<string name="page_debug_notifications">Debug icons</string>
<string name="page_cards_layout">Cards layout</string> <string name="page_cards_layout">Cards layout</string>
<string name="page_miscellaneous">Miscellaneous</string> <string name="page_miscellaneous">Miscellaneous</string>
<string name="page_filter_apps">Filter apps</string> <string name="page_filter_apps">Filter apps</string>
@@ -29,14 +28,10 @@
<string name="navigation_indented_rules">&#160;&#160;&#160;&#160;Rules</string> <string name="navigation_indented_rules">&#160;&#160;&#160;&#160;Rules</string>
<string name="navigation_indented_apps">&#160;&#160;&#160;&#160;Apps</string> <string name="navigation_indented_apps">&#160;&#160;&#160;&#160;Apps</string>
<string name="navigation_indented_cards_layout">&#160;&#160;&#160;&#160;Cards layout</string> <string name="navigation_indented_cards_layout">&#160;&#160;&#160;&#160;Cards layout</string>
<string name="navigation_indented_debug_notifications">&#160;&#160;&#160;&#160;Debug icons</string>
<string name="navigation_indented_miscellaneous">&#160;&#160;&#160;&#160;Miscellaneous</string> <string name="navigation_indented_miscellaneous">&#160;&#160;&#160;&#160;Miscellaneous</string>
<string name="navigation_indented_filter_logging">&#160;&#160;&#160;&#160;Filter logging</string> <string name="navigation_indented_filter_logging">&#160;&#160;&#160;&#160;Filter logging</string>
<string name="navigation_indented_filter_apps">&#160;&#160;&#160;&#160;Filter apps</string> <string name="navigation_indented_filter_apps">&#160;&#160;&#160;&#160;Filter apps</string>
<string name="keep_aod_visible_during_calls">Keep AOD visible during calls</string> <string name="keep_aod_visible_during_calls">Keep AOD visible during calls</string>
<string name="keep_aod_visible_during_calls_hint">Prevents OneUI from hiding the always-on display while a call is active.</string>
<string name="show_lockscreen_battery_percent">Show battery % on lockscreen when unplugged</string> <string name="show_lockscreen_battery_percent">Show battery % on lockscreen when unplugged</string>
<string name="show_lockscreen_battery_percent_hint">Shows the battery percentage even when the phone is not charging.</string>
<string name="show_aod_battery_percent">Show battery % on AOD when unplugged</string> <string name="show_aod_battery_percent">Show battery % on AOD when unplugged</string>
<string name="show_aod_battery_percent_hint">Shows the battery percentage in the bottom AOD area even when the phone is not charging.</string>
</resources> </resources>