From 2b3eeed9dc791cd7394a360a3eeaa02306ca6263 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 14 Jan 2019 12:01:33 +0000 Subject: [PATCH] Simplified setup screen --- .../java/eu/faircode/email/ActivitySetup.java | 68 +++++++++++++++- .../java/eu/faircode/email/FragmentSetup.java | 80 ------------------- .../res/drawable/baseline_live_help_24.xml | 10 +++ .../main/res/drawable/baseline_palette_24.xml | 10 +++ app/src/main/res/layout/fragment_setup.xml | 53 ------------ .../main/res/layout/item_drawer_separator.xml | 4 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 89 insertions(+), 138 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_live_help_24.xml create mode 100644 app/src/main/res/drawable/baseline_palette_24.xml diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 31bdb81f31..d477d090a8 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -32,6 +32,7 @@ import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; +import android.provider.Settings; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.MenuItem; @@ -131,12 +132,23 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On case R.string.title_setup_help: onMenuHelp(); break; + case R.string.title_setup_notifications: + onManageNotifications(); + break; case R.string.title_setup_export: onMenuExport(); break; case R.string.title_setup_import: onMenuImport(); break; + case R.string.title_setup_light_theme: + case R.string.title_setup_dark_theme: + case R.string.title_setup_black_theme: + onMenuTheme(item.getId()); + break; + case R.string.title_setup_advanced: + onMenuOptions(); + break; case R.string.menu_legend: onMenuLegend(); break; @@ -159,15 +171,29 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On DrawerAdapter drawerArray = new DrawerAdapter(this); if (getIntentHelp().resolveActivity(pm) != null) - drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_settings_applications_24, R.string.title_setup_help)); + drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_live_help_24, R.string.title_setup_help)); drawerArray.add(new DrawerItem(R.layout.item_drawer_separator)); + if (getIntentNotifications(this).resolveActivity(pm) != null) + drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_notifications_24, R.string.title_setup_notifications)); + if (getIntentExport().resolveActivity(pm) != null) drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_archive_24, R.string.title_setup_export)); if (getIntentImport().resolveActivity(pm) != null) drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_unarchive_24, R.string.title_setup_import)); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + String theme = prefs.getString("theme", "light"); + if ("dark".equals(theme)) + drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_black_theme)); + else if ("black".equals(theme)) + drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_light_theme)); + else + drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_dark_theme)); + + drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_settings_applications_24, R.string.title_setup_advanced)); + drawerArray.add(new DrawerItem(R.layout.item_drawer_separator)); drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_help_24, R.string.menu_legend)); @@ -311,6 +337,10 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On startActivity(getIntentHelp()); } + private void onManageNotifications() { + startActivity(getIntentNotifications(this)); + } + private void onMenuExport() { if (Helper.isPro(this)) try { @@ -333,6 +363,33 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On } } + private void onMenuTheme(int id) { + if (Helper.isPro(this)) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + switch (id) { + case R.string.title_setup_light_theme: + prefs.edit().putString("theme", "light").apply(); + break; + case R.string.title_setup_dark_theme: + prefs.edit().putString("theme", "dark").apply(); + break; + case R.string.title_setup_black_theme: + prefs.edit().putString("theme", "black").apply(); + break; + } + } else { + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); + fragmentTransaction.commit(); + } + } + + private void onMenuOptions() { + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, new FragmentOptions()).addToBackStack("options"); + fragmentTransaction.commit(); + } + private void onMenuLegend() { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new FragmentLegend()).addToBackStack("legend"); @@ -359,6 +416,13 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On return intent; } + private static Intent getIntentNotifications(Context context) { + return new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) + .putExtra("app_package", context.getPackageName()) + .putExtra("app_uid", context.getApplicationInfo().uid) + .putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); + } + private static Intent getIntentExport() { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); @@ -578,7 +642,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On for (int s = 0; s < jsettings.length(); s++) { JSONObject jsetting = (JSONObject) jsettings.get(s); String key = jsetting.getString("key"); - if (!"pro".equals(key)) { + if (!"pro".equals(key) && !"theme".equals(key)) { Object value = jsetting.get("value"); if (value instanceof Boolean) editor.putBoolean(key, (Boolean) value); diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 7bc412003c..18c2f60717 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -25,7 +25,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; @@ -33,16 +32,12 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.PowerManager; -import android.preference.PreferenceManager; import android.provider.Settings; 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.TextView; -import android.widget.ToggleButton; import java.util.List; @@ -73,13 +68,6 @@ public class FragmentSetup extends FragmentEx { private Button btnData; - private Button btnNotifications; - - private ToggleButton tbDarkTheme; - private CheckBox cbBlackTheme; - - private Button btnOptions; - private Drawable check; private static final String[] permissions = new String[]{ @@ -111,14 +99,8 @@ public class FragmentSetup extends FragmentEx { btnDoze = view.findViewById(R.id.btnDoze); tvDozeDone = view.findViewById(R.id.tvDozeDone); - btnNotifications = view.findViewById(R.id.btnNotifications); - btnData = view.findViewById(R.id.btnData); - tbDarkTheme = view.findViewById(R.id.tbDarkTheme); - cbBlackTheme = view.findViewById(R.id.cbBlackTheme); - btnOptions = view.findViewById(R.id.btnOptions); - // Wire controls btnQuick.setOnClickListener(new View.OnClickListener() { @@ -189,61 +171,6 @@ public class FragmentSetup extends FragmentEx { } }); - PackageManager pm = getContext().getPackageManager(); - btnNotifications.setVisibility(getIntentNotifications(getContext()).resolveActivity(pm) == null ? View.GONE : View.VISIBLE); - btnNotifications.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(getIntentNotifications(getContext())); - } - }); - - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - - String theme = prefs.getString("theme", "light"); - boolean light = "light".equals(theme); - tbDarkTheme.setTag(!light); - tbDarkTheme.setChecked(!light); - tbDarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton button, boolean checked) { - if (Helper.isPro(getContext())) { - if (checked != (Boolean) button.getTag()) { - button.setTag(checked); - tbDarkTheme.setChecked(checked); - prefs.edit().putString("theme", checked ? "dark" : "light").apply(); - } - } else { - prefs.edit().remove("theme").apply(); - if (checked) { - tbDarkTheme.setChecked(false); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); - fragmentTransaction.commit(); - } - } - cbBlackTheme.setVisibility(tbDarkTheme.isChecked() ? View.VISIBLE : View.GONE); - } - }); - - cbBlackTheme.setChecked("black".equals(theme)); - cbBlackTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean checked) { - prefs.edit().putString("theme", checked ? "black" : "dark").apply(); - } - }); - cbBlackTheme.setVisibility(tbDarkTheme.isChecked() ? View.VISIBLE : View.GONE); - - btnOptions.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.content_frame, new FragmentOptions()).addToBackStack("options"); - fragmentTransaction.commit(); - } - }); - // Initialize tvAccountDone.setText(null); tvAccountDone.setCompoundDrawables(null, null, null, null); @@ -423,11 +350,4 @@ public class FragmentSetup extends FragmentEx { } }.execute(FragmentSetup.this, new Bundle(), "setup:sync"); } - - private static Intent getIntentNotifications(Context context) { - return new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) - .putExtra("app_package", context.getPackageName()) - .putExtra("app_uid", context.getApplicationInfo().uid) - .putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - } } diff --git a/app/src/main/res/drawable/baseline_live_help_24.xml b/app/src/main/res/drawable/baseline_live_help_24.xml new file mode 100644 index 0000000000..d074524486 --- /dev/null +++ b/app/src/main/res/drawable/baseline_live_help_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/baseline_palette_24.xml b/app/src/main/res/drawable/baseline_palette_24.xml new file mode 100644 index 0000000000..230f75166b --- /dev/null +++ b/app/src/main/res/drawable/baseline_palette_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_setup.xml b/app/src/main/res/layout/fragment_setup.xml index 7b63ce8336..4f5e430db8 100644 --- a/app/src/main/res/layout/fragment_setup.xml +++ b/app/src/main/res/layout/fragment_setup.xml @@ -241,58 +241,5 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvDozeDone" /> - - - -