Merge branch 'libre-tube:master' into master

This commit is contained in:
XelXen 2022-06-21 11:45:42 +05:30 committed by GitHub
commit cd39b9d76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 2 deletions

View File

@ -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 -> {

View File

@ -1,11 +1,15 @@
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
import org.chromium.base.CommandLine.reset
class AdvancedSettings : PreferenceFragmentCompat() {
val TAG = "AdvancedSettings"
@ -23,5 +27,33 @@ class AdvancedSettings : PreferenceFragmentCompat() {
sharedPreferences.edit().remove("search_history").commit()
true
}
val resetSettings = findPreference<Preference>("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()
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="459"
android:viewportHeight="459">
<path
android:fillColor="#FF000000"
android:pathData="M229.5,0C102.75,0 0,102.75 0,229.5S102.75,459 229.5,459S459,356.25 459,229.5S356.25,0 229.5,0zM307.11,271.63c9.8,9.8 9.8,25.68 0,35.48c-4.9,4.9 -11.32,7.35 -17.74,7.35c-6.42,0 -12.84,-2.45 -17.74,-7.35L229.5,264.98l-42.13,42.13c-4.9,4.9 -11.32,7.35 -17.74,7.35c-6.42,0 -12.84,-2.45 -17.74,-7.35c-9.8,-9.8 -9.8,-25.68 0,-35.48l42.13,-42.13l-42.13,-42.13c-9.8,-9.8 -9.8,-25.68 0,-35.48s25.68,-9.8 35.48,0l42.13,42.13l42.13,-42.13c9.8,-9.8 25.68,-9.8 35.48,0c9.8,9.8 9.8,25.68 0,35.48l-42.13,42.13L307.11,271.63z" />
</vector>

View File

@ -201,4 +201,6 @@
<string name="pauseOnScreenOff_summary">Pause the player when the screen is turned off.</string>
<string name="autoplay_summary">Automatically play the next video when the current is finished.</string>
<string name="clonePlaylist">Clone playlist</string>
<string name="reset">Restore defaults</string>
<string name="reset_message">Are you sure you want to reset all the apps settings to its default?</string>
</resources>

View File

@ -46,4 +46,13 @@
</PreferenceCategory>
<PreferenceCategory>
<Preference
android:icon="@drawable/ic_reset"
app:key="reset_settings"
app:title="@string/reset" />
</PreferenceCategory>
</PreferenceScreen>