Bulk block senders

pull/206/head
M66B 3 years ago
parent ffbc591684
commit 4bf24baf5e

@ -3249,16 +3249,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onActionRaw(); onActionRaw();
return true; return true;
} else if (itemId == R.string.title_folder_inbox) { } else if (itemId == R.string.title_folder_inbox) {
onActionMoveSelection(EntityFolder.INBOX); onActionMoveSelection(EntityFolder.INBOX, false);
return true; return true;
} else if (itemId == R.string.title_archive) { } else if (itemId == R.string.title_archive) {
onActionMoveSelection(EntityFolder.ARCHIVE); onActionMoveSelection(EntityFolder.ARCHIVE, false);
return true; return true;
} else if (itemId == R.string.title_spam) { } else if (itemId == R.string.title_spam) {
onActionJunkSelection(); onActionJunkSelection();
return true; return true;
} else if (itemId == R.string.title_trash) { } else if (itemId == R.string.title_trash) {
onActionMoveSelection(EntityFolder.TRASH); onActionMoveSelection(EntityFolder.TRASH, false);
return true; return true;
} else if (itemId == R.string.title_delete_permanently) { } else if (itemId == R.string.title_delete_permanently) {
onActionDeleteSelection( onActionDeleteSelection(
@ -3634,21 +3634,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onActionJunkSelection() { private void onActionJunkSelection() {
int count = selectionTracker.getSelection().size();
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putString("question", getResources() aargs.putInt("count", selectionTracker.getSelection().size());
.getQuantityString(R.plurals.title_ask_spam, count, count));
FragmentDialogAsk ask = new FragmentDialogAsk(); FragmentDialogAskSpam ask = new FragmentDialogAskSpam();
ask.setArguments(aargs); ask.setArguments(aargs);
ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_JUNK); ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_JUNK);
ask.show(getParentFragmentManager(), "messages:junk"); ask.show(getParentFragmentManager(), "messages:junk");
} }
private void onActionMoveSelection(final String type) { private void onActionMoveSelection(final String type, boolean block) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("type", type); args.putString("type", type);
args.putBoolean("block", block);
args.putLongArray("ids", getSelection()); args.putLongArray("ids", getSelection());
new SimpleTask<ArrayList<MessageTarget>>() { new SimpleTask<ArrayList<MessageTarget>>() {
@ -3683,7 +3681,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (sourceFolder == null || sourceFolder.read_only) if (sourceFolder == null || sourceFolder.read_only)
continue; continue;
result.add(new MessageTarget(context, threaded, account, sourceFolder, account, targetFolder)); result.add(new MessageTarget(context, threaded, account, sourceFolder, account, targetFolder)
.setBlock(block));
} }
} }
@ -5503,7 +5502,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (MessageTarget target : targets) for (MessageTarget target : targets)
if (message.id.equals(target.id)) { if (message.id.equals(target.id)) {
Log.i("Eval thread target id=" + target.id); Log.i("Eval thread target id=" + target.id);
if (!target.isAccross()) { if (!target.isAcross()) {
found = true; found = true;
if (target.targetFolder.id == folder) if (target.targetFolder.id == folder)
count++; count++;
@ -5517,7 +5516,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
for (MessageTarget target : mt) for (MessageTarget target : mt)
if (!target.isAccross() && target.targetFolder.id == folder && if (!target.isAcross() && target.targetFolder.id == folder &&
(removed == null || !removed.contains(target.id))) (removed == null || !removed.contains(target.id)))
count++; count++;
@ -5922,6 +5921,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityOperation.queue(context, message, EntityOperation.COPY, target.targetFolder.id); EntityOperation.queue(context, message, EntityOperation.COPY, target.targetFolder.id);
else else
EntityOperation.queue(context, message, EntityOperation.MOVE, target.targetFolder.id); EntityOperation.queue(context, message, EntityOperation.MOVE, target.targetFolder.id);
if (target.block &&
EntityFolder.JUNK.equals(target.targetFolder.type))
EntityContact.update(context,
message.account, message.from,
EntityContact.TYPE_JUNK, message.received);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -6087,7 +6092,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static String getNames(ArrayList<MessageTarget> result, boolean dest) { private static String getNames(ArrayList<MessageTarget> result, boolean dest) {
boolean across = false; boolean across = false;
for (MessageTarget target : result) for (MessageTarget target : result)
if (target.isAccross()) if (target.isAcross())
across = true; across = true;
Map<String, Integer> nameCount = new HashMap<>(); Map<String, Integer> nameCount = new HashMap<>();
@ -6663,7 +6668,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
break; break;
case REQUEST_MESSAGES_JUNK: case REQUEST_MESSAGES_JUNK:
if (resultCode == RESULT_OK) if (resultCode == RESULT_OK)
onActionMoveSelection(EntityFolder.JUNK); onActionMoveSelection(EntityFolder.JUNK,
data.getBundleExtra("args").getBoolean("block"));
break; break;
case REQUEST_ASKED_MOVE: case REQUEST_ASKED_MOVE:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
@ -8044,7 +8050,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private void onMoveAskAcross(final ArrayList<MessageTarget> result) { private void onMoveAskAcross(final ArrayList<MessageTarget> result) {
boolean across = false; boolean across = false;
for (MessageTarget target : result) for (MessageTarget target : result)
if (target.isAccross()) { if (target.isAcross()) {
across = true; across = true;
break; break;
} }
@ -8715,6 +8721,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Account targetAccount; Account targetAccount;
Folder targetFolder; Folder targetFolder;
boolean copy; boolean copy;
boolean block;
MessageTarget(Context context, EntityMessage message, MessageTarget(Context context, EntityMessage message,
EntityAccount sourceAccount, EntityFolder sourceFolder, EntityAccount sourceAccount, EntityFolder sourceFolder,
@ -8731,7 +8738,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return this; return this;
} }
boolean isAccross() { MessageTarget setBlock(boolean block) {
this.block = block;
return this;
}
boolean isAcross() {
return (sourceAccount.id != targetAccount.id); return (sourceAccount.id != targetAccount.id);
} }
@ -8742,6 +8754,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
targetAccount = (Account) in.readSerializable(); targetAccount = (Account) in.readSerializable();
targetFolder = (Folder) in.readSerializable(); targetFolder = (Folder) in.readSerializable();
copy = (in.readInt() != 0); copy = (in.readInt() != 0);
block = (in.readInt() != 0);
} }
@Override @Override
@ -8752,6 +8765,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
dest.writeSerializable(targetAccount); dest.writeSerializable(targetAccount);
dest.writeSerializable(targetFolder); dest.writeSerializable(targetFolder);
dest.writeInt(copy ? 1 : 0); dest.writeInt(copy ? 1 : 0);
dest.writeInt(block ? 1 : 0);
} }
@Override @Override
@ -8798,6 +8812,37 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
public static class FragmentDialogAskSpam extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Bundle args = getArguments();
int count = args.getInt("count");
String text = getResources().getQuantityString(R.plurals.title_ask_spam, count, count);
final Context context = getContext();
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_ask_spam, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
CheckBox cbBlockSender = dview.findViewById(R.id.cbBlockSender);
tvMessage.setText(text);
cbBlockSender.setChecked(true);
return new AlertDialog.Builder(context)
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getArguments().putBoolean("block", cbBlockSender.isChecked());
sendResult(Activity.RESULT_OK);
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
public static class FragmentDialogReporting extends FragmentDialogBase { public static class FragmentDialogReporting extends FragmentDialogBase {
@NonNull @NonNull
@Override @Override

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableStart="@drawable/twotone_report_24"
android:drawablePadding="6dp"
android:drawableTint="?attr/colorWarning"
android:paddingTop="6dp"
android:text="Spam"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbBlockSender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_block_sender"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>
Loading…
Cancel
Save