2022-06-07 16:12:59 +05:30
|
|
|
package com.github.libretube.preferences
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2022-06-07 23:46:58 +05:30
|
|
|
import android.widget.TextView
|
2022-06-07 16:12:59 +05:30
|
|
|
import androidx.preference.Preference
|
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
|
|
import com.github.libretube.R
|
2022-06-21 11:42:40 +05:30
|
|
|
import com.github.libretube.requireMainActivityRestart
|
2022-06-26 01:51:22 +05:30
|
|
|
import com.github.libretube.util.PreferenceHelper
|
2022-06-21 11:42:40 +05:30
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
2022-06-07 16:12:59 +05:30
|
|
|
|
2022-06-07 20:22:06 +05:30
|
|
|
class AdvancedSettings : PreferenceFragmentCompat() {
|
|
|
|
val TAG = "AdvancedSettings"
|
2022-06-09 17:52:07 +05:30
|
|
|
|
2022-06-07 16:12:59 +05:30
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
2022-06-07 20:22:06 +05:30
|
|
|
setPreferencesFromResource(R.xml.advanced_settings, rootKey)
|
|
|
|
|
2022-06-08 00:52:35 +05:30
|
|
|
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView)
|
|
|
|
topBarTextView?.text = getString(R.string.advanced)
|
2022-06-07 23:46:58 +05:30
|
|
|
|
2022-06-07 20:22:06 +05:30
|
|
|
val clearHistory = findPreference<Preference>("clear_history")
|
|
|
|
clearHistory?.setOnPreferenceClickListener {
|
2022-06-26 01:51:22 +05:30
|
|
|
PreferenceHelper.removePreference(requireContext(), "search_history")
|
2022-06-07 20:22:06 +05:30
|
|
|
true
|
|
|
|
}
|
2022-06-21 11:42:40 +05:30
|
|
|
|
|
|
|
val resetSettings = findPreference<Preference>("reset_settings")
|
|
|
|
resetSettings?.setOnPreferenceClickListener {
|
|
|
|
showResetDialog()
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun showResetDialog() {
|
|
|
|
MaterialAlertDialogBuilder(requireContext())
|
|
|
|
.setPositiveButton(R.string.reset) { _, _ ->
|
|
|
|
// clear default preferences
|
2022-06-26 01:51:22 +05:30
|
|
|
PreferenceHelper.clearPreferences(requireContext())
|
2022-06-21 11:42:40 +05:30
|
|
|
|
|
|
|
// clear login token
|
2022-06-26 14:38:10 +05:30
|
|
|
PreferenceHelper.setToken(requireContext(), "")
|
2022-06-21 11:42:40 +05:30
|
|
|
|
|
|
|
requireMainActivityRestart = true
|
|
|
|
activity?.recreate()
|
|
|
|
}
|
|
|
|
.setNegativeButton(getString(R.string.cancel)) { _, _ -> }
|
|
|
|
.setTitle(R.string.reset)
|
|
|
|
.setMessage(R.string.reset_message)
|
|
|
|
.show()
|
2022-06-07 16:12:59 +05:30
|
|
|
}
|
2022-06-07 16:14:22 +05:30
|
|
|
}
|