diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 7da81e0eb6..1cd885f082 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 2551904e65..4938018293 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -79,6 +79,7 @@ dependencies { implementation "androidx.appcompat:appcompat:$androidx_version" implementation "androidx.recyclerview:recyclerview:$androidx_version" + implementation "androidx.recyclerview:recyclerview-selection:$androidx_version" implementation "com.google.android.material:material:$androidx_version" implementation "androidx.browser:browser:$androidx_version" implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version" diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index eb0074b97d..fa1445186c 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.graphics.Typeface; import android.preference.PreferenceManager; import android.text.format.DateUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -41,6 +42,8 @@ import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.Observer; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.paging.PagedListAdapter; +import androidx.recyclerview.selection.ItemDetailsLookup; +import androidx.recyclerview.selection.SelectionTracker; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -48,6 +51,7 @@ public class AdapterMessage extends PagedListAdaptercreateSelectAnything()) + .withOnDragInitiatedListener(new OnDragInitiatedListener() { + @Override + public boolean onDragInitiated(@NonNull MotionEvent e) { + Log.i(Helper.TAG, "onDragInitiated"); + return true; + } + }).build(); + + + adapter.setSelectionTracker(selectionTracker); + + selectionTracker.addObserver(new SelectionTracker.SelectionObserver() { + @Override + public void onItemStateChanged(@NonNull Object key, boolean selected) { + Log.i(Helper.TAG, "onItemStateChanged"); + super.onItemStateChanged(key, selected); + } + + @Override + public void onSelectionRefresh() { + Log.i(Helper.TAG, "onSelectionRefresh"); + super.onSelectionRefresh(); + } + + @Override + public void onSelectionChanged() { + Log.i(Helper.TAG, "onSelectionChanged"); + super.onSelectionChanged(); + } + + @Override + public void onSelectionRestored() { + Log.i(Helper.TAG, "onSelectionRestored"); + super.onSelectionRestored(); + } + }); + + if (savedInstanceState != null) + selectionTracker.onRestoreInstanceState(savedInstanceState); + pbWait.setVisibility(View.GONE); grpReady.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/MyActionModeController.java b/app/src/main/java/eu/faircode/email/MyActionModeController.java new file mode 100644 index 0000000000..49ef39db9f --- /dev/null +++ b/app/src/main/java/eu/faircode/email/MyActionModeController.java @@ -0,0 +1,38 @@ +package eu.faircode.email; + +import android.content.Context; +import android.view.Menu; +import android.view.MenuItem; + +import androidx.appcompat.view.ActionMode; +import androidx.recyclerview.selection.SelectionTracker; + +public class MyActionModeController implements ActionMode.Callback { + private final Context context; + private final SelectionTracker selectionTracker; + + public MyActionModeController(Context context, SelectionTracker selectionTracker) { + this.context = context; + this.selectionTracker = selectionTracker; + } + + @Override + public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { + return false; + } + + @Override + public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { + return false; + } + + @Override + public void onDestroyActionMode(ActionMode actionMode) { + selectionTracker.clearSelection(); + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/faircode/email/MyItemDetail.java b/app/src/main/java/eu/faircode/email/MyItemDetail.java new file mode 100644 index 0000000000..1bff9392f3 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/MyItemDetail.java @@ -0,0 +1,30 @@ +package eu.faircode.email; + +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.recyclerview.selection.ItemDetailsLookup; + +public class MyItemDetail extends ItemDetailsLookup.ItemDetails { + private final int adapterPosition; + private final Long selectionKey; + + public MyItemDetail(int adapterPosition, Long selectionKey) { + Log.i(Helper.TAG, "MyItemDetail"); + this.adapterPosition = adapterPosition; + this.selectionKey = selectionKey; + } + + @Override + public int getPosition() { + Log.i(Helper.TAG, "MyItemDetail.getPosition=" + adapterPosition); + return adapterPosition; + } + + @Nullable + @Override + public Long getSelectionKey() { + Log.i(Helper.TAG, "MyItemDetail.getSelectionKey=" + selectionKey); + return selectionKey; + } +} diff --git a/app/src/main/java/eu/faircode/email/MyItemKeyProvider.java b/app/src/main/java/eu/faircode/email/MyItemKeyProvider.java new file mode 100644 index 0000000000..4ca91582c8 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/MyItemKeyProvider.java @@ -0,0 +1,37 @@ +package eu.faircode.email; + +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.paging.PagedList; +import androidx.recyclerview.selection.ItemKeyProvider; +import androidx.recyclerview.widget.RecyclerView; + +public class MyItemKeyProvider extends ItemKeyProvider { + private final PagedList messages; + + public MyItemKeyProvider(PagedList messages) { + super(ItemKeyProvider.SCOPE_MAPPED); + this.messages = messages; + Log.i(Helper.TAG, "MyItemKeyProvider"); + } + + @Nullable + @Override + public Long getKey(int position) { + Log.i(Helper.TAG, "MyItemKeyProvider.getKey pos=" + position + " key=" + messages.get(position).id); + return messages.get(position).id; + } + + @Override + public int getPosition(@NonNull Long key) { + Log.i(Helper.TAG, "MyItemKeyProvider.getPosition key=" + key); + int pos = RecyclerView.NO_POSITION; + for (int i = 0; i < messages.size(); i++) + if (messages.get(i).id.equals(key)) + pos = i; + Log.i(Helper.TAG, "MyItemKeyProvider.getPosition key=" + key + " pos=" + pos); + return pos; + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/faircode/email/MyItemLookup.java b/app/src/main/java/eu/faircode/email/MyItemLookup.java new file mode 100644 index 0000000000..8bca612960 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/MyItemLookup.java @@ -0,0 +1,35 @@ +package eu.faircode.email; + +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.selection.ItemDetailsLookup; +import androidx.recyclerview.widget.RecyclerView; + +public class MyItemLookup extends ItemDetailsLookup { + + private final RecyclerView recyclerView; + + public MyItemLookup(RecyclerView recyclerView) { + Log.i(Helper.TAG, "MyItemLookup"); + this.recyclerView = recyclerView; + } + + @Nullable + @Override + public ItemDetails getItemDetails(@NonNull MotionEvent e) { + Log.i(Helper.TAG, "MyItemLookup.getItemDetails"); + View view = recyclerView.findChildViewUnder(e.getX(), e.getY()); + if (view != null) { + RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view); + if (viewHolder instanceof AdapterMessage.ViewHolder) { + return ((AdapterMessage.ViewHolder) viewHolder).getItemDetails(); + } + } + + return null; + } +}