mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-16 15:20:31 +05:30
55 lines
2.0 KiB
Kotlin
55 lines
2.0 KiB
Kotlin
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 com.github.libretube.R
|
|
import com.github.libretube.requireMainActivityRestart
|
|
import com.github.libretube.util.PreferenceHelper
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
class AdvancedSettings : PreferenceFragmentCompat() {
|
|
val TAG = "AdvancedSettings"
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
setPreferencesFromResource(R.xml.advanced_settings, rootKey)
|
|
|
|
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView)
|
|
topBarTextView?.text = getString(R.string.advanced)
|
|
|
|
val clearHistory = findPreference<Preference>("clear_history")
|
|
clearHistory?.setOnPreferenceClickListener {
|
|
PreferenceHelper.removePreference(requireContext(), "search_history")
|
|
true
|
|
}
|
|
|
|
val resetSettings = findPreference<Preference>("reset_settings")
|
|
resetSettings?.setOnPreferenceClickListener {
|
|
showResetDialog()
|
|
true
|
|
}
|
|
}
|
|
|
|
private fun showResetDialog() {
|
|
MaterialAlertDialogBuilder(requireContext())
|
|
.setPositiveButton(R.string.reset) { _, _ ->
|
|
// clear default preferences
|
|
PreferenceHelper.clearPreferences(requireContext())
|
|
|
|
// 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()
|
|
}
|
|
}
|