From 46536dd6a749e3fd9d063f3d8492e46cfe49eb3f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 21 Jun 2022 08:12:40 +0200 Subject: [PATCH 1/2] reset settings option --- .../dialogs/PlaylistOptionsDialog.kt | 13 ++++++-- .../libretube/preferences/AdvancedSettings.kt | 33 +++++++++++++++++++ app/src/main/res/drawable/ic_reset.xml | 10 ++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/advanced_settings.xml | 9 +++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_reset.xml diff --git a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt index 2c12decb9..862bf8a4f 100644 --- a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt @@ -5,6 +5,7 @@ import android.content.Context import android.os.Bundle import android.util.Log import android.widget.ArrayAdapter +import android.widget.Toast import androidx.fragment.app.DialogFragment import com.github.libretube.R import com.github.libretube.obj.PlaylistId @@ -44,8 +45,16 @@ class PlaylistOptionsDialog( 0 -> { val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) - val token = sharedPref?.getString("token", "")!! - importPlaylist(token, playlistId) + val token = sharedPref?.getString("token", "") + if (token != "") { + importPlaylist(token!!, playlistId) + } else { + Toast.makeText( + context, + R.string.login_first, + Toast.LENGTH_SHORT + ).show() + } } // share the playlist 1 -> { diff --git a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt index 44330ad77..af45a41d8 100644 --- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt @@ -1,11 +1,16 @@ package com.github.libretube.preferences +import android.content.Context import android.os.Bundle import android.widget.TextView import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.github.libretube.R +import com.github.libretube.requireMainActivityRestart +import com.github.libretube.util.ThemeHelper +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.chromium.base.CommandLine.reset class AdvancedSettings : PreferenceFragmentCompat() { val TAG = "AdvancedSettings" @@ -23,5 +28,33 @@ class AdvancedSettings : PreferenceFragmentCompat() { sharedPreferences.edit().remove("search_history").commit() true } + + val resetSettings = findPreference("reset_settings") + resetSettings?.setOnPreferenceClickListener { + showResetDialog() + true + } + } + + private fun showResetDialog() { + MaterialAlertDialogBuilder(requireContext()) + .setPositiveButton(R.string.reset) { _, _ -> + // clear default preferences + val sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()) + sharedPreferences.edit().clear().commit() + + // clear login token + val sharedPrefToken = + context?.getSharedPreferences("token", Context.MODE_PRIVATE) + sharedPrefToken?.edit()?.clear()?.commit() + + requireMainActivityRestart = true + activity?.recreate() + } + .setNegativeButton(getString(R.string.cancel)) { _, _ -> } + .setTitle(R.string.reset) + .setMessage(R.string.reset_message) + .show() } } diff --git a/app/src/main/res/drawable/ic_reset.xml b/app/src/main/res/drawable/ic_reset.xml new file mode 100644 index 000000000..2edc1a97d --- /dev/null +++ b/app/src/main/res/drawable/ic_reset.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aef9e11b1..13f95ac83 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -201,4 +201,6 @@ Pause the player when the screen is turned off. Automatically play the next video when the current is finished. Clone playlist + Restore defaults + Are you sure you want to reset all the apps settings to its default? diff --git a/app/src/main/res/xml/advanced_settings.xml b/app/src/main/res/xml/advanced_settings.xml index cbbd525b6..a9e92a024 100644 --- a/app/src/main/res/xml/advanced_settings.xml +++ b/app/src/main/res/xml/advanced_settings.xml @@ -46,4 +46,13 @@ + + + + + + \ No newline at end of file From 058adb6d998d40f1a3f58c29db2dc3cd941a7115 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 21 Jun 2022 08:13:02 +0200 Subject: [PATCH 2/2] fix --- .../java/com/github/libretube/preferences/AdvancedSettings.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt index af45a41d8..3f0715198 100644 --- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt @@ -8,7 +8,6 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.github.libretube.R import com.github.libretube.requireMainActivityRestart -import com.github.libretube.util.ThemeHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.chromium.base.CommandLine.reset