From 44e4f0d47381cc8a61e9d7685fedf928f9c022c6 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 20 Jun 2021 07:33:36 +0200 Subject: [PATCH] Added 'more options' to junk dialog --- .../eu/faircode/email/FragmentDialogJunk.java | 57 ++++++++++++++----- app/src/main/res/layout/dialog_junk.xml | 38 ++++++++++++- 2 files changed, 77 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java b/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java index c9629a87f7..2685a99250 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java @@ -59,12 +59,15 @@ public class FragmentDialogJunk extends FragmentDialogBase { final ImageButton ibInfoProvider = view.findViewById(R.id.ibInfoProvider); final CheckBox cbBlockSender = view.findViewById(R.id.cbBlockSender); final CheckBox cbBlockDomain = view.findViewById(R.id.cbBlockDomain); + final ImageButton ibMore = view.findViewById(R.id.ibMore); + final TextView tvMore = view.findViewById(R.id.tvMore); final Button btnEditRules = view.findViewById(R.id.btnEditRules); final CheckBox cbJunkFilter = view.findViewById(R.id.cbJunkFilter); final ImageButton ibInfoFilter = view.findViewById(R.id.ibInfoFilter); final Group grpInJunk = view.findViewById(R.id.grpInJunk); + final Group grpMore = view.findViewById(R.id.grpMore); - tvMessage.setText(getString(R.string.title_ask_spam_who, from)); + // Wire controls ibInfoProvider.setOnClickListener(new View.OnClickListener() { @Override @@ -73,9 +76,6 @@ public class FragmentDialogJunk extends FragmentDialogBase { } }); - cbBlockSender.setEnabled(canBlock && ActivityBilling.isPro(getContext())); - cbBlockDomain.setEnabled(false); - cbBlockSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -83,6 +83,22 @@ public class FragmentDialogJunk extends FragmentDialogBase { } }); + View.OnClickListener onMore = new View.OnClickListener() { + @Override + public void onClick(View v) { + if (grpMore.getVisibility() == View.VISIBLE) { + ibMore.setImageLevel(1); + grpMore.setVisibility(View.GONE); + } else { + ibMore.setImageLevel(0); + grpMore.setVisibility(View.VISIBLE); + } + } + }; + + ibMore.setOnClickListener(onMore); + tvMore.setOnClickListener(onMore); + btnEditRules.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -192,7 +208,15 @@ public class FragmentDialogJunk extends FragmentDialogBase { } }); + // Initialize + tvMessage.setText(inJunk + ? getString(R.string.title_folder_junk) + : getString(R.string.title_ask_spam_who, from)); + cbBlockSender.setEnabled(canBlock && ActivityBilling.isPro(getContext())); + cbBlockDomain.setEnabled(false); + ibMore.setImageLevel(1); grpInJunk.setVisibility(inJunk ? View.GONE : View.VISIBLE); + grpMore.setVisibility(inJunk ? View.VISIBLE : View.GONE); new SimpleTask() { @Override @@ -235,17 +259,20 @@ public class FragmentDialogJunk extends FragmentDialogBase { } }.execute(FragmentDialogJunk.this, args, "junk:filter"); - return new AlertDialog.Builder(getContext()) + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) .setView(view) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - getArguments().putBoolean("block_sender", cbBlockSender.isChecked()); - getArguments().putBoolean("block_domain", cbBlockDomain.isChecked()); - sendResult(Activity.RESULT_OK); - } - }) - .setNegativeButton(android.R.string.cancel, null) - .create(); + .setNegativeButton(android.R.string.cancel, null); + + if (!inJunk) + builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + getArguments().putBoolean("block_sender", cbBlockSender.isChecked()); + getArguments().putBoolean("block_domain", cbBlockDomain.isChecked()); + sendResult(Activity.RESULT_OK); + } + }); + + return builder.create(); } } diff --git a/app/src/main/res/layout/dialog_junk.xml b/app/src/main/res/layout/dialog_junk.xml index 23e6e6a24b..472020a3d3 100644 --- a/app/src/main/res/layout/dialog_junk.xml +++ b/app/src/main/res/layout/dialog_junk.xml @@ -78,6 +78,30 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/cbBlockDomain" /> + + + +