mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 11:15:51 +00:00
Refactoring
This commit is contained in:
parent
e64b9289e3
commit
3df4ba3a8d
4 changed files with 83 additions and 45 deletions
|
@ -188,8 +188,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
private Group grpAttachments;
|
||||
private Group grpExpanded;
|
||||
|
||||
private ItemDetailsMessage itemDetails = null;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
|
@ -542,7 +540,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
});
|
||||
}
|
||||
|
||||
itemDetails = new ItemDetailsMessage(position, message.id);
|
||||
itemView.setActivated(selectionTracker != null && selectionTracker.isSelected(message.id));
|
||||
}
|
||||
|
||||
|
@ -1530,7 +1527,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) {
|
||||
return itemDetails;
|
||||
return new ItemDetailsMessage(this);
|
||||
}
|
||||
|
||||
Long getKey() {
|
||||
return getKeyAtPosition(getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1575,6 +1576,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
return differ.getItemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return super.getItemId(position);
|
||||
}
|
||||
|
||||
private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =
|
||||
new DiffUtil.ItemCallback<TupleMessageEx>() {
|
||||
@Override
|
||||
|
@ -1616,6 +1622,54 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
this.selectionTracker = selectionTracker;
|
||||
}
|
||||
|
||||
int getPositionForKey(long key) {
|
||||
PagedList<TupleMessageEx> messages = getCurrentList();
|
||||
if (messages != null)
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
TupleMessageEx message = messages.get(i);
|
||||
if (message != null && message.id.equals(key)) {
|
||||
Log.i(Helper.TAG, "Position=" + i + " @Key=" + key);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Log.i(Helper.TAG, "Position=" + RecyclerView.NO_POSITION + " @Key=" + key);
|
||||
return RecyclerView.NO_POSITION;
|
||||
}
|
||||
|
||||
TupleMessageEx getItemAtPosition(int pos) {
|
||||
PagedList<TupleMessageEx> list = getCurrentList();
|
||||
if (list != null && pos < list.size()) {
|
||||
TupleMessageEx message = list.get(pos);
|
||||
Long key = (message == null ? null : message.id);
|
||||
Log.i(Helper.TAG, "Item=" + key + " @Position=" + pos);
|
||||
return message;
|
||||
} else {
|
||||
Log.i(Helper.TAG, "Item=" + null + " @Position=" + pos);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
TupleMessageEx getItemForKey(long key) {
|
||||
PagedList<TupleMessageEx> messages = getCurrentList();
|
||||
if (messages != null)
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
TupleMessageEx message = messages.get(i);
|
||||
if (message != null && message.id.equals(key)) {
|
||||
Log.i(Helper.TAG, "Item=" + message.id + " @Key=" + key);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
Log.i(Helper.TAG, "Item=" + null + " @Key" + key);
|
||||
return null;
|
||||
}
|
||||
|
||||
Long getKeyAtPosition(int pos) {
|
||||
TupleMessageEx message = getItemAtPosition(pos);
|
||||
Long key = (message == null ? null : message.id);
|
||||
Log.i(Helper.TAG, "Key=" + key + " @Position=" + pos);
|
||||
return key;
|
||||
}
|
||||
|
||||
interface IProperties {
|
||||
void setExpanded(long id, boolean expand);
|
||||
|
||||
|
|
|
@ -19,26 +19,31 @@ package eu.faircode.email;
|
|||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.selection.ItemDetailsLookup;
|
||||
|
||||
public class ItemDetailsMessage extends ItemDetailsLookup.ItemDetails<Long> {
|
||||
private int pos;
|
||||
private Long key;
|
||||
private AdapterMessage.ViewHolder viewHolder;
|
||||
|
||||
ItemDetailsMessage(int pos, Long id) {
|
||||
this.pos = pos;
|
||||
this.key = id;
|
||||
ItemDetailsMessage(AdapterMessage.ViewHolder viewHolder) {
|
||||
this.viewHolder = viewHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPosition() {
|
||||
int pos = viewHolder.getAdapterPosition();
|
||||
Log.i(Helper.TAG, "ItemDetails pos=" + pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Long getSelectionKey() {
|
||||
int pos = viewHolder.getAdapterPosition();
|
||||
Long key = viewHolder.getKey();
|
||||
Log.i(Helper.TAG, "ItemDetails pos=" + pos + " key=" + key);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
||||
|
@ -37,23 +36,12 @@ public class ItemKeyProviderMessage extends ItemKeyProvider<Long> {
|
|||
@Override
|
||||
public Long getKey(int pos) {
|
||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||
PagedList<TupleMessageEx> list = adapter.getCurrentList();
|
||||
if (list != null && pos < list.size())
|
||||
return list.get(pos).id;
|
||||
else
|
||||
return null;
|
||||
return adapter.getKeyAtPosition(pos);
|
||||
}
|
||||
|
||||
@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;
|
||||
return adapter.getPositionForKey(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.recyclerview.selection.SelectionTracker;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -39,34 +38,26 @@ public class SelectionPredicateMessage extends SelectionTracker.SelectionPredica
|
|||
@Override
|
||||
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
||||
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)) {
|
||||
if (message.uid != null && (account < 0 || account == message.account)) {
|
||||
account = message.account;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
TupleMessageEx message = adapter.getItemForKey(key);
|
||||
|
||||
if (message != null && message.uid != null && (account < 0 || account == message.account)) {
|
||||
account = message.account;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
||||
if (messages != null) {
|
||||
TupleMessageEx message = messages.get(position);
|
||||
if (message != null) {
|
||||
if (message.uid != null && (account < 0 || account == message.account)) {
|
||||
account = message.account;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TupleMessageEx message = adapter.getItemAtPosition(position);
|
||||
|
||||
if (message != null && message.uid != null && (account < 0 || account == message.account)) {
|
||||
account = message.account;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue