修改我的收藏-社区文章/回答UI
This commit is contained in:
@ -9,11 +9,20 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.CollectionUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.baselist.LoadType;
|
||||
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding;
|
||||
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder;
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity;
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.qa.entity.Questions;
|
||||
import com.gh.gamecenter.qa.questions.detail.AnswerViewHolder;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
/**
|
||||
* Created by khy on 22/12/17.
|
||||
@ -23,11 +32,14 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> {
|
||||
|
||||
private OnListClickListener mListClickListener;
|
||||
|
||||
private AnswerViewModel mListViewModel;
|
||||
|
||||
private String mEntrance;
|
||||
private AnswerFragment.Type mType;
|
||||
|
||||
public AnswerAdapter(Context context, AnswerFragment.Type type, OnListClickListener listClickListener, String entrance) {
|
||||
public AnswerAdapter(Context context, AnswerViewModel viewModel, AnswerFragment.Type type, OnListClickListener listClickListener, String entrance) {
|
||||
super(context);
|
||||
mListViewModel = viewModel;
|
||||
mListClickListener = listClickListener;
|
||||
mEntrance = entrance;
|
||||
this.mType = type;
|
||||
@ -47,8 +59,8 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> {
|
||||
view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view, mListClickListener);
|
||||
case ItemViewType.ITEM_BODY:
|
||||
view = mLayoutInflater.inflate(R.layout.ask_answer_item, parent, false);
|
||||
return new AnswerViewHolder(view, mListClickListener);
|
||||
view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false);
|
||||
return new CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -58,7 +70,41 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> {
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (getItemViewType(position)) {
|
||||
case ItemViewType.ITEM_BODY:
|
||||
((AnswerViewHolder) holder).initCollectionAnswerViewHolder(mContext, mEntityList.get(position), mEntrance, mType);
|
||||
CommunityAnswerItemViewHolder viewHolder = (CommunityAnswerItemViewHolder) holder;
|
||||
AnswerEntity entity = mEntityList.get(position);
|
||||
String path;
|
||||
if (mType == AnswerFragment.Type.COLLECTION) {
|
||||
path = "我的收藏-回答列表";
|
||||
} else if (mType == AnswerFragment.Type.HISTORY) {
|
||||
path = "浏览记录-回答列表";
|
||||
} else {
|
||||
path = "插入回答-收藏回答列表";
|
||||
}
|
||||
viewHolder.bindAnswerItem(entity, mEntrance, path);
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (entity.getActive()) {
|
||||
mContext.startActivity(AnswerDetailActivity.getIntent(mContext, entity.getId(), mEntrance, path));
|
||||
} else {
|
||||
showDeleteDialog(entity.getId());
|
||||
}
|
||||
|
||||
if (!entity.getRead()) {
|
||||
entity.setRead(true);
|
||||
notifyItemChanged(position);
|
||||
mListViewModel.postCollectionAnswerRead(entity.getId());
|
||||
}
|
||||
}
|
||||
});
|
||||
viewHolder.getBinding().title.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Questions questions = entity.getQuestions();
|
||||
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, questions.getId(), mEntrance, path));
|
||||
}
|
||||
});
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
|
||||
@ -68,6 +114,26 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
private void showDeleteDialog(String answerId) {
|
||||
DialogUtils.showCancelAlertDialog(mContext, "提示"
|
||||
, "内容已被删除,是否取消收藏?"
|
||||
, "取消收藏", "暂不"
|
||||
, () -> CollectionUtils.INSTANCE.deleteCollection(mContext, answerId
|
||||
, CollectionUtils.CollectionType.answer, new CollectionUtils.OnCollectionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Utils.toast(mContext, R.string.collection_cancel);
|
||||
mListViewModel.load(LoadType.REFRESH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
Utils.toast(mContext, R.string.collection_cancel_failure);
|
||||
}
|
||||
}), null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mEntityList == null || mEntityList.isEmpty() ? 0 : mEntityList.size() + FOOTER_ITEM_COUNT;
|
||||
|
||||
Reference in New Issue
Block a user