Browse Source

Finished multiple select

main
M66B 6 years ago
parent
commit
4ae073b939
5 changed files with 174 additions and 44 deletions
  1. +2
    -1
      app/src/main/java/eu/faircode/email/AdapterMessage.java
  2. +136
    -7
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  3. +19
    -2
      app/src/main/java/eu/faircode/email/SelectionPredicateMessage.java
  4. +17
    -11
      app/src/main/res/layout/fragment_messages.xml
  5. +0
    -23
      app/src/main/res/menu/action_multiple.xml

+ 2
- 1
app/src/main/java/eu/faircode/email/AdapterMessage.java View File

@ -1289,8 +1289,9 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
try { try {
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
db.message().setMessageUiHide(id, true);
EntityMessage message = db.message().getMessage(id);
EntityOperation.queue(db, message, EntityOperation.MOVE, target); EntityOperation.queue(db, message, EntityOperation.MOVE, target);
db.setTransactionSuccessful(); db.setTransactionSuccessful();


+ 136
- 7
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -44,13 +44,18 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import java.io.Serializable; import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
@ -61,6 +66,7 @@ import androidx.lifecycle.ViewModelProviders;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.paging.LivePagedListBuilder; import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList; import androidx.paging.PagedList;
import androidx.recyclerview.selection.MutableSelection;
import androidx.recyclerview.selection.SelectionTracker; import androidx.recyclerview.selection.SelectionTracker;
import androidx.recyclerview.selection.StorageStrategy; import androidx.recyclerview.selection.StorageStrategy;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
@ -69,12 +75,12 @@ import androidx.recyclerview.widget.RecyclerView;
public class FragmentMessages extends FragmentEx { public class FragmentMessages extends FragmentEx {
private ViewGroup view; private ViewGroup view;
private View popupAnchor;
private TextView tvSupport; private TextView tvSupport;
private ImageButton ibHintSupport; private ImageButton ibHintSupport;
private ImageButton ibHintActions; private ImageButton ibHintActions;
private TextView tvNoEmail; private TextView tvNoEmail;
private RecyclerView rvMessage; private RecyclerView rvMessage;
private BottomNavigationView multiple;
private BottomNavigationView bottom_navigation; private BottomNavigationView bottom_navigation;
private ProgressBar pbWait; private ProgressBar pbWait;
private Group grpSupport; private Group grpSupport;
@ -82,6 +88,7 @@ public class FragmentMessages extends FragmentEx {
private Group grpHintActions; private Group grpHintActions;
private Group grpReady; private Group grpReady;
private FloatingActionButton fab; private FloatingActionButton fab;
private FloatingActionButton fabMove;
private long folder = -1; private long folder = -1;
private long account = -1; private long account = -1;
@ -144,12 +151,12 @@ public class FragmentMessages extends FragmentEx {
setHasOptionsMenu(true); setHasOptionsMenu(true);
// Get controls // Get controls
popupAnchor = view.findViewById(R.id.popupAnchor);
tvSupport = view.findViewById(R.id.tvSupport); tvSupport = view.findViewById(R.id.tvSupport);
ibHintSupport = view.findViewById(R.id.ibHintSupport); ibHintSupport = view.findViewById(R.id.ibHintSupport);
ibHintActions = view.findViewById(R.id.ibHintActions); ibHintActions = view.findViewById(R.id.ibHintActions);
tvNoEmail = view.findViewById(R.id.tvNoEmail); tvNoEmail = view.findViewById(R.id.tvNoEmail);
rvMessage = view.findViewById(R.id.rvFolder); rvMessage = view.findViewById(R.id.rvFolder);
multiple = view.findViewById(R.id.multiple);
bottom_navigation = view.findViewById(R.id.bottom_navigation); bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
grpSupport = view.findViewById(R.id.grpSupport); grpSupport = view.findViewById(R.id.grpSupport);
@ -157,6 +164,7 @@ public class FragmentMessages extends FragmentEx {
grpHintActions = view.findViewById(R.id.grpHintActions); grpHintActions = view.findViewById(R.id.grpHintActions);
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);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
@ -234,21 +242,24 @@ public class FragmentMessages extends FragmentEx {
}); });
rvMessage.setAdapter(adapter); rvMessage.setAdapter(adapter);
if (viewType == AdapterMessage.ViewType.FOLDER && BuildConfig.DEBUG) {
if (viewType == AdapterMessage.ViewType.FOLDER) {
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())
.withSelectionPredicate(new SelectionPredicateMessage(rvMessage))
.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() {
multiple.setVisibility(selectionTracker.hasSelection() ? View.VISIBLE : View.GONE);
if (selectionTracker.hasSelection())
fabMove.show();
else
fabMove.hide();
} }
}); });
} }
@ -520,14 +531,129 @@ public class FragmentMessages extends FragmentEx {
} }
}); });
fabMove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putLong("folder", folder);
new SimpleTask<List<EntityFolder>>() {
@Override
protected List<EntityFolder> onLoad(Context context, Bundle args) {
long folder = args.getLong("folder");
DB db = DB.getInstance(context);
EntityFolder source = db.folder().getFolder(folder);
List<EntityFolder> folders = db.folder().getFolders(source.account);
List<EntityFolder> targets = new ArrayList<>();
for (EntityFolder f : folders)
if (!f.id.equals(folder) && !EntityFolder.DRAFTS.equals(f.type))
targets.add(f);
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(targets, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = Integer.compare(
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
return targets;
}
@Override
protected void onLoaded(final Bundle args, List<EntityFolder> folders) {
PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor);
int order = 0;
for (EntityFolder folder : folders) {
String name = (folder.display == null
? Helper.localizeFolderName(getContext(), 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) {
MutableSelection<Long> selection = new MutableSelection<>();
selectionTracker.copySelection(selection);
long[] ids = new long[selection.size()];
int i = 0;
for (Long id : selection)
ids[i++] = id;
selectionTracker.clearSelection();
args.putLongArray("ids", ids);
args.putLong("target", target.getItemId());
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long[] ids = args.getLongArray("ids");
long target = args.getLong("target");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (long id : ids) {
db.message().setMessageUiHide(id, true);
EntityMessage message = db.message().getMessage(id);
EntityOperation.queue(db, message, EntityOperation.MOVE, target);
}
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);
return true;
}
});
popupMenu.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), ex);
}
}.load(FragmentMessages.this, args);
}
});
// Initialize // Initialize
tvNoEmail.setVisibility(View.GONE); tvNoEmail.setVisibility(View.GONE);
multiple.setVisibility(View.GONE);
bottom_navigation.setVisibility(View.GONE); bottom_navigation.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
fab.hide(); fab.hide();
fabMove.hide();
return view; return view;
} }
@ -644,7 +770,10 @@ public class FragmentMessages extends FragmentEx {
} }
}); });
multiple.setVisibility(selectionTracker != null && selectionTracker.hasSelection() ? View.VISIBLE : View.GONE);
if (selectionTracker != null && selectionTracker.hasSelection())
fabMove.show();
else
fabMove.hide();
if (viewType == AdapterMessage.ViewType.THREAD) { if (viewType == AdapterMessage.ViewType.THREAD) {
// Navigation // Navigation


+ 19
- 2
app/src/main/java/eu/faircode/email/SelectionPredicateMessage.java View File

@ -1,18 +1,35 @@
package eu.faircode.email; package eu.faircode.email;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.paging.PagedList;
import androidx.recyclerview.selection.SelectionTracker; import androidx.recyclerview.selection.SelectionTracker;
import androidx.recyclerview.widget.RecyclerView;
public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> { public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> {
private RecyclerView recyclerView;
SelectionPredicateMessage(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
}
@Override @Override
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) { public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
return true;
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
if (messages != null)
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i);
if (message != null && message.id.equals(key))
return (message.uid != null);
}
return false;
} }
@Override @Override
public boolean canSetStateAtPosition(int position, boolean nextState) { public boolean canSetStateAtPosition(int position, boolean nextState) {
return true;
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
return (adapter.getCurrentList().get(position).uid != null);
} }
@Override @Override


+ 17
- 11
app/src/main/res/layout/fragment_messages.xml View File

@ -10,6 +10,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<View
android:id="@+id/popupAnchor"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/tvSupport" android:id="@+id/tvSupport"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -164,6 +171,16 @@
app:constraint_referenced_ids="rvFolder" /> app:constraint_referenced_ids="rvFolder" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabMove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_margin="16dp"
android:src="@drawable/baseline_folder_24"
android:tint="@color/colorActionForeground"
app:backgroundTint="?attr/colorAccent" />
<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"
@ -173,15 +190,4 @@
android:src="@drawable/baseline_edit_24" android:src="@drawable/baseline_edit_24"
android:tint="@color/colorActionForeground" android:tint="@color/colorActionForeground"
app:backgroundTint="?attr/colorAccent" /> app:backgroundTint="?attr/colorAccent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/multiple"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
app:itemIconTint="@color/bottomnav_background"
app:itemTextColor="@color/bottomnav_background"
app:labelVisibilityMode="labeled"
app:menu="@menu/action_multiple" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

+ 0
- 23
app/src/main/res/menu/action_multiple.xml View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_junk"
android:icon="@drawable/baseline_report_24"
android:title="@string/title_spam" />
<item
android:id="@+id/action_delete"
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_trash" />
<item
android:id="@+id/action_move"
android:icon="@drawable/baseline_folder_24"
android:title="@string/title_move" />
<item
android:id="@+id/action_archive"
android:icon="@drawable/baseline_archive_24"
android:title="@string/title_archive" />
</menu>

Loading…
Cancel
Save