mirror of https://github.com/readrops/Readrops.git
Add DiffUtil changePayload actions to avoid the list flickering
This commit is contained in:
parent
bc1581c4d4
commit
54d6fca734
|
@ -104,7 +104,7 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
|||
FeedWithFolder feedWithFolder1 = oldItem.getModel();
|
||||
FeedWithFolder feedWithFolder2 = newItem.getModel();
|
||||
|
||||
return feedWithFolder1.getFeed().getName().equals(feedWithFolder1.getFeed().getName()) &&
|
||||
return feedWithFolder1.getFeed().getName().equals(feedWithFolder2.getFeed().getName()) &&
|
||||
feedWithFolder1.getFeed().getUrl().equals(feedWithFolder2.getFeed().getUrl()) &&
|
||||
feedWithFolder1.getFolder().getName().equals(feedWithFolder2.getFolder().getName());
|
||||
}
|
||||
|
@ -112,7 +112,18 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
|||
@Nullable
|
||||
@Override
|
||||
public Object getChangePayload(FeedWithFolderItem oldItem, int oldItemPosition, FeedWithFolderItem newItem, int newItemPosition) {
|
||||
return null;
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
if (!oldItem.getModel().getFeed().getName().equals(newItem.getModel().getFeed().getName()))
|
||||
bundle.putString(FeedWithFolderItem.FEED_NAME_KEY, newItem.getModel().getFeed().getName());
|
||||
|
||||
if (!oldItem.getModel().getFolder().getName().equals(newItem.getModel().getFolder().getName()))
|
||||
bundle.putString(FeedWithFolderItem.FOLDER_NAME_KEY, newItem.getModel().getFolder().getName());
|
||||
|
||||
if (bundle.size() > 0)
|
||||
return bundle;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.readrops.app.views;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
@ -16,6 +17,9 @@ import java.util.List;
|
|||
|
||||
public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWithFolderItem, FeedWithFolderItem.ViewHolder> {
|
||||
|
||||
public static final String FEED_NAME_KEY = "name";
|
||||
public static final String FOLDER_NAME_KEY = "folder_name";
|
||||
|
||||
private ManageFeedsListener listener;
|
||||
|
||||
public FeedWithFolderItem(FeedWithFolder feedWithFolder) {
|
||||
|
@ -38,34 +42,51 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
|
|||
return R.layout.feed_layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getIdentifier() {
|
||||
return getModel().getFeed().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(ViewHolder holder, List<Object> payloads) {
|
||||
super.bindView(holder, payloads);
|
||||
FeedWithFolder feedWithFolder = getModel();
|
||||
if (!payloads.isEmpty()) {
|
||||
Bundle bundle = (Bundle)payloads.get(0);
|
||||
|
||||
if (feedWithFolder.getFeed().getIconUrl() != null) {
|
||||
GlideApp.with(holder.itemView.getContext())
|
||||
.load(feedWithFolder.getFeed().getIconUrl())
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.placeholder(R.drawable.ic_rss_feed)
|
||||
.into(holder.feedIcon);
|
||||
} else
|
||||
holder.feedIcon.setImageResource(R.drawable.ic_rss_feed);
|
||||
if (bundle.getString(FEED_NAME_KEY) != null)
|
||||
holder.feedName.setText(bundle.getString(FEED_NAME_KEY));
|
||||
|
||||
holder.feedName.setText(feedWithFolder.getFeed().getName());
|
||||
if (feedWithFolder.getFeed().getDescription() != null) {
|
||||
holder.feedDescription.setVisibility(View.VISIBLE);
|
||||
holder.feedDescription.setText(feedWithFolder.getFeed().getDescription());
|
||||
} else
|
||||
holder.feedDescription.setVisibility(View.GONE);
|
||||
if (bundle.getString(FOLDER_NAME_KEY) != null)
|
||||
holder.folderName.setText(bundle.getString(FOLDER_NAME_KEY));
|
||||
} else {
|
||||
FeedWithFolder feedWithFolder = getModel();
|
||||
|
||||
if (feedWithFolder.getFeed().getIconUrl() != null) {
|
||||
GlideApp.with(holder.itemView.getContext())
|
||||
.load(feedWithFolder.getFeed().getIconUrl())
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.placeholder(R.drawable.ic_rss_feed)
|
||||
.into(holder.feedIcon);
|
||||
} else
|
||||
holder.feedIcon.setImageResource(R.drawable.ic_rss_feed);
|
||||
|
||||
holder.feedName.setText(feedWithFolder.getFeed().getName());
|
||||
if (feedWithFolder.getFeed().getDescription() != null) {
|
||||
holder.feedDescription.setVisibility(View.VISIBLE);
|
||||
holder.feedDescription.setText(feedWithFolder.getFeed().getDescription());
|
||||
} else
|
||||
holder.feedDescription.setVisibility(View.GONE);
|
||||
|
||||
if (feedWithFolder.getFolder().getId() != 1)
|
||||
holder.folderName.setText(feedWithFolder.getFolder().getName());
|
||||
else
|
||||
holder.folderName.setText(holder.itemView.getResources().getString(R.string.no_folder));
|
||||
|
||||
holder.editFeed.setOnClickListener(v -> listener.onEdit(feedWithFolder));
|
||||
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(feedWithFolder));
|
||||
}
|
||||
|
||||
if (feedWithFolder.getFolder().getId() != 1)
|
||||
holder.folderName.setText(feedWithFolder.getFolder().getName());
|
||||
else
|
||||
holder.folderName.setText(holder.itemView.getResources().getString(R.string.no_folder));
|
||||
|
||||
holder.editFeed.setOnClickListener(v -> listener.onEdit(feedWithFolder));
|
||||
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(feedWithFolder));
|
||||
}
|
||||
|
||||
public void setListener(ManageFeedsListener listener) {
|
||||
|
|
Loading…
Reference in New Issue