Copy event logging settings
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user