mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Use paged list differ
This commit is contained in:
parent
592afd8003
commit
3dced44622
1 changed files with 21 additions and 7 deletions
|
@ -98,14 +98,15 @@ import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import androidx.paging.PagedListAdapter;
|
import androidx.paging.AsyncPagedListDiffer;
|
||||||
|
import androidx.paging.PagedList;
|
||||||
import androidx.recyclerview.selection.ItemDetailsLookup;
|
import androidx.recyclerview.selection.ItemDetailsLookup;
|
||||||
import androidx.recyclerview.selection.SelectionTracker;
|
import androidx.recyclerview.selection.SelectionTracker;
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMessage.ViewHolder> {
|
public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHolder> {
|
||||||
private Context context;
|
private Context context;
|
||||||
private LifecycleOwner owner;
|
private LifecycleOwner owner;
|
||||||
private FragmentManager fragmentManager;
|
private FragmentManager fragmentManager;
|
||||||
|
@ -127,14 +128,15 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
||||||
private boolean hasWebView;
|
private boolean hasWebView;
|
||||||
|
|
||||||
private SelectionTracker<Long> selectionTracker = null;
|
private SelectionTracker<Long> selectionTracker = null;
|
||||||
|
private AsyncPagedListDiffer<TupleMessageEx> differ = new AsyncPagedListDiffer<>(this, DIFF_CALLBACK);
|
||||||
private DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG);
|
|
||||||
|
|
||||||
enum ViewType {UNIFIED, FOLDER, THREAD, SEARCH}
|
enum ViewType {UNIFIED, FOLDER, THREAD, SEARCH}
|
||||||
|
|
||||||
private static final float LOW_LIGHT = 0.6f;
|
private static final float LOW_LIGHT = 0.6f;
|
||||||
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L;
|
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L;
|
||||||
|
|
||||||
|
private static DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG);
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder implements
|
public class ViewHolder extends RecyclerView.ViewHolder implements
|
||||||
View.OnClickListener, BottomNavigationView.OnNavigationItemSelectedListener {
|
View.OnClickListener, BottomNavigationView.OnNavigationItemSelectedListener {
|
||||||
private View itemView;
|
private View itemView;
|
||||||
|
@ -550,7 +552,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
||||||
if (pos == RecyclerView.NO_POSITION)
|
if (pos == RecyclerView.NO_POSITION)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TupleMessageEx message = getItem(pos);
|
TupleMessageEx message = differ.getItem(pos);
|
||||||
|
|
||||||
if (view.getId() == R.id.ivAddContact)
|
if (view.getId() == R.id.ivAddContact)
|
||||||
onAddContact(message);
|
onAddContact(message);
|
||||||
|
@ -1534,7 +1536,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
||||||
|
|
||||||
AdapterMessage(Context context, LifecycleOwner owner, FragmentManager fragmentManager,
|
AdapterMessage(Context context, LifecycleOwner owner, FragmentManager fragmentManager,
|
||||||
ViewType viewType, boolean outgoing, IProperties properties) {
|
ViewType viewType, boolean outgoing, IProperties properties) {
|
||||||
super(DIFF_CALLBACK);
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.fragmentManager = fragmentManager;
|
this.fragmentManager = fragmentManager;
|
||||||
|
@ -1561,6 +1562,19 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
||||||
this.hasWebView = pm.hasSystemFeature("android.software.webview");
|
this.hasWebView = pm.hasSystemFeature("android.software.webview");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void submitList(PagedList<TupleMessageEx> pagedList) {
|
||||||
|
differ.submitList(pagedList);
|
||||||
|
}
|
||||||
|
|
||||||
|
PagedList<TupleMessageEx> getCurrentList() {
|
||||||
|
return differ.getCurrentList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return differ.getItemCount();
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -1589,7 +1603,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
holder.unwire();
|
holder.unwire();
|
||||||
|
|
||||||
TupleMessageEx message = getItem(position);
|
TupleMessageEx message = differ.getItem(position);
|
||||||
if (message == null)
|
if (message == null)
|
||||||
holder.clear();
|
holder.clear();
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue