mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Ask restart when theme is changed
This commit is contained in:
parent
f66fda968e
commit
e9b62b71d1
3 changed files with 30 additions and 2 deletions
|
@ -16,15 +16,18 @@ package app.fedilab.android.activities
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import app.fedilab.android.R
|
||||
import app.fedilab.android.databinding.ActivitySettingsBinding
|
||||
import app.fedilab.android.helper.Helper
|
||||
import app.fedilab.android.helper.ThemeHelper
|
||||
import app.fedilab.android.ui.fragment.settings.FragmentThemingSettings
|
||||
|
||||
class SettingsActivity : BaseActivity() {
|
||||
class SettingsActivity : BaseActivity(), FragmentThemingSettings.ActionTheming {
|
||||
private lateinit var binding: ActivitySettingsBinding
|
||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||
|
||||
|
@ -34,7 +37,6 @@ class SettingsActivity : BaseActivity() {
|
|||
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val navController = findNavController(R.id.fragment_container)
|
||||
appBarConfiguration = AppBarConfiguration.Builder().build()
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
|
@ -53,4 +55,16 @@ class SettingsActivity : BaseActivity() {
|
|||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun restart() {
|
||||
val restartBuilder = AlertDialog.Builder(this, Helper.dialogStyle())
|
||||
restartBuilder.setTitle(getString(R.string.restart_the_app))
|
||||
restartBuilder.setMessage(getString(R.string.restart_the_app_theme))
|
||||
restartBuilder.setNegativeButton(R.string.no) { dialog, which -> dialog.dismiss() }
|
||||
restartBuilder.setPositiveButton(R.string.restart) { dialog, which ->
|
||||
dialog.dismiss()
|
||||
Helper.restart(this)
|
||||
}
|
||||
restartBuilder.create().show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.ComposeActivity;
|
||||
import app.fedilab.android.activities.SettingsActivity;
|
||||
import app.fedilab.android.databinding.PopupStatusThemeBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
|
@ -75,6 +76,8 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
|
|||
private List<LinkedHashMap<String, String>> listOfThemes;
|
||||
private SharedPreferences appPref;
|
||||
private SharedPreferences cyneaPref;
|
||||
public ActionTheming actionTheming;
|
||||
private boolean shouldRestart;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
|
@ -82,6 +85,8 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
|
|||
appPref = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||
createPref();
|
||||
listOfThemes = ThemeHelper.getContributorsTheme(requireActivity());
|
||||
shouldRestart = false;
|
||||
actionTheming = (SettingsActivity) requireActivity();
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,6 +106,9 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
|
|||
getPreferenceScreen().getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
if (shouldRestart && actionTheming != null) {
|
||||
actionTheming.restart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,9 +117,14 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
|
|||
if (key.equals("use_custom_theme")) {
|
||||
createPref();
|
||||
}
|
||||
shouldRestart = true;
|
||||
Helper.recreateMainActivity(requireActivity());
|
||||
}
|
||||
|
||||
public interface ActionTheming {
|
||||
void restart();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint("ApplySharedPref")
|
||||
|
|
|
@ -1599,4 +1599,5 @@
|
|||
<string name="state">State</string>
|
||||
<string name="restart_the_app">Restart the app?</string>
|
||||
<string name="restart">Restart</string>
|
||||
<string name="restart_the_app_theme">You should restart the application to apply changes.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue