mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-31 20:25:38 +00:00
Bulk block senders
This commit is contained in:
parent
ffbc591684
commit
4bf24baf5e
2 changed files with 99 additions and 16 deletions
|
@ -3249,16 +3249,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
onActionRaw();
|
||||
return true;
|
||||
} else if (itemId == R.string.title_folder_inbox) {
|
||||
onActionMoveSelection(EntityFolder.INBOX);
|
||||
onActionMoveSelection(EntityFolder.INBOX, false);
|
||||
return true;
|
||||
} else if (itemId == R.string.title_archive) {
|
||||
onActionMoveSelection(EntityFolder.ARCHIVE);
|
||||
onActionMoveSelection(EntityFolder.ARCHIVE, false);
|
||||
return true;
|
||||
} else if (itemId == R.string.title_spam) {
|
||||
onActionJunkSelection();
|
||||
return true;
|
||||
} else if (itemId == R.string.title_trash) {
|
||||
onActionMoveSelection(EntityFolder.TRASH);
|
||||
onActionMoveSelection(EntityFolder.TRASH, false);
|
||||
return true;
|
||||
} else if (itemId == R.string.title_delete_permanently) {
|
||||
onActionDeleteSelection(
|
||||
|
@ -3634,21 +3634,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}
|
||||
|
||||
private void onActionJunkSelection() {
|
||||
int count = selectionTracker.getSelection().size();
|
||||
|
||||
Bundle aargs = new Bundle();
|
||||
aargs.putString("question", getResources()
|
||||
.getQuantityString(R.plurals.title_ask_spam, count, count));
|
||||
aargs.putInt("count", selectionTracker.getSelection().size());
|
||||
|
||||
FragmentDialogAsk ask = new FragmentDialogAsk();
|
||||
FragmentDialogAskSpam ask = new FragmentDialogAskSpam();
|
||||
ask.setArguments(aargs);
|
||||
ask.setTargetFragment(FragmentMessages.this, REQUEST_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();
|
||||
args.putString("type", type);
|
||||
args.putBoolean("block", block);
|
||||
args.putLongArray("ids", getSelection());
|
||||
|
||||
new SimpleTask<ArrayList<MessageTarget>>() {
|
||||
|
@ -3683,7 +3681,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
if (sourceFolder == null || sourceFolder.read_only)
|
||||
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)
|
||||
if (message.id.equals(target.id)) {
|
||||
Log.i("Eval thread target id=" + target.id);
|
||||
if (!target.isAccross()) {
|
||||
if (!target.isAcross()) {
|
||||
found = true;
|
||||
if (target.targetFolder.id == folder)
|
||||
count++;
|
||||
|
@ -5517,7 +5516,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}
|
||||
|
||||
for (MessageTarget target : mt)
|
||||
if (!target.isAccross() && target.targetFolder.id == folder &&
|
||||
if (!target.isAcross() && target.targetFolder.id == folder &&
|
||||
(removed == null || !removed.contains(target.id)))
|
||||
count++;
|
||||
|
||||
|
@ -5922,6 +5921,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
EntityOperation.queue(context, message, EntityOperation.COPY, target.targetFolder.id);
|
||||
else
|
||||
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();
|
||||
|
@ -6087,7 +6092,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
private static String getNames(ArrayList<MessageTarget> result, boolean dest) {
|
||||
boolean across = false;
|
||||
for (MessageTarget target : result)
|
||||
if (target.isAccross())
|
||||
if (target.isAcross())
|
||||
across = true;
|
||||
|
||||
Map<String, Integer> nameCount = new HashMap<>();
|
||||
|
@ -6663,7 +6668,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
break;
|
||||
case REQUEST_MESSAGES_JUNK:
|
||||
if (resultCode == RESULT_OK)
|
||||
onActionMoveSelection(EntityFolder.JUNK);
|
||||
onActionMoveSelection(EntityFolder.JUNK,
|
||||
data.getBundleExtra("args").getBoolean("block"));
|
||||
break;
|
||||
case REQUEST_ASKED_MOVE:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
|
@ -8044,7 +8050,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
private void onMoveAskAcross(final ArrayList<MessageTarget> result) {
|
||||
boolean across = false;
|
||||
for (MessageTarget target : result)
|
||||
if (target.isAccross()) {
|
||||
if (target.isAcross()) {
|
||||
across = true;
|
||||
break;
|
||||
}
|
||||
|
@ -8715,6 +8721,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
Account targetAccount;
|
||||
Folder targetFolder;
|
||||
boolean copy;
|
||||
boolean block;
|
||||
|
||||
MessageTarget(Context context, EntityMessage message,
|
||||
EntityAccount sourceAccount, EntityFolder sourceFolder,
|
||||
|
@ -8731,7 +8738,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
return this;
|
||||
}
|
||||
|
||||
boolean isAccross() {
|
||||
MessageTarget setBlock(boolean block) {
|
||||
this.block = block;
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean isAcross() {
|
||||
return (sourceAccount.id != targetAccount.id);
|
||||
}
|
||||
|
||||
|
@ -8742,6 +8754,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
targetAccount = (Account) in.readSerializable();
|
||||
targetFolder = (Folder) in.readSerializable();
|
||||
copy = (in.readInt() != 0);
|
||||
block = (in.readInt() != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8752,6 +8765,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
dest.writeSerializable(targetAccount);
|
||||
dest.writeSerializable(targetFolder);
|
||||
dest.writeInt(copy ? 1 : 0);
|
||||
dest.writeInt(block ? 1 : 0);
|
||||
}
|
||||
|
||||
@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 {
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
38
app/src/main/res/layout/dialog_ask_spam.xml
Normal file
38
app/src/main/res/layout/dialog_ask_spam.xml
Normal file
|
@ -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…
Reference in a new issue