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..22a7aee55 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,14 @@ 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.google.android.material.dialog.MaterialAlertDialogBuilder class AdvancedSettings : PreferenceFragmentCompat() { val TAG = "AdvancedSettings" @@ -23,5 +26,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..c8023e03a 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? This will log you out and reset all your settings! 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