mirror of https://github.com/readrops/Readrops.git
Migrate FeedsAdapter to viewBinding
This commit is contained in:
parent
93be8b92b9
commit
f7a78df815
|
@ -3,8 +3,6 @@ package com.readrops.app.adapters;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -14,12 +12,13 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
import com.readrops.app.R;
|
import com.readrops.app.R;
|
||||||
import com.readrops.db.pojo.FeedWithFolder;
|
import com.readrops.app.databinding.FeedLayoutBinding;
|
||||||
import com.readrops.app.utils.GlideApp;
|
import com.readrops.app.utils.GlideApp;
|
||||||
|
import com.readrops.db.pojo.FeedWithFolder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewHolder> {
|
public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.FeedViewHolder> {
|
||||||
|
|
||||||
private ManageFeedsListener listener;
|
private ManageFeedsListener listener;
|
||||||
|
|
||||||
|
@ -52,20 +51,16 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedWithFolder getItemAt(int position) {
|
|
||||||
return getItem(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
public FeedViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.feed_layout, viewGroup, false);
|
FeedLayoutBinding binding = FeedLayoutBinding.inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false);
|
||||||
|
|
||||||
return new ViewHolder(view);
|
return new FeedViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull FeedViewHolder viewHolder, int i) {
|
||||||
FeedWithFolder feedWithFolder = getItem(i);
|
FeedWithFolder feedWithFolder = getItem(i);
|
||||||
|
|
||||||
if (feedWithFolder.getFeed().getIconUrl() != null) {
|
if (feedWithFolder.getFeed().getIconUrl() != null) {
|
||||||
|
@ -73,21 +68,21 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
.load(feedWithFolder.getFeed().getIconUrl())
|
.load(feedWithFolder.getFeed().getIconUrl())
|
||||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||||
.placeholder(R.drawable.ic_rss_feed_grey)
|
.placeholder(R.drawable.ic_rss_feed_grey)
|
||||||
.into(viewHolder.feedIcon);
|
.into(viewHolder.binding.feedLayoutIcon);
|
||||||
} else
|
} else
|
||||||
viewHolder.feedIcon.setImageResource(R.drawable.ic_rss_feed_grey);
|
viewHolder.binding.feedLayoutIcon.setImageResource(R.drawable.ic_rss_feed_grey);
|
||||||
|
|
||||||
viewHolder.feedName.setText(feedWithFolder.getFeed().getName());
|
viewHolder.binding.feedLayoutName.setText(feedWithFolder.getFeed().getName());
|
||||||
if (feedWithFolder.getFeed().getDescription() != null) {
|
if (feedWithFolder.getFeed().getDescription() != null) {
|
||||||
viewHolder.feedDescription.setVisibility(View.VISIBLE);
|
viewHolder.binding.feedLayoutDescription.setVisibility(View.VISIBLE);
|
||||||
viewHolder.feedDescription.setText(feedWithFolder.getFeed().getDescription());
|
viewHolder.binding.feedLayoutDescription.setText(feedWithFolder.getFeed().getDescription());
|
||||||
} else
|
} else
|
||||||
viewHolder.feedDescription.setVisibility(View.GONE);
|
viewHolder.binding.feedLayoutDescription.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (feedWithFolder.getFolder() != null)
|
if (feedWithFolder.getFolder() != null)
|
||||||
viewHolder.folderName.setText(feedWithFolder.getFolder().getName());
|
viewHolder.binding.feedLayoutFolder.setText(feedWithFolder.getFolder().getName());
|
||||||
else
|
else
|
||||||
viewHolder.folderName.setText(R.string.no_folder);
|
viewHolder.binding.feedLayoutFolder.setText(R.string.no_folder);
|
||||||
|
|
||||||
viewHolder.itemView.setOnClickListener(v -> listener.onEdit(feedWithFolder));
|
viewHolder.itemView.setOnClickListener(v -> listener.onEdit(feedWithFolder));
|
||||||
viewHolder.itemView.setOnLongClickListener(v -> {
|
viewHolder.itemView.setOnLongClickListener(v -> {
|
||||||
|
@ -98,16 +93,16 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull List<Object> payloads) {
|
public void onBindViewHolder(@NonNull FeedViewHolder holder, int position, @NonNull List<Object> payloads) {
|
||||||
if (!payloads.isEmpty()) {
|
if (!payloads.isEmpty()) {
|
||||||
FeedWithFolder feedWithFolder = (FeedWithFolder) payloads.get(0);
|
FeedWithFolder feedWithFolder = (FeedWithFolder) payloads.get(0);
|
||||||
|
|
||||||
holder.feedName.setText(feedWithFolder.getFeed().getName());
|
holder.binding.feedLayoutName.setText(feedWithFolder.getFeed().getName());
|
||||||
|
|
||||||
if (feedWithFolder.getFolder() != null)
|
if (feedWithFolder.getFolder() != null)
|
||||||
holder.folderName.setText(feedWithFolder.getFolder().getName());
|
holder.binding.feedLayoutName.setText(feedWithFolder.getFolder().getName());
|
||||||
else
|
else
|
||||||
holder.folderName.setText(R.string.no_folder);
|
holder.binding.feedLayoutName.setText(R.string.no_folder);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
onBindViewHolder(holder, position);
|
onBindViewHolder(holder, position);
|
||||||
|
@ -115,24 +110,19 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
|
|
||||||
public interface ManageFeedsListener {
|
public interface ManageFeedsListener {
|
||||||
void onOpenLink(FeedWithFolder feedWithFolder);
|
void onOpenLink(FeedWithFolder feedWithFolder);
|
||||||
|
|
||||||
void onEdit(FeedWithFolder feedWithFolder);
|
void onEdit(FeedWithFolder feedWithFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected class ViewHolder extends RecyclerView.ViewHolder {
|
protected class FeedViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private ImageView feedIcon;
|
private FeedLayoutBinding binding;
|
||||||
private TextView feedName;
|
|
||||||
private TextView feedDescription;
|
|
||||||
private TextView folderName;
|
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public FeedViewHolder(FeedLayoutBinding binding) {
|
||||||
super(itemView);
|
super(binding.getRoot());
|
||||||
|
|
||||||
feedIcon = itemView.findViewById(R.id.feed_layout_icon);
|
this.binding = binding;
|
||||||
feedName = itemView.findViewById(R.id.feed_layout_name);
|
|
||||||
feedDescription = itemView.findViewById(R.id.feed_layout_description);
|
|
||||||
folderName = itemView.findViewById(R.id.feed_layout_folder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue