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.LogField
import se.ajpanton.notificationlog.settings.LogViewSettingsStore import se.ajpanton.notificationlog.settings.LogViewSettingsStore
import se.ajpanton.notificationlog.settings.TimestampZone 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) { class SettingsFragment : Fragment(R.layout.fragment_settings) {
private var binding: FragmentSettingsBinding? = null 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) settings = settings.copy(timestampZone = TimestampZone.entries[position]); store.save(settings)
} }
} }
binding!!.copyEventSettings.setOnClickListener { chooseCopySource() }
} }
override fun onDestroyView() { binding = null; super.onDestroyView() } 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)
} }
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?> <?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="Settings" android:textAppearance="?attr/textAppearanceHeadline5"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Show on each log line"/><LinearLayout android:id="@+id/field_toggles" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Timestamp timezone"/><Spinner android:id="@+id/timezone" android:layout_width="match_parent" android:layout_height="wrap_content"/></LinearLayout></ScrollView> <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="Settings" android:textAppearance="?attr/textAppearanceHeadline5"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Show on each log line"/><LinearLayout android:id="@+id/field_toggles" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Timestamp timezone"/><Spinner android:id="@+id/timezone" android:layout_width="match_parent" android:layout_height="wrap_content"/><Button android:id="@+id/copy_event_settings" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Copy settings"/></LinearLayout></ScrollView>