mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 19:34:15 +01:00
Load IDs from model
This commit is contained in:
@@ -200,17 +200,6 @@ public interface DaoMessage {
|
||||
" ORDER BY message.received DESC")
|
||||
List<Long> getMessageIdsByFolder(Long folder);
|
||||
|
||||
@Query("SELECT message.id" +
|
||||
" FROM message" +
|
||||
" JOIN folder ON folder.id = message.folder" +
|
||||
" WHERE ((:search AND ui_found)" +
|
||||
" OR (NOT :search AND :folder IS NULL AND folder.unified)" +
|
||||
" OR (NOT :search AND folder.id = :folder))" +
|
||||
" AND ui_hide = 0" +
|
||||
" AND (:snoozed OR ui_snoozed IS NULL)" +
|
||||
" ORDER BY message.received DESC")
|
||||
List<Long> getMessageIds(Long folder, boolean search, boolean snoozed);
|
||||
|
||||
@Query("SELECT id" +
|
||||
" FROM message" +
|
||||
" WHERE content" +
|
||||
|
||||
@@ -2605,36 +2605,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
}
|
||||
|
||||
private void onMenuSelectAll() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean snoozed = prefs.getBoolean("snoozed", false);
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", folder);
|
||||
args.putBoolean("search", viewType == AdapterMessage.ViewType.SEARCH);
|
||||
args.putBoolean("snoozed", snoozed);
|
||||
|
||||
new SimpleTask<List<Long>>() {
|
||||
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
|
||||
model.getIds(getContext(), getViewLifecycleOwner(), new Observer<List<Long>>() {
|
||||
@Override
|
||||
protected List<Long> onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean search = args.getBoolean("search");
|
||||
boolean snoozed = args.getBoolean("snoozed");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
return db.message().getMessageIds(id < 0 ? null : id, search, snoozed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, List<Long> ids) {
|
||||
public void onChanged(List<Long> ids) {
|
||||
selectionTracker.clearSelection();
|
||||
for (long id : ids)
|
||||
selectionTracker.select(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(getFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "messages:all");
|
||||
});
|
||||
}
|
||||
|
||||
private void updateState(List<TupleFolderEx> folders) {
|
||||
|
||||
@@ -21,6 +21,7 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -35,9 +36,11 @@ import androidx.lifecycle.ViewModel;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.room.paging.LimitOffsetDataSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -214,7 +217,7 @@ public class ViewModelMessages extends ViewModel {
|
||||
|
||||
Model model = models.get(last);
|
||||
if (model == null) {
|
||||
Log.w("Observe previous/next without list");
|
||||
Log.w("Observe previous/next without model");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -259,6 +262,41 @@ public class ViewModelMessages extends ViewModel {
|
||||
});
|
||||
}
|
||||
|
||||
void getIds(Context context, LifecycleOwner owner, final Observer<List<Long>> observer) {
|
||||
final Model model = models.get(last);
|
||||
if (model == null) {
|
||||
Log.w("Get IDs without model");
|
||||
observer.onChanged(new ArrayList<Long>());
|
||||
return;
|
||||
}
|
||||
|
||||
new SimpleTask<List<Long>>() {
|
||||
@Override
|
||||
protected List<Long> onExecute(Context context, Bundle args) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
|
||||
LimitOffsetDataSource<TupleMessageEx> ds = (LimitOffsetDataSource<TupleMessageEx>) model.list.getValue().getDataSource();
|
||||
int count = ds.countItems();
|
||||
for (int i = 0; i < count; i += 100)
|
||||
for (TupleMessageEx message : ds.loadRange(i, Math.min(100, count - i)))
|
||||
ids.add(message.id);
|
||||
|
||||
Log.i("Loaded messages #" + ids.size());
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, List<Long> ids) {
|
||||
observer.onChanged(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
observer.onChanged(new ArrayList<Long>());
|
||||
}
|
||||
}.execute(context, owner, new Bundle(), "model:ids");
|
||||
}
|
||||
|
||||
private class Args {
|
||||
private long account;
|
||||
private String type;
|
||||
|
||||
Reference in New Issue
Block a user