diff --git a/app/src/main/java/se/ajpanton/notificationlog/SettingsFragment.kt b/app/src/main/java/se/ajpanton/notificationlog/SettingsFragment.kt
index 7bf2ff3..ef6d7ef 100644
--- a/app/src/main/java/se/ajpanton/notificationlog/SettingsFragment.kt
+++ b/app/src/main/java/se/ajpanton/notificationlog/SettingsFragment.kt
@@ -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)
}
diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml
index 63f6642..da09ba8 100644
--- a/app/src/main/res/layout/fragment_settings.xml
+++ b/app/src/main/res/layout/fragment_settings.xml
@@ -1,2 +1,2 @@
-
+