修改社区文章/回答列表样式

This commit is contained in:
kehaoyuan@ghzhushou.com
2020-02-17 14:26:37 +08:00
parent 51c152ca5e
commit 7c2f411a48
9 changed files with 62 additions and 249 deletions

View File

@ -7,14 +7,15 @@ import com.gh.common.util.MtaHelper
import com.gh.common.util.StringUtils
import com.gh.common.util.visibleIf
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
import com.gh.gamecenter.entity.CommunityEntity
import com.gh.gamecenter.gamedetail.fuli.FuLiViewModel
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
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.qa.recommends.AskQuestionsRecommendsViewHolder
import com.halo.assistant.HaloApp
import com.lightgame.adapter.BaseRecyclerAdapter
@ -22,17 +23,17 @@ class GameDetailAnswerAdapter(context: Context,
var mViewModel: FuLiViewModel,
private val mAnswerList: List<AnswerEntity>,
private val mEntrance: String)
: BaseRecyclerAdapter<AskQuestionsRecommendsViewHolder>(context) {
: BaseRecyclerAdapter<CommunityAnswerItemViewHolder>(context) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AskQuestionsRecommendsViewHolder {
val view = mLayoutInflater.inflate(R.layout.ask_questions_hot_item, parent, false)
return AskQuestionsRecommendsViewHolder(view)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommunityAnswerItemViewHolder {
val view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false)
return CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view))
}
override fun getItemCount(): Int = mAnswerList.size
override fun onBindViewHolder(holder: AskQuestionsRecommendsViewHolder, position: Int) {
holder.mLine.visibleIf(position > 0)
override fun onBindViewHolder(holder: CommunityAnswerItemViewHolder, position: Int) {
holder.binding.topLine.visibleIf(position > 0)
val entity = mAnswerList[position]
if ("community_article" == entity.type) {
val questions = Questions()
@ -40,8 +41,8 @@ class GameDetailAnswerAdapter(context: Context,
entity.questions = questions
}
val path = "游戏详情-动态"
holder.initQuestionsHotViewHolder(mContext, entity, mEntrance, path)
holder.mAskTitle.setOnClickListener {
holder.bindAnswerItem(entity, mEntrance, path)
holder.binding.title.setOnClickListener {
HaloApp.put(Constants.GAME_DETAIL_COME_IN, true)
MtaHelper.onEvent("进入问答", "游戏详情", mViewModel.gameCommunity?.name + "+" + mViewModel.game.name)
if ("community_article" == entity.type) {

View File

@ -42,7 +42,7 @@ class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : B
binding.userName.setOnClickListener(userClick)
}
fun bindArticleItem(entity: ArticleEntity) {
fun bindArticleItem(entity: ArticleEntity, entrance: String, path: String) {
bindAnswerItem(entity.transformAnswerEntity(),entrance, path)
}
}

View File

@ -8,11 +8,12 @@ import com.gh.common.constant.ItemViewType
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
import com.gh.gamecenter.manager.UserManager
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
import com.gh.gamecenter.qa.entity.ArticleEntity
import com.gh.gamecenter.qa.entity.Questions
import com.gh.gamecenter.qa.recommends.AskQuestionsRecommendsViewHolder
class SimpleArticleListAdapter(context: Context) : ListAdapter<ArticleEntity>(context) {
@ -33,8 +34,8 @@ class SimpleArticleListAdapter(context: Context) : ListAdapter<ArticleEntity>(co
FooterViewHolder(view)
}
else -> {
view = mLayoutInflater.inflate(R.layout.ask_questions_hot_item, parent, false)
AskQuestionsRecommendsViewHolder(view)
view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false)
CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view))
}
}
}
@ -46,12 +47,12 @@ class SimpleArticleListAdapter(context: Context) : ListAdapter<ArticleEntity>(co
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (getItemViewType(position)) {
ItemViewType.ITEM_BODY -> {
val viewHolder = holder as AskQuestionsRecommendsViewHolder
val viewHolder = holder as CommunityAnswerItemViewHolder
val articleEntity = mEntityList[position]
val questions = Questions()
questions.title = articleEntity.title
viewHolder.initArticleViewHolder(mContext, articleEntity, "", getPath())
viewHolder.mAskTitle.setOnClickListener {
viewHolder.bindArticleItem(articleEntity, "", getPath())
viewHolder.binding.title.setOnClickListener {
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, UserManager.getInstance().community, articleEntity.id, "", getPath()))
}

View File

@ -8,14 +8,15 @@ import com.gh.common.util.ImageUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
import com.gh.gamecenter.entity.SpecialColumn
import com.gh.gamecenter.manager.UserManager
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
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.qa.recommends.AskQuestionsRecommendsViewHolder
class HotAdapter(context: Context,
private val mEntrance: String,
@ -32,7 +33,8 @@ class HotAdapter(context: Context,
FooterViewHolder(mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false))
}
else -> {
AskQuestionsRecommendsViewHolder(mLayoutInflater.inflate(R.layout.ask_questions_hot_item, parent, false))
val view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false)
CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view))
}
}
}
@ -42,14 +44,14 @@ class HotAdapter(context: Context,
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is AskQuestionsRecommendsViewHolder) {
if (holder is CommunityAnswerItemViewHolder) {
val answerEntity = mEntityList[position]
if ("community_article" == answerEntity.type) {
val questions = Questions()
questions.title = answerEntity.articleTitle
answerEntity.questions = questions
}
holder.initQuestionsHotViewHolder(mContext, answerEntity, mEntrance, mPath)
holder.bindAnswerItem(answerEntity, mEntrance, mPath)
holder.itemView.setOnClickListener {
if ("community_article" == answerEntity.type) {
mContext.startActivity(
@ -64,7 +66,7 @@ class HotAdapter(context: Context,
mContext.startActivity(AnswerDetailActivity.getIntent(mContext, answerEntity.id, mEntrance, mPath, mSpecialColumn))
}
}
holder.mAskTitle.setOnClickListener {
holder.binding.title.setOnClickListener {
if ("community_article" == answerEntity.type) {
mContext.startActivity(
ArticleDetailActivity.getIntent(
@ -79,7 +81,6 @@ class HotAdapter(context: Context,
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, questions.id, mEntrance, mPath, mSpecialColumn))
}
}
answerEntity.user.auth?.let { ImageUtils.display(holder.badgeIcon, it.icon) }
} else if (holder is FooterViewHolder) {
holder.initItemPadding()
holder.initFooterViewHolder(mIsLoading, mIsNetworkError, mIsOver, R.string.ask_loadover_hint)

View File

@ -8,14 +8,15 @@ import com.gh.common.util.ImageUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
import com.gh.gamecenter.entity.SpecialColumn
import com.gh.gamecenter.manager.UserManager
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
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.qa.recommends.AskQuestionsRecommendsViewHolder
class RecommendsAdapter(context: Context,
private val mEntrance: String,
@ -32,7 +33,8 @@ class RecommendsAdapter(context: Context,
FooterViewHolder(mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false))
}
else -> {
AskQuestionsRecommendsViewHolder(mLayoutInflater.inflate(R.layout.ask_questions_hot_item, parent, false))
val view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false)
CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view))
}
}
}
@ -42,14 +44,14 @@ class RecommendsAdapter(context: Context,
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is AskQuestionsRecommendsViewHolder) {
if (holder is CommunityAnswerItemViewHolder) {
val answerEntity = mEntityList[position]
if ("community_article" == answerEntity.type) {
val questions = Questions()
questions.title = answerEntity.articleTitle
answerEntity.questions = questions
}
holder.initQuestionsHotViewHolder(mContext, answerEntity, mEntrance, mPath)
holder.bindAnswerItem(answerEntity, mEntrance, mPath)
holder.itemView.setOnClickListener {
if ("community_article" == answerEntity.type) {
mContext.startActivity(
@ -63,7 +65,7 @@ class RecommendsAdapter(context: Context,
mContext.startActivity(AnswerDetailActivity.getIntent(mContext, answerEntity.id, mEntrance, mPath, mSpecialColumn))
}
}
holder.mAskTitle.setOnClickListener {
holder.binding.title.setOnClickListener {
if ("community_article" == answerEntity.type) {
mContext.startActivity(
ArticleDetailActivity.getIntent(mContext,
@ -77,10 +79,6 @@ class RecommendsAdapter(context: Context,
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, questions.id, mEntrance, mPath, mSpecialColumn))
}
}
if (answerEntity.user.auth != null) {
ImageUtils.display(holder.badgeIcon, answerEntity.user.auth!!.icon)
}
} else if (holder is FooterViewHolder) {
holder.initItemPadding()
holder.initFooterViewHolder(mIsLoading, mIsNetworkError, mIsOver, R.string.ask_loadover_hint)

View File

@ -30,13 +30,28 @@ data class ArticleEntity(
var time: TimeEntity? = TimeEntity(),
var user: UserEntity = UserEntity()) : Parcelable {
fun getPassVideos(): List<CommunityVideoEntity> {
val passVideos = arrayListOf<CommunityVideoEntity>()
for (video in videos) {
if (video.status == "pass") passVideos.add(video)
}
return passVideos
fun getPassVideos(): List<CommunityVideoEntity> {
val passVideos = arrayListOf<CommunityVideoEntity>()
for (video in videos) {
if (video.status == "pass") passVideos.add(video)
}
return passVideos
}
fun transformAnswerEntity() : AnswerEntity{
val question = Questions(title = title)
val answer = AnswerEntity()
answer.id = id
answer.questions = question
answer.brief = brief
answer.images = images
answer.videos = videos
answer.user = user
answer.time = time?.create
answer.vote = count.vote
answer.commentCount = count.comment
return answer
}
}
@Parcelize

View File

@ -22,13 +22,14 @@ import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
import com.gh.gamecenter.adapter.viewholder.ReuseViewHolder
import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
import com.gh.gamecenter.entity.CommunityEntity
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
import com.gh.gamecenter.qa.column.detail.AskColumnDetailActivity
import com.gh.gamecenter.qa.entity.InviteEntity
import com.gh.gamecenter.qa.entity.QuestionsDetailEntity
import com.gh.gamecenter.qa.questions.invite.QuestionsInviteAdapter
import com.gh.gamecenter.qa.recommends.AskQuestionsRecommendsViewHolder
import com.gh.gamecenter.video.VideoVerifyItemViewHolder
import com.google.android.flexbox.FlexboxLayout
@ -104,8 +105,8 @@ class QuestionsDetailAdapter(
return RecommendedUserToInviteViewHolder(view)
}
TYPE_SIMILAR_ANSWER -> {
view = mLayoutInflater.inflate(R.layout.ask_questions_hot_item, parent, false)
return AskQuestionsRecommendsViewHolder(view)
view = mLayoutInflater.inflate(R.layout.community_answer_item, parent, false)
return CommunityAnswerItemViewHolder(CommunityAnswerItemBinding.bind(view))
}
else -> {
view = mLayoutInflater.inflate(R.layout.reuse_nodata_skip, parent, false)
@ -182,10 +183,10 @@ class QuestionsDetailAdapter(
TYPE_SIMILAR_ANSWER -> {
val index = position - TOP_ITEM_COUNT
if (index != -1) {
val viewHolder = holder as AskQuestionsRecommendsViewHolder
val answerEntity = mEntityList[index].similarAnswer
viewHolder.initQuestionsHotViewHolder(mContext, answerEntity, "", "问题推荐")
viewHolder.mAskTitle.setOnClickListener {
val viewHolder = holder as CommunityAnswerItemViewHolder
val answerEntity = mEntityList[index].similarAnswer?:return
viewHolder.bindAnswerItem(answerEntity, "", "问题推荐")
viewHolder.binding.title.setOnClickListener {
val questions = answerEntity?.questions
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, questions!!.id, "", "问题推荐"))
}

View File

@ -1,203 +0,0 @@
package com.gh.gamecenter.qa.recommends;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.base.BaseRecyclerViewHolder;
import com.gh.base.OnListClickListener;
import com.gh.common.util.DirectUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.MtaHelper;
import com.gh.common.util.NewsUtils;
import com.gh.common.util.NumberUtils;
import com.gh.common.view.DrawableView;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.UserEntity;
import com.gh.gamecenter.qa.entity.AnswerEntity;
import com.gh.gamecenter.qa.entity.ArticleEntity;
import com.gh.gamecenter.qa.entity.CommunityVideoEntity;
import java.util.List;
import butterknife.BindView;
/**
* Created by khy on 4/12/17.
* see {@link com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder}
*/
@Deprecated
public class AskQuestionsRecommendsViewHolder extends BaseRecyclerViewHolder<AnswerEntity> {
@BindView(R.id.ask_item_usericon)
SimpleDraweeView mAskUsericon;
@BindView(R.id.ask_item_user_badge)
public SimpleDraweeView badgeIcon;
@BindView(R.id.ask_item_username)
TextView mAskUsername;
@BindView(R.id.ask_item_title)
public TextView mAskTitle;
@BindView(R.id.ask_item_content)
TextView mAskContent;
@BindView(R.id.ask_item_img)
SimpleDraweeView mAskImg;
@BindView(R.id.ask_item_votecount)
TextView mAskVotecount;
@BindView(R.id.ask_item_answercount)
TextView mAskAnswerCount;
@BindView(R.id.ask_item_end_desc)
TextView mAskEndDesc;
@BindView(R.id.ask_item_line)
public View mLine;
@BindView(R.id.ask_item_video_duration)
TextView mVideoDuration;
@BindView(R.id.ask_item_video_play)
View mVideoPlayIcon;
@BindView(R.id.sdv_user_badge)
SimpleDraweeView userBadgeSdv;
@BindView(R.id.tv_badge_name)
TextView badgeNameTv;
public AskQuestionsRecommendsViewHolder(View itemView, OnListClickListener listClickListener) {
super(itemView, listClickListener);
itemView.setOnClickListener(this);
mAskTitle.setOnClickListener(this);
}
public AskQuestionsRecommendsViewHolder(View itemView) {
super(itemView);
}
public void initQuestionsHotViewHolder(Context context, AnswerEntity entity, String entrance, String path) {
setClickData(entity);
mAskVotecount.setText(itemView.getContext().getString(R.string.ask_vote_count, NumberUtils.transSimpleCount(entity.getVote())));
// 3.6.3 产品说隐藏掉评论
mAskAnswerCount.setVisibility(View.GONE);
mAskAnswerCount.setText(String.format("%s 评论", NumberUtils.transSimpleCount(entity.getCommentCount())));
mAskContent.setText(entity.getBrief());
UserEntity user = entity.getUser();
mAskUsername.setText(user.getName());
ImageUtils.displayIcon(mAskUsericon, user.getIcon());
if (user.getAuth() != null) {
ImageUtils.display(badgeIcon, user.getAuth().getIcon());
} else {
ImageUtils.display(badgeIcon, "");
}
if (user.getBadge() != null) {
userBadgeSdv.setVisibility(View.VISIBLE);
badgeNameTv.setVisibility(View.VISIBLE);
ImageUtils.display(userBadgeSdv, user.getBadge().getIcon());
badgeNameTv.setText(user.getBadge().getName());
} else {
userBadgeSdv.setVisibility(View.GONE);
badgeNameTv.setVisibility(View.GONE);
}
userBadgeSdv.setOnClickListener(v -> {
String key = "";
if (path.equals("标签专栏-热门")) {
key = "问题标签详情-热门";
} else if (path.equals("标签专栏-精华")) {
key = "问题标签详情-精华";
} else if (path.equals("专栏-热门")) {
key = "问答-专栏详情-热门";
} else if (path.equals("专栏-精华")) {
key = "问答-专栏详情-精华";
} /*else if (path.equals("问题推荐")) {
key = "问答-推荐";
}*/ else if (path.equals("游戏详情-动态")) {
key = "游戏详情-热门回答";
} else if (path.equals("问答-推荐-按精选") || path.equals("问答-推荐-按时间")) {
key = "问答-推荐";
}
MtaHelper.onEvent("进入徽章墙_用户记录", key, user.getName() + "" + user.getId() + "");
MtaHelper.onEvent("徽章中心", "进入徽章中心", key);
DirectUtils.directToBadgeWall(context, user.getId(), user.getName(), user.getIcon());
});
badgeNameTv.setOnClickListener(v -> userBadgeSdv.performClick());
mAskTitle.setText(entity.getQuestions().getTitle());
setAnswerImage(entity.getImages(), entity.getPassVideos(), path);
View.OnClickListener userClick = v -> DirectUtils.directToHomeActivity(context, entity.getUser().getId(), entrance, path);
mAskUsericon.setOnClickListener(userClick);
mAskUsername.setOnClickListener(userClick);
if (entity.getTime() != null && entity.getTime() != 0) {
mAskEndDesc.setText(NewsUtils.getFormattedTime(entity.getTime()));
}
}
public void initArticleViewHolder(Context context, ArticleEntity entity, String entrance, String path) {
mAskVotecount.setText(itemView.getContext().getString(R.string.ask_vote_count, NumberUtils.transSimpleCount(entity.getCount().getVote())));
// 3.6.3 产品说隐藏掉评论
mAskAnswerCount.setVisibility(View.GONE);
mAskContent.setText(entity.getBrief());
UserEntity user = entity.getUser();
mAskUsername.setText(user.getName());
ImageUtils.displayIcon(mAskUsericon, user.getIcon());
if (user.getAuth() != null) {
ImageUtils.display(badgeIcon, user.getAuth().getIcon());
} else {
ImageUtils.display(badgeIcon, "");
}
if (user.getBadge() != null) {
userBadgeSdv.setVisibility(View.VISIBLE);
badgeNameTv.setVisibility(View.VISIBLE);
ImageUtils.display(userBadgeSdv, user.getBadge().getIcon());
badgeNameTv.setText(user.getBadge().getName());
} else {
userBadgeSdv.setVisibility(View.GONE);
badgeNameTv.setVisibility(View.GONE);
}
userBadgeSdv.setOnClickListener(v -> {
MtaHelper.onEvent("进入徽章墙_用户记录", "问答-全部-文章", user.getName() + "" + user.getName() + "");
MtaHelper.onEvent("徽章中心", "进入徽章中心", "问答-全部-文章");
DirectUtils.directToBadgeWall(context, user.getId(), user.getName(), user.getIcon());
});
badgeNameTv.setOnClickListener(v -> userBadgeSdv.performClick());
mAskTitle.setText(entity.getTitle());
setAnswerImage(entity.getImages(), entity.getPassVideos(), path);
View.OnClickListener userClick = v -> DirectUtils.directToHomeActivity(context, entity.getUser().getId(), entrance, path);
mAskUsericon.setOnClickListener(userClick);
mAskUsername.setOnClickListener(userClick);
if (entity.getTime() != null && entity.getTime().getCreate() != 0) {
mAskEndDesc.setText(NewsUtils.getFormattedTime(entity.getTime().getCreate()));
}
}
private void setAnswerImage( List<String> images, List<CommunityVideoEntity> videos, String path) {
if (videos.size() > 0) {
CommunityVideoEntity videoEntity = videos.get(0);
ImageUtils.display(mAskImg, videoEntity.getPoster());
mVideoDuration.setBackground(DrawableView.getOvalDrawable(R.color.black_alpha_80, 999F));
mVideoDuration.setText(videoEntity.getDuration());
mVideoPlayIcon.setVisibility(View.VISIBLE);
mVideoDuration.setVisibility(View.VISIBLE);
mAskImg.setVisibility(View.VISIBLE);
} else if (images.size() > 0) {
mAskImg.setVisibility(View.VISIBLE);
ImageUtils.display(mAskImg, images.get(0));
mVideoPlayIcon.setVisibility(View.GONE);
mVideoDuration.setVisibility(View.GONE);
} else {
mAskImg.setVisibility(View.GONE);
mVideoPlayIcon.setVisibility(View.GONE);
mVideoDuration.setVisibility(View.GONE);
}
}
}

View File

@ -16,7 +16,6 @@ import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
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.qa.recommends.AskQuestionsRecommendsViewHolder
open class RecommendNewestAdapter(context: Context) : ListAdapter<AnswerEntity>(context) {