mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 12:44:42 +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 grpAttachments;
|
||||||
private Group grpExpanded;
|
private Group grpExpanded;
|
||||||
|
|
||||||
private ItemDetailsMessage itemDetails = null;
|
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
super(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));
|
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) {
|
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();
|
return differ.getItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return super.getItemId(position);
|
||||||
|
}
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =
|
private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =
|
||||||
new DiffUtil.ItemCallback<TupleMessageEx>() {
|
new DiffUtil.ItemCallback<TupleMessageEx>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1616,6 +1622,54 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
this.selectionTracker = selectionTracker;
|
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 {
|
interface IProperties {
|
||||||
void setExpanded(long id, boolean expand);
|
void setExpanded(long id, boolean expand);
|
||||||
|
|
||||||
|
|
|
@ -19,26 +19,31 @@ package eu.faircode.email;
|
||||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.recyclerview.selection.ItemDetailsLookup;
|
import androidx.recyclerview.selection.ItemDetailsLookup;
|
||||||
|
|
||||||
public class ItemDetailsMessage extends ItemDetailsLookup.ItemDetails<Long> {
|
public class ItemDetailsMessage extends ItemDetailsLookup.ItemDetails<Long> {
|
||||||
private int pos;
|
private AdapterMessage.ViewHolder viewHolder;
|
||||||
private Long key;
|
|
||||||
|
|
||||||
ItemDetailsMessage(int pos, Long id) {
|
ItemDetailsMessage(AdapterMessage.ViewHolder viewHolder) {
|
||||||
this.pos = pos;
|
this.viewHolder = viewHolder;
|
||||||
this.key = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
|
int pos = viewHolder.getAdapterPosition();
|
||||||
|
Log.i(Helper.TAG, "ItemDetails pos=" + pos);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Long getSelectionKey() {
|
public Long getSelectionKey() {
|
||||||
|
int pos = viewHolder.getAdapterPosition();
|
||||||
|
Long key = viewHolder.getKey();
|
||||||
|
Log.i(Helper.TAG, "ItemDetails pos=" + pos + " key=" + key);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ package eu.faircode.email;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.paging.PagedList;
|
|
||||||
import androidx.recyclerview.selection.ItemKeyProvider;
|
import androidx.recyclerview.selection.ItemKeyProvider;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
@ -37,23 +36,12 @@ public class ItemKeyProviderMessage extends ItemKeyProvider<Long> {
|
||||||
@Override
|
@Override
|
||||||
public Long getKey(int pos) {
|
public Long getKey(int pos) {
|
||||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
PagedList<TupleMessageEx> list = adapter.getCurrentList();
|
return adapter.getKeyAtPosition(pos);
|
||||||
if (list != null && pos < list.size())
|
|
||||||
return list.get(pos).id;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPosition(@NonNull Long key) {
|
public int getPosition(@NonNull Long key) {
|
||||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
return adapter.getPositionForKey(key);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ 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;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
@ -39,34 +38,26 @@ public class SelectionPredicateMessage extends SelectionTracker.SelectionPredica
|
||||||
@Override
|
@Override
|
||||||
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
||||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
TupleMessageEx message = adapter.getItemForKey(key);
|
||||||
if (messages != null)
|
|
||||||
for (int i = 0; i < messages.size(); i++) {
|
if (message != null && message.uid != null && (account < 0 || account == message.account)) {
|
||||||
TupleMessageEx message = messages.get(i);
|
account = message.account;
|
||||||
if (message != null && message.id.equals(key)) {
|
return true;
|
||||||
if (message.uid != null && (account < 0 || account == message.account)) {
|
}
|
||||||
account = message.account;
|
|
||||||
return true;
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
||||||
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
||||||
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
TupleMessageEx message = adapter.getItemAtPosition(position);
|
||||||
if (messages != null) {
|
|
||||||
TupleMessageEx message = messages.get(position);
|
if (message != null && message.uid != null && (account < 0 || account == message.account)) {
|
||||||
if (message != null) {
|
account = message.account;
|
||||||
if (message.uid != null && (account < 0 || account == message.account)) {
|
return true;
|
||||||
account = message.account;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue