Skip to content

Commit

Permalink
[Feat]: 用户详情页面补充
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Dec 18, 2023
1 parent 0902fab commit b9fdb14
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 60 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@
android:name="com.xiaoyv.bangumi.ui.feature.setting.robot.RobotConfigActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="false" />
<activity
android:name="com.xiaoyv.bangumi.ui.feature.user.blog.UserBlogActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="false" />
</application>

</manifest>
25 changes: 22 additions & 3 deletions app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.xiaoyv.bangumi.ui.feature.summary.SummaryActivity
import com.xiaoyv.bangumi.ui.feature.tag.TagDetailActivity
import com.xiaoyv.bangumi.ui.feature.topic.TopicActivity
import com.xiaoyv.bangumi.ui.feature.user.UserActivity
import com.xiaoyv.bangumi.ui.feature.user.blog.UserBlogActivity
import com.xiaoyv.bangumi.ui.feature.web.WebActivity
import com.xiaoyv.bangumi.ui.media.detail.MediaDetailActivity
import com.xiaoyv.bangumi.ui.profile.edit.EditProfileActivity
Expand All @@ -52,6 +53,7 @@ import com.xiaoyv.common.config.bean.SearchItem
import com.xiaoyv.common.helper.CacheHelper
import com.xiaoyv.common.kts.debugLog
import com.xiaoyv.common.kts.decodeUrl
import com.xiaoyv.widget.kts.showToastCompat

/**
* Class: [RouteHelper]
Expand Down Expand Up @@ -226,6 +228,13 @@ object RouteHelper {
)
}

fun jumpUserBlog(userId: String) {
ActivityUtils.startActivity(
bundleOf(NavKey.KEY_STRING to userId),
UserBlogActivity::class.java
)
}

fun jumpPostTopic(postAttach: PostAttach? = null) {
ActivityUtils.startActivity(
bundleOf(NavKey.KEY_PARCELABLE to postAttach),
Expand Down Expand Up @@ -270,8 +279,18 @@ object RouteHelper {
IndexDetailActivity::class.open(bundleOf(NavKey.KEY_STRING to id))
}

fun jumpIndexList(isSortByNewest: Boolean) {
IndexListActivity::class.open(bundleOf(NavKey.KEY_BOOLEAN to isSortByNewest))
/**
* 目录列表查询,没有指定用户则查询全部目录
*
* @param targetUserId 如果指定了用户ID,[isSortByNewest] 则表示是否查询用户创建的目录,否则查询收藏的目录
*/
fun jumpIndexList(isSortByNewest: Boolean, targetUserId: String? = null) {
IndexListActivity::class.open(
bundleOf(
NavKey.KEY_BOOLEAN to isSortByNewest,
NavKey.KEY_STRING to targetUserId
)
)
}

fun jumpGroupList() {
Expand Down Expand Up @@ -393,7 +412,7 @@ object RouteHelper {
}

fun jumpSendMessage(userId: String) {

showToastCompat("正在开发中...")
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.xiaoyv.bangumi.ui.discover.blog

import com.blankj.utilcode.util.StringUtils
import com.xiaoyv.bangumi.base.BaseListViewModel
import com.xiaoyv.blueprint.kts.launchUI
import com.xiaoyv.common.api.BgmApiManager
import com.xiaoyv.common.api.parser.entity.BlogEntity
import com.xiaoyv.common.api.parser.impl.parserBlogList
import com.xiaoyv.common.config.annotation.MediaType
import com.xiaoyv.common.helper.UserHelper
import com.xiaoyv.common.kts.CommonString

/**
* Class: [BlogViewModel]
Expand Down Expand Up @@ -48,30 +45,8 @@ class BlogViewModel : BaseListViewModel<BlogEntity>() {
require(UserHelper.isLogin) { "你还没有登录呢" }
}

return BgmApiManager.bgmWebApi.queryBlogList(
queryPath = queryPath,
tagPath = tagPath,
page = current
).parserBlogList(userId.isNotBlank()).apply {
// 刷新时,检测是否为空数据
if (isRefresh) require(isNotEmpty()) {
StringUtils.getString(CommonString.common_empty_tip)
}
}
}

private fun queryBlogList() {
launchUI(
stateView = loadingViewState,
error = {
it.printStackTrace()
if (isRefresh) onListLiveData.value = null
else current--
},
block = {

}
)
return BgmApiManager.bgmWebApi.queryBlogList(queryPath, tagPath, current)
.parserBlogList(userId.isNotBlank(), isMine)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class IndexListActivity : BaseListActivity<IndexItemEntity, IndexListViewModel>(

override fun initIntentData(intent: Intent, bundle: Bundle, isNewIntent: Boolean) {
viewModel.isSortByNewest = bundle.getBoolean(NavKey.KEY_BOOLEAN, false)
viewModel.userId = bundle.getString(NavKey.KEY_STRING).orEmpty()
}

override fun initListener() {
Expand All @@ -43,24 +44,24 @@ class IndexListActivity : BaseListActivity<IndexItemEntity, IndexListViewModel>(

override fun onListDataFinish(list: List<IndexItemEntity>) {
binding.toolbar.title = if (viewModel.isSortByNewest) {
"目录列表-时间排序"
if (viewModel.queryForUser) "目录列表-TA 的创建" else "目录列表-时间排序"
} else {
"目录列表-热门排序"
if (viewModel.queryForUser) "目录列表-TA 的收藏" else "目录列表-热门排序"
}

invalidateMenu()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (viewModel.isSortByNewest) {
menu.add("按热门排序")
menu.add(if (viewModel.queryForUser) "TA 收藏的目录" else "按热门排序")
.setOnMenuItemClickListener {
viewModel.isSortByNewest = false
viewModel.refresh()
true
}
} else {
menu.add("按创建时间排序")
menu.add(if (viewModel.queryForUser) "TA 创建的目录" else "按热门排序")
.setOnMenuItemClickListener {
viewModel.isSortByNewest = true
viewModel.refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,32 @@ class IndexListViewModel : BaseListViewModel<IndexItemEntity>() {
internal val isMine: Boolean
get() = userId.isNotBlank() && userId == UserHelper.currentUser.id

internal val queryForUser: Boolean
get() = userId.isNotBlank()

override suspend fun onRequestListImpl(): List<IndexItemEntity> {
if (requireLogin) {
require(UserHelper.isLogin) { "你还没有登录呢" }
}

return if (userId.isNotBlank()) {
BgmApiManager.bgmWebApi.queryUserIndex(userId, current)
.parserUserIndexList()
} else {
BgmApiManager.bgmWebApi.queryIndexList(
orderBy = if (isSortByNewest) null else "collect",
page = current
).parserIndexList()
return when {
// 查询指定用户的目录
queryForUser -> {
// 是否拼接查询收藏路径,复用下 isSortByNewest 字段
// 指定用户ID时,isSortByNewest == true,查询创建的目录,反之查询收藏的目录
val queryCollect = if (isSortByNewest) "" else "/collect"
BgmApiManager.bgmWebApi.queryUserIndex(userId, queryCollect, current).let {
if (isSortByNewest) it.parserUserIndexList()
else it.parserIndexList()
}
}
// 查询全部目录列表
else -> {
BgmApiManager.bgmWebApi.queryIndexList(
orderBy = if (isSortByNewest) null else "collect",
page = current
).parserIndexList()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.xiaoyv.common.kts.randomY
import com.xiaoyv.common.kts.showConfirmDialog
import com.xiaoyv.common.widget.dialog.AnimeLoadingDialog
import com.xiaoyv.common.widget.dialog.AnimeReportDialog
import com.xiaoyv.widget.callback.setOnFastLimitClickListener
import com.xiaoyv.widget.dialog.UiDialog


Expand Down Expand Up @@ -82,7 +83,13 @@ class UserActivity : BaseViewModelActivity<ActivityUserBinding, UserViewModel>()
}

override fun initListener() {
binding.bottomRightTextView.setOnFastLimitClickListener {
RouteHelper.jumpIndexList(true, viewModel.userId)
}

binding.middleRightTextView.setOnFastLimitClickListener {
RouteHelper.jumpUserBlog(viewModel.userId)
}
}

override fun LifecycleOwner.initViewObserver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.xiaoyv.bangumi.ui.feature.user.chart.ChartFragment
import com.xiaoyv.bangumi.ui.feature.user.overview.UserOverviewFragment
import com.xiaoyv.bangumi.ui.feature.user.sign.SignFragment
import com.xiaoyv.bangumi.ui.profile.page.save.SaveListFragment
import com.xiaoyv.bangumi.ui.timeline.page.TimelinePageFragment
import com.xiaoyv.common.config.annotation.TimelineType
import com.xiaoyv.common.config.annotation.UserCenterType
import com.xiaoyv.common.config.bean.UserCenterTab

Expand All @@ -28,7 +30,6 @@ class UserAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
UserCenterTab("收藏", UserCenterType.TYPE_SAVE),
UserCenterTab("统计", UserCenterType.TYPE_CHART),
UserCenterTab("时间线", UserCenterType.TYPE_TIMELINE),
UserCenterTab("超展开", UserCenterType.TYPE_SUPER),
UserCenterTab("关于", UserCenterType.TYPE_ABOUT)
)

Expand All @@ -40,6 +41,11 @@ class UserAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
UserCenterType.TYPE_SAVE -> SaveListFragment.newInstance(userId)
UserCenterType.TYPE_ABOUT -> SignFragment.newInstance()
UserCenterType.TYPE_CHART -> ChartFragment.newInstance()
UserCenterType.TYPE_TIMELINE -> TimelinePageFragment.newInstance(
type = TimelineType.TYPE_ALL,
userId = userId,
requireLogin = false
)
else -> EmptyFragment.newInstance()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.xiaoyv.bangumi.ui.feature.user.blog

import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import com.xiaoyv.bangumi.databinding.ActivityUserBlogListBinding
import com.xiaoyv.bangumi.ui.discover.blog.BlogFragment
import com.xiaoyv.blueprint.base.binding.BaseBindingActivity
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.blueprint.kts.LazyUtils.loadRootFragment
import com.xiaoyv.common.kts.initNavBack

/**
* Class: [UserBlogActivity]
*
* @author why
* @since 12/19/23
*/
class UserBlogActivity : BaseBindingActivity<ActivityUserBlogListBinding>() {
private var userId: String = ""

override fun initIntentData(intent: Intent, bundle: Bundle, isNewIntent: Boolean) {
userId = bundle.getString(NavKey.KEY_STRING).orEmpty()
}

override fun initView() {
binding.toolbar.initNavBack(this)
}

override fun initData() {
loadRootFragment(binding.flContainer.id, BlogFragment.newInstance(userId, false))
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
item.initNavBack(this)
return super.onOptionsItemSelected(item)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.xiaoyv.common.api.parser.entity.MediaDetailEntity
import com.xiaoyv.common.config.annotation.InterestType
import com.xiaoyv.common.helper.callback.IdDiffItemCallback
import com.xiaoyv.common.helper.callback.RecyclerItemTouchedListener
import com.xiaoyv.common.kts.CommonColor
import com.xiaoyv.common.kts.GoogleAttr
import com.xiaoyv.common.kts.forceCast
import com.xiaoyv.common.kts.inflater
Expand Down Expand Up @@ -98,6 +99,13 @@ class OverviewEpBinder(
override fun BaseQuickBindingHolder<FragmentOverviewEpItemBinding>.converted(item: MediaDetailEntity.MediaProgress) {
binding.tvEp.text = item.number
when {
item.isWatched -> {
binding.tvEp.setTextColor(context.getAttrColor(GoogleAttr.colorOnPrimarySurface))
binding.tvEp.backgroundTintList = ColorStateList.valueOf(
context.getColor(CommonColor.save_collect)
)
}

item.isRelease -> {
binding.tvEp.setTextColor(context.getAttrColor(GoogleAttr.colorOnPrimaryContainer))
binding.tvEp.backgroundTintList = ColorStateList.valueOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class ProfileAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :

internal val tabs = listOf(
ProfileTab("收藏", ProfileType.TYPE_COLLECTION),
ProfileTab("日志", ProfileType.TYPE_BLOG),
ProfileTab("目录", ProfileType.TYPE_INDEX),
ProfileTab("时间胶囊", ProfileType.TYPE_TIMELINE),
ProfileTab("日志", ProfileType.TYPE_BLOG),
ProfileTab("小组", ProfileType.TYPE_GROUP),
ProfileTab("好友", ProfileType.TYPE_FRIEND),
ProfileTab("人物", ProfileType.TYPE_MONO),
ProfileTab("小组", ProfileType.TYPE_GROUP),
ProfileTab("时间胶囊", ProfileType.TYPE_TIMELINE),
ProfileTab("维基", ProfileType.TYPE_WIKI)
)

Expand All @@ -49,7 +49,7 @@ class ProfileAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
)
// 时间线
ProfileType.TYPE_TIMELINE -> TimelinePageFragment.newInstance(
type = TimelineType.TYPE_USER,
type = TimelineType.TYPE_ALL,
userId = myId,
requireLogin = true
)
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/xiaoyv/bangumi/ui/profile/ProfileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.LifecycleOwner
import com.blankj.utilcode.util.ColorUtils
import com.google.android.material.badge.BadgeDrawable
import com.google.android.material.badge.BadgeUtils
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.xiaoyv.bangumi.databinding.FragmentProfileBinding
import com.xiaoyv.bangumi.helper.RouteHelper
Expand Down Expand Up @@ -79,6 +80,19 @@ class ProfileFragment : BaseViewModelFragment<FragmentProfileBinding, ProfileVie
}
}

binding.tableLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(p0: TabLayout.Tab?) {
binding.appBar.setExpanded(false, true)
}

override fun onTabUnselected(p0: TabLayout.Tab?) {
}

override fun onTabReselected(p0: TabLayout.Tab?) {
binding.appBar.setExpanded(false, true)
}
})

binding.ivAvatar.setOnFastLimitClickListener {
editProfileOrLogin()
}
Expand Down
Loading

0 comments on commit b9fdb14

Please sign in to comment.