Skip to content

Commit

Permalink
[Feat]: 优化页面
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Dec 10, 2023
1 parent 76e5cc5 commit f6e09f0
Show file tree
Hide file tree
Showing 28 changed files with 402 additions and 117 deletions.
50 changes: 50 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
</intent>
</queries>

<application
android:name="com.xiaoyv.common.MainApp"
android:allowBackup="true"
Expand All @@ -41,6 +47,50 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.xiaoyv.bangumi.ui.feature.scheme.SchemeActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="true"
android:launchMode="singleTask">

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- bgm://bangumi.android/route?data=xxx -->
<data
android:host="bangumi.android"
android:pathPattern="/route"
android:scheme="bgm" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- 处理链接 -->
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="bgm.tv" />
<data android:host="bangumi.tv" />
<data android:host="chii.in" />
<data android:host="next.bgm.tv" />
<data android:host="next.bangumi.tv" />
<data android:host="next.chii.in" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name=".ui.HomeActivity"
android:configChanges="orientation|keyboard|screenSize"
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.xiaoyv.bangumi.ui.profile.edit.EditProfileActivity
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.blueprint.kts.open
import com.xiaoyv.common.api.parser.entity.MediaDetailEntity
import com.xiaoyv.common.config.annotation.BgmPathType
import com.xiaoyv.common.config.annotation.TopicType
import com.xiaoyv.common.config.bean.SearchItem
import com.xiaoyv.common.helper.CacheHelper
Expand All @@ -39,11 +40,22 @@ import com.xiaoyv.common.kts.debugLog
* @since 11/25/23
*/
object RouteHelper {

/**
* - https://bangumi.tv/group/topic/390252#post_2535628
* - /person/57315
*/
fun handleUrl(titleLink: String) {
val id = titleLink.substringAfterLast("/")
.substringBefore("#")
.substringBefore("?")

when {
// 人物
titleLink.contains(BgmPathType.TYPE_PERSON) -> {
jumpPerson(id, false)
}
}

debugLog { "Handle Url: $titleLink" }
}

Expand Down Expand Up @@ -183,4 +195,8 @@ object RouteHelper {
bundleOf(NavKey.KEY_SERIALIZABLE_ARRAY to htmlSummary)
)
}

fun jumpRatingDetail() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class GroupDetailActivity :
binding.tvDesc.text = entity.id
binding.toolbar.title = entity.name
binding.tvTime.text = entity.time
binding.tvSummary.text = entity.summaryText.ifBlank { "这个小组暂时没有介绍呢" }
binding.tvSummary.text = entity.summary.ifBlank { "这个小组暂时没有介绍呢" }
binding.tvSummary.setOnFastLimitClickListener {
RouteHelper.jumpSummaryDetail(entity.summaryHtml)
}

recentlyAdapter.submitList(entity.recently)
otherAdapter.submitList(entity.otherGroups)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.xiaoyv.bangumi.helper.RouteHelper
import com.xiaoyv.blueprint.base.mvvm.normal.BaseViewModelActivity
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.blueprint.kts.toJson
import com.xiaoyv.common.helper.FixHelper
import com.xiaoyv.common.helper.UserHelper
import com.xiaoyv.common.kts.CommonDrawable
import com.xiaoyv.common.kts.debugLog
Expand All @@ -23,6 +24,7 @@ import com.xiaoyv.common.kts.showConfirmDialog
import com.xiaoyv.common.widget.dialog.AnimeLoadingDialog
import com.xiaoyv.widget.callback.setOnFastLimitClickListener
import com.xiaoyv.widget.dialog.UiDialog
import com.xiaoyv.widget.kts.dpi

/**
* Class: [PersonActivity]
Expand All @@ -49,6 +51,8 @@ class PersonActivity : BaseViewModelActivity<ActivityPersonBinding, PersonViewMo

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

FixHelper.fixCool(binding.ivBanner, binding.toolbarLayout, 204.dpi)
}

override fun initData() {
Expand Down Expand Up @@ -78,18 +82,19 @@ class PersonActivity : BaseViewModelActivity<ActivityPersonBinding, PersonViewMo
val entity = it ?: return@observe
debugLog { "Person: " + entity.toJson(true) }

binding.ivBanner.loadImageBlur(entity.poster)
binding.ivCover.loadImageBlurBackground(entity.poster)
binding.ivCover.loadImageAnimate(entity.poster, centerCrop = false)
binding.ivCover.setOnFastLimitClickListener {
RouteHelper.jumpPreviewImage(entity.posterLarge)
}
binding.toolbar.title = entity.nameNative

binding.toolbar.title = entity.nameNative
binding.tvTitle.text = entity.nameNative
binding.tvSubtitle.text = entity.nameCn
binding.tvJob.text = if (entity.isVirtual) "虚拟角色" else entity.job

binding.ivBanner.loadImageBlur(entity.poster)

invalidateOptionsMenu()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.xiaoyv.bangumi.ui.feature.scheme

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.EncodeUtils
import com.xiaoyv.bangumi.databinding.ActivitySchemeBinding
import com.xiaoyv.bangumi.helper.RouteHelper
import com.xiaoyv.blueprint.base.binding.BaseBindingActivity
import com.xiaoyv.common.kts.debugLog
import com.xiaoyv.widget.callback.setOnFastLimitClickListener

/**
* Class: [SchemeActivity]
*
* @author why
* @since 12/10/23
*/
class SchemeActivity : BaseBindingActivity<ActivitySchemeBinding>() {

override fun initIntentData(intent: Intent, bundle: Bundle, isNewIntent: Boolean) {
val scheme = intent.scheme ?: return
val uri = intent.data ?: return
handleDeepLink(scheme, uri)
}

override fun initView() {

}

override fun initData() {

}

override fun initListener() {
binding.btnJump.setOnFastLimitClickListener {
ActivityUtils.startActivity(
Intent.createChooser(
Intent.parseUri("https://bgm.tv/subject_search/", Intent.URI_ALLOW_UNSAFE),
"跳转"
)
)
}
}

private fun handleDeepLink(scheme: String, uri: Uri) {
debugLog { "Scheme: $scheme, uri: $uri" }

when (scheme) {
"bgm" -> {
val routeData = uri.getQueryParameter("data").orEmpty().let {
EncodeUtils.base64Decode(it).decodeToString()
}
if (routeData.isNotBlank()) {
RouteHelper.handleUrl(routeData)
}
}

else -> RouteHelper.handleUrl(uri.toString())
}
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.core.text.method.LinkMovementMethodCompat
import androidx.lifecycle.LifecycleOwner
import com.xiaoyv.bangumi.databinding.ActivitySummaryBinding
import com.xiaoyv.bangumi.helper.RouteHelper
import com.xiaoyv.blueprint.base.mvvm.normal.BaseViewModelActivity
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.common.api.parser.parseHtml
import com.xiaoyv.common.kts.CommonDrawable
import com.xiaoyv.common.kts.initNavBack
import com.xiaoyv.common.kts.openInBrowser
Expand All @@ -25,22 +25,27 @@ import com.xiaoyv.widget.dialog.UiDialog
*/
class SummaryActivity : BaseViewModelActivity<ActivitySummaryBinding, SummaryViewModel>() {
override fun initIntentData(intent: Intent, bundle: Bundle, isNewIntent: Boolean) {
viewModel.summary.value = bundle.getStringArray(NavKey.KEY_SERIALIZABLE_ARRAY).orEmpty()
viewModel.summary = bundle.getStringArray(NavKey.KEY_SERIALIZABLE_ARRAY).orEmpty()
}

override fun initView() {
binding.toolbar.initNavBack(this)
binding.tvSummary.isClickable = true
binding.tvSummary.movementMethod = LinkMovementMethodCompat.getInstance()
}

override fun initData() {

viewModel.showOriginal()
}

override fun LifecycleOwner.initViewObserver() {
viewModel.summary.observe(this) {
binding.stateView.initObserver(this, viewModel.loadingViewState)

viewModel.summaryOriginal.observe(this) {
binding.tvSummary.text = null
it.forEach { text ->
binding.tvSummary.append(text.parseHtml())

it.orEmpty().forEach { text ->
binding.tvSummary.append(text)
binding.tvSummary.append("\n")
}

Expand Down Expand Up @@ -69,6 +74,10 @@ class SummaryActivity : BaseViewModelActivity<ActivitySummaryBinding, SummaryVie
}
}

override fun initListener() {

}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (viewModel.isShowOriginal) {
menu.add("翻译")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import kotlinx.coroutines.withContext
* @since 12/10/23
*/
class SummaryViewModel : BaseViewModel() {
internal var summary = MutableLiveData<Array<out String>>()
internal var summary: Array<out String> = emptyArray()
internal var summaryOriginal = MutableLiveData<List<CharSequence>?>()
internal var summaryTranslate = MutableLiveData<String>()
internal var isShowOriginal = true

Expand All @@ -32,7 +33,7 @@ class SummaryViewModel : BaseViewModel() {
* 待翻译的文本
*/
private val needTranslateText: String
get() = summary.value.orEmpty().joinToString("\n") {
get() = summary.joinToString("\n") {
it.parseHtml().toString().trim()
}

Expand All @@ -43,25 +44,24 @@ class SummaryViewModel : BaseViewModel() {
* 直接刷新
*/
fun showOriginal() {
isShowOriginal = true
summary.value = summary.value
launchUI(stateView = loadingViewState) {
isShowOriginal = true
summaryOriginal.value = withContext(Dispatchers.IO) {
summary.map { it.parseHtml() }
}
}
}

fun shoTranslate() {
isShowOriginal = false

launchUI(
state = loadingDialogState(cancelable = false),
stateView = loadingViewState,
error = {
it.printStackTrace()

if (it is IllegalArgumentException) {
onNeedConfig.value = Unit
} else {
showToastCompat(it.errorMsg)
}
showToastCompat(it.errorMsg)
},
block = {
isShowOriginal = false
val translate = CacheHelper.readTranslate(cacheKey)
if (translate.isNotBlank()) {
summaryTranslate.value = translate
Expand All @@ -72,7 +72,10 @@ class SummaryViewModel : BaseViewModel() {
val salt = System.currentTimeMillis().toString()
val sign = generateSign(needTranslateText, appId, secret, salt)

require(appId.isNotBlank() && secret.isNotBlank()) { "请先配置百度翻译的 AppId 和 Secret " }
if (appId.isBlank() || secret.isBlank()) {
onNeedConfig.value = Unit
return@launchUI
}

val result: BaiduTranslateEntity = withContext(Dispatchers.IO) {
BgmApiManager.bgmJsonApi.postBaiduTranslate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,7 @@ class UserActivity : BaseViewModelActivity<ActivityUserBinding, UserViewModel>()
}

override fun initListener() {
binding.appBar.addOnOffsetChangedListener { _, i ->
binding.fabTop.isVisible =
abs(i) < 100.dpi && binding.vpContent.currentItem == vpAdapter.itemCount - 1
}

binding.fabTop.setOnFastLimitClickListener {
binding.appBar.setExpanded(false, true)
}
}

override fun LifecycleOwner.initViewObserver() {
Expand Down
Loading

0 comments on commit f6e09f0

Please sign in to comment.