mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
commit
539bacd941
@ -162,11 +162,18 @@ class MainActivity : BaseActivity() {
|
|||||||
* Show a break reminder when watched too long
|
* Show a break reminder when watched too long
|
||||||
*/
|
*/
|
||||||
private fun setupBreakReminder() {
|
private fun setupBreakReminder() {
|
||||||
|
if (!PreferenceHelper.getBoolean(
|
||||||
|
PreferenceKeys.BREAK_REMINDER_TOGGLE,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
) return
|
||||||
val breakReminderPref = PreferenceHelper.getString(
|
val breakReminderPref = PreferenceHelper.getString(
|
||||||
PreferenceKeys.BREAK_REMINDER,
|
PreferenceKeys.BREAK_REMINDER,
|
||||||
"disabled"
|
"0"
|
||||||
)
|
)
|
||||||
if (breakReminderPref == "disabled") return
|
if (!breakReminderPref.all { Character.isDigit(it) } ||
|
||||||
|
breakReminderPref == "" || breakReminderPref == "0"
|
||||||
|
) return
|
||||||
Handler(Looper.getMainLooper()).postDelayed(
|
Handler(Looper.getMainLooper()).postDelayed(
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.libretube.preferences
|
package com.github.libretube.preferences
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -37,10 +38,15 @@ class GeneralSettings : MaterialPreferenceFragment() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
val breakReminder = findPreference<ListPreference>(PreferenceKeys.BREAK_REMINDER)
|
val breakReminder = findPreference<SwitchPreferenceCompat>(PreferenceKeys.BREAK_REMINDER_TOGGLE)
|
||||||
breakReminder?.setOnPreferenceChangeListener { _, _ ->
|
val breakReminderTime = findPreference<EditTextPreference>(PreferenceKeys.BREAK_REMINDER)
|
||||||
val restartDialog = RequireRestartDialog()
|
breakReminderTime?.isEnabled = PreferenceHelper.getBoolean(
|
||||||
restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name)
|
PreferenceKeys.BREAK_REMINDER_TOGGLE,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
breakReminder?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
breakReminderTime?.isEnabled = newValue as Boolean
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ object PreferenceHelper {
|
|||||||
authEditor = authSettings.edit()
|
authEditor = authSettings.edit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun putString(key: String?, value: String) {
|
||||||
|
editor.putString(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
fun getString(key: String?, defValue: String?): String {
|
fun getString(key: String?, defValue: String?): String {
|
||||||
return settings.getString(key, defValue)!!
|
return settings.getString(key, defValue)!!
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ object PreferenceKeys {
|
|||||||
const val LANGUAGE = "language"
|
const val LANGUAGE = "language"
|
||||||
const val REGION = "region"
|
const val REGION = "region"
|
||||||
const val AUTO_ROTATION = "auto_rotation"
|
const val AUTO_ROTATION = "auto_rotation"
|
||||||
|
const val BREAK_REMINDER_TOGGLE = "break_reminder_toggle"
|
||||||
const val BREAK_REMINDER = "break_reminder"
|
const val BREAK_REMINDER = "break_reminder"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +93,7 @@ object PreferenceKeys {
|
|||||||
* Advanced
|
* Advanced
|
||||||
*/
|
*/
|
||||||
const val DATA_SAVER_MODE = "data_saver_mode"
|
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 RESET_SETTINGS = "reset_settings"
|
||||||
const val CLEAR_SEARCH_HISTORY = "clear_search_history"
|
const val CLEAR_SEARCH_HISTORY = "clear_search_history"
|
||||||
const val CLEAR_WATCH_HISTORY = "clear_watch_history"
|
const val CLEAR_WATCH_HISTORY = "clear_watch_history"
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.github.libretube.views
|
package com.github.libretube.views
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||||
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +41,24 @@ open class MaterialPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.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
|
* Otherwise show the normal dialog, dialogs for other preference types are not supported yet
|
||||||
*/
|
*/
|
||||||
|
18
app/src/main/res/layout/dialog_text_preference.xml
Normal file
18
app/src/main/res/layout/dialog_text_preference.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/inputLayout"
|
||||||
|
style="@style/CustomDialogTextInputLayout"
|
||||||
|
android:layout_marginTop="10dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/input"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="number" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -828,24 +828,6 @@
|
|||||||
<item>unlimited</item>
|
<item>unlimited</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="breakReminder">
|
|
||||||
<item>@string/disabled</item>
|
|
||||||
<item>15 min</item>
|
|
||||||
<item>30 min</item>
|
|
||||||
<item>60 min</item>
|
|
||||||
<item>90 min</item>
|
|
||||||
<item>120 min</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="breakReminderValues">
|
|
||||||
<item>disabled</item>
|
|
||||||
<item>15</item>
|
|
||||||
<item>30</item>
|
|
||||||
<item>60</item>
|
|
||||||
<item>90</item>
|
|
||||||
<item>120</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="resizeMode">
|
<string-array name="resizeMode">
|
||||||
<item>@string/resize_mode_fit</item>
|
<item>@string/resize_mode_fit</item>
|
||||||
<item>@string/resize_mode_zoom</item>
|
<item>@string/resize_mode_zoom</item>
|
||||||
|
@ -310,4 +310,5 @@
|
|||||||
<string name="maximum_image_cache">Max image cache size</string>
|
<string name="maximum_image_cache">Max image cache size</string>
|
||||||
<string name="copied_to_clipboard">Copied to clipboard</string>
|
<string name="copied_to_clipboard">Copied to clipboard</string>
|
||||||
<string name="open_copied">Open</string>
|
<string name="open_copied">Open</string>
|
||||||
|
<string name="break_reminder_time">Minutes before being reminded</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -63,13 +63,18 @@
|
|||||||
|
|
||||||
<PreferenceCategory app:title="@string/misc">
|
<PreferenceCategory app:title="@string/misc">
|
||||||
|
|
||||||
<ListPreference
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:icon="@drawable/ic_notification"
|
||||||
|
app:key="break_reminder_toggle"
|
||||||
|
app:title="@string/break_reminder" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:enabled="false"
|
||||||
android:icon="@drawable/ic_time"
|
android:icon="@drawable/ic_time"
|
||||||
app:defaultValue="disabled"
|
app:defaultValue="60"
|
||||||
app:entries="@array/breakReminder"
|
|
||||||
app:entryValues="@array/breakReminderValues"
|
|
||||||
app:key="break_reminder"
|
app:key="break_reminder"
|
||||||
app:title="@string/break_reminder"
|
app:title="@string/break_reminder_time"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
Loading…
Reference in New Issue
Block a user