diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 95066ffa8..a4515e054 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -162,11 +162,16 @@ class MainActivity : BaseActivity() { * Show a break reminder when watched too long */ private fun setupBreakReminder() { + if (!PreferenceHelper.getBoolean( + PreferenceKeys.BREAK_REMINDER_TOGGLE, + false + ) + ) return val breakReminderPref = PreferenceHelper.getString( PreferenceKeys.BREAK_REMINDER, - "disabled" + "0" ) - if (breakReminderPref == "disabled") return + if (!breakReminderPref.all { Character.isDigit(it) }) return Handler(Looper.getMainLooper()).postDelayed( { try { diff --git a/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt b/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt index 3e8fba413..5287ef3b8 100644 --- a/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt @@ -1,6 +1,7 @@ package com.github.libretube.preferences import android.os.Bundle +import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.SwitchPreferenceCompat import com.github.libretube.R @@ -37,10 +38,15 @@ class GeneralSettings : MaterialPreferenceFragment() { true } - val breakReminder = findPreference(PreferenceKeys.BREAK_REMINDER) - breakReminder?.setOnPreferenceChangeListener { _, _ -> - val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) + val breakReminder = findPreference(PreferenceKeys.BREAK_REMINDER_TOGGLE) + val breakReminderTime = findPreference(PreferenceKeys.BREAK_REMINDER) + breakReminderTime?.isEnabled = PreferenceHelper.getBoolean( + PreferenceKeys.BREAK_REMINDER_TOGGLE, + false + ) + + breakReminder?.setOnPreferenceChangeListener { _, newValue -> + breakReminderTime?.isEnabled = newValue as Boolean true } } diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt index 80e5decb4..63ca4b25f 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt @@ -31,6 +31,10 @@ object PreferenceHelper { authEditor = authSettings.edit() } + fun putString(key: String?, value: String) { + editor.putString(key, value) + } + fun getString(key: String?, defValue: String?): String { return settings.getString(key, defValue)!! } diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index dbe69a7f1..4ff0e6b23 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -17,6 +17,7 @@ object PreferenceKeys { const val LANGUAGE = "language" const val REGION = "region" const val AUTO_ROTATION = "auto_rotation" + const val BREAK_REMINDER_TOGGLE = "break_reminder_toggle" const val BREAK_REMINDER = "break_reminder" /** @@ -92,7 +93,7 @@ object PreferenceKeys { * Advanced */ const val DATA_SAVER_MODE = "data_saver_mode" - const val MAX_IMAGE_CACHE = "" + const val MAX_IMAGE_CACHE = "image_cache_size" const val RESET_SETTINGS = "reset_settings" const val CLEAR_SEARCH_HISTORY = "clear_search_history" const val CLEAR_WATCH_HISTORY = "clear_watch_history" diff --git a/app/src/main/java/com/github/libretube/views/MaterialPreferenceFragment.kt b/app/src/main/java/com/github/libretube/views/MaterialPreferenceFragment.kt index 1bce4578a..3f420dd38 100644 --- a/app/src/main/java/com/github/libretube/views/MaterialPreferenceFragment.kt +++ b/app/src/main/java/com/github/libretube/views/MaterialPreferenceFragment.kt @@ -1,10 +1,15 @@ package com.github.libretube.views import android.os.Bundle +import android.util.Log +import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import com.github.libretube.R +import com.github.libretube.databinding.DialogTextPreferenceBinding +import com.github.libretube.extensions.TAG +import com.github.libretube.preferences.PreferenceHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder /** @@ -38,6 +43,24 @@ open class MaterialPreferenceFragment : PreferenceFragmentCompat() { .setNegativeButton(R.string.cancel, null) .show() } + is EditTextPreference -> { + val binding = DialogTextPreferenceBinding.inflate(layoutInflater) + binding.input.setText( + PreferenceHelper.getString( + preference.key, + "" + ) + ) + MaterialAlertDialogBuilder(requireContext()) + .setTitle(preference.title) + .setView(binding.root) + .setPositiveButton(R.string.okay) { _, _ -> + // save the new value + preference.text = binding.input.text.toString() + } + .setNegativeButton(R.string.cancel, null) + .show() + } /** * Otherwise show the normal dialog, dialogs for other preference types are not supported yet */ diff --git a/app/src/main/res/layout/dialog_text_preference.xml b/app/src/main/res/layout/dialog_text_preference.xml new file mode 100644 index 000000000..3b52fab01 --- /dev/null +++ b/app/src/main/res/layout/dialog_text_preference.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index e4d0eff1c..9efa17ea4 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -828,24 +828,6 @@ unlimited - - @string/disabled - 15 min - 30 min - 60 min - 90 min - 120 min - - - - disabled - 15 - 30 - 60 - 90 - 120 - - @string/resize_mode_fit @string/resize_mode_zoom diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4a3421c9a..c2dd962d8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -310,4 +310,5 @@ Max image cache size Copied to clipboard Open + Minutes before being reminded diff --git a/app/src/main/res/xml/general_settings.xml b/app/src/main/res/xml/general_settings.xml index e97a86801..67649f076 100644 --- a/app/src/main/res/xml/general_settings.xml +++ b/app/src/main/res/xml/general_settings.xml @@ -63,13 +63,18 @@ - + +