Added search for sender for single selected message

pull/207/head
M66B 3 years ago
parent 5100c1a41c
commit 46922da9f8

@ -4489,71 +4489,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void onSearchContact(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<Address[]>() {
@Override
protected Address[] onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityFolder folder = db.folder().getFolder(message.folder);
if (folder == null)
return null;
boolean ingoing = false;
boolean outgoing = EntityFolder.isOutgoing(folder.type);
if (message.identity != null) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity == null)
return null;
if (message.to != null)
for (Address recipient : message.to)
if (identity.similarAddress(recipient)) {
ingoing = true;
break;
}
if (message.from != null)
for (Address sender : message.from)
if (identity.similarAddress(sender)) {
outgoing = true;
break;
}
}
if (outgoing && ingoing && message.reply != null)
return message.reply;
return (outgoing ? message.to : message.from);
}
@Override
protected void onExecuted(Bundle args, Address[] addresses) {
if (addresses == null || addresses.length == 0)
return;
String query = ((InternetAddress) addresses[0]).getAddress();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_SEARCH_ADDRESS)
.putExtra("account", -1L)
.putExtra("folder", -1L)
.putExtra("query", query));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "message:search");
FragmentMessages.searchSender(context, owner, parentFragment.getParentFragmentManager(), message.id);
}
@TargetApi(Build.VERSION_CODES.O)

@ -3453,6 +3453,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
popupMenu.getMenu().add(Menu.FIRST, R.string.title_copy_to, order++, R.string.title_copy_to)
.setIcon(R.drawable.twotone_file_copy_24);
if (ids.length == 1)
popupMenu.getMenu().add(Menu.FIRST, R.string.title_search_sender, order++, R.string.title_search_sender)
.setIcon(R.drawable.twotone_search_24);
popupMenu.insertIcons(context);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@ -3519,6 +3523,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} else if (itemId == R.string.title_copy_to) {
onActionMoveSelectionAccount(result.copyto.id, true, result.folders);
return true;
} else if (itemId == R.string.title_search_sender) {
long[] ids = getSelection();
if (ids.length != 1)
return false;
searchSender(getContext(), getViewLifecycleOwner(), getParentFragmentManager(), ids[0]);
return true;
}
return false;
}
@ -9307,6 +9317,74 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fragmentTransaction.commit();
}
static void searchSender(Context context, LifecycleOwner owner, FragmentManager fm, long message) {
Bundle args = new Bundle();
args.putLong("id", message);
new SimpleTask<Address[]>() {
@Override
protected Address[] onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityFolder folder = db.folder().getFolder(message.folder);
if (folder == null)
return null;
boolean ingoing = false;
boolean outgoing = EntityFolder.isOutgoing(folder.type);
if (message.identity != null) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity == null)
return null;
if (message.to != null)
for (Address recipient : message.to)
if (identity.similarAddress(recipient)) {
ingoing = true;
break;
}
if (message.from != null)
for (Address sender : message.from)
if (identity.similarAddress(sender)) {
outgoing = true;
break;
}
}
if (outgoing && ingoing && message.reply != null)
return message.reply;
return (outgoing ? message.to : message.from);
}
@Override
protected void onExecuted(Bundle args, Address[] addresses) {
if (addresses == null || addresses.length == 0)
return;
String query = ((InternetAddress) addresses[0]).getAddress();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_SEARCH_ADDRESS)
.putExtra("account", -1L)
.putExtra("folder", -1L)
.putExtra("query", query));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(fm, ex);
}
}.execute(context, owner, args, "message:search");
}
private static class ActionData {
private boolean delete; // Selects action
private boolean forever; // Selects icon

@ -82,8 +82,8 @@
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_legend_similar"
android:tooltipText="@string/title_legend_similar"
android:contentDescription="@string/title_search_sender"
android:tooltipText="@string/title_search_sender"
app:layout_constraintEnd_toStartOf="@+id/ibNotifyContact"
app:layout_constraintTop_toBottomOf="@id/ibExpanderAddress"
app:srcCompat="@drawable/twotone_search_24" />

@ -244,10 +244,10 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_search"
android:contentDescription="@string/title_search_sender"
android:padding="6dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_search"
android:tooltipText="@string/title_search_sender"
app:srcCompat="@drawable/twotone_search_24"
tools:ignore="MissingConstraints" />

@ -1503,6 +1503,7 @@
<string name="title_search_device">Search on device</string>
<string name="title_search_server">Search on server</string>
<string name="title_search_in">Search in</string>
<string name="title_search_sender">Search for sender</string>
<string name="title_search_delete">Delete saved search?</string>

Loading…
Cancel
Save