Browse Source

Moved dark theme setting to setup

main
M66B 6 years ago
parent
commit
4467a088ea
5 changed files with 56 additions and 15 deletions
  1. +19
    -2
      app/src/main/java/eu/faircode/email/ActivityBase.java
  2. +1
    -12
      app/src/main/java/eu/faircode/email/ActivityView.java
  3. +24
    -0
      app/src/main/java/eu/faircode/email/FragmentSetup.java
  4. +11
    -0
      app/src/main/res/layout/fragment_setup.xml
  5. +1
    -1
      app/src/main/res/values/strings.xml

+ 19
- 2
app/src/main/java/eu/faircode/email/ActivityBase.java View File

@ -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();
}
}

+ 1
- 12
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -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));
}


+ 24
- 0
app/src/main/java/eu/faircode/email/FragmentSetup.java View File

@ -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);


+ 11
- 0
app/src/main/res/layout/fragment_setup.xml View File

@ -160,5 +160,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPermissions" />
<CheckBox
android:id="@+id/cbDarkTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_setup_dark_theme"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" />
</android.support.constraint.ConstraintLayout>
</ScrollView>

+ 1
- 1
app/src/main/res/values/strings.xml View File

@ -10,7 +10,6 @@
<string name="menu_unified">Unified inbox</string>
<string name="menu_folders">Folders</string>
<string name="menu_theme">Dark theme</string>
<string name="menu_setup">Setup</string>
<string name="menu_debug">Debug info</string>
@ -36,6 +35,7 @@
<string name="title_setup_permissions">Grant permissions</string>
<string name="title_setup_permissions_remark">To read contacts (optional)</string>
<string name="title_setup_done">Done</string>
<string name="title_setup_dark_theme">Dark theme</string>
<string name="title_name">Your name</string>
<string name="title_email">Your email address</string>


Loading…
Cancel
Save