Simplified setup screen

pull/147/head
M66B 6 years ago
parent 624b24e132
commit 2b3eeed9dc

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

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

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,2L5,2c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h4l3,3 3,-3h4c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM13,18h-2v-2h2v2zM15.07,10.25l-0.9,0.92C13.45,11.9 13,12.5 13,14h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,8c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"/>
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
</vector>

@ -241,58 +241,5 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDozeDone" />
<View
android:id="@+id/vSeparatorDoze"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnData" />
<Button
android:id="@+id/btnNotifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_notifications"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorDoze" />
<ToggleButton
android:id="@+id/tbDarkTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:textOff="@string/title_setup_dark_theme"
android:textOn="@string/title_setup_light_theme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnNotifications" />
<CheckBox
android:id="@+id/cbBlackTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_setup_black_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tbDarkTheme" />
<Button
android:id="@+id/btnOptions"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_advanced"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbBlackTheme" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -3,8 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp">
android:paddingTop="6dp"
android:paddingBottom="6dp">
<View
android:id="@+id/vSeparator"

@ -107,7 +107,7 @@
<string name="title_setup_done">Done</string>
<string name="title_setup_light_theme">Light theme</string>
<string name="title_setup_dark_theme">Dark theme</string>
<string name="title_setup_black_background">Black background</string>
<string name="title_setup_black_theme">Black theme</string>
<string name="title_advanced">Advanced options</string>

Loading…
Cancel
Save