2018-10-24 09:09:07 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2018-10-24 15:18:01 +00:00
|
|
|
import androidx.paging.PagedList;
|
2018-10-24 09:09:07 +00:00
|
|
|
import androidx.recyclerview.selection.SelectionTracker;
|
2018-10-24 15:18:01 +00:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2018-10-24 09:09:07 +00:00
|
|
|
|
|
|
|
|
public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> {
|
|
|
|
|
|
2018-10-24 15:18:01 +00:00
|
|
|
private RecyclerView recyclerView;
|
|
|
|
|
|
|
|
|
|
SelectionPredicateMessage(RecyclerView recyclerView) {
|
|
|
|
|
this.recyclerView = recyclerView;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 09:09:07 +00:00
|
|
|
@Override
|
|
|
|
|
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
2018-10-24 15:18:01 +00:00
|
|
|
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;
|
2018-10-24 09:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
2018-10-24 15:18:01 +00:00
|
|
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
|
|
|
|
return (adapter.getCurrentList().get(position).uid != null);
|
2018-10-24 09:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canSelectMultiple() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|