From cdbefd2d4f86d898b35d2bbe58bc19fffc10e72f Mon Sep 17 00:00:00 2001 From: juntao Date: Thu, 20 Aug 2020 21:01:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=83=A8=E5=88=86=E5=B8=96?= =?UTF-8?q?=E5=AD=90=E8=AF=A6=E6=83=85=E7=9A=84=E5=8A=9F=E8=83=BD=20https:?= =?UTF-8?q?//gitlab.ghzs.com/pm/halo-app-issues/-/issues/967?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SnappingLinearLayoutManager.kt | 20 ++++ .../adapter/viewholder/FooterViewHolder.java | 32 +++++- .../gh/gamecenter/baselist/ListFragment.java | 2 +- .../java/com/gh/gamecenter/entity/MeEntity.kt | 2 +- .../article/detail/ArticleDetailFragment.kt | 52 +++------- .../article/detail/ArticleDetailViewModel.kt | 9 +- .../detail/BaseArticleDetailCommentAdapter.kt | 33 +++++-- .../BaseArticleDetailCommentFragment.kt | 97 +++++++++++++++++++ .../BaseArticleDetailCommentViewModel.kt | 34 +++++++ .../comment/ArticleDetailCommentAdapter.kt | 33 ++----- .../comment/ArticleDetailCommentFragment.kt | 67 ++++--------- .../comment/ArticleDetailCommentViewModel.kt | 25 +++-- .../qa/comment/NewCommentFragment.kt | 16 +-- .../res/layout/fragment_article_detail.xml | 14 ++- .../fragment_article_detail_comment.xml | 21 +++- .../item_article_detail_comment_empty.xml | 4 +- .../layout/item_article_detail_content.xml | 1 + .../piece_article_detail_comment_filter.xml | 1 + app/src/main/res/values/strings.xml | 1 + 19 files changed, 319 insertions(+), 145 deletions(-) create mode 100644 app/src/main/java/com/gh/common/view/vertical_recycler/SnappingLinearLayoutManager.kt create mode 100644 app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentFragment.kt diff --git a/app/src/main/java/com/gh/common/view/vertical_recycler/SnappingLinearLayoutManager.kt b/app/src/main/java/com/gh/common/view/vertical_recycler/SnappingLinearLayoutManager.kt new file mode 100644 index 0000000000..1c16d10183 --- /dev/null +++ b/app/src/main/java/com/gh/common/view/vertical_recycler/SnappingLinearLayoutManager.kt @@ -0,0 +1,20 @@ +package com.gh.common.view.vertical_recycler + +import android.content.Context +import android.graphics.PointF +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.LinearSmoothScroller +import androidx.recyclerview.widget.RecyclerView + +class SnappingLinearLayoutManager(val context: Context) : LinearLayoutManager(context) { + override fun smoothScrollToPosition(recyclerView: RecyclerView?, state: RecyclerView.State?, position: Int) { + val smoothScroller = object : LinearSmoothScroller(context) { + override fun getVerticalSnapPreference(): Int = SNAP_TO_START + override fun computeScrollVectorForPosition(targetPosition: Int): PointF = + this@SnappingLinearLayoutManager.computeScrollVectorForPosition(targetPosition) + ?: PointF(0F, 0F) + } + smoothScroller.targetPosition = position + startSmoothScroll(smoothScroller) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/FooterViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/FooterViewHolder.java index 6a49eb2504..ba86d199b9 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/FooterViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/FooterViewHolder.java @@ -1,11 +1,12 @@ package com.gh.gamecenter.adapter.viewholder; -import androidx.annotation.StringRes; import android.view.View; import android.view.View.OnClickListener; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.StringRes; + import com.gh.base.BaseRecyclerViewHolder; import com.gh.base.OnListClickListener; import com.gh.gamecenter.R; @@ -88,6 +89,35 @@ public class FooterViewHolder extends BaseRecyclerViewHolder { }); } + public void bindFooterDefaultEmpty(ListViewModel viewModel, boolean isLoading, boolean isNetworkError, boolean isOver) { + if (isNetworkError) { + lineLeft.setVisibility(View.GONE); + lineRight.setVisibility(View.GONE); + loading.setVisibility(View.GONE); + hint.setVisibility(View.VISIBLE); + hint.setText(R.string.loading_failed_retry); + } else if (isOver) { + lineLeft.setVisibility(View.GONE); + lineRight.setVisibility(View.GONE); + loading.setVisibility(View.GONE); + hint.setVisibility(View.VISIBLE); + hint.setText(R.string.ask_loadover_hint); + } else if (isLoading) { + lineLeft.setVisibility(View.GONE); + lineRight.setVisibility(View.GONE); + loading.setVisibility(View.VISIBLE); + hint.setVisibility(View.VISIBLE); + hint.setText(R.string.loading); + } else { + lineLeft.setVisibility(View.GONE); + lineRight.setVisibility(View.GONE); + loading.setVisibility(View.GONE); + hint.setVisibility(View.GONE); + } + itemView.setOnClickListener(v -> { + if (isNetworkError) viewModel.load(LoadType.RETRY); + }); + } public void initFooterViewHolder(boolean isLoading, boolean isNetworkError, boolean isOver, @StringRes int loadOverHint) { if (isNetworkError) { diff --git a/app/src/main/java/com/gh/gamecenter/baselist/ListFragment.java b/app/src/main/java/com/gh/gamecenter/baselist/ListFragment.java index d8479e13f0..e4adddcb69 100644 --- a/app/src/main/java/com/gh/gamecenter/baselist/ListFragment.java +++ b/app/src/main/java/com/gh/gamecenter/baselist/ListFragment.java @@ -149,7 +149,7 @@ public abstract class ListFragment onLoadRefresh()); + if (mReuseNoConn != null) mReuseNoConn.setOnClickListener(view1 -> onLoadRefresh()); } private Class getViewModelClass() { diff --git a/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt index 29a369cf86..60c555ac0a 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt @@ -62,7 +62,7 @@ class MeEntity(@SerializedName("is_community_voted") @SerializedName("is_version_requested") var isVersionRequested: Boolean = false, - @SerializedName("is_follower",alternate = ["is_follow"]) + @SerializedName("is_follower", alternate = ["is_follow"]) var isFollower: Boolean = false, // 是否已经关注该用户 @SerializedName("is_favorite") diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailFragment.kt index c71cc08400..c756a80ac8 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailFragment.kt @@ -26,7 +26,6 @@ import com.gh.gamecenter.ImageViewerActivity import com.gh.gamecenter.R import com.gh.gamecenter.SuggestionActivity import com.gh.gamecenter.baselist.ListAdapter -import com.gh.gamecenter.baselist.ListFragment import com.gh.gamecenter.baselist.LoadType import com.gh.gamecenter.entity.CommentEntity import com.gh.gamecenter.entity.CommunityEntity @@ -47,20 +46,11 @@ import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import java.util.* -class ArticleDetailFragment : ListFragment() { - - @BindView(R.id.reuse_none_data) - lateinit var mNoneData: View - - @BindView(R.id.reuse_no_connection) - lateinit var mNoConn: View +class ArticleDetailFragment : BaseArticleDetailCommentFragment() { @BindView(R.id.reuse_tv_none_data) lateinit var mNoDataText: TextView - @BindView(R.id.reuse_ll_loading) - lateinit var mLoading: View - private var mElapsedHelper: TimeElapsedHelper? = null private var mIsShowCommentManager: Boolean = false @@ -95,12 +85,6 @@ class ArticleDetailFragment : ListFragment mAdapter?.articleDetailVH?.run { @@ -125,17 +109,17 @@ class ArticleDetailFragment : ListFragment?) { + mEntityList = ArrayList(updateData ?: arrayListOf()) + notifyDataSetChanged() + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return when (viewType) { ItemViewType.ITEM_FOOTER -> { @@ -45,11 +62,11 @@ abstract class BaseArticleDetailCommentAdapter(context: Context, } ITEM_ERROR_EMPTY -> { - object : RecyclerView.ViewHolder(mLayoutInflater.inflate(R.layout.item_article_detail_comment_empty, parent, false)) {} + ArticleDetailCommentErrorViewHolder(mLayoutInflater.inflate(R.layout.item_article_detail_comment_empty, parent, false)) } ITEM_ERROR_CONNECTION -> { - object : RecyclerView.ViewHolder(mLayoutInflater.inflate(R.layout.item_article_detail_comment_empty, parent, false)) {} + ArticleDetailCommentErrorViewHolder(mLayoutInflater.inflate(R.layout.item_article_detail_comment_empty, parent, false)) } else -> throw IllegalAccessException() @@ -81,11 +98,12 @@ abstract class BaseArticleDetailCommentAdapter(context: Context, is FooterViewHolder -> { holder.initItemPadding() - holder.initFooterViewHolder(mIsLoading, mIsNetworkError, mIsOver, R.string.ask_loadover_hint) + holder.bindFooterDefaultEmpty(mViewModel, mIsLoading, mIsNetworkError, mIsOver) } } } + inner class ArticleDetailCommentErrorViewHolder(view: View) : RecyclerView.ViewHolder(view) inner class ArticleDetailCommentFilterViewHolder(var binding: PieceArticleDetailCommentFilterBinding) : RecyclerView.ViewHolder(binding.root) { fun bindView(article: ArticleDetailEntity? = null, comment: CommentEntity? = null) { binding.run { @@ -140,12 +158,13 @@ abstract class BaseArticleDetailCommentAdapter(context: Context, binding.root.context.startActivity(this) } } + binding.commentCountTv.text = viewModel.getCommentText(comment.reply, "评论") } else { // 评论详情用的样式 binding.floorHintTv.text = CommentUtils.getCommentTime(comment.time) - binding.commentCountTv.setOnClickListener { - commentClosure?.invoke(comment) - } + binding.commentCountTv.setOnClickListener { commentClosure?.invoke(comment) } + binding.commentCountTv.setCompoundDrawables(null, null, null, null) + binding.commentCountTv.text = "回复" binding.replyUserContainer.goneIf(comment.parentUser == null) comment.parentUser?.let { binding.replyUserNameTv.text = it.name @@ -155,10 +174,8 @@ abstract class BaseArticleDetailCommentAdapter(context: Context, binding.replyUserNameTv.setOnClickListener { DirectUtils.directToHomeActivity(binding.root.context, comment.user.id, 1, "", "") } - binding.commentCountTv.text = "回复" } } - binding.commentCountTv.text = viewModel.getCommentText(comment.reply, "评论") } @SuppressLint("SetTextI18n") diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentFragment.kt new file mode 100644 index 0000000000..b04d082a7b --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentFragment.kt @@ -0,0 +1,97 @@ +package com.gh.gamecenter.qa.article.detail + +import android.graphics.drawable.InsetDrawable +import android.os.Bundle +import android.view.View +import android.widget.TextView +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import butterknife.BindView +import com.gh.common.util.DisplayUtils +import com.gh.common.view.CustomDividerItemDecoration +import com.gh.common.view.vertical_recycler.SnappingLinearLayoutManager +import com.gh.gamecenter.R +import com.gh.gamecenter.baselist.ListFragment + +abstract class BaseArticleDetailCommentFragment : ListFragment() { + + @BindView(R.id.fixedTopFilterView) + lateinit var fixedTopFilterView: View + + @BindView(R.id.filterLatestTv) + lateinit var filterLatestTv: TextView + + @BindView(R.id.filterOldestTv) + lateinit var filterOldestTv: TextView + + @BindView(R.id.commentHintTv) + lateinit var commentHintTv: TextView + + @BindView(R.id.commentHintCountTv) + lateinit var commentHintCountTv: TextView + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + mListRv.layoutManager = SnappingLinearLayoutManager(requireContext()).apply { mLayoutManager = this } + mListRv.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + val firstCompletelyVisiblePosition = mLayoutManager.findFirstCompletelyVisibleItemPosition() + if (RecyclerView.NO_POSITION == firstCompletelyVisiblePosition) return + + val filterView = mLayoutManager.findViewByPosition(1) + + if (firstCompletelyVisiblePosition >= 2 && filterView == null) { + fixedTopFilterView.visibility = View.VISIBLE + updateFixedTopFilterView() + } else { + filterView?.let { + if (it.top <= 0 && fixedTopFilterView.visibility == View.GONE) { + fixedTopFilterView.visibility = View.VISIBLE + updateFixedTopFilterView() + } else if (it.top > 0 && fixedTopFilterView.visibility == View.VISIBLE) { + fixedTopFilterView.visibility = View.GONE + } + } + } + } + }) + + + filterLatestTv.setOnClickListener { + getFilterVH()?.binding?.filterLatestTv?.performClick() + updateFixedTopFilterView() + } + filterOldestTv.setOnClickListener { + getFilterVH()?.binding?.filterOldestTv?.performClick() + updateFixedTopFilterView() + } + } + + override fun onLoadRefresh() { + // do nothing + } + + override fun onLoadEmpty() { + // do nothing + } + + override fun getItemDecoration(): RecyclerView.ItemDecoration { + val insetDivider = InsetDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.divider_article_detail_comment), DisplayUtils.dip2px(20F), 0, DisplayUtils.dip2px(20F), 0) + val itemDecoration = CustomDividerItemDecoration(requireContext(), notDecorateTheFirstTwoItems = true, notDecorateTheLastItem = true) + itemDecoration.setDrawable(insetDivider) + return itemDecoration + } + + fun updateFixedTopFilterView() { + filterLatestTv.setTextColor(getFilterVH()?.binding?.filterLatestTv?.textColors) + filterOldestTv.setTextColor(getFilterVH()?.binding?.filterOldestTv?.textColors) + commentHintTv.text = getFilterVH()?.binding?.commentHintTv?.text + commentHintCountTv.text = getFilterVH()?.binding?.commentHintCountTv?.text + } + + private fun getFilterVH(): BaseArticleDetailCommentAdapter.ArticleDetailCommentFilterViewHolder? { + return (provideListAdapter() as BaseArticleDetailCommentAdapter).filterVH + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentViewModel.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentViewModel.kt index 3a3891a370..2ad940eb08 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/BaseArticleDetailCommentViewModel.kt @@ -6,6 +6,8 @@ import com.gh.common.util.CommentDraftContainer import com.gh.common.util.PostCommentUtils import com.gh.common.util.ToastUtils import com.gh.gamecenter.baselist.ListViewModel +import com.gh.gamecenter.baselist.LoadParams +import com.gh.gamecenter.baselist.LoadStatus import com.gh.gamecenter.baselist.LoadType import com.gh.gamecenter.entity.CommentDraft import com.gh.gamecenter.entity.CommentEntity @@ -20,6 +22,38 @@ abstract class BaseArticleDetailCommentViewModel(application: Application, var a val loadResultLiveData = MutableLiveData() + override fun loadStatusControl(size: Int) { + if (mCurLoadParams.loadOffset == LoadParams.DEFAULT_OFFSET) { // 初始化列表 + when { + size == 0 -> { + mLoadStatusLiveData.setValue(LoadStatus.INIT_EMPTY) + } + size == REQUEST_FAILURE_SIZE -> { + // TODO 处理列表加载失败问题 + mLoadStatusLiveData.setValue(LoadStatus.INIT_LOADED) + } + size < mOverLimitSize -> { + // 避免一个屏幕出现两次分页 + mLoadStatusLiveData.setValue(LoadStatus.INIT_OVER) + } + else -> mLoadStatusLiveData.setValue(LoadStatus.INIT_LOADED) + } + } else { + when (size) { + REQUEST_FAILURE_SIZE -> mLoadStatusLiveData.setValue(LoadStatus.LIST_FAILED) + 0 -> mLoadStatusLiveData.setValue(LoadStatus.LIST_OVER) + else -> mLoadStatusLiveData.setValue(LoadStatus.LIST_LOADED) + } + } + + if (size == REQUEST_FAILURE_SIZE) { + mRetryParams = mCurLoadParams + } else { + mRetryParams = null + mCurLoadParams.loadOffset = mCurLoadParams.loadOffset + 1 // 页数 + 1 + } + } + fun changeSort(sortType: SortType) { if (sortType != currentSortType) { currentSortType = sortType diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentAdapter.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentAdapter.kt index 54698cdc0d..651e17af4d 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentAdapter.kt @@ -8,12 +8,9 @@ import androidx.constraintlayout.widget.ConstraintSet import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.RecyclerView import com.gh.gamecenter.R -import com.gh.gamecenter.baselist.LoadStatus import com.gh.gamecenter.databinding.ItemArticleDetailCommentBinding import com.gh.gamecenter.entity.CommentEntity import com.gh.gamecenter.qa.article.detail.BaseArticleDetailCommentAdapter -import com.gh.gamecenter.qa.article.detail.CommentItemData -import java.util.* class ArticleDetailCommentAdapter(context: Context, var mViewModel: ArticleDetailCommentViewModel, @@ -21,27 +18,13 @@ class ArticleDetailCommentAdapter(context: Context, commentClosure: ((CommentEntity) -> Unit)? = null) : BaseArticleDetailCommentAdapter(context, mViewModel, type, commentClosure) { - override fun loadChange(status: LoadStatus?) { - if (status == LoadStatus.INIT) { - mIsNetworkError = false - mIsOver = false - mIsLoading = true - return - } else { - super.loadChange(status) - } - } - - override fun setListData(updateData: MutableList?) { - mEntityList = ArrayList(updateData ?: arrayListOf()) - notifyDataSetChanged() - } + var topCommentVH: ArticleDetailTopCommentViewHolder? = null override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return when (viewType) { ITEM_COMMENT_TOP -> { val binding: ItemArticleDetailCommentBinding = DataBindingUtil.inflate(mLayoutInflater, R.layout.item_article_detail_comment, parent, false) - ArticleDetailTopCommentViewHolder(binding) + ArticleDetailTopCommentViewHolder(binding).apply { topCommentVH = this } } else -> super.onCreateViewHolder(parent, viewType) @@ -55,19 +38,17 @@ class ArticleDetailCommentAdapter(context: Context, } is ArticleDetailCommentFilterViewHolder -> { - holder.bindView(comment = mViewModel.commentDetailLiveData.value) + holder.bindView(comment = mViewModel.commentDetail) } else -> super.onBindViewHolder(holder, position) } } - private inner class ArticleDetailTopCommentViewHolder(var binding: ItemArticleDetailCommentBinding) + inner class ArticleDetailTopCommentViewHolder(var binding: ItemArticleDetailCommentBinding) : RecyclerView.ViewHolder(binding.root) { fun bindView(comment: CommentEntity) { - binding.comment = comment - val constraintSet = ConstraintSet() constraintSet.clone(binding.contentTv.parent as ConstraintLayout) @@ -75,11 +56,13 @@ class ArticleDetailCommentAdapter(context: Context, constraintSet.connect(binding.contentTv.id, ConstraintSet.START, binding.iconContainer.id, ConstraintSet.START) constraintSet.applyTo(binding.contentTv.parent as ConstraintLayout) + binding.comment = comment binding.moreIv.visibility = View.GONE + binding.floorHintTv.text = "1F" + binding.commentCountTv.text = mViewModel.getCommentText(comment.reply, "回复") + binding.commentCountTv.setOnClickListener { commentClosure?.invoke(comment) } ArticleDetailCommentViewHolder.bindComment(binding, mViewModel, comment) - binding.commentCountTv.text = mViewModel.getCommentText(comment.reply, "回复") - binding.floorHintTv.text = "1F" } } diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentFragment.kt index acbcde42ca..27d8da7cc0 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/comment/ArticleDetailCommentFragment.kt @@ -1,43 +1,26 @@ package com.gh.gamecenter.qa.article.detail.comment -import android.app.Activity import android.content.Intent -import android.graphics.drawable.InsetDrawable import android.os.Bundle import android.view.View import android.view.ViewGroup -import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat -import androidx.recyclerview.widget.RecyclerView -import butterknife.BindView -import com.gh.common.history.HistoryHelper import com.gh.common.util.* -import com.gh.common.view.CustomDividerItemDecoration import com.gh.gamecenter.R import com.gh.gamecenter.baselist.ListAdapter -import com.gh.gamecenter.baselist.ListFragment import com.gh.gamecenter.baselist.LoadType import com.gh.gamecenter.entity.CommentEntity import com.gh.gamecenter.qa.article.detail.BaseArticleDetailCommentAdapter +import com.gh.gamecenter.qa.article.detail.BaseArticleDetailCommentFragment import com.gh.gamecenter.qa.article.detail.BaseArticleDetailCommentViewModel import com.gh.gamecenter.qa.article.detail.CommentItemData import com.gh.gamecenter.qa.comment.CommentActivity import com.halo.assistant.HaloApp import com.qq.gdt.action.ActionType -import kotlinx.android.synthetic.main.fragment_article_detail.* -import kotlinx.android.synthetic.main.fragment_article_detail_comment.toolbar +import kotlinx.android.synthetic.main.fragment_article_detail_comment.* import kotlinx.android.synthetic.main.piece_article_input_container.* -class ArticleDetailCommentFragment : ListFragment() { - - @BindView(R.id.reuse_none_data) - lateinit var mNoneData: View - - @BindView(R.id.reuse_no_connection) - lateinit var mNoConn: View - - @BindView(R.id.reuse_ll_loading) - lateinit var mLoading: View +class ArticleDetailCommentFragment : BaseArticleDetailCommentFragment() { private var mAdapter: ArticleDetailCommentAdapter? = null private lateinit var mViewModel: ArticleDetailCommentViewModel @@ -63,10 +46,12 @@ class ArticleDetailCommentFragment : ListFragment { return mAdapter ?: ArticleDetailCommentAdapter(requireContext(), mViewModel, BaseArticleDetailCommentAdapter.AdapterType.SUB_COMMENT) { @@ -92,8 +73,8 @@ class ArticleDetailCommentFragment : ListFragment - (toolbar.layoutParams as ViewGroup.MarginLayoutParams).topMargin = insets.systemWindowInsetTop + ViewCompat.setOnApplyWindowInsetsListener(toolbarContainer) { _, insets -> + (toolbarContainer.layoutParams as ViewGroup.MarginLayoutParams).topMargin = insets.systemWindowInsetTop insets.consumeSystemWindowInsets() } @@ -103,7 +84,7 @@ class ArticleDetailCommentFragment : ListFragment { - mNoConn.visibility = View.GONE - mLoading.visibility = View.GONE + mReuseNoConn?.visibility = View.GONE + mListLoading?.visibility = View.GONE GdtHelper.logAction(ActionType.PAGE_VIEW, GdtHelper.CONTENT_TYPE, "QA_ARTICLE", @@ -146,11 +120,8 @@ class ArticleDetailCommentFragment : ListFragment { if (it == BaseArticleDetailCommentViewModel.LoadResult.DELETED) { - - HistoryHelper.deleteArticleEntity(mViewModel.articleId) - - mNoConn.visibility = View.GONE - mNoneData.visibility = View.VISIBLE + mReuseNoConn?.visibility = View.GONE + mReuseNoData?.visibility = View.VISIBLE toast(R.string.content_delete_toast) toolbar.menu?.run { @@ -159,11 +130,11 @@ class ArticleDetailCommentFragment : ListFragment() + var commentDetail: CommentEntity? = null override fun provideDataObservable(page: Int): Observable>? = null @@ -29,18 +30,22 @@ class ArticleDetailCommentViewModel(application: Application, } private fun mergeListData(commentList: List?) { - commentDetailLiveData.value?.let { commentDetail -> + commentDetail?.let { it -> val mergedList = arrayListOf().apply { if (mResultLiveData.value != null && mResultLiveData.value?.size != 0) { // 保持头两个 item 的内存地址不变 add(mResultLiveData.value!![0]) add(mResultLiveData.value!![1]) } else { - add(CommentItemData(commentTop = commentDetail)) + add(CommentItemData(commentTop = it)) add(CommentItemData(filter = true)) } - commentList?.forEach { - add(CommentItemData(commentNormal = it)) + if (commentList.isNullOrEmpty() && mLoadStatusLiveData.value == LoadStatus.INIT_EMPTY) { + add(CommentItemData(errorEmpty = true)) + } else { + commentList?.forEach { + add(CommentItemData(commentNormal = it)) + } } } mResultLiveData.postValue(mergedList) @@ -59,13 +64,17 @@ class ArticleDetailCommentViewModel(application: Application, .subscribe(object : BiResponse() { @SuppressLint("CheckResult") override fun onSuccess(data: CommentEntity) { - commentDetailLiveData.postValue(data) + commentDetail = data loadResultLiveData.postValue(LoadResult.SUCCESS) mergeListData(mListLiveData.value) } override fun onFailure(exception: Exception) { - commentDetailLiveData.postValue(null) + if (exception is HttpException && exception.code().toString().contains("404")) { + loadResultLiveData.postValue(LoadResult.DELETED) + } else { + loadResultLiveData.postValue(LoadResult.NETWORK_ERROR) + } } }) } diff --git a/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt index 994cb92afb..1b170db978 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt @@ -104,11 +104,6 @@ open class NewCommentFragment : ListFragment mSendingDialog?.dismiss() toast("发表成功") - if (mShowInputOnly) { - requireActivity().finish() - return@Observer - } - if (mCommentEntity != null) { // 补充默认草稿 mCommentEntity = null // 清空当前评论实体 commentEt.hint = getString(R.string.message_detail_comment_hint) @@ -120,7 +115,6 @@ open class NewCommentFragment : ListFragment mCommentCount++ updateCommentCount() - onRefresh() if (mCommentListener != null) { mCommentListener?.onCountChange(mCommentCount) @@ -138,6 +132,13 @@ open class NewCommentFragment : ListFragment SyncFieldConstants.ANSWER_COMMENT_COUNT, mCommentCount)) } + + if (mShowInputOnly) { + requireActivity().finish() + return@Observer + } else { + onRefresh() + } } apiResponse.httpException != null -> { mSendingDialog?.dismiss() @@ -182,6 +183,9 @@ open class NewCommentFragment : ListFragment super.onViewCreated(view, savedInstanceState) if (mShowInputOnly) { + if (mCommentEntity != null) { + commentEt.hint = "回复:${mCommentEntity?.user?.name}" + } commentContainer.visibility = View.GONE } diff --git a/app/src/main/res/layout/fragment_article_detail.xml b/app/src/main/res/layout/fragment_article_detail.xml index c25bfaa050..423d0f1e05 100644 --- a/app/src/main/res/layout/fragment_article_detail.xml +++ b/app/src/main/res/layout/fragment_article_detail.xml @@ -11,8 +11,7 @@ style="@style/Base_ToolbarStyle" android:layout_width="match_parent" android:layout_height="@dimen/appbar_height" - android:background="@color/white" - app:layout_collapseMode="pin"> + android:background="@color/white"> + android:translationX="-32dp"> + + @@ -35,7 +36,8 @@ @@ -43,7 +45,7 @@ + android:layout_height="match_parent" /> + + diff --git a/app/src/main/res/layout/item_article_detail_content.xml b/app/src/main/res/layout/item_article_detail_content.xml index f634a082b1..31e8760ae5 100644 --- a/app/src/main/res/layout/item_article_detail_content.xml +++ b/app/src/main/res/layout/item_article_detail_content.xml @@ -96,6 +96,7 @@ android:id="@+id/badgeContainer" android:layout_width="wrap_content" android:layout_height="match_parent" + android:layout_marginLeft="4dp" android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/piece_article_detail_comment_filter.xml b/app/src/main/res/layout/piece_article_detail_comment_filter.xml index a6ed8600d9..e65088e2db 100644 --- a/app/src/main/res/layout/piece_article_detail_comment_filter.xml +++ b/app/src/main/res/layout/piece_article_detail_comment_filter.xml @@ -8,6 +8,7 @@ android:layout_width="match_parent" android:layout_height="44dp" android:background="@color/white" + android:clickable="false" android:paddingLeft="20dp" android:paddingRight="20dp" tools:showIn="@layout/fragment_article_detail"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f39134959..644ab05e6d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -648,6 +648,7 @@ 选择论坛*]]> 请撰写帖子... + 还没有人评论噢~说说你的看法吧 https://www.ghzs.com/communities/%1$s/articles/%2$s.html %1$s发布了帖子:%2$s (%3$d赞同)