mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Moved dark theme setting to setup
This commit is contained in:
@@ -23,13 +23,30 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
|
||||
abstract class ActivityBase extends AppCompatActivity {
|
||||
abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(Helper.TAG, "Create " + this.getClass().getName());
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String theme = prefs.getString("theme", "light");
|
||||
setTheme("dark".equals(theme) ? R.style.AppThemeDark : R.style.AppThemeLight);
|
||||
setTheme("light".equals(theme) ? R.style.AppThemeLight : R.style.AppThemeDark);
|
||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.i(Helper.TAG, "Destroy " + this.getClass().getName());
|
||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
Log.i(Helper.TAG, "Preference " + key + "=" + prefs.getAll().get(key));
|
||||
if ("theme".equals(key))
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +111,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
case R.string.menu_folders:
|
||||
onMenuFolders();
|
||||
break;
|
||||
case R.string.menu_theme:
|
||||
onMenuTheme();
|
||||
break;
|
||||
case R.string.menu_setup:
|
||||
onMenuSetup();
|
||||
break;
|
||||
@@ -184,6 +181,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
super.onSharedPreferenceChanged(prefs, key);
|
||||
if ("eula".equals(key))
|
||||
init();
|
||||
}
|
||||
@@ -244,7 +242,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
ArrayAdapterDrawer drawerArray = new ArrayAdapterDrawer(this, R.layout.item_drawer);
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_unified));
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_folders));
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_theme, "dark".equals(prefs.getString("theme", "light"))));
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_setup));
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.string.menu_debug));
|
||||
drawerList.setAdapter(drawerArray);
|
||||
@@ -268,14 +265,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void onMenuTheme() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String theme = prefs.getString("theme", "light");
|
||||
theme = ("dark".equals(theme) ? "light" : "dark");
|
||||
prefs.edit().putString("theme", theme).apply();
|
||||
recreate();
|
||||
}
|
||||
|
||||
private void onMenuSetup() {
|
||||
startActivity(new Intent(ActivityView.this, ActivitySetup.class));
|
||||
}
|
||||
|
||||
@@ -21,8 +21,10 @@ package eu.faircode.email;
|
||||
|
||||
import android.Manifest;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -33,6 +35,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -54,6 +58,8 @@ public class FragmentSetup extends Fragment {
|
||||
private Button btnPermissions;
|
||||
private TextView tvPermissionsDone;
|
||||
|
||||
private CheckBox cbDarkTheme;
|
||||
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
private static final String[] permissions = new String[]{
|
||||
@@ -79,6 +85,8 @@ public class FragmentSetup extends Fragment {
|
||||
btnPermissions = view.findViewById(R.id.btnPermissions);
|
||||
tvPermissionsDone = view.findViewById(R.id.tvPermissionsDone);
|
||||
|
||||
cbDarkTheme = view.findViewById(R.id.cbDarkTheme);
|
||||
|
||||
// Wire controls
|
||||
|
||||
btnAccount.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -175,6 +183,22 @@ public class FragmentSetup extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
String theme = prefs.getString("theme", "light");
|
||||
boolean dark = "dark".equals(theme);
|
||||
cbDarkTheme.setTag(dark);
|
||||
cbDarkTheme.setChecked(dark);
|
||||
cbDarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
||||
if (checked != (Boolean) button.getTag()) {
|
||||
button.setTag(checked);
|
||||
cbDarkTheme.setChecked(checked);
|
||||
prefs.edit().putString("theme", checked ? "dark" : "light").apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize
|
||||
|
||||
pbAccount.setVisibility(View.GONE);
|
||||
|
||||
Reference in New Issue
Block a user