diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt index 4309ecf2..ea901b4b 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt @@ -8,6 +8,8 @@ package com.stevesoltys.seedvault.settings import android.content.SharedPreferences import android.os.Bundle import android.view.View +import androidx.preference.ListPreference +import androidx.preference.Preference import androidx.preference.PreferenceCategory import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager @@ -16,6 +18,7 @@ import androidx.work.ExistingPeriodicWorkPolicy.UPDATE import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.permitDiskReads import com.stevesoltys.seedvault.plugins.StoragePluginManager +import com.stevesoltys.seedvault.settings.preference.M3ListPreference import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.sharedViewModel @@ -42,6 +45,21 @@ class SchedulingFragment : PreferenceFragmentCompat(), } } + override fun onDisplayPreferenceDialog(preference: Preference?) { + when (preference) { + is ListPreference -> { + val dialogFragment = M3ListPreference.newInstance(preference.getKey()) + dialogFragment.setTargetFragment(this, 0) + dialogFragment.show( + parentFragmentManager, + M3ListPreference.PREFERENCE_DIALOG_FRAGMENT_TAG + ) + } + + else -> super.onDisplayPreferenceDialog(preference) + } + } + override fun onStart() { super.onStart() diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/preference/M3ListPreference.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/preference/M3ListPreference.kt new file mode 100644 index 00000000..45e5cc9d --- /dev/null +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/preference/M3ListPreference.kt @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrightText: 2024 The Calyx Institute + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.stevesoltys.seedvault.settings.preference + +import android.app.Dialog +import android.os.Bundle +import androidx.preference.ListPreferenceDialogFragmentCompat +import com.google.android.material.dialog.MaterialAlertDialogBuilder + +class M3ListPreference : ListPreferenceDialogFragmentCompat() { + + companion object { + const val PREFERENCE_DIALOG_FRAGMENT_TAG = "androidx.preference.PreferenceFragment.DIALOG" + + fun newInstance(key: String?): M3ListPreference { + val fragment = M3ListPreference() + val bundle = Bundle(1) + bundle.putString(ARG_KEY, key) + fragment.arguments = bundle + return fragment + } + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val builder = MaterialAlertDialogBuilder(requireContext()) + .setTitle(preference.dialogTitle) + .setIcon(preference.dialogIcon) + .setPositiveButton(preference.positiveButtonText, this) + .setNegativeButton(preference.negativeButtonText, this) + + val contentView = onCreateDialogView(requireContext()) + if (contentView != null) { + onBindDialogView(contentView) + builder.setView(contentView) + } else { + builder.setMessage(preference.dialogMessage) + } + + onPrepareDialogBuilder(builder) + return builder.create() + } +}