Copy event logging settings

This commit is contained in:
ajp_anton
2026-07-23 09:56:29 +00:00
parent f698871e9a
commit 53cc4eb529
2 changed files with 27 additions and 1 deletions
@@ -9,6 +9,9 @@ import se.ajpanton.notificationlog.databinding.FragmentSettingsBinding
import se.ajpanton.notificationlog.settings.LogField
import se.ajpanton.notificationlog.settings.LogViewSettingsStore
import se.ajpanton.notificationlog.settings.TimestampZone
import se.ajpanton.notificationlog.settings.LoggingType
import se.ajpanton.notificationlog.settings.LoggingRuleStore
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class SettingsFragment : Fragment(R.layout.fragment_settings) {
private var binding: FragmentSettingsBinding? = null
@@ -42,6 +45,29 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
settings = settings.copy(timestampZone = TimestampZone.entries[position]); store.save(settings)
}
}
binding!!.copyEventSettings.setOnClickListener { chooseCopySource() }
}
override fun onDestroyView() { binding = null; super.onDestroyView() }
private fun chooseCopySource() {
val types = LoggingType.entries
MaterialAlertDialogBuilder(requireContext())
.setTitle("Copy settings from")
.setItems(types.map { it.label() }.toTypedArray()) { _, index -> chooseCopyTargets(types[index]) }
.show()
}
private fun chooseCopyTargets(source: LoggingType) {
val targets = LoggingType.entries.filterNot { it == source }
val checked = BooleanArray(targets.size)
MaterialAlertDialogBuilder(requireContext())
.setTitle("Copy ${source.label()} settings to")
.setMultiChoiceItems(targets.map { it.label() }.toTypedArray(), checked) { _, index, selected -> checked[index] = selected }
.setNegativeButton("Cancel", null)
.setPositiveButton("Copy") { _, _ ->
LoggingRuleStore(requireContext()).copy(source, targets.filterIndexed { index, _ -> checked[index] }.toSet())
}.show()
}
private fun LoggingType.label() = name.lowercase().replace('_', ' ').replaceFirstChar(Char::uppercase)
}