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();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex, false))
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();
else {
Bundle args = new Bundle();
args.putString("error", Helper.formatThrowable(ex, false));
FragmentDialogError fragment = new FragmentDialogError();
fragment.setArguments(args);
fragment.show(getFragmentManager(), "boundary:error");
}
}
};
@ -4359,4 +4361,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
.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)
*/
import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -35,7 +36,9 @@ import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.DialogFragment;
import androidx.preference.PreferenceManager;
public class FragmentOptionsDisplay extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -97,7 +100,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
btnTheme.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onSelectTheme();
new FragmentDialogTheme().show(getFragmentManager(), "setup:theme");
}
});
@ -256,7 +259,39 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
editor.apply();
}
private void onSelectTheme() {
private void setOptions() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = prefs.getBoolean("compact", false);
String startup = prefs.getString("startup", "unified");
String[] startupValues = getResources().getStringArray(R.array.startupValues);
for (int pos = 0; pos < startupValues.length; pos++)
if (startupValues[pos].equals(startup)) {
spStartup.setSelection(pos);
break;
}
swDate.setChecked(prefs.getBoolean("date", true));
swThreading.setChecked(prefs.getBoolean("threading", true));
swAvatars.setChecked(prefs.getBoolean("avatars", true));
swIdenticons.setChecked(prefs.getBoolean("identicons", false));
swCircular.setChecked(prefs.getBoolean("circular", true));
swNameEmail.setChecked(prefs.getBoolean("name_email", !compact));
swSubjectItalic.setChecked(prefs.getBoolean("subject_italic", true));
swFlags.setChecked(prefs.getBoolean("flags", true));
swPreview.setChecked(prefs.getBoolean("preview", false));
swAddresses.setChecked(prefs.getBoolean("addresses", false));
swAttachmentsAlt.setChecked(prefs.getBoolean("attachments_alt", false));
swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swImages.setChecked(prefs.getBoolean("autoimages", false));
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);
@ -299,37 +334,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
return new AlertDialog.Builder(getContext())
.setView(dview)
.show();
.create();
}
private void setOptions() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = prefs.getBoolean("compact", false);
String startup = prefs.getString("startup", "unified");
String[] startupValues = getResources().getStringArray(R.array.startupValues);
for (int pos = 0; pos < startupValues.length; pos++)
if (startupValues[pos].equals(startup)) {
spStartup.setSelection(pos);
break;
}
swDate.setChecked(prefs.getBoolean("date", true));
swThreading.setChecked(prefs.getBoolean("threading", true));
swAvatars.setChecked(prefs.getBoolean("avatars", true));
swIdenticons.setChecked(prefs.getBoolean("identicons", false));
swCircular.setChecked(prefs.getBoolean("circular", true));
swNameEmail.setChecked(prefs.getBoolean("name_email", !compact));
swSubjectItalic.setChecked(prefs.getBoolean("subject_italic", true));
swFlags.setChecked(prefs.getBoolean("flags", true));
swPreview.setChecked(prefs.getBoolean("preview", false));
swAddresses.setChecked(prefs.getBoolean("addresses", false));
swAttachmentsAlt.setChecked(prefs.getBoolean("attachments_alt", false));
swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swImages.setChecked(prefs.getBoolean("autoimages", false));
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
}
}

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@ -42,7 +43,9 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
@ -161,20 +164,7 @@ public class FragmentSetup extends FragmentBase {
btnDoze.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.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();
new FragmentDialogDoze().show(getFragmentManager(), "setup:doze");
}
});
@ -357,4 +347,24 @@ public class FragmentSetup extends FragmentBase {
tvPermissionsDone.setCompoundDrawablesWithIntrinsicBounds(has ? check : null, null, null, null);
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