mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-04 03:43:55 +01:00
Allow multiple select for same account in unified inbox
This commit is contained in:
@@ -132,7 +132,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|||||||
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L;
|
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L;
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements
|
public class ViewHolder extends RecyclerView.ViewHolder implements
|
||||||
View.OnClickListener, View.OnLongClickListener, BottomNavigationView.OnNavigationItemSelectedListener {
|
View.OnClickListener, BottomNavigationView.OnNavigationItemSelectedListener {
|
||||||
private View itemView;
|
private View itemView;
|
||||||
private View vwColor;
|
private View vwColor;
|
||||||
private ImageView ivExpander;
|
private ImageView ivExpander;
|
||||||
@@ -181,10 +181,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|||||||
|
|
||||||
private ItemDetailsMessage itemDetails = null;
|
private ItemDetailsMessage itemDetails = null;
|
||||||
|
|
||||||
private final static int action_seen = 1;
|
|
||||||
private final static int action_unseen = 2;
|
|
||||||
private final static int action_move = 3;
|
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
@@ -248,9 +244,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|||||||
|
|
||||||
private void wire() {
|
private void wire() {
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
if (viewType == ViewType.UNIFIED)
|
|
||||||
itemView.setOnLongClickListener(this);
|
|
||||||
|
|
||||||
ivExpanderAddress.setOnClickListener(this);
|
ivExpanderAddress.setOnClickListener(this);
|
||||||
ivAddContact.setOnClickListener(this);
|
ivAddContact.setOnClickListener(this);
|
||||||
btnHtml.setOnClickListener(this);
|
btnHtml.setOnClickListener(this);
|
||||||
@@ -261,9 +254,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|||||||
|
|
||||||
private void unwire() {
|
private void unwire() {
|
||||||
itemView.setOnClickListener(null);
|
itemView.setOnClickListener(null);
|
||||||
if (viewType == ViewType.UNIFIED)
|
|
||||||
itemView.setOnLongClickListener(null);
|
|
||||||
|
|
||||||
ivExpanderAddress.setOnClickListener(null);
|
ivExpanderAddress.setOnClickListener(null);
|
||||||
ivAddContact.setOnClickListener(null);
|
ivAddContact.setOnClickListener(null);
|
||||||
btnHtml.setOnClickListener(null);
|
btnHtml.setOnClickListener(null);
|
||||||
@@ -559,171 +549,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onLongClick(View v) {
|
|
||||||
int pos = getAdapterPosition();
|
|
||||||
if (pos == RecyclerView.NO_POSITION)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
final TupleMessageEx message = getItem(pos);
|
|
||||||
|
|
||||||
PopupMenu popupMenu = new PopupMenu(context, itemView);
|
|
||||||
|
|
||||||
if (message.ui_seen)
|
|
||||||
popupMenu.getMenu().add(Menu.NONE, action_unseen, 1, R.string.title_unseen);
|
|
||||||
else
|
|
||||||
popupMenu.getMenu().add(Menu.NONE, action_seen, 1, R.string.title_seen);
|
|
||||||
|
|
||||||
popupMenu.getMenu().add(Menu.NONE, action_move, 2, R.string.title_move);
|
|
||||||
|
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem target) {
|
|
||||||
switch (target.getItemId()) {
|
|
||||||
case action_seen:
|
|
||||||
onActionSeen(true);
|
|
||||||
return true;
|
|
||||||
case action_unseen:
|
|
||||||
onActionSeen(false);
|
|
||||||
return true;
|
|
||||||
case action_move:
|
|
||||||
onActionMove();
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onActionSeen(boolean seen) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putLong("account", message.account);
|
|
||||||
args.putString("thread", message.thread);
|
|
||||||
args.putBoolean("found", message.ui_found);
|
|
||||||
args.putBoolean("seen", seen);
|
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
|
||||||
@Override
|
|
||||||
protected Void onLoad(Context context, Bundle args) throws Throwable {
|
|
||||||
long account = args.getLong("account");
|
|
||||||
String thread = args.getString("thread");
|
|
||||||
boolean found = args.getBoolean("found");
|
|
||||||
boolean seen = args.getBoolean("seen");
|
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
|
||||||
try {
|
|
||||||
db.beginTransaction();
|
|
||||||
|
|
||||||
List<EntityMessage> messages = db.message().getMessageByThread(account, thread, found);
|
|
||||||
for (EntityMessage message : messages) {
|
|
||||||
db.message().setMessageUiSeen(message.id, seen);
|
|
||||||
db.message().setMessageUiIgnored(message.id, true);
|
|
||||||
EntityOperation.queue(db, message, EntityOperation.SEEN, seen);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityOperation.process(context);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.load(context, owner, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onActionMove() {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putSerializable("message", message);
|
|
||||||
|
|
||||||
new SimpleTask<List<EntityFolder>>() {
|
|
||||||
@Override
|
|
||||||
protected List<EntityFolder> onLoad(Context context, Bundle args) {
|
|
||||||
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
|
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
|
||||||
|
|
||||||
List<EntityFolder> folders = db.folder().getFolders(message.account);
|
|
||||||
List<EntityFolder> targets = new ArrayList<>();
|
|
||||||
for (EntityFolder f : folders)
|
|
||||||
if (!f.unified && !EntityFolder.DRAFTS.equals(f.type))
|
|
||||||
targets.add(f);
|
|
||||||
|
|
||||||
EntityFolder.sort(targets);
|
|
||||||
|
|
||||||
return targets;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLoaded(final Bundle args, List<EntityFolder> folders) {
|
|
||||||
PopupMenu popupMenu = new PopupMenu(context, itemView);
|
|
||||||
|
|
||||||
int order = 0;
|
|
||||||
for (EntityFolder folder : folders) {
|
|
||||||
String name = (folder.display == null
|
|
||||||
? Helper.localizeFolderName(context, folder.name)
|
|
||||||
: folder.display);
|
|
||||||
popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(final MenuItem target) {
|
|
||||||
args.putLong("target", target.getItemId());
|
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
|
||||||
@Override
|
|
||||||
protected Void onLoad(Context context, Bundle args) {
|
|
||||||
long target = args.getLong("target");
|
|
||||||
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
|
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
|
||||||
try {
|
|
||||||
db.beginTransaction();
|
|
||||||
|
|
||||||
List<EntityMessage> messages = db.message().getMessageByThread(
|
|
||||||
message.account, message.thread, message.ui_found);
|
|
||||||
for (EntityMessage threaded : messages) {
|
|
||||||
db.message().setMessageUiHide(threaded.id, true);
|
|
||||||
EntityOperation.queue(db, threaded, EntityOperation.MOVE, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityOperation.process(context);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onException(Bundle args, Throwable ex) {
|
|
||||||
Helper.unexpectedError(context, ex);
|
|
||||||
}
|
|
||||||
}.load(context, owner, args);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
popupMenu.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onException(Bundle args, Throwable ex) {
|
|
||||||
Helper.unexpectedError(context, ex);
|
|
||||||
}
|
|
||||||
}.load(context, owner, args);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
popupMenu.show();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onAddContact(TupleMessageEx message) {
|
private void onAddContact(TupleMessageEx message) {
|
||||||
for (Address address : message.from) {
|
for (Address address : message.from) {
|
||||||
InternetAddress ia = (InternetAddress) address;
|
InternetAddress ia = (InternetAddress) address;
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
private Group grpHintSelect;
|
private Group grpHintSelect;
|
||||||
private Group grpReady;
|
private Group grpReady;
|
||||||
private FloatingActionButton fab;
|
private FloatingActionButton fab;
|
||||||
private FloatingActionButton fabMove;
|
private FloatingActionButton fabMore;
|
||||||
private FloatingActionButton fabDelete;
|
|
||||||
|
|
||||||
private long folder = -1;
|
private long folder = -1;
|
||||||
private long account = -1;
|
private long account = -1;
|
||||||
@@ -175,8 +174,7 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
grpHintSelect = view.findViewById(R.id.grpHintSelect);
|
grpHintSelect = view.findViewById(R.id.grpHintSelect);
|
||||||
grpReady = view.findViewById(R.id.grpReady);
|
grpReady = view.findViewById(R.id.grpReady);
|
||||||
fab = view.findViewById(R.id.fab);
|
fab = view.findViewById(R.id.fab);
|
||||||
fabMove = view.findViewById(R.id.fabMove);
|
fabMore = view.findViewById(R.id.fabMore);
|
||||||
fabDelete = view.findViewById(R.id.fabDelete);
|
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
|
||||||
@@ -327,26 +325,27 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
|
|
||||||
rvMessage.setAdapter(adapter);
|
rvMessage.setAdapter(adapter);
|
||||||
|
|
||||||
if (viewType == AdapterMessage.ViewType.FOLDER) {
|
if (viewType != AdapterMessage.ViewType.THREAD) {
|
||||||
|
final SelectionPredicateMessage predicate = new SelectionPredicateMessage(rvMessage);
|
||||||
|
|
||||||
selectionTracker = new SelectionTracker.Builder<>(
|
selectionTracker = new SelectionTracker.Builder<>(
|
||||||
"messages-selection",
|
"messages-selection",
|
||||||
rvMessage,
|
rvMessage,
|
||||||
new ItemKeyProviderMessage(rvMessage),
|
new ItemKeyProviderMessage(rvMessage),
|
||||||
new ItemDetailsLookupMessage(rvMessage),
|
new ItemDetailsLookupMessage(rvMessage),
|
||||||
StorageStrategy.createLongStorage())
|
StorageStrategy.createLongStorage())
|
||||||
.withSelectionPredicate(new SelectionPredicateMessage(rvMessage))
|
.withSelectionPredicate(predicate)
|
||||||
.build();
|
.build();
|
||||||
adapter.setSelectionTracker(selectionTracker);
|
adapter.setSelectionTracker(selectionTracker);
|
||||||
|
|
||||||
selectionTracker.addObserver(new SelectionTracker.SelectionObserver() {
|
selectionTracker.addObserver(new SelectionTracker.SelectionObserver() {
|
||||||
@Override
|
@Override
|
||||||
public void onSelectionChanged() {
|
public void onSelectionChanged() {
|
||||||
if (selectionTracker.hasSelection()) {
|
if (selectionTracker.hasSelection())
|
||||||
fabMove.show();
|
fabMore.show();
|
||||||
fabDelete.show();
|
else {
|
||||||
} else {
|
fabMore.hide();
|
||||||
fabMove.hide();
|
predicate.clearAccount();
|
||||||
fabDelete.hide();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -548,24 +547,148 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fabMove.setOnClickListener(new View.OnClickListener() {
|
fabMore.setOnClickListener(new View.OnClickListener() {
|
||||||
|
private final int action_seen = 1;
|
||||||
|
private final int action_unseen = 2;
|
||||||
|
private final int action_move = 3;
|
||||||
|
private final int action_trash = 4;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
args.putLongArray("ids", getSelection());
|
||||||
|
|
||||||
|
new SimpleTask<Integer[]>() {
|
||||||
|
@Override
|
||||||
|
protected Integer[] onLoad(Context context, Bundle args) {
|
||||||
|
long[] ids = args.getLongArray("ids");
|
||||||
|
|
||||||
|
Integer[] result = new Integer[2];
|
||||||
|
result[0] = 0;
|
||||||
|
result[1] = 0;
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
|
||||||
|
for (Long id : ids) {
|
||||||
|
EntityMessage message = db.message().getMessage(id);
|
||||||
|
result[message.ui_seen ? 1 : 0]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLoaded(Bundle args, Integer[] result) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(getContext(), fabMore);
|
||||||
|
|
||||||
|
if (result[0] > 0)
|
||||||
|
popupMenu.getMenu().add(Menu.NONE, action_seen, 1, R.string.title_seen);
|
||||||
|
if (result[1] > 0)
|
||||||
|
popupMenu.getMenu().add(Menu.NONE, action_unseen, 2, R.string.title_unseen);
|
||||||
|
popupMenu.getMenu().add(Menu.NONE, action_move, 3, R.string.title_move);
|
||||||
|
popupMenu.getMenu().add(Menu.NONE, action_trash, 4, R.string.title_trash);
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem target) {
|
||||||
|
switch (target.getItemId()) {
|
||||||
|
case action_seen:
|
||||||
|
onActionSeen(true);
|
||||||
|
return true;
|
||||||
|
case action_unseen:
|
||||||
|
onActionSeen(false);
|
||||||
|
return true;
|
||||||
|
case action_move:
|
||||||
|
onActionMove();
|
||||||
|
return true;
|
||||||
|
case action_trash:
|
||||||
|
onActionDelete();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
}.load(FragmentMessages.this, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long[] getSelection() {
|
||||||
|
MutableSelection<Long> selection = new MutableSelection<>();
|
||||||
|
selectionTracker.copySelection(selection);
|
||||||
|
|
||||||
|
long[] ids = new long[selection.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (Long id : selection)
|
||||||
|
ids[i++] = id;
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onActionSeen(boolean seen) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLongArray("ids", getSelection());
|
||||||
|
args.putBoolean("seen", seen);
|
||||||
|
|
||||||
|
selectionTracker.clearSelection();
|
||||||
|
|
||||||
|
new SimpleTask<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void onLoad(Context context, Bundle args) {
|
||||||
|
long[] ids = args.getLongArray("ids");
|
||||||
|
boolean seen = args.getBoolean("seen");
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
try {
|
||||||
|
db.beginTransaction();
|
||||||
|
|
||||||
|
for (long id : ids) {
|
||||||
|
EntityMessage message = db.message().getMessage(id);
|
||||||
|
db.message().setMessageUiSeen(message.id, seen);
|
||||||
|
db.message().setMessageUiIgnored(message.id, true);
|
||||||
|
EntityOperation.queue(db, message, EntityOperation.SEEN, seen);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOperation.process(context);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
Helper.unexpectedError(getContext(), ex);
|
||||||
|
}
|
||||||
|
}.load(FragmentMessages.this, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onActionMove() {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLongArray("ids", getSelection());
|
||||||
args.putLong("folder", folder);
|
args.putLong("folder", folder);
|
||||||
|
|
||||||
new SimpleTask<List<EntityFolder>>() {
|
new SimpleTask<List<EntityFolder>>() {
|
||||||
@Override
|
@Override
|
||||||
protected List<EntityFolder> onLoad(Context context, Bundle args) {
|
protected List<EntityFolder> onLoad(Context context, Bundle args) {
|
||||||
long folder = args.getLong("folder");
|
long[] ids = args.getLongArray("ids");
|
||||||
|
long fid = args.getLong("folder");
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
|
|
||||||
EntityFolder source = db.folder().getFolder(folder);
|
EntityMessage message = db.message().getMessage(ids[0]);
|
||||||
List<EntityFolder> folders = db.folder().getFolders(source.account);
|
List<EntityFolder> folders = db.folder().getFolders(message.account);
|
||||||
|
|
||||||
List<EntityFolder> targets = new ArrayList<>();
|
List<EntityFolder> targets = new ArrayList<>();
|
||||||
for (EntityFolder f : folders)
|
for (EntityFolder folder : folders)
|
||||||
if (!f.id.equals(folder) && !EntityFolder.DRAFTS.equals(f.type))
|
if (!EntityFolder.DRAFTS.equals(folder.type))
|
||||||
targets.add(f);
|
if (fid < 0 ? !folder.unified : !folder.id.equals(fid))
|
||||||
|
targets.add(folder);
|
||||||
|
|
||||||
EntityFolder.sort(targets);
|
EntityFolder.sort(targets);
|
||||||
|
|
||||||
@@ -587,19 +710,10 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(final MenuItem target) {
|
public boolean onMenuItemClick(final MenuItem target) {
|
||||||
MutableSelection<Long> selection = new MutableSelection<>();
|
args.putLong("target", target.getItemId());
|
||||||
selectionTracker.copySelection(selection);
|
|
||||||
|
|
||||||
long[] ids = new long[selection.size()];
|
|
||||||
int i = 0;
|
|
||||||
for (Long id : selection)
|
|
||||||
ids[i++] = id;
|
|
||||||
|
|
||||||
selectionTracker.clearSelection();
|
selectionTracker.clearSelection();
|
||||||
|
|
||||||
args.putLongArray("ids", ids);
|
|
||||||
args.putLong("target", target.getItemId());
|
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
new SimpleTask<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void onLoad(Context context, Bundle args) {
|
protected Void onLoad(Context context, Bundle args) {
|
||||||
@@ -651,29 +765,18 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
}
|
}
|
||||||
}.load(FragmentMessages.this, args);
|
}.load(FragmentMessages.this, args);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
fabDelete.setOnClickListener(new View.OnClickListener() {
|
private void onActionDelete() {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
||||||
.setMessage(R.string.title_ask_delete_selected)
|
.setMessage(R.string.title_ask_delete_selected)
|
||||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
MutableSelection<Long> selection = new MutableSelection<>();
|
args.putLongArray("ids", getSelection());
|
||||||
selectionTracker.copySelection(selection);
|
|
||||||
|
|
||||||
long[] ids = new long[selection.size()];
|
|
||||||
int i = 0;
|
|
||||||
for (Long id : selection)
|
|
||||||
ids[i++] = id;
|
|
||||||
|
|
||||||
selectionTracker.clearSelection();
|
selectionTracker.clearSelection();
|
||||||
|
|
||||||
args.putLongArray("ids", ids);
|
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
new SimpleTask<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void onLoad(Context context, Bundle args) {
|
protected Void onLoad(Context context, Bundle args) {
|
||||||
@@ -724,8 +827,7 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
pbWait.setVisibility(View.VISIBLE);
|
pbWait.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
fab.hide();
|
fab.hide();
|
||||||
fabMove.hide();
|
fabMore.hide();
|
||||||
fabDelete.hide();
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@@ -850,9 +952,9 @@ public class FragmentMessages extends FragmentEx {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (selectionTracker != null && selectionTracker.hasSelection())
|
if (selectionTracker != null && selectionTracker.hasSelection())
|
||||||
fabMove.show();
|
fabMore.show();
|
||||||
else
|
else
|
||||||
fabMove.hide();
|
fabMore.hide();
|
||||||
|
|
||||||
if (viewType == AdapterMessage.ViewType.THREAD)
|
if (viewType == AdapterMessage.ViewType.THREAD)
|
||||||
db.folder().liveSystemFolders(account).observe(getViewLifecycleOwner(), new Observer<List<EntityFolder>>() {
|
db.folder().liveSystemFolders(account).observe(getViewLifecycleOwner(), new Observer<List<EntityFolder>>() {
|
||||||
|
|||||||
@@ -25,13 +25,17 @@ import androidx.recyclerview.selection.SelectionTracker;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> {
|
public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> {
|
||||||
|
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
|
private long account = -1;
|
||||||
|
|
||||||
SelectionPredicateMessage(RecyclerView recyclerView) {
|
SelectionPredicateMessage(RecyclerView recyclerView) {
|
||||||
this.recyclerView = recyclerView;
|
this.recyclerView = recyclerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearAccount() {
|
||||||
|
account = -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
||||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
@@ -39,8 +43,13 @@ public class SelectionPredicateMessage extends SelectionTracker.SelectionPredica
|
|||||||
if (messages != null)
|
if (messages != null)
|
||||||
for (int i = 0; i < messages.size(); i++) {
|
for (int i = 0; i < messages.size(); i++) {
|
||||||
TupleMessageEx message = messages.get(i);
|
TupleMessageEx message = messages.get(i);
|
||||||
if (message != null && message.id.equals(key))
|
if (message != null && message.id.equals(key)) {
|
||||||
return (message.uid != null);
|
if (message.uid != null && (account < 0 || account == message.account)) {
|
||||||
|
account = message.account;
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -48,7 +57,15 @@ public class SelectionPredicateMessage extends SelectionTracker.SelectionPredica
|
|||||||
@Override
|
@Override
|
||||||
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
||||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
return (adapter.getCurrentList().get(position).uid != null);
|
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
||||||
|
if (messages != null) {
|
||||||
|
TupleMessageEx message = messages.get(position);
|
||||||
|
if (message.uid != null && (account < 0 || account == message.account)) {
|
||||||
|
account = message.account;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -209,34 +209,15 @@
|
|||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fabMove"
|
android:id="@+id/fabMore"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end|center_vertical"
|
android:layout_gravity="end|center_vertical"
|
||||||
android:layout_margin="@dimen/fab_padding"
|
android:layout_margin="@dimen/fab_padding"
|
||||||
android:src="@drawable/baseline_folder_24"
|
android:src="@drawable/baseline_more_vert_24"
|
||||||
android:tint="@color/colorActionForeground"
|
android:tint="@color/colorActionForeground"
|
||||||
app:backgroundTint="?attr/colorSeparator" />
|
app:backgroundTint="?attr/colorSeparator" />
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/fabAnchor"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="15dp"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
app:layout_anchor="@+id/fabMove"
|
|
||||||
app:layout_anchorGravity="bottom" />
|
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/fabDelete"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:src="@drawable/baseline_delete_24"
|
|
||||||
android:tint="@color/colorActionForeground"
|
|
||||||
app:backgroundTint="?attr/colorSeparator"
|
|
||||||
app:layout_anchor="@+id/fabAnchor"
|
|
||||||
app:layout_anchorGravity="bottom" />
|
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user