mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
fix theme and introduce require restart dialog
This commit is contained in:
parent
bedfb13539
commit
9cbf9f2155
@ -1,10 +1,8 @@
|
||||
package com.github.libretube.activities
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.ActivitySettingsBinding
|
||||
import com.github.libretube.preferences.MainSettings
|
||||
@ -12,7 +10,6 @@ import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.material.color.DynamicColors
|
||||
|
||||
var isCurrentViewMainSettings = true
|
||||
var requireMainActivityRestart = false
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
val TAG = "SettingsActivity"
|
||||
@ -50,17 +47,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (isCurrentViewMainSettings) {
|
||||
if (requireMainActivityRestart) {
|
||||
requireMainActivityRestart = false
|
||||
// kill player notification
|
||||
val nManager =
|
||||
this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
nManager.cancelAll()
|
||||
ThemeHelper.restartMainActivity(this)
|
||||
ActivityCompat.finishAffinity(this)
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
finishAndRemoveTask()
|
||||
} else {
|
||||
isCurrentViewMainSettings = true
|
||||
|
@ -7,7 +7,6 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.databinding.DialogDeleteAccountBinding
|
||||
import com.github.libretube.obj.DeleteUserRequest
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
@ -55,10 +54,10 @@ class DeleteAccountDialog : DialogFragment() {
|
||||
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show()
|
||||
return@launchWhenCreated
|
||||
}
|
||||
requireMainActivityRestart = true
|
||||
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
|
||||
logout()
|
||||
dialog?.dismiss()
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
}
|
||||
}
|
||||
run()
|
||||
|
@ -7,7 +7,6 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.databinding.DialogLoginBinding
|
||||
import com.github.libretube.obj.Login
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
@ -82,9 +81,9 @@ class LoginDialog : DialogFragment() {
|
||||
Toast.makeText(context, R.string.loggedIn, Toast.LENGTH_SHORT).show()
|
||||
PreferenceHelper.setToken(requireContext(), response.token!!)
|
||||
PreferenceHelper.setUsername(requireContext(), login.username!!)
|
||||
requireMainActivityRestart = true
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(parentFragmentManager, "RequireRestartDialog")
|
||||
dialog?.dismiss()
|
||||
activity?.recreate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.databinding.DialogLogoutBinding
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
@ -25,7 +24,6 @@ class LogoutDialog : DialogFragment() {
|
||||
binding.user.text =
|
||||
binding.user.text.toString() + " (" + user + ")"
|
||||
binding.logout.setOnClickListener {
|
||||
requireMainActivityRestart = true
|
||||
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
|
||||
PreferenceHelper.setToken(requireContext(), "")
|
||||
dialog?.dismiss()
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.github.libretube.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class RequireRestartDialog : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.require_restart)
|
||||
.setMessage(R.string.require_restart_message)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
activity?.recreate()
|
||||
ThemeHelper.restartMainActivity(requireContext())
|
||||
}
|
||||
.setNegativeButton(R.string.cancel) { _, _ -> }
|
||||
.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.SettingsActivity
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.dialogs.RequireRestartDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class AdvancedSettings : PreferenceFragmentCompat() {
|
||||
@ -48,8 +48,8 @@ class AdvancedSettings : PreferenceFragmentCompat() {
|
||||
// clear login token
|
||||
PreferenceHelper.setToken(requireContext(), "")
|
||||
|
||||
requireMainActivityRestart = true
|
||||
activity?.recreate()
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
}
|
||||
.setNegativeButton(getString(R.string.cancel)) { _, _ -> }
|
||||
.setTitle(R.string.reset)
|
||||
|
@ -6,7 +6,7 @@ import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreference
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.SettingsActivity
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.dialogs.RequireRestartDialog
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.material.color.DynamicColors
|
||||
|
||||
@ -20,16 +20,16 @@ class AppearanceSettings : PreferenceFragmentCompat() {
|
||||
|
||||
val themeToggle = findPreference<ListPreference>("theme_togglee")
|
||||
themeToggle?.setOnPreferenceChangeListener { _, _ ->
|
||||
requireMainActivityRestart = true
|
||||
activity?.recreate()
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
|
||||
val accentColor = findPreference<ListPreference>("accent_color")
|
||||
updateAccentColorValues(accentColor!!)
|
||||
accentColor.setOnPreferenceChangeListener { _, _ ->
|
||||
requireMainActivityRestart = true
|
||||
activity?.recreate()
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
|
||||
@ -41,13 +41,15 @@ class AppearanceSettings : PreferenceFragmentCompat() {
|
||||
|
||||
val gridColumns = findPreference<ListPreference>("grid")
|
||||
gridColumns?.setOnPreferenceChangeListener { _, _ ->
|
||||
requireMainActivityRestart = true
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
|
||||
val hideTrending = findPreference<SwitchPreference>("hide_trending_page")
|
||||
hideTrending?.setOnPreferenceChangeListener { _, _ ->
|
||||
requireMainActivityRestart = true
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreference
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.SettingsActivity
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.dialogs.CustomInstanceDialog
|
||||
import com.github.libretube.dialogs.DeleteAccountDialog
|
||||
import com.github.libretube.dialogs.LoginDialog
|
||||
import com.github.libretube.dialogs.LogoutDialog
|
||||
import com.github.libretube.dialogs.RequireRestartDialog
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
import org.json.JSONObject
|
||||
import org.json.JSONTokener
|
||||
@ -119,7 +119,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
||||
// fetchInstance()
|
||||
initCustomInstances(instance!!)
|
||||
instance.setOnPreferenceChangeListener { _, newValue ->
|
||||
requireMainActivityRestart = true
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
RetrofitInstance.url = newValue.toString()
|
||||
if (!PreferenceHelper.getBoolean(requireContext(), "auth_instance_toggle", false)) {
|
||||
RetrofitInstance.authUrl = newValue.toString()
|
||||
@ -136,22 +137,24 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
||||
authInstance.isVisible = false
|
||||
}
|
||||
authInstance.setOnPreferenceChangeListener { _, newValue ->
|
||||
requireMainActivityRestart = true
|
||||
// save new auth url
|
||||
RetrofitInstance.authUrl = newValue.toString()
|
||||
RetrofitInstance.lazyMgr.reset()
|
||||
logout()
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
|
||||
val authInstanceToggle = findPreference<SwitchPreference>("auth_instance_toggle")
|
||||
authInstanceToggle?.setOnPreferenceChangeListener { _, newValue ->
|
||||
requireMainActivityRestart = true
|
||||
authInstance.isVisible = newValue == true
|
||||
logout()
|
||||
// either use new auth url or the normal api url if auth instance disabled
|
||||
RetrofitInstance.authUrl = if (newValue == false) RetrofitInstance.url
|
||||
else authInstance.value
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import androidx.preference.PreferenceFragmentCompat
|
||||
import com.github.libretube.BuildConfig
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.isCurrentViewMainSettings
|
||||
import com.github.libretube.activities.requireMainActivityRestart
|
||||
import com.github.libretube.dialogs.RequireRestartDialog
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.github.libretube.util.checkUpdate
|
||||
|
||||
@ -25,7 +25,8 @@ class MainSettings : PreferenceFragmentCompat() {
|
||||
|
||||
val region = findPreference<Preference>("region")
|
||||
region?.setOnPreferenceChangeListener { _, _ ->
|
||||
requireMainActivityRestart = true
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -231,4 +231,6 @@
|
||||
<string name="open">Open …</string>
|
||||
<string name="chapters">Chapters</string>
|
||||
<string name="change_playback_speed">Playback speed</string>
|
||||
<string name="require_restart">Restart required</string>
|
||||
<string name="require_restart_message">This change requires an app restart. Do you want to restart the app now? Otherwise the changes will be applied on the next app restart.</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user