修改我的收藏-社区文章/回答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;
|
||||
|
||||
@ -4,18 +4,13 @@ import android.view.View;
|
||||
|
||||
import com.gh.common.history.HistoryDatabase;
|
||||
import com.gh.common.util.CollectionUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.baselist.ListFragment;
|
||||
import com.gh.gamecenter.baselist.LoadType;
|
||||
import com.gh.gamecenter.baselist.NormalListViewModel;
|
||||
import com.gh.gamecenter.eventbus.EBCollectionChanged;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
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.QuestionsDetailActivity;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -43,7 +38,7 @@ public class AnswerFragment extends ListFragment<AnswerEntity, AnswerViewModel>
|
||||
|
||||
@Override
|
||||
protected ListAdapter provideListAdapter() {
|
||||
return mAdapter == null ? mAdapter = new AnswerAdapter(getContext(), mType,this, mEntrance) : mAdapter;
|
||||
return mAdapter == null ? mAdapter = new AnswerAdapter(getContext(), mListViewModel, mType, this, mEntrance) : mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,56 +59,13 @@ public class AnswerFragment extends ListFragment<AnswerEntity, AnswerViewModel>
|
||||
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
AnswerEntity entity;
|
||||
switch (view.getId()) {
|
||||
case R.id.footerview_item:
|
||||
if (mAdapter.isNetworkError()) {
|
||||
mListViewModel.load(LoadType.RETRY);
|
||||
}
|
||||
break;
|
||||
case R.id.ask_answer_item_constraintlayout:
|
||||
case R.id.ask_answer_item_content:
|
||||
entity = (AnswerEntity) data;
|
||||
if (entity.getActive()) {
|
||||
startActivity(AnswerDetailActivity.getIntent(getContext(), entity.getId(), mEntrance, "我的收藏-回答"));
|
||||
} else {
|
||||
showDeleteDialog(entity.getId());
|
||||
}
|
||||
|
||||
if (!entity.getRead()) {
|
||||
entity.setRead(true);
|
||||
mAdapter.notifyItemChanged(position);
|
||||
mListViewModel.postCollectionAnswerRead(entity.getId());
|
||||
}
|
||||
break;
|
||||
case R.id.ask_answer_item_title:
|
||||
entity = (AnswerEntity) data;
|
||||
Questions questions = entity.getQuestions();
|
||||
startActivity(QuestionsDetailActivity.getIntent(getContext(), questions.getId(), mEntrance, "我的收藏-回答"));
|
||||
break;
|
||||
if (view.getId() == R.id.footerview_item) {
|
||||
if (mAdapter.isNetworkError()) {
|
||||
mListViewModel.load(LoadType.RETRY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void showDeleteDialog(String answerId) {
|
||||
DialogUtils.showCancelAlertDialog(getContext(), "提示"
|
||||
, "内容已被删除,是否取消收藏?"
|
||||
, "取消收藏", "暂不"
|
||||
, () -> CollectionUtils.INSTANCE.deleteCollection(getContext(), answerId
|
||||
, CollectionUtils.CollectionType.answer, new CollectionUtils.OnCollectionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
toast(R.string.collection_cancel);
|
||||
mListViewModel.load(LoadType.REFRESH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
toast(R.string.collection_cancel_failure);
|
||||
}
|
||||
}), null);
|
||||
}
|
||||
|
||||
// 收藏事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBCollectionChanged changed) {
|
||||
|
||||
@ -1,18 +1,16 @@
|
||||
package com.gh.gamecenter.collection
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Paint
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import anet.channel.util.Utils.context
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.databinding.CollectionComunityArticleItemBinding
|
||||
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
|
||||
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
|
||||
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
|
||||
@ -30,7 +28,7 @@ class CommunityArticleAdapter(context: Context,
|
||||
return ItemViewType.ITEM_BODY
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val view: View
|
||||
return when (viewType) {
|
||||
ItemViewType.ITEM_FOOTER -> {
|
||||
@ -38,8 +36,8 @@ class CommunityArticleAdapter(context: Context,
|
||||
FooterViewHolder(view)
|
||||
}
|
||||
else -> {
|
||||
view = mLayoutInflater.inflate(R.layout.collection_comunity_article_item, parent, false)
|
||||
CollectionCommunityArticleViewHolder(CollectionComunityArticleItemBinding.bind(view))
|
||||
view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false)
|
||||
CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,35 +45,12 @@ class CommunityArticleAdapter(context: Context,
|
||||
override fun getItemCount(): Int = if (mEntityList.size == 0) 0 else mEntityList.size + 1
|
||||
|
||||
|
||||
override fun onBindViewHolder(holder: androidx.recyclerview.widget.RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is CollectionCommunityArticleViewHolder) {
|
||||
val path = "我的收藏-文章"
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is CommunityAnswerItemViewHolder) {
|
||||
val path = if (mType == CommunityArticleFragment.Type.COLLECTION) "我的收藏-文章列表" else "浏览记录-文章列表"
|
||||
val entity = mEntityList[position]
|
||||
holder.binding.data = entity
|
||||
holder.bindArticleItem(entity, mEntrance, path)
|
||||
|
||||
if (entity.active) {
|
||||
holder.binding.content.paint.flags = Paint.ANTI_ALIAS_FLAG
|
||||
holder.binding.content.setTextColor(ContextCompat.getColor(mContext, R.color.title))
|
||||
} else {
|
||||
holder.binding.content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
|
||||
holder.binding.content.setTextColor(ContextCompat.getColor(mContext, R.color.hint))
|
||||
}
|
||||
if (entity.user.badge != null) {
|
||||
holder.binding.sdvUserBadge.visibility = View.VISIBLE
|
||||
holder.binding.tvBadgeName.visibility = View.VISIBLE
|
||||
ImageUtils.display(holder.binding.sdvUserBadge, entity.user.badge!!.icon)
|
||||
holder.binding.tvBadgeName.text = entity.user.badge!!.name
|
||||
} else {
|
||||
holder.binding.sdvUserBadge.visibility = View.GONE
|
||||
holder.binding.tvBadgeName.visibility = View.GONE
|
||||
}
|
||||
val key = if (mType == CommunityArticleFragment.Type.COLLECTION) "我的收藏-文章列表" else "浏览记录-文章列表"
|
||||
holder.binding.sdvUserBadge.setOnClickListener { v ->
|
||||
MtaHelper.onEvent("进入徽章墙_用户记录", key, entity.user.name + "(" + entity.user.id + ")")
|
||||
MtaHelper.onEvent("徽章中心", "进入徽章中心", key)
|
||||
DirectUtils.directToBadgeWall(mContext, entity.user.id, entity.user.name, entity.user.icon)
|
||||
}
|
||||
holder.binding.tvBadgeName.setOnClickListener { v -> holder.binding.sdvUserBadge.performClick() }
|
||||
holder.itemView.setOnClickListener {
|
||||
if (entity.active) {
|
||||
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, entity.community, entity.id, mEntrance, path))
|
||||
@ -91,27 +66,6 @@ class CommunityArticleAdapter(context: Context,
|
||||
mViewModel.postCollectionArticleRead(entity.community.id, entity.id)
|
||||
}
|
||||
}
|
||||
holder.binding.userIconContainer.setOnClickListener {
|
||||
DirectUtils.directToHomeActivity(mContext, entity.user.id, mEntrance, path)
|
||||
}
|
||||
|
||||
holder.binding.userName.setOnClickListener {
|
||||
DirectUtils.directToHomeActivity(mContext, entity.user.id, mEntrance, path)
|
||||
}
|
||||
if (!entity.read) {
|
||||
holder.binding.title.post {
|
||||
val lineCount = holder.binding.title.lineCount
|
||||
if (lineCount > 0) {
|
||||
val lineWidth = holder.binding.title.layout.getLineWidth(lineCount - 1)
|
||||
val layoutParams = holder.binding.unreadHint.layoutParams as ConstraintLayout.LayoutParams
|
||||
layoutParams.setMargins(lineWidth.toInt(), 0, 0, DisplayUtils.dip2px(18f))
|
||||
holder.binding.unreadHint.layoutParams = layoutParams
|
||||
holder.binding.unreadHint.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holder.binding.unreadHint.visibility = View.GONE
|
||||
}
|
||||
} else if (holder is FooterViewHolder) {
|
||||
holder.initItemPadding()
|
||||
holder.initFooterViewHolder(mViewModel, mIsLoading, isNetworkError, mIsOver)
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.gh.gamecenter.qa.answer
|
||||
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Typeface
|
||||
import android.view.View
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
@ -13,14 +16,13 @@ import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Utils
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import retrofit2.HttpException
|
||||
|
||||
/**
|
||||
* 因为社区回答和社区文章的样式完全一样,所以就统一处理吧!
|
||||
* 因为社区回答和社区文章的样式完全一样,所以就统一处理吧!有需要时可以直接复制一份作为单独的社区文章样式
|
||||
*/
|
||||
class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : BaseRecyclerViewHolder<Any>(binding.root) {
|
||||
|
||||
@ -100,6 +102,8 @@ class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : B
|
||||
key = "问答-推荐"
|
||||
} else if (path == "问题详情" || path == "折叠答案") {
|
||||
key = path
|
||||
} else {
|
||||
key = path // 默认就使用path字段吧,总比为空的好
|
||||
}
|
||||
MtaHelper.onEvent("进入徽章墙_用户记录", key, user.name + "(" + user.id + ")")
|
||||
MtaHelper.onEvent("徽章中心", "进入徽章中心", key)
|
||||
@ -110,6 +114,31 @@ class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : B
|
||||
binding.userIcon.setOnClickListener(userClick)
|
||||
binding.userName.setOnClickListener(userClick)
|
||||
|
||||
// 内容修改时,再标题加上红点,一般用于收藏
|
||||
if (!entity.read) {
|
||||
binding.title.post {
|
||||
val lineCount = binding.title.lineCount
|
||||
if (lineCount > 0) {
|
||||
val lineWidth = binding.title.layout.getLineWidth(lineCount - 1)
|
||||
val layoutParams = binding.unreadHint.layoutParams as ConstraintLayout.LayoutParams
|
||||
layoutParams.setMargins(lineWidth.toInt(), 0, 0, DisplayUtils.dip2px(18f))
|
||||
binding.unreadHint.layoutParams = layoutParams
|
||||
binding.unreadHint.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
} else {
|
||||
binding.unreadHint.visibility = View.GONE
|
||||
}
|
||||
|
||||
// 如果当前回答/文章被删除则内容加上删除线,一般用于收藏
|
||||
if (entity.active) {
|
||||
binding.content.paint.flags = Paint.ANTI_ALIAS_FLAG
|
||||
binding.content.setTextColor(ContextCompat.getColor(itemView.context, R.color.text_666666))
|
||||
} else {
|
||||
binding.content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
|
||||
binding.content.setTextColor(ContextCompat.getColor(itemView.context, R.color.hint))
|
||||
}
|
||||
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,10 @@ data class ArticleEntity(
|
||||
answer.user = user
|
||||
answer.time = time?.create
|
||||
answer.vote = count.vote
|
||||
answer.active = active
|
||||
answer.commentCount = count.comment
|
||||
answer.orderTag = orderTag
|
||||
answer.read = read
|
||||
return answer
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user