光环前端优化汇总(2020年5月第2周)(问答相关)https://gitlab.ghzs.com/pm/halo-app-issues/-/issues/858
This commit is contained in:
@ -1,7 +1,11 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.gh.common.annotation.SyncPage
|
||||
import com.gh.common.syncpage.SyncFieldConstants
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.qa.entity.CommunityVideoEntity
|
||||
import com.gh.gamecenter.qa.entity.Questions
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@ -21,7 +25,8 @@ data class PersonalHistoryEntity(
|
||||
@SerializedName("fold_users")
|
||||
var foldUsers: List<UserEntity>? = null,
|
||||
val images: List<String> = ArrayList(),
|
||||
var comment: Comment = Comment()) :Parcelable{
|
||||
val me: MeEntity = MeEntity(),
|
||||
var comment: Comment = Comment()) : Parcelable {
|
||||
|
||||
fun getPassVideos(): List<CommunityVideoEntity> {
|
||||
val passVideos = arrayListOf<CommunityVideoEntity>()
|
||||
@ -36,20 +41,25 @@ data class PersonalHistoryEntity(
|
||||
data class Question(
|
||||
@SerializedName("_id")
|
||||
val id: String = "",
|
||||
var title: String = ""):Parcelable
|
||||
var title: String = "") : Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class Count(
|
||||
@SyncPage(syncNames = [SyncFieldConstants.ANSWER_COMMENT_COUNT, SyncFieldConstants.ARTICLE_COMMENT_COUNT])
|
||||
var comment: Int = -1,
|
||||
@SyncPage(syncNames = [SyncFieldConstants.ANSWER_VOTE_COUNT, SyncFieldConstants.ARTICLE_VOTE_COUNT])
|
||||
var vote: Int = -1,
|
||||
@SyncPage(syncNames = [SyncFieldConstants.ANSWER_COUNT])
|
||||
var answer: Int = -1,
|
||||
var reply: Int = -1):Parcelable
|
||||
var reply: Int = -1) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class Comment(
|
||||
@SerializedName("_id")
|
||||
val id: String = "",
|
||||
var star: Int = 0,
|
||||
var content: String = "",
|
||||
val game: Game = Game()):Parcelable
|
||||
val game: Game = Game()) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class Game(
|
||||
@ -67,4 +77,34 @@ data class PersonalHistoryEntity(
|
||||
var isLibaoExists: Boolean = false,
|
||||
val active: Boolean = true//游戏是否被隐藏 false被隐藏
|
||||
) : Parcelable
|
||||
|
||||
|
||||
// 因为内容是文章和回答混合的,所以返回的有可能是文章的实体
|
||||
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.time = time
|
||||
answer.vote = count.vote
|
||||
answer.commentCount = count.comment
|
||||
answer.me = me
|
||||
if (type.contains("article")) {
|
||||
answer.type = "community_article"
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
fun transformQuestionEntity(): Questions {
|
||||
val question = Questions(title = title)
|
||||
question.answerCount = count.answer
|
||||
question.me = me
|
||||
question.id = id
|
||||
question.images = images as ArrayList<String>
|
||||
question.communityName = community.name
|
||||
return question
|
||||
}
|
||||
}
|
||||
@ -37,8 +37,8 @@ class GameDetailAnswerAdapter(context: Context,
|
||||
|
||||
override fun onBindViewHolder(holder: CommunityAnswerItemViewHolder, position: Int) {
|
||||
holder.binding.contentContainer.setBackgroundColor(ContextCompat.getColor(mContext,R.color.transparent))
|
||||
holder.binding.commentCountContainer.setBackgroundColor(ContextCompat.getColor(mContext,R.color.transparent))
|
||||
holder.binding.voteCountContainer.setBackgroundColor(ContextCompat.getColor(mContext,R.color.transparent))
|
||||
holder.commentCountContainer.setBackgroundColor(ContextCompat.getColor(mContext,R.color.transparent))
|
||||
holder.voteCountContainer.setBackgroundColor(ContextCompat.getColor(mContext,R.color.transparent))
|
||||
holder.binding.contentContainer.setPadding(DisplayUtils.dip2px(12f),0,DisplayUtils.dip2px(12f),0)
|
||||
|
||||
holder.binding.topLine.visibleIf(position > 0)
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package com.gh.gamecenter.personalhome
|
||||
|
||||
import android.view.View
|
||||
import com.gh.gamecenter.databinding.PersonalHomeItemBinding
|
||||
import com.gh.gamecenter.entity.PersonalHistoryEntity
|
||||
import com.gh.gamecenter.qa.answer.BaseAnswerOrArticleItemViewHolder
|
||||
import com.gh.gamecenter.qa.questions.CommunityQuestionViewHolder
|
||||
|
||||
class PersonalItemViewHolder(val binding: PersonalHomeItemBinding) : BaseAnswerOrArticleItemViewHolder(binding.root) {
|
||||
|
||||
fun bindPersonalItem(entity: PersonalHistoryEntity, entrance: String) {
|
||||
commentCountContainer.isClickable = true
|
||||
if (entity.type.contains("question")) {
|
||||
voteCountContainer.visibility = View.INVISIBLE
|
||||
CommunityQuestionViewHolder.bindAnswerCount(
|
||||
entity.transformQuestionEntity(),
|
||||
commentCountContainer,
|
||||
commentCount,
|
||||
entrance)
|
||||
} else {
|
||||
voteCountContainer.visibility = View.VISIBLE
|
||||
bindCommendAndVote(entity.transformAnswerEntity(), entrance)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,5 @@ package com.gh.gamecenter.personalhome
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.gamecenter.databinding.FollowersOrFansItemBinding
|
||||
import com.gh.gamecenter.databinding.PersonalHomeItemBinding
|
||||
|
||||
class PersonalItemViewHolder(val binding: PersonalHomeItemBinding): BaseRecyclerViewHolder<Any>(binding.root)
|
||||
class FollowersOrFansViewHolder(val binding: FollowersOrFansItemBinding) : BaseRecyclerViewHolder<Any>(binding.root)
|
||||
@ -26,7 +26,9 @@ import java.util.regex.Pattern
|
||||
|
||||
class UserHistoryAdapter(context: Context,
|
||||
private val mListViewModel: UserHistoryViewModel,
|
||||
private val mEntrance: String, val itemClickCallback: (historyEntity: PersonalHistoryEntity, position: Int) -> Unit) : ListAdapter<PersonalHistoryEntity>(context) {
|
||||
private val mEntrance: String,
|
||||
val itemClickCallback: (historyEntity: PersonalHistoryEntity, position: Int) -> Unit)
|
||||
: ListAdapter<PersonalHistoryEntity>(context) {
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when {
|
||||
@ -66,17 +68,12 @@ class UserHistoryAdapter(context: Context,
|
||||
}
|
||||
|
||||
private fun bindNormalItem(holder: PersonalItemViewHolder, position: Int) {
|
||||
holder.binding.root.setPadding(20F.dip2px(), if (position == 0) 0 else 16F.dip2px(), 20F.dip2px(), 0)
|
||||
|
||||
val historyEntity = mEntityList[holder.adapterPosition]
|
||||
|
||||
// 微调约束,将问题标题放到用户头像下面
|
||||
val constraintSet = ConstraintSet()
|
||||
constraintSet.clone(holder.binding.constraintLayout)
|
||||
constraintSet.connect(R.id.user_icon_container, ConstraintSet.TOP, R.id.constraint_layout, ConstraintSet.TOP)
|
||||
constraintSet.connect(R.id.question_title, ConstraintSet.TOP, R.id.user_icon_container, ConstraintSet.BOTTOM, DisplayUtils.dip2px(9F))
|
||||
constraintSet.connect(R.id.answer_content, ConstraintSet.TOP, R.id.question_title, ConstraintSet.BOTTOM)
|
||||
constraintSet.applyTo(holder.binding.constraintLayout)
|
||||
holder.bindPersonalItem(historyEntity, mEntrance)
|
||||
|
||||
val path = "个人主页-问答"
|
||||
holder.binding.run {
|
||||
entity = historyEntity
|
||||
endDesc.text = entity?.community?.name
|
||||
@ -85,13 +82,6 @@ class UserHistoryAdapter(context: Context,
|
||||
userCommand.text = if (!command.isEmpty()) command else historyEntity?.user?.name + ""
|
||||
|
||||
questionTitle.setOnClickListener {
|
||||
/*if ("community_article" == historyEntity.type || "community_article_vote" == historyEntity.type) {
|
||||
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, historyEntity.community, historyEntity.id, mEntrance, path))
|
||||
} else {
|
||||
val id = if (historyEntity.type.contains("question")) historyEntity.id
|
||||
else historyEntity?.question?.id
|
||||
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, id, mEntrance, path))
|
||||
}*/
|
||||
holder.itemView.performClick()
|
||||
}
|
||||
|
||||
@ -100,13 +90,6 @@ class UserHistoryAdapter(context: Context,
|
||||
userCommand.setOnClickListener {}
|
||||
}
|
||||
holder.itemView.setOnClickListener {
|
||||
/*if ("community_article" == historyEntity.type || "community_article_vote" == historyEntity.type) {
|
||||
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, historyEntity.community, historyEntity.id, mEntrance, path))
|
||||
} else if (!historyEntity.type.contains("question")) {
|
||||
mContext.startActivity(AnswerDetailActivity.getIntent(mContext, historyEntity.id, mEntrance, path))
|
||||
} else if (historyEntity.type.contains("question")) {
|
||||
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, historyEntity.id, mEntrance, path))
|
||||
}*/
|
||||
itemClickCallback.invoke(historyEntity, position)
|
||||
}
|
||||
}
|
||||
@ -130,8 +113,6 @@ class UserHistoryAdapter(context: Context,
|
||||
GameDetailActivity.startGameDetailActivity(mContext, historyEntity.comment.game.id, mEntrance)
|
||||
}
|
||||
holder.binding.root.setOnClickListener {
|
||||
// val intent = RatingReplyActivity.getIntent(holder.binding.root.context, historyEntity.comment.game.id, historyEntity.comment.id, mEntrance, "个人主页-评论")
|
||||
// holder.binding.root.context.startActivity(intent)
|
||||
itemClickCallback.invoke(historyEntity, position)
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,366 @@
|
||||
package com.gh.gamecenter.qa.answer
|
||||
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.airbnb.lottie.LottieAnimationView
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.VoteEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.qa.comment.CommentActivity
|
||||
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.lightgame.utils.Utils
|
||||
import com.lightgame.view.CheckableImageView
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import retrofit2.HttpException
|
||||
|
||||
/**
|
||||
* 主要实现文章/回答的点赞和评论操作
|
||||
*/
|
||||
open class BaseAnswerOrArticleItemViewHolder(itemView: View) : BaseRecyclerViewHolder<Any>(itemView) {
|
||||
|
||||
val voteIcon: CheckableImageView = itemView.findViewById(R.id.vote_icon)
|
||||
val voteCount: TextView = itemView.findViewById(R.id.vote_count)
|
||||
val commentCount: TextView = itemView.findViewById(R.id.comment_count)
|
||||
val voteAnimation: LottieAnimationView = itemView.findViewById(R.id.vote_animation)
|
||||
val commentCountContainer: View = itemView.findViewById(R.id.comment_count_container)
|
||||
val voteCountContainer: View = itemView.findViewById(R.id.vote_count_container)
|
||||
|
||||
|
||||
fun bindCommendAndVote(entity: AnswerEntity, entrance: String) {
|
||||
binNormalView(entity)
|
||||
|
||||
commentCountContainer.setOnClickListener {
|
||||
if (filterIllegalCommentStatus(entity.commentable, entity.active)) return@setOnClickListener
|
||||
|
||||
if (entity.type == "community_article") {
|
||||
val communityId = if (entity.articleCommunityId.isNotEmpty()) entity.articleCommunityId
|
||||
else UserManager.getInstance().community.id
|
||||
val intent = CommentActivity.getArticleCommentIntent(itemView.context,
|
||||
entity.id!!,
|
||||
entity.commentCount,
|
||||
"", entity.commentCount == 0, communityId)
|
||||
itemView.context.startActivity(intent)
|
||||
} else {
|
||||
val intent = CommentActivity.getAnswerCommentIntent(itemView.context,
|
||||
entity.id!!,
|
||||
entity.commentCount,
|
||||
"", entity.commentCount == 0)
|
||||
itemView.context.startActivity(intent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
voteCountContainer.setOnClickListener {
|
||||
if (filterIllegalVoteStatus(entity.active)) return@setOnClickListener
|
||||
|
||||
debounceActionWithInterval(R.id.container_like, 1000) {
|
||||
CheckLoginUtils.checkLogin(itemView.context, entrance) {
|
||||
if (!voteIcon.isChecked) voteAnswer(entity)
|
||||
else cancelAnswerVote(entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bindCommendAndVote(entity: ArticleEntity, entrance: String) {
|
||||
binNormalView(entity.transformAnswerEntity())
|
||||
|
||||
commentCountContainer.setOnClickListener {
|
||||
if (filterIllegalCommentStatus(entity.commentable, entity.active)) return@setOnClickListener
|
||||
|
||||
val communityId = if (entity.community.id.isNotEmpty()) entity.community.id
|
||||
else UserManager.getInstance().community.id
|
||||
val intent = CommentActivity.getArticleCommentIntent(itemView.context,
|
||||
entity.id,
|
||||
entity.count.comment,
|
||||
"", entity.count.comment == 0, communityId)
|
||||
itemView.context.startActivity(intent)
|
||||
}
|
||||
|
||||
voteCountContainer.setOnClickListener {
|
||||
if (filterIllegalVoteStatus(entity.active)) return@setOnClickListener
|
||||
|
||||
debounceActionWithInterval(R.id.container_like, 1000) {
|
||||
CheckLoginUtils.checkLogin(itemView.context, entrance) {
|
||||
if (!voteIcon.isChecked) voteArticle(entity)
|
||||
else cancelArticleVote(entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun binNormalView(entity: AnswerEntity) {
|
||||
setVoteAndCommentStyle(entity)
|
||||
commentCount.text = if (entity.commentCount > 0) entity.commentCount.toString() else "评论"
|
||||
voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
}
|
||||
|
||||
private fun setVoteAndCommentStyle(entity: AnswerEntity) {
|
||||
|
||||
if (!entity.active) {
|
||||
voteIcon.setImageResource(R.drawable.community_vote_unavailable)
|
||||
voteCount.setTextColor(R.color.text_cccccc.toColor())
|
||||
} else if (entity.me.isCommunityArticleVote || entity.me.isAnswerVoted) {
|
||||
voteIcon.setImageResource(R.drawable.community_vote_selector)
|
||||
voteIcon.isChecked = true
|
||||
voteCount.setTextColor(R.color.theme_font.toColor())
|
||||
} else {
|
||||
voteIcon.setImageResource(R.drawable.community_vote_selector)
|
||||
voteIcon.isChecked = false
|
||||
voteCount.setTextColor(R.color.text_999999.toColor())
|
||||
}
|
||||
|
||||
if (entity.commentable && entity.active) {
|
||||
val commentIcon = itemView.context.resources.getDrawable(R.drawable.community_comment_count)
|
||||
commentIcon.setBounds(0, 0, commentIcon.minimumWidth, commentIcon.minimumHeight)
|
||||
commentCount.setCompoundDrawables(commentIcon, null, null, null)
|
||||
commentCount.setTextColor(R.color.text_999999.toColor())
|
||||
} else {
|
||||
val commentCloseIcon = itemView.context.resources.getDrawable(R.drawable.community_comment_count_unavailable)
|
||||
commentCloseIcon.setBounds(0, 0, commentCloseIcon.minimumWidth, commentCloseIcon.minimumHeight)
|
||||
commentCount.setCompoundDrawables(commentCloseIcon, null, null, null)
|
||||
commentCount.setTextColor(R.color.text_cccccc.toColor())
|
||||
}
|
||||
}
|
||||
|
||||
private fun voteAnswer(entity: AnswerEntity) {
|
||||
entity.vote = entity.vote + 1
|
||||
voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
playVoteAnimation()
|
||||
|
||||
val voteObservable = if (entity.type == "community_article") {
|
||||
val communityId = if (entity.articleCommunityId.isNotEmpty()) entity.articleCommunityId
|
||||
else UserManager.getInstance().community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleVote(communityId, entity.id)
|
||||
} else {
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postAnswerVote(entity.id)
|
||||
}
|
||||
voteObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
} else {
|
||||
entity.me.isAnswerVoted = true
|
||||
}
|
||||
Utils.toast(itemView.context, "已赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity)
|
||||
true
|
||||
} else {
|
||||
entity.vote = entity.vote - 1
|
||||
if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
} else {
|
||||
entity.me.isAnswerVoted = true
|
||||
}
|
||||
voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity)
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun cancelAnswerVote(entity: AnswerEntity) {
|
||||
entity.vote = entity.vote - 1
|
||||
|
||||
voteIcon.isChecked = false
|
||||
voteCount.setTextColor(R.color.text_999999.toColor())
|
||||
voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
|
||||
val unVoteObservable = if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = false
|
||||
|
||||
val communityId = if (entity.articleCommunityId.isNotEmpty()) entity.articleCommunityId
|
||||
else UserManager.getInstance().community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleUnVote(communityId, entity.id)
|
||||
} else {
|
||||
entity.me.isAnswerVoted = false
|
||||
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postAnswerUnvote(entity.id)
|
||||
}
|
||||
unVoteObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
Utils.toast(itemView.context, "取消赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity)
|
||||
true
|
||||
} else {
|
||||
entity.vote = entity.vote + 1
|
||||
if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
} else {
|
||||
entity.me.isAnswerVoted = true
|
||||
}
|
||||
voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity)
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun voteArticle(entity: ArticleEntity) {
|
||||
entity.count.vote = entity.count.vote + 1
|
||||
voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
playVoteAnimation()
|
||||
|
||||
val communityId = if (entity.community.id.isEmpty()) UserManager.getInstance().community.id
|
||||
else entity.community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleVote(communityId, entity.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
Utils.toast(itemView.context, "已赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
true
|
||||
} else {
|
||||
entity.count.vote = entity.count.vote - 1
|
||||
entity.me.isCommunityArticleVote = false
|
||||
voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun cancelArticleVote(entity: ArticleEntity) {
|
||||
entity.count.vote = entity.count.vote - 1
|
||||
entity.me.isCommunityArticleVote = false
|
||||
voteIcon.isChecked = false
|
||||
voteCount.setTextColor(R.color.text_999999.toColor())
|
||||
voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
|
||||
val communityId = if (entity.community.id.isEmpty()) UserManager.getInstance().community.id
|
||||
else entity.community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleUnVote(communityId, entity.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
Utils.toast(itemView.context, "取消赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
true
|
||||
} else {
|
||||
entity.count.vote = entity.count.vote + 1
|
||||
entity.me.isCommunityArticleVote = true
|
||||
voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun playVoteAnimation() {
|
||||
voteCount.setTextColor(R.color.theme_font.toColor())
|
||||
voteIcon.isChecked = true
|
||||
voteIcon.visibility = View.GONE
|
||||
voteAnimation.visibility = View.VISIBLE
|
||||
voteAnimation.setAnimation("lottie/community_vote.json")
|
||||
voteAnimation.playAnimation()
|
||||
voteAnimation.doOnAnimationEnd {
|
||||
voteAnimation.visibility = View.GONE
|
||||
voteIcon.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterIllegalCommentStatus(commentable: Boolean, active: Boolean): Boolean {
|
||||
if (!commentable) {
|
||||
Utils.toast(itemView.context, "作者已关闭评论")
|
||||
return true
|
||||
}
|
||||
|
||||
if (!active) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun filterIllegalVoteStatus(active: Boolean): Boolean {
|
||||
if (!active) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,7 +26,7 @@ import retrofit2.HttpException
|
||||
*
|
||||
* 注意:相当一部分页面时回答和文章混合的请注意区分
|
||||
*/
|
||||
class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : BaseRecyclerViewHolder<Any>(binding.root) {
|
||||
class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : BaseAnswerOrArticleItemViewHolder(binding.root) {
|
||||
|
||||
fun bindAnswerItem(entity: AnswerEntity, entrance: String, path: String) {
|
||||
bindAnswerItem(entity, false, entrance, path)
|
||||
@ -38,67 +38,16 @@ class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : B
|
||||
*/
|
||||
fun bindAnswerItem(entity: AnswerEntity, useAlternativeStyle: Boolean, entrance: String, path: String) {
|
||||
bindItem(entity, entrance, path)
|
||||
bindCommendAndVote(entity, entrance)
|
||||
|
||||
if (useAlternativeStyle) {
|
||||
changeToAlternativeStyle()
|
||||
}
|
||||
binding.commentCountContainer.setOnClickListener {
|
||||
if (filterIllegalCommentStatus(entity.commentable, entity.active)) return@setOnClickListener
|
||||
|
||||
if (entity.type == "community_article") {
|
||||
val communityId = if (entity.articleCommunityId.isNotEmpty()) entity.articleCommunityId
|
||||
else UserManager.getInstance().community.id
|
||||
val intent = CommentActivity.getArticleCommentIntent(itemView.context,
|
||||
entity.id!!,
|
||||
entity.commentCount,
|
||||
"", entity.commentCount == 0, communityId)
|
||||
itemView.context.startActivity(intent)
|
||||
} else {
|
||||
val intent = CommentActivity.getAnswerCommentIntent(itemView.context,
|
||||
entity.id!!,
|
||||
entity.commentCount,
|
||||
"", entity.commentCount == 0)
|
||||
itemView.context.startActivity(intent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
binding.voteCountContainer.setOnClickListener {
|
||||
if (filterIllegalVoteStatus(entity.active)) return@setOnClickListener
|
||||
|
||||
debounceActionWithInterval(R.id.container_like, 1000) {
|
||||
CheckLoginUtils.checkLogin(itemView.context, entrance) {
|
||||
if (!binding.voteIcon.isChecked) voteAnswer(entity)
|
||||
else cancelAnswerVote(entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bindArticleItem(entity: ArticleEntity, entrance: String, path: String) {
|
||||
bindItem(entity.transformAnswerEntity(), entrance, path)
|
||||
binding.commentCountContainer.setOnClickListener {
|
||||
if (filterIllegalCommentStatus(entity.commentable, entity.active)) return@setOnClickListener
|
||||
|
||||
val communityId = if (entity.community.id.isNotEmpty()) entity.community.id
|
||||
else UserManager.getInstance().community.id
|
||||
val intent = CommentActivity.getArticleCommentIntent(itemView.context,
|
||||
entity.id,
|
||||
entity.count.comment,
|
||||
"", entity.count.comment == 0, communityId)
|
||||
itemView.context.startActivity(intent)
|
||||
}
|
||||
|
||||
binding.voteCountContainer.setOnClickListener {
|
||||
if (filterIllegalVoteStatus(entity.active)) return@setOnClickListener
|
||||
|
||||
debounceActionWithInterval(R.id.container_like, 1000) {
|
||||
CheckLoginUtils.checkLogin(itemView.context, entrance) {
|
||||
if (!binding.voteIcon.isChecked) voteArticle(entity)
|
||||
else cancelArticleVote(entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
bindCommendAndVote(entity, entrance)
|
||||
}
|
||||
|
||||
private fun changeToAlternativeStyle() {
|
||||
@ -170,271 +119,6 @@ class CommunityAnswerItemViewHolder(val binding: CommunityAnswerItemBinding) : B
|
||||
binding.content.paint.flags = Paint.ANTI_ALIAS_FLAG
|
||||
binding.content.setTextColor(ContextCompat.getColor(itemView.context, R.color.text_666666))
|
||||
}
|
||||
|
||||
setVoteAndCommentStyle(entity)
|
||||
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
|
||||
private fun setVoteAndCommentStyle(entity: AnswerEntity) {
|
||||
|
||||
if (!entity.active) {
|
||||
binding.voteIcon.setImageResource(R.drawable.community_vote_unavailable)
|
||||
binding.voteCount.setTextColor(R.color.text_cccccc.toColor())
|
||||
} else if (entity.me.isCommunityArticleVote || entity.me.isAnswerVoted) {
|
||||
binding.voteIcon.setImageResource(R.drawable.community_vote_selector)
|
||||
binding.voteIcon.isChecked = true
|
||||
binding.voteCount.setTextColor(R.color.theme_font.toColor())
|
||||
} else {
|
||||
binding.voteIcon.setImageResource(R.drawable.community_vote_selector)
|
||||
binding.voteIcon.isChecked = false
|
||||
binding.voteCount.setTextColor(R.color.text_999999.toColor())
|
||||
}
|
||||
|
||||
if (entity.commentable && entity.active) {
|
||||
val commentIcon = itemView.context.resources.getDrawable(R.drawable.community_comment_count)
|
||||
commentIcon.setBounds(0, 0, commentIcon.minimumWidth, commentIcon.minimumHeight)
|
||||
binding.commentCount.setCompoundDrawables(commentIcon, null, null, null)
|
||||
binding.commentCount.setTextColor(R.color.text_999999.toColor())
|
||||
} else {
|
||||
val commentCloseIcon = itemView.context.resources.getDrawable(R.drawable.community_comment_count_unavailable)
|
||||
commentCloseIcon.setBounds(0, 0, commentCloseIcon.minimumWidth, commentCloseIcon.minimumHeight)
|
||||
binding.commentCount.setCompoundDrawables(commentCloseIcon, null, null, null)
|
||||
binding.commentCount.setTextColor(R.color.text_cccccc.toColor())
|
||||
}
|
||||
}
|
||||
|
||||
private fun voteAnswer(entity: AnswerEntity) {
|
||||
entity.vote = entity.vote + 1
|
||||
binding.voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
playVoteAnimation()
|
||||
|
||||
val voteObservable = if (entity.type == "community_article") {
|
||||
val communityId = if (entity.articleCommunityId.isNotEmpty()) entity.articleCommunityId
|
||||
else UserManager.getInstance().community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleVote(communityId, entity.id)
|
||||
} else {
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postAnswerVote(entity.id)
|
||||
}
|
||||
voteObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
} else {
|
||||
entity.me.isAnswerVoted = true
|
||||
}
|
||||
Utils.toast(itemView.context, "已赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity)
|
||||
true
|
||||
} else {
|
||||
entity.vote = entity.vote - 1
|
||||
if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
} else {
|
||||
entity.me.isAnswerVoted = true
|
||||
}
|
||||
binding.voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity)
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun cancelAnswerVote(entity: AnswerEntity) {
|
||||
entity.vote = entity.vote - 1
|
||||
|
||||
binding.voteIcon.isChecked = false
|
||||
binding.voteCount.setTextColor(R.color.text_999999.toColor())
|
||||
binding.voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
|
||||
val unVoteObservable = if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = false
|
||||
|
||||
val communityId = if (entity.articleCommunityId.isNotEmpty()) entity.articleCommunityId
|
||||
else UserManager.getInstance().community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleUnVote(communityId, entity.id)
|
||||
} else {
|
||||
entity.me.isAnswerVoted = false
|
||||
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postAnswerUnvote(entity.id)
|
||||
}
|
||||
unVoteObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
Utils.toast(itemView.context, "取消赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity)
|
||||
true
|
||||
} else {
|
||||
entity.vote = entity.vote + 1
|
||||
if (entity.type == "community_article") {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
} else {
|
||||
entity.me.isAnswerVoted = true
|
||||
}
|
||||
binding.voteCount.text = if (entity.vote > 0) entity.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity)
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun voteArticle(entity: ArticleEntity) {
|
||||
entity.count.vote = entity.count.vote + 1
|
||||
binding.voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
playVoteAnimation()
|
||||
|
||||
val communityId = if (entity.community.id.isEmpty()) UserManager.getInstance().community.id
|
||||
else entity.community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleVote(communityId, entity.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
entity.me.isCommunityArticleVote = true
|
||||
Utils.toast(itemView.context, "已赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
true
|
||||
} else {
|
||||
entity.count.vote = entity.count.vote - 1
|
||||
entity.me.isCommunityArticleVote = false
|
||||
binding.voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun cancelArticleVote(entity: ArticleEntity) {
|
||||
entity.count.vote = entity.count.vote - 1
|
||||
entity.me.isCommunityArticleVote = false
|
||||
binding.voteIcon.isChecked = false
|
||||
binding.voteCount.setTextColor(R.color.text_999999.toColor())
|
||||
binding.voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
|
||||
val communityId = if (entity.community.id.isEmpty()) UserManager.getInstance().community.id
|
||||
else entity.community.id
|
||||
RetrofitManager.getInstance(itemView.context).api
|
||||
.postCommunityArticleUnVote(communityId, entity.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<VoteEntity>() {
|
||||
override fun onResponse(response: VoteEntity?) {
|
||||
Utils.toast(itemView.context, "取消赞同")
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(itemView.context, e?.response()?.errorBody()?.string(), false) {
|
||||
if (403008 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_hint)
|
||||
true
|
||||
} else if (403036 == it) {
|
||||
Utils.toast(itemView.context, R.string.ask_vote_limit_hint)
|
||||
true
|
||||
} else if (404001 == it) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
entity.active = false
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
true
|
||||
} else {
|
||||
entity.count.vote = entity.count.vote + 1
|
||||
entity.me.isCommunityArticleVote = true
|
||||
binding.voteCount.text = if (entity.count.vote > 0) entity.count.vote.toString() else "赞同"
|
||||
setVoteAndCommentStyle(entity.transformAnswerEntity())
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun playVoteAnimation() {
|
||||
binding.voteCount.setTextColor(R.color.theme_font.toColor())
|
||||
binding.voteIcon.isChecked = true
|
||||
binding.voteIcon.visibility = View.GONE
|
||||
binding.voteAnimation.visibility = View.VISIBLE
|
||||
binding.voteAnimation.setAnimation("lottie/community_vote.json")
|
||||
binding.voteAnimation.playAnimation()
|
||||
binding.voteAnimation.doOnAnimationEnd {
|
||||
binding.voteAnimation.visibility = View.GONE
|
||||
binding.voteIcon.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterIllegalCommentStatus(commentable: Boolean, active: Boolean): Boolean {
|
||||
if (!commentable) {
|
||||
Utils.toast(itemView.context, "作者已关闭评论")
|
||||
return true
|
||||
}
|
||||
|
||||
if (!active) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun filterIllegalVoteStatus(active: Boolean): Boolean {
|
||||
if (!active) {
|
||||
Utils.toast(itemView.context, "内容可能已被删除")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.gh.gamecenter.qa.answer
|
||||
|
||||
import com.gh.gamecenter.databinding.CommunityMyAnswerItemBinding
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
|
||||
class MyAnswerViewHolder(val binding: CommunityMyAnswerItemBinding) : BaseAnswerOrArticleItemViewHolder(binding.root) {
|
||||
|
||||
fun bindItem(entity: AnswerEntity, entrance: String) {
|
||||
bindCommendAndVote(entity, entrance)
|
||||
binding.data = entity
|
||||
|
||||
}
|
||||
|
||||
fun bindItem(entity: ArticleEntity, entrance: String) {
|
||||
bindCommendAndVote(entity, entrance)
|
||||
binding.data = entity.transformAnswerEntity()
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
package com.gh.gamecenter.qa.article
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.gamecenter.databinding.CommunityArticleItemBinding
|
||||
|
||||
class ArticleViewHolder(val binding: CommunityArticleItemBinding): BaseRecyclerViewHolder<Any>(binding.root)
|
||||
@ -9,7 +9,8 @@ import com.gh.common.syncpage.ISyncAdapterHandler
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.databinding.CommunityArticleItemBinding
|
||||
import com.gh.gamecenter.databinding.CommunityMyAnswerItemBinding
|
||||
import com.gh.gamecenter.qa.answer.MyAnswerViewHolder
|
||||
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
|
||||
@ -32,8 +33,8 @@ class MyArticleAdapter(context: Context,
|
||||
FooterViewHolder(view)
|
||||
}
|
||||
else -> {
|
||||
view = mLayoutInflater.inflate(R.layout.community_article_item, parent, false)
|
||||
ArticleViewHolder(CommunityArticleItemBinding.bind(view))
|
||||
view = mLayoutInflater.inflate(R.layout.community_my_answer_item, parent, false)
|
||||
MyAnswerViewHolder(CommunityMyAnswerItemBinding.bind(view))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,9 +44,9 @@ class MyArticleAdapter(context: Context,
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is ArticleViewHolder) {
|
||||
if (holder is MyAnswerViewHolder) {
|
||||
val entity = mEntityList[position]
|
||||
holder.binding.data = entity
|
||||
holder.bindItem(entity, mEntrance)
|
||||
holder.itemView.setOnClickListener {
|
||||
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, entity.community, entity.id, mEntrance, mPath))
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ data class ArticleEntity(
|
||||
answer.read = read
|
||||
answer.me = me
|
||||
answer.commentable = commentable
|
||||
answer.active = active
|
||||
answer.communityName = community.name
|
||||
return answer
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,20 +6,20 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.syncpage.ISyncAdapterHandler
|
||||
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.PersonalHomeItemBinding
|
||||
import com.gh.gamecenter.databinding.CommunityFollowItemBinding
|
||||
import com.gh.gamecenter.entity.PersonalHistoryEntity
|
||||
import com.gh.gamecenter.personalhome.PersonalItemViewHolder
|
||||
import com.gh.gamecenter.personalhome.home.UserHistoryAdapter
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
|
||||
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity
|
||||
|
||||
class AskFollowAdapter(val context: Context, val viewModel: AskFollowViewModel)
|
||||
: ListAdapter<PersonalHistoryEntity>(context) {
|
||||
: ListAdapter<PersonalHistoryEntity>(context), ISyncAdapterHandler {
|
||||
|
||||
private val mEntrance = ""
|
||||
|
||||
@ -38,16 +38,17 @@ class AskFollowAdapter(val context: Context, val viewModel: AskFollowViewModel)
|
||||
FooterViewHolder(view)
|
||||
}
|
||||
else -> {
|
||||
view = mLayoutInflater.inflate(R.layout.personal_home_item, parent, false)
|
||||
PersonalItemViewHolder(PersonalHomeItemBinding.bind(view))
|
||||
view = mLayoutInflater.inflate(R.layout.community_follow_item, parent, false)
|
||||
CommunityFollowItemViewHolder(CommunityFollowItemBinding.bind(view))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (holder) {
|
||||
is PersonalItemViewHolder -> {
|
||||
is CommunityFollowItemViewHolder -> {
|
||||
val historyEntity = mEntityList[position]
|
||||
holder.bindFollowItem(historyEntity, mEntrance)
|
||||
|
||||
val path = "问答-关注"
|
||||
holder.binding.run {
|
||||
@ -77,7 +78,7 @@ class AskFollowAdapter(val context: Context, val viewModel: AskFollowViewModel)
|
||||
dialog.show((context as AppCompatActivity).supportFragmentManager, "more")
|
||||
}
|
||||
}
|
||||
userCommand.text = "赞同了$type"
|
||||
userCommand.text = ("赞同了$type")
|
||||
} else {
|
||||
userName.text = historyEntity.user?.name
|
||||
userName.setOnClickListener { userIcon.performClick() }
|
||||
@ -86,21 +87,16 @@ class AskFollowAdapter(val context: Context, val viewModel: AskFollowViewModel)
|
||||
}
|
||||
if (historyEntity.user?.badge != null) {
|
||||
sdvUserBadge.visibility = View.VISIBLE
|
||||
tvBadgeName.visibility = View.VISIBLE
|
||||
ImageUtils.display(sdvUserBadge, historyEntity.user?.badge?.icon)
|
||||
tvBadgeName.text = historyEntity.user?.badge?.name
|
||||
} else {
|
||||
sdvUserBadge.visibility = View.GONE
|
||||
tvBadgeName.visibility = View.GONE
|
||||
}
|
||||
sdvUserBadge.setOnClickListener {
|
||||
MtaHelper.onEvent("进入徽章墙_用户记录", "问答-关注", "${historyEntity?.user?.name}(${historyEntity?.user?.id})")
|
||||
MtaHelper.onEvent("徽章中心", "进入徽章中心", "问答-关注")
|
||||
DirectUtils.directToBadgeWall(context, historyEntity?.user?.id, historyEntity?.user?.name, historyEntity?.user?.icon)
|
||||
}
|
||||
tvBadgeName.setOnClickListener { sdvUserBadge.performClick() }
|
||||
|
||||
endDesc.text = NewsUtils.getFormattedTime(historyEntity.time)
|
||||
questionTitle.setOnClickListener {
|
||||
if ("community_article" == historyEntity.type || "community_article_vote" == historyEntity.type) {
|
||||
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, historyEntity.community, historyEntity.id, mEntrance, path))
|
||||
@ -142,4 +138,9 @@ class AskFollowAdapter(val context: Context, val viewModel: AskFollowViewModel)
|
||||
return if (mEntityList == null || mEntityList.isEmpty()) 0 else mEntityList.size + 1
|
||||
}
|
||||
|
||||
override fun getSyncData(position: Int): Pair<String, PersonalHistoryEntity>? {
|
||||
if (position >= mEntityList.size) return null
|
||||
val entity = mEntityList[position]
|
||||
return Pair(entity.id, entity)
|
||||
}
|
||||
}
|
||||
@ -30,14 +30,19 @@ class AskFollowFragment : ListFragment<PersonalHistoryEntity, AskFollowViewModel
|
||||
|
||||
@BindView(R.id.reuse_none_data)
|
||||
lateinit var noDataContainer: View
|
||||
|
||||
@BindView(R.id.reuse_tv_none_data)
|
||||
lateinit var noDataTv: TextView
|
||||
|
||||
@BindView(R.id.recommend_container)
|
||||
lateinit var recommendContainer: View
|
||||
|
||||
@BindView(R.id.recommend_scrollview)
|
||||
lateinit var recommendScrollView: NestedScrollView
|
||||
|
||||
@BindView(R.id.recommend_user_container)
|
||||
lateinit var recommendUserContainer: LinearLayout
|
||||
|
||||
@BindView(R.id.save_btn)
|
||||
lateinit var saveBtn: View
|
||||
|
||||
@ -171,7 +176,7 @@ class AskFollowFragment : ListFragment<PersonalHistoryEntity, AskFollowViewModel
|
||||
}
|
||||
|
||||
userAnswerCountTv.text = requireContext().getString(R.string.ask_answer_count, NumberUtils.transSimpleCount(user.count.answer))
|
||||
userVoteCountTv.text = context!!.getString(R.string.ask_vote_count, NumberUtils.transSimpleCount(user.count.vote!!))
|
||||
userVoteCountTv.text = requireContext().getString(R.string.ask_vote_count, NumberUtils.transSimpleCount(user.count.vote!!))
|
||||
|
||||
recommendUserContainer.addView(userView)
|
||||
}
|
||||
@ -255,6 +260,14 @@ class AskFollowFragment : ListFragment<PersonalHistoryEntity, AskFollowViewModel
|
||||
hideRecommendUser()
|
||||
}
|
||||
|
||||
override fun addSyncPageObserver(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun provideSyncAdapter(): AskFollowAdapter {
|
||||
return mAdapter
|
||||
}
|
||||
|
||||
@OnClick(R.id.reuse_tv_none_data)
|
||||
override fun onClick(v: View) {
|
||||
when (v.id) {
|
||||
|
||||
@ -32,17 +32,6 @@ class AskFollowViewModel(application: Application)
|
||||
|
||||
override fun mergeResultLiveData() {
|
||||
mResultLiveData.addSource(mListLiveData) { mutableList ->
|
||||
mutableList?.let {
|
||||
for (entity in it) {
|
||||
// 产品说隐藏掉回答和文章在这个页面的评论数,这里简单把它置为 -1 来隐藏
|
||||
if (entity.type == "answer"
|
||||
|| entity.type == "community_article"
|
||||
|| entity.type == "answer_vote"
|
||||
|| entity.type == "community_article_vote") {
|
||||
entity.count.comment = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
mResultLiveData.postValue(mutableList)
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package com.gh.gamecenter.qa.follow
|
||||
|
||||
import android.view.View
|
||||
import com.gh.gamecenter.databinding.CommunityFollowItemBinding
|
||||
import com.gh.gamecenter.entity.PersonalHistoryEntity
|
||||
import com.gh.gamecenter.qa.answer.BaseAnswerOrArticleItemViewHolder
|
||||
import com.gh.gamecenter.qa.questions.CommunityQuestionViewHolder
|
||||
|
||||
class CommunityFollowItemViewHolder(val binding: CommunityFollowItemBinding) : BaseAnswerOrArticleItemViewHolder(binding.root) {
|
||||
|
||||
fun bindFollowItem(entity: PersonalHistoryEntity, entrance: String) {
|
||||
commentCountContainer.isClickable = true
|
||||
if (entity.type.contains("question")) {
|
||||
voteCountContainer.visibility = View.INVISIBLE
|
||||
CommunityQuestionViewHolder.bindAnswerCount(
|
||||
entity.transformQuestionEntity(),
|
||||
commentCountContainer,
|
||||
commentCount,
|
||||
entrance)
|
||||
} else {
|
||||
voteCountContainer.visibility = View.VISIBLE
|
||||
bindCommendAndVote(entity.transformAnswerEntity(), entrance)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,27 @@
|
||||
package com.gh.gamecenter.qa.myqa;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import kotlin.Pair;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.syncpage.ISyncAdapterHandler;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.qa.questions.detail.AnswerViewHolder;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.databinding.CommunityMyAnswerItemBinding;
|
||||
import com.gh.gamecenter.qa.answer.MyAnswerViewHolder;
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity;
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import kotlin.Pair;
|
||||
|
||||
/**
|
||||
* Created by khy on 20/12/17.
|
||||
*/
|
||||
@ -26,10 +29,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
class MyAnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAdapterHandler {
|
||||
|
||||
private OnListClickListener mListClickListener;
|
||||
private String mEntrance;
|
||||
|
||||
MyAnswerAdapter(Context context, OnListClickListener listClickListener) {
|
||||
MyAnswerAdapter(Context context, OnListClickListener listClickListener, String entrance) {
|
||||
super(context);
|
||||
mListClickListener = listClickListener;
|
||||
mEntrance = entrance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,8 +51,8 @@ class MyAnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAdapterH
|
||||
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_my_answer_item, parent, false);
|
||||
return new MyAnswerViewHolder(CommunityMyAnswerItemBinding.bind(view));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -57,7 +62,18 @@ class MyAnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAdapterH
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (getItemViewType(position)) {
|
||||
case ItemViewType.ITEM_BODY:
|
||||
((AnswerViewHolder) holder).initMyAnswerViewHolder(mEntityList.get(position));
|
||||
MyAnswerViewHolder answerViewHolder = ((MyAnswerViewHolder) holder);
|
||||
AnswerEntity entity = mEntityList.get(position);
|
||||
answerViewHolder.bindItem(entity, mEntrance);
|
||||
CommunityMyAnswerItemBinding binding = answerViewHolder.getBinding();
|
||||
binding.title.setOnClickListener(v ->
|
||||
mContext.startActivity(QuestionsDetailActivity.getIntent(mContext,
|
||||
entity.getQuestions().getId(), mEntrance, "我的光环-我的问答-我的回答")));
|
||||
|
||||
holder.itemView.setOnClickListener(v ->
|
||||
mContext.startActivity(AnswerDetailActivity.getIntent(mContext,
|
||||
entity.getId(), mEntrance, "我的光环-我的问答-我的回答")));
|
||||
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
|
||||
|
||||
@ -3,6 +3,9 @@ package com.gh.gamecenter.qa.myqa;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
@ -10,18 +13,13 @@ import com.gh.gamecenter.baselist.ListFragment;
|
||||
import com.gh.gamecenter.baselist.LoadType;
|
||||
import com.gh.gamecenter.baselist.NormalListViewModel;
|
||||
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 com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
@ -42,7 +40,7 @@ public class MyAnswerFragment extends ListFragment<AnswerEntity, NormalListViewM
|
||||
|
||||
@Override
|
||||
protected ListAdapter provideListAdapter() {
|
||||
return mAdapter == null ? mAdapter = new MyAnswerAdapter(getContext(), this) : mAdapter;
|
||||
return mAdapter == null ? mAdapter = new MyAnswerAdapter(getContext(), this, mEntrance) : mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,22 +51,12 @@ public class MyAnswerFragment extends ListFragment<AnswerEntity, NormalListViewM
|
||||
|
||||
@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_title:
|
||||
entity = (AnswerEntity) data;
|
||||
Questions questions = entity.getQuestions();
|
||||
startActivity(QuestionsDetailActivity.getIntent(getContext(), questions.getId(), mEntrance, "我的光环-我的问答-我的回答"));
|
||||
break;
|
||||
case R.id.ask_answer_item_constraintlayout:
|
||||
entity = (AnswerEntity) data;
|
||||
startActivity(AnswerDetailActivity.getIntent(getContext(), entity.getId(), mEntrance, "我的光环-我的问答-我的回答"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ package com.gh.gamecenter.qa.questions
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.common.util.CheckLoginUtils
|
||||
import com.gh.common.util.NewsUtils
|
||||
@ -28,40 +30,49 @@ class CommunityQuestionViewHolder(val binding: CommunityQuestionItemBinding) : B
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun bindViewHolder(questions: Questions, entrance: String, path: String) {
|
||||
binding.title.text = questions.title
|
||||
if (questions.answerCount > 0) {
|
||||
DrawableView.setTextDrawable(
|
||||
binding.answerCount,
|
||||
R.drawable.community_question_answer_count,
|
||||
NumberUtils.transSimpleCount(questions.answerCount))
|
||||
} else {
|
||||
DrawableView.setTextDrawable(
|
||||
binding.answerCount,
|
||||
R.drawable.community_question_answer_edit,
|
||||
"回答")
|
||||
}
|
||||
bindAnswerCount(questions, binding.answerCountContainer, binding.answerCount, entrance)
|
||||
}
|
||||
|
||||
// 虽然很丑陋,但是没有想到其它好的办法实现:https://gitlab.ghzs.com/pm/halo-app-issues/issues/812 (7)
|
||||
if (questions.answerCount <= 0 && questions.me.myAnswerId.isNullOrEmpty()) {
|
||||
binding.answerCountContainer.setOnTouchListener { _, event ->
|
||||
if (event.action == MotionEvent.ACTION_DOWN || event.action == MotionEvent.ACTION_MOVE) {
|
||||
binding.answerCountContainer.setBackgroundResource(R.drawable.reuse_listview_item_style)
|
||||
} else {
|
||||
binding.answerCountContainer.background = null
|
||||
}
|
||||
false
|
||||
companion object {
|
||||
fun bindAnswerCount(questions: Questions,
|
||||
answerCountContainer: View,
|
||||
answerCountTv: TextView,
|
||||
entrance: String) {
|
||||
if (questions.answerCount > 0) {
|
||||
DrawableView.setTextDrawable(
|
||||
answerCountTv,
|
||||
R.drawable.community_question_answer_count,
|
||||
NumberUtils.transSimpleCount(questions.answerCount))
|
||||
} else {
|
||||
DrawableView.setTextDrawable(
|
||||
answerCountTv,
|
||||
R.drawable.community_question_answer_edit,
|
||||
"回答")
|
||||
}
|
||||
|
||||
binding.answerCountContainer.setOnClickListener {
|
||||
CheckLoginUtils.checkLogin(itemView.context, entrance) {
|
||||
val communityName = if (questions.communityName.isNullOrEmpty()) UserManager.getInstance().community.name
|
||||
else questions.communityName
|
||||
itemView.context.startActivity(AnswerEditActivity.getIntent(itemView.context, questions, communityName))
|
||||
// 虽然很丑陋,但是没有想到其它好的办法实现:https://gitlab.ghzs.com/pm/halo-app-issues/issues/812 (7)
|
||||
if (questions.answerCount <= 0 && questions.me.myAnswerId.isNullOrEmpty()) {
|
||||
answerCountContainer.setOnTouchListener { _, event ->
|
||||
if (event.action == MotionEvent.ACTION_DOWN || event.action == MotionEvent.ACTION_MOVE) {
|
||||
answerCountContainer.setBackgroundResource(R.drawable.reuse_listview_item_style)
|
||||
} else {
|
||||
answerCountContainer.background = null
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
answerCountContainer.setOnClickListener {
|
||||
CheckLoginUtils.checkLogin(it.context, entrance) {
|
||||
val communityName = if (questions.communityName.isNullOrEmpty()) UserManager.getInstance().community.name
|
||||
else questions.communityName
|
||||
it.context.startActivity(AnswerEditActivity.getIntent(it.context, questions, communityName))
|
||||
}
|
||||
}
|
||||
answerCountContainer.isClickable = true
|
||||
} else {
|
||||
answerCountContainer.isClickable = false
|
||||
answerCountContainer.setOnTouchListener(null)
|
||||
}
|
||||
binding.answerCountContainer.isClickable = true
|
||||
} else {
|
||||
binding.answerCountContainer.isClickable = false
|
||||
binding.answerCountContainer.setOnTouchListener(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user