From 3289d62ca0769ff600ba5842437fd3e5bc3c39fb Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Mon, 31 Aug 2026 01:19:58 +0000 Subject: [PATCH] Consolidate notification utility settings --- .../DebugNotificationsFragment.kt | 82 ------------------ .../notificationsmaster/MainActivity.kt | 2 - .../MiscellaneousFragment.kt | 58 +++++++++++++ .../main/res/layout/fragment_cards_layout.xml | 2 +- .../layout/fragment_debug_notifications.xml | 79 ----------------- .../res/layout/fragment_miscellaneous.xml | 86 +++++++++++++++---- app/src/main/res/menu/drawer_menu.xml | 3 - app/src/main/res/values/strings.xml | 5 -- 8 files changed, 129 insertions(+), 188 deletions(-) delete mode 100644 app/src/main/java/se/ajpanton/notificationsmaster/DebugNotificationsFragment.kt delete mode 100644 app/src/main/res/layout/fragment_debug_notifications.xml diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/DebugNotificationsFragment.kt b/app/src/main/java/se/ajpanton/notificationsmaster/DebugNotificationsFragment.kt deleted file mode 100644 index 024837e..0000000 --- a/app/src/main/java/se/ajpanton/notificationsmaster/DebugNotificationsFragment.kt +++ /dev/null @@ -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 - } -} diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt index c5e974e..9ef0337 100644 --- a/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt +++ b/app/src/main/java/se/ajpanton/notificationsmaster/MainActivity.kt @@ -180,7 +180,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte page == Page.APPS -> AppsFragment() page == Page.NOTIFICATION_VISIBILITY -> NotificationVisibilityFragment() page == Page.CARDS_LAYOUT -> CardsLayoutFragment() - page == Page.DEBUG_NOTIFICATIONS -> DebugNotificationsFragment() page == Page.MISCELLANEOUS -> MiscellaneousFragment() page == Page.LOG_DISPLAY -> LogDisplayFragment() page == Page.FILTER_LOGGING -> FilterLoggingFragment() @@ -387,7 +386,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte APPS(R.id.nav_apps, R.string.page_apps), NOTIFICATION_VISIBILITY(R.id.nav_notification_visibility, R.string.page_notification_visibility), 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), LOG_DISPLAY(R.id.nav_log_display, R.string.page_log_display), FILTER_LOGGING(R.id.nav_filter_logging, R.string.page_filter_logging), diff --git a/app/src/main/java/se/ajpanton/notificationsmaster/MiscellaneousFragment.kt b/app/src/main/java/se/ajpanton/notificationsmaster/MiscellaneousFragment.kt index cb43b46..fa790ca 100644 --- a/app/src/main/java/se/ajpanton/notificationsmaster/MiscellaneousFragment.kt +++ b/app/src/main/java/se/ajpanton/notificationsmaster/MiscellaneousFragment.kt @@ -1,16 +1,35 @@ 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 com.google.android.material.switchmaterial.SwitchMaterial import se.ajpanton.notificationsmaster.databinding.FragmentMiscellaneousBinding +import se.ajpanton.notificationsmaster.debug.DebugNotifications 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 + 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?) { binding = FragmentMiscellaneousBinding.bind(view) @@ -26,11 +45,27 @@ class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) { bind(binding!!.showAodBatteryPercent, settings.showAodBatteryPercentWhenUnplugged) { current, 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() { super.onResume() activity?.title = getString(R.string.page_miscellaneous) + DebugNotifications.apply(requireContext()) + refreshDebugNotifications() } override fun onDestroyView() { @@ -48,4 +83,27 @@ class MiscellaneousFragment : Fragment(R.layout.fragment_miscellaneous) { 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 + } } diff --git a/app/src/main/res/layout/fragment_cards_layout.xml b/app/src/main/res/layout/fragment_cards_layout.xml index 9da2338..79fbe7d 100644 --- a/app/src/main/res/layout/fragment_cards_layout.xml +++ b/app/src/main/res/layout/fragment_cards_layout.xml @@ -12,7 +12,7 @@ - - - - - - - - - - - - -