diff --git a/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt b/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt index a2b6e57c2b..d1d3093423 100644 --- a/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt +++ b/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt @@ -668,7 +668,8 @@ object NewFlatLogUtils { searchKey: String, bbsId: String, sequence: Int, - name: String + name: String, + button: String ) { json { KEY_EVENT to "search_bbs_click" @@ -677,6 +678,7 @@ object NewFlatLogUtils { "bbs_id" to bbsId "sequence" to sequence "name" to name + "button" to button parseAndPutMeta()() }.let(::log) } diff --git a/app/src/main/java/com/gh/gamecenter/forum/list/ForumListAdapter.kt b/app/src/main/java/com/gh/gamecenter/forum/list/ForumListAdapter.kt index c1a298fa9b..052ff98ecc 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/list/ForumListAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/list/ForumListAdapter.kt @@ -15,6 +15,7 @@ import com.gh.gamecenter.common.utils.debounceActionWithInterval import com.gh.gamecenter.common.utils.toBinding import com.gh.gamecenter.common.utils.toColor import com.gh.gamecenter.common.utils.toDrawable +import com.gh.gamecenter.core.utils.NumberUtils import com.gh.gamecenter.databinding.ForumMyFollowBinding import com.gh.gamecenter.entity.ForumEntity import com.gh.gamecenter.eventbus.EBForumFollowChange @@ -58,7 +59,6 @@ class ForumListAdapter( holder.binding.run { root.setBackgroundColor(R.color.ui_surface.toColor(mContext)) forumNameTv.setTextColor(R.color.text_primary.toColor(mContext)) - topLine.setBackgroundColor(R.color.ui_divider.toColor(mContext)) val forumEntity = mEntityList[position] forumNameTv.text = forumEntity.name @@ -71,14 +71,16 @@ class ForumListAdapter( forumEntity.game.iconFloat ) } - topLine.visibility = if (position == 0) View.GONE else View.VISIBLE if (mViewModel?.type == ForumListActivity.TYPE_FOLLOW) { moreIv.visibility = View.VISIBLE followTv.visibility = View.GONE + hotTv.visibility = View.GONE } else { moreIv.visibility = View.GONE followTv.visibility = View.VISIBLE + hotTv.visibility = View.VISIBLE + hotTv.text = NumberUtils.transSimpleCount(forumEntity.hot) followTv.run { text = if (forumEntity.me.isFollowForum) { diff --git a/app/src/main/java/com/gh/gamecenter/forum/list/ForumListFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/list/ForumListFragment.kt index 784d8565ee..b73adeedf3 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/list/ForumListFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/list/ForumListFragment.kt @@ -13,17 +13,17 @@ class ForumListFragment : ListFragment() { private var mAdapter: ForumListAdapter? = null private var mViewModel: ForumListViewModel? = null - + private var type = "" override fun provideListAdapter() = mAdapter ?: ForumListAdapter(requireContext(), mEntrance, provideListViewModel()).apply { mAdapter = this } override fun provideListViewModel() = viewModelProvider() - override fun getItemDecoration() = SpacingItemDecoration(onlyDecorateTheFirstItem = true, top = 8F.dip2px()) + override fun getItemDecoration() = SpacingItemDecoration(onlyDecorateTheFirstItem = true, top = 0.5F.dip2px()) override fun onCreate(savedInstanceState: Bundle?) { - val type = arguments?.getString(EntranceConsts.KEY_TYPE) ?: "" + type = arguments?.getString(EntranceConsts.KEY_TYPE) ?: "" mViewModel = provideListViewModel() mViewModel?.type = type when (type) { @@ -31,6 +31,7 @@ class ForumListFragment : ListFragment() { setNavigationTitle("关注论坛") mViewModel?.setOverLimitSize(1000) } + ForumListActivity.TYPE_HOT -> setNavigationTitle("热门论坛") ForumListActivity.TYPE_OFFICIAL -> setNavigationTitle("综合论坛") } diff --git a/app/src/main/java/com/gh/gamecenter/forum/moderator/ModeratorListFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/moderator/ModeratorListFragment.kt index d48c69b652..fcb21c3aa5 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/moderator/ModeratorListFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/moderator/ModeratorListFragment.kt @@ -42,7 +42,7 @@ class ModeratorListFragment : ToolbarFragment() { mViewModel?.isModerators?.observe(this, Observer { if (it) { - mBinding.applyTv.background = R.drawable.bg_forum_follow.toDrawable() + mBinding.applyTv.background = R.drawable.bg_forum_follow.toDrawable(requireContext()) mBinding.applyTv.setTextColor(R.color.text_theme.toColor(requireContext())) mBinding.applyTv.text = "您已是版主" mBinding.applyTv.setOnClickListener { diff --git a/app/src/main/java/com/gh/gamecenter/forum/search/CommunitySearchEventListener.kt b/app/src/main/java/com/gh/gamecenter/forum/search/CommunitySearchEventListener.kt index 67b2cc4331..6359d0685f 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/search/CommunitySearchEventListener.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/search/CommunitySearchEventListener.kt @@ -11,7 +11,7 @@ interface CommunitySearchEventListener { fun onItemExposed(contentId: String?, itemType: String?, title: String?, sequence: Int) // 在论坛搜索点击论坛item,进入论坛详情 - fun onBbsItemClick(sequence: Int, bbsId: String, name: String) + fun onBbsItemClick(sequence: Int, bbsId: String, name: String, button: String) companion object { diff --git a/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListAdapter.kt b/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListAdapter.kt index f16b997e12..c0a697be89 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListAdapter.kt @@ -295,7 +295,8 @@ class ForumContentSearchListAdapter( eventListener.onBbsItemClick( position, answer.questions.id, - htmlToString(answer.questions.title) + htmlToString(answer.questions.title), + BUTTON_VIEW_FORUM_DETAIL ) mContext.startActivity( ForumVideoDetailActivity.getIntent( @@ -426,7 +427,8 @@ class ForumContentSearchListAdapter( eventListener.onBbsItemClick( position, answer.questions.id, - htmlToString(answer.questions.title) + htmlToString(answer.questions.title), + BUTTON_VIEW_FORUM_DETAIL ) } } @@ -443,12 +445,16 @@ class ForumContentSearchListAdapter( } } - class ForumSearchContentListViewHolder(val binding: ForumSearchContentListBinding) : - BaseRecyclerViewHolder(binding.root) - override fun getSyncData(position: Int): Pair? { if (position >= mEntityList.size) return null val entity = mEntityList[position] return Pair(entity.id ?: "", entity) } + + companion object { + private const val BUTTON_VIEW_FORUM_DETAIL = "查看论坛详情" + } + + class ForumSearchContentListViewHolder(val binding: ForumSearchContentListBinding) : + BaseRecyclerViewHolder(binding.root) } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListFragment.kt index 6b92a7f89a..a873389a96 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/search/ForumContentSearchListFragment.kt @@ -173,13 +173,14 @@ class ForumContentSearchListFragment : LazyListFragment Unit, val onSelectCallback: ((entity: CommunityEntity, position: Int) -> Unit)? = null ) : ListAdapter(content) { @@ -63,18 +67,27 @@ class ChooseForumContainerAdapter( if (holder is ForumItemViewHolder) { val forumEntity = mEntityList[position] holder.binding.forumNameTv.text = forumEntity.name.fromHtml() - holder.binding.followTv.background = - if (forumEntity.isFollow) R.drawable.button_round_gray_light.toDrawable() else R.drawable.bg_forum_follow.toDrawable() - holder.binding.followTv.text = if (forumEntity.isFollow) "已关注" else "关注" + + val drawableResId = + if (forumEntity.me.isFollowForum) R.drawable.bg_forum_already_follow else R.drawable.bg_forum_follow + holder.binding.followTv.background = drawableResId.toDrawable(holder.itemView.context) + + holder.binding.followTv.text = if (forumEntity.me.isFollowForum) "已关注" else "关注" holder.binding.followTv.setTextColor( - if (forumEntity.isFollow) R.color.text_tertiary.toColor(mContext) else R.color.text_theme.toColor( + if (forumEntity.me.isFollowForum) R.color.text_tertiary.toColor(mContext) else R.color.primary_theme.toColor( mContext ) ) + holder.binding.hotTv.text = NumberUtils.transSimpleCount(forumEntity.hot) + + holder.binding.followTv.setOnClickListener { + val button = if (forumEntity.me.isFollowForum) BUTTON_UN_FOLLOW else BUTTON_FOLLOW + childClick(position, forumEntity, button) + handleFollowTvClick(holder.binding, forumEntity) + } val icon = forumEntity.icon.ifEmpty { forumEntity.game.getIcon() } holder.binding.forumIcon.displayGameIcon(icon, forumEntity.game.iconSubscript, forumEntity.game.iconFloat) - holder.binding.followTv.visibility = View.GONE holder.itemView.setOnClickListener { val tabType = if (type == ChooseForumContainerFragment.ChooseForumType.SEARCH.value) "论坛tab" else "" val bbsType = if (forumEntity.type == "official_bbs") "综合论坛" else "游戏论坛" @@ -98,6 +111,8 @@ class ChooseForumContainerAdapter( iconSubscript = forumEntity.game.iconSubscript ), position ) + + childClick(position, forumEntity, VIEW_FORUM_DETAIL) } } else if (holder is FooterViewHolder) { holder.initItemPadding() @@ -107,5 +122,47 @@ class ChooseForumContainerAdapter( } } + private fun handleFollowTvClick(binding: ForumItemBinding, forumEntity: ForumEntity) { + binding.run { + debounceActionWithInterval(R.id.followTv) { + CheckLoginUtils.checkLogin(mContext, entrance) { + if (forumEntity.me.isFollowForum) { + viewModel.unFollowForum(forumEntity.id) { + forumEntity.me.isFollowForum = false + followTv.background = R.drawable.bg_forum_follow.toDrawable(mContext) + followTv.setTextColor(R.color.primary_theme.toColor(mContext)) + followTv.text = "关注" + ToastUtils.showToast("取消成功") + EventBus.getDefault().post(EBForumFollowChange(newEntity(forumEntity), false)) + } + } else { + viewModel.followForum(forumEntity.id) { + forumEntity.me.isFollowForum = true + followTv.background = R.drawable.bg_forum_already_follow.toDrawable(mContext) + followTv.setTextColor(R.color.text_tertiary.toColor(mContext)) + followTv.text = "已关注" + ToastUtils.showToast("关注成功") + EventBus.getDefault().post(EBForumFollowChange(newEntity(forumEntity), true)) + } + } + } + } + } + } + + + private fun newEntity(forumEntity: ForumEntity) = with(forumEntity) { + ForumEntity( + id, game, HtmlUtils.stripHtml(name), icon, isFollow, isRecommend, orderTag, unread, type, me, hot + ) + } + + companion object { + + private const val BUTTON_FOLLOW = "关注" + private const val BUTTON_UN_FOLLOW = "取消关注" + private const val VIEW_FORUM_DETAIL = "查看论坛详情" + } + class ForumItemViewHolder(val binding: ForumItemBinding) : BaseRecyclerViewHolder(binding.root) } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/qa/dialog/ChooseForumContainerFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/dialog/ChooseForumContainerFragment.kt index 63b6d312d6..7d3eaabee2 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/dialog/ChooseForumContainerFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/dialog/ChooseForumContainerFragment.kt @@ -4,6 +4,7 @@ import androidx.core.content.ContextCompat import androidx.core.os.bundleOf import androidx.fragment.app.Fragment import androidx.recyclerview.widget.RecyclerView +import com.gh.common.util.NewFlatLogUtils import com.gh.common.util.NewLogUtils import com.gh.gamecenter.R import com.gh.gamecenter.SearchActivity.Companion.trackSearchResultClick @@ -12,6 +13,7 @@ import com.gh.gamecenter.common.baselist.LazyListFragment import com.gh.gamecenter.common.baselist.ListAdapter import com.gh.gamecenter.common.constant.EntranceConsts import com.gh.gamecenter.common.utils.viewModelProvider +import com.gh.gamecenter.core.utils.HtmlUtils import com.gh.gamecenter.entity.ForumEntity import com.gh.gamecenter.forum.detail.ForumDetailActivity @@ -21,21 +23,34 @@ class ChooseForumContainerFragment : LazyListFragment { - return mAdapter ?: ChooseForumContainerAdapter(requireContext(), type, mListViewModel) { enity, position -> + return mAdapter ?: ChooseForumContainerAdapter( + requireContext(), + type, + mListViewModel, + mEntrance, + childClick = { position, forumEntity, button -> + + NewFlatLogUtils.logSearchBbsClick( + mSearchType, mSearchKey, forumEntity.id, position + 1, HtmlUtils.stripHtml(forumEntity.name), button + ) + } + ) { enity, position -> trackSearchResultClick(mSearchKey, mSearchType) if (requireActivity() is ChooseForumActivity) { (requireActivity() as ChooseForumActivity).chooseSuccess(enity) - val entrance = - if (type == ChooseForumType.ATTENTION.value) "我的关注tab" else if (type == ChooseForumType.HOT.value) "热门论坛tab" else "搜索结果" val bbsType = if (enity.type == "game_bbs") "游戏论坛" else "综合论坛" NewLogUtils.logChooseForumPanelClick("click_select_forum_panel_forum", entrance, enity.id, bbsType) } else { @@ -81,6 +96,7 @@ class ChooseForumContainerFragment : LazyListFragment(application) { + private val mApi: ApiService = RetrofitManager.getInstance().api + private val mCompositeDisposable = CompositeDisposable() private var mPage = 0 @@ -68,6 +76,36 @@ class ChooseForumContainerViewModel( } } + fun followForum(bbsId: String, onSuccess: () -> Unit) { + val disposable = mApi + .followForum(bbsId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + onSuccess.invoke() + } + }) + mCompositeDisposable.add(disposable) + } + + fun unFollowForum(bbsId: String, onSuccess: () -> Unit) { + val disposable = mApi.unFollowForum(bbsId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + onSuccess.invoke() + } + }) + mCompositeDisposable.add(disposable) + } + + override fun onCleared() { + super.onCleared() + mCompositeDisposable.clear() + } + class Factory(val type: String, val searchKey: String, val searchType: String) : ViewModelProvider.NewInstanceFactory() { override fun create(modelClass: Class): T { diff --git a/app/src/main/res/drawable/bg_forum_already_follow.xml b/app/src/main/res/drawable/bg_forum_already_follow.xml new file mode 100644 index 0000000000..61ea403271 --- /dev/null +++ b/app/src/main/res/drawable/bg_forum_already_follow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_forum_follow.xml b/app/src/main/res/drawable/bg_forum_follow.xml index 87c822d721..02917389d3 100644 --- a/app/src/main/res/drawable/bg_forum_follow.xml +++ b/app/src/main/res/drawable/bg_forum_follow.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/forum_item.xml b/app/src/main/res/layout/forum_item.xml index fcd055cd3a..0df5b9708e 100644 --- a/app/src/main/res/layout/forum_item.xml +++ b/app/src/main/res/layout/forum_item.xml @@ -1,36 +1,65 @@ - + android:layout_width="48dp" + android:layout_height="48dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + android:textSize="14sp" + app:layout_constraintEnd_toStartOf="@id/followTv" + app:layout_constraintStart_toEndOf="@id/forumIcon" + app:layout_constraintTop_toTopOf="@id/forumIcon" + app:layout_constraintBottom_toTopOf="@id/hotTv" + app:layout_constraintVertical_chainStyle="packed" + tools:text="口袋妖怪-游戏标题游戏游戏标题游戏游戏标题游戏" /> + + - + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="关注" /> + diff --git a/app/src/main/res/layout/forum_my_follow.xml b/app/src/main/res/layout/forum_my_follow.xml index d036842568..3fa46f098f 100644 --- a/app/src/main/res/layout/forum_my_follow.xml +++ b/app/src/main/res/layout/forum_my_follow.xml @@ -1,22 +1,15 @@ - - - + android:layout_marginStart="12dp" + android:layout_marginEnd="16dp"> + + + + +