完成视频详情顶部区域

This commit is contained in:
jack
2021-05-24 15:51:00 +08:00
parent 4549f78ede
commit f1302dd1bb
15 changed files with 301 additions and 82 deletions

View File

@ -38,6 +38,7 @@ class CommentActivity : BaseActivity() {
val videoId = intent.getStringExtra(VIDEO_ID) ?: ""
val isVideoAuthor = intent.getBooleanExtra(IS_VIDEO_AUTHOR, false)
val isStairsComment = intent.getBooleanExtra(IS_STAIRS_COMMENT, false)
val commentEntity: CommentEntity? = intent.getParcelableExtra(COMMENT_ENTITY) ?: null
@ -89,6 +90,8 @@ class CommentActivity : BaseActivity() {
commentCount,
isVideoAuthor,
commentEntity,
mShowInputOnly,
isStairsComment,
commentCallback)
}
}
@ -96,7 +99,7 @@ class CommentActivity : BaseActivity() {
supportFragmentManager.beginTransaction().replace(R.id.answerCommentPlaceholderView, commentFragment!!, NewCommentFragment::class.java.simpleName).commitNowAllowingStateLoss()
maskView.alpha = 0f
if (videoId.isNullOrEmpty()) {
if (!isStairsComment) {
maskView.animate().alpha(1f).setDuration(300).start()
}
answerCommentPlaceholderView.translationY = (DisplayUtils.getScreenHeight()).toFloat()
@ -128,6 +131,7 @@ class CommentActivity : BaseActivity() {
const val COMMENT_ENTITY = "comment_entity"
const val IS_VIDEO_AUTHOR = "isVideoAuthor"
const val SHOW_KEYBOARD = "show_keyboard"
const val IS_STAIRS_COMMENT = "is_stairs_comment"
const val ARTICLE_ID = "article_id"
const val COMMUNITY_ID = "community_id"
@ -159,12 +163,15 @@ class CommentActivity : BaseActivity() {
}
@JvmStatic
fun getVideoCommentIntent(context: Context, videoId: String, commentCount: Int? = 0, isVideoAuthor: Boolean, showKeyboard: Boolean): Intent {
fun getVideoCommentIntent(context: Context, videoId: String, commentCount: Int? = 0, isVideoAuthor: Boolean,
showKeyboard: Boolean, showInputOnly: Boolean = false, isStairsComment: Boolean = true): Intent {
val intent = Intent(context, CommentActivity::class.java)
intent.putExtra(VIDEO_ID, videoId)
intent.putExtra(COMMENT_COUNT, commentCount)
intent.putExtra(IS_VIDEO_AUTHOR, isVideoAuthor)
intent.putExtra(SHOW_KEYBOARD, showKeyboard)
intent.putExtra(SHOW_INPUT_ONLY, showInputOnly)
intent.putExtra(IS_STAIRS_COMMENT, isStairsComment)
if (context is Activity) {
context.overridePendingTransition(0, 0)
}

View File

@ -12,6 +12,7 @@ import android.widget.*
import androidx.annotation.Nullable
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
@ -465,32 +466,6 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
}
open fun popInputLayout(isPopup: Boolean, height: Int) {
/*mCommentLine.goneIf(isPopup)
mShadowView.goneIf(mShowInputOnly || !isPopup)
if (requireActivity() is CommentDetailActivity) {
val shadowView = (requireActivity() as CommentDetailActivity).shadowView
shadowView.visibility = if (isPopup && !mShowInputOnly) View.VISIBLE else View.GONE
DisplayUtils.setLightStatusBar(requireActivity(), !isPopup)
shadowView.setOnClickListener { Util_System_Keyboard.hideSoftKeyboard(activity) }
}
mAnswerContent.orientation = if (isPopup) LinearLayout.VERTICAL else LinearLayout.HORIZONTAL
if (isPopup) {
mAnswerContent.background = ContextCompat.getDrawable(requireActivity(), R.drawable.bg_shape_white_radius_10_top_only)
} else {
mAnswerContent.setBackgroundColor(ContextCompat.getColor(requireActivity(), R.color.white))
mOffset = Math.abs(height)
}
val mScrollViewParams = mScrollView.layoutParams as LinearLayout.LayoutParams
mScrollViewParams.width = if (isPopup) LinearLayout.LayoutParams.MATCH_PARENT else 0
mScrollViewParams.height = if (isPopup) DisplayUtils.dip2px(64f) else DisplayUtils.dip2px(28f)
mScrollView.layoutParams = mScrollViewParams
val mLayoutParams = commentInputContainer.layoutParams as FrameLayout.LayoutParams
mLayoutParams.height = if (isPopup) DisplayUtils.dip2px(130f) else LinearLayout.LayoutParams.WRAP_CONTENT
mLayoutParams.bottomMargin = if (isPopup) height + mOffset - DisplayUtils.dip2px(12F) else 0
commentInputContainer.layoutParams = mLayoutParams*/
mCommentLine.goneIf(mShowInputOnly || isPopup)
mShadowView.goneIf(mShowInputOnly || !isPopup)
if (requireActivity() is CommentDetailActivity) {
@ -574,6 +549,7 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
const val SHOW_INPUT_ONLY = "showInputOnly"
const val COMMENT_ENTITY = "commentEntity"
const val IS_VIDEO_AUTHOR = "isVideoAuthor"
const val IS_STAIRS_COMMENT = "is_stairs_comment"
fun getAnswerCommentInstance(answerId: String,
showSoftKeyboardOnStartUp: Boolean,
@ -626,19 +602,41 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
commentCount: Int,
isVideoAuthor: Boolean,
commentEntity: CommentEntity? = null,
showInputOnly: Boolean,
isStairsComment: Boolean,
listener: AnswerDetailFragment.CommentListener)
: StairsCommentFragment {
return StairsCommentFragment().apply {
mCommentListener = listener
with(bundleOf(
SHOW_SOFT_KEY_BOARD_ON_STARTUP to showSoftKeyboardOnStartUp,
VIDEO_ID to videoId,
COMMENT_COUNT to commentCount,
COMMENT_TYPE to CommentType.VIDEO,
COMMENT_ENTITY to commentEntity,
IS_VIDEO_AUTHOR to isVideoAuthor
))
: Fragment {
return if (isStairsComment){
StairsCommentFragment().apply {
mCommentListener = listener
with(bundleOf(
SHOW_SOFT_KEY_BOARD_ON_STARTUP to showSoftKeyboardOnStartUp,
VIDEO_ID to videoId,
COMMENT_COUNT to commentCount,
COMMENT_TYPE to CommentType.VIDEO,
COMMENT_ENTITY to commentEntity,
IS_VIDEO_AUTHOR to isVideoAuthor
))
}
}else {
NewCommentFragment().apply {
mCommentListener = listener
with(bundleOf(
SHOW_SOFT_KEY_BOARD_ON_STARTUP to showSoftKeyboardOnStartUp,
VIDEO_ID to videoId,
COMMENT_COUNT to commentCount,
COMMENT_TYPE to CommentType.VIDEO,
COMMENT_ENTITY to commentEntity,
SHOW_INPUT_ONLY to showInputOnly,
IS_STAIRS_COMMENT to isStairsComment,
IS_VIDEO_AUTHOR to isVideoAuthor
))
}
}
}
}
}

View File

@ -13,6 +13,7 @@ import android.widget.SeekBar
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.facebook.drawee.view.SimpleDraweeView
import com.gh.common.constant.Constants
import com.gh.common.observer.MuteCallback
import com.gh.common.observer.VolumeObserver
@ -37,8 +38,8 @@ class ForumTopVideoView @JvmOverloads constructor(context: Context, attrs: Attri
private var mVolumeObserver: VolumeObserver
private var mMuteDisposable: Disposable? = null
private var mIsAutoPlay = false
var thumbImage: SimpleDraweeView = findViewById(R.id.thumbImage)
var mForumVideoEntity: ForumVideoEntity? = null
var viewModel: ForumVideoDetailViewModel? = null
var uuid = UUID.randomUUID().toString()
@ -194,7 +195,7 @@ class ForumTopVideoView @JvmOverloads constructor(context: Context, attrs: Attri
}
fun updateThumb(url: String) {
Picasso.with(context).load(url).fit().into(findViewById<ImageView>(R.id.thumbImage))
ImageUtils.display(thumbImage, url)
}
override fun touchDoubleUp() {

View File

@ -24,7 +24,7 @@ class ForumVideoDetailActivity : BaseActivity() {
}
companion object {
const val VIDEO_PATCH_REQUEST=100
const val VIDEO_PATCH_REQUEST = 100
fun getIntent(context: Context, videoId: String): Intent {
val intent = Intent(context, ForumVideoDetailActivity::class.java)
intent.putExtra(EntranceUtils.KEY_VIDEO_ID, videoId)

View File

@ -14,9 +14,12 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import com.ethanhua.skeleton.Skeleton
import com.ethanhua.skeleton.ViewSkeletonScreen
import com.gh.base.BaseActivity
@ -72,6 +75,7 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
private var mCommentCountTv: TextView? = null
private var mMoreMenuItem: MenuItem? = null
private var mForumVideoEntity: ForumVideoEntity? = null
private var mVideoId = ""
private val dataWatcher = object : DataWatcher() {
override fun onDataChanged(downloadEntity: DownloadEntity) {
@ -87,8 +91,8 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
}
override fun initFragmentList(fragments: MutableList<Fragment>) {
fragments.add(VideoDescFragment())
fragments.add(VideoCommentFragment())
fragments.add(VideoDescFragment().apply { arguments = bundleOf(EntranceUtils.KEY_VIDEO_ID to mVideoId) })
fragments.add(VideoCommentFragment().apply { arguments = bundleOf(EntranceUtils.KEY_VIDEO_ID to mVideoId) })
}
override fun initTabTitleList(tabTitleList: MutableList<String>) {
@ -96,6 +100,11 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
tabTitleList.add("评论")
}
override fun onCreate(savedInstanceState: Bundle?) {
mVideoId = arguments?.getString(EntranceUtils.KEY_VIDEO_ID) ?: ""
super.onCreate(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mBinding.toolbar.inflateMenu(R.menu.menu_forum_video_detail)
@ -104,8 +113,7 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
(mBinding.toolbar.layoutParams as ViewGroup.MarginLayoutParams).topMargin = insets.systemWindowInsetTop
insets.consumeSystemWindowInsets()
}
val videoId = arguments?.getString(EntranceUtils.KEY_VIDEO_ID) ?: ""
mViewModel = viewModelProviderFromParent(ForumVideoDetailViewModel.Factory(videoId))
mViewModel = viewModelProviderFromParent(ForumVideoDetailViewModel.Factory(mVideoId))
mSkeleton = Skeleton.bind(mBinding.skeleton).shimmer(false).load(R.layout.fragment_video_detail_skeleton).show()
mBinding.toolbar.setNavigationOnClickListener { requireActivity().finish() }
@ -142,17 +150,30 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
if (it.status == Status.SUCCESS) {
val entity = it.data as ForumVideoEntity
mForumVideoEntity = entity
mCommentCountTv?.text = entity.commentCount.toString()
mBinding.topVideoView.setForumVideoEntity(mForumVideoEntity)
updateVideoParams()
setUpTopVideo(entity.url, entity.poster)
mCommentCountTv?.text = entity.commentCount.toString()
setGameInfo(entity)
mBinding.container.visibility = View.VISIBLE
mBinding.reuseNoneData.root.visibility = View.GONE
mBinding.reuseNoConnection.root.visibility = View.GONE
} else {
mBinding.reuseNoConnection.root.visibility = View.VISIBLE
mBinding.container.visibility = View.GONE
if (it.exception != null && it.exception.code() == 404) {
mBinding.reuseNoneData.reuseTvNoneData.text = "页面不见了"
mBinding.reuseNoneData.root.visibility = View.VISIBLE
} else {
mBinding.reuseNoConnection.root.visibility = View.VISIBLE
}
}
mBinding.reuseLoading.root.visibility = View.GONE
mSkeleton?.hide()
}
mViewModel.deleteLiveData.observe(viewLifecycleOwner, Observer {
ToastUtils.showToast("删除成功")
requireActivity().finish()
})
}
private fun setGameInfo(entity: ForumVideoEntity) {
@ -197,10 +218,10 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
private fun updateVideoParams() {
if (mForumVideoEntity == null) return
val videoInfo = mForumVideoEntity!!.videoInfo
val ratio = if (videoInfo.width == 0 || videoInfo.height == 0) {
180 / 101f
val ratio = if (videoInfo.width < videoInfo.height) {
3 / 4f //竖屏
} else {
videoInfo.width / videoInfo.height.toFloat()
180 / 101f //横屏
}
val updateWidth = DisplayUtils.getScreenWidth()
val updateHeight = updateWidth / ratio
@ -430,7 +451,7 @@ class ForumVideoDetailFragment : BaseFragment_TabLayout() {
}
"删除" -> {
DialogUtils.showNewAlertDialog(requireContext(), "提示", "删除视频后,其中的所有评论及回复都将被删除", "取消", "删除", {}, {
// mViewModel.doHideThisArticle(mViewModel.detailEntity!!.community.id, mViewModel.articleId)
mViewModel.deleteVideo(mForumVideoEntity?.id ?: "")
})
}
}

View File

@ -5,6 +5,7 @@ import android.app.Application
import android.net.Uri
import android.text.TextUtils
import androidx.lifecycle.*
import com.gh.common.util.ErrorHelper
import com.gh.common.util.observableToMain
import com.gh.gamecenter.entity.ForumVideoEntity
import com.gh.gamecenter.entity.VideoEntity
@ -15,7 +16,10 @@ import com.gh.gamecenter.retrofit.RetrofitManager
import com.google.android.exoplayer2.upstream.cache.CacheUtil
import com.google.gson.JsonObject
import com.halo.assistant.HaloApp
import com.lightgame.utils.Utils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import okhttp3.ResponseBody
import retrofit2.HttpException
import tv.danmaku.ijk.media.exo2.ExoSourceManager
@ -25,6 +29,7 @@ class ForumVideoDetailViewModel(application: Application, val videoId: String) :
val detailLiveData = MediatorLiveData<Resource<ForumVideoEntity>>()
val updateDetailLiveData = MediatorLiveData<ForumVideoEntity>()
var needToUpdateShareCount = MutableLiveData<Int>()
var deleteLiveData = MutableLiveData<Boolean>()
init {
getVideoDetail()
@ -51,8 +56,7 @@ class ForumVideoDetailViewModel(application: Application, val videoId: String) :
@SuppressLint("CheckResult")
fun shareVideoStatistics(videoEntity: ForumVideoEntity?) {
if (videoEntity == null) return
RetrofitManager.getInstance(getApplication())
.api.shareVideoStatistics(videoEntity.id)
mApi.shareVideoStatistics(videoEntity.id)
.subscribeOn(Schedulers.io())
.subscribe(object : BiResponse<JsonObject>() {
override fun onSuccess(data: JsonObject) {
@ -68,6 +72,21 @@ class ForumVideoDetailViewModel(application: Application, val videoId: String) :
}
fun deleteVideo(videoId: String) {
mApi.deleteVideo(videoId)
.compose(observableToMain())
.subscribe(object : Response<ResponseBody>() {
override fun onResponse(response: ResponseBody?) {
deleteLiveData.postValue(true)
}
override fun onFailure(e: HttpException?) {
val string = e?.response()?.errorBody()?.string() ?: ""
ErrorHelper.handleError(getApplication(), string)
}
})
}
fun isTopVideoPartlyCached(topVideoUrl: String): Boolean {
val cache = ExoSourceManager.getCacheSingleInstance(HaloApp.getInstance().application, null)
val key = CacheUtil.generateKey(Uri.parse(topVideoUrl))

View File

@ -10,7 +10,7 @@ import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.ItemArticleDetailCommentBinding
import com.gh.gamecenter.entity.CommentEntity
class VideoCommentAdapter(val context: Context) : ListAdapter<CommentEntity>(context) {
class VideoCommentAdapter(val context: Context, val mViewModel: VideoCommentViewModel, val entrance: String) : ListAdapter<CommentEntity>(context) {
public override fun setListData(updateData: MutableList<CommentEntity>?) {
super.setListData(updateData)
@ -39,7 +39,7 @@ class VideoCommentAdapter(val context: Context) : ListAdapter<CommentEntity>(con
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is VideoCommentViewHolder) {
val commentEntity = mEntityList[position]
holder.bindComment(commentEntity)
holder.bindComment(commentEntity, mViewModel, entrance)
}
}
}

View File

@ -1,18 +1,30 @@
package com.gh.gamecenter.qa.video.detail.comment
import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.gh.common.util.*
import com.gh.common.view.CustomDividerItemDecoration
import com.gh.gamecenter.R
import com.gh.gamecenter.baselist.LazyListFragment
import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.FragmentVideoCommentListBinding
import com.gh.gamecenter.entity.CommentEntity
import com.gh.gamecenter.entity.ForumVideoEntity
import com.gh.gamecenter.manager.UserManager
import com.gh.gamecenter.mvvm.Status
import com.gh.gamecenter.qa.comment.CommentActivity
import com.gh.gamecenter.qa.video.detail.ForumVideoDetailViewModel
class VideoCommentFragment : LazyListFragment<CommentEntity, VideoCommentViewModel>() {
private lateinit var mBinding: FragmentVideoCommentListBinding
private lateinit var mVideoDetailViewModel: ForumVideoDetailViewModel
private var mAdapter: VideoCommentAdapter? = null
private var mVideoId = ""
override fun provideListAdapter(): ListAdapter<*> {
return mAdapter ?: VideoCommentAdapter(requireContext()).apply {
return mAdapter ?: VideoCommentAdapter(requireContext(), mListViewModel, mEntrance).apply {
mAdapter = this
}
}
@ -26,15 +38,51 @@ class VideoCommentFragment : LazyListFragment<CommentEntity, VideoCommentViewMod
return itemDecoration
}
override fun provideListViewModel(): VideoCommentViewModel {
return viewModelProvider(VideoCommentViewModel.Factory(mVideoId))
}
override fun onRealLayoutInflated(inflatedView: View) {
mBinding = FragmentVideoCommentListBinding.bind(inflatedView)
}
override fun onCreate(savedInstanceState: Bundle?) {
mVideoId = arguments?.getString(EntranceUtils.KEY_VIDEO_ID) ?: ""
super.onCreate(savedInstanceState)
}
override fun onFragmentFirstVisible() {
mVideoDetailViewModel = viewModelProviderFromParent()
super.onFragmentFirstVisible()
mListRefresh?.isEnabled = false
val list = mutableListOf<CommentEntity>()
repeat(10) {
list.add(CommentEntity())
mBinding.replyTv.setDebouncedClickListener {
startCommentActivity()
}
mAdapter?.setListData(list)
onLoadDone()
observeData()
}
private fun observeData() {
mVideoDetailViewModel.detailLiveData.observeNonNull(this) {
if (it.status == Status.SUCCESS) {
mListViewModel.videoDetail = it.data as ForumVideoEntity
mBinding.allCommentCountTv.text = mListViewModel.videoDetail?.commentCount.toString()
onRefresh()
}
}
}
private fun startCommentActivity() {
mListViewModel.videoDetail?.let {
val intent = CommentActivity.getVideoCommentIntent(
requireContext(),
it.id,
it.commentCount,
it.user.id == UserManager.getInstance().userId,
true, true, false
)
startActivityForResult(intent, CommentActivity.REQUEST_CODE)
}
}
override fun isAutomaticLoad(): Boolean = false
}

View File

@ -1,11 +1,78 @@
package com.gh.gamecenter.qa.video.detail.comment
import android.annotation.SuppressLint
import android.text.SpannableStringBuilder
import com.gh.base.BaseRecyclerViewHolder
import com.gh.common.util.*
import com.gh.gamecenter.R
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.BaseArticleDetailCommentViewModel
import com.gh.gamecenter.qa.comment.CommentActivity
class VideoCommentViewHolder(val binding: ItemArticleDetailCommentBinding) : BaseRecyclerViewHolder<Any>(binding.root) {
fun bindComment(comment: CommentEntity) {
fun bindComment(comment: CommentEntity, mViewModel: VideoCommentViewModel, entrance: String) {
binding.comment = comment
binding.userIconIv.display(comment.user.border, comment.user.icon, comment.user.auth?.icon)
binding.contentTv.text = comment.content
binding.likeCountTv.text = mViewModel.getLikeText(comment.vote)
if (comment.me?.isCommentVoted == true) {
binding.likeCountTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.comment_vote_select, 0, 0, 0)
} else {
binding.likeCountTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.comment_vote_unselect, 0, 0, 0)
}
binding.commentCountTv.text = mViewModel.getCommentText(comment.reply, "回复")
binding.likeCountTv.setDebouncedClickListener {
binding.likeCountTv.context.ifLogin("视频评论-点赞") {
}
}
binding.userIconIv.setOnClickListener {
DirectUtils.directToHomeActivity(binding.root.context, comment.user.id, 1, entrance, "视频详情")
}
binding.userNameTv.setOnClickListener { binding.userIconIv.performClick() }
binding.badgeTv.setOnClickListener {
DialogUtils.showViewBadgeDialog(binding.root.context, comment.user.badge) {
DirectUtils.directToBadgeWall(binding.root.context, comment.user.id, comment.user.name, comment.user.icon)
}
}
binding.badgeIv.setOnClickListener { binding.badgeTv.performClick() }
updateSubComment(comment, mViewModel, entrance)
}
@SuppressLint("SetTextI18n")
fun updateSubComment(comment: CommentEntity, mViewModel: VideoCommentViewModel, entrance: String) {
val subCommentList = comment.subCommentList
val articleOwnerUserId = mViewModel.videoDetail?.user?.id ?: ""
binding.moreSubCommentBtn.goneIf(comment.reply < 3)
binding.moreSubCommentBtn.text = "查看全部${comment.reply}条回复"
binding.subCommentContainer.goneIf(subCommentList.isNullOrEmpty())
binding.firstSubCommentTv.goneIf(subCommentList?.firstOrNull() == null)
binding.secondSubCommentTv.goneIf(subCommentList?.secondOrNull() == null)
binding.subCommentContainer.setRoundedColorBackground(R.color.text_F5F5F5, 5F)
subCommentList?.firstOrNull()?.let {
binding.firstSubCommentTv.text = getSubCommentSpanned(it.user.name, if (it.user.id == articleOwnerUserId) "作者" else "", it.content)
}
subCommentList?.secondOrNull()?.let {
binding.secondSubCommentTv.text = getSubCommentSpanned(it.user.name, if (it.user.id == articleOwnerUserId) "作者" else "", it.content)
}
binding.subCommentContainer.setOnClickListener {
}
}
private fun getSubCommentSpanned(name: String?, author: String?, content: String?): SpannableStringBuilder {
val finalAuthor = author ?: ""
val finalName = "$name "
val colon = " "
val nameSpan = SpanBuilder(finalName).color(0, finalName.length, R.color.theme_font).build()
val authorSpan = if (finalAuthor.isNotEmpty()) SpanBuilder(finalAuthor).image(0, finalAuthor.length, R.drawable.ic_hint_author).build() else ""
val colonSpan = SpanBuilder(colon).color(0, colon.length, R.color.theme_font).build()
return SpannableStringBuilder().append(nameSpan).append(authorSpan).append(colonSpan).append(content)
}
}

View File

@ -1,16 +1,39 @@
package com.gh.gamecenter.qa.video.detail.comment
import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.gh.gamecenter.baselist.ListViewModel
import com.gh.gamecenter.entity.CommentEntity
import com.gh.gamecenter.entity.ForumVideoEntity
import com.gh.gamecenter.retrofit.RetrofitManager
import com.halo.assistant.HaloApp
import io.reactivex.Observable
class VideoCommentViewModel(application: Application) : ListViewModel<CommentEntity,CommentEntity>(application) {
class VideoCommentViewModel(application: Application, val videoId: String) : ListViewModel<CommentEntity, CommentEntity>(application) {
private val mApi = RetrofitManager.getInstance(getApplication()).api
var videoDetail: ForumVideoEntity? = null
override fun provideDataObservable(page: Int): Observable<MutableList<CommentEntity>>? {
return null
return mApi.getVideoCommentList(videoId, page)
}
override fun mergeResultLiveData() {
mResultLiveData.addSource(mListLiveData, mResultLiveData::postValue)
}
fun getLikeText(likeCount: Int, defaultLikeText: String = "赞同"): String {
return if (likeCount == 0) defaultLikeText else "$likeCount"
}
fun getCommentText(commentCount: Int, defaultComment: String): String {
return if (commentCount == 0) defaultComment else "$commentCount"
}
class Factory(private val videoId: String) : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return VideoCommentViewModel(HaloApp.getInstance().application, videoId) as T
}
}
}

View File

@ -17,9 +17,9 @@ import com.gh.gamecenter.manager.UserManager
import com.gh.gamecenter.qa.video.detail.ForumVideoDetailViewModel
class VideoDescTopViewHolder(val binding: ItemVideoDescTopBinding, var mIsExpand: Boolean, var mShrinkHeight: Int, var mExpandHeight: Int, val mVideoDetailViewModel: ForumVideoDetailViewModel, val mViewModel: VideoDescViewModel) : BaseRecyclerViewHolder<Any>(binding.root) {
private var mIsAnimationFinish = true
fun bindData(entity: ForumVideoEntity) {
initAnimation()
ImageUtils.display(binding.userAvatar, entity.user.icon)
binding.userNameTv.text = entity.user.name
binding.fansAndTimeTv.text = "${entity.user.count.fans}粉丝 · ${CommentUtils.getCommentTime(entity.time.upload)}"
@ -100,6 +100,7 @@ class VideoDescTopViewHolder(val binding: ItemVideoDescTopBinding, var mIsExpand
if (!mIsExpand) {
binding.titleTv.maxLines = Int.MAX_VALUE
}
mIsAnimationFinish = false
}
animator.doOnEnd {
if (mIsExpand) {
@ -107,8 +108,11 @@ class VideoDescTopViewHolder(val binding: ItemVideoDescTopBinding, var mIsExpand
}
mIsExpand = !mIsExpand
binding.expandMoreIv.rotation = if (mIsExpand) 180f else 0f
mIsAnimationFinish = true
}
if (mIsAnimationFinish) {
animator.start()
}
animator.start()
}
}

View File

@ -141,7 +141,7 @@ class VideoDescViewModel(application: Application) : ListViewModel<ForumVideoEnt
@SuppressLint("CheckResult")
private fun undoFavoriteVideo(videoId: String) {
RetrofitManager.getInstance(getApplication())
.api.collectVideo(UserManager.getInstance().userId, videoId)
.api.undoCollectVideo(UserManager.getInstance().userId, videoId)
.compose(singleToMain())
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {

View File

@ -6,6 +6,7 @@
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
@ -197,6 +198,10 @@
android:id="@+id/reuse_no_connection"
layout="@layout/reuse_no_connection" />
<include
android:id="@+id/reuse_none_data"
layout="@layout/reuse_none_data" />
<FrameLayout
android:id="@+id/skeleton"
android:layout_width="match_parent"

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/filterContainer"
@ -67,6 +68,7 @@
android:id="@+id/list_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_controller"
android:layout_below="@+id/filterContainer">
<androidx.recyclerview.widget.RecyclerView
@ -75,6 +77,37 @@
android:layout_height="wrap_content" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottomContainer"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:clickable="true"
android:focusable="true">
<TextView
android:id="@+id/replyTv"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="@drawable/bg_shape_f5_radius_999"
android:gravity="center_vertical"
android:text="说点什么吧"
android:includeFontPadding="false"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/text_cccccc"
android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<include
layout="@layout/reuse_loading"
android:layout_width="wrap_content"

View File

@ -16,21 +16,14 @@
<RelativeLayout
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#000000"
android:scaleType="fitCenter" >
android:layout_height="match_parent">
<ImageView
<com.gh.common.view.WrapContentDraweeView
android:id="@+id/thumbImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:scaleType="centerCrop" />
</RelativeLayout>
<include