Ask with warning

This commit is contained in:
M66B 2020-10-25 14:55:58 +01:00
parent bc20fe328e
commit 3800c98239
11 changed files with 35 additions and 5 deletions

View File

@ -732,6 +732,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
aargs.putString("question", context.getString(R.string.title_empty_spam_ask));
else
throw new IllegalArgumentException("Invalid folder type=" + type);
aargs.putBoolean("warning", true);
aargs.putString("remark", context.getString(R.string.title_empty_all));
aargs.putLong("folder", folder.id);
aargs.putString("type", type);
@ -800,6 +801,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
Bundle aargs = new Bundle();
aargs.putLong("id", folder.id);
aargs.putString("question", context.getString(R.string.title_folder_delete));
aargs.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);

View File

@ -3833,6 +3833,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putLong("id", message.id);
aargs.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
@ -4402,6 +4403,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putLong("id", message.id);
aargs.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);

View File

@ -1635,6 +1635,7 @@ public class FragmentAccount extends FragmentBase {
private void onMenuDelete() {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_account_delete));
aargs.putBoolean("warning", true);
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(aargs);

View File

@ -239,6 +239,7 @@ public class FragmentAnswer extends FragmentBase {
private void onActionDelete() {
Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_delete_answer));
args.putBoolean("warning", true);
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(args);

View File

@ -1826,6 +1826,7 @@ public class FragmentCompose extends FragmentBase {
else {
Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_discard));
args.putBoolean("warning", true);
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(args);

View File

@ -21,8 +21,10 @@ package eu.faircode.email;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -39,11 +41,16 @@ public class FragmentDialogAsk extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
String question = getArguments().getString("question");
String remark = getArguments().getString("remark");
String notagain = getArguments().getString("notagain");
Bundle args = getArguments();
String question = args.getString("question");
String remark = args.getString("remark");
String notagain = args.getString("notagain");
boolean warning = args.getBoolean("warning");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null);
final Context context = getContext();
final int colorError = Helper.resolveColor(context, R.attr.colorError);
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_ask_again, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
TextView tvRemark = dview.findViewById(R.id.tvRemark);
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
@ -53,11 +60,19 @@ public class FragmentDialogAsk extends FragmentDialogBase {
tvRemark.setVisibility(remark == null ? View.GONE : View.VISIBLE);
cbNotAgain.setVisibility(notagain == null ? View.GONE : View.VISIBLE);
if (warning) {
Drawable w = context.getResources().getDrawable(R.drawable.twotone_warning_24, context.getTheme());
w.setBounds(0, 0, w.getIntrinsicWidth(), w.getIntrinsicHeight());
w.setTint(colorError);
tvMessage.setCompoundDrawablesRelative(w, null, null, null);
tvMessage.setCompoundDrawablePadding(Helper.dp2pixels(context, 12));
}
if (notagain != null)
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean(notagain, isChecked).apply();
}
});

View File

@ -385,6 +385,7 @@ public class FragmentFolder extends FragmentBase {
private void onMenuDelete() {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_folder_delete));
aargs.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);

View File

@ -1295,6 +1295,7 @@ public class FragmentIdentity extends FragmentBase {
private void onMenuDelete() {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_identity_delete));
aargs.putBoolean("warning", true);
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(aargs);

View File

@ -2195,6 +2195,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_delete));
args.putLong("id", message.id);
args.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(args);
@ -3097,6 +3098,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
aargs.putString("question", getResources()
.getQuantityString(R.plurals.title_deleting_messages, ids.size(), ids.size()));
aargs.putLongArray("ids", Helper.toLongArray(ids));
aargs.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
@ -3373,6 +3375,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
aargs.putString("question", getResources()
.getQuantityString(R.plurals.title_deleting_messages, ids.size(), ids.size()));
aargs.putLongArray("ids", Helper.toLongArray(ids));
aargs.putBoolean("warning", true);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
@ -4132,6 +4135,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
account < 0 ? R.string.title_empty_spam_all_ask : R.string.title_empty_spam_ask));
else
throw new IllegalArgumentException("Invalid folder type=" + type);
aargs.putBoolean("warning", true);
aargs.putString("remark", getString(R.string.title_empty_all));
aargs.putLong("account", account);
aargs.putString("type", type);

View File

@ -701,6 +701,7 @@ public class FragmentPop extends FragmentBase {
private void onMenuDelete() {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_account_delete));
aargs.putBoolean("warning", true);
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(aargs);

View File

@ -947,6 +947,7 @@ public class FragmentRule extends FragmentBase {
private void onActionDelete() {
Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_delete_rule));
args.putBoolean("warning", true);
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(args);