Skip to content

Commit

Permalink
[Feat]: 收藏文案优化
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Dec 21, 2023
1 parent 007bdb2 commit 2c8f799
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlinx.coroutines.withContext
*/
class UserViewModel : BaseViewModel() {
internal val onUserInfoLiveData = MutableLiveData<UserDetailEntity?>()
internal val onActionResult = MutableLiveData<Boolean>()
private val onActionResult = MutableLiveData<Boolean>()

var userId: String = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UserOverviewAdapter : BaseMultiItemAdapter<Any>() {
override fun onBind(
holder: BaseQuickBindingHolder<FragmentUserOverviewTitleBinding>,
position: Int,
item: Any?
item: Any?,
) {
val overview = item as? UserDetailEntity.SaveOverview
holder.binding.tvTitle.text = overview?.title
Expand All @@ -52,7 +52,7 @@ class UserOverviewAdapter : BaseMultiItemAdapter<Any>() {
override fun onCreate(
context: Context,
parent: ViewGroup,
viewType: Int
viewType: Int,
): BaseQuickBindingHolder<FragmentUserOverviewTitleBinding> {
return BaseQuickBindingHolder(
FragmentUserOverviewTitleBinding.inflate(context.inflater, parent, false)
Expand All @@ -65,14 +65,14 @@ class UserOverviewAdapter : BaseMultiItemAdapter<Any>() {
}

/**
* 收藏的媒体表格
* 用户页面收藏的媒体表格
*/
private class ItemGridBinder :
OnMultiItemAdapterListener<Any, BaseQuickBindingHolder<FragmentUserOverviewItemBinding>> {
override fun onBind(
holder: BaseQuickBindingHolder<FragmentUserOverviewItemBinding>,
position: Int,
item: Any?
item: Any?,
) {
val relative = item as? MediaDetailEntity.MediaRelative ?: return
if (relative.id.isBlank()) {
Expand All @@ -85,14 +85,13 @@ class UserOverviewAdapter : BaseMultiItemAdapter<Any>() {
holder.binding.ivCover.loadImageAnimate(relative.cover)
}

@SuppressLint("WrongConstant")
holder.binding.tvTip.text = InterestType.string(relative.type)
holder.binding.tvTip.text = InterestType.string(relative.collectType, relative.type)
}

override fun onCreate(
context: Context,
parent: ViewGroup,
viewType: Int
viewType: Int,
): BaseQuickBindingHolder<FragmentUserOverviewItemBinding> {
return BaseQuickBindingHolder(
FragmentUserOverviewItemBinding.inflate(context.inflater, parent, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,28 @@ class MediaChapterAdapter : BaseQuickDiffBindingAdapter<MediaChapterEntity,
when {
// 看过
item.collectType == InterestType.TYPE_COLLECT -> {
binding.vAired.text = InterestType.string(item.collectType)
binding.vAired.text = item.collectStateText
binding.vAired.backgroundTintList = context.getColor(CommonColor.save_collect).tint
binding.vAired.setTextColor(context.getColor(CommonColor.save_collect_text))
}
// 想看
item.collectType == InterestType.TYPE_WISH -> {
binding.vAired.text = InterestType.string(item.collectType)
binding.vAired.text = item.collectStateText
binding.vAired.backgroundTintList = context.getColor(CommonColor.save_wish).tint
binding.vAired.setTextColor(context.getColor(CommonColor.save_wish_text))
}
// 抛弃
item.collectType == InterestType.TYPE_DROPPED -> {
binding.vAired.text = InterestType.string(item.collectType)
binding.vAired.text = item.collectStateText
binding.vAired.backgroundTintList = context.getColor(CommonColor.save_dropped).tint
binding.vAired.setTextColor(context.getColor(CommonColor.save_dropped_text))
}
// 放送中
item.isAiring -> {
binding.vAired.text = item.airedStateText
binding.vAired.backgroundTintList = context.getColor(CommonColor.state_airing).tint
binding.vAired.setTextColor(context.getColor(CommonColor.state_airing_text))
}
// 已经播出
item.isAired -> {
binding.vAired.text = item.airedStateText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OverviewSaveBinder(private var onSaveBtnClickListener: (AdapterTypeItem, I

holder.binding.tvSave.text = StringUtils.getString(
CommonString.media_save_tip,
InterestType.string(collectState.interest),
InterestType.string(collectState.interest, mediaType),
GlobalConfig.mediaTypeName(mediaType)
)
holder.binding.tvSave.setOnFastLimitClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,71 @@
package com.xiaoyv.bangumi.ui.profile.page.save

import android.os.Bundle
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.QuickAdapterHelper
import com.chad.library.adapter.base.loadState.LoadState
import com.chad.library.adapter.base.loadState.trailing.TrailingLoadStateAdapter
import androidx.core.view.doOnPreDraw
import androidx.core.view.updateLayoutParams
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.xiaoyv.bangumi.R
import com.xiaoyv.bangumi.databinding.FragmentSaveListBinding
import com.xiaoyv.bangumi.base.BaseListFragment
import com.xiaoyv.bangumi.helper.RouteHelper
import com.xiaoyv.blueprint.base.mvvm.normal.BaseViewModelFragment
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.common.api.parser.entity.BrowserEntity
import com.xiaoyv.common.config.GlobalConfig
import com.xiaoyv.common.config.annotation.InterestCollectType
import com.xiaoyv.common.config.annotation.InterestType
import com.xiaoyv.common.databinding.ViewSaveListFilterBinding
import com.xiaoyv.common.helper.UserHelper
import com.xiaoyv.common.kts.GoogleAttr
import com.xiaoyv.common.kts.CommonId
import com.xiaoyv.common.kts.setOnDebouncedChildClickListener
import com.xiaoyv.widget.binder.BaseQuickDiffBindingAdapter
import com.xiaoyv.widget.callback.setOnFastLimitClickListener
import com.xiaoyv.widget.kts.getAttrColor

/**
* Class: [SaveListFragment]
*
* @author why
* @since 11/24/23
*/
class SaveListFragment : BaseViewModelFragment<FragmentSaveListBinding, SaveListViewModel>() {
class SaveListFragment : BaseListFragment<BrowserEntity.Item, SaveListViewModel>() {
private val mediaTypes get() = GlobalConfig.mediaTypes

private val contentAdapter by lazy { SaveListAdapter() }
private lateinit var filter: ViewSaveListFilterBinding

private val adapterHelper by lazy {
QuickAdapterHelper.Builder(contentAdapter)
.setTrailingLoadStateAdapter(object : TrailingLoadStateAdapter.OnTrailingListener {
override fun isAllowLoading(): Boolean {
return binding.srlRefresh.isRefreshing.not()
}
override val isOnlyOnePage: Boolean
get() = false

override fun onFailRetry() {
viewModel.loadMore()
}
override val loadingBias: Float
get() = 0.3f

override fun onLoad() {
viewModel.loadMore()
}
})
.build()
override fun onCreateContentAdapter(): BaseQuickDiffBindingAdapter<BrowserEntity.Item, *> {
return SaveListAdapter()
}

private val layoutManager: LinearLayoutManager?
get() = binding.rvContent.layoutManager as? LinearLayoutManager

private val mediaTypes get() = GlobalConfig.mediaTypes

override fun initArgumentsData(arguments: Bundle) {
viewModel.userId = arguments.getString(NavKey.KEY_STRING).orEmpty()
viewModel.requireLogin = arguments.getBoolean(NavKey.KEY_BOOLEAN, false)
}

override fun initView() {
binding.srlRefresh.initRefresh { false }
binding.srlRefresh.setColorSchemeColors(hostActivity.getAttrColor(GoogleAttr.colorPrimary))
}
super.initView()

override fun initData() {
binding.rvContent.setHasFixedSize(true)
binding.rvContent.adapter = adapterHelper.adapter
}
// 过滤菜单
filter = ViewSaveListFilterBinding.inflate(layoutInflater, binding.flContainer, true)
filter.root.doOnPreDraw {
binding.rvContent.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = filter.root.height
}
}

override fun initListener() {
binding.listType.setOnCheckedStateChangeListener { _, ints ->
// 切换
filter.listType.setOnCheckedStateChangeListener { _, ints ->
val type = when (ints.firstOrNull()) {
R.id.type_wish -> InterestCollectType.TYPE_WISH
R.id.type_collect -> InterestCollectType.TYPE_COLLECT
R.id.type_do -> InterestCollectType.TYPE_DO
R.id.type_on_hold -> InterestCollectType.TYPE_ON_HOLD
R.id.type_dropped -> InterestCollectType.TYPE_DROPPED
CommonId.type_wish -> InterestCollectType.TYPE_WISH
CommonId.type_collect -> InterestCollectType.TYPE_COLLECT
CommonId.type_do -> InterestCollectType.TYPE_DO
CommonId.type_on_hold -> InterestCollectType.TYPE_ON_HOLD
CommonId.type_dropped -> InterestCollectType.TYPE_DROPPED
else -> null
}

Expand All @@ -86,55 +75,50 @@ class SaveListFragment : BaseViewModelFragment<FragmentSaveListBinding, SaveList
}
}

binding.chipMediaType.setOnFastLimitClickListener {
// 类别切换
filter.chipMediaType.setOnFastLimitClickListener {
val item = mediaTypes.map { it.title }.toTypedArray()
MaterialAlertDialogBuilder(hostActivity)
.setItems(item) { _, position ->
binding.chipMediaType.text = mediaTypes[position].title
viewModel.mediaType = mediaTypes[position].type
val mediaType = mediaTypes[position].type
filter.chipMediaType.text = mediaTypes[position].title

// 设置文案
filter.typeWish.text = InterestType.string(InterestType.TYPE_WISH, mediaType)
filter.typeCollect.text =
InterestType.string(InterestType.TYPE_COLLECT, mediaType)
filter.typeDo.text = InterestType.string(InterestType.TYPE_DO, mediaType)
filter.typeOnHold.text =
InterestType.string(InterestType.TYPE_ON_HOLD, mediaType)
filter.typeDropped.text =
InterestType.string(InterestType.TYPE_DROPPED, mediaType)

// 刷新
viewModel.mediaType = mediaType
viewModel.refresh()
}
.create()
.show()
}
}

binding.srlRefresh.setOnRefreshListener {
adapterHelper.trailingLoadState = LoadState.None
viewModel.refresh()
}
override fun initListener() {
super.initListener()

contentAdapter.setOnDebouncedChildClickListener(R.id.item_save) {
RouteHelper.jumpMediaDetail(it.id)
}
}

override fun LifecycleOwner.initViewObserver() {
binding.stateView.initObserver(
lifecycleOwner = this,
loadingBias = 0.3f,
loadingViewState = viewModel.loadingViewState,
canShowLoading = { viewModel.isRefresh && !binding.srlRefresh.isRefreshing },
canShowTip = { viewModel.isRefresh }
)

viewModel.onListLiveData.observe(this) {
contentAdapter.submitList(it.orEmpty()) {
if (viewModel.isRefresh) {
layoutManager?.scrollToPositionWithOffset(0, 0)
}

adapterHelper.trailingLoadState = viewModel.loadingMoreState
}
}

override fun autoInitData() {
// 嵌套在 Profile 页面的情况
if (viewModel.requireLogin) {
UserHelper.observeUserInfo(this) {
viewModel.userId = it.id.orEmpty()
viewModel.refresh()
}
} else {
viewModel.refresh()
super.autoInitData()
}
}

Expand Down
Loading

0 comments on commit 2c8f799

Please sign in to comment.