mirror of https://github.com/M66B/FairEmail.git
parent
1fdb9c70a8
commit
61441c3c8a
@ -0,0 +1,29 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
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 ItemDetailsLookupMessage extends ItemDetailsLookup<Long> {
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
|
||||||
|
ItemDetailsLookupMessage(RecyclerView recyclerView) {
|
||||||
|
this.recyclerView = recyclerView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) {
|
||||||
|
View view = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
|
||||||
|
if (view != null) {
|
||||||
|
RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view);
|
||||||
|
if (viewHolder instanceof AdapterMessage.ViewHolder)
|
||||||
|
return ((AdapterMessage.ViewHolder) viewHolder).getItemDetails(motionEvent);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.recyclerview.selection.ItemDetailsLookup;
|
||||||
|
|
||||||
|
public class ItemDetailsMessage extends ItemDetailsLookup.ItemDetails<Long> {
|
||||||
|
private int pos;
|
||||||
|
private Long key;
|
||||||
|
|
||||||
|
ItemDetailsMessage(int pos, Long id) {
|
||||||
|
this.pos = pos;
|
||||||
|
this.key = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPosition() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Long getSelectionKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.paging.PagedList;
|
||||||
|
import androidx.recyclerview.selection.ItemKeyProvider;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
public class ItemKeyProviderMessage extends ItemKeyProvider<Long> {
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
|
||||||
|
ItemKeyProviderMessage(RecyclerView recyclerView) {
|
||||||
|
super(ItemKeyProvider.SCOPE_CACHED);
|
||||||
|
this.recyclerView = recyclerView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Long getKey(int pos) {
|
||||||
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
|
return adapter.getCurrentList().get(pos).id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPosition(@NonNull Long key) {
|
||||||
|
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 i;
|
||||||
|
}
|
||||||
|
return RecyclerView.NO_POSITION;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.selection.SelectionTracker;
|
||||||
|
|
||||||
|
public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canSelectMultiple() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue