|
|
@@ -13,23 +13,29 @@ import androidx.recyclerview.widget.RecyclerView;
|
|
|
import com.atmob.common.logging.AtmobLog;
|
|
|
import com.atmob.voiceai.data.api.bean.VoiceListBean;
|
|
|
import com.atmob.voiceai.databinding.ItemVoiceAiListBinding;
|
|
|
+import com.atmob.voiceai.databinding.ItemVoiceListFootBinding;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
-public class VoiceAIListAdapter extends RecyclerView.Adapter<VoiceAIListAdapter.ViewHolder> {
|
|
|
+public class VoiceAIListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
|
|
|
private final AsyncListDiffer<VoiceListBean> listDiffer;
|
|
|
|
|
|
private final LifecycleOwner lifecycleOwner;
|
|
|
|
|
|
+ public static final int TYPE_FOOT = 3;
|
|
|
+
|
|
|
public VoiceAIListAdapter(@NonNull LifecycleOwner lifecycleOwner) {
|
|
|
this.lifecycleOwner = lifecycleOwner;
|
|
|
this.listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback<VoiceListBean>() {
|
|
|
@Override
|
|
|
public boolean areItemsTheSame(@NonNull VoiceListBean oldItem, @NonNull VoiceListBean newItem) {
|
|
|
- if (oldItem.isAddIcon() == newItem.isAddIcon()) {
|
|
|
- return true;
|
|
|
+ if (oldItem.getViewType() != newItem.getViewType()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (oldItem.isAddIcon() != newItem.isAddIcon()) {
|
|
|
+ return false;
|
|
|
}
|
|
|
return oldItem.getId() == newItem.getId();
|
|
|
}
|
|
|
@@ -55,28 +61,58 @@ public class VoiceAIListAdapter extends RecyclerView.Adapter<VoiceAIListAdapter.
|
|
|
|
|
|
@NonNull
|
|
|
@Override
|
|
|
- public VoiceAIListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
Context context = parent.getContext();
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
|
|
- return new ViewHolder(ItemVoiceAiListBinding.inflate(layoutInflater));
|
|
|
+ if (viewType == TYPE_FOOT) {
|
|
|
+ return new ViewFootHolder(ItemVoiceListFootBinding.inflate(layoutInflater));
|
|
|
+ } else {
|
|
|
+ return new ViewHolder(ItemVoiceAiListBinding.inflate(layoutInflater));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void onBindViewHolder(@NonNull VoiceAIListAdapter.ViewHolder holder, int position) {
|
|
|
- holder.bind(listDiffer.getCurrentList().get(position));
|
|
|
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
|
|
+ VoiceListBean voiceListBean = listDiffer.getCurrentList().get(position);
|
|
|
+ if (voiceListBean.getViewType() != TYPE_FOOT) {
|
|
|
+ ((ViewHolder) holder).bind(voiceListBean);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void submit(List<VoiceListBean> itemBeanList) {
|
|
|
+ VoiceListBean voiceListBean = new VoiceListBean();
|
|
|
+ voiceListBean.setViewType(TYPE_FOOT);
|
|
|
+ itemBeanList.add(voiceListBean);
|
|
|
listDiffer.submitList(itemBeanList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int getItemViewType(int position) {
|
|
|
+ VoiceListBean voiceListBean = listDiffer.getCurrentList().get(position);
|
|
|
+ if (voiceListBean.getViewType() == TYPE_FOOT) {
|
|
|
+ return TYPE_FOOT;
|
|
|
+ }
|
|
|
+ return super.getItemViewType(position);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public int getItemCount() {
|
|
|
return listDiffer.getCurrentList().size();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public class ViewFootHolder extends RecyclerView.ViewHolder {
|
|
|
+
|
|
|
+ private final ItemVoiceListFootBinding binding;
|
|
|
+
|
|
|
+ public ViewFootHolder(@NonNull ItemVoiceListFootBinding binding) {
|
|
|
+ super(binding.getRoot());
|
|
|
+ this.binding = binding;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
private final ItemVoiceAiListBinding binding;
|