Monitor deleted selected messages

pull/180/head
M66B 4 years ago
parent 8a5dafc1fd
commit 19757af886

@ -130,6 +130,7 @@ import androidx.paging.AsyncPagedListDiffer;
import androidx.paging.PagedList;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.selection.ItemDetailsLookup;
import androidx.recyclerview.selection.Selection;
import androidx.recyclerview.selection.SelectionTracker;
import androidx.recyclerview.widget.AdapterListUpdateCallback;
import androidx.recyclerview.widget.AsyncDifferConfig;
@ -5143,6 +5144,46 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
gotoTop = false;
properties.scrollTo(0, 0);
}
if (selectionTracker != null && selectionTracker.hasSelection()) {
Selection<Long> selection = selectionTracker.getSelection();
long[] ids = new long[selection.size()];
int i = 0;
for (Long id : selection)
ids[i++] = id;
Bundle args = new Bundle();
args.putLongArray("ids", ids);
new SimpleTask<List<Long>>() {
@Override
protected List<Long> onExecute(Context context, Bundle args) throws Throwable {
long[] ids = args.getLongArray("ids");
List<Long> removed = new ArrayList<>();
DB db = DB.getInstance(context);
for (long id : ids)
if (db.message().countVisible(id) == 0)
removed.add(id);
return removed;
}
@Override
protected void onExecuted(Bundle args, List<Long> removed) {
Log.i("Selection removed=" + removed.size());
for (long id : removed)
selectionTracker.deselect(id);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "selection:update");
}
}
});

@ -244,13 +244,6 @@ public interface DaoMessage {
" GROUP BY account.id")
LiveData<TupleThreadStats> liveThreadStats(long account, String thread, Long id, boolean filter_archive);
@Query("SELECT message.id FROM folder" +
" JOIN message ON message.folder = folder.id" +
" WHERE ((:folder IS NULL AND :type IS NULL AND folder.unified)" +
" OR folder.type = :type OR folder.id = :folder)" +
" AND ui_hide")
LiveData<List<Long>> liveHiddenFolder(Long folder, String type);
@Query("SELECT id FROM message" +
" WHERE account = :account" +
" AND thread = :thread" +
@ -366,6 +359,10 @@ public interface DaoMessage {
" AND msgid = :msgid")
int countMessageByMsgId(long folder, String msgid);
@Query("SELECT COUNT(*) FROM message" +
" WHERE id = :id AND NOT ui_hide")
int countVisible(long id);
@Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, identity.color AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +

@ -3111,14 +3111,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
updateState(folders);
}
});
db.message().liveHiddenFolder(null, type).observe(getViewLifecycleOwner(), new Observer<List<Long>>() {
@Override
public void onChanged(List<Long> ids) {
if (ids != null && selectionTracker != null)
for (long id : ids)
selectionTracker.deselect(id);
}
});
break;
case FOLDER:
@ -3132,14 +3124,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
updateState(folders);
}
});
db.message().liveHiddenFolder(folder, null).observe(getViewLifecycleOwner(), new Observer<List<Long>>() {
@Override
public void onChanged(List<Long> ids) {
if (ids != null && selectionTracker != null)
for (long id : ids)
selectionTracker.deselect(id);
}
});
break;
case THREAD:

Loading…
Cancel
Save