Use dialog fragments to select theme, disable doze, boundary errors

pull/157/head
M66B 6 years ago
parent 976daac18a
commit be56a865cb

@ -2694,12 +2694,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
snackbar.show(); snackbar.show();
} else if (ex instanceof IllegalArgumentException) } else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else else {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) Bundle args = new Bundle();
.setMessage(Helper.formatThrowable(ex, false)) args.putString("error", Helper.formatThrowable(ex, false));
.setPositiveButton(android.R.string.cancel, null)
.create() FragmentDialogError fragment = new FragmentDialogError();
.show(); fragment.setArguments(args);
fragment.show(getFragmentManager(), "boundary:error");
}
} }
}; };
@ -4359,4 +4361,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
.create(); .create();
} }
} }
public static class FragmentDialogError extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
String error = getArguments().getString("error");
return new AlertDialog.Builder(getContext())
.setMessage(error)
.setPositiveButton(android.R.string.cancel, null)
.create();
}
}
} }

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B) Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/ */
import android.app.Dialog;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -35,7 +36,9 @@ import android.widget.Spinner;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.DialogFragment;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
public class FragmentOptionsDisplay extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentOptionsDisplay extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -97,7 +100,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
btnTheme.setOnClickListener(new View.OnClickListener() { btnTheme.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
onSelectTheme(); new FragmentDialogTheme().show(getFragmentManager(), "setup:theme");
} }
}); });
@ -256,54 +259,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
editor.apply(); editor.apply();
} }
private void onSelectTheme() {
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_theme, null);
final RadioGroup rgTheme = dview.findViewById(R.id.rgTheme);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String theme = prefs.getString("theme", "light");
switch (theme) {
case "dark":
rgTheme.check(R.id.rbThemeDark);
break;
case "black":
rgTheme.check(R.id.rbThemeBlack);
break;
case "system":
rgTheme.check(R.id.rbThemeSystem);
break;
default:
rgTheme.check(R.id.rbThemeLight);
}
rgTheme.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
getActivity().getIntent().putExtra("tab", "display");
switch (checkedId) {
case R.id.rbThemeLight:
prefs.edit().putString("theme", "light").apply();
break;
case R.id.rbThemeDark:
prefs.edit().putString("theme", "dark").apply();
break;
case R.id.rbThemeBlack:
prefs.edit().putString("theme", "black").apply();
break;
case R.id.rbThemeSystem:
prefs.edit().putString("theme", "system").apply();
break;
}
}
});
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setView(dview)
.show();
}
private void setOptions() { private void setOptions() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
@ -332,4 +287,56 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swImages.setChecked(prefs.getBoolean("autoimages", false)); swImages.setChecked(prefs.getBoolean("autoimages", false));
swActionbar.setChecked(prefs.getBoolean("actionbar", true)); swActionbar.setChecked(prefs.getBoolean("actionbar", true));
} }
public static class FragmentDialogTheme extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_theme, null);
final RadioGroup rgTheme = dview.findViewById(R.id.rgTheme);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String theme = prefs.getString("theme", "light");
switch (theme) {
case "dark":
rgTheme.check(R.id.rbThemeDark);
break;
case "black":
rgTheme.check(R.id.rbThemeBlack);
break;
case "system":
rgTheme.check(R.id.rbThemeSystem);
break;
default:
rgTheme.check(R.id.rbThemeLight);
}
rgTheme.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
getActivity().getIntent().putExtra("tab", "display");
switch (checkedId) {
case R.id.rbThemeLight:
prefs.edit().putString("theme", "light").apply();
break;
case R.id.rbThemeDark:
prefs.edit().putString("theme", "dark").apply();
break;
case R.id.rbThemeBlack:
prefs.edit().putString("theme", "black").apply();
break;
case R.id.rbThemeSystem:
prefs.edit().putString("theme", "system").apply();
break;
}
}
});
return new AlertDialog.Builder(getContext())
.setView(dview)
.create();
}
}
} }

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.Manifest; import android.Manifest;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -42,7 +43,9 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -161,20 +164,7 @@ public class FragmentSetup extends FragmentBase {
btnDoze.setOnClickListener(new View.OnClickListener() { btnDoze.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) new FragmentDialogDoze().show(getFragmentManager(), "setup:doze");
.setMessage(R.string.title_setup_doze_instructions)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
} catch (Throwable ex) {
Log.e(ex);
}
}
})
.create()
.show();
} }
}); });
@ -357,4 +347,24 @@ public class FragmentSetup extends FragmentBase {
tvPermissionsDone.setCompoundDrawablesWithIntrinsicBounds(has ? check : null, null, null, null); tvPermissionsDone.setCompoundDrawablesWithIntrinsicBounds(has ? check : null, null, null, null);
btnPermissions.setEnabled(!has); btnPermissions.setEnabled(!has);
} }
public static class FragmentDialogDoze extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setMessage(R.string.title_setup_doze_instructions)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
} catch (Throwable ex) {
Log.e(ex);
}
}
})
.create();
}
}
} }

Loading…
Cancel
Save