Skip to content

Commit

Permalink
[Feat]: snapshot 版本脚本修复
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Apr 16, 2024
1 parent e4997cb commit eafff0d
Show file tree
Hide file tree
Showing 70 changed files with 7,111 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@
android:name="com.xiaoyv.bangumi.ui.feature.friendly.rank.FriendRankDetailActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="false" />
<activity
android:name="com.xiaoyv.bangumi.special.subtitle.SubtitleToolActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="false" />

<receiver
android:name="com.xiaoyv.bangumi.special.widget.AnimeWidget"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.xiaoyv.bangumi.special.magnet.MagnetActivity
import com.xiaoyv.bangumi.special.mikan.MikanActivity
import com.xiaoyv.bangumi.special.mikan.resource.MikanResourceActivity
import com.xiaoyv.bangumi.special.picture.AnimePicturesNetActivity
import com.xiaoyv.bangumi.special.subtitle.SubtitleToolActivity
import com.xiaoyv.bangumi.special.syncer.SyncerActivity
import com.xiaoyv.bangumi.special.syncer.list.SyncerListActivity
import com.xiaoyv.bangumi.special.thunder.ThunderActivity
Expand Down Expand Up @@ -507,6 +508,10 @@ object RouteHelper {
MagnetActivity::class.open(bundleOf(NavKey.KEY_STRING to keyword))
}

fun jumpSubtitleTool() {
SubtitleToolActivity::class.open()
}

fun jumpAlmanac() {
AlmanacActivity::class.open()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.xiaoyv.bangumi.special.subtitle

import android.view.MenuItem
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.CallSuper
import com.xiaoyv.bangumi.databinding.ActivitySubtitleToolBinding
import com.xiaoyv.blueprint.base.mvvm.normal.BaseViewModelActivity
import com.xiaoyv.common.kts.initNavBack
import com.xiaoyv.common.widget.dialog.AnimeLoadingDialog
import com.xiaoyv.widget.callback.setOnFastLimitClickListener
import com.xiaoyv.widget.dialog.UiDialog

class SubtitleToolActivity :
BaseViewModelActivity<ActivitySubtitleToolBinding, SubtitleToolViewModel>() {

private val selectSubtitleLauncher =
registerForActivityResult(ActivityResultContracts.GetContent()) {
viewModel.loadSubtitleFromMedia(it ?: return@registerForActivityResult)
}

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

override fun initData() {

}

override fun initListener() {
binding.btnSubtitle.setOnFastLimitClickListener {
selectSubtitleLauncher.launch("*/*")
}
}

override fun onCreateLoadingDialog(): UiDialog {
return AnimeLoadingDialog(this)
}

@CallSuper
override fun onOptionsItemSelected(item: MenuItem): Boolean {
item.initNavBack(this)
return super.onOptionsItemSelected(item)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.xiaoyv.bangumi.special.subtitle

import android.net.Uri
import androidx.media3.common.DataReader
import androidx.media3.common.Format
import androidx.media3.common.MediaItem
import androidx.media3.common.MimeTypes
import androidx.media3.common.util.UnstableApi
import androidx.media3.extractor.DefaultExtractorInput
import androidx.media3.extractor.DefaultExtractorsFactory
import androidx.media3.extractor.ExtractorOutput
import androidx.media3.extractor.PositionHolder
import androidx.media3.extractor.mp4.Mp4Extractor
import androidx.media3.extractor.text.DefaultSubtitleParserFactory
import androidx.media3.extractor.text.SubtitleParser
import com.xiaoyv.blueprint.base.mvvm.normal.BaseViewModel
import com.xiaoyv.blueprint.kts.launchUI
import com.xiaoyv.blueprint.kts.toJson
import com.xiaoyv.common.kts.debugLog
import com.xiaoyv.common.kts.inputStream
import com.xiaoyv.widget.kts.errorMsg
import com.xiaoyv.widget.kts.showToastCompat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@UnstableApi
class SubtitleToolViewModel : BaseViewModel() {

fun loadSubtitleFromMedia(uri: Uri) {
launchUI(error = {
it.printStackTrace()

}) {
// SubtitleExtractor
withContext(Dispatchers.IO) {
val parserFactory = DefaultSubtitleParserFactory()
val create = parserFactory.create(
Format.Builder()
.setSampleMimeType(MimeTypes.TEXT_SSA)
.build()
)
create.parse(uri.inputStream().readBytes(), SubtitleParser.OutputOptions.allCues()) {

debugLog { it.toJson() }
}
//
// val extractors = DefaultExtractorsFactory()
// .setSubtitleParserFactory(parserFactory)
// .createExtractors(uri, emptyMap())
// extractors.first()
// val mp4Extractor = Mp4Extractor(parserFactory)
// mp4Extractor.init(ExtractorOutput.PLACEHOLDER)
// mp4Extractor.read(DefaultExtractorInput(DataReader), PositionHolder())
// mp4Extractor.getSeekPoints()
// debugLog { "Extractors: ${extractors.size}" }
}
}
}

fun loadSubtitleFile(uri: Uri) {
launchUI(error = {
it.printStackTrace()

showToastCompat(it.errorMsg)
}) {
/* withContext(Dispatchers.IO) {
val fileName = uri.parseFileName(context.contentResolver)
debugLog { "文件名:$fileName" }
when {
fileName.endsWith(".ass", true) -> {
val parser = ASSParser()
val subtitle = uri.inputStream().use { parser.parse(it, fileName) }
debugLog { subtitle.toString() }
FileIOUtils.writeFileFromString(
PathUtils.getExternalAppFilesPath() + "/subtitle.ass",
subtitle.toString()
)
}
fileName.endsWith(".srt", true) -> {
val parser = SRTParser()
val subtitle = uri.inputStream().use { parser.parse(it, fileName) }
debugLog { subtitle.toString() }
}
else -> throw IllegalArgumentException("请选择 .ass 或 .srt 字幕文件")
}
}*/
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class HomeFragment : BaseViewModelFragment<FragmentHomeBinding, HomeViewModel>()
FeatureType.TYPE_DETECT_ANIME -> RouteHelper.jumpDetectAnime()
FeatureType.TYPE_DETECT_CHARACTER -> RouteHelper.jumpDetectCharacter()
FeatureType.TYPE_MAGNET -> RouteHelper.jumpAnimeMagnet()
FeatureType.TYPE_SUBTITLE->RouteHelper.jumpSubtitleTool()
FeatureType.TYPE_DOLLARS -> RouteHelper.jumpDollars()
FeatureType.TYPE_WIKI -> {
toast("暂未开放")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class HomeViewModel : BaseViewModel() {
title = "搜资源",
icon = CommonDrawable.ic_manage_search
),
HomeIndexFeature(
id = FeatureType.TYPE_SUBTITLE,
title = "字幕工具",
icon = CommonDrawable.ic_subtitles
),
HomeIndexFeature(
id = FeatureType.TYPE_DOLLARS,
title = "Dollars",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FriendRankDetailActivity : BaseListActivity<FriendlyRankEntity, FriendRank


override fun onListDataFinish(list: List<FriendlyRankEntity>) {
if (list.isEmpty()) {
if (list.isEmpty() && viewModel.overScoreCount == 1) {
showConfirmDialog(
title = "温馨提示",
message = "本地暂无好友评分数据,是否去拉取重新生成排行榜?",
Expand All @@ -65,7 +65,7 @@ class FriendRankDetailActivity : BaseListActivity<FriendlyRankEntity, FriendRank
showOptionsDialog(
title = "超过 n 位好友评分才看",
items = mutableListOf<String>().apply {
repeat(10) {
repeat(50) {
add(String.format("仅看 %d+ 人评分条目", it + 1))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.xiaoyv.bangumi.ui.feature.friendly.rank
import com.xiaoyv.bangumi.base.BaseListViewModel
import com.xiaoyv.common.database.BgmDatabaseManager
import com.xiaoyv.common.database.friendly.FriendlyRankEntity
import kotlinx.coroutines.delay
import kotlin.random.Random

class FriendRankDetailViewModel : BaseListViewModel<FriendlyRankEntity>() {
/**
Expand All @@ -16,9 +18,10 @@ class FriendRankDetailViewModel : BaseListViewModel<FriendlyRankEntity>() {
internal var overScoreCount = 1

override val emptyCheck: Boolean
get() = false
get() = overScoreCount != 1

override suspend fun onRequestListImpl(): List<FriendlyRankEntity> {
delay(Random.nextLong(300, 500))
return BgmDatabaseManager.friendlyRank.getFriendRank(
scoreCount = overScoreCount,
offset = (current - 1) * pageSize,
Expand Down
40 changes: 40 additions & 0 deletions app/src/main/res/layout/activity_subtitle_tool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<com.xiaoyv.common.widget.appbar.AnimeAppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:theme="@style/Theme.Bangumi.AppBarOverlay">

<com.xiaoyv.common.widget.appbar.AnimeToolbar
android:id="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/Theme.Bangumi.PopupOverlay"
app:title="字幕工具" />

</com.xiaoyv.common.widget.appbar.AnimeAppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<com.xiaoyv.common.widget.button.AnimeButton
android:id="@+id/btn_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/ui_layout_margin"
android:layout_marginTop="@dimen/ui_layout_margin"
android:paddingVertical="@dimen/ui_size_12"
android:text="一键翻译字幕文件"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ plugins {
alias(libs.plugins.jetbrainsKotlinJvm) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.googleKsp) apply false

id("com.google.gms.google-services") version "4.4.0" apply false
alias(libs.plugins.googleServices) apply false
}

buildscript {
Expand Down
16 changes: 12 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[versions]
agp = "8.3.0"
agp = "8.3.2"
blueprint = "1.1.50"
coreSplashscreen = "1.0.1"
firebaseCrashlyticsGradle = "2.9.9"
fragmentKtx = "1.6.2"
googleFirebaseBom = "32.8.0"
googleFirebaseBom = "32.8.1"
gson = "2.10.1"
jiebaAnalysis = "1.0.2"
jsoup = "1.17.2"
kotlin = "1.9.10"
juniversalchardet = "1.0.3"
exifinterface = "1.3.7"
kotlin = "1.9.23"
google-services="4.4.1"
coreKtx = "1.12.0"
junit = "4.13.2"
junitVersion = "1.1.5"
Expand All @@ -25,9 +28,10 @@ speedDial = "3.3.0"
sqliteJdbc = "3.44.1.0"
subsamplingScaleImageViewAndroidx = "3.10.0"
swiperefreshlayout = "1.1.0"
ksp = "1.9.10-1.0.13"
ksp = "1.9.23-1.0.19"
lifecycleLivedataKtx = "2.7.0"
lifecycleViewmodelKtx = "2.7.0"
threetenabp = "1.4.7"
workRuntimeKtx = "2.9.0"
vico = "2.0.0-alpha.5"
slf4j-simple = "2.0.9"
Expand All @@ -53,11 +57,13 @@ firebase-crashlytics-gradle = { module = "com.google.firebase:firebase-crashlyti
glide-ksp = { module = "com.github.bumptech.glide:ksp", version.ref = "glideVersion" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
jieba-analysis = { module = "com.huaban:jieba-analysis", version.ref = "jiebaAnalysis" }
androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version.ref = "exifinterface" }
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
juniversalchardet = { module = "com.googlecode.juniversalchardet:juniversalchardet", version.ref = "juniversalchardet" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
Expand All @@ -67,6 +73,7 @@ sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqliteJdbc" }
subsampling-scale-image-view-androidx = { module = "com.davemorrissey.labs:subsampling-scale-image-view-androidx", version.ref = "subsamplingScaleImageViewAndroidx" }
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "lifecycleLivedataKtx" }
androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
threetenabp = { module = "com.jakewharton.threetenabp:threetenabp", version.ref = "threetenabp" }
vico-core = { group = "com.patrykandpatrick.vico", name = "core", version.ref = "vico" }
vico-views = { group = "com.patrykandpatrick.vico", name = "views", version.ref = "vico" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j-core" }
Expand All @@ -78,4 +85,5 @@ androidLibrary = { id = "com.android.library", version.ref = "agp" }
jetbrainsKotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
googleKsp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
googleServices = { id = "com.google.gms.google-services", version.ref = "google-services" }

6 changes: 5 additions & 1 deletion lib-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {
}

exec {
commandLine("bash", "-c", "git rev-parse HEAD")
commandLine("git", "rev-parse", "HEAD")
isIgnoreExitValue = true
standardOutput = it
}
Expand Down Expand Up @@ -73,6 +73,7 @@ dependencies {
api(project(":lib-live2d"))
api(project(":lib-emoji"))
api(project(":lib-thunder"))
// api(project(":lib-subtitle"))

api(libs.blueprint)
api(libs.blueprint.floater)
Expand Down Expand Up @@ -111,6 +112,9 @@ dependencies {
api(libs.firebase.analytics.ktx)
api(libs.firebase.crashlytics.ktx)

api("androidx.media3:media3-extractor:1.3.1")
api("androidx.media3:media3-common:1.3.1")

compileOnly(files("../lib-live2d/libs/Live2DCubismCore.aar"))

testImplementation(libs.junit)
Expand Down
Loading

0 comments on commit eafff0d

Please sign in to comment.