Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3f3481f4f | ||
|
|
1b19513efb | ||
|
|
935de13343 | ||
|
|
01a3b0101e | ||
|
|
d6df5fbe5f | ||
|
|
929b7f72f8 | ||
|
|
e028ca40b1 | ||
|
|
d206465ee1 | ||
|
|
9117bf58b8 | ||
|
|
bd826a9236 | ||
|
|
a5dbae7fff | ||
|
|
00405d2e3b | ||
|
|
72dcb92aca | ||
|
|
8d511933df | ||
|
|
06a2f6d7c0 | ||
|
|
0d785bf1f8 | ||
|
|
4c3acb047c | ||
|
|
d3dbc9f8dc | ||
|
|
4b97f89c0b | ||
|
|
6be024f86f | ||
|
|
6512808506 | ||
|
|
2d65cd3006 | ||
|
|
391b01e9d0 | ||
|
|
d4ce3a5d8b | ||
|
|
bf47c065c9 | ||
|
|
c6b3ca9311 | ||
|
|
a3d50eb935 | ||
|
|
188811fde6 | ||
|
|
37353dac15 | ||
|
|
350d16db75 | ||
|
|
0f27daf664 | ||
|
|
afdc4af2f2 | ||
|
|
1b50a73bfc | ||
|
|
978c309cd7 | ||
|
|
c0f65042e6 | ||
|
|
a7d01e0306 | ||
|
|
ed2cf4c18c | ||
|
|
db3e153409 | ||
|
|
810ca5bf9d | ||
|
|
84b24775d6 | ||
|
|
9039b27c7f | ||
|
|
30b43878ab | ||
|
|
e7afd316f8 | ||
|
|
f3dd4a9b5c | ||
|
|
94b37ef00f | ||
|
|
bea50ab32f | ||
|
|
63296d2a92 | ||
|
|
b291044acc | ||
|
|
ee4e573f4f | ||
|
|
e8f192ccf8 | ||
|
|
c8ec481fc9 | ||
|
|
1fc8c4924e | ||
|
|
55fc2796a9 | ||
|
|
4d3d067f77 | ||
|
|
bb2c729a7e | ||
|
|
54eb5a60a8 | ||
|
|
6667330ce0 | ||
|
|
440188f261 | ||
|
|
9d2d3b97a1 | ||
|
|
23e80dd637 | ||
|
|
ab4c246675 | ||
|
|
2a32dec183 | ||
|
|
5dafc68775 | ||
|
|
80c962a95c | ||
|
|
2fef7470e0 | ||
|
|
0cb0ab0613 | ||
|
|
70d8e0f982 | ||
|
|
48b4e67d34 | ||
|
|
a3a79f7068 | ||
|
|
04f034817c | ||
|
|
516593499c | ||
|
|
df36890b48 | ||
|
|
222bacdeeb | ||
|
|
b83b5799e3 | ||
|
|
d4ae8f427f | ||
|
|
98d7debfb5 | ||
|
|
b5e9deb4bd | ||
|
|
47df002d8e | ||
|
|
4f1feeadbd | ||
|
|
8b50b5bd06 | ||
|
|
8481611372 | ||
|
|
b1e95b370c | ||
|
|
0ef0d46919 | ||
|
|
b4d38f8e10 | ||
|
|
c034627fdb | ||
|
|
ef29fc5f15 | ||
|
|
671e0ce143 | ||
|
|
0f1f64a09f | ||
|
|
d29ae20491 | ||
|
|
12e08a89a4 | ||
|
|
e0ba54f23b | ||
|
|
5043d6c25b | ||
|
|
ab6800aba2 | ||
|
|
f8500bbaca | ||
|
|
9b1afbdb36 | ||
|
|
f4cf7bc2dd | ||
|
|
60489d6dca | ||
|
|
44d3bcba18 | ||
|
|
f206977ad8 | ||
|
|
f3d64f6fb5 | ||
|
|
6318ca24ec | ||
|
|
b513ac0a9c | ||
|
|
25d90e1383 | ||
|
|
7804809d83 | ||
|
|
5f278a3510 | ||
|
|
a1c0af3f00 | ||
|
|
b5bfc1d7b2 | ||
|
|
1d2ba93e48 | ||
|
|
c08df9af40 | ||
|
|
be166f5856 | ||
|
|
e531c78997 | ||
|
|
8ed6cd9fd6 | ||
|
|
c1d55b91a2 | ||
|
|
3dcfa02372 | ||
|
|
b6826f7483 | ||
|
|
cd3d84cf9a | ||
|
|
010ce326ea | ||
|
|
2577797772 | ||
|
|
05e2952815 | ||
|
|
6ae9e8e043 | ||
|
|
182b7e3ac2 | ||
|
|
8bb365db2a | ||
|
|
0cb57d084d | ||
|
|
5c174b007c | ||
|
|
35364c949a | ||
|
|
814b2c0b7b | ||
|
|
3d0e0804ca |
No files matched your search
@@ -4,6 +4,7 @@ package com.stormg.lumadrama
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.app.PictureInPictureParams
|
import android.app.PictureInPictureParams
|
||||||
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.media.MediaMetadataRetriever
|
import android.media.MediaMetadataRetriever
|
||||||
@@ -12,6 +13,8 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
import android.util.Rational
|
import android.util.Rational
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
@@ -21,6 +24,7 @@ import io.flutter.embedding.android.FlutterActivity
|
|||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.util.Locale
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
@@ -36,6 +40,9 @@ class MainActivity : FlutterActivity() {
|
|||||||
private var imeInset = 0
|
private var imeInset = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
splashScreen.setOnExitAnimationListener { screen -> screen.remove() }
|
||||||
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
@@ -62,6 +69,23 @@ class MainActivity : FlutterActivity() {
|
|||||||
result.success(false)
|
result.success(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 设备标识:SSAID 免权限,卸载重装不变,避免客户端自己生成的 id 每次重装都变
|
||||||
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.stormg.lumadrama/device")
|
||||||
|
.setMethodCallHandler { call, result ->
|
||||||
|
when (call.method) {
|
||||||
|
"ssaid" -> {
|
||||||
|
val value = try {
|
||||||
|
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
result.success(value)
|
||||||
|
}
|
||||||
|
// 设备区域:注册时作为服务端 IP 解析失败后的兜底
|
||||||
|
"region" -> result.success(currentRegion())
|
||||||
|
else -> result.notImplemented()
|
||||||
|
}
|
||||||
|
}
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.stormg.lumadrama/share")
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.stormg.lumadrama/share")
|
||||||
.setMethodCallHandler { call, result ->
|
.setMethodCallHandler { call, result ->
|
||||||
if (call.method != "shareText") {
|
if (call.method != "shareText") {
|
||||||
@@ -153,6 +177,28 @@ class MainActivity : FlutterActivity() {
|
|||||||
?.bottom
|
?.bottom
|
||||||
?: 0
|
?: 0
|
||||||
|
|
||||||
|
/** 网络运营商国家优先,其次 SIM 卡,最后系统语言;都拿不到返回空串。 */
|
||||||
|
private fun currentRegion(): String {
|
||||||
|
return try {
|
||||||
|
val telephony = getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
|
||||||
|
val localeCountry = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
resources.configuration.locales.get(0).country
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
resources.configuration.locale.country
|
||||||
|
}
|
||||||
|
val candidates = listOfNotNull(
|
||||||
|
telephony?.networkCountryIso,
|
||||||
|
telephony?.simCountryIso,
|
||||||
|
localeCountry
|
||||||
|
)
|
||||||
|
candidates.firstOrNull { it.isNotBlank() }?.uppercase(Locale.ROOT) ?: ""
|
||||||
|
} catch (_: Exception) {
|
||||||
|
// 个别 ROM 读运营商信息会抛 SecurityException,别让注册流程卡住
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun emitImeInset(value: Int) {
|
private fun emitImeInset(value: Int) {
|
||||||
if (value == imeInset) return
|
if (value == imeInset) return
|
||||||
imeInset = value
|
imeInset = value
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 8.3 KiB |
@@ -1,4 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Author: fruit.com.cn -->
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="@color/splash_background" />
|
<item android:drawable="@color/splash_background" />
|
||||||
|
<item>
|
||||||
|
<bitmap
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@drawable/splash_screen" />
|
||||||
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 46 KiB |
@@ -1,4 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Author: fruit.com.cn -->
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="@color/splash_background" />
|
<item android:drawable="@color/splash_background" />
|
||||||
|
<item>
|
||||||
|
<bitmap
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@drawable/splash_screen" />
|
||||||
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Author: fruit.com.cn -->
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@color/splash_background" />
|
||||||
<item>
|
<item>
|
||||||
<bitmap android:gravity="fill" android:src="@drawable/background"/>
|
<bitmap
|
||||||
</item>
|
android:gravity="center"
|
||||||
<item>
|
android:src="@drawable/splash_screen" />
|
||||||
<bitmap android:gravity="center" android:src="@drawable/splash"/>
|
|
||||||
</item>
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Author: fruit.com.cn -->
|
<!-- Author: fruit.com.cn -->
|
||||||
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="@color/splash_background" />
|
<item android:drawable="@color/splash_background" />
|
||||||
|
<item>
|
||||||
|
<bitmap
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@drawable/splash_screen" />
|
||||||
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 52 KiB |
@@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Author: fruit.com.cn -->
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@color/splash_background" />
|
||||||
<item>
|
<item>
|
||||||
<bitmap android:gravity="fill" android:src="@drawable/background"/>
|
<bitmap
|
||||||
</item>
|
android:gravity="center"
|
||||||
<item>
|
android:src="@drawable/splash_screen" />
|
||||||
<bitmap android:gravity="center" android:src="@drawable/splash"/>
|
|
||||||
</item>
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
||||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
<item name="android:windowSplashScreenBackground">#000000</item>
|
<item name="android:windowSplashScreenBackground">#000000</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</item>
|
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_brand</item>
|
||||||
|
<item name="android:windowSplashScreenAnimationDuration">0</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||||
<item name="android:windowBackground">@color/splash_background</item>
|
<item name="android:windowBackground">@color/splash_background</item>
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
||||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
<item name="android:windowSplashScreenBackground">#000000</item>
|
<item name="android:windowSplashScreenBackground">#000000</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</item>
|
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_brand</item>
|
||||||
|
<item name="android:windowSplashScreenAnimationDuration">0</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||||
<item name="android:windowBackground">@color/splash_background</item>
|
<item name="android:windowBackground">@color/splash_background</item>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 24 KiB |
@@ -11,6 +11,7 @@
|
|||||||
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
|
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
|
||||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
||||||
|
8C4E1A022F9A4B1000C636F3 /* WirelessDataPrompt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4E1A012F9A4B1000C636F3 /* WirelessDataPrompt.swift */; };
|
||||||
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; };
|
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; };
|
||||||
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
|
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
|
||||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||||
@@ -49,6 +50,7 @@
|
|||||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
|
8C4E1A012F9A4B1000C636F3 /* WirelessDataPrompt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WirelessDataPrompt.swift; sourceTree = "<group>"; };
|
||||||
7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
||||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; };
|
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; };
|
||||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||||
@@ -122,6 +124,7 @@
|
|||||||
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
|
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
|
||||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
||||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
||||||
|
8C4E1A012F9A4B1000C636F3 /* WirelessDataPrompt.swift */,
|
||||||
7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */,
|
7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */,
|
||||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
||||||
);
|
);
|
||||||
@@ -282,6 +285,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
||||||
|
8C4E1A022F9A4B1000C636F3 /* WirelessDataPrompt.swift in Sources */,
|
||||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
||||||
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */,
|
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import Flutter
|
|||||||
import UIKit
|
import UIKit
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
|
||||||
|
private let thumbnailHTTPHeaderFieldsKey = "AVURLAssetHTTPHeaderFieldsKey"
|
||||||
|
|
||||||
private final class ThumbnailResponseGate {
|
private final class ThumbnailResponseGate {
|
||||||
private let lock = NSLock()
|
private let lock = NSLock()
|
||||||
private var completed = false
|
private var completed = false
|
||||||
@@ -29,12 +31,13 @@ final class RunnerFlutterViewController: FlutterViewController {
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.backgroundColor = UIColor(red: 16.0 / 255.0, green: 12.0 / 255.0, blue: 10.0 / 255.0, alpha: 1)
|
view.backgroundColor = .black
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@main
|
@main
|
||||||
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
||||||
|
private let wirelessDataPrompt = WirelessDataPrompt()
|
||||||
private let thumbnailQueue = DispatchQueue(
|
private let thumbnailQueue = DispatchQueue(
|
||||||
label: "com.stormg.lumadrama.thumbnail",
|
label: "com.stormg.lumadrama.thumbnail",
|
||||||
qos: .userInitiated
|
qos: .userInitiated
|
||||||
@@ -48,8 +51,19 @@ final class RunnerFlutterViewController: FlutterViewController {
|
|||||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func applicationDidBecomeActive(_ application: UIApplication) {
|
||||||
|
super.applicationDidBecomeActive(application)
|
||||||
|
requestWirelessDataPrompt()
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestWirelessDataPrompt() {
|
||||||
|
wirelessDataPrompt.requestSystemPrompt()
|
||||||
|
}
|
||||||
|
|
||||||
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||||
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
||||||
|
registerWirelessDataChannel(engineBridge)
|
||||||
|
registerDeviceIdChannel(engineBridge)
|
||||||
let channel = FlutterMethodChannel(
|
let channel = FlutterMethodChannel(
|
||||||
name: "com.stormg.lumadrama/share",
|
name: "com.stormg.lumadrama/share",
|
||||||
binaryMessenger: engineBridge.applicationRegistrar.messenger()
|
binaryMessenger: engineBridge.applicationRegistrar.messenger()
|
||||||
@@ -104,7 +118,7 @@ final class RunnerFlutterViewController: FlutterViewController {
|
|||||||
|
|
||||||
let options: [String: Any]? = headers.isEmpty
|
let options: [String: Any]? = headers.isEmpty
|
||||||
? nil
|
? nil
|
||||||
: [AVURLAssetHTTPHeaderFieldsKey: headers]
|
: [thumbnailHTTPHeaderFieldsKey: headers]
|
||||||
let asset = AVURLAsset(url: assetUrl, options: options)
|
let asset = AVURLAsset(url: assetUrl, options: options)
|
||||||
let generator = AVAssetImageGenerator(asset: asset)
|
let generator = AVAssetImageGenerator(asset: asset)
|
||||||
generator.appliesPreferredTrackTransform = true
|
generator.appliesPreferredTrackTransform = true
|
||||||
@@ -130,4 +144,45 @@ final class RunnerFlutterViewController: FlutterViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 设备标识:IDFV 免权限,卸载本 App 不变,避免客户端自生成的 id 每次重装都变。
|
||||||
|
/// 同通道顺带提供设备区域(ISO-2),注册时作为服务端 IP 解析失败后的兜底。
|
||||||
|
private func registerDeviceIdChannel(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||||
|
let channel = FlutterMethodChannel(
|
||||||
|
name: "com.stormg.lumadrama/device",
|
||||||
|
binaryMessenger: engineBridge.applicationRegistrar.messenger()
|
||||||
|
)
|
||||||
|
channel.setMethodCallHandler { call, result in
|
||||||
|
switch call.method {
|
||||||
|
case "idfv":
|
||||||
|
result(UIDevice.current.identifierForVendor?.uuidString)
|
||||||
|
case "region":
|
||||||
|
if #available(iOS 16.0, *) {
|
||||||
|
result(Locale.current.region?.identifier)
|
||||||
|
} else {
|
||||||
|
result(Locale.current.regionCode)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func registerWirelessDataChannel(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||||
|
let channel = FlutterMethodChannel(
|
||||||
|
name: WirelessDataPrompt.channelName,
|
||||||
|
binaryMessenger: engineBridge.applicationRegistrar.messenger()
|
||||||
|
)
|
||||||
|
channel.setMethodCallHandler { [weak self] call, result in
|
||||||
|
guard call.method == WirelessDataPrompt.awaitDecisionMethod else {
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard let self else {
|
||||||
|
result(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.wirelessDataPrompt.awaitDecision(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 24 KiB |
@@ -16,18 +16,13 @@
|
|||||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" image="LaunchBackground" translatesAutoresizingMaskIntoConstraints="NO" id="tWc-Dq-wcI"/>
|
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4"/>
|
||||||
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4"></imageView>
|
|
||||||
</subviews>
|
</subviews>
|
||||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
<color key="backgroundColor" red="0" green="0" blue="0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstItem="YRO-k0-Ey4" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="3T2-ad-Qdv"/>
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="3T2-ad-Qdv"/>
|
||||||
<constraint firstItem="tWc-Dq-wcI" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="RPx-PI-7Xg"/>
|
|
||||||
<constraint firstItem="tWc-Dq-wcI" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="SdS-ul-q2q"/>
|
|
||||||
<constraint firstAttribute="trailing" secondItem="tWc-Dq-wcI" secondAttribute="trailing" id="Swv-Gf-Rwn"/>
|
|
||||||
<constraint firstAttribute="trailing" secondItem="YRO-k0-Ey4" secondAttribute="trailing" id="TQA-XW-tRk"/>
|
<constraint firstAttribute="trailing" secondItem="YRO-k0-Ey4" secondAttribute="trailing" id="TQA-XW-tRk"/>
|
||||||
<constraint firstItem="YRO-k0-Ey4" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="duK-uY-Gun"/>
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="duK-uY-Gun"/>
|
||||||
<constraint firstItem="tWc-Dq-wcI" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="kV7-tw-vXt"/>
|
|
||||||
<constraint firstItem="YRO-k0-Ey4" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="xPn-NY-SIU"/>
|
<constraint firstItem="YRO-k0-Ey4" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="xPn-NY-SIU"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</view>
|
</view>
|
||||||
@@ -38,7 +33,6 @@
|
|||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
<resources>
|
<resources>
|
||||||
<image name="LaunchImage" width="1400" height="1400"/>
|
<image name="LaunchImage" width="390" height="844"/>
|
||||||
<image name="LaunchBackground" width="1" height="1"/>
|
|
||||||
</resources>
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
<key>NSIncludesSubdomains</key>
|
<key>NSIncludesSubdomains</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
<key>192.168.31.187</key>
|
<key>192.168.31.243</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
import Flutter
|
import Flutter
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class SceneDelegate: FlutterSceneDelegate {
|
class SceneDelegate: FlutterSceneDelegate {
|
||||||
|
override func sceneDidBecomeActive(_ scene: UIScene) {
|
||||||
|
super.sceneDidBecomeActive(scene)
|
||||||
|
(UIApplication.shared.delegate as? AppDelegate)?.requestWirelessDataPrompt()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import CoreTelephony
|
||||||
|
import Flutter
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// 监听系统无线数据选择,并用 URLSession 唤起系统选择框。
|
||||||
|
final class WirelessDataPrompt {
|
||||||
|
static let channelName = "com.stormg.lumadrama/wireless-data"
|
||||||
|
static let awaitDecisionMethod = "awaitDecision"
|
||||||
|
|
||||||
|
/// 系统选择框由 URLSession 触发,Dart 的 Socket 请求不会弹出。
|
||||||
|
private static let promptURL = URL(string: "https://captive.apple.com/hotspot-detect.html")
|
||||||
|
|
||||||
|
private let cellularData = CTCellularData()
|
||||||
|
private let lock = NSLock()
|
||||||
|
private var pending: [FlutterResult] = []
|
||||||
|
private var decided = false
|
||||||
|
private var didRequestPrompt = false
|
||||||
|
|
||||||
|
init() {
|
||||||
|
cellularData.cellularDataRestrictionDidUpdateNotifier = { [weak self] state in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.completeIfDecided(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 应用进入前台后请求一次,促使系统弹出无线数据选择。
|
||||||
|
func requestSystemPrompt() {
|
||||||
|
guard !didRequestPrompt, let promptURL = Self.promptURL else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
didRequestPrompt = true
|
||||||
|
_ = cellularData.restrictedState
|
||||||
|
URLSession.shared.dataTask(with: promptURL) { _, _, _ in }.resume()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 未允许前先挂起;用户允许无线数据后再放行。
|
||||||
|
func awaitDecision(_ result: @escaping FlutterResult) {
|
||||||
|
lock.lock()
|
||||||
|
if decided {
|
||||||
|
lock.unlock()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(nil)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pending.append(result)
|
||||||
|
lock.unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func completeIfDecided(_ state: CTCellularDataRestrictedState) {
|
||||||
|
if state != .notRestricted {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lock.lock()
|
||||||
|
if decided {
|
||||||
|
lock.unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
decided = true
|
||||||
|
let waiters = pending
|
||||||
|
pending.removeAll()
|
||||||
|
lock.unlock()
|
||||||
|
waiters.forEach { $0(nil) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import 'core/data/remote/catalog_api.dart';
|
|||||||
import 'core/data/remote/category_api.dart';
|
import 'core/data/remote/category_api.dart';
|
||||||
import 'core/data/remote/comment_api.dart';
|
import 'core/data/remote/comment_api.dart';
|
||||||
import 'core/data/remote/commerce_api.dart';
|
import 'core/data/remote/commerce_api.dart';
|
||||||
|
import 'core/data/remote/device_profile.dart';
|
||||||
import 'core/data/remote/download_api.dart';
|
import 'core/data/remote/download_api.dart';
|
||||||
import 'core/data/remote/interaction_api.dart';
|
import 'core/data/remote/interaction_api.dart';
|
||||||
import 'core/data/remote/library_api.dart';
|
import 'core/data/remote/library_api.dart';
|
||||||
@@ -30,6 +31,7 @@ import 'core/data/repositories/favorite_repository.dart';
|
|||||||
import 'core/data/repositories/interaction_repository.dart';
|
import 'core/data/repositories/interaction_repository.dart';
|
||||||
import 'core/data/repositories/notice_repository.dart';
|
import 'core/data/repositories/notice_repository.dart';
|
||||||
import 'core/data/repositories/playback_repository.dart';
|
import 'core/data/repositories/playback_repository.dart';
|
||||||
|
import 'core/data/repositories/playlist_repository.dart';
|
||||||
import 'core/data/repositories/search_repository.dart';
|
import 'core/data/repositories/search_repository.dart';
|
||||||
import 'core/data/repositories/store_repository.dart';
|
import 'core/data/repositories/store_repository.dart';
|
||||||
import 'core/data/repositories/watch_history_repository.dart';
|
import 'core/data/repositories/watch_history_repository.dart';
|
||||||
@@ -41,6 +43,7 @@ import 'core/data/services/download_controller.dart';
|
|||||||
import 'core/data/services/favorite_controller.dart';
|
import 'core/data/services/favorite_controller.dart';
|
||||||
import 'core/data/services/interaction_controller.dart';
|
import 'core/data/services/interaction_controller.dart';
|
||||||
import 'core/data/services/locale_controller.dart';
|
import 'core/data/services/locale_controller.dart';
|
||||||
|
import 'core/data/services/playlist_controller.dart';
|
||||||
import 'core/data/services/event_tracker.dart';
|
import 'core/data/services/event_tracker.dart';
|
||||||
import 'core/data/services/playback_position_cache.dart';
|
import 'core/data/services/playback_position_cache.dart';
|
||||||
import 'core/data/services/playback_session.dart';
|
import 'core/data/services/playback_session.dart';
|
||||||
@@ -83,6 +86,7 @@ class LumaDramaApp extends StatefulWidget {
|
|||||||
this.commerceRepository,
|
this.commerceRepository,
|
||||||
this.storeRepository,
|
this.storeRepository,
|
||||||
this.searchRepository,
|
this.searchRepository,
|
||||||
|
this.playlistRepository,
|
||||||
this.haptics = const FlutterHaptics(),
|
this.haptics = const FlutterHaptics(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,6 +107,7 @@ class LumaDramaApp extends StatefulWidget {
|
|||||||
final CommerceRepository? commerceRepository;
|
final CommerceRepository? commerceRepository;
|
||||||
final StoreRepository? storeRepository;
|
final StoreRepository? storeRepository;
|
||||||
final SearchRepository? searchRepository;
|
final SearchRepository? searchRepository;
|
||||||
|
final PlaylistRepository? playlistRepository;
|
||||||
final Haptics haptics;
|
final Haptics haptics;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -113,12 +118,13 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
late final AuthSessionStore _sessionStore = AuthSessionStore();
|
late final AuthSessionStore _sessionStore = AuthSessionStore();
|
||||||
|
|
||||||
/// 全 App 共用一个 ApiClient:这样目录、账号、后续的互动/进度请求
|
/// 全 App 共用一个 ApiClient:这样目录、账号、后续的互动/进度请求
|
||||||
/// 都自动带 `Authorization` 与 `X-Device-Id`,401 的刷新重试也只有一处实现。
|
/// 都自动带 `Authorization`、`X-Device-Id` 与平台头,401 的刷新重试也只有一处实现。
|
||||||
late final ApiClient _apiClient = ApiClient(
|
late final ApiClient _apiClient = ApiClient(
|
||||||
accessTokenReader: () => _auth.accessToken,
|
accessTokenReader: () => _auth.accessToken,
|
||||||
tokenRefresher: () => _auth.refresh(),
|
tokenRefresher: () => _auth.refresh(),
|
||||||
onUnauthorized: () => _auth.clear(),
|
onUnauthorized: () => _auth.clear(),
|
||||||
deviceIdReader: _sessionStore.deviceId,
|
deviceIdReader: _sessionStore.deviceId,
|
||||||
|
platformReader: clientPlatform,
|
||||||
);
|
);
|
||||||
|
|
||||||
late final AuthController _auth = AuthController(
|
late final AuthController _auth = AuthController(
|
||||||
@@ -126,8 +132,10 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
_sessionStore,
|
_sessionStore,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
late final CatalogApi _catalogApi = CatalogApi(_apiClient);
|
||||||
|
|
||||||
late final CatalogRepository _catalogRepository =
|
late final CatalogRepository _catalogRepository =
|
||||||
widget.catalogRepository ?? HttpCatalogRepository(CatalogApi(_apiClient));
|
widget.catalogRepository ?? HttpCatalogRepository(_catalogApi);
|
||||||
|
|
||||||
late final CategoryRepository _categoryRepository =
|
late final CategoryRepository _categoryRepository =
|
||||||
widget.categoryRepository ??
|
widget.categoryRepository ??
|
||||||
@@ -135,17 +143,11 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
|
|
||||||
late final WatchHistoryRepository _watchHistory =
|
late final WatchHistoryRepository _watchHistory =
|
||||||
widget.watchHistoryRepository ??
|
widget.watchHistoryRepository ??
|
||||||
HttpWatchHistoryRepository(
|
HttpWatchHistoryRepository(WatchApi(_apiClient));
|
||||||
WatchApi(_apiClient),
|
|
||||||
isSignedIn: () => _auth.isSignedIn,
|
|
||||||
);
|
|
||||||
|
|
||||||
late final FavoriteRepository _favorites =
|
late final FavoriteRepository _favorites =
|
||||||
widget.favoriteRepository ??
|
widget.favoriteRepository ??
|
||||||
HttpFavoriteRepository(
|
HttpFavoriteRepository(LibraryApi(_apiClient));
|
||||||
LibraryApi(_apiClient),
|
|
||||||
isSignedIn: () => _auth.isSignedIn,
|
|
||||||
);
|
|
||||||
|
|
||||||
late final PlaybackRepository _playback =
|
late final PlaybackRepository _playback =
|
||||||
widget.playbackRepository ??
|
widget.playbackRepository ??
|
||||||
@@ -177,6 +179,13 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
late final SearchRepository _searchRepository =
|
late final SearchRepository _searchRepository =
|
||||||
widget.searchRepository ?? HttpSearchRepository(CatalogApi(_apiClient));
|
widget.searchRepository ?? HttpSearchRepository(CatalogApi(_apiClient));
|
||||||
|
|
||||||
|
/// 测试注入了目录仓库时不打剧单接口,剧单页继续用本地分区。
|
||||||
|
late final PlaylistRepository? _playlistRepository =
|
||||||
|
widget.playlistRepository ??
|
||||||
|
(widget.catalogRepository == null
|
||||||
|
? HttpPlaylistRepository(CatalogApi(_apiClient))
|
||||||
|
: null);
|
||||||
|
|
||||||
late final StoreRepository _storeRepository =
|
late final StoreRepository _storeRepository =
|
||||||
widget.storeRepository ?? HttpStoreRepository(CommerceApi(_apiClient));
|
widget.storeRepository ?? HttpStoreRepository(CommerceApi(_apiClient));
|
||||||
|
|
||||||
@@ -206,7 +215,7 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
unawaited(_localeController.load());
|
unawaited(_localeController.load());
|
||||||
// 登录/登出时同步收藏状态:收藏属于账号,不能跨账号串联
|
// 登录/登出时同步收藏状态:收藏属于账号,不能跨账号串联
|
||||||
_auth.addListener(_onAuthChanged);
|
_auth.addListener(_onAuthChanged);
|
||||||
if (_auth.isSignedIn) unawaited(_favoriteController.load());
|
unawaited(_favoriteController.load());
|
||||||
if (_auth.isSignedIn) unawaited(_walletController.load());
|
if (_auth.isSignedIn) unawaited(_walletController.load());
|
||||||
unawaited(_downloadController.restore());
|
unawaited(_downloadController.restore());
|
||||||
}
|
}
|
||||||
@@ -222,6 +231,7 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
unawaited(_walletController.load());
|
unawaited(_walletController.load());
|
||||||
} else {
|
} else {
|
||||||
_favoriteController.clear();
|
_favoriteController.clear();
|
||||||
|
unawaited(_favoriteController.load());
|
||||||
_downloadController.reset();
|
_downloadController.reset();
|
||||||
_walletController.reset();
|
_walletController.reset();
|
||||||
}
|
}
|
||||||
@@ -239,14 +249,26 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CategoryController _createCategories() {
|
||||||
|
final controller = CategoryController(_categoryRepository);
|
||||||
|
if (widget.catalogRepository == null) {
|
||||||
|
controller.dramaPageLoader = CategoryApi(_apiClient).dramas;
|
||||||
|
}
|
||||||
|
controller.load();
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final playlists = _playlistRepository;
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
Provider(create: (_) => PlaybackCoordinator()),
|
Provider(create: (_) => PlaybackCoordinator()),
|
||||||
Provider<EventTracker>(create: (_) => EventTracker(_apiClient)),
|
Provider<EventTracker>(create: (_) => EventTracker(_apiClient)),
|
||||||
Provider<PlayerFactory>(create: (_) => widget.playerFactory),
|
Provider<PlayerFactory>(create: (_) => widget.playerFactory),
|
||||||
Provider<CatalogRepository>.value(value: _catalogRepository),
|
Provider<CatalogRepository>.value(value: _catalogRepository),
|
||||||
|
if (widget.catalogRepository == null)
|
||||||
|
Provider<CatalogApi>.value(value: _catalogApi),
|
||||||
Provider<PlaybackRepository>.value(value: _playback),
|
Provider<PlaybackRepository>.value(value: _playback),
|
||||||
Provider<PlaybackPositionCache>.value(value: _playbackPositionCache),
|
Provider<PlaybackPositionCache>.value(value: _playbackPositionCache),
|
||||||
Provider<WatchHistoryRepository>.value(value: _watchHistory),
|
Provider<WatchHistoryRepository>.value(value: _watchHistory),
|
||||||
@@ -260,11 +282,15 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
Provider<SearchRepository>.value(value: _searchRepository),
|
Provider<SearchRepository>.value(value: _searchRepository),
|
||||||
Provider<Haptics>.value(value: widget.haptics),
|
Provider<Haptics>.value(value: widget.haptics),
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => CatalogController(_catalogRepository)..load(),
|
create: (_) {
|
||||||
),
|
final catalog = CatalogController(_catalogRepository);
|
||||||
ChangeNotifierProvider(
|
if (widget.catalogRepository != null) catalog.load();
|
||||||
create: (_) => CategoryController(_categoryRepository)..load(),
|
return catalog;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
ChangeNotifierProvider(create: (_) => _createCategories()),
|
||||||
|
if (playlists != null)
|
||||||
|
ChangeNotifierProvider(create: (_) => PlaylistController(playlists)),
|
||||||
ChangeNotifierProvider.value(value: _favoriteController),
|
ChangeNotifierProvider.value(value: _favoriteController),
|
||||||
ChangeNotifierProvider.value(value: _downloadController),
|
ChangeNotifierProvider.value(value: _downloadController),
|
||||||
ChangeNotifierProvider.value(value: _walletController),
|
ChangeNotifierProvider.value(value: _walletController),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class AppConfig {
|
|||||||
/// 开发调试默认服务地址,当前指向本机局域网 IP。
|
/// 开发调试默认服务地址,当前指向本机局域网 IP。
|
||||||
///
|
///
|
||||||
/// 换网络时只改这一行,地址不要带结尾斜杠。
|
/// 换网络时只改这一行,地址不要带结尾斜杠。
|
||||||
static const String devHostBaseUrl = 'http://192.168.31.187:8081';
|
static const String devHostBaseUrl = 'http://192.168.31.243:8081';
|
||||||
|
|
||||||
/// 本机后端地址:通过 `adb reverse tcp:8081 tcp:8081` 映射到开发机,
|
/// 本机后端地址:通过 `adb reverse tcp:8081 tcp:8081` 映射到开发机,
|
||||||
/// 探测可达时 App 直连本机服务;不可达时回落到公网地址。
|
/// 探测可达时 App 直连本机服务;不可达时回落到公网地址。
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'locale_text.dart';
|
||||||
|
|
||||||
/// 服务端内容分类。id 按契约保持字符串,避免雪花 ID 精度丢失。
|
/// 服务端内容分类。id 按契约保持字符串,避免雪花 ID 精度丢失。
|
||||||
class ContentCategory {
|
class ContentCategory {
|
||||||
const ContentCategory({required this.id, required this.name});
|
const ContentCategory({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
this.locales = const {},
|
||||||
|
});
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
/// 中文名称,与 locales 里的 zh 相同。
|
||||||
final String name;
|
final String name;
|
||||||
|
final Map<String, String> locales;
|
||||||
|
|
||||||
/// 解析 `GET /app/categories` 的单项。
|
/// 解析 `GET /app/categories` 的单项。
|
||||||
factory ContentCategory.fromJson(Map<String, dynamic> json) {
|
factory ContentCategory.fromJson(Map<String, dynamic> json) {
|
||||||
return ContentCategory(
|
final locales = localeMap(json['locales']);
|
||||||
id: (json['id'] ?? '').toString(),
|
final name = json['name'] as String? ?? locales['zh'] ?? '';
|
||||||
name: json['name'] as String? ?? '',
|
return ContentCategory(id: (json['id'] ?? '').toString(), name: name, locales: locales);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
/// 按界面语言取名称。缺对应语言时回落到中文。
|
||||||
|
String localizedName(String languageCode) {
|
||||||
|
return localizedText(languageCode, name, locales);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'json_numbers.dart';
|
import 'json_numbers.dart';
|
||||||
|
import 'locale_text.dart';
|
||||||
|
|
||||||
/// 短剧与剧集,字段与后端 `/app/**` 的下发结构对应。
|
/// 短剧与剧集,字段与后端 `/app/**` 的下发结构对应。
|
||||||
///
|
///
|
||||||
@@ -18,6 +21,7 @@ class Episode {
|
|||||||
this.likeCount,
|
this.likeCount,
|
||||||
this.commentCount,
|
this.commentCount,
|
||||||
this.thumbnailsUrl,
|
this.thumbnailsUrl,
|
||||||
|
this.posterUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
@@ -34,12 +38,14 @@ class Episode {
|
|||||||
final int? likeCount;
|
final int? likeCount;
|
||||||
final int? commentCount;
|
final int? commentCount;
|
||||||
final String? thumbnailsUrl;
|
final String? thumbnailsUrl;
|
||||||
|
final String? posterUrl;
|
||||||
|
|
||||||
Episode withVideoUrl(
|
Episode withVideoUrl(
|
||||||
String url, {
|
String url, {
|
||||||
int? likeCount,
|
int? likeCount,
|
||||||
int? commentCount,
|
int? commentCount,
|
||||||
String? thumbnailsUrl,
|
String? thumbnailsUrl,
|
||||||
|
String? posterUrl,
|
||||||
}) => Episode(
|
}) => Episode(
|
||||||
id: id,
|
id: id,
|
||||||
number: number,
|
number: number,
|
||||||
@@ -51,6 +57,21 @@ class Episode {
|
|||||||
likeCount: likeCount ?? this.likeCount,
|
likeCount: likeCount ?? this.likeCount,
|
||||||
commentCount: commentCount ?? this.commentCount,
|
commentCount: commentCount ?? this.commentCount,
|
||||||
thumbnailsUrl: thumbnailsUrl ?? this.thumbnailsUrl,
|
thumbnailsUrl: thumbnailsUrl ?? this.thumbnailsUrl,
|
||||||
|
posterUrl: posterUrl ?? this.posterUrl,
|
||||||
|
);
|
||||||
|
|
||||||
|
Episode withStats({int? likeCount, int? commentCount}) => Episode(
|
||||||
|
id: id,
|
||||||
|
number: number,
|
||||||
|
title: title,
|
||||||
|
isFree: isFree,
|
||||||
|
videoUrl: videoUrl,
|
||||||
|
durationSec: durationSec,
|
||||||
|
locked: locked,
|
||||||
|
likeCount: likeCount ?? this.likeCount,
|
||||||
|
commentCount: commentCount ?? this.commentCount,
|
||||||
|
thumbnailsUrl: thumbnailsUrl,
|
||||||
|
posterUrl: posterUrl,
|
||||||
);
|
);
|
||||||
|
|
||||||
factory Episode.fromJson(Map<String, dynamic> json) {
|
factory Episode.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -65,6 +86,7 @@ class Episode {
|
|||||||
likeCount: _optionalInt(json['likeCount']),
|
likeCount: _optionalInt(json['likeCount']),
|
||||||
commentCount: _optionalInt(json['commentCount']),
|
commentCount: _optionalInt(json['commentCount']),
|
||||||
thumbnailsUrl: _optionalString(json['thumbnailsUrl']),
|
thumbnailsUrl: _optionalString(json['thumbnailsUrl']),
|
||||||
|
posterUrl: _optionalString(json['posterUrl']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +98,14 @@ class Drama {
|
|||||||
required this.synopsis,
|
required this.synopsis,
|
||||||
required this.posterUrl,
|
required this.posterUrl,
|
||||||
this.episodes = const [],
|
this.episodes = const [],
|
||||||
|
this.titleLocales = const {},
|
||||||
|
this.synopsisLocales = const {},
|
||||||
|
this.tag = '',
|
||||||
|
this.tagLocales = const {},
|
||||||
|
this.tagColor = '',
|
||||||
this.category = '',
|
this.category = '',
|
||||||
|
this.categoryLocales = const {},
|
||||||
|
this.types = const [],
|
||||||
this.genre = '',
|
this.genre = '',
|
||||||
this.totalEpisodes = 0,
|
this.totalEpisodes = 0,
|
||||||
this.freeEpisodes = 0,
|
this.freeEpisodes = 0,
|
||||||
@@ -94,9 +123,16 @@ class Drama {
|
|||||||
final String id;
|
final String id;
|
||||||
final String title;
|
final String title;
|
||||||
final String synopsis;
|
final String synopsis;
|
||||||
|
final Map<String, String> titleLocales;
|
||||||
|
final Map<String, String> synopsisLocales;
|
||||||
|
final String tag;
|
||||||
|
final Map<String, String> tagLocales;
|
||||||
|
final String tagColor;
|
||||||
final String posterUrl;
|
final String posterUrl;
|
||||||
final List<Episode> episodes;
|
final List<Episode> episodes;
|
||||||
final String category;
|
final String category;
|
||||||
|
final Map<String, String> categoryLocales;
|
||||||
|
final List<Map<String, String>> types;
|
||||||
final String genre;
|
final String genre;
|
||||||
final int totalEpisodes;
|
final int totalEpisodes;
|
||||||
final int freeEpisodes;
|
final int freeEpisodes;
|
||||||
@@ -127,19 +163,26 @@ class Drama {
|
|||||||
/// 列表卡片:带一集可播预览(首页直接起播),完整剧集进详情再取。
|
/// 列表卡片:带一集可播预览(首页直接起播),完整剧集进详情再取。
|
||||||
factory Drama.fromCardJson(Map<String, dynamic> json) {
|
factory Drama.fromCardJson(Map<String, dynamic> json) {
|
||||||
final preview = json['preview'];
|
final preview = json['preview'];
|
||||||
|
final text = _DramaText.fromJson(json);
|
||||||
return Drama(
|
return Drama(
|
||||||
id: (json['id'] ?? '').toString(),
|
id: (json['id'] ?? '').toString(),
|
||||||
title: json['title'] as String? ?? '',
|
title: text.title,
|
||||||
synopsis: json['synopsis'] as String? ?? '',
|
synopsis: text.synopsis,
|
||||||
|
titleLocales: text.titleLocales,
|
||||||
|
synopsisLocales: text.synopsisLocales,
|
||||||
|
tag: text.tag,
|
||||||
|
tagLocales: text.tagLocales,
|
||||||
|
tagColor: json['tagColor'] as String? ?? '',
|
||||||
posterUrl: json['cover'] as String? ?? '',
|
posterUrl: json['cover'] as String? ?? '',
|
||||||
episodes: preview is Map<String, dynamic>
|
episodes: preview is Map<String, dynamic>
|
||||||
? [Episode.fromJson(preview)]
|
? [Episode.fromJson(preview)]
|
||||||
: const [],
|
: const [],
|
||||||
category: json['category'] as String? ?? '',
|
category: text.category,
|
||||||
genre: json['genre'] as String? ?? '',
|
categoryLocales: text.categoryLocales,
|
||||||
|
types: text.types,
|
||||||
|
genre: text.genre,
|
||||||
totalEpisodes: (json['totalEpisodes'] as num?)?.toInt() ?? 0,
|
totalEpisodes: (json['totalEpisodes'] as num?)?.toInt() ?? 0,
|
||||||
isHot: json['isHot'] == true,
|
isHot: json['isHot'] == true,
|
||||||
// viewCount 后端是 Long,按字符串下发(见 json_numbers.dart)
|
|
||||||
viewCount: jsonToInt(json['viewCount']),
|
viewCount: jsonToInt(json['viewCount']),
|
||||||
likeCount: _optionalInt(json['likeCount']),
|
likeCount: _optionalInt(json['likeCount']),
|
||||||
favoriteCount: _optionalInt(json['favoriteCount']),
|
favoriteCount: _optionalInt(json['favoriteCount']),
|
||||||
@@ -152,13 +195,21 @@ class Drama {
|
|||||||
|
|
||||||
/// 详情:带剧集列表。
|
/// 详情:带剧集列表。
|
||||||
factory Drama.fromDetailJson(Map<String, dynamic> json) {
|
factory Drama.fromDetailJson(Map<String, dynamic> json) {
|
||||||
|
final text = _DramaText.fromJson(json);
|
||||||
return Drama(
|
return Drama(
|
||||||
id: (json['id'] ?? '').toString(),
|
id: (json['id'] ?? '').toString(),
|
||||||
title: json['title'] as String? ?? '',
|
title: text.title,
|
||||||
synopsis: json['synopsis'] as String? ?? '',
|
synopsis: text.synopsis,
|
||||||
|
titleLocales: text.titleLocales,
|
||||||
|
synopsisLocales: text.synopsisLocales,
|
||||||
|
tag: text.tag,
|
||||||
|
tagLocales: text.tagLocales,
|
||||||
|
tagColor: json['tagColor'] as String? ?? '',
|
||||||
posterUrl: json['cover'] as String? ?? '',
|
posterUrl: json['cover'] as String? ?? '',
|
||||||
category: json['category'] as String? ?? '',
|
category: text.category,
|
||||||
genre: json['genre'] as String? ?? '',
|
categoryLocales: text.categoryLocales,
|
||||||
|
types: text.types,
|
||||||
|
genre: text.genre,
|
||||||
totalEpisodes: (json['totalEpisodes'] as num?)?.toInt() ?? 0,
|
totalEpisodes: (json['totalEpisodes'] as num?)?.toInt() ?? 0,
|
||||||
freeEpisodes: (json['freeEpisodes'] as num?)?.toInt() ?? 0,
|
freeEpisodes: (json['freeEpisodes'] as num?)?.toInt() ?? 0,
|
||||||
isHot: json['isHot'] == true,
|
isHot: json['isHot'] == true,
|
||||||
@@ -176,6 +227,37 @@ class Drama {
|
|||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String localizedTitle(String languageCode) {
|
||||||
|
return localizedText(languageCode, title, titleLocales);
|
||||||
|
}
|
||||||
|
|
||||||
|
String localizedSynopsis(String languageCode) {
|
||||||
|
return localizedText(languageCode, synopsis, synopsisLocales);
|
||||||
|
}
|
||||||
|
|
||||||
|
String localizedTag(String languageCode) {
|
||||||
|
return localizedText(languageCode, tag, tagLocales);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 标签角标背景色。接口没给合法色值时用 fallback。
|
||||||
|
Color tagRibbonColor(Color fallback) {
|
||||||
|
final parsed = _colorFromHex(tagColor);
|
||||||
|
return parsed ?? fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按当前语言取类型名称。接口没带语言表时返回空,调用方继续用中文 genre。
|
||||||
|
List<String> localizedTypeLabels(String languageCode) {
|
||||||
|
final labels = <String>[];
|
||||||
|
for (final item in types) {
|
||||||
|
final label = localizedText(languageCode, item['zh'] ?? '', item);
|
||||||
|
if (label.isNotEmpty && !labels.contains(label)) labels.add(label);
|
||||||
|
}
|
||||||
|
if (labels.isNotEmpty) return labels;
|
||||||
|
final primary = localizedText(languageCode, '', categoryLocales);
|
||||||
|
if (primary.isNotEmpty) return [primary];
|
||||||
|
return const [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int? _optionalInt(dynamic value) => value == null ? null : jsonToInt(value);
|
int? _optionalInt(dynamic value) => value == null ? null : jsonToInt(value);
|
||||||
@@ -184,3 +266,81 @@ String? _optionalString(dynamic value) {
|
|||||||
final text = value is String ? value.trim() : '';
|
final text = value is String ? value.trim() : '';
|
||||||
return text.isEmpty ? null : text;
|
return text.isEmpty ? null : text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color? _colorFromHex(String raw) {
|
||||||
|
final text = raw.trim();
|
||||||
|
if (text.length != 7 || !text.startsWith('#')) return null;
|
||||||
|
final value = int.tryParse(text.substring(1), radix: 16);
|
||||||
|
if (value == null) return null;
|
||||||
|
return Color(0xFF000000 | value);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, String>> _typeLocales(Object? raw) {
|
||||||
|
if (raw is! List) return const [];
|
||||||
|
return raw.whereType<Map>().map(localeMap).toList(growable: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 从语言表还原中文展示字段。列表接口不再单独下发 title / synopsis / tag。
|
||||||
|
class _DramaText {
|
||||||
|
const _DramaText({
|
||||||
|
required this.title,
|
||||||
|
required this.synopsis,
|
||||||
|
required this.titleLocales,
|
||||||
|
required this.synopsisLocales,
|
||||||
|
required this.tag,
|
||||||
|
required this.tagLocales,
|
||||||
|
required this.category,
|
||||||
|
required this.categoryLocales,
|
||||||
|
required this.types,
|
||||||
|
required this.genre,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final String synopsis;
|
||||||
|
final Map<String, String> titleLocales;
|
||||||
|
final Map<String, String> synopsisLocales;
|
||||||
|
final String tag;
|
||||||
|
final Map<String, String> tagLocales;
|
||||||
|
final String category;
|
||||||
|
final Map<String, String> categoryLocales;
|
||||||
|
final List<Map<String, String>> types;
|
||||||
|
final String genre;
|
||||||
|
|
||||||
|
factory _DramaText.fromJson(Map<String, dynamic> json) {
|
||||||
|
final titleLocales = localeMap(json['titleLocales']);
|
||||||
|
final synopsisLocales = localeMap(json['synopsisLocales']);
|
||||||
|
final tagLocales = localeMap(json['tagLocales']);
|
||||||
|
final categoryLocales = localeMap(json['categoryLocales']);
|
||||||
|
final types = _typeLocales(json['types']);
|
||||||
|
final category = _firstText(categoryLocales, json['category'], types);
|
||||||
|
return _DramaText(
|
||||||
|
title: _firstText(titleLocales, json['title']),
|
||||||
|
synopsis: _firstText(synopsisLocales, json['synopsis'] ?? json['description']),
|
||||||
|
titleLocales: titleLocales,
|
||||||
|
synopsisLocales: synopsisLocales,
|
||||||
|
tag: _firstText(tagLocales, json['tag']),
|
||||||
|
tagLocales: tagLocales,
|
||||||
|
category: category,
|
||||||
|
categoryLocales: categoryLocales,
|
||||||
|
types: types,
|
||||||
|
genre: _genreText(types, json['genre']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _firstText(Map<String, String> locales, Object? fallback, [List<Map<String, String>>? types]) {
|
||||||
|
final chinese = locales['zh'] ?? '';
|
||||||
|
if (chinese.isNotEmpty) return chinese;
|
||||||
|
if (types != null && types.isNotEmpty) {
|
||||||
|
final label = types.first['zh'] ?? '';
|
||||||
|
if (label.isNotEmpty) return label;
|
||||||
|
}
|
||||||
|
return fallback is String ? fallback : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
String _genreText(List<Map<String, String>> types, Object? fallback) {
|
||||||
|
final names = types.map((item) => item['zh'] ?? '').where((value) => value.isNotEmpty);
|
||||||
|
final joined = names.join(' / ');
|
||||||
|
if (joined.isNotEmpty) return joined;
|
||||||
|
return fallback is String ? fallback : '';
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'json_numbers.dart';
|
||||||
|
|
||||||
|
/// 播放页轻量互动计数快照,不包含播放地址或票据信息。
|
||||||
|
class EpisodeStats {
|
||||||
|
const EpisodeStats({
|
||||||
|
required this.episodeId,
|
||||||
|
required this.dramaId,
|
||||||
|
required this.likeCount,
|
||||||
|
required this.commentCount,
|
||||||
|
required this.favoriteCount,
|
||||||
|
required this.liked,
|
||||||
|
required this.favorited,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String episodeId;
|
||||||
|
final String dramaId;
|
||||||
|
final int likeCount;
|
||||||
|
final int commentCount;
|
||||||
|
final int favoriteCount;
|
||||||
|
final bool liked;
|
||||||
|
final bool favorited;
|
||||||
|
|
||||||
|
EpisodeStats copyWith({
|
||||||
|
String? dramaId,
|
||||||
|
int? likeCount,
|
||||||
|
int? commentCount,
|
||||||
|
int? favoriteCount,
|
||||||
|
bool? liked,
|
||||||
|
bool? favorited,
|
||||||
|
}) {
|
||||||
|
return EpisodeStats(
|
||||||
|
episodeId: episodeId,
|
||||||
|
dramaId: dramaId ?? this.dramaId,
|
||||||
|
likeCount: likeCount ?? this.likeCount,
|
||||||
|
commentCount: commentCount ?? this.commentCount,
|
||||||
|
favoriteCount: favoriteCount ?? this.favoriteCount,
|
||||||
|
liked: liked ?? this.liked,
|
||||||
|
favorited: favorited ?? this.favorited,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
factory EpisodeStats.fromJson(Map<String, dynamic> json) {
|
||||||
|
return EpisodeStats(
|
||||||
|
episodeId: jsonToId(json['episodeId']),
|
||||||
|
dramaId: jsonToId(json['dramaId']),
|
||||||
|
likeCount: jsonToInt(json['likeCount']),
|
||||||
|
commentCount: jsonToInt(json['commentCount']),
|
||||||
|
favoriteCount: jsonToInt(json['favoriteCount']),
|
||||||
|
liked: json['liked'] == true,
|
||||||
|
favorited: json['favorited'] == true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ class FeedSection {
|
|||||||
factory FeedSection.fromJson(Map<String, dynamic> json) {
|
factory FeedSection.fromJson(Map<String, dynamic> json) {
|
||||||
return FeedSection(
|
return FeedSection(
|
||||||
code: json['code'] as String? ?? '',
|
code: json['code'] as String? ?? '',
|
||||||
title: json['title'] as String? ?? '',
|
title: _sectionTitle(json),
|
||||||
dramas: (json['dramas'] as List? ?? const [])
|
dramas: (json['dramas'] as List? ?? const [])
|
||||||
.whereType<Map<String, dynamic>>()
|
.whereType<Map<String, dynamic>>()
|
||||||
.map(Drama.fromCardJson)
|
.map(Drama.fromCardJson)
|
||||||
@@ -84,3 +84,12 @@ class FeedBanner {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _sectionTitle(Map<String, dynamic> json) {
|
||||||
|
final locales = json['titleLocales'];
|
||||||
|
if (locales is Map) {
|
||||||
|
final chinese = locales['zh']?.toString() ?? '';
|
||||||
|
if (chinese.isNotEmpty) return chinese;
|
||||||
|
}
|
||||||
|
return json['title'] as String? ?? '';
|
||||||
|
}
|
||||||
@@ -58,14 +58,16 @@ class LikeToggleResult {
|
|||||||
|
|
||||||
/// 控制器统一返回结果;失败消息可直接展示后端 `message`。
|
/// 控制器统一返回结果;失败消息可直接展示后端 `message`。
|
||||||
class OperationResult<T> {
|
class OperationResult<T> {
|
||||||
const OperationResult._(this.data, this.errorMessage);
|
const OperationResult._(this.data, this.errorMessage, this.errorCode);
|
||||||
|
|
||||||
const OperationResult.success([T? data]) : this._(data, null);
|
const OperationResult.success([T? data]) : this._(data, null, null);
|
||||||
|
|
||||||
const OperationResult.failure(this.errorMessage) : data = null;
|
const OperationResult.failure(this.errorMessage, {this.errorCode})
|
||||||
|
: data = null;
|
||||||
|
|
||||||
final T? data;
|
final T? data;
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
|
final int? errorCode;
|
||||||
|
|
||||||
bool get isSuccess => errorMessage == null;
|
bool get isSuccess => errorMessage == null;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
/// 把接口里的语言表解析成字符串映射。
|
||||||
|
Map<String, String> localeMap(Object? raw) {
|
||||||
|
if (raw is! Map) return const {};
|
||||||
|
return raw.map((key, value) => MapEntry('$key', value?.toString() ?? ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按当前语言取文案。没有对应语言时用中文,中文也没有时用 fallback。
|
||||||
|
String localizedText(String languageCode, String fallback, Map<String, String> locales) {
|
||||||
|
final selected = locales[languageCode] ?? '';
|
||||||
|
if (selected.isNotEmpty) return selected;
|
||||||
|
final chinese = locales['zh'] ?? '';
|
||||||
|
if (chinese.isNotEmpty) return chinese;
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
@@ -14,7 +14,9 @@ class PlayTicket {
|
|||||||
this.unlockCoin = 0,
|
this.unlockCoin = 0,
|
||||||
this.previewSeconds = 0,
|
this.previewSeconds = 0,
|
||||||
this.qualities = const [],
|
this.qualities = const [],
|
||||||
|
this.tracks = const [],
|
||||||
this.thumbnailsUrl,
|
this.thumbnailsUrl,
|
||||||
|
this.posterUrl,
|
||||||
this.likeCount,
|
this.likeCount,
|
||||||
this.commentCount,
|
this.commentCount,
|
||||||
});
|
});
|
||||||
@@ -39,9 +41,13 @@ class PlayTicket {
|
|||||||
/// 试看秒数:仅 `COIN_REQUIRED` 时有意义(付费解锁在 B2 做)。
|
/// 试看秒数:仅 `COIN_REQUIRED` 时有意义(付费解锁在 B2 做)。
|
||||||
final int previewSeconds;
|
final int previewSeconds;
|
||||||
|
|
||||||
/// 后端下发的清晰度档位(如 AUTO / 720P / 1080P),HLS 由播放器自动切换。
|
/// 后端下发的清晰度档位(如 AUTO / 720p / 1080p)。
|
||||||
final List<String> qualities;
|
final List<String> qualities;
|
||||||
|
|
||||||
|
/// 各档签名地址。AUTO 是主列表,点选其它档位时换成对应地址。
|
||||||
|
final List<PlayQualityTrack> tracks;
|
||||||
final String? thumbnailsUrl;
|
final String? thumbnailsUrl;
|
||||||
|
final String? posterUrl;
|
||||||
final int? likeCount;
|
final int? likeCount;
|
||||||
final int? commentCount;
|
final int? commentCount;
|
||||||
|
|
||||||
@@ -64,7 +70,9 @@ class PlayTicket {
|
|||||||
.whereType<String>()
|
.whereType<String>()
|
||||||
.where((quality) => quality.isNotEmpty)
|
.where((quality) => quality.isNotEmpty)
|
||||||
.toList(),
|
.toList(),
|
||||||
|
tracks: _tracks(json['tracks'], json['playUrl'] as String? ?? ''),
|
||||||
thumbnailsUrl: _optionalString(json['thumbnailsUrl']),
|
thumbnailsUrl: _optionalString(json['thumbnailsUrl']),
|
||||||
|
posterUrl: _optionalString(json['posterUrl']),
|
||||||
likeCount: json['likeCount'] == null
|
likeCount: json['likeCount'] == null
|
||||||
? null
|
? null
|
||||||
: jsonToInt(json['likeCount']),
|
: jsonToInt(json['likeCount']),
|
||||||
@@ -75,6 +83,67 @@ class PlayTicket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<PlayQualityTrack> _tracks(dynamic raw, String playUrl) {
|
||||||
|
final tracks = <PlayQualityTrack>[];
|
||||||
|
if (raw is List) {
|
||||||
|
for (final item in raw) {
|
||||||
|
if (item is! Map) continue;
|
||||||
|
final quality = item['quality'] as String? ?? '';
|
||||||
|
final url = item['playUrl'] as String? ?? '';
|
||||||
|
if (quality.isEmpty || url.isEmpty) continue;
|
||||||
|
tracks.add(PlayQualityTrack(quality: quality, playUrl: url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tracks.isEmpty && playUrl.isNotEmpty) {
|
||||||
|
tracks.add(PlayQualityTrack(quality: 'AUTO', playUrl: playUrl));
|
||||||
|
}
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按票据里的分轨地址取播放地址;没有分轨时,从主列表路径推出同目录的单档地址。
|
||||||
|
String? qualityPlayUrl({
|
||||||
|
required String quality,
|
||||||
|
required List<PlayQualityTrack> tracks,
|
||||||
|
required String currentUrl,
|
||||||
|
}) {
|
||||||
|
final wanted = quality.toUpperCase();
|
||||||
|
for (final track in tracks) {
|
||||||
|
if (track.quality.toUpperCase() == wanted && track.playUrl.isNotEmpty) {
|
||||||
|
return track.playUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return siblingRenditionUrl(currentUrl, wanted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `.../master.m3u8` 与 `.../720p/index.m3u8` 互相换算,查询参数原样保留。
|
||||||
|
String? siblingRenditionUrl(String currentUrl, String quality) {
|
||||||
|
final uri = Uri.tryParse(currentUrl);
|
||||||
|
if (uri == null || uri.path.isEmpty) return null;
|
||||||
|
final path = uri.path;
|
||||||
|
const masterSuffix = '/master.m3u8';
|
||||||
|
String? root;
|
||||||
|
if (path.endsWith(masterSuffix)) {
|
||||||
|
root = path.substring(0, path.length - masterSuffix.length);
|
||||||
|
} else {
|
||||||
|
final match = RegExp(r'/(\d+p)/index\.m3u8$').firstMatch(path);
|
||||||
|
if (match == null) return null;
|
||||||
|
root = path.substring(0, match.start);
|
||||||
|
}
|
||||||
|
final next = quality.toUpperCase() == 'AUTO'
|
||||||
|
? '$root$masterSuffix'
|
||||||
|
: '$root/${quality.toLowerCase()}/index.m3u8';
|
||||||
|
if (next == path) return currentUrl;
|
||||||
|
return uri.replace(path: next).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 一档清晰度的签名播放地址。
|
||||||
|
class PlayQualityTrack {
|
||||||
|
const PlayQualityTrack({required this.quality, required this.playUrl});
|
||||||
|
|
||||||
|
final String quality;
|
||||||
|
final String playUrl;
|
||||||
|
}
|
||||||
|
|
||||||
String? _optionalString(dynamic value) {
|
String? _optionalString(dynamic value) {
|
||||||
final text = value is String ? value.trim() : '';
|
final text = value is String ? value.trim() : '';
|
||||||
return text.isEmpty ? null : text;
|
return text.isEmpty ? null : text;
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'drama.dart';
|
||||||
|
import 'locale_text.dart';
|
||||||
|
|
||||||
|
/// C 端剧单:`GET /app/playlists` 与 `GET /app/playlists/{id}` 的同一结构。
|
||||||
|
class PlaylistDetail {
|
||||||
|
const PlaylistDetail({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.description,
|
||||||
|
this.locales = const {},
|
||||||
|
this.descriptionLocales = const {},
|
||||||
|
required this.dramaCount,
|
||||||
|
required this.dramas,
|
||||||
|
this.pageIndex = 1,
|
||||||
|
this.pageSize = 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
/// 中文名称,与 locales 里的 zh 相同。
|
||||||
|
final String name;
|
||||||
|
final Map<String, String> locales;
|
||||||
|
|
||||||
|
/// 中文描述,与 descriptionLocales 里的 zh 相同。
|
||||||
|
final String description;
|
||||||
|
final Map<String, String> descriptionLocales;
|
||||||
|
final int dramaCount;
|
||||||
|
final int pageIndex;
|
||||||
|
final int pageSize;
|
||||||
|
final List<Drama> dramas;
|
||||||
|
|
||||||
|
factory PlaylistDetail.fromJson(Map<String, dynamic> json) {
|
||||||
|
final dramas = _dramasOf(json['list']);
|
||||||
|
final locales = localeMap(json['locales']);
|
||||||
|
final descriptions = localeMap(json['descriptionLocales']);
|
||||||
|
return PlaylistDetail(
|
||||||
|
id: (json['id'] ?? '').toString(),
|
||||||
|
name: json['name'] as String? ?? locales['zh'] ?? '',
|
||||||
|
locales: locales,
|
||||||
|
description: json['description'] as String? ?? descriptions['zh'] ?? '',
|
||||||
|
descriptionLocales: descriptions,
|
||||||
|
dramaCount: (json['dramaCount'] as num?)?.toInt() ?? dramas.length,
|
||||||
|
pageIndex: (json['pageIndex'] as num?)?.toInt() ?? 1,
|
||||||
|
pageSize: (json['pageSize'] as num?)?.toInt() ?? dramas.length,
|
||||||
|
dramas: dramas,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按界面语言取名称。缺对应语言时回落到中文。
|
||||||
|
String localizedName(String languageCode) {
|
||||||
|
return localizedText(languageCode, name, locales);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按界面语言取描述。缺对应语言时回落到中文。
|
||||||
|
String localizedDescription(String languageCode) {
|
||||||
|
return localizedText(languageCode, description, descriptionLocales);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Drama> _dramasOf(Object? rows) {
|
||||||
|
if (rows is! List) return const [];
|
||||||
|
return rows
|
||||||
|
.whereType<Map>()
|
||||||
|
.map((item) => Drama.fromCardJson(Map<String, dynamic>.from(item)))
|
||||||
|
.toList(growable: false);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
import 'json_numbers.dart';
|
import 'json_numbers.dart';
|
||||||
|
import 'locale_text.dart';
|
||||||
|
|
||||||
/// 服务端续看记录:`GET /app/watch/progress?dramaId=` 与 `/app/watch/recent` 的下发结构。
|
/// 服务端续看记录:`GET /app/watch/progress?dramaId=` 与 `/app/watch/recent` 的下发结构。
|
||||||
///
|
///
|
||||||
@@ -13,17 +14,20 @@ class WatchProgress {
|
|||||||
required this.position,
|
required this.position,
|
||||||
required this.duration,
|
required this.duration,
|
||||||
this.dramaTitle,
|
this.dramaTitle,
|
||||||
|
this.titleLocales = const {},
|
||||||
this.dramaCover,
|
this.dramaCover,
|
||||||
this.episodeNumber,
|
this.episodeNumber,
|
||||||
this.totalEpisodes,
|
this.totalEpisodes,
|
||||||
this.finished = false,
|
this.finished = false,
|
||||||
this.playCount = 0,
|
this.playCount = 0,
|
||||||
|
this.viewCount,
|
||||||
this.updatedAt,
|
this.updatedAt,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String dramaId;
|
final String dramaId;
|
||||||
final String episodeId;
|
final String episodeId;
|
||||||
final String? dramaTitle;
|
final String? dramaTitle;
|
||||||
|
final Map<String, String> titleLocales;
|
||||||
final String? dramaCover;
|
final String? dramaCover;
|
||||||
final int? episodeNumber;
|
final int? episodeNumber;
|
||||||
final int? totalEpisodes;
|
final int? totalEpisodes;
|
||||||
@@ -31,6 +35,9 @@ class WatchProgress {
|
|||||||
final Duration duration;
|
final Duration duration;
|
||||||
final bool finished;
|
final bool finished;
|
||||||
final int playCount;
|
final int playCount;
|
||||||
|
|
||||||
|
/// 短剧热度。历史列表没下发时为空,不能拿用户自己的 playCount 冒充。
|
||||||
|
final int? viewCount;
|
||||||
final DateTime? updatedAt;
|
final DateTime? updatedAt;
|
||||||
|
|
||||||
bool get hasPosition => position > Duration.zero;
|
bool get hasPosition => position > Duration.zero;
|
||||||
@@ -41,11 +48,17 @@ class WatchProgress {
|
|||||||
return (position.inMilliseconds / duration.inMilliseconds).clamp(0.0, 1.0);
|
return (position.inMilliseconds / duration.inMilliseconds).clamp(0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 按当前语言取剧名。没有对应语言时回退中文,再回退 dramaTitle。
|
||||||
|
String localizedTitle(String languageCode) {
|
||||||
|
return localizedText(languageCode, dramaTitle ?? '', titleLocales);
|
||||||
|
}
|
||||||
|
|
||||||
factory WatchProgress.fromJson(Map<String, dynamic> json) {
|
factory WatchProgress.fromJson(Map<String, dynamic> json) {
|
||||||
return WatchProgress(
|
return WatchProgress(
|
||||||
dramaId: (json['dramaId'] ?? '').toString(),
|
dramaId: (json['dramaId'] ?? '').toString(),
|
||||||
episodeId: (json['episodeId'] ?? '').toString(),
|
episodeId: (json['episodeId'] ?? '').toString(),
|
||||||
dramaTitle: json['dramaTitle']?.toString(),
|
dramaTitle: json['dramaTitle']?.toString(),
|
||||||
|
titleLocales: localeMap(json['titleLocales']),
|
||||||
dramaCover: json['dramaCover']?.toString(),
|
dramaCover: json['dramaCover']?.toString(),
|
||||||
episodeNumber: json['episodeNumber'] == null
|
episodeNumber: json['episodeNumber'] == null
|
||||||
? null
|
? null
|
||||||
@@ -57,6 +70,9 @@ class WatchProgress {
|
|||||||
duration: Duration(milliseconds: jsonToInt(json['durationMs'])),
|
duration: Duration(milliseconds: jsonToInt(json['durationMs'])),
|
||||||
finished: json['finished'] == true,
|
finished: json['finished'] == true,
|
||||||
playCount: jsonToInt(json['playCount']),
|
playCount: jsonToInt(json['playCount']),
|
||||||
|
viewCount: json['viewCount'] == null
|
||||||
|
? null
|
||||||
|
: jsonToInt(json['viewCount']),
|
||||||
updatedAt: DateTime.tryParse(json['updatedAt'] as String? ?? ''),
|
updatedAt: DateTime.tryParse(json['updatedAt'] as String? ?? ''),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -65,6 +81,7 @@ class WatchProgress {
|
|||||||
'dramaId': dramaId,
|
'dramaId': dramaId,
|
||||||
'episodeId': episodeId,
|
'episodeId': episodeId,
|
||||||
if (dramaTitle != null) 'dramaTitle': dramaTitle,
|
if (dramaTitle != null) 'dramaTitle': dramaTitle,
|
||||||
|
if (titleLocales.isNotEmpty) 'titleLocales': titleLocales,
|
||||||
if (dramaCover != null) 'dramaCover': dramaCover,
|
if (dramaCover != null) 'dramaCover': dramaCover,
|
||||||
if (episodeNumber != null) 'episodeNumber': episodeNumber,
|
if (episodeNumber != null) 'episodeNumber': episodeNumber,
|
||||||
if (totalEpisodes != null) 'totalEpisodes': totalEpisodes,
|
if (totalEpisodes != null) 'totalEpisodes': totalEpisodes,
|
||||||
@@ -72,6 +89,7 @@ class WatchProgress {
|
|||||||
'durationMs': duration.inMilliseconds,
|
'durationMs': duration.inMilliseconds,
|
||||||
'finished': finished,
|
'finished': finished,
|
||||||
'playCount': playCount,
|
'playCount': playCount,
|
||||||
|
if (viewCount != null) 'viewCount': viewCount,
|
||||||
if (updatedAt != null) 'updatedAt': updatedAt!.toIso8601String(),
|
if (updatedAt != null) 'updatedAt': updatedAt!.toIso8601String(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,13 @@ class WatchRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 服务端分页标题优先,详情标题作为回退。
|
/// 服务端分页标题优先,详情标题作为回退。
|
||||||
String get displayTitle {
|
String get displayTitle => localizedDisplayTitle('zh');
|
||||||
final pageTitle = progress.dramaTitle?.trim() ?? '';
|
|
||||||
return pageTitle.isNotEmpty ? pageTitle : drama?.title.trim() ?? '';
|
/// 按当前语言取标题。分页语言表优先,详情语言表作为回退。
|
||||||
|
String localizedDisplayTitle(String languageCode) {
|
||||||
|
final pageTitle = progress.localizedTitle(languageCode).trim();
|
||||||
|
if (pageTitle.isNotEmpty) return pageTitle;
|
||||||
|
return drama?.localizedTitle(languageCode).trim() ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 服务端分页封面优先,详情封面作为回退。
|
/// 服务端分页封面优先,详情封面作为回退。
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class ApiClient {
|
|||||||
this.tokenRefresher,
|
this.tokenRefresher,
|
||||||
this.onUnauthorized,
|
this.onUnauthorized,
|
||||||
this.deviceIdReader,
|
this.deviceIdReader,
|
||||||
|
this.platformReader,
|
||||||
}) : _fixedBaseUrl = baseUrl {
|
}) : _fixedBaseUrl = baseUrl {
|
||||||
_dio = Dio(
|
_dio = Dio(
|
||||||
BaseOptions(
|
BaseOptions(
|
||||||
@@ -40,6 +41,7 @@ class ApiClient {
|
|||||||
AuthHeaderInterceptor(
|
AuthHeaderInterceptor(
|
||||||
accessTokenReader: accessTokenReader,
|
accessTokenReader: accessTokenReader,
|
||||||
deviceIdReader: deviceIdReader,
|
deviceIdReader: deviceIdReader,
|
||||||
|
platformReader: platformReader,
|
||||||
),
|
),
|
||||||
const EnvelopeInterceptor(),
|
const EnvelopeInterceptor(),
|
||||||
NetworkLogInterceptor(),
|
NetworkLogInterceptor(),
|
||||||
@@ -67,6 +69,9 @@ class ApiClient {
|
|||||||
/// 设备号(`X-Device-Id`):注册风控、后续下载绑定都要用
|
/// 设备号(`X-Device-Id`):注册风控、后续下载绑定都要用
|
||||||
final Future<String> Function()? deviceIdReader;
|
final Future<String> Function()? deviceIdReader;
|
||||||
|
|
||||||
|
/// 客户端平台(`X-Client-Platform`):后台区分 iOS / Android
|
||||||
|
final String Function()? platformReader;
|
||||||
|
|
||||||
Future<Object?> get(String path, {Map<String, String>? query}) {
|
Future<Object?> get(String path, {Map<String, String>? query}) {
|
||||||
return _request('GET', path, query: query);
|
return _request('GET', path, query: query);
|
||||||
}
|
}
|
||||||
@@ -148,7 +153,8 @@ class ApiClient {
|
|||||||
skipAuthRetry: skipAuthRetry,
|
skipAuthRetry: skipAuthRetry,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
onUnauthorized?.call();
|
final token = accessTokenReader?.call();
|
||||||
|
if (token == null || token.isEmpty) onUnauthorized?.call();
|
||||||
throw ApiException(401, cause.message ?? '登录已过期');
|
throw ApiException(401, cause.message ?? '登录已过期');
|
||||||
}
|
}
|
||||||
if (cause is ApiException) {
|
if (cause is ApiException) {
|
||||||
|
|||||||
@@ -32,7 +32,11 @@ class TokenExpiredException implements Exception {
|
|||||||
///
|
///
|
||||||
/// 每个请求都重新取一次令牌,所以刷新成功后重发的那次会自动带上新令牌。
|
/// 每个请求都重新取一次令牌,所以刷新成功后重发的那次会自动带上新令牌。
|
||||||
class AuthHeaderInterceptor extends Interceptor {
|
class AuthHeaderInterceptor extends Interceptor {
|
||||||
AuthHeaderInterceptor({this.accessTokenReader, this.deviceIdReader});
|
AuthHeaderInterceptor({
|
||||||
|
this.accessTokenReader,
|
||||||
|
this.deviceIdReader,
|
||||||
|
this.platformReader,
|
||||||
|
});
|
||||||
|
|
||||||
/// 当前 access token;未登录返回 null 或空串。
|
/// 当前 access token;未登录返回 null 或空串。
|
||||||
final String? Function()? accessTokenReader;
|
final String? Function()? accessTokenReader;
|
||||||
@@ -40,6 +44,9 @@ class AuthHeaderInterceptor extends Interceptor {
|
|||||||
/// 设备号(`X-Device-Id`):注册风控、下载绑定都用它。
|
/// 设备号(`X-Device-Id`):注册风控、下载绑定都用它。
|
||||||
final Future<String> Function()? deviceIdReader;
|
final Future<String> Function()? deviceIdReader;
|
||||||
|
|
||||||
|
/// 客户端平台(`X-Client-Platform`):后台区分 iOS / Android,匿名请求同样要带。
|
||||||
|
final String Function()? platformReader;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onRequest(
|
Future<void> onRequest(
|
||||||
RequestOptions options,
|
RequestOptions options,
|
||||||
@@ -54,6 +61,10 @@ class AuthHeaderInterceptor extends Interceptor {
|
|||||||
if (deviceId != null && deviceId.isNotEmpty) {
|
if (deviceId != null && deviceId.isNotEmpty) {
|
||||||
options.headers['X-Device-Id'] = deviceId;
|
options.headers['X-Device-Id'] = deviceId;
|
||||||
}
|
}
|
||||||
|
final platform = platformReader?.call() ?? '';
|
||||||
|
if (platform.isNotEmpty) {
|
||||||
|
options.headers['X-Client-Platform'] = platform;
|
||||||
|
}
|
||||||
handler.next(options);
|
handler.next(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class AuthApi {
|
|||||||
required String code,
|
required String code,
|
||||||
required String deviceId,
|
required String deviceId,
|
||||||
String platform = '',
|
String platform = '',
|
||||||
|
String osVersion = '',
|
||||||
String appVersion = '',
|
String appVersion = '',
|
||||||
}) async {
|
}) async {
|
||||||
final data = await _client.post(
|
final data = await _client.post(
|
||||||
@@ -43,6 +44,7 @@ class AuthApi {
|
|||||||
'code': code,
|
'code': code,
|
||||||
'deviceId': deviceId,
|
'deviceId': deviceId,
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
|
'osVersion': osVersion,
|
||||||
'appVersion': appVersion,
|
'appVersion': appVersion,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -54,7 +56,9 @@ class AuthApi {
|
|||||||
required String target,
|
required String target,
|
||||||
required String code,
|
required String code,
|
||||||
required String deviceId,
|
required String deviceId,
|
||||||
|
String countryCode = '',
|
||||||
String platform = '',
|
String platform = '',
|
||||||
|
String osVersion = '',
|
||||||
String appVersion = '',
|
String appVersion = '',
|
||||||
}) async {
|
}) async {
|
||||||
final data = await _client.post(
|
final data = await _client.post(
|
||||||
@@ -63,8 +67,10 @@ class AuthApi {
|
|||||||
'targetType': 'PHONE',
|
'targetType': 'PHONE',
|
||||||
'target': target,
|
'target': target,
|
||||||
'code': code,
|
'code': code,
|
||||||
|
'countryCode': countryCode,
|
||||||
'deviceId': deviceId,
|
'deviceId': deviceId,
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
|
'osVersion': osVersion,
|
||||||
'appVersion': appVersion,
|
'appVersion': appVersion,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -75,7 +81,9 @@ class AuthApi {
|
|||||||
required String email,
|
required String email,
|
||||||
required String password,
|
required String password,
|
||||||
required String deviceId,
|
required String deviceId,
|
||||||
|
String countryCode = '',
|
||||||
String platform = '',
|
String platform = '',
|
||||||
|
String osVersion = '',
|
||||||
String appVersion = '',
|
String appVersion = '',
|
||||||
}) async {
|
}) async {
|
||||||
final data = await _client.post(
|
final data = await _client.post(
|
||||||
@@ -84,9 +92,10 @@ class AuthApi {
|
|||||||
'targetType': 'EMAIL',
|
'targetType': 'EMAIL',
|
||||||
'target': email,
|
'target': email,
|
||||||
'password': password,
|
'password': password,
|
||||||
'countryCode': 'ID',
|
'countryCode': countryCode,
|
||||||
'deviceId': deviceId,
|
'deviceId': deviceId,
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
|
'osVersion': osVersion,
|
||||||
'appVersion': appVersion,
|
'appVersion': appVersion,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -98,6 +107,7 @@ class AuthApi {
|
|||||||
required String password,
|
required String password,
|
||||||
required String deviceId,
|
required String deviceId,
|
||||||
String platform = '',
|
String platform = '',
|
||||||
|
String osVersion = '',
|
||||||
String appVersion = '',
|
String appVersion = '',
|
||||||
}) async {
|
}) async {
|
||||||
final data = await _client.post(
|
final data = await _client.post(
|
||||||
@@ -108,17 +118,25 @@ class AuthApi {
|
|||||||
'password': password,
|
'password': password,
|
||||||
'deviceId': deviceId,
|
'deviceId': deviceId,
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
|
'osVersion': osVersion,
|
||||||
'appVersion': appVersion,
|
'appVersion': appVersion,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return AuthSession.fromJson((data as Map).cast<String, dynamic>());
|
return AuthSession.fromJson((data as Map).cast<String, dynamic>());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<AuthSession> refresh(String refreshToken) async {
|
Future<AuthSession> refresh(
|
||||||
|
String refreshToken, {
|
||||||
|
String platform = '',
|
||||||
|
String osVersion = '',
|
||||||
|
}) async {
|
||||||
final data = await _client.post(
|
final data = await _client.post(
|
||||||
'/app/auth/refresh',
|
'/app/auth/refresh',
|
||||||
body: {'refreshToken': refreshToken},
|
body: {
|
||||||
// 刷新请求本身不带旧令牌重试,失败就是失败
|
'refreshToken': refreshToken,
|
||||||
|
'platform': platform,
|
||||||
|
'osVersion': osVersion,
|
||||||
|
},
|
||||||
skipAuthRetry: true,
|
skipAuthRetry: true,
|
||||||
);
|
);
|
||||||
return AuthSession.fromJson((data as Map).cast<String, dynamic>());
|
return AuthSession.fromJson((data as Map).cast<String, dynamic>());
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import '../models/content_category.dart';
|
||||||
import '../models/drama.dart';
|
import '../models/drama.dart';
|
||||||
import '../models/feed_page.dart';
|
import '../models/feed_page.dart';
|
||||||
import '../models/home_feed.dart';
|
import '../models/home_feed.dart';
|
||||||
|
import '../models/page_result.dart';
|
||||||
|
import '../models/playlist_detail.dart';
|
||||||
import '../models/search_result.dart';
|
import '../models/search_result.dart';
|
||||||
import 'api_client.dart';
|
import 'api_client.dart';
|
||||||
|
|
||||||
@@ -58,12 +61,95 @@ class CatalogApi {
|
|||||||
return SearchResult.fromJson(_asMap(data));
|
return SearchResult.fromJson(_asMap(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const int playlistPageSize = 10;
|
||||||
|
static const int playlistDramaPageSize = 20;
|
||||||
|
|
||||||
|
/// 已启用剧单,分页返回,每条带已上线短剧卡片。
|
||||||
|
Future<PageResult<PlaylistDetail>> playlists({
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = playlistPageSize,
|
||||||
|
}) async {
|
||||||
|
final data = await _client.get(
|
||||||
|
'/app/playlists',
|
||||||
|
query: {
|
||||||
|
'pageIndex': '$pageIndex',
|
||||||
|
'pageSize': '$pageSize',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return PageResult.parse(data, PlaylistDetail.fromJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 单个剧单详情。短剧按 pageIndex、pageSize 翻页。
|
||||||
|
Future<PlaylistDetail> playlist(
|
||||||
|
String id, {
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = playlistDramaPageSize,
|
||||||
|
}) async {
|
||||||
|
return PlaylistDetail.fromJson(
|
||||||
|
_asMap(
|
||||||
|
await _client.get(
|
||||||
|
'/app/playlists/$id',
|
||||||
|
query: {
|
||||||
|
'pageIndex': '$pageIndex',
|
||||||
|
'pageSize': '$pageSize',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 已启用首页分类,名称在 locales。
|
||||||
|
Future<List<ContentCategory>> classifications() async {
|
||||||
|
return _categories(await _client.get('/app/categories'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 已启用类型,名称在 locales。
|
||||||
|
Future<List<ContentCategory>> dramaCategories() async {
|
||||||
|
return _categories(await _client.get('/app/drama-categories'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 已启用标签,名称在 locales。
|
||||||
|
Future<List<ContentCategory>> tags() async {
|
||||||
|
return _categories(await _client.get('/app/tags'));
|
||||||
|
}
|
||||||
|
|
||||||
|
static const int libraryPageSize = 20;
|
||||||
|
|
||||||
|
/// 全部短剧。同一组 id 多选为或,组与组之间为且。
|
||||||
|
Future<PageResult<Drama>> libraryDramas({
|
||||||
|
List<String> categoryIds = const [],
|
||||||
|
List<String> classificationIds = const [],
|
||||||
|
List<String> tagIds = const [],
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = libraryPageSize,
|
||||||
|
}) async {
|
||||||
|
final data = await _client.post(
|
||||||
|
'/app/dramas/page',
|
||||||
|
body: {
|
||||||
|
'pageIndex': pageIndex,
|
||||||
|
'pageSize': pageSize,
|
||||||
|
'categoryIds': categoryIds,
|
||||||
|
'classificationIds': classificationIds,
|
||||||
|
'tagIds': tagIds,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return PageResult.parse(data, Drama.fromCardJson);
|
||||||
|
}
|
||||||
|
|
||||||
Future<Drama> dramaDetail(String dramaId) async {
|
Future<Drama> dramaDetail(String dramaId) async {
|
||||||
return Drama.fromDetailJson(
|
return Drama.fromDetailJson(
|
||||||
_asMap(await _client.get('/app/dramas/$dramaId')),
|
_asMap(await _client.get('/app/dramas/$dramaId')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ContentCategory> _categories(Object? data) {
|
||||||
|
if (data is! List) return const [];
|
||||||
|
return [
|
||||||
|
for (final item in data)
|
||||||
|
if (item is Map<String, dynamic>) ContentCategory.fromJson(item),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, dynamic> _asMap(Object? data) {
|
Map<String, dynamic> _asMap(Object? data) {
|
||||||
if (data is Map<String, dynamic>) return data;
|
if (data is Map<String, dynamic>) return data;
|
||||||
throw const ApiException(-1, '返回数据格式异常');
|
throw const ApiException(-1, '返回数据格式异常');
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
import '../models/content_category.dart';
|
import '../models/content_category.dart';
|
||||||
|
import '../models/drama.dart';
|
||||||
|
import '../models/page_result.dart';
|
||||||
import 'api_client.dart';
|
import 'api_client.dart';
|
||||||
|
|
||||||
/// 内容分类接口,对应契约 `GET /app/categories`。
|
/// 内容分类接口,对应契约 `GET /app/categories`。
|
||||||
class CategoryApi {
|
class CategoryApi {
|
||||||
const CategoryApi(this._client);
|
const CategoryApi(this._client);
|
||||||
|
|
||||||
|
static const int dramaPageSize = 20;
|
||||||
|
|
||||||
final ApiClient _client;
|
final ApiClient _client;
|
||||||
|
|
||||||
/// 拉取已启用分类,id 全程按字符串解析。
|
/// 拉取已启用分类,id 全程按字符串解析。
|
||||||
@@ -18,4 +22,20 @@ class CategoryApi {
|
|||||||
if (item is Map<String, dynamic>) ContentCategory.fromJson(item),
|
if (item is Map<String, dynamic>) ContentCategory.fromJson(item),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 分类下已上线短剧,pageIndex 从 1 开始。
|
||||||
|
Future<PageResult<Drama>> dramas(
|
||||||
|
String categoryId, {
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = dramaPageSize,
|
||||||
|
}) async {
|
||||||
|
final data = await _client.get(
|
||||||
|
'/app/categories/$categoryId/dramas',
|
||||||
|
query: {
|
||||||
|
'pageIndex': '$pageIndex',
|
||||||
|
'pageSize': '$pageSize',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return PageResult.parse(data, Drama.fromCardJson);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
/// 客户端平台,后台只用来区分 iOS / Android。
|
||||||
|
///
|
||||||
|
/// 系统版本、机型一律不上报:后台列表需要的只是「这台设备是安卓还是苹果」。
|
||||||
|
String clientPlatform() {
|
||||||
|
if (kIsWeb) return 'WEB';
|
||||||
|
if (Platform.isAndroid) return 'ANDROID';
|
||||||
|
if (Platform.isIOS) return 'IOS';
|
||||||
|
return '';
|
||||||
|
}
|
||||||
@@ -36,4 +36,9 @@ class LibraryApi {
|
|||||||
Future<void> removeFavorite(String dramaId) async {
|
Future<void> removeFavorite(String dramaId) async {
|
||||||
await _client.delete('/app/favorites/$dramaId');
|
await _client.delete('/app/favorites/$dramaId');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 一次取消多部短剧,请求体为 dramaIds 数组。
|
||||||
|
Future<void> removeFavorites(List<String> dramaIds) async {
|
||||||
|
await _client.post('/app/favorites/remove', body: {'dramaIds': dramaIds});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import '../models/episode_stats.dart';
|
||||||
import '../models/play_ticket.dart';
|
import '../models/play_ticket.dart';
|
||||||
import 'api_client.dart';
|
import 'api_client.dart';
|
||||||
|
|
||||||
@@ -17,4 +18,11 @@ class PlaybackApi {
|
|||||||
if (data is Map<String, dynamic>) return PlayTicket.fromJson(data);
|
if (data is Map<String, dynamic>) return PlayTicket.fromJson(data);
|
||||||
throw const ApiException(-1, '返回数据格式异常');
|
throw const ApiException(-1, '返回数据格式异常');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 轻量刷新互动计数:不签发地址,也不占用播放票据缓存。
|
||||||
|
Future<EpisodeStats> episodeStats(String episodeId) async {
|
||||||
|
final data = await _client.get('/app/episodes/$episodeId/stats');
|
||||||
|
if (data is Map<String, dynamic>) return EpisodeStats.fromJson(data);
|
||||||
|
throw const ApiException(-1, '返回数据格式异常');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import '../models/page_result.dart';
|
|||||||
import '../models/watch_progress.dart';
|
import '../models/watch_progress.dart';
|
||||||
import 'api_client.dart';
|
import 'api_client.dart';
|
||||||
|
|
||||||
/// 观看进度接口:`/app/watch/*`(契约 §1.5)。全部需要登录态。
|
/// 观看进度接口:`/app/watch/*`(契约 §1.5)。支持账号或设备身份。
|
||||||
class WatchApi {
|
class WatchApi {
|
||||||
const WatchApi(this._client);
|
const WatchApi(this._client);
|
||||||
|
|
||||||
|
|||||||
@@ -13,29 +13,30 @@ abstract interface class FavoriteRepository {
|
|||||||
Future<PageResult<Drama>> page({int pageIndex = 1, int pageSize = 20});
|
Future<PageResult<Drama>> page({int pageIndex = 1, int pageSize = 20});
|
||||||
|
|
||||||
Future<void> remove(String dramaId);
|
Future<void> remove(String dramaId);
|
||||||
|
|
||||||
|
/// 一次取消多部短剧。
|
||||||
|
Future<void> removeMany(List<String> dramaIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpFavoriteRepository implements FavoriteRepository {
|
class HttpFavoriteRepository implements FavoriteRepository {
|
||||||
const HttpFavoriteRepository(this._api, {this.isSignedIn});
|
const HttpFavoriteRepository(this._api);
|
||||||
|
|
||||||
final LibraryApi _api;
|
final LibraryApi _api;
|
||||||
|
|
||||||
/// 未登录时不请求:收藏属于账号,匿名浏览时列表按空处理(点收藏按钮会先引导登录)。
|
|
||||||
final bool Function()? isSignedIn;
|
|
||||||
|
|
||||||
bool get _signedIn => isSignedIn?.call() ?? true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> toggle(String dramaId) => _api.toggleFavorite(dramaId);
|
Future<bool> toggle(String dramaId) => _api.toggleFavorite(dramaId);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<PageResult<Drama>> page({int pageIndex = 1, int pageSize = 20}) async {
|
Future<PageResult<Drama>> page({int pageIndex = 1, int pageSize = 20}) async {
|
||||||
if (!_signedIn) return const PageResult();
|
|
||||||
return _api.favorites(pageIndex: pageIndex, pageSize: pageSize);
|
return _api.favorites(pageIndex: pageIndex, pageSize: pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> remove(String dramaId) => _api.removeFavorite(dramaId);
|
Future<void> remove(String dramaId) => _api.removeFavorite(dramaId);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> removeMany(List<String> dramaIds) =>
|
||||||
|
_api.removeFavorites(dramaIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 内存实现:单测与 widget 测试注入用。
|
/// 内存实现:单测与 widget 测试注入用。
|
||||||
@@ -51,6 +52,7 @@ class InMemoryFavoriteRepository implements FavoriteRepository {
|
|||||||
bool failRemove = false;
|
bool failRemove = false;
|
||||||
int toggleCalls = 0;
|
int toggleCalls = 0;
|
||||||
int pageCalls = 0;
|
int pageCalls = 0;
|
||||||
|
int removeManyCalls = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> toggle(String dramaId) async {
|
Future<bool> toggle(String dramaId) async {
|
||||||
@@ -80,4 +82,11 @@ class InMemoryFavoriteRepository implements FavoriteRepository {
|
|||||||
if (failRemove) throw StateError('favorite unavailable');
|
if (failRemove) throw StateError('favorite unavailable');
|
||||||
_saved.remove(dramaId);
|
_saved.remove(dramaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> removeMany(List<String> dramaIds) async {
|
||||||
|
removeManyCalls += 1;
|
||||||
|
if (failRemove) throw StateError('favorite unavailable');
|
||||||
|
_saved.removeAll(dramaIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import '../models/episode_stats.dart';
|
||||||
import '../models/play_ticket.dart';
|
import '../models/play_ticket.dart';
|
||||||
import '../remote/playback_api.dart';
|
import '../remote/playback_api.dart';
|
||||||
|
|
||||||
@@ -10,6 +11,9 @@ import '../remote/playback_api.dart';
|
|||||||
abstract interface class PlaybackRepository {
|
abstract interface class PlaybackRepository {
|
||||||
Future<PlayTicket> ticketFor(String episodeId, {bool forceRefresh = false});
|
Future<PlayTicket> ticketFor(String episodeId, {bool forceRefresh = false});
|
||||||
|
|
||||||
|
/// 读取互动计数快照;与 [ticketFor] 分离,避免为了刷新计数重新签发地址。
|
||||||
|
Future<EpisodeStats> episodeStats(String episodeId);
|
||||||
|
|
||||||
/// 当前缓存的票据是否还在有效期内(用于"回前台发现过期就重新取")。
|
/// 当前缓存的票据是否还在有效期内(用于"回前台发现过期就重新取")。
|
||||||
bool isFresh(String episodeId);
|
bool isFresh(String episodeId);
|
||||||
}
|
}
|
||||||
@@ -42,6 +46,10 @@ class HttpPlaybackRepository implements PlaybackRepository {
|
|||||||
return ticket;
|
return ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<EpisodeStats> episodeStats(String episodeId) =>
|
||||||
|
_api.episodeStats(episodeId);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool isFresh(String episodeId) {
|
bool isFresh(String episodeId) {
|
||||||
final cached = _cache[episodeId];
|
final cached = _cache[episodeId];
|
||||||
@@ -65,11 +73,22 @@ class _CachedTicket {
|
|||||||
|
|
||||||
/// 测试与离线场景用:按集返回固定票据,并记录被请求过几次。
|
/// 测试与离线场景用:按集返回固定票据,并记录被请求过几次。
|
||||||
class FakePlaybackRepository implements PlaybackRepository {
|
class FakePlaybackRepository implements PlaybackRepository {
|
||||||
FakePlaybackRepository({this.ticket, this.error, this.fresh = true});
|
FakePlaybackRepository({
|
||||||
|
this.ticket,
|
||||||
|
this.error,
|
||||||
|
this.fresh = true,
|
||||||
|
this.stats,
|
||||||
|
this.statsError,
|
||||||
|
Map<String, EpisodeStats>? statsByEpisode,
|
||||||
|
}) : statsByEpisode = statsByEpisode ?? {};
|
||||||
|
|
||||||
PlayTicket? ticket;
|
PlayTicket? ticket;
|
||||||
Object? error;
|
Object? error;
|
||||||
|
EpisodeStats? stats;
|
||||||
|
Object? statsError;
|
||||||
|
final Map<String, EpisodeStats> statsByEpisode;
|
||||||
final List<String> requests = [];
|
final List<String> requests = [];
|
||||||
|
final List<String> statsRequests = [];
|
||||||
final List<bool> forced = [];
|
final List<bool> forced = [];
|
||||||
|
|
||||||
/// 模拟"票据是否还有效":置 false 可验证回前台会重新取。
|
/// 模拟"票据是否还有效":置 false 可验证回前台会重新取。
|
||||||
@@ -95,4 +114,13 @@ class FakePlaybackRepository implements PlaybackRepository {
|
|||||||
qualities: const ['AUTO', '720P', '1080P'],
|
qualities: const ['AUTO', '720P', '1080P'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<EpisodeStats> episodeStats(String episodeId) async {
|
||||||
|
statsRequests.add(episodeId);
|
||||||
|
if (statsError != null) throw statsError!;
|
||||||
|
final value = statsByEpisode[episodeId] ?? stats;
|
||||||
|
if (value != null) return value;
|
||||||
|
throw StateError('episode stats not configured for $episodeId');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import '../models/page_result.dart';
|
||||||
|
import '../models/playlist_detail.dart';
|
||||||
|
import '../remote/catalog_api.dart';
|
||||||
|
|
||||||
|
/// 剧单来源:列表分页拉取,详情用于打开单条时刷新。
|
||||||
|
abstract interface class PlaylistRepository {
|
||||||
|
Future<PageResult<PlaylistDetail>> fetchPlaylists({
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = CatalogApi.playlistPageSize,
|
||||||
|
});
|
||||||
|
|
||||||
|
Future<PlaylistDetail> fetchPlaylist(
|
||||||
|
String id, {
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = CatalogApi.playlistDramaPageSize,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class HttpPlaylistRepository implements PlaylistRepository {
|
||||||
|
HttpPlaylistRepository(this._api);
|
||||||
|
|
||||||
|
final CatalogApi _api;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PageResult<PlaylistDetail>> fetchPlaylists({
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = CatalogApi.playlistPageSize,
|
||||||
|
}) => _api.playlists(pageIndex: pageIndex, pageSize: pageSize);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PlaylistDetail> fetchPlaylist(
|
||||||
|
String id, {
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = CatalogApi.playlistDramaPageSize,
|
||||||
|
}) => _api.playlist(id, pageIndex: pageIndex, pageSize: pageSize);
|
||||||
|
}
|
||||||
@@ -35,18 +35,12 @@ abstract interface class WatchHistoryRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HttpWatchHistoryRepository implements WatchHistoryRepository {
|
class HttpWatchHistoryRepository implements WatchHistoryRepository {
|
||||||
const HttpWatchHistoryRepository(this._api, {this.isSignedIn});
|
const HttpWatchHistoryRepository(this._api);
|
||||||
|
|
||||||
final WatchApi _api;
|
final WatchApi _api;
|
||||||
|
|
||||||
/// 未登录时这些接口必然 401:直接短路成"没有记录",让浏览/试看保持匿名可用。
|
|
||||||
final bool Function()? isSignedIn;
|
|
||||||
|
|
||||||
bool get _signedIn => isSignedIn?.call() ?? true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<WatchProgress?> progressFor(String dramaId) async {
|
Future<WatchProgress?> progressFor(String dramaId) async {
|
||||||
if (!_signedIn) return null;
|
|
||||||
return _api.progressOfDrama(dramaId);
|
return _api.progressOfDrama(dramaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +51,6 @@ class HttpWatchHistoryRepository implements WatchHistoryRepository {
|
|||||||
Duration? duration,
|
Duration? duration,
|
||||||
bool finished = false,
|
bool finished = false,
|
||||||
}) async {
|
}) async {
|
||||||
if (!_signedIn) return null;
|
|
||||||
return _api.saveProgress(
|
return _api.saveProgress(
|
||||||
episodeId: episodeId,
|
episodeId: episodeId,
|
||||||
position: position,
|
position: position,
|
||||||
@@ -71,19 +64,16 @@ class HttpWatchHistoryRepository implements WatchHistoryRepository {
|
|||||||
int pageIndex = 1,
|
int pageIndex = 1,
|
||||||
int pageSize = 20,
|
int pageSize = 20,
|
||||||
}) async {
|
}) async {
|
||||||
if (!_signedIn) return const PageResult();
|
|
||||||
return _api.recent(pageIndex: pageIndex, pageSize: pageSize);
|
return _api.recent(pageIndex: pageIndex, pageSize: pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> remove(String dramaId) async {
|
Future<void> remove(String dramaId) async {
|
||||||
if (!_signedIn) return;
|
|
||||||
await _api.removeProgress(dramaId);
|
await _api.removeProgress(dramaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> clear() async {
|
Future<void> clear() async {
|
||||||
if (!_signedIn) return;
|
|
||||||
await _api.clearProgress();
|
await _api.clearProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,173 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
// 全部短剧筛选与分页:拉取分类、类型、标签,并按页加载短剧。
|
||||||
|
|
||||||
|
import '../models/content_category.dart';
|
||||||
|
import '../models/drama.dart';
|
||||||
|
import '../models/page_result.dart';
|
||||||
|
import '../remote/catalog_api.dart';
|
||||||
|
|
||||||
|
/// 全部短剧筛选与分页所需的远端能力。
|
||||||
|
abstract interface class AllDramasRemote {
|
||||||
|
/// 已启用分类。
|
||||||
|
Future<List<ContentCategory>> classifications();
|
||||||
|
|
||||||
|
/// 已启用类型。
|
||||||
|
Future<List<ContentCategory>> categories();
|
||||||
|
|
||||||
|
/// 已启用标签。
|
||||||
|
Future<List<ContentCategory>> tags();
|
||||||
|
|
||||||
|
/// 按当前筛选取一页短剧。
|
||||||
|
Future<PageResult<Drama>> dramas({
|
||||||
|
required List<String> categoryIds,
|
||||||
|
required List<String> classificationIds,
|
||||||
|
required List<String> tagIds,
|
||||||
|
required int pageIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 用现有目录接口实现全部短剧远端能力。
|
||||||
|
class CatalogAllDramasRemote implements AllDramasRemote {
|
||||||
|
/// 绑定目录接口。
|
||||||
|
const CatalogAllDramasRemote(this._api);
|
||||||
|
|
||||||
|
final CatalogApi _api;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<ContentCategory>> classifications() => _api.classifications();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<ContentCategory>> categories() => _api.dramaCategories();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<ContentCategory>> tags() => _api.tags();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PageResult<Drama>> dramas({
|
||||||
|
required List<String> categoryIds,
|
||||||
|
required List<String> classificationIds,
|
||||||
|
required List<String> tagIds,
|
||||||
|
required int pageIndex,
|
||||||
|
}) {
|
||||||
|
return _api.libraryDramas(
|
||||||
|
categoryIds: categoryIds,
|
||||||
|
classificationIds: classificationIds,
|
||||||
|
tagIds: tagIds,
|
||||||
|
pageIndex: pageIndex,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 全部短剧:筛选项来自类型、分类、标签,列表按页加载。
|
||||||
|
class AllDramasController {
|
||||||
|
AllDramasController({
|
||||||
|
AllDramasRemote? api,
|
||||||
|
this.classifications = const [],
|
||||||
|
this.categories = const [],
|
||||||
|
this.tags = const [],
|
||||||
|
this.dramas = const [],
|
||||||
|
}) : _api = api; // ignore: prefer_initializing_formals
|
||||||
|
|
||||||
|
final AllDramasRemote? _api;
|
||||||
|
List<ContentCategory> classifications;
|
||||||
|
List<ContentCategory> categories;
|
||||||
|
List<ContentCategory> tags;
|
||||||
|
final Set<String> selectedClassifications = {};
|
||||||
|
final Set<String> selectedCategories = {};
|
||||||
|
final Set<String> selectedTags = {};
|
||||||
|
List<Drama> dramas;
|
||||||
|
bool loading = false;
|
||||||
|
bool loadingMore = false;
|
||||||
|
bool hasMore = false;
|
||||||
|
String? error;
|
||||||
|
int _page = 1;
|
||||||
|
int _total = 0;
|
||||||
|
|
||||||
|
bool get usesRemote => _api != null;
|
||||||
|
|
||||||
|
/// 预览用:筛选项和列表都已在本地,不请求接口。
|
||||||
|
factory AllDramasController.preview({
|
||||||
|
List<ContentCategory> classifications = const [],
|
||||||
|
List<ContentCategory> categories = const [],
|
||||||
|
List<ContentCategory> tags = const [],
|
||||||
|
List<Drama> dramas = const [],
|
||||||
|
}) {
|
||||||
|
return AllDramasController(
|
||||||
|
classifications: classifications,
|
||||||
|
categories: categories,
|
||||||
|
tags: tags,
|
||||||
|
dramas: dramas,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 从第一页重新拉取筛选项和短剧。没有接口时直接返回。
|
||||||
|
Future<void> refresh() async {
|
||||||
|
if (_api == null) return;
|
||||||
|
loading = true;
|
||||||
|
error = null;
|
||||||
|
_page = 1;
|
||||||
|
try {
|
||||||
|
final filters = await Future.wait([
|
||||||
|
_api.classifications(),
|
||||||
|
_api.categories(),
|
||||||
|
_api.tags(),
|
||||||
|
]);
|
||||||
|
classifications = filters[0];
|
||||||
|
categories = filters[1];
|
||||||
|
tags = filters[2];
|
||||||
|
final page = await _loadPage(1);
|
||||||
|
dramas = page;
|
||||||
|
hasMore = dramas.length < _total;
|
||||||
|
} catch (caught) {
|
||||||
|
error = '$caught';
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 追加下一页。没有更多、正在加载或没有接口时直接返回。
|
||||||
|
Future<void> loadMore() async {
|
||||||
|
if (_api == null || loading || loadingMore || !hasMore) return;
|
||||||
|
loadingMore = true;
|
||||||
|
error = null;
|
||||||
|
try {
|
||||||
|
final next = await _loadPage(_page + 1);
|
||||||
|
_page += 1;
|
||||||
|
dramas = [...dramas, ...next];
|
||||||
|
hasMore = dramas.length < _total;
|
||||||
|
} catch (caught) {
|
||||||
|
error = '$caught';
|
||||||
|
} finally {
|
||||||
|
loadingMore = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 切换一个分类。传入空字符串表示清空这一组。
|
||||||
|
void toggleClassification(String id) =>
|
||||||
|
_toggle(selectedClassifications, id);
|
||||||
|
|
||||||
|
/// 切换一个类型。传入空字符串表示清空这一组。
|
||||||
|
void toggleCategory(String id) => _toggle(selectedCategories, id);
|
||||||
|
|
||||||
|
/// 切换一个标签。传入空字符串表示清空这一组。
|
||||||
|
void toggleTag(String id) => _toggle(selectedTags, id);
|
||||||
|
|
||||||
|
void _toggle(Set<String> selected, String id) {
|
||||||
|
if (id.isEmpty) {
|
||||||
|
selected.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!selected.add(id)) selected.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Drama>> _loadPage(int pageIndex) async {
|
||||||
|
final page = await _api!.dramas(
|
||||||
|
categoryIds: selectedCategories.toList(growable: false),
|
||||||
|
classificationIds: selectedClassifications.toList(growable: false),
|
||||||
|
tagIds: selectedTags.toList(growable: false),
|
||||||
|
pageIndex: pageIndex,
|
||||||
|
);
|
||||||
|
_total = page.total;
|
||||||
|
return page.list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
import '../models/auth_session.dart';
|
import '../models/auth_session.dart';
|
||||||
@@ -9,7 +11,7 @@ import 'auth_session_store.dart';
|
|||||||
///
|
///
|
||||||
/// 职责:本地会话的读写([AuthSessionStore])、注册/登录/登出、令牌刷新;
|
/// 职责:本地会话的读写([AuthSessionStore])、注册/登录/登出、令牌刷新;
|
||||||
/// 也是 [ApiClient] 的 `accessTokenReader` / `tokenRefresher` / `onUnauthorized` 实现方 ——
|
/// 也是 [ApiClient] 的 `accessTokenReader` / `tokenRefresher` / `onUnauthorized` 实现方 ——
|
||||||
/// 401 → 刷新 → 重试失败就清会话,UI 通过 [isSignedIn] 自动回到未登录态。
|
/// 401 → 刷新 → 重试。令牌被拒绝才清会话,服务中断时保持登录。
|
||||||
class AuthController extends ChangeNotifier {
|
class AuthController extends ChangeNotifier {
|
||||||
AuthController(this._api, this._store);
|
AuthController(this._api, this._store);
|
||||||
|
|
||||||
@@ -19,6 +21,10 @@ class AuthController extends ChangeNotifier {
|
|||||||
AuthSession? _session;
|
AuthSession? _session;
|
||||||
String _deviceId = '';
|
String _deviceId = '';
|
||||||
bool _loaded = false;
|
bool _loaded = false;
|
||||||
|
Future<bool>? _refreshing;
|
||||||
|
|
||||||
|
/// 登录已过期、账号停用才清本地会话。服务不可达不能当成退出登录。
|
||||||
|
static const Set<int> _rejectedSessionCodes = {401, 100001};
|
||||||
|
|
||||||
bool get isLoaded => _loaded;
|
bool get isLoaded => _loaded;
|
||||||
bool get isSignedIn => _session != null;
|
bool get isSignedIn => _session != null;
|
||||||
@@ -42,7 +48,9 @@ class AuthController extends ChangeNotifier {
|
|||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
deviceId: await _store.deviceId(),
|
deviceId: await _store.deviceId(),
|
||||||
|
countryCode: await _store.deviceRegion(),
|
||||||
platform: _platform,
|
platform: _platform,
|
||||||
|
osVersion: _osVersion,
|
||||||
);
|
);
|
||||||
await _apply(session);
|
await _apply(session);
|
||||||
}
|
}
|
||||||
@@ -53,14 +61,12 @@ class AuthController extends ChangeNotifier {
|
|||||||
password: password,
|
password: password,
|
||||||
deviceId: await _store.deviceId(),
|
deviceId: await _store.deviceId(),
|
||||||
platform: _platform,
|
platform: _platform,
|
||||||
|
osVersion: _osVersion,
|
||||||
);
|
);
|
||||||
await _apply(session);
|
await _apply(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> sendOtp({
|
Future<void> sendOtp({required String target, String scene = 'LOGIN'}) async {
|
||||||
required String target,
|
|
||||||
String scene = 'LOGIN',
|
|
||||||
}) async {
|
|
||||||
await _api.sendOtp(
|
await _api.sendOtp(
|
||||||
target: target,
|
target: target,
|
||||||
scene: scene,
|
scene: scene,
|
||||||
@@ -77,6 +83,7 @@ class AuthController extends ChangeNotifier {
|
|||||||
code: code,
|
code: code,
|
||||||
deviceId: await _store.deviceId(),
|
deviceId: await _store.deviceId(),
|
||||||
platform: _platform,
|
platform: _platform,
|
||||||
|
osVersion: _osVersion,
|
||||||
);
|
);
|
||||||
await _apply(session);
|
await _apply(session);
|
||||||
}
|
}
|
||||||
@@ -89,11 +96,19 @@ class AuthController extends ChangeNotifier {
|
|||||||
target: target,
|
target: target,
|
||||||
code: code,
|
code: code,
|
||||||
deviceId: await _store.deviceId(),
|
deviceId: await _store.deviceId(),
|
||||||
|
countryCode: await _store.deviceRegion(),
|
||||||
platform: _platform,
|
platform: _platform,
|
||||||
|
osVersion: _osVersion,
|
||||||
);
|
);
|
||||||
await _apply(session);
|
await _apply(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> clear() async {
|
||||||
|
_session = null;
|
||||||
|
await _store.clear();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> signOut() async {
|
Future<void> signOut() async {
|
||||||
final refreshToken = _session?.refreshToken ?? '';
|
final refreshToken = _session?.refreshToken ?? '';
|
||||||
_session = null;
|
_session = null;
|
||||||
@@ -107,29 +122,43 @@ class AuthController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 供 [ApiClient] 调用:刷新令牌并落盘。失败时清本地会话。
|
/// 供 [ApiClient] 调用:刷新令牌并落盘。
|
||||||
Future<bool> refresh() async {
|
///
|
||||||
|
/// 同一时刻只刷新一次,避免重启期间并发 401 把新令牌轮换掉。
|
||||||
|
/// 网络失败或 5xx 保留本地会话;只有令牌被拒绝才退出登录。
|
||||||
|
Future<bool> refresh() {
|
||||||
|
final current = _refreshing;
|
||||||
|
if (current != null) return current;
|
||||||
|
final run = _refreshSingle();
|
||||||
|
_refreshing = run;
|
||||||
|
return run.whenComplete(() {
|
||||||
|
if (identical(_refreshing, run)) _refreshing = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _refreshSingle() async {
|
||||||
final refreshToken = _session?.refreshToken ?? '';
|
final refreshToken = _session?.refreshToken ?? '';
|
||||||
if (refreshToken.isEmpty) {
|
if (refreshToken.isEmpty) {
|
||||||
await clear();
|
await clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await _apply(await _api.refresh(refreshToken));
|
await _apply(
|
||||||
|
await _api.refresh(
|
||||||
|
refreshToken,
|
||||||
|
platform: _platform,
|
||||||
|
osVersion: _osVersion,
|
||||||
|
),
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
|
} on ApiException catch (error) {
|
||||||
|
if (_rejectedSessionCodes.contains(error.code)) await clear();
|
||||||
|
return false;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
await clear();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> clear() async {
|
|
||||||
if (_session == null) return;
|
|
||||||
_session = null;
|
|
||||||
await _store.clear();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 资料保存成功后同步登录态摘要,保留当前令牌。
|
/// 资料保存成功后同步登录态摘要,保留当前令牌。
|
||||||
Future<void> applyProfile(AuthUser user) async {
|
Future<void> applyProfile(AuthUser user) async {
|
||||||
final current = _session;
|
final current = _session;
|
||||||
@@ -154,4 +183,9 @@ class AuthController extends ChangeNotifier {
|
|||||||
if (kIsWeb) return 'WEB';
|
if (kIsWeb) return 'WEB';
|
||||||
return defaultTargetPlatform == TargetPlatform.iOS ? 'IOS' : 'ANDROID';
|
return defaultTargetPlatform == TargetPlatform.iOS ? 'IOS' : 'ANDROID';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get _osVersion {
|
||||||
|
if (kIsWeb) return '';
|
||||||
|
return Platform.operatingSystemVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import 'dart:math';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../models/auth_session.dart';
|
import '../models/auth_session.dart';
|
||||||
|
import 'device_id_provider.dart';
|
||||||
|
|
||||||
/// 令牌与设备号的本地持久化。
|
/// 令牌与设备号的本地持久化。
|
||||||
///
|
///
|
||||||
@@ -11,13 +12,17 @@ import '../models/auth_session.dart';
|
|||||||
/// `SharedPreferences.getInstance()` 在新版本里已标注弃用,两套混用还会让
|
/// `SharedPreferences.getInstance()` 在新版本里已标注弃用,两套混用还会让
|
||||||
/// widget 测试只 mock 到其中一套。
|
/// widget 测试只 mock 到其中一套。
|
||||||
///
|
///
|
||||||
/// 设备号是后端注册风控与后续"下载设备绑定"的依据,所以**首次生成后就固定下来**;
|
/// 设备号优先取系统标识(Android SSAID / iOS IDFV),这样卸载重装后还是同一台设备;
|
||||||
/// 不引 UUID 库(保持极简依赖),用「时间戳 + 随机数」拼一个够用的 id。
|
/// 系统标识不可用时才回退到本地生成并持久化的 UUID,保证任何环境都能跑。
|
||||||
class AuthSessionStore {
|
class AuthSessionStore {
|
||||||
AuthSessionStore({SharedPreferencesAsync? preferences})
|
AuthSessionStore({
|
||||||
: _preferences = preferences ?? SharedPreferencesAsync();
|
SharedPreferencesAsync? preferences,
|
||||||
|
DeviceIdProvider? deviceIdProvider,
|
||||||
|
}) : _preferences = preferences ?? SharedPreferencesAsync(),
|
||||||
|
_deviceIdProvider = deviceIdProvider ?? DeviceIdProvider();
|
||||||
|
|
||||||
final SharedPreferencesAsync _preferences;
|
final SharedPreferencesAsync _preferences;
|
||||||
|
final DeviceIdProvider _deviceIdProvider;
|
||||||
|
|
||||||
static const _kAccessToken = 'auth.accessToken';
|
static const _kAccessToken = 'auth.accessToken';
|
||||||
static const _kRefreshToken = 'auth.refreshToken';
|
static const _kRefreshToken = 'auth.refreshToken';
|
||||||
@@ -25,21 +30,46 @@ class AuthSessionStore {
|
|||||||
static const _kDeviceId = 'device.id';
|
static const _kDeviceId = 'device.id';
|
||||||
|
|
||||||
String? _cachedDeviceId;
|
String? _cachedDeviceId;
|
||||||
|
String? _cachedRegion;
|
||||||
|
|
||||||
Future<String> deviceId() async {
|
Future<String> deviceId() async {
|
||||||
if (_cachedDeviceId != null) return _cachedDeviceId!;
|
if (_cachedDeviceId != null) return _cachedDeviceId!;
|
||||||
var value = await _preferences.getString(_kDeviceId) ?? '';
|
final systemId = await _deviceIdProvider.systemDeviceId();
|
||||||
if (value.isEmpty) {
|
final value = systemId ?? await _localDeviceId();
|
||||||
final random = Random();
|
|
||||||
value =
|
|
||||||
'd-${DateTime.now().millisecondsSinceEpoch.toRadixString(36)}-'
|
|
||||||
'${random.nextInt(1 << 32).toRadixString(36)}';
|
|
||||||
await _preferences.setString(_kDeviceId, value);
|
|
||||||
}
|
|
||||||
_cachedDeviceId = value;
|
_cachedDeviceId = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 设备区域(ISO-2),取不到返回空串;只在注册时作为服务端 IP 解析失败后的兜底。
|
||||||
|
Future<String> deviceRegion() async {
|
||||||
|
if (_cachedRegion != null) return _cachedRegion!;
|
||||||
|
final value = await _deviceIdProvider.deviceRegion() ?? '';
|
||||||
|
_cachedRegion = value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 系统标识取不到时的兜底:本地 UUIDv4,生成一次后固定下来。
|
||||||
|
Future<String> _localDeviceId() async {
|
||||||
|
final stored = await _preferences.getString(_kDeviceId) ?? '';
|
||||||
|
if (stored.isNotEmpty) return stored;
|
||||||
|
final generated = 'd-${_uuidV4()}';
|
||||||
|
await _preferences.setString(_kDeviceId, generated);
|
||||||
|
return generated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// UUIDv4:122 位随机,碰撞概率可忽略,不引第三方依赖。
|
||||||
|
String _uuidV4() {
|
||||||
|
final random = Random.secure();
|
||||||
|
final bytes = List<int>.generate(16, (_) => random.nextInt(256));
|
||||||
|
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
||||||
|
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||||
|
String hex(int start, int end) => bytes
|
||||||
|
.sublist(start, end)
|
||||||
|
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
||||||
|
.join();
|
||||||
|
return '${hex(0, 4)}-${hex(4, 6)}-${hex(6, 8)}-${hex(8, 10)}-${hex(10, 16)}';
|
||||||
|
}
|
||||||
|
|
||||||
Future<AuthSession?> read() async {
|
Future<AuthSession?> read() async {
|
||||||
final accessToken = await _preferences.getString(_kAccessToken) ?? '';
|
final accessToken = await _preferences.getString(_kAccessToken) ?? '';
|
||||||
final refreshToken = await _preferences.getString(_kRefreshToken) ?? '';
|
final refreshToken = await _preferences.getString(_kRefreshToken) ?? '';
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import '../../config/app_config.dart';
|
|||||||
import '../models/content_category.dart';
|
import '../models/content_category.dart';
|
||||||
import '../models/drama.dart';
|
import '../models/drama.dart';
|
||||||
import '../models/home_feed.dart';
|
import '../models/home_feed.dart';
|
||||||
|
import '../models/page_result.dart';
|
||||||
|
import '../remote/category_api.dart';
|
||||||
import '../repositories/category_repository.dart';
|
import '../repositories/category_repository.dart';
|
||||||
|
|
||||||
/// 剧场页数据:服务端分类清单与发现 feed。
|
/// 剧场页数据:服务端分类清单与发现 feed。
|
||||||
@@ -14,13 +16,80 @@ class CategoryController extends ChangeNotifier {
|
|||||||
|
|
||||||
final CategoryRepository _repository;
|
final CategoryRepository _repository;
|
||||||
|
|
||||||
|
/// 生产环境注入。未注入时首页分类继续用本地筛选。
|
||||||
|
Future<PageResult<Drama>> Function(
|
||||||
|
String categoryId, {
|
||||||
|
int pageIndex,
|
||||||
|
int pageSize,
|
||||||
|
})? dramaPageLoader;
|
||||||
|
|
||||||
List<ContentCategory> categories = const [];
|
List<ContentCategory> categories = const [];
|
||||||
|
final Map<String, CategoryDramaSlot> _slots = {};
|
||||||
HomeFeed feed = const HomeFeed();
|
HomeFeed feed = const HomeFeed();
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
String? error;
|
String? error;
|
||||||
String? debugError;
|
String? debugError;
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
|
|
||||||
|
/// 某个分类自己的短剧分页,不和别的分类共用。
|
||||||
|
CategoryDramaSlot slotOf(String categoryId) {
|
||||||
|
return _slots.putIfAbsent(categoryId, CategoryDramaSlot.new);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 打开分类并加载第一页短剧。
|
||||||
|
Future<void> openCategory(String categoryId) async {
|
||||||
|
final loader = dramaPageLoader;
|
||||||
|
if (loader == null) return;
|
||||||
|
final slot = slotOf(categoryId);
|
||||||
|
slot.loading = true;
|
||||||
|
slot.loadingMore = false;
|
||||||
|
_notify();
|
||||||
|
try {
|
||||||
|
final page = await loader(
|
||||||
|
categoryId,
|
||||||
|
pageIndex: 1,
|
||||||
|
pageSize: CategoryApi.dramaPageSize,
|
||||||
|
);
|
||||||
|
slot.dramas = page.list;
|
||||||
|
slot.total = page.total;
|
||||||
|
slot.pageIndex = 1;
|
||||||
|
} catch (exception) {
|
||||||
|
if (kDebugMode) debugPrint('[category] $exception');
|
||||||
|
} finally {
|
||||||
|
slot.loading = false;
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 上拉加载这个分类的下一页。
|
||||||
|
Future<void> loadMore(String categoryId) async {
|
||||||
|
final loader = dramaPageLoader;
|
||||||
|
final slot = _slots[categoryId];
|
||||||
|
if (loader == null || slot == null) return;
|
||||||
|
if (slot.loading || slot.loadingMore || !slot.hasMore) return;
|
||||||
|
slot.loadingMore = true;
|
||||||
|
_notify();
|
||||||
|
try {
|
||||||
|
final page = await loader(
|
||||||
|
categoryId,
|
||||||
|
pageIndex: slot.pageIndex + 1,
|
||||||
|
pageSize: CategoryApi.dramaPageSize,
|
||||||
|
);
|
||||||
|
if (page.list.isEmpty) {
|
||||||
|
slot.total = slot.dramas.length;
|
||||||
|
} else {
|
||||||
|
slot.dramas = [...slot.dramas, ...page.list];
|
||||||
|
slot.total = page.total;
|
||||||
|
slot.pageIndex += 1;
|
||||||
|
}
|
||||||
|
} catch (exception) {
|
||||||
|
if (kDebugMode) debugPrint('[category] more $exception');
|
||||||
|
} finally {
|
||||||
|
slot.loadingMore = false;
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 分类九宫格点击后读取该分类的剧目;缺失分区返回空列表。
|
/// 分类九宫格点击后读取该分类的剧目;缺失分区返回空列表。
|
||||||
List<Drama> dramasOf(String categoryId) {
|
List<Drama> dramasOf(String categoryId) {
|
||||||
final code = 'category-$categoryId';
|
final code = 'category-$categoryId';
|
||||||
@@ -30,19 +99,23 @@ class CategoryController extends ChangeNotifier {
|
|||||||
return const [];
|
return const [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 加载分类与发现 feed;失败保留可重试错误态。
|
/// 首页只拉分类,再拉第一个分类的短剧。发现页聚合留到没有短剧分页时再取。
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
loading = true;
|
loading = true;
|
||||||
error = null;
|
error = null;
|
||||||
debugError = null;
|
debugError = null;
|
||||||
_notify();
|
_notify();
|
||||||
try {
|
try {
|
||||||
|
if (dramaPageLoader != null) {
|
||||||
|
categories = await _repository.fetchCategories();
|
||||||
|
} else {
|
||||||
final results = await Future.wait<Object>([
|
final results = await Future.wait<Object>([
|
||||||
_repository.fetchCategories(),
|
_repository.fetchCategories(),
|
||||||
_repository.fetchDiscoverFeed(),
|
_repository.fetchDiscoverFeed(),
|
||||||
]);
|
]);
|
||||||
categories = results[0] as List<ContentCategory>;
|
categories = results[0] as List<ContentCategory>;
|
||||||
feed = results[1] as HomeFeed;
|
feed = results[1] as HomeFeed;
|
||||||
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
error = 'categoriesError';
|
error = 'categoriesError';
|
||||||
debugError = exception.toString();
|
debugError = exception.toString();
|
||||||
@@ -53,6 +126,9 @@ class CategoryController extends ChangeNotifier {
|
|||||||
loading = false;
|
loading = false;
|
||||||
_notify();
|
_notify();
|
||||||
}
|
}
|
||||||
|
if (error == null && dramaPageLoader != null && categories.isNotEmpty) {
|
||||||
|
await openCategory(categories.first.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _notify() {
|
void _notify() {
|
||||||
@@ -65,3 +141,14 @@ class CategoryController extends ChangeNotifier {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 单个分类的短剧分页状态。
|
||||||
|
class CategoryDramaSlot {
|
||||||
|
List<Drama> dramas = const [];
|
||||||
|
int total = 0;
|
||||||
|
int pageIndex = 0;
|
||||||
|
bool loading = false;
|
||||||
|
bool loadingMore = false;
|
||||||
|
|
||||||
|
bool get hasMore => dramas.length < total;
|
||||||
|
}
|
||||||
@@ -197,7 +197,10 @@ class CommentController extends ChangeNotifier {
|
|||||||
_insertPublished(comment, replyTo);
|
_insertPublished(comment, replyTo);
|
||||||
return OperationResult.success(comment);
|
return OperationResult.success(comment);
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
return OperationResult.failure(_errorMessage(failure));
|
return OperationResult.failure(
|
||||||
|
_errorMessage(failure),
|
||||||
|
errorCode: failure is ApiException ? failure.code : null,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
submitting = false;
|
submitting = false;
|
||||||
_notify();
|
_notify();
|
||||||
@@ -217,7 +220,10 @@ class CommentController extends ChangeNotifier {
|
|||||||
return const OperationResult.success();
|
return const OperationResult.success();
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
_restoreComment(comment, location);
|
_restoreComment(comment, location);
|
||||||
return OperationResult.failure(_errorMessage(failure));
|
return OperationResult.failure(
|
||||||
|
_errorMessage(failure),
|
||||||
|
errorCode: failure is ApiException ? failure.code : null,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
_deletingCommentIds.remove(comment.id);
|
_deletingCommentIds.remove(comment.id);
|
||||||
_notify();
|
_notify();
|
||||||
@@ -253,7 +259,10 @@ class CommentController extends ChangeNotifier {
|
|||||||
return OperationResult.success(result);
|
return OperationResult.success(result);
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
_replaceComment(current);
|
_replaceComment(current);
|
||||||
return OperationResult.failure(_errorMessage(failure));
|
return OperationResult.failure(
|
||||||
|
_errorMessage(failure),
|
||||||
|
errorCode: failure is ApiException ? failure.code : null,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
_likingCommentIds.remove(comment.id);
|
_likingCommentIds.remove(comment.id);
|
||||||
_notify();
|
_notify();
|
||||||
@@ -277,7 +286,10 @@ class CommentController extends ChangeNotifier {
|
|||||||
);
|
);
|
||||||
return OperationResult.success(reportId);
|
return OperationResult.success(reportId);
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
return OperationResult.failure(_errorMessage(failure));
|
return OperationResult.failure(
|
||||||
|
_errorMessage(failure),
|
||||||
|
errorCode: failure is ApiException ? failure.code : null,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
/// 读取系统级设备标识,两端都不需要任何权限。
|
||||||
|
///
|
||||||
|
/// - Android:SSAID(`Settings.Secure.ANDROID_ID`),卸载重装不变;
|
||||||
|
/// - iOS:IDFV(`identifierForVendor`),卸载本 App 不变,同厂商应用全删才会变。
|
||||||
|
///
|
||||||
|
/// 两端都由原生侧提供,不引插件:项目 iOS 走 SPM,避免混入 CocoaPods。
|
||||||
|
/// 取不到(Web、测试环境、通道异常)时返回 null,由调用方回退到本地生成的 id。
|
||||||
|
class DeviceIdProvider {
|
||||||
|
static const MethodChannel _channel = MethodChannel(
|
||||||
|
'com.stormg.lumadrama/device',
|
||||||
|
);
|
||||||
|
|
||||||
|
Future<String?> systemDeviceId() async {
|
||||||
|
if (kIsWeb) return null;
|
||||||
|
try {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
final ssaid = await _channel.invokeMethod<String>('ssaid');
|
||||||
|
if (ssaid != null && ssaid.isNotEmpty) return 'a-$ssaid';
|
||||||
|
}
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
final idfv = await _channel.invokeMethod<String>('idfv');
|
||||||
|
if (idfv != null && idfv.isNotEmpty) return 'i-$idfv';
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// 原生通道不可用(widget 测试)时走本地兜底
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备所在区域(ISO-2),仅用于服务端 IP 解析失败时兜底注册国家。
|
||||||
|
/// Android 依次取网络运营商 / SIM 卡 / 系统语言的国家,iOS 取系统 region。
|
||||||
|
Future<String?> deviceRegion() async {
|
||||||
|
if (kIsWeb) return null;
|
||||||
|
try {
|
||||||
|
final region = await _channel.invokeMethod<String>('region');
|
||||||
|
final value = region?.trim().toUpperCase() ?? '';
|
||||||
|
if (value.length == 2) return value;
|
||||||
|
} catch (_) {
|
||||||
|
// 原生通道不可用(widget 测试)时返回 null,由服务端兜底
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
import '../models/drama.dart';
|
import '../models/drama.dart';
|
||||||
|
import '../remote/api_client.dart';
|
||||||
import '../repositories/favorite_repository.dart';
|
import '../repositories/favorite_repository.dart';
|
||||||
|
|
||||||
/// 收藏状态:**以服务端为准**。
|
/// 收藏状态:**以服务端为准**。
|
||||||
@@ -17,6 +18,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
final FavoriteRepository _repository;
|
final FavoriteRepository _repository;
|
||||||
final int pageSize;
|
final int pageSize;
|
||||||
final Set<String> _saved = {};
|
final Set<String> _saved = {};
|
||||||
|
final Map<String, int> _favoriteCounts = {};
|
||||||
List<Drama> cards = const [];
|
List<Drama> cards = const [];
|
||||||
int total = 0;
|
int total = 0;
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
@@ -24,6 +26,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
bool hasMore = false;
|
bool hasMore = false;
|
||||||
String? error;
|
String? error;
|
||||||
String? loadMoreError;
|
String? loadMoreError;
|
||||||
|
int? lastErrorCode;
|
||||||
int _pageIndex = 0;
|
int _pageIndex = 0;
|
||||||
int _requestSeq = 0;
|
int _requestSeq = 0;
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
@@ -32,6 +35,53 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
|
|
||||||
bool isSaved(String dramaId) => _saved.contains(dramaId);
|
bool isSaved(String dramaId) => _saved.contains(dramaId);
|
||||||
|
|
||||||
|
/// 当前剧收藏数;包含本地 toggle 增量。
|
||||||
|
int? favoriteCount(String dramaId) => _favoriteCounts[dramaId];
|
||||||
|
|
||||||
|
/// 首次展示时缓存卡片基数;之后统一由本控制器维护,避免页面各存一份。
|
||||||
|
int? favoriteCountFor(Drama drama) {
|
||||||
|
final current = _favoriteCounts[drama.id];
|
||||||
|
if (current != null) return current;
|
||||||
|
final fallback = drama.favoriteCount;
|
||||||
|
if (fallback == null) return null;
|
||||||
|
final normalized = fallback < 0 ? 0 : fallback;
|
||||||
|
_favoriteCounts[drama.id] = normalized;
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 用 stats/detail 的服务端快照校准唯一状态和计数。
|
||||||
|
void applyServerState(
|
||||||
|
String dramaId, {
|
||||||
|
required bool saved,
|
||||||
|
int? favoriteCount,
|
||||||
|
}) {
|
||||||
|
var changed = _saved.contains(dramaId) != saved;
|
||||||
|
if (saved) {
|
||||||
|
_saved.add(dramaId);
|
||||||
|
} else {
|
||||||
|
_saved.remove(dramaId);
|
||||||
|
}
|
||||||
|
if (favoriteCount != null) {
|
||||||
|
final normalized = favoriteCount < 0 ? 0 : favoriteCount;
|
||||||
|
changed = changed || _favoriteCounts[dramaId] != normalized;
|
||||||
|
_favoriteCounts[dramaId] = normalized;
|
||||||
|
}
|
||||||
|
if (changed) notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 详情等只有计数、没有当前收藏状态的接口使用。
|
||||||
|
void applyServerCount(
|
||||||
|
String dramaId,
|
||||||
|
int? favoriteCount, {
|
||||||
|
bool notify = true,
|
||||||
|
}) {
|
||||||
|
if (favoriteCount == null) return;
|
||||||
|
final normalized = favoriteCount < 0 ? 0 : favoriteCount;
|
||||||
|
if (_favoriteCounts[dramaId] == normalized) return;
|
||||||
|
_favoriteCounts[dramaId] = normalized;
|
||||||
|
if (notify) this.notify();
|
||||||
|
}
|
||||||
|
|
||||||
void notify() {
|
void notify() {
|
||||||
if (!_disposed) notifyListeners();
|
if (!_disposed) notifyListeners();
|
||||||
}
|
}
|
||||||
@@ -43,6 +93,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
loadingMore = false;
|
loadingMore = false;
|
||||||
error = null;
|
error = null;
|
||||||
loadMoreError = null;
|
loadMoreError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
notify();
|
notify();
|
||||||
try {
|
try {
|
||||||
final page = await _repository.page(pageIndex: 1, pageSize: pageSize);
|
final page = await _repository.page(pageIndex: 1, pageSize: pageSize);
|
||||||
@@ -52,12 +103,14 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
_saved
|
_saved
|
||||||
..clear()
|
..clear()
|
||||||
..addAll(list.map((drama) => drama.id));
|
..addAll(list.map((drama) => drama.id));
|
||||||
|
_rememberCardCounts(list);
|
||||||
total = page.total;
|
total = page.total;
|
||||||
_pageIndex = 1;
|
_pageIndex = 1;
|
||||||
hasMore = page.list.isNotEmpty && cards.length < total;
|
hasMore = page.list.isNotEmpty && cards.length < total;
|
||||||
} catch (_) {
|
} catch (failure) {
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
error = 'favoritesError';
|
error = 'favoritesError';
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
@@ -73,6 +126,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
final request = ++_requestSeq;
|
final request = ++_requestSeq;
|
||||||
loadingMore = true;
|
loadingMore = true;
|
||||||
loadMoreError = null;
|
loadMoreError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
notify();
|
notify();
|
||||||
try {
|
try {
|
||||||
final page = await _repository.page(
|
final page = await _repository.page(
|
||||||
@@ -86,12 +140,14 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
).where((drama) => known.add(drama.id)).toList(growable: false);
|
).where((drama) => known.add(drama.id)).toList(growable: false);
|
||||||
cards = [...cards, ...appended];
|
cards = [...cards, ...appended];
|
||||||
_saved.addAll(appended.map((drama) => drama.id));
|
_saved.addAll(appended.map((drama) => drama.id));
|
||||||
|
_rememberCardCounts(appended);
|
||||||
total = page.total;
|
total = page.total;
|
||||||
_pageIndex += 1;
|
_pageIndex += 1;
|
||||||
hasMore = page.list.isNotEmpty && cards.length < total;
|
hasMore = page.list.isNotEmpty && cards.length < total;
|
||||||
} catch (_) {
|
} catch (failure) {
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
loadMoreError = 'favoritesError';
|
loadMoreError = 'favoritesError';
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
@@ -101,18 +157,23 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 未登录时不要调用(服务端要求登录态)。
|
/// 每次切换都以接口状态为准;匿名请求由设备号归属。
|
||||||
///
|
///
|
||||||
/// [card] 是当前剧的卡片(播放页/详情页手上就有):收藏成功时直接放进列表,
|
/// [card] 是当前剧的卡片(播放页/详情页手上就有):收藏成功时直接放进列表,
|
||||||
/// 这样"收藏完打开我的收藏"能立刻看到,不必等下一次整表刷新。
|
/// 这样"收藏完打开我的收藏"能立刻看到,不必等下一次整表刷新。
|
||||||
Future<bool> toggle(String dramaId, {Drama? card}) async {
|
Future<bool> toggle(String dramaId, {Drama? card}) async {
|
||||||
|
lastErrorCode = null;
|
||||||
final wasSaved = _saved.contains(dramaId);
|
final wasSaved = _saved.contains(dramaId);
|
||||||
|
final previousCount = card == null
|
||||||
|
? favoriteCount(dramaId)
|
||||||
|
: favoriteCountFor(card);
|
||||||
final previousCards = cards;
|
final previousCards = cards;
|
||||||
final previousTotal = total;
|
final previousTotal = total;
|
||||||
final previousHasMore = hasMore;
|
final previousHasMore = hasMore;
|
||||||
// 乐观更新
|
// 乐观更新
|
||||||
if (wasSaved) {
|
if (wasSaved) {
|
||||||
_saved.remove(dramaId);
|
_saved.remove(dramaId);
|
||||||
|
_stepCount(dramaId, -1);
|
||||||
if (cards.any((drama) => drama.id == dramaId)) {
|
if (cards.any((drama) => drama.id == dramaId)) {
|
||||||
cards = cards.where((drama) => drama.id != dramaId).toList();
|
cards = cards.where((drama) => drama.id != dramaId).toList();
|
||||||
total = total > 0 ? total - 1 : 0;
|
total = total > 0 ? total - 1 : 0;
|
||||||
@@ -120,6 +181,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_saved.add(dramaId);
|
_saved.add(dramaId);
|
||||||
|
_stepCount(dramaId, 1);
|
||||||
}
|
}
|
||||||
notify();
|
notify();
|
||||||
try {
|
try {
|
||||||
@@ -128,6 +190,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
if (saved) {
|
if (saved) {
|
||||||
_saved.add(dramaId);
|
_saved.add(dramaId);
|
||||||
if (wasSaved) {
|
if (wasSaved) {
|
||||||
|
_restoreCount(dramaId, previousCount);
|
||||||
cards = previousCards;
|
cards = previousCards;
|
||||||
total = previousTotal;
|
total = previousTotal;
|
||||||
hasMore = previousHasMore;
|
hasMore = previousHasMore;
|
||||||
@@ -138,6 +201,9 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_saved.remove(dramaId);
|
_saved.remove(dramaId);
|
||||||
|
if (!wasSaved) {
|
||||||
|
_restoreCount(dramaId, previousCount);
|
||||||
|
}
|
||||||
if (cards.any((drama) => drama.id == dramaId)) {
|
if (cards.any((drama) => drama.id == dramaId)) {
|
||||||
cards = cards.where((drama) => drama.id != dramaId).toList();
|
cards = cards.where((drama) => drama.id != dramaId).toList();
|
||||||
total = total > 0 ? total - 1 : 0;
|
total = total > 0 ? total - 1 : 0;
|
||||||
@@ -146,7 +212,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
notify();
|
notify();
|
||||||
return true;
|
return true;
|
||||||
} catch (_) {
|
} catch (failure) {
|
||||||
// 回滚
|
// 回滚
|
||||||
cards = previousCards;
|
cards = previousCards;
|
||||||
total = previousTotal;
|
total = previousTotal;
|
||||||
@@ -156,6 +222,46 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
_saved.remove(dramaId);
|
_saved.remove(dramaId);
|
||||||
}
|
}
|
||||||
|
_restoreCount(dramaId, previousCount);
|
||||||
|
notify();
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 一次取消多部收藏。失败时整批回滚。
|
||||||
|
Future<bool> removeMany(List<String> dramaIds) async {
|
||||||
|
final ids = dramaIds.toSet();
|
||||||
|
if (ids.isEmpty) return true;
|
||||||
|
final previousCards = cards;
|
||||||
|
final previousTotal = total;
|
||||||
|
final previousHasMore = hasMore;
|
||||||
|
final removed = cards.where((drama) => ids.contains(drama.id)).toList();
|
||||||
|
if (removed.isEmpty) return true;
|
||||||
|
final previousCounts = {
|
||||||
|
for (final drama in removed) drama.id: _favoriteCounts[drama.id],
|
||||||
|
};
|
||||||
|
cards = cards.where((drama) => !ids.contains(drama.id)).toList();
|
||||||
|
for (final id in ids) {
|
||||||
|
_saved.remove(id);
|
||||||
|
_stepCount(id, -1);
|
||||||
|
}
|
||||||
|
total = total > removed.length ? total - removed.length : 0;
|
||||||
|
hasMore = cards.length < total;
|
||||||
|
notify();
|
||||||
|
try {
|
||||||
|
await _repository.removeMany(dramaIds);
|
||||||
|
return true;
|
||||||
|
} catch (_) {
|
||||||
|
cards = previousCards;
|
||||||
|
total = previousTotal;
|
||||||
|
hasMore = previousHasMore;
|
||||||
|
for (final drama in removed) {
|
||||||
|
_saved.add(drama.id);
|
||||||
|
}
|
||||||
|
for (final entry in previousCounts.entries) {
|
||||||
|
_restoreCount(entry.key, entry.value);
|
||||||
|
}
|
||||||
notify();
|
notify();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -166,7 +272,9 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
final index = cards.indexWhere((drama) => drama.id == dramaId);
|
final index = cards.indexWhere((drama) => drama.id == dramaId);
|
||||||
if (index < 0) return true;
|
if (index < 0) return true;
|
||||||
final removed = cards[index];
|
final removed = cards[index];
|
||||||
|
final previousCount = _favoriteCounts[dramaId];
|
||||||
_saved.remove(dramaId);
|
_saved.remove(dramaId);
|
||||||
|
_stepCount(dramaId, -1);
|
||||||
final next = [...cards]..removeAt(index);
|
final next = [...cards]..removeAt(index);
|
||||||
cards = next;
|
cards = next;
|
||||||
total = total > 0 ? total - 1 : 0;
|
total = total > 0 ? total - 1 : 0;
|
||||||
@@ -183,6 +291,7 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
);
|
);
|
||||||
cards = restored;
|
cards = restored;
|
||||||
_saved.add(dramaId);
|
_saved.add(dramaId);
|
||||||
|
_restoreCount(dramaId, previousCount);
|
||||||
total += 1;
|
total += 1;
|
||||||
hasMore = cards.length < total;
|
hasMore = cards.length < total;
|
||||||
notify();
|
notify();
|
||||||
@@ -213,6 +322,30 @@ class FavoriteController extends ChangeNotifier {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _rememberCardCounts(List<Drama> dramas) {
|
||||||
|
for (final drama in dramas) {
|
||||||
|
final count = drama.favoriteCount;
|
||||||
|
if (count != null && !_favoriteCounts.containsKey(drama.id)) {
|
||||||
|
_favoriteCounts[drama.id] = count < 0 ? 0 : count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _stepCount(String dramaId, int delta) {
|
||||||
|
final current = _favoriteCounts[dramaId];
|
||||||
|
if (current == null) return;
|
||||||
|
final next = current + delta;
|
||||||
|
_favoriteCounts[dramaId] = next < 0 ? 0 : next;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _restoreCount(String dramaId, int? count) {
|
||||||
|
if (count == null) {
|
||||||
|
_favoriteCounts.remove(dramaId);
|
||||||
|
} else {
|
||||||
|
_favoriteCounts[dramaId] = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class HomeFeedController extends ChangeNotifier {
|
|||||||
String? get cursor => _state(_channel).cursor;
|
String? get cursor => _state(_channel).cursor;
|
||||||
bool get hasMore => _state(_channel).hasMore;
|
bool get hasMore => _state(_channel).hasMore;
|
||||||
bool get loaded => _state(_channel).loaded;
|
bool get loaded => _state(_channel).loaded;
|
||||||
|
bool get isLoading => _state(_channel).loading;
|
||||||
bool get loadingMore => _state(_channel).loadingMore;
|
bool get loadingMore => _state(_channel).loadingMore;
|
||||||
bool get loadingFirstPage => !loaded && _state(_channel).loading;
|
bool get loadingFirstPage => !loaded && _state(_channel).loading;
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,24 @@ class InteractionController extends ChangeNotifier {
|
|||||||
/// 该集服务端最新点赞数。
|
/// 该集服务端最新点赞数。
|
||||||
int? episodeLikeCount(String episodeId) => _episodeLikeCounts[episodeId];
|
int? episodeLikeCount(String episodeId) => _episodeLikeCounts[episodeId];
|
||||||
|
|
||||||
|
/// 用轻量统计快照校准当前用户的分集点赞状态与计数。
|
||||||
|
void applyEpisodeStats(
|
||||||
|
String episodeId, {
|
||||||
|
required bool liked,
|
||||||
|
required int likeCount,
|
||||||
|
}) {
|
||||||
|
final changed =
|
||||||
|
_likedEpisodeIds.contains(episodeId) != liked ||
|
||||||
|
_episodeLikeCounts[episodeId] != likeCount;
|
||||||
|
if (liked) {
|
||||||
|
_likedEpisodeIds.add(episodeId);
|
||||||
|
} else {
|
||||||
|
_likedEpisodeIds.remove(episodeId);
|
||||||
|
}
|
||||||
|
_episodeLikeCounts[episodeId] = likeCount;
|
||||||
|
if (changed) _notify();
|
||||||
|
}
|
||||||
|
|
||||||
/// 乐观切换剧集点赞,失败时回滚并以服务端返回状态校准。
|
/// 乐观切换剧集点赞,失败时回滚并以服务端返回状态校准。
|
||||||
Future<OperationResult<LikeToggleResult>> toggleDramaLike(String dramaId) =>
|
Future<OperationResult<LikeToggleResult>> toggleDramaLike(String dramaId) =>
|
||||||
_toggleLike(
|
_toggleLike(
|
||||||
@@ -97,7 +115,10 @@ class InteractionController extends ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
likedIds.remove(id);
|
likedIds.remove(id);
|
||||||
}
|
}
|
||||||
return OperationResult.failure(_errorMessage(failure));
|
return OperationResult.failure(
|
||||||
|
_errorMessage(failure),
|
||||||
|
errorCode: failure is ApiException ? failure.code : null,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
busyIds.remove(id);
|
busyIds.remove(id);
|
||||||
_notify();
|
_notify();
|
||||||
@@ -121,7 +142,10 @@ class InteractionController extends ChangeNotifier {
|
|||||||
);
|
);
|
||||||
return OperationResult.success(reportId);
|
return OperationResult.success(reportId);
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
return OperationResult.failure(_errorMessage(failure));
|
return OperationResult.failure(
|
||||||
|
_errorMessage(failure),
|
||||||
|
errorCode: failure is ApiException ? failure.code : null,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,223 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
part of 'playback_session.dart';
|
||||||
|
|
||||||
|
/// 当前集加上一集、下一集,切集时最多三个解码器。
|
||||||
|
const int maxLivePlayers = 3;
|
||||||
|
|
||||||
|
/// 另一条播放路由必须等当前路由释放完全部原生播放器。
|
||||||
|
class PlaybackCoordinator {
|
||||||
|
PlaybackSession? _owner;
|
||||||
|
Future<void> _handoff = Future<void>.value();
|
||||||
|
|
||||||
|
Future<bool> _acquire(PlaybackSession session, bool Function() valid) {
|
||||||
|
final result = _handoff.then((_) async {
|
||||||
|
if (!valid()) return false;
|
||||||
|
final previous = _owner;
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[player-coordinator] phase=acquire '
|
||||||
|
'session=${identityHashCode(session)} owner=${session.owner.name} '
|
||||||
|
'previous=${previous == null ? '-' : identityHashCode(previous)} '
|
||||||
|
'previousOwner=${previous?.owner.name ?? '-'} '
|
||||||
|
'previousLive=${previous?.livePlayerCount ?? 0} '
|
||||||
|
'same=${identical(previous, session)}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (_owner != session) {
|
||||||
|
if (previous != null && previous.owner != session.owner) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[player-owner] phase=reject-coordinator-handoff '
|
||||||
|
'owner=${session.owner.name} '
|
||||||
|
'activeOwner=${previous.owner.name}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
await previous?._releasePlayers();
|
||||||
|
if (previous != null && previous.livePlayerCount != 0) return false;
|
||||||
|
_owner = null;
|
||||||
|
if (!valid()) return false;
|
||||||
|
_owner = session;
|
||||||
|
}
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[player-coordinator] phase=acquired '
|
||||||
|
'session=${identityHashCode(session)} live=${session.livePlayerCount}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
_handoff = result.then<void>((_) {});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _forget(PlaybackSession session) {
|
||||||
|
if (_owner == session && session.livePlayerCount == 0) _owner = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_PlayerSlot? _usableWarm(
|
||||||
|
PlaybackSession session,
|
||||||
|
_PlayerSlot? slot,
|
||||||
|
int index,
|
||||||
|
) {
|
||||||
|
if (slot == null || slot.index != index || slot.failure != null) return null;
|
||||||
|
if (session.isLocked) return null;
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 滑走的一集若仍是相邻集,就留着最后一帧,其余槽位释放。
|
||||||
|
Future<void> _parkNeighbors(
|
||||||
|
PlaybackSession session,
|
||||||
|
_PlayerSlot? old,
|
||||||
|
_PlayerSlot? warmNext,
|
||||||
|
_PlayerSlot? warmPrevious,
|
||||||
|
) async {
|
||||||
|
await _placeNeighbor(session, old, roleHint: 'old-current');
|
||||||
|
await _placeNeighbor(session, warmNext, roleHint: 'next');
|
||||||
|
await _placeNeighbor(session, warmPrevious, roleHint: 'previous');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _placeNeighbor(
|
||||||
|
PlaybackSession session,
|
||||||
|
_PlayerSlot? slot, {
|
||||||
|
required String roleHint,
|
||||||
|
}) async {
|
||||||
|
if (slot == null || slot == session._active || slot.retiring) return;
|
||||||
|
if (slot.owner != session.owner) {
|
||||||
|
session._logOwnerRejection('park', slot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (session._next == null && slot.index == session._nextIndex) {
|
||||||
|
session._next = slot;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (session._previous == null && slot.index == session._previousIndex) {
|
||||||
|
session._previous = slot;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await session._retire(slot, trigger: 'park-neighbor', roleHint: roleHint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 当前集已经出画后,按手势方向静默准备上一集和下一集。
|
||||||
|
void _warmNeighbors(PlaybackSession session, {bool preferredNext = true}) {
|
||||||
|
final request = session._generation;
|
||||||
|
final nextTask = _warmOne(session, request, session._nextIndex, next: true);
|
||||||
|
final previousTask = _warmOne(
|
||||||
|
session,
|
||||||
|
request,
|
||||||
|
session._previousIndex,
|
||||||
|
next: false,
|
||||||
|
);
|
||||||
|
session._preloadTask = Future.wait(
|
||||||
|
preferredNext ? [nextTask, previousTask] : [previousTask, nextTask],
|
||||||
|
).then<void>((_) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _warmOne(
|
||||||
|
PlaybackSession session,
|
||||||
|
int request,
|
||||||
|
int? index, {
|
||||||
|
required bool next,
|
||||||
|
}) async {
|
||||||
|
final candidate = await _allocateNeighbor(
|
||||||
|
session,
|
||||||
|
request,
|
||||||
|
index,
|
||||||
|
next: next,
|
||||||
|
);
|
||||||
|
if (candidate == null) return;
|
||||||
|
await candidate.ready;
|
||||||
|
if (session._closed || !_stillHeld(session, candidate, next: next)) return;
|
||||||
|
if (candidate.failure == null) {
|
||||||
|
session._notify();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await session._enqueue(() async {
|
||||||
|
if (!_stillHeld(session, candidate, next: next)) return;
|
||||||
|
_clearNeighbor(session, next: next);
|
||||||
|
await session._retire(
|
||||||
|
candidate,
|
||||||
|
trigger: 'warm-failure',
|
||||||
|
roleHint: next ? 'next' : 'previous',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<_PlayerSlot?> _allocateNeighbor(
|
||||||
|
PlaybackSession session,
|
||||||
|
int request,
|
||||||
|
int? index, {
|
||||||
|
required bool next,
|
||||||
|
}) async {
|
||||||
|
_PlayerSlot? created;
|
||||||
|
await session._enqueue(() async {
|
||||||
|
if (session._closed || request != session._generation) return;
|
||||||
|
final allowed = _neighborAllowed(session, index);
|
||||||
|
final current = next ? session._next : session._previous;
|
||||||
|
if (!allowed || current?.index != index) {
|
||||||
|
_clearNeighbor(session, next: next);
|
||||||
|
await session._retire(
|
||||||
|
current,
|
||||||
|
trigger: 'warm-slot-invalid',
|
||||||
|
roleHint: next ? 'next' : 'previous',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!_canAllocate(session, request, allowed: allowed, next: next)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
created = session._create(index!);
|
||||||
|
} on StateError catch (error) {
|
||||||
|
if (kDebugMode) debugPrint('相邻集预热跳过: $error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (next) {
|
||||||
|
session._next = created;
|
||||||
|
} else {
|
||||||
|
session._previous = created;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _neighborAllowed(PlaybackSession session, int? index) {
|
||||||
|
return index != null &&
|
||||||
|
index >= 0 &&
|
||||||
|
index < session.episodes.length &&
|
||||||
|
index != session._currentIndex &&
|
||||||
|
session.canPlay(session.episodes[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _canAllocate(
|
||||||
|
PlaybackSession session,
|
||||||
|
int request, {
|
||||||
|
required bool allowed,
|
||||||
|
required bool next,
|
||||||
|
}) {
|
||||||
|
final held = next ? session._next : session._previous;
|
||||||
|
return session._visible &&
|
||||||
|
!session._overlayOpen &&
|
||||||
|
request == session._generation &&
|
||||||
|
session._active?.prepared == true &&
|
||||||
|
allowed &&
|
||||||
|
held == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _stillHeld(
|
||||||
|
PlaybackSession session,
|
||||||
|
_PlayerSlot slot, {
|
||||||
|
required bool next,
|
||||||
|
}) {
|
||||||
|
return (next ? session._next : session._previous) == slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _clearNeighbor(PlaybackSession session, {required bool next}) {
|
||||||
|
if (next) {
|
||||||
|
session._next = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session._previous = null;
|
||||||
|
}
|
||||||
@@ -5,42 +5,21 @@ import 'dart:async';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import '../models/drama.dart';
|
import '../models/drama.dart';
|
||||||
import '../models/player_port.dart';
|
import '../models/player_port.dart';
|
||||||
|
import 'video_player_port.dart';
|
||||||
|
|
||||||
|
part 'playback_neighbors.dart';
|
||||||
|
part 'playback_session_controls.dart';
|
||||||
|
|
||||||
|
/// 新纹理第一帧常是黑的,旧画面只盖住这一小段。
|
||||||
|
const Duration _qualityHandoffHold = Duration(milliseconds: 200);
|
||||||
|
|
||||||
typedef PlayerFactory = PlayerPort Function(Episode episode);
|
typedef PlayerFactory = PlayerPort Function(Episode episode);
|
||||||
typedef PlayerPreparation =
|
typedef PlayerPreparation =
|
||||||
Future<void> Function(Episode episode, PlayerPort player);
|
Future<void> Function(Episode episode, PlayerPort player);
|
||||||
|
|
||||||
/// Shared by routes: the previous session releases all native players before
|
enum PlaybackSessionOwner { home, player }
|
||||||
/// another session allocates. The app therefore has at most two, not two per page.
|
|
||||||
class PlaybackCoordinator {
|
|
||||||
PlaybackSession? _owner;
|
|
||||||
Future<void> _handoff = Future<void>.value();
|
|
||||||
|
|
||||||
Future<bool> _acquire(PlaybackSession session, bool Function() valid) {
|
/// Owns current plus previous/next frames; allocation stays serialized.
|
||||||
final result = _handoff.then((_) async {
|
|
||||||
if (!valid()) return false;
|
|
||||||
if (_owner != session) {
|
|
||||||
final previous = _owner;
|
|
||||||
await previous?._releasePlayers();
|
|
||||||
// A failed native disposal cannot be treated as a free decoder slot.
|
|
||||||
if (previous != null && previous.livePlayerCount != 0) return false;
|
|
||||||
_owner = null;
|
|
||||||
if (!valid()) return false;
|
|
||||||
_owner = session;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
_handoff = result.then<void>((_) {});
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _forget(PlaybackSession session) {
|
|
||||||
if (_owner == session && session.livePlayerCount == 0) _owner = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Owns current + one prepared successor. All allocation, playback and disposal
|
|
||||||
/// operations are serialized; initialization can run while current plays.
|
|
||||||
class PlaybackSession extends ChangeNotifier {
|
class PlaybackSession extends ChangeNotifier {
|
||||||
PlaybackSession({
|
PlaybackSession({
|
||||||
required this.episodes,
|
required this.episodes,
|
||||||
@@ -50,6 +29,8 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
this.activate,
|
this.activate,
|
||||||
PlaybackCoordinator? coordinator,
|
PlaybackCoordinator? coordinator,
|
||||||
this.waitForFrame,
|
this.waitForFrame,
|
||||||
|
this.owner = PlaybackSessionOwner.player,
|
||||||
|
this.dramaIdAt,
|
||||||
}) : _coordinator = coordinator ?? PlaybackCoordinator();
|
}) : _coordinator = coordinator ?? PlaybackCoordinator();
|
||||||
|
|
||||||
final List<Episode> episodes;
|
final List<Episode> episodes;
|
||||||
@@ -62,15 +43,20 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
/// Runs only when a slot becomes current (e.g. progress listeners).
|
/// Runs only when a slot becomes current (e.g. progress listeners).
|
||||||
final PlayerPreparation? activate;
|
final PlayerPreparation? activate;
|
||||||
final Future<void> Function()? waitForFrame;
|
final Future<void> Function()? waitForFrame;
|
||||||
|
final PlaybackSessionOwner owner;
|
||||||
|
final String? Function(int index)? dramaIdAt;
|
||||||
final PlaybackCoordinator _coordinator;
|
final PlaybackCoordinator _coordinator;
|
||||||
final Set<_PlayerSlot> _live = {};
|
final Set<_PlayerSlot> _live = {};
|
||||||
_PlayerSlot? _active;
|
_PlayerSlot? _active;
|
||||||
_PlayerSlot? _next;
|
_PlayerSlot? _next;
|
||||||
|
_PlayerSlot? _previous;
|
||||||
|
_PlayerSlot? _handoff;
|
||||||
Future<void> _operations = Future<void>.value();
|
Future<void> _operations = Future<void>.value();
|
||||||
Future<void> _preloadTask = Future<void>.value();
|
Future<void> _preloadTask = Future<void>.value();
|
||||||
int _generation = 0;
|
int _generation = 0;
|
||||||
int _currentIndex = 0;
|
int _currentIndex = 0;
|
||||||
int? _nextIndex;
|
int? _nextIndex;
|
||||||
|
int? _previousIndex;
|
||||||
bool _selected = false;
|
bool _selected = false;
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
bool _closed = false;
|
bool _closed = false;
|
||||||
@@ -98,9 +84,18 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
bool get canAutoAdvance => _mayPlay && !_loading && active != null;
|
bool get canAutoAdvance => _mayPlay && !_loading && active != null;
|
||||||
bool get isLocked => !canPlay(currentEpisode);
|
bool get isLocked => !canPlay(currentEpisode);
|
||||||
String? get error => _error;
|
String? get error => _error;
|
||||||
|
bool get debugAppResumed => _appResumed;
|
||||||
|
bool get debugRouteVisible => _routeVisible;
|
||||||
|
bool get debugOverlayOpen => _overlayOpen;
|
||||||
|
bool get debugVisible => _visible;
|
||||||
|
bool get debugMayPlay => _mayPlay;
|
||||||
// Includes initialization and asynchronous disposal, until native release ends.
|
// Includes initialization and asynchronous disposal, until native release ends.
|
||||||
int get livePlayerCount => _live.length;
|
int get livePlayerCount => _live.length;
|
||||||
|
bool get activeSlotActivated => _active?.activated ?? false;
|
||||||
|
bool get activeSlotPlaying => _active?.playing ?? false;
|
||||||
int? get preloadedIndex => _next?.prepared == true ? _next?.index : null;
|
int? get preloadedIndex => _next?.prepared == true ? _next?.index : null;
|
||||||
|
int? get previousPreloadedIndex =>
|
||||||
|
_previous?.prepared == true ? _previous?.index : null;
|
||||||
Future<void> get playbackSettled => _operations;
|
Future<void> get playbackSettled => _operations;
|
||||||
Future<void> get preloadSettled => _preloadTask;
|
Future<void> get preloadSettled => _preloadTask;
|
||||||
|
|
||||||
@@ -115,7 +110,7 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
/// during a swipe without starting audio or registering history listeners.
|
/// during a swipe without starting audio or registering history listeners.
|
||||||
PlayerPort? preparedPlayerAt(int index) {
|
PlayerPort? preparedPlayerAt(int index) {
|
||||||
if (_closed) return null;
|
if (_closed) return null;
|
||||||
for (final slot in [_active, _next]) {
|
for (final slot in [_active, _next, _previous]) {
|
||||||
if (slot == null ||
|
if (slot == null ||
|
||||||
slot.retiring ||
|
slot.retiring ||
|
||||||
slot.index != index ||
|
slot.index != index ||
|
||||||
@@ -128,24 +123,40 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 队列重排后把当前仍在播放的 slot 映射到新索引,不重新创建播放器。
|
/// 队列重排后把当前仍在播放的 slot 映射到新索引,不重新创建播放器。
|
||||||
void remapCurrentIndex(int index, {int? preloadIndex}) {
|
void remapCurrentIndex(int index, {int? preloadIndex, int? previousIndex}) {
|
||||||
if (_closed || index < 0 || index >= episodes.length) return;
|
if (_closed || index < 0 || index >= episodes.length) return;
|
||||||
final activeSlot = _active;
|
final activeSlot = _active;
|
||||||
if (activeSlot == null || activeSlot.index != _currentIndex) {
|
if (activeSlot == null || activeSlot.index != _currentIndex) {
|
||||||
_currentIndex = index;
|
_currentIndex = index;
|
||||||
_nextIndex = preloadIndex;
|
_rememberNeighbors(preloadIndex, previousIndex);
|
||||||
_notify();
|
_notify();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_generation++;
|
_generation++;
|
||||||
activeSlot.index = index;
|
activeSlot.index = index;
|
||||||
_currentIndex = index;
|
_currentIndex = index;
|
||||||
_nextIndex = preloadIndex;
|
_rememberNeighbors(preloadIndex, previousIndex);
|
||||||
final staleNext = _next;
|
final staleNext = _next;
|
||||||
|
final stalePrevious = _previous;
|
||||||
_next = null;
|
_next = null;
|
||||||
|
_previous = null;
|
||||||
_notify();
|
_notify();
|
||||||
unawaited(_enqueue(() async => _retire(staleNext)));
|
unawaited(
|
||||||
if (_visible && !_overlayOpen) _schedulePreload();
|
_enqueue(() async {
|
||||||
|
await _retire(staleNext, trigger: 'remap-stale-next', roleHint: 'next');
|
||||||
|
await _retire(
|
||||||
|
stalePrevious,
|
||||||
|
trigger: 'remap-stale-previous',
|
||||||
|
roleHint: 'previous',
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (_visible && !_overlayOpen) _warmNeighbors(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _rememberNeighbors(int? preloadIndex, int? previousIndex) {
|
||||||
|
_nextIndex = preloadIndex;
|
||||||
|
_previousIndex = previousIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _enqueue(Future<void> Function() operation) {
|
Future<void> _enqueue(Future<void> Function() operation) {
|
||||||
@@ -162,8 +173,15 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_PlayerSlot _create(int index) {
|
_PlayerSlot _create(int index) {
|
||||||
if (_live.length >= 2) throw StateError('Playback resource limit reached');
|
if (_live.length >= maxLivePlayers) {
|
||||||
final slot = _PlayerSlot(index, factory(episodes[index]));
|
throw StateError('Playback resource limit reached');
|
||||||
|
}
|
||||||
|
final slot = _PlayerSlot(
|
||||||
|
index,
|
||||||
|
factory(episodes[index]),
|
||||||
|
owner: owner,
|
||||||
|
dramaId: dramaIdAt?.call(index),
|
||||||
|
);
|
||||||
_live.add(slot);
|
_live.add(slot);
|
||||||
slot.ready = () async {
|
slot.ready = () async {
|
||||||
try {
|
try {
|
||||||
@@ -181,12 +199,33 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _retire(_PlayerSlot? slot) async {
|
Future<void> _retire(
|
||||||
if (slot == null || !_live.contains(slot)) return;
|
_PlayerSlot? slot, {
|
||||||
|
required String trigger,
|
||||||
|
String? roleHint,
|
||||||
|
}) async {
|
||||||
|
if (slot == null) return;
|
||||||
|
if (slot.owner != owner) {
|
||||||
|
_logOwnerRejection('retire', slot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_live.contains(slot)) return;
|
||||||
|
final role = _slotRole(slot, roleHint: roleHint);
|
||||||
|
final video = slot.player is VideoPlayerPort
|
||||||
|
? slot.player as VideoPlayerPort
|
||||||
|
: null;
|
||||||
|
final value = video?.controller.value;
|
||||||
|
final slotPlaying = slot.playing;
|
||||||
slot.retiring = true;
|
slot.retiring = true;
|
||||||
final cleared = _active == slot || _next == slot;
|
final cleared =
|
||||||
|
_active == slot ||
|
||||||
|
_next == slot ||
|
||||||
|
_previous == slot ||
|
||||||
|
_handoff == slot;
|
||||||
if (_active == slot) _active = null;
|
if (_active == slot) _active = null;
|
||||||
if (_next == slot) _next = null;
|
if (_next == slot) _next = null;
|
||||||
|
if (_previous == slot) _previous = null;
|
||||||
|
if (_handoff == slot) _handoff = null;
|
||||||
if (cleared) _notify();
|
if (cleared) _notify();
|
||||||
await waitForFrame?.call();
|
await waitForFrame?.call();
|
||||||
await slot.ready;
|
await slot.ready;
|
||||||
@@ -195,22 +234,51 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
} finally {
|
} finally {
|
||||||
await slot.player.dispose();
|
await slot.player.dispose();
|
||||||
_live.remove(slot);
|
_live.remove(slot);
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[player-slot] slot_released role=$role owner=${slot.owner.name} '
|
||||||
|
'selectOwner=$owner drama=${slot.dramaId ?? '-'} '
|
||||||
|
'episodeIndex=${slot.index} '
|
||||||
|
'controller=${_playerIdentity(slot.player)} '
|
||||||
|
'slotPlaying=${slotPlaying ? 1 : 0} '
|
||||||
|
'isPlaying=${value?.isPlaying == true ? 1 : 0} '
|
||||||
|
'position=${value?.position.inMilliseconds ?? '-'} '
|
||||||
|
'currentIndex=$_currentIndex generation=$_generation '
|
||||||
|
'trigger=$trigger',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// preloadIndex comes from the visible queue, so filtered categories and series
|
/// preloadIndex comes from the visible queue, so filtered categories and series
|
||||||
/// use exactly the same mechanism without warming an unrelated episode.
|
/// use exactly the same mechanism without warming an unrelated episode.
|
||||||
Future<void> select(int index, {int? preloadIndex}) async {
|
Future<void> select(
|
||||||
|
int index, {
|
||||||
|
int? preloadIndex,
|
||||||
|
int? previousIndex,
|
||||||
|
bool? userWantsPlay,
|
||||||
|
}) async {
|
||||||
if (_closed || index < 0 || index >= episodes.length) return;
|
if (_closed || index < 0 || index >= episodes.length) return;
|
||||||
// 切到另一集时,上一集按下的暂停不跟着走:滑过去就应该自动播放。
|
if (kDebugMode) {
|
||||||
// 重复选中同一集(例如页面重新可见)不在这里恢复,尊重用户按下的暂停。
|
debugPrint(
|
||||||
if (!_selected || index != _currentIndex) {
|
'[player-session] phase=select-enter session=${identityHashCode(this)} '
|
||||||
|
'owner=${owner.name} index=$index user=$_userWantsPlay '
|
||||||
|
'selected=$_selected current=$_currentIndex '
|
||||||
|
'appResumed=$_appResumed routeVisible=$_routeVisible '
|
||||||
|
'overlayOpen=$_overlayOpen visible=$_visible mayPlay=$_mayPlay '
|
||||||
|
'live=${_live.length}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// 切换到不同剧集时恢复播放;仍停留在同一集时保留用户暂停。
|
||||||
|
if (userWantsPlay != null) {
|
||||||
|
_userWantsPlay = userWantsPlay;
|
||||||
|
} else if (!_selected || index != _currentIndex) {
|
||||||
_userWantsPlay = true;
|
_userWantsPlay = true;
|
||||||
}
|
}
|
||||||
final request = ++_generation;
|
final request = ++_generation;
|
||||||
_selected = true;
|
_selected = true;
|
||||||
_currentIndex = index;
|
_currentIndex = index;
|
||||||
_nextIndex = preloadIndex;
|
_rememberNeighbors(preloadIndex, previousIndex);
|
||||||
_error = null;
|
_error = null;
|
||||||
if (!_visible) {
|
if (!_visible) {
|
||||||
_loading = false;
|
_loading = false;
|
||||||
@@ -235,6 +303,7 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
_PlayerSlot? target;
|
_PlayerSlot? target;
|
||||||
await _enqueue(() async {
|
await _enqueue(() async {
|
||||||
if (_closed || request != _generation) return;
|
if (_closed || request != _generation) return;
|
||||||
|
await _retire(_handoff, trigger: 'select-handoff');
|
||||||
final old = _active;
|
final old = _active;
|
||||||
if (old != null &&
|
if (old != null &&
|
||||||
old.index == index &&
|
old.index == index &&
|
||||||
@@ -243,20 +312,27 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
target = old;
|
target = old;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (old != null) await old.player.pause();
|
if (old != null) {
|
||||||
final warm = _next;
|
await old.player.pause();
|
||||||
|
old.playing = false;
|
||||||
|
}
|
||||||
|
final warmNext = _next;
|
||||||
|
final warmPrevious = _previous;
|
||||||
_active = null;
|
_active = null;
|
||||||
_next = null;
|
_next = null;
|
||||||
final hit = warm?.index == index && warm?.failure == null && !isLocked;
|
_previous = null;
|
||||||
if (hit) {
|
final warm =
|
||||||
|
_usableWarm(this, warmNext, index) ??
|
||||||
|
_usableWarm(this, warmPrevious, index);
|
||||||
|
if (warm != null) {
|
||||||
|
warm.reusedWarm = true;
|
||||||
target = _active = warm;
|
target = _active = warm;
|
||||||
_loading = !warm!.prepared;
|
_loading = !warm.prepared;
|
||||||
_notify();
|
_notify();
|
||||||
// Start a ready successor before awaiting slow disposal of the old one.
|
// Start a ready successor before awaiting slow disposal of the old one.
|
||||||
if (warm.prepared) await _start(warm, request);
|
if (warm.prepared) await _start(warm, request);
|
||||||
}
|
}
|
||||||
await _retire(old);
|
await _parkNeighbors(this, old, warmNext, warmPrevious);
|
||||||
if (!hit) await _retire(warm);
|
|
||||||
if (_closed || request != _generation || isLocked) return;
|
if (_closed || request != _generation || isLocked) return;
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
target = _active = _create(index);
|
target = _active = _create(index);
|
||||||
@@ -269,7 +345,116 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
await slot.ready;
|
await slot.ready;
|
||||||
if (_closed || request != _generation || _active != slot) return;
|
if (_closed || request != _generation || _active != slot) return;
|
||||||
await _enqueue(() => _start(slot, request));
|
await _enqueue(() => _start(slot, request));
|
||||||
if (!_closed && request == _generation) _schedulePreload();
|
if (!_closed && request == _generation) _warmNeighbors(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 后台准备新片源,成功后再替换当前播放器。失败时原播放器保持不动。
|
||||||
|
Future<bool> replaceCurrent() async {
|
||||||
|
if (_closed || !_selected) return false;
|
||||||
|
final index = _currentIndex;
|
||||||
|
if (index < 0 || index >= episodes.length || isLocked) return false;
|
||||||
|
if (!canPlay(episodes[index])) return false;
|
||||||
|
final request = _generation;
|
||||||
|
final slot = await _prepareReplacement(index, request);
|
||||||
|
if (slot == null) {
|
||||||
|
await _resumeActive();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
await slot.ready;
|
||||||
|
if (!_replacementReady(slot, request)) {
|
||||||
|
await _dropReplacement(slot);
|
||||||
|
await _resumeActive();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final previous = await _showReplacement(slot, request);
|
||||||
|
if (_active != slot) {
|
||||||
|
await _dropReplacement(slot);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
await _enqueue(() => _start(slot, request));
|
||||||
|
await Future<void>.delayed(_qualityHandoffHold);
|
||||||
|
if (previous != null && _handoff == previous && _active == slot) {
|
||||||
|
await _enqueue(
|
||||||
|
() => _retire(previous, trigger: 'quality-handoff-complete'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!_closed && request == _generation) _warmNeighbors(this);
|
||||||
|
return _active == slot && slot.failure == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<_PlayerSlot?> _prepareReplacement(int index, int request) async {
|
||||||
|
_PlayerSlot? created;
|
||||||
|
await _enqueue(() async {
|
||||||
|
if (_closed || request != _generation || _active == null) return;
|
||||||
|
final warm = _next;
|
||||||
|
_next = null;
|
||||||
|
await _retire(_handoff, trigger: 'replacement-handoff');
|
||||||
|
await _retire(warm, trigger: 'replacement-next');
|
||||||
|
if (_closed || request != _generation || _active == null) return;
|
||||||
|
try {
|
||||||
|
created = _create(index);
|
||||||
|
} catch (_) {
|
||||||
|
created = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _replacementReady(_PlayerSlot slot, int request) {
|
||||||
|
return !_closed &&
|
||||||
|
request == _generation &&
|
||||||
|
_active != null &&
|
||||||
|
slot.failure == null &&
|
||||||
|
slot.prepared;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _resumeActive() async {
|
||||||
|
final slot = _active;
|
||||||
|
if (slot == null || !_userWantsPlay || _closed) return;
|
||||||
|
await _enqueue(() => _applyPlayback(slot));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _dropReplacement(_PlayerSlot slot) {
|
||||||
|
return _enqueue(() async {
|
||||||
|
if (_live.contains(slot)) {
|
||||||
|
await _retire(slot, trigger: 'replacement-drop');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 先把已出画的新播放器交到界面上,旧播放器留给调用方稍后释放。
|
||||||
|
Future<_PlayerSlot?> _showReplacement(_PlayerSlot slot, int request) async {
|
||||||
|
_PlayerSlot? previous;
|
||||||
|
var shown = false;
|
||||||
|
await _enqueue(() async {
|
||||||
|
if (!_replacementReady(slot, request)) return;
|
||||||
|
previous = _active;
|
||||||
|
await _catchUp(slot, previous);
|
||||||
|
_handoff = previous;
|
||||||
|
_active = slot;
|
||||||
|
shown = true;
|
||||||
|
if (previous != null) {
|
||||||
|
await previous!.player.pause();
|
||||||
|
previous!.playing = false;
|
||||||
|
}
|
||||||
|
_notify();
|
||||||
|
});
|
||||||
|
if (!shown || _active != slot) return null;
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 旧片仍在播,把新片对齐到当前进度,盖住时画面才接得上。
|
||||||
|
Future<void> _catchUp(_PlayerSlot slot, _PlayerSlot? previous) async {
|
||||||
|
final next = slot.player;
|
||||||
|
final current = previous?.player;
|
||||||
|
if (next is! VideoPlayerPort || current is! VideoPlayerPort) return;
|
||||||
|
final position = current.controller.value.position;
|
||||||
|
if (position <= Duration.zero) return;
|
||||||
|
try {
|
||||||
|
await next.seekTo(position);
|
||||||
|
} catch (_) {
|
||||||
|
// 对齐失败仍用准备阶段的进度,不因此放弃切换。
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _start(_PlayerSlot slot, int request) async {
|
Future<void> _start(_PlayerSlot slot, int request) async {
|
||||||
@@ -295,6 +480,22 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
Future<void> _applyPlayback(_PlayerSlot slot) async {
|
Future<void> _applyPlayback(_PlayerSlot slot) async {
|
||||||
if (_closed || _active != slot || !slot.activated) return;
|
if (_closed || _active != slot || !slot.activated) return;
|
||||||
final shouldPlay = _mayPlay && slot.index == _currentIndex && !isLocked;
|
final shouldPlay = _mayPlay && slot.index == _currentIndex && !isLocked;
|
||||||
|
final video = slot.player is VideoPlayerPort
|
||||||
|
? slot.player as VideoPlayerPort
|
||||||
|
: null;
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[player-session] phase=apply-playback '
|
||||||
|
'session=${identityHashCode(this)} owner=${owner.name} '
|
||||||
|
'index=${slot.index} shouldPlay=$shouldPlay user=$_userWantsPlay '
|
||||||
|
'appResumed=$_appResumed routeVisible=$_routeVisible '
|
||||||
|
'overlayOpen=$_overlayOpen locked=$isLocked '
|
||||||
|
'player=${identityHashCode(slot.player)} '
|
||||||
|
'controller=${video == null ? '-' : identityHashCode(video.controller)} '
|
||||||
|
'isPlaying=${video?.controller.value.isPlaying ?? '-'} '
|
||||||
|
'slotPlaying=${slot.playing}',
|
||||||
|
);
|
||||||
|
}
|
||||||
if (shouldPlay == slot.playing) return;
|
if (shouldPlay == slot.playing) return;
|
||||||
if (shouldPlay) {
|
if (shouldPlay) {
|
||||||
await slot.player.play();
|
await slot.player.play();
|
||||||
@@ -302,96 +503,42 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
await slot.player.pause();
|
await slot.player.pause();
|
||||||
}
|
}
|
||||||
slot.playing = shouldPlay;
|
slot.playing = shouldPlay;
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[player-session] phase=apply-playback-result '
|
||||||
|
'session=${identityHashCode(this)} index=${slot.index} '
|
||||||
|
'shouldPlay=$shouldPlay '
|
||||||
|
'isPlaying=${video?.controller.value.isPlaying ?? '-'} '
|
||||||
|
'slotPlaying=${slot.playing}',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _schedulePreload() {
|
|
||||||
final request = _generation;
|
|
||||||
final index = _nextIndex;
|
|
||||||
_preloadTask = () async {
|
|
||||||
_PlayerSlot? candidate;
|
|
||||||
await _enqueue(() async {
|
|
||||||
if (_closed || request != _generation) return;
|
|
||||||
final allowed =
|
|
||||||
index != null &&
|
|
||||||
index >= 0 &&
|
|
||||||
index < episodes.length &&
|
|
||||||
index != _currentIndex &&
|
|
||||||
canPlay(episodes[index]);
|
|
||||||
if (!allowed || _next?.index != index) {
|
|
||||||
final stale = _next;
|
|
||||||
_next = null;
|
|
||||||
await _retire(stale);
|
|
||||||
}
|
|
||||||
if (!_visible ||
|
|
||||||
_overlayOpen ||
|
|
||||||
request != _generation ||
|
|
||||||
_active?.prepared != true ||
|
|
||||||
!allowed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
candidate = _next ??= _create(index);
|
|
||||||
} catch (_) {
|
|
||||||
// Optional allocation failure must not interrupt the playing item.
|
|
||||||
}
|
|
||||||
});
|
|
||||||
final slot = candidate;
|
|
||||||
if (slot == null) return;
|
|
||||||
await slot.ready;
|
|
||||||
if (_closed || _next != slot) return;
|
|
||||||
if (slot.failure != null) {
|
|
||||||
// Optional work fails silently. A later explicit selection retries.
|
|
||||||
await _enqueue(() async {
|
|
||||||
if (_next != slot) return;
|
|
||||||
_next = null;
|
|
||||||
await _retire(slot);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
_notify();
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAppResumed(bool value) {
|
|
||||||
_appResumed = value;
|
|
||||||
_syncPlayback();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRouteVisible(bool value) {
|
|
||||||
_routeVisible = value;
|
|
||||||
_syncPlayback();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setOverlayOpen(bool value) {
|
|
||||||
_overlayOpen = value;
|
|
||||||
_syncPlayback();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setUserWantsPlay(bool value) {
|
|
||||||
_userWantsPlay = value;
|
|
||||||
_syncPlayback();
|
|
||||||
_notify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _syncPlayback() {
|
void _syncPlayback() {
|
||||||
if (_closed) return;
|
if (_closed) return;
|
||||||
if (_visible && _selected && active == null) {
|
if (_visible && _selected && active == null) {
|
||||||
unawaited(select(_currentIndex, preloadIndex: _nextIndex));
|
unawaited(
|
||||||
|
select(
|
||||||
|
_currentIndex,
|
||||||
|
preloadIndex: _nextIndex,
|
||||||
|
previousIndex: _previousIndex,
|
||||||
|
),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final slot = _active;
|
final slot = _active;
|
||||||
if (slot != null) unawaited(_enqueue(() => _applyPlayback(slot)));
|
if (slot != null) unawaited(_enqueue(() => _applyPlayback(slot)));
|
||||||
if (_visible && !_overlayOpen && !_loading) _schedulePreload();
|
if (_visible && !_overlayOpen && !_loading) _warmNeighbors(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _releasePlayers() {
|
Future<void> _releasePlayers() {
|
||||||
_generation++;
|
_generation++;
|
||||||
return _enqueue(() async {
|
return _enqueue(() async {
|
||||||
_active = _next = null;
|
_active = _next = _previous = _handoff = null;
|
||||||
_loading = false;
|
_loading = false;
|
||||||
_notify();
|
_notify();
|
||||||
for (final slot in _live.toList()) {
|
for (final slot in _live.toList()) {
|
||||||
await _retire(slot);
|
await _retire(slot, trigger: 'session-release-all');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -400,6 +547,23 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
if (!_closed) notifyListeners();
|
if (!_closed) notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _slotRole(_PlayerSlot slot, {String? roleHint}) {
|
||||||
|
if (identical(slot, _active)) return 'current';
|
||||||
|
if (identical(slot, _previous)) return 'previous';
|
||||||
|
if (identical(slot, _next)) return 'next';
|
||||||
|
if (identical(slot, _handoff)) return 'handoff';
|
||||||
|
return roleHint ?? 'unassigned';
|
||||||
|
}
|
||||||
|
|
||||||
|
void _logOwnerRejection(String phase, _PlayerSlot slot) {
|
||||||
|
if (!kDebugMode) return;
|
||||||
|
debugPrint(
|
||||||
|
'[player-owner] phase=reject-$phase expected=${owner.name} '
|
||||||
|
'actual=${slot.owner.name} drama=${slot.dramaId ?? '-'} '
|
||||||
|
'episodeIndex=${slot.index} controller=${_playerIdentity(slot.player)}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
if (_closed) return;
|
if (_closed) return;
|
||||||
_closed = true;
|
_closed = true;
|
||||||
@@ -410,13 +574,27 @@ class PlaybackSession extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PlayerSlot {
|
class _PlayerSlot {
|
||||||
_PlayerSlot(this.index, this.player);
|
_PlayerSlot(
|
||||||
|
this.index,
|
||||||
|
this.player, {
|
||||||
|
required this.owner,
|
||||||
|
required this.dramaId,
|
||||||
|
});
|
||||||
int index;
|
int index;
|
||||||
final PlayerPort player;
|
final PlayerPort player;
|
||||||
|
final PlaybackSessionOwner owner;
|
||||||
|
final String? dramaId;
|
||||||
late final Future<void> ready;
|
late final Future<void> ready;
|
||||||
bool prepared = false;
|
bool prepared = false;
|
||||||
bool activated = false;
|
bool activated = false;
|
||||||
bool playing = false;
|
bool playing = false;
|
||||||
bool retiring = false;
|
bool retiring = false;
|
||||||
|
bool reusedWarm = false;
|
||||||
Object? failure;
|
Object? failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _playerIdentity(PlayerPort player) {
|
||||||
|
return player is VideoPlayerPort
|
||||||
|
? '${identityHashCode(player.controller)}'
|
||||||
|
: '${identityHashCode(player)}';
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
part of 'playback_session.dart';
|
||||||
|
|
||||||
|
/// 播放会话的可见性、用户意图与相邻集预热控制。
|
||||||
|
extension PlaybackSessionControls on PlaybackSession {
|
||||||
|
/// 滑动手势开始时按方向优先准备相邻集,不改变当前集播放状态。
|
||||||
|
void prewarmNeighbors({required bool forward}) {
|
||||||
|
if (!_visible || _overlayOpen || _active?.prepared != true) return;
|
||||||
|
_warmNeighbors(this, preferredNext: forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 路由交接时同步暂停当前原生播放器,controller 仍由 session 持有。
|
||||||
|
Future<void> pauseForRouteHandoff() {
|
||||||
|
if (_closed) return Future<void>.value();
|
||||||
|
_routeVisible = false;
|
||||||
|
return _enqueue(() async {
|
||||||
|
final slot = _active;
|
||||||
|
if (slot == null) return;
|
||||||
|
await slot.player.pause();
|
||||||
|
slot.playing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 路由恢复可见后立即同步当前 controller,并等待原生播放状态落地。
|
||||||
|
Future<void> resumeForRouteHandoff() {
|
||||||
|
if (_closed) return Future<void>.value();
|
||||||
|
_routeVisible = true;
|
||||||
|
return _enqueue(() async {
|
||||||
|
final slot = _active;
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[feed-handoff] phase=resume slot=${slot?.index} '
|
||||||
|
'activated=${slot?.activated} playing=${slot?.playing} '
|
||||||
|
'retiring=${slot?.retiring} current=$_currentIndex '
|
||||||
|
'visible=$_visible user=$_userWantsPlay loading=$_loading',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (slot == null || slot.retiring) return;
|
||||||
|
if (!slot.activated) {
|
||||||
|
try {
|
||||||
|
await activate?.call(episodes[slot.index], slot.player);
|
||||||
|
} catch (error) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint('[feed-handoff] phase=activation-failed error=$error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_closed || _active != slot || slot.retiring) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[feed-handoff] phase=activation-aborted closed=$_closed '
|
||||||
|
'activeSame=${identical(_active, slot)} retiring=${slot.retiring}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
slot.activated = true;
|
||||||
|
}
|
||||||
|
await _applyPlayback(slot);
|
||||||
|
if (_visible && !_overlayOpen && !_loading) _warmNeighbors(this);
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(
|
||||||
|
'[feed-handoff] phase=resumed activated=${slot.activated} '
|
||||||
|
'playing=${slot.playing}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 选中锁定集时立即停播并释放所有原生播放器,不创建新片源。
|
||||||
|
Future<void> selectLocked(
|
||||||
|
int index, {
|
||||||
|
int? preloadIndex,
|
||||||
|
int? previousIndex,
|
||||||
|
}) {
|
||||||
|
if (_closed || index < 0 || index >= episodes.length) {
|
||||||
|
return Future<void>.value();
|
||||||
|
}
|
||||||
|
_generation++;
|
||||||
|
_selected = false;
|
||||||
|
_currentIndex = index;
|
||||||
|
_rememberNeighbors(preloadIndex, previousIndex);
|
||||||
|
_loading = false;
|
||||||
|
_error = null;
|
||||||
|
_userWantsPlay = false;
|
||||||
|
_notify();
|
||||||
|
return _releasePlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 清晰度切换时盖住黑帧的旧播放器。只在仍由会话持有时交给界面。
|
||||||
|
PlayerPort? handoffAt(int index) {
|
||||||
|
final slot = _handoff;
|
||||||
|
if (_closed || slot == null || slot.retiring || slot.index != index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return slot.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 当前索引是否复用了已预热的播放器槽。
|
||||||
|
bool reusedWarmAt(int index) {
|
||||||
|
for (final slot in [_active, _next, _previous]) {
|
||||||
|
if (slot != null && !slot.retiring && slot.index == index) {
|
||||||
|
return slot.reusedWarm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 同步应用前台状态并恢复或暂停当前集。
|
||||||
|
void setAppResumed(bool value) {
|
||||||
|
_appResumed = value;
|
||||||
|
_syncPlayback();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 同步播放器路由是否可见。
|
||||||
|
void setRouteVisible(bool value) {
|
||||||
|
_routeVisible = value;
|
||||||
|
_syncPlayback();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 同步浮层是否遮挡播放器。
|
||||||
|
void setOverlayOpen(bool value) {
|
||||||
|
_overlayOpen = value;
|
||||||
|
_syncPlayback();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 记录用户播放意图;切换剧集时会在 [PlaybackSession.select] 中恢复播放。
|
||||||
|
void setUserWantsPlay(bool value) {
|
||||||
|
_userWantsPlay = value;
|
||||||
|
_syncPlayback();
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import '../models/playlist_detail.dart';
|
||||||
|
import '../remote/catalog_api.dart';
|
||||||
|
import '../repositories/playlist_repository.dart';
|
||||||
|
|
||||||
|
/// 推荐页剧单:已启用剧单及其短剧卡片。
|
||||||
|
class PlaylistController extends ChangeNotifier {
|
||||||
|
PlaylistController(this._repository);
|
||||||
|
|
||||||
|
final PlaylistRepository _repository;
|
||||||
|
|
||||||
|
static const int pageSize = CatalogApi.playlistPageSize;
|
||||||
|
|
||||||
|
List<PlaylistDetail> items = const [];
|
||||||
|
bool loading = false;
|
||||||
|
bool loadingMore = false;
|
||||||
|
bool loaded = false;
|
||||||
|
bool hasMore = false;
|
||||||
|
String? error;
|
||||||
|
int _pageIndex = 1;
|
||||||
|
bool _disposed = false;
|
||||||
|
|
||||||
|
/// 从第一页重新拉取。失败保留错误态,成功后替换本地缓存。
|
||||||
|
Future<void> load() async {
|
||||||
|
loading = true;
|
||||||
|
error = null;
|
||||||
|
_notify();
|
||||||
|
try {
|
||||||
|
final page = await _repository.fetchPlaylists(pageSize: pageSize);
|
||||||
|
items = page.list;
|
||||||
|
_pageIndex = 1;
|
||||||
|
hasMore = items.length < page.total;
|
||||||
|
loaded = true;
|
||||||
|
} catch (exception) {
|
||||||
|
error = 'playlistsError';
|
||||||
|
if (kDebugMode) debugPrint('[playlist] $exception');
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 滚到底时追加下一页。没有更多或正在请求时直接返回。
|
||||||
|
Future<void> loadMore() async {
|
||||||
|
if (loading || loadingMore || !hasMore) return;
|
||||||
|
loadingMore = true;
|
||||||
|
_notify();
|
||||||
|
try {
|
||||||
|
final page = await _repository.fetchPlaylists(
|
||||||
|
pageIndex: _pageIndex + 1,
|
||||||
|
pageSize: pageSize,
|
||||||
|
);
|
||||||
|
if (page.list.isEmpty) {
|
||||||
|
hasMore = false;
|
||||||
|
} else {
|
||||||
|
items = [...items, ...page.list];
|
||||||
|
_pageIndex += 1;
|
||||||
|
hasMore = items.length < page.total;
|
||||||
|
}
|
||||||
|
} catch (exception) {
|
||||||
|
if (kDebugMode) debugPrint('[playlist] more $exception');
|
||||||
|
} finally {
|
||||||
|
loadingMore = false;
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 打开某一剧单时再取一次详情;失败则回落到列表里已有的那条。
|
||||||
|
Future<PlaylistDetail> detail(
|
||||||
|
String id, {
|
||||||
|
int pageIndex = 1,
|
||||||
|
int pageSize = CatalogApi.playlistDramaPageSize,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
return await _repository.fetchPlaylist(
|
||||||
|
id,
|
||||||
|
pageIndex: pageIndex,
|
||||||
|
pageSize: pageSize,
|
||||||
|
);
|
||||||
|
} catch (exception) {
|
||||||
|
if (kDebugMode) debugPrint('[playlist] detail $id $exception');
|
||||||
|
return items.firstWhere(
|
||||||
|
(item) => item.id == id,
|
||||||
|
orElse: () => PlaylistDetail(
|
||||||
|
id: id,
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
dramaCount: 0,
|
||||||
|
dramas: const [],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _notify() {
|
||||||
|
if (!_disposed) notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_disposed = true;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import '../../config/app_config.dart';
|
|||||||
import 'sprite_thumbnail_asset_loader.dart';
|
import 'sprite_thumbnail_asset_loader.dart';
|
||||||
|
|
||||||
const Duration spriteVttCacheTtl = Duration(minutes: 10);
|
const Duration spriteVttCacheTtl = Duration(minutes: 10);
|
||||||
const int spriteImageCacheCapacity = 2;
|
const int spriteImageCacheCapacity = 1;
|
||||||
|
|
||||||
/// 单个 VTT cue 对应的 sprite 裁剪区域。
|
/// 单个 VTT cue 对应的 sprite 裁剪区域。
|
||||||
class SpriteThumbnailCue {
|
class SpriteThumbnailCue {
|
||||||
@@ -122,6 +122,8 @@ abstract interface class SpriteThumbnailAxisSource implements Listenable {
|
|||||||
SpriteThumbnailFrame? cachedFrameAt(String? thumbnailsUrl, Duration position);
|
SpriteThumbnailFrame? cachedFrameAt(String? thumbnailsUrl, Duration position);
|
||||||
|
|
||||||
bool hasAxis(String? thumbnailsUrl);
|
bool hasAxis(String? thumbnailsUrl);
|
||||||
|
|
||||||
|
Future<void> prepareAt(String? thumbnailsUrl, Duration position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// VTT 时间轴、cue 二分与 sprite ui.Image LRU 缓存。
|
/// VTT 时间轴、cue 二分与 sprite ui.Image LRU 缓存。
|
||||||
@@ -130,35 +132,36 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
SpriteThumbnailAxisService({
|
SpriteThumbnailAxisService({
|
||||||
SpriteThumbnailAssetLoader? loader,
|
SpriteThumbnailAssetLoader? loader,
|
||||||
this.cacheTtl = spriteVttCacheTtl,
|
this.cacheTtl = spriteVttCacheTtl,
|
||||||
|
this.spriteCacheCapacity = spriteImageCacheCapacity,
|
||||||
DateTime Function()? now,
|
DateTime Function()? now,
|
||||||
}) : _loader = loader ?? DioSpriteThumbnailAssetLoader(),
|
}) : _loader = loader ?? DioSpriteThumbnailAssetLoader(),
|
||||||
_now = now ?? DateTime.now;
|
_now = now ?? DateTime.now;
|
||||||
|
|
||||||
final SpriteThumbnailAssetLoader _loader;
|
final SpriteThumbnailAssetLoader _loader;
|
||||||
final Duration cacheTtl;
|
final Duration cacheTtl;
|
||||||
|
final int spriteCacheCapacity;
|
||||||
final DateTime Function() _now;
|
final DateTime Function() _now;
|
||||||
final Map<String, _CachedAxis> _axisCache = {};
|
final Map<String, _CachedAxis> _axisCache = {};
|
||||||
final Map<String, Future<SpriteThumbnailAxis>> _axisRequests = {};
|
final Map<String, Future<SpriteThumbnailAxis>> _axisRequests = {};
|
||||||
final LinkedHashMap<String, _CachedSprite> _spriteCache = LinkedHashMap();
|
final LinkedHashMap<String, _CachedSprite> _spriteCache = LinkedHashMap();
|
||||||
final Map<String, Future<_CachedSprite?>> _spriteRequests = {};
|
final Map<String, Future<_CachedSprite?>> _spriteRequests = {};
|
||||||
final Set<String> _failedSprites = {};
|
final Set<String> _failedSprites = {};
|
||||||
String? _activeAxisUrl;
|
|
||||||
int _axisGeneration = 0;
|
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
int get spriteCacheSize => _spriteCache.length;
|
int get spriteCacheSize => _spriteCache.length;
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
List<String> get spriteCacheKeys => _spriteCache.keys.toList();
|
List<String> get spriteCacheKeys => _spriteCache.keys
|
||||||
|
.map((url) => Uri.tryParse(url)?.pathSegments.lastOrNull ?? url)
|
||||||
|
.toList();
|
||||||
|
|
||||||
/// 播放器就绪时预取当前 cue 与相邻 sprite,拖动帧不触发网络或解码。
|
/// 播放器就绪时预取当前 cue;容量大于 1 时顺带预取相邻 sprite。
|
||||||
|
@override
|
||||||
Future<void> prepareAt(String? thumbnailsUrl, Duration position) async {
|
Future<void> prepareAt(String? thumbnailsUrl, Duration position) async {
|
||||||
final url = _normalizeUrl(thumbnailsUrl);
|
final url = _normalizeUrl(thumbnailsUrl);
|
||||||
if (_disposed || url == null) return;
|
if (_disposed || url == null) return;
|
||||||
_activateAxis(url);
|
|
||||||
final axis = await _loadAxis(url);
|
final axis = await _loadAxis(url);
|
||||||
if (_disposed || _activeAxisUrl != url) return;
|
if (_disposed) return;
|
||||||
for (final cue in _prefetchCues(axis, position)) {
|
for (final cue in _prefetchCues(axis, position)) {
|
||||||
await _ensureSprite(axis, cue);
|
await _ensureSprite(axis, cue);
|
||||||
}
|
}
|
||||||
@@ -167,7 +170,7 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
@override
|
@override
|
||||||
bool hasAxis(String? thumbnailsUrl) {
|
bool hasAxis(String? thumbnailsUrl) {
|
||||||
final url = _normalizeUrl(thumbnailsUrl);
|
final url = _normalizeUrl(thumbnailsUrl);
|
||||||
if (url == null || url != _activeAxisUrl) return false;
|
if (url == null) return false;
|
||||||
return _readAxis(url) != null;
|
return _readAxis(url) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,12 +180,14 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
Duration position,
|
Duration position,
|
||||||
) {
|
) {
|
||||||
final url = _normalizeUrl(thumbnailsUrl);
|
final url = _normalizeUrl(thumbnailsUrl);
|
||||||
if (url == null || url != _activeAxisUrl) return null;
|
if (url == null) return null;
|
||||||
final axis = _readAxis(url);
|
final axis = _readAxis(url);
|
||||||
if (axis == null) return null;
|
if (axis == null) return null;
|
||||||
final cue = selectSpriteThumbnailCue(axis.cues, position);
|
final cue = selectSpriteThumbnailCue(axis.cues, position);
|
||||||
if (cue == null) return null;
|
if (cue == null) return null;
|
||||||
final cached = _readSprite(cue.spriteFile);
|
final cached = _readSprite(
|
||||||
|
axis.resolveSpriteUri(cue.spriteFile).toString(),
|
||||||
|
);
|
||||||
if (cached == null) return null;
|
if (cached == null) return null;
|
||||||
final sourceRect = _scaledSourceRect(cached, cue.sourceRect);
|
final sourceRect = _scaledSourceRect(cached, cue.sourceRect);
|
||||||
if (sourceRect == null) return null;
|
if (sourceRect == null) return null;
|
||||||
@@ -203,13 +208,6 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _activateAxis(String url) {
|
|
||||||
if (_activeAxisUrl == url) return;
|
|
||||||
_activeAxisUrl = url;
|
|
||||||
_axisGeneration++;
|
|
||||||
_clearSprites();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<SpriteThumbnailAxis> _loadAxis(String url) {
|
Future<SpriteThumbnailAxis> _loadAxis(String url) {
|
||||||
final cached = _readAxis(url);
|
final cached = _readAxis(url);
|
||||||
if (cached != null) return Future.value(cached);
|
if (cached != null) return Future.value(cached);
|
||||||
@@ -236,7 +234,6 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
} on SpriteThumbnailForbiddenException {
|
} on SpriteThumbnailForbiddenException {
|
||||||
if (_disposed) return SpriteThumbnailAxis.empty(url);
|
if (_disposed) return SpriteThumbnailAxis.empty(url);
|
||||||
_axisCache.remove(url);
|
_axisCache.remove(url);
|
||||||
if (_activeAxisUrl == url) _clearSprites();
|
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -271,6 +268,7 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
if (current == null) return const [];
|
if (current == null) return const [];
|
||||||
final index = axis.cues.indexOf(current);
|
final index = axis.cues.indexOf(current);
|
||||||
final candidates = <SpriteThumbnailCue>[current];
|
final candidates = <SpriteThumbnailCue>[current];
|
||||||
|
if (spriteCacheCapacity <= 1) return candidates;
|
||||||
for (final direction in const [1, -1]) {
|
for (final direction in const [1, -1]) {
|
||||||
for (var step = 1; step < axis.cues.length; step++) {
|
for (var step = 1; step < axis.cues.length; step++) {
|
||||||
final neighborIndex = index + direction * step;
|
final neighborIndex = index + direction * step;
|
||||||
@@ -290,23 +288,23 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
SpriteThumbnailAxis axis,
|
SpriteThumbnailAxis axis,
|
||||||
SpriteThumbnailCue cue,
|
SpriteThumbnailCue cue,
|
||||||
) {
|
) {
|
||||||
final cached = _readSprite(cue.spriteFile);
|
final spriteUrl = axis.resolveSpriteUri(cue.spriteFile).toString();
|
||||||
|
final cached = _readSprite(spriteUrl);
|
||||||
if (cached != null) return Future.value(cached);
|
if (cached != null) return Future.value(cached);
|
||||||
if (_failedSprites.contains(cue.spriteFile)) return Future.value();
|
if (_failedSprites.contains(spriteUrl)) return Future.value();
|
||||||
final existing = _spriteRequests[cue.spriteFile];
|
final existing = _spriteRequests[spriteUrl];
|
||||||
if (existing != null) return existing;
|
if (existing != null) return existing;
|
||||||
final generation = _axisGeneration;
|
final request = _loadSprite(axis, cue, spriteUrl);
|
||||||
final request = _loadSprite(axis, cue, generation);
|
_spriteRequests[spriteUrl] = request;
|
||||||
_spriteRequests[cue.spriteFile] = request;
|
|
||||||
return request.whenComplete(() {
|
return request.whenComplete(() {
|
||||||
_spriteRequests.remove(cue.spriteFile);
|
_spriteRequests.remove(spriteUrl);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<_CachedSprite?> _loadSprite(
|
Future<_CachedSprite?> _loadSprite(
|
||||||
SpriteThumbnailAxis axis,
|
SpriteThumbnailAxis axis,
|
||||||
SpriteThumbnailCue cue,
|
SpriteThumbnailCue cue,
|
||||||
int generation,
|
String spriteUrl,
|
||||||
) async {
|
) async {
|
||||||
SpriteThumbnailDecodedImage? decoded;
|
SpriteThumbnailDecodedImage? decoded;
|
||||||
try {
|
try {
|
||||||
@@ -315,16 +313,16 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
decoded = null;
|
decoded = null;
|
||||||
}
|
}
|
||||||
if (decoded == null) {
|
if (decoded == null) {
|
||||||
_failedSprites.add(cue.spriteFile);
|
_failedSprites.add(spriteUrl);
|
||||||
if (!_disposed) notifyListeners();
|
if (!_disposed) notifyListeners();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (_disposed || generation != _axisGeneration) {
|
if (_disposed) {
|
||||||
decoded.image.dispose();
|
decoded.image.dispose();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final cached = _CachedSprite(decoded);
|
final cached = _CachedSprite(decoded);
|
||||||
_putSprite(cue.spriteFile, cached);
|
_putSprite(spriteUrl, cached);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
@@ -339,7 +337,7 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
void _putSprite(String key, _CachedSprite value) {
|
void _putSprite(String key, _CachedSprite value) {
|
||||||
_spriteCache.remove(key)?.decoded.image.dispose();
|
_spriteCache.remove(key)?.decoded.image.dispose();
|
||||||
_spriteCache[key] = value;
|
_spriteCache[key] = value;
|
||||||
while (_spriteCache.length > spriteImageCacheCapacity) {
|
while (_spriteCache.length > spriteCacheCapacity) {
|
||||||
final oldest = _spriteCache.remove(_spriteCache.keys.first);
|
final oldest = _spriteCache.remove(_spriteCache.keys.first);
|
||||||
oldest?.decoded.image.dispose();
|
oldest?.decoded.image.dispose();
|
||||||
}
|
}
|
||||||
@@ -375,8 +373,6 @@ class SpriteThumbnailAxisService extends ChangeNotifier
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _clearAll() {
|
void _clearAll() {
|
||||||
_axisGeneration++;
|
|
||||||
_activeAxisUrl = null;
|
|
||||||
_axisCache.clear();
|
_axisCache.clear();
|
||||||
_axisRequests.clear();
|
_axisRequests.clear();
|
||||||
_clearSprites();
|
_clearSprites();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
String? error;
|
String? error;
|
||||||
String? loadMoreError;
|
String? loadMoreError;
|
||||||
String? actionError;
|
String? actionError;
|
||||||
|
int? lastErrorCode;
|
||||||
int _pageIndex = 0;
|
int _pageIndex = 0;
|
||||||
int _requestSeq = 0;
|
int _requestSeq = 0;
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
@@ -50,6 +51,7 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
error = null;
|
error = null;
|
||||||
loadMoreError = null;
|
loadMoreError = null;
|
||||||
actionError = null;
|
actionError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
_notify();
|
_notify();
|
||||||
try {
|
try {
|
||||||
final page = await _history.recent(pageIndex: 1, pageSize: pageSize);
|
final page = await _history.recent(pageIndex: 1, pageSize: pageSize);
|
||||||
@@ -71,6 +73,7 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
);
|
);
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
error = failure is ApiException ? failure.message : 'progressError';
|
error = failure is ApiException ? failure.message : 'progressError';
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
@@ -86,6 +89,7 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
final request = ++_requestSeq;
|
final request = ++_requestSeq;
|
||||||
loadingMore = true;
|
loadingMore = true;
|
||||||
loadMoreError = null;
|
loadMoreError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
_notify();
|
_notify();
|
||||||
try {
|
try {
|
||||||
final page = await _history.recent(
|
final page = await _history.recent(
|
||||||
@@ -108,6 +112,7 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
loadMoreError = failure is ApiException
|
loadMoreError = failure is ApiException
|
||||||
? failure.message
|
? failure.message
|
||||||
: 'progressError';
|
: 'progressError';
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!_disposed && request == _requestSeq) {
|
if (!_disposed && request == _requestSeq) {
|
||||||
@@ -148,17 +153,19 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
total = total > 0 ? total - 1 : 0;
|
total = total > 0 ? total - 1 : 0;
|
||||||
hasMore = records.length < total;
|
hasMore = records.length < total;
|
||||||
actionError = null;
|
actionError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
_notify();
|
_notify();
|
||||||
try {
|
try {
|
||||||
await _history.remove(dramaId);
|
await _history.remove(dramaId);
|
||||||
return true;
|
return true;
|
||||||
} catch (_) {
|
} catch (failure) {
|
||||||
final next = [...records];
|
final next = [...records];
|
||||||
next.insert(index > next.length ? next.length : index, removed);
|
next.insert(index > next.length ? next.length : index, removed);
|
||||||
records = next;
|
records = next;
|
||||||
total += 1;
|
total += 1;
|
||||||
hasMore = records.length < total;
|
hasMore = records.length < total;
|
||||||
actionError = 'recordDeleteFailed';
|
actionError = 'recordDeleteFailed';
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
_notify();
|
_notify();
|
||||||
@@ -179,16 +186,18 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
loadingMore = false;
|
loadingMore = false;
|
||||||
clearing = true;
|
clearing = true;
|
||||||
actionError = null;
|
actionError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
_notify();
|
_notify();
|
||||||
try {
|
try {
|
||||||
await _history.clear();
|
await _history.clear();
|
||||||
return true;
|
return true;
|
||||||
} catch (_) {
|
} catch (failure) {
|
||||||
records = previous;
|
records = previous;
|
||||||
total = previousTotal;
|
total = previousTotal;
|
||||||
_pageIndex = previousPageIndex;
|
_pageIndex = previousPageIndex;
|
||||||
hasMore = records.length < total;
|
hasMore = records.length < total;
|
||||||
actionError = 'recordClearFailed';
|
actionError = 'recordClearFailed';
|
||||||
|
if (failure is ApiException) lastErrorCode = failure.code;
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
clearing = false;
|
clearing = false;
|
||||||
@@ -305,6 +314,23 @@ class WatchRecordsController extends ChangeNotifier {
|
|||||||
if (!_disposed) notifyListeners();
|
if (!_disposed) notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 切换账号/设备身份时清除内存数据,不删除服务端记录。
|
||||||
|
void reset() {
|
||||||
|
_requestSeq += 1;
|
||||||
|
records = const [];
|
||||||
|
total = 0;
|
||||||
|
loading = false;
|
||||||
|
loadingMore = false;
|
||||||
|
hasMore = false;
|
||||||
|
clearing = false;
|
||||||
|
error = null;
|
||||||
|
loadMoreError = null;
|
||||||
|
actionError = null;
|
||||||
|
lastErrorCode = null;
|
||||||
|
_pageIndex = 0;
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
/// 账号资料页只读字段的展示格式化。
|
||||||
|
///
|
||||||
|
/// 后端存的是 ISO 国家码、BCP-47 语言标签和 IANA 时区(`ID` / `id-ID` / `Asia/Jakarta`),
|
||||||
|
/// 直接展示对用户没有意义,这里统一转成当前界面语言的名称。
|
||||||
|
/// 国家与城市名只维护中文与英文两套:界面语言为印尼语时回退英文名,
|
||||||
|
/// 语言名与账号状态则三种界面语言都有。
|
||||||
|
library;
|
||||||
|
|
||||||
|
const _countryNamesZh = {
|
||||||
|
'ID': '印度尼西亚',
|
||||||
|
'MY': '马来西亚',
|
||||||
|
'SG': '新加坡',
|
||||||
|
'TH': '泰国',
|
||||||
|
'VN': '越南',
|
||||||
|
'PH': '菲律宾',
|
||||||
|
'KH': '柬埔寨',
|
||||||
|
'MM': '缅甸',
|
||||||
|
'LA': '老挝',
|
||||||
|
'BN': '文莱',
|
||||||
|
'CN': '中国',
|
||||||
|
'TW': '中国台湾',
|
||||||
|
'HK': '中国香港',
|
||||||
|
'MO': '中国澳门',
|
||||||
|
'JP': '日本',
|
||||||
|
'KR': '韩国',
|
||||||
|
'IN': '印度',
|
||||||
|
'PK': '巴基斯坦',
|
||||||
|
'BD': '孟加拉国',
|
||||||
|
'LK': '斯里兰卡',
|
||||||
|
'NP': '尼泊尔',
|
||||||
|
'US': '美国',
|
||||||
|
'CA': '加拿大',
|
||||||
|
'MX': '墨西哥',
|
||||||
|
'BR': '巴西',
|
||||||
|
'AR': '阿根廷',
|
||||||
|
'CL': '智利',
|
||||||
|
'CO': '哥伦比亚',
|
||||||
|
'PE': '秘鲁',
|
||||||
|
'VE': '委内瑞拉',
|
||||||
|
'EC': '厄瓜多尔',
|
||||||
|
'GT': '危地马拉',
|
||||||
|
'DO': '多米尼加',
|
||||||
|
'GB': '英国',
|
||||||
|
'DE': '德国',
|
||||||
|
'FR': '法国',
|
||||||
|
'ES': '西班牙',
|
||||||
|
'IT': '意大利',
|
||||||
|
'NL': '荷兰',
|
||||||
|
'PL': '波兰',
|
||||||
|
'RU': '俄罗斯',
|
||||||
|
'UA': '乌克兰',
|
||||||
|
'TR': '土耳其',
|
||||||
|
'SA': '沙特阿拉伯',
|
||||||
|
'AE': '阿联酋',
|
||||||
|
'IL': '以色列',
|
||||||
|
'EG': '埃及',
|
||||||
|
'NG': '尼日利亚',
|
||||||
|
'ZA': '南非',
|
||||||
|
'KE': '肯尼亚',
|
||||||
|
'MA': '摩洛哥',
|
||||||
|
'AU': '澳大利亚',
|
||||||
|
'NZ': '新西兰',
|
||||||
|
};
|
||||||
|
|
||||||
|
const _countryNamesEn = {
|
||||||
|
'ID': 'Indonesia',
|
||||||
|
'MY': 'Malaysia',
|
||||||
|
'SG': 'Singapore',
|
||||||
|
'TH': 'Thailand',
|
||||||
|
'VN': 'Vietnam',
|
||||||
|
'PH': 'Philippines',
|
||||||
|
'KH': 'Cambodia',
|
||||||
|
'MM': 'Myanmar',
|
||||||
|
'LA': 'Laos',
|
||||||
|
'BN': 'Brunei',
|
||||||
|
'CN': 'China',
|
||||||
|
'TW': 'Taiwan',
|
||||||
|
'HK': 'Hong Kong',
|
||||||
|
'MO': 'Macau',
|
||||||
|
'JP': 'Japan',
|
||||||
|
'KR': 'South Korea',
|
||||||
|
'IN': 'India',
|
||||||
|
'PK': 'Pakistan',
|
||||||
|
'BD': 'Bangladesh',
|
||||||
|
'LK': 'Sri Lanka',
|
||||||
|
'NP': 'Nepal',
|
||||||
|
'US': 'United States',
|
||||||
|
'CA': 'Canada',
|
||||||
|
'MX': 'Mexico',
|
||||||
|
'BR': 'Brazil',
|
||||||
|
'AR': 'Argentina',
|
||||||
|
'CL': 'Chile',
|
||||||
|
'CO': 'Colombia',
|
||||||
|
'PE': 'Peru',
|
||||||
|
'VE': 'Venezuela',
|
||||||
|
'EC': 'Ecuador',
|
||||||
|
'GT': 'Guatemala',
|
||||||
|
'DO': 'Dominican Republic',
|
||||||
|
'GB': 'United Kingdom',
|
||||||
|
'DE': 'Germany',
|
||||||
|
'FR': 'France',
|
||||||
|
'ES': 'Spain',
|
||||||
|
'IT': 'Italy',
|
||||||
|
'NL': 'Netherlands',
|
||||||
|
'PL': 'Poland',
|
||||||
|
'RU': 'Russia',
|
||||||
|
'UA': 'Ukraine',
|
||||||
|
'TR': 'Turkey',
|
||||||
|
'SA': 'Saudi Arabia',
|
||||||
|
'AE': 'United Arab Emirates',
|
||||||
|
'IL': 'Israel',
|
||||||
|
'EG': 'Egypt',
|
||||||
|
'NG': 'Nigeria',
|
||||||
|
'ZA': 'South Africa',
|
||||||
|
'KE': 'Kenya',
|
||||||
|
'MA': 'Morocco',
|
||||||
|
'AU': 'Australia',
|
||||||
|
'NZ': 'New Zealand',
|
||||||
|
};
|
||||||
|
|
||||||
|
const _timezoneNamesZh = {
|
||||||
|
'Asia/Jakarta': '雅加达',
|
||||||
|
'Asia/Kuala_Lumpur': '吉隆坡',
|
||||||
|
'Asia/Singapore': '新加坡',
|
||||||
|
'Asia/Bangkok': '曼谷',
|
||||||
|
'Asia/Ho_Chi_Minh': '胡志明市',
|
||||||
|
'Asia/Manila': '马尼拉',
|
||||||
|
'Asia/Phnom_Penh': '金边',
|
||||||
|
'Asia/Yangon': '仰光',
|
||||||
|
'Asia/Vientiane': '万象',
|
||||||
|
'Asia/Brunei': '斯里巴加湾市',
|
||||||
|
'Asia/Shanghai': '上海',
|
||||||
|
'Asia/Taipei': '台北',
|
||||||
|
'Asia/Hong_Kong': '香港',
|
||||||
|
'Asia/Macau': '澳门',
|
||||||
|
'Asia/Tokyo': '东京',
|
||||||
|
'Asia/Seoul': '首尔',
|
||||||
|
'Asia/Kolkata': '加尔各答',
|
||||||
|
'Asia/Karachi': '卡拉奇',
|
||||||
|
'Asia/Dhaka': '达卡',
|
||||||
|
'Asia/Colombo': '科伦坡',
|
||||||
|
'Asia/Kathmandu': '加德满都',
|
||||||
|
'America/New_York': '纽约',
|
||||||
|
'America/Toronto': '多伦多',
|
||||||
|
'America/Mexico_City': '墨西哥城',
|
||||||
|
'America/Sao_Paulo': '圣保罗',
|
||||||
|
'America/Argentina/Buenos_Aires': '布宜诺斯艾利斯',
|
||||||
|
'America/Santiago': '圣地亚哥',
|
||||||
|
'America/Bogota': '波哥大',
|
||||||
|
'America/Lima': '利马',
|
||||||
|
'America/Caracas': '加拉加斯',
|
||||||
|
'America/Guayaquil': '瓜亚基尔',
|
||||||
|
'America/Guatemala': '危地马拉城',
|
||||||
|
'America/Santo_Domingo': '圣多明各',
|
||||||
|
'Europe/London': '伦敦',
|
||||||
|
'Europe/Berlin': '柏林',
|
||||||
|
'Europe/Paris': '巴黎',
|
||||||
|
'Europe/Madrid': '马德里',
|
||||||
|
'Europe/Rome': '罗马',
|
||||||
|
'Europe/Amsterdam': '阿姆斯特丹',
|
||||||
|
'Europe/Warsaw': '华沙',
|
||||||
|
'Europe/Moscow': '莫斯科',
|
||||||
|
'Europe/Kyiv': '基辅',
|
||||||
|
'Europe/Istanbul': '伊斯坦布尔',
|
||||||
|
'Asia/Riyadh': '利雅得',
|
||||||
|
'Asia/Dubai': '迪拜',
|
||||||
|
'Asia/Jerusalem': '耶路撒冷',
|
||||||
|
'Africa/Cairo': '开罗',
|
||||||
|
'Africa/Lagos': '拉各斯',
|
||||||
|
'Africa/Johannesburg': '约翰内斯堡',
|
||||||
|
'Africa/Nairobi': '内罗毕',
|
||||||
|
'Africa/Casablanca': '卡萨布兰卡',
|
||||||
|
'Australia/Sydney': '悉尼',
|
||||||
|
'Pacific/Auckland': '奥克兰',
|
||||||
|
};
|
||||||
|
|
||||||
|
const _languageNames = {
|
||||||
|
'id': {'zh': '印度尼西亚语', 'en': 'Indonesian', 'id': 'Bahasa Indonesia'},
|
||||||
|
'en': {'zh': '英语', 'en': 'English', 'id': 'Inggris'},
|
||||||
|
'zh': {'zh': '中文', 'en': 'Chinese', 'id': 'Mandarin'},
|
||||||
|
};
|
||||||
|
|
||||||
|
const _statusNames = {
|
||||||
|
'normal': {'zh': '正常', 'en': 'Active', 'id': 'Aktif'},
|
||||||
|
'limited': {'zh': '受限', 'en': 'Limited', 'id': 'Dibatasi'},
|
||||||
|
'banned': {'zh': '已封禁', 'en': 'Banned', 'id': 'Diblokir'},
|
||||||
|
'deactivated': {'zh': '已注销', 'en': 'Deactivated', 'id': 'Dinonaktifkan'},
|
||||||
|
};
|
||||||
|
|
||||||
|
String _pick(Map<String, String> names, String localeName) =>
|
||||||
|
names[localeName] ?? names['en']!;
|
||||||
|
|
||||||
|
/// 国家码 → 国家名;未收录的码原样返回。
|
||||||
|
String countryName(String code, String localeName) {
|
||||||
|
final key = code.trim().toUpperCase();
|
||||||
|
if (key.isEmpty) return '';
|
||||||
|
final names = localeName == 'zh' ? _countryNamesZh : _countryNamesEn;
|
||||||
|
return names[key] ?? key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// IANA 时区 → 城市名;中文界面查表,其余语言取时区里的城市段。
|
||||||
|
String timezoneName(String timezone, String localeName) {
|
||||||
|
final value = timezone.trim();
|
||||||
|
if (value.isEmpty) return '';
|
||||||
|
if (localeName == 'zh') {
|
||||||
|
final name = _timezoneNamesZh[value];
|
||||||
|
if (name != null) return name;
|
||||||
|
}
|
||||||
|
final city = value.split('/').last.replaceAll('_', ' ');
|
||||||
|
return city.isEmpty ? value : city;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// BCP-47 语言标签 → 语言名,按主语言归类(`zh-TW` 也算中文)。
|
||||||
|
String languageName(String language, String localeName) {
|
||||||
|
final value = language.trim();
|
||||||
|
if (value.isEmpty) return '';
|
||||||
|
final primary = value.split(RegExp('[-_]')).first.toLowerCase();
|
||||||
|
final names = _languageNames[primary];
|
||||||
|
return names == null ? value : _pick(names, localeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 账号状态 → 展示文案;未知状态原样返回。
|
||||||
|
String accountStatusText(String status, String localeName) {
|
||||||
|
final value = status.trim().toLowerCase();
|
||||||
|
final names = _statusNames[value];
|
||||||
|
return names == null ? status : _pick(names, localeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// VIP 等级:0 表示未开通,避免用户看到一个孤零零的 0。
|
||||||
|
String vipLevelText(int level, String localeName) {
|
||||||
|
if (level > 0) return 'VIP $level';
|
||||||
|
return switch (localeName) {
|
||||||
|
'zh' => '未开通',
|
||||||
|
'id' => 'Belum aktif',
|
||||||
|
_ => 'Not subscribed',
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,6 +2,37 @@
|
|||||||
|
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
/// 按后端 `ErrorCode` 取当前语言文案。未收录的业务码回退服务端 message。
|
||||||
|
String userFacingApiMessage(AppLocalizations l10n, int code, String message) {
|
||||||
|
final localized = _apiMessage(l10n, code);
|
||||||
|
if (localized != null) return localized;
|
||||||
|
if (message.isEmpty) return l10n.authServerError;
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 已定义错误码。500 用服务繁忙,不展示「系统异常」。
|
||||||
|
String? _apiMessage(AppLocalizations l10n, int code) {
|
||||||
|
return switch (code) {
|
||||||
|
400 => l10n.apiErrorBadRequest,
|
||||||
|
401 => l10n.apiErrorUnauthorized,
|
||||||
|
403 => l10n.apiErrorForbidden,
|
||||||
|
404 => l10n.apiErrorNotFound,
|
||||||
|
429 => l10n.apiErrorTooManyRequests,
|
||||||
|
500 => l10n.authServerError,
|
||||||
|
100000 => l10n.apiErrorLoginFailed,
|
||||||
|
100001 => l10n.apiErrorAccountDisabled,
|
||||||
|
100002 => l10n.apiErrorCoinNotEnough,
|
||||||
|
100003 => l10n.apiErrorEpisodeUnavailable,
|
||||||
|
100004 => l10n.apiErrorEpisodeUnlocked,
|
||||||
|
100005 => l10n.apiErrorOrderInvalid,
|
||||||
|
100006 => l10n.apiErrorVipExpired,
|
||||||
|
200001 => l10n.apiErrorDataExists,
|
||||||
|
200002 => l10n.apiErrorDataNotFound,
|
||||||
|
200003 => l10n.apiErrorNotAllowed,
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// logic 里的错误在两种情况下是"哨兵值":本地网络异常(读不到后端提示语)与
|
/// logic 里的错误在两种情况下是"哨兵值":本地网络异常(读不到后端提示语)与
|
||||||
/// 我们自己包装的失败。这里统一翻译成当前语言的文案;服务端给的中文提示原样展示。
|
/// 我们自己包装的失败。这里统一翻译成当前语言的文案;服务端给的中文提示原样展示。
|
||||||
String errorText(AppLocalizations l10n, String? code, String fallback) {
|
String errorText(AppLocalizations l10n, String? code, String fallback) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ String localizedDramaTitle(AppLocalizations l10n, Drama drama) =>
|
|||||||
'the-signal-demo' => l10n.dramaSignalTitle,
|
'the-signal-demo' => l10n.dramaSignalTitle,
|
||||||
'city-lights-demo' => l10n.dramaCityTitle,
|
'city-lights-demo' => l10n.dramaCityTitle,
|
||||||
'vengeance-demo' => l10n.dramaVengeanceTitle,
|
'vengeance-demo' => l10n.dramaVengeanceTitle,
|
||||||
_ => drama.title,
|
_ => drama.localizedTitle(l10n.localeName.split(RegExp(r'[_-]')).first),
|
||||||
};
|
};
|
||||||
|
|
||||||
String localizedDramaSynopsis(AppLocalizations l10n, Drama drama) =>
|
String localizedDramaSynopsis(AppLocalizations l10n, Drama drama) =>
|
||||||
@@ -16,7 +16,7 @@ String localizedDramaSynopsis(AppLocalizations l10n, Drama drama) =>
|
|||||||
'the-signal-demo' => l10n.dramaSignalSynopsis,
|
'the-signal-demo' => l10n.dramaSignalSynopsis,
|
||||||
'city-lights-demo' => l10n.dramaCitySynopsis,
|
'city-lights-demo' => l10n.dramaCitySynopsis,
|
||||||
'vengeance-demo' => l10n.dramaVengeanceSynopsis,
|
'vengeance-demo' => l10n.dramaVengeanceSynopsis,
|
||||||
_ => drama.synopsis,
|
_ => drama.localizedSynopsis(l10n.localeName.split(RegExp(r'[_-]')).first),
|
||||||
};
|
};
|
||||||
|
|
||||||
String localizedEpisodeTitle(AppLocalizations l10n, int number) =>
|
String localizedEpisodeTitle(AppLocalizations l10n, int number) =>
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:html/dom.dart' as dom;
|
||||||
|
import 'package:html/parser.dart' as html_parser;
|
||||||
|
|
||||||
|
import '../theme/app_colors.dart';
|
||||||
|
|
||||||
|
const double _bodySize = 16;
|
||||||
|
const double _headingSize = 18;
|
||||||
|
const double _blockGap = 12;
|
||||||
|
const double _lineHeight = 1.7;
|
||||||
|
|
||||||
|
const TextStyle _bodyStyle = TextStyle(
|
||||||
|
color: AppColors.textPrimary,
|
||||||
|
fontSize: _bodySize,
|
||||||
|
height: _lineHeight,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 把协议页的 HTML 正文画成普通控件。
|
||||||
|
class LegalArticleView extends StatelessWidget {
|
||||||
|
const LegalArticleView({super.key, required this.html});
|
||||||
|
|
||||||
|
final String html;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final fragment = html_parser.parseFragment(html);
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
for (final node in fragment.nodes) _block(node),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _block(dom.Node node) {
|
||||||
|
if (node is! dom.Element) {
|
||||||
|
return _paragraph(node.text ?? '');
|
||||||
|
}
|
||||||
|
switch (node.localName) {
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
return _heading(node.text);
|
||||||
|
case 'ul':
|
||||||
|
case 'ol':
|
||||||
|
return _list(node);
|
||||||
|
case 'pre':
|
||||||
|
return _paragraph(node.text);
|
||||||
|
case 'blockquote':
|
||||||
|
return _paragraph(node.text);
|
||||||
|
default:
|
||||||
|
return _paragraphSpan(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _heading(String text) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: _blockGap),
|
||||||
|
child: Text(
|
||||||
|
text.trim(),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: AppColors.textPrimary,
|
||||||
|
fontSize: _headingSize,
|
||||||
|
height: 1.4,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _list(dom.Element element) {
|
||||||
|
final items = element.children.where((child) => child.localName == 'li');
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: _blockGap),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
for (final item in items)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4),
|
||||||
|
child: Text('• ${item.text.trim()}', style: _bodyStyle),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _paragraph(String text) {
|
||||||
|
final value = text.trim();
|
||||||
|
if (value.isEmpty) return const SizedBox.shrink();
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: _blockGap),
|
||||||
|
child: Text(value, style: _bodyStyle),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _paragraphSpan(dom.Element element) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: _blockGap),
|
||||||
|
child: Text.rich(TextSpan(style: _bodyStyle, children: _inlines(element))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InlineSpan> _inlines(dom.Node node) {
|
||||||
|
if (node is dom.Text) {
|
||||||
|
return [TextSpan(text: node.text)];
|
||||||
|
}
|
||||||
|
if (node is! dom.Element) return const [];
|
||||||
|
final children = node.nodes.expand(_inlines).toList();
|
||||||
|
switch (node.localName) {
|
||||||
|
case 'strong':
|
||||||
|
case 'b':
|
||||||
|
return [TextSpan(style: const TextStyle(fontWeight: FontWeight.w700), children: children)];
|
||||||
|
case 'em':
|
||||||
|
case 'i':
|
||||||
|
return [TextSpan(style: const TextStyle(fontStyle: FontStyle.italic), children: children)];
|
||||||
|
case 'a':
|
||||||
|
return [TextSpan(style: const TextStyle(color: AppColors.blue), children: children)];
|
||||||
|
case 'br':
|
||||||
|
return const [TextSpan(text: '\n')];
|
||||||
|
default:
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
|
import '../config/app_config.dart';
|
||||||
|
|
||||||
|
final RegExp _articlePattern = RegExp(
|
||||||
|
'<article>([\\s\\S]*)</article>',
|
||||||
|
caseSensitive: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 从协议页里取出正文。没有 article 时退回整页。
|
||||||
|
String legalArticle(String html) {
|
||||||
|
final match = _articlePattern.firstMatch(html);
|
||||||
|
final body = match?.group(1);
|
||||||
|
if (body == null || body.trim().isEmpty) return html;
|
||||||
|
return body.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 拉取协议页 HTML。不走业务 JSON 包装。
|
||||||
|
Future<String> fetchLegalArticle(String url) async {
|
||||||
|
final dio = Dio(
|
||||||
|
BaseOptions(
|
||||||
|
connectTimeout: AppConfig.requestTimeout,
|
||||||
|
receiveTimeout: AppConfig.requestTimeout,
|
||||||
|
responseType: ResponseType.plain,
|
||||||
|
validateStatus: (code) => code != null && code >= 200 && code < 300,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final response = await dio.get<String>(url);
|
||||||
|
final body = response.data;
|
||||||
|
if (body == null || body.trim().isEmpty) {
|
||||||
|
throw StateError('empty legal page');
|
||||||
|
}
|
||||||
|
return legalArticle(body);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'legal_web_page.dart';
|
||||||
|
|
||||||
|
/// 在当前 App 里打开协议地址。
|
||||||
|
Future<void> openLegalUrlOrNotify(BuildContext context, String url) {
|
||||||
|
return Navigator.of(context).push<void>(
|
||||||
|
MaterialPageRoute<void>(builder: (_) => LegalWebPage(url: url)),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../config/app_config.dart';
|
||||||
|
|
||||||
|
/// 隐私协议公开路径,对应 `/privacy/{语言}`。
|
||||||
|
const String legalPrivacyPath = 'privacy';
|
||||||
|
|
||||||
|
/// 服务条款公开路径,对应 `/terms/{语言}`。
|
||||||
|
const String legalTermsPath = 'terms';
|
||||||
|
|
||||||
|
const Set<String> _legalLanguages = {'zh', 'en', 'id'};
|
||||||
|
|
||||||
|
/// 界面语言落到协议页支持的三种语言。其余语言用英文。
|
||||||
|
String legalLanguageCode(Locale locale) {
|
||||||
|
final code = locale.languageCode;
|
||||||
|
if (_legalLanguages.contains(code)) return code;
|
||||||
|
return 'en';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 拼出当前服务器上的协议页地址。
|
||||||
|
String legalPageUrl(String path, Locale locale) {
|
||||||
|
final base = AppConfig.apiBaseUrl;
|
||||||
|
final root = base.endsWith('/') ? base.substring(0, base.length - 1) : base;
|
||||||
|
return '$root/$path/${legalLanguageCode(locale)}';
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../l10n/app_localizations.dart';
|
||||||
|
import '../theme/app_colors.dart';
|
||||||
|
import '../widgets/plain_page_scaffold.dart';
|
||||||
|
import 'legal_article_view.dart';
|
||||||
|
import 'legal_html.dart';
|
||||||
|
|
||||||
|
const double _pagePadding = 20;
|
||||||
|
|
||||||
|
/// 在应用内展示协议页,不使用系统 WebView。
|
||||||
|
class LegalWebPage extends StatefulWidget {
|
||||||
|
const LegalWebPage({super.key, required this.url, this.load});
|
||||||
|
|
||||||
|
final String url;
|
||||||
|
|
||||||
|
/// 测试时可替换网络请求。
|
||||||
|
final Future<String> Function(String url)? load;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<LegalWebPage> createState() => _LegalWebPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LegalWebPageState extends State<LegalWebPage> {
|
||||||
|
String? _html;
|
||||||
|
var _failed = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_load();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _load() async {
|
||||||
|
setState(() {
|
||||||
|
_html = null;
|
||||||
|
_failed = false;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
final loader = widget.load ?? fetchLegalArticle;
|
||||||
|
final html = await loader(widget.url);
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _html = html);
|
||||||
|
} catch (_) {
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _failed = true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return PlainPageScaffold(
|
||||||
|
pageKey: const Key('legal-web-page'),
|
||||||
|
backKey: const Key('legal-web-back'),
|
||||||
|
title: '',
|
||||||
|
child: _body(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _body(BuildContext context) {
|
||||||
|
final html = _html;
|
||||||
|
if (html != null) {
|
||||||
|
return ListView(
|
||||||
|
padding: const EdgeInsets.fromLTRB(_pagePadding, 8, _pagePadding, 28),
|
||||||
|
children: [
|
||||||
|
LegalArticleView(html: html),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (_failed) return _failure(context);
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
key: Key('legal-web-loading'),
|
||||||
|
color: AppColors.blue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _failure(BuildContext context) {
|
||||||
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(l10n.legalOpenFailed, style: const TextStyle(color: AppColors.muted)),
|
||||||
|
TextButton(
|
||||||
|
key: const Key('legal-web-retry'),
|
||||||
|
onPressed: _load,
|
||||||
|
child: Text(l10n.retry),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@ import 'package:flutter/widgets.dart';
|
|||||||
|
|
||||||
/// 无位移的短促淡入转场。
|
/// 无位移的短促淡入转场。
|
||||||
class FadePageRoute<T> extends PageRouteBuilder<T> {
|
class FadePageRoute<T> extends PageRouteBuilder<T> {
|
||||||
FadePageRoute({required WidgetBuilder builder, super.settings})
|
FadePageRoute({
|
||||||
: super(
|
required WidgetBuilder builder,
|
||||||
transitionDuration: const Duration(milliseconds: 220),
|
super.settings,
|
||||||
reverseTransitionDuration: const Duration(milliseconds: 180),
|
super.transitionDuration = const Duration(milliseconds: 220),
|
||||||
|
super.reverseTransitionDuration = const Duration(milliseconds: 180),
|
||||||
|
}) : super(
|
||||||
pageBuilder: (context, _, _) => builder(context),
|
pageBuilder: (context, _, _) => builder(context),
|
||||||
transitionsBuilder: (context, animation, _, child) => FadeTransition(
|
transitionsBuilder: (context, animation, _, child) => FadeTransition(
|
||||||
opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut),
|
opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut),
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
/// iOS 首次启动等待系统无线数据选择,再发首个接口请求。
|
||||||
|
abstract final class WirelessDataPrompt {
|
||||||
|
const WirelessDataPrompt._();
|
||||||
|
|
||||||
|
/// 系统选择超过此时长仍未回调时继续启动。
|
||||||
|
static const Duration decisionTimeout = Duration(seconds: 15);
|
||||||
|
|
||||||
|
/// 与 iOS `WirelessDataPrompt.channelName` 保持一致。
|
||||||
|
static const String channelName = 'com.stormg.lumadrama/wireless-data';
|
||||||
|
|
||||||
|
static const String _awaitDecisionMethod = 'awaitDecision';
|
||||||
|
|
||||||
|
static const MethodChannel _channel = MethodChannel(channelName);
|
||||||
|
|
||||||
|
static Future<void>? _pending;
|
||||||
|
|
||||||
|
/// 非 iOS 立即返回。iOS 只等待一次,失败或超时后放行。
|
||||||
|
static Future<void> awaitDecision({
|
||||||
|
required bool enabled,
|
||||||
|
Future<void> Function()? ask,
|
||||||
|
Duration? timeout,
|
||||||
|
}) {
|
||||||
|
if (!enabled) return Future<void>.value();
|
||||||
|
return _pending ??= _askOnce(ask, timeout ?? decisionTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 测试隔离用,清掉已完成的等待。
|
||||||
|
@visibleForTesting
|
||||||
|
static void resetForTest() {
|
||||||
|
_pending = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _askOnce(
|
||||||
|
Future<void> Function()? ask,
|
||||||
|
Duration timeout,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
await (ask ?? _invokeChannel).call().timeout(timeout);
|
||||||
|
} on TimeoutException {
|
||||||
|
_log('decision timed out');
|
||||||
|
} catch (error) {
|
||||||
|
_log('decision skipped: $error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _invokeChannel() {
|
||||||
|
return _channel.invokeMethod<void>(_awaitDecisionMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _log(String message) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint('[wireless-data] $message');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,12 @@ abstract final class AppColors {
|
|||||||
/// 中性深灰卡片与控件表面。
|
/// 中性深灰卡片与控件表面。
|
||||||
static const contentCard = Color(0xFF16161A);
|
static const contentCard = Color(0xFF16161A);
|
||||||
static const contentSurface = Color(0xFF1C1C1E);
|
static const contentSurface = Color(0xFF1C1C1E);
|
||||||
|
|
||||||
|
/// 首页、分类与搜索网格骨架的极暗底色。
|
||||||
|
static const skeletonSurface = Color(0xFF0E0E0E);
|
||||||
|
|
||||||
|
/// 播放器、推荐与详情页大面积媒体占位的深灰底色。
|
||||||
|
static const skeletonMedia = Color(0xFF1C1C1E);
|
||||||
static const contentChip = Color(0xFF2C2C2E);
|
static const contentChip = Color(0xFF2C2C2E);
|
||||||
static const contentBorder = Color(0x1AFFFFFF);
|
static const contentBorder = Color(0x1AFFFFFF);
|
||||||
static const filterChipSelected = Color(0xFF21090E);
|
static const filterChipSelected = Color(0xFF21090E);
|
||||||
@@ -104,12 +110,16 @@ abstract final class AppColors {
|
|||||||
static const mineIconSupport = Color(0xFFA78BFA);
|
static const mineIconSupport = Color(0xFFA78BFA);
|
||||||
static const mineIconLanguage = Color(0xFF22D3EE);
|
static const mineIconLanguage = Color(0xFF22D3EE);
|
||||||
static const mineIconSettings = Color(0xFFA1A1AA);
|
static const mineIconSettings = Color(0xFFA1A1AA);
|
||||||
|
static const mineIconNotices = Color(0xFFFF8A4C);
|
||||||
static const recommendPlaylistGlow = Color(0x26FF6B2C);
|
static const recommendPlaylistGlow = Color(0x26FF6B2C);
|
||||||
|
|
||||||
/// 次级文字与列表 chevron。
|
/// 次级文字与列表 chevron。
|
||||||
static const textPrimary = Color(0xFFFFFFFF);
|
static const textPrimary = Color(0xFFFFFFFF);
|
||||||
static const textSecondary = Color(0xFFB0B0B0);
|
static const textSecondary = Color(0xFFB0B0B0);
|
||||||
static const textTertiary = Color(0xFF8E8E93);
|
static const textTertiary = Color(0xFF8E8E93);
|
||||||
|
|
||||||
|
/// 列表底部「没有更多了」这类弱提示。
|
||||||
|
static const textHint = Color(0xFF5C5C60);
|
||||||
static const textTabInactive = Color(0xFFB0B0B0);
|
static const textTabInactive = Color(0xFFB0B0B0);
|
||||||
static const textFilterIcon = Color(0xFF7A7A7E);
|
static const textFilterIcon = Color(0xFF7A7A7E);
|
||||||
static const searchResultMeta = Color(0xFF9E9E9E);
|
static const searchResultMeta = Color(0xFF9E9E9E);
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ abstract final class AppDimens {
|
|||||||
static const double cardBadgeFont = 9;
|
static const double cardBadgeFont = 9;
|
||||||
static const double cardCoverTitleGap = 6;
|
static const double cardCoverTitleGap = 6;
|
||||||
static const double cardTitleTagGap = 6;
|
static const double cardTitleTagGap = 6;
|
||||||
|
static const double skeletonBarHeight = 10;
|
||||||
|
static const double skeletonBarRadius = 4;
|
||||||
|
static const double skeletonBarGap = 4;
|
||||||
|
static const double skeletonTitleBarGap = 3;
|
||||||
|
static const double skeletonBodyExtent = 34;
|
||||||
static const double cardCoverAspectRatio = 3 / 4;
|
static const double cardCoverAspectRatio = 3 / 4;
|
||||||
static const double homeCardBodyExtent = 84;
|
static const double homeCardBodyExtent = 84;
|
||||||
static const double homePrimaryTabFont = 18;
|
static const double homePrimaryTabFont = 18;
|
||||||
@@ -182,7 +187,7 @@ abstract final class AppDimens {
|
|||||||
static const double followingAddIconStroke = 1.5;
|
static const double followingAddIconStroke = 1.5;
|
||||||
static const double followingGridGap = 6;
|
static const double followingGridGap = 6;
|
||||||
static const double followingGridRowGap = 12;
|
static const double followingGridRowGap = 12;
|
||||||
static const double followingCardTextExtent = 66;
|
static const double followingCardTextExtent = 70;
|
||||||
static const double followingSubtitleFont = 12;
|
static const double followingSubtitleFont = 12;
|
||||||
static const double followingSubtitleGap = 4;
|
static const double followingSubtitleGap = 4;
|
||||||
static const double followingProgressHeight = 2;
|
static const double followingProgressHeight = 2;
|
||||||
@@ -224,7 +229,7 @@ abstract final class AppDimens {
|
|||||||
static const double mineSectionLinkFont = 12;
|
static const double mineSectionLinkFont = 12;
|
||||||
static const double mineSectionGap = 20;
|
static const double mineSectionGap = 20;
|
||||||
static const double mineContinueCardWidth = 96;
|
static const double mineContinueCardWidth = 96;
|
||||||
static const double mineContinueRowHeight = 168;
|
static const double mineContinueRowHeight = 172;
|
||||||
static const double mineContinueTitleFont = 13;
|
static const double mineContinueTitleFont = 13;
|
||||||
static const double mineContinueMetaFont = 11;
|
static const double mineContinueMetaFont = 11;
|
||||||
static const double mineStatsValueFont = 18;
|
static const double mineStatsValueFont = 18;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Future<void> openAuthPage(BuildContext context, {bool signUpMode = false}) {
|
|||||||
|
|
||||||
/// 受限动作的登录闸:已登录返回 true;未登录弹底部提示并引导登录,返回 false。
|
/// 受限动作的登录闸:已登录返回 true;未登录弹底部提示并引导登录,返回 false。
|
||||||
///
|
///
|
||||||
/// 首页/发现/详情保持匿名可看,只有收藏、点赞、评论这类"要对到具体账号"的动作才走这里。
|
/// 首页/发现/详情与非付费互动保持匿名可用;解锁、权益与消耗类动作走这里。
|
||||||
Future<bool> ensureSignedIn(BuildContext context) async {
|
Future<bool> ensureSignedIn(BuildContext context) async {
|
||||||
final auth = context.read<AuthController>();
|
final auth = context.read<AuthController>();
|
||||||
if (auth.isSignedIn) return true;
|
if (auth.isSignedIn) return true;
|
||||||
@@ -76,6 +76,7 @@ Future<bool> ensureSignedIn(BuildContext context) async {
|
|||||||
|
|
||||||
if (go == true && context.mounted) {
|
if (go == true && context.mounted) {
|
||||||
await openAuthPage(context);
|
await openAuthPage(context);
|
||||||
|
if (context.mounted) return context.read<AuthController>().isSignedIn;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../theme/app_colors.dart';
|
||||||
|
import '../theme/app_dimens.dart';
|
||||||
|
|
||||||
|
const Duration _shimmerPeriod = Duration(milliseconds: 1400);
|
||||||
|
const double _shimmerTravel = 2.4;
|
||||||
|
const double _shimmerStart = -1.2;
|
||||||
|
const double _subtitleWidthFactor = 0.62;
|
||||||
|
const double _shimmerPhaseStep = 0.13;
|
||||||
|
const Color _shimmerHighlight = Color(0x0DFFFFFF);
|
||||||
|
|
||||||
|
/// 首页短剧网格的占位。行数至少铺满可视高度,并带一道扫光。
|
||||||
|
class DramaGridSkeleton extends StatefulWidget {
|
||||||
|
const DramaGridSkeleton({
|
||||||
|
super.key,
|
||||||
|
required this.columns,
|
||||||
|
required this.horizontalPadding,
|
||||||
|
required this.crossAxisSpacing,
|
||||||
|
required this.mainAxisSpacing,
|
||||||
|
this.itemCount = 9,
|
||||||
|
this.physics = const NeverScrollableScrollPhysics(),
|
||||||
|
});
|
||||||
|
|
||||||
|
final int columns;
|
||||||
|
final double horizontalPadding;
|
||||||
|
final double crossAxisSpacing;
|
||||||
|
final double mainAxisSpacing;
|
||||||
|
final int itemCount;
|
||||||
|
final ScrollPhysics physics;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DramaGridSkeleton> createState() => _DramaGridSkeletonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DramaGridSkeletonState extends State<DramaGridSkeleton>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
late final AnimationController _shimmer = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: _shimmerPeriod,
|
||||||
|
)..repeat();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_shimmer.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return AnimatedBuilder(
|
||||||
|
animation: _shimmer,
|
||||||
|
builder: (context, _) => _grid(
|
||||||
|
constraints.maxWidth,
|
||||||
|
constraints.maxHeight,
|
||||||
|
_shimmer.value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _grid(double width, double height, double shimmerValue) {
|
||||||
|
final itemWidth = _itemWidth(width);
|
||||||
|
final itemExtent = _itemExtent(itemWidth);
|
||||||
|
return GridView.builder(
|
||||||
|
physics: widget.physics,
|
||||||
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
widget.horizontalPadding,
|
||||||
|
AppDimens.spaceMd,
|
||||||
|
widget.horizontalPadding,
|
||||||
|
AppDimens.spaceXl,
|
||||||
|
),
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: widget.columns,
|
||||||
|
crossAxisSpacing: widget.crossAxisSpacing,
|
||||||
|
mainAxisSpacing: widget.mainAxisSpacing,
|
||||||
|
mainAxisExtent: itemExtent,
|
||||||
|
),
|
||||||
|
itemCount: _fillCount(height, itemExtent),
|
||||||
|
itemBuilder: (context, index) =>
|
||||||
|
_SkeletonCard(index: index, shimmerValue: shimmerValue),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
double _itemWidth(double width) {
|
||||||
|
final gaps = widget.crossAxisSpacing * (widget.columns - 1);
|
||||||
|
return (width - widget.horizontalPadding * 2 - gaps) / widget.columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
double _itemExtent(double itemWidth) {
|
||||||
|
return itemWidth / AppDimens.cardCoverAspectRatio +
|
||||||
|
AppDimens.skeletonBodyExtent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _fillCount(double height, double extent) {
|
||||||
|
if (!height.isFinite || extent <= 0) return widget.itemCount;
|
||||||
|
final rowHeight = extent + widget.mainAxisSpacing;
|
||||||
|
final rows = (height / rowHeight).ceil() + 1;
|
||||||
|
return math.max(widget.itemCount, rows * widget.columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SkeletonCard extends StatelessWidget {
|
||||||
|
const _SkeletonCard({required this.index, required this.shimmerValue});
|
||||||
|
|
||||||
|
final int index;
|
||||||
|
final double shimmerValue;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final phase = (shimmerValue + index * _shimmerPhaseStep) % 1.0;
|
||||||
|
return Stack(
|
||||||
|
key: Key('drama-grid-skeleton-$index'),
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
AspectRatio(
|
||||||
|
aspectRatio: AppDimens.cardCoverAspectRatio,
|
||||||
|
child: const _SkeletonBlock(),
|
||||||
|
),
|
||||||
|
const SizedBox(height: AppDimens.cardCoverTitleGap),
|
||||||
|
const _SkeletonBar(),
|
||||||
|
const SizedBox(height: AppDimens.skeletonTitleBarGap),
|
||||||
|
const FractionallySizedBox(
|
||||||
|
widthFactor: _subtitleWidthFactor,
|
||||||
|
child: _SkeletonBar(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: IgnorePointer(
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(AppDimens.homeCardRadius),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(gradient: _cardHighlight(phase)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LinearGradient _cardHighlight(double shimmerValue) {
|
||||||
|
final shift = _shimmerStart + _shimmerTravel * shimmerValue;
|
||||||
|
return LinearGradient(
|
||||||
|
begin: Alignment(shift, -0.3),
|
||||||
|
end: Alignment(shift + 1, 0.3),
|
||||||
|
colors: const [Colors.transparent, _shimmerHighlight, Colors.transparent],
|
||||||
|
stops: const [0.42, 0.5, 0.58],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SkeletonBlock extends StatelessWidget {
|
||||||
|
const _SkeletonBlock();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.skeletonSurface,
|
||||||
|
borderRadius: BorderRadius.circular(AppDimens.homeCardRadius),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SkeletonBar extends StatelessWidget {
|
||||||
|
const _SkeletonBar();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
height: AppDimens.skeletonBarHeight,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.skeletonSurface,
|
||||||
|
borderRadius: BorderRadius.circular(AppDimens.skeletonBarRadius),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ import 'package:flutter/material.dart';
|
|||||||
import '../theme/app_colors.dart';
|
import '../theme/app_colors.dart';
|
||||||
import '../theme/app_dimens.dart';
|
import '../theme/app_dimens.dart';
|
||||||
|
|
||||||
const double _regularIconSize = 48;
|
const double _regularIconSize = 72;
|
||||||
const double _compactIconSize = 32;
|
const double _compactIconSize = 44;
|
||||||
const double _maxContentWidth = 260;
|
const double _maxContentWidth = 260;
|
||||||
const double _regularHorizontal = 24;
|
const double _regularHorizontal = 24;
|
||||||
const double _regularVertical = 28;
|
const double _regularVertical = 28;
|
||||||
@@ -78,7 +78,7 @@ class EmptyState extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 空状态只留一枚图标,不加水印底和描边。
|
/// 空列表只放一枚大图标,不画线框,也不铺底色。
|
||||||
class _EmptyMark extends StatelessWidget {
|
class _EmptyMark extends StatelessWidget {
|
||||||
const _EmptyMark({required this.icon, required this.compact});
|
const _EmptyMark({required this.icon, required this.compact});
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ class _EmptyMark extends StatelessWidget {
|
|||||||
icon,
|
icon,
|
||||||
key: const Key('empty-state-icon'),
|
key: const Key('empty-state-icon'),
|
||||||
size: compact ? _compactIconSize : _regularIconSize,
|
size: compact ? _compactIconSize : _regularIconSize,
|
||||||
color: AppColors.blueSoft,
|
color: AppColors.subtle,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,6 @@ class _EmptyCopy extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final scheme = Theme.of(context).colorScheme;
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -126,10 +125,10 @@ class _EmptyCopy extends StatelessWidget {
|
|||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
color: scheme.onSurface,
|
color: AppColors.textTertiary,
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w400,
|
||||||
height: 1.35,
|
height: 1.35,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -8,19 +8,27 @@ import '../theme/app_colors.dart';
|
|||||||
import '../theme/app_dimens.dart';
|
import '../theme/app_dimens.dart';
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
/// 网络分页列表底部状态:仅保留加载圈与错误重试。
|
/// 网络分页列表底部:加载中、失败重试、没有下一页。
|
||||||
class PagedListFooter extends StatelessWidget {
|
class PagedListFooter extends StatelessWidget {
|
||||||
const PagedListFooter({
|
const PagedListFooter({
|
||||||
super.key,
|
super.key,
|
||||||
required this.loading,
|
required this.loading,
|
||||||
required this.onRetry,
|
required this.onRetry,
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
|
this.hasMore = true,
|
||||||
|
this.hasItems = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool loading;
|
final bool loading;
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
final Future<void> Function() onRetry;
|
final Future<void> Function() onRetry;
|
||||||
|
|
||||||
|
/// 还有下一页时不显示结束文案。
|
||||||
|
final bool hasMore;
|
||||||
|
|
||||||
|
/// 列表为空时不显示「没有更多了」。
|
||||||
|
final bool hasItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
@@ -58,6 +66,17 @@ class PagedListFooter extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (hasItems && !hasMore) {
|
||||||
|
return Padding(
|
||||||
|
key: const Key('paged-list-no-more'),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
child: Text(
|
||||||
|
l10n.noMoreItems,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(color: AppColors.textHint, fontSize: 12),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../l10n/app_localizations.dart';
|
||||||
import '../theme/app_colors.dart';
|
import '../theme/app_colors.dart';
|
||||||
import '../theme/app_dimens.dart';
|
import '../theme/app_dimens.dart';
|
||||||
|
|
||||||
@@ -71,10 +72,14 @@ class PagedLoadFooter extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.loading,
|
required this.loading,
|
||||||
required this.loadMoreKey,
|
required this.loadMoreKey,
|
||||||
|
this.hasMore = true,
|
||||||
|
this.hasItems = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool loading;
|
final bool loading;
|
||||||
final Key loadMoreKey;
|
final Key loadMoreKey;
|
||||||
|
final bool hasMore;
|
||||||
|
final bool hasItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -93,6 +98,18 @@ class PagedLoadFooter extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (hasItems && !hasMore) {
|
||||||
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
return Padding(
|
||||||
|
key: const Key('paged-list-no-more'),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
child: Text(
|
||||||
|
l10n.noMoreItems,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(color: AppColors.textHint, fontSize: 12),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,24 @@ import 'package:flutter/material.dart';
|
|||||||
import '../config/app_config.dart';
|
import '../config/app_config.dart';
|
||||||
import '../theme/app_colors.dart';
|
import '../theme/app_colors.dart';
|
||||||
|
|
||||||
|
const int _minImageDecodePixels = 96;
|
||||||
|
const int _maxImageDecodePixels = 2048;
|
||||||
|
|
||||||
|
/// 将布局逻辑尺寸换算成有限像素尺寸,兼顾小头像和全屏首帧。
|
||||||
|
int resolveImageDecodePixels(double? logicalExtent, double devicePixelRatio) {
|
||||||
|
final ratio = devicePixelRatio.isFinite && devicePixelRatio > 0
|
||||||
|
? devicePixelRatio
|
||||||
|
: 1.0;
|
||||||
|
final extent =
|
||||||
|
logicalExtent != null && logicalExtent.isFinite && logicalExtent > 0
|
||||||
|
? logicalExtent
|
||||||
|
: 120.0;
|
||||||
|
return (extent * ratio)
|
||||||
|
.ceil()
|
||||||
|
.clamp(_minImageDecodePixels, _maxImageDecodePixels)
|
||||||
|
.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
/// 封面图统一入口:后端给的是相对路径,这里补服务地址并处理加载失败。
|
/// 封面图统一入口:后端给的是相对路径,这里补服务地址并处理加载失败。
|
||||||
class RemoteImage extends StatelessWidget {
|
class RemoteImage extends StatelessWidget {
|
||||||
const RemoteImage(
|
const RemoteImage(
|
||||||
@@ -17,6 +35,8 @@ class RemoteImage extends StatelessWidget {
|
|||||||
this.fallbackIconKey,
|
this.fallbackIconKey,
|
||||||
this.fallbackAspectRatio,
|
this.fallbackAspectRatio,
|
||||||
this.fallbackColor = AppColors.raised,
|
this.fallbackColor = AppColors.raised,
|
||||||
|
this.decodeWidth,
|
||||||
|
this.decodeHeight,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String path;
|
final String path;
|
||||||
@@ -27,38 +47,84 @@ class RemoteImage extends StatelessWidget {
|
|||||||
final Key? fallbackIconKey;
|
final Key? fallbackIconKey;
|
||||||
final double? fallbackAspectRatio;
|
final double? fallbackAspectRatio;
|
||||||
final Color fallbackColor;
|
final Color fallbackColor;
|
||||||
|
final int? decodeWidth;
|
||||||
|
final int? decodeHeight;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final url = AppConfig.mediaUrl(path);
|
final url = AppConfig.mediaUrl(path);
|
||||||
if (url.isEmpty) return _fallback();
|
if (url.isEmpty) return _fallback(brand: showFallbackIcon);
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final pixelRatio = MediaQuery.devicePixelRatioOf(context);
|
||||||
|
final layoutWidth = constraints.hasBoundedWidth
|
||||||
|
? constraints.maxWidth
|
||||||
|
: width;
|
||||||
|
final aspectRatio =
|
||||||
|
fallbackAspectRatio != null &&
|
||||||
|
fallbackAspectRatio!.isFinite &&
|
||||||
|
fallbackAspectRatio! > 0
|
||||||
|
? fallbackAspectRatio
|
||||||
|
: null;
|
||||||
|
final inferredHeight = constraints.hasBoundedHeight
|
||||||
|
? constraints.maxHeight
|
||||||
|
: height ??
|
||||||
|
(layoutWidth != null && aspectRatio != null
|
||||||
|
? layoutWidth / aspectRatio
|
||||||
|
: null);
|
||||||
|
final cacheWidth =
|
||||||
|
decodeWidth ?? resolveImageDecodePixels(layoutWidth, pixelRatio);
|
||||||
|
final cacheHeight =
|
||||||
|
decodeHeight ??
|
||||||
|
(inferredHeight == null
|
||||||
|
? null
|
||||||
|
: resolveImageDecodePixels(inferredHeight, pixelRatio));
|
||||||
return Image.network(
|
return Image.network(
|
||||||
url,
|
url,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
fit: fit,
|
fit: fit,
|
||||||
errorBuilder: (_, _, _) => _fallback(),
|
cacheWidth: cacheWidth
|
||||||
|
.clamp(_minImageDecodePixels, _maxImageDecodePixels)
|
||||||
|
.toInt(),
|
||||||
|
cacheHeight: cacheHeight
|
||||||
|
?.clamp(_minImageDecodePixels, _maxImageDecodePixels)
|
||||||
|
.toInt(),
|
||||||
|
gaplessPlayback: true,
|
||||||
|
errorBuilder: (_, _, _) => _fallback(brand: showFallbackIcon),
|
||||||
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
|
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
|
||||||
if (wasSynchronouslyLoaded || frame != null) return child;
|
if (wasSynchronouslyLoaded || frame != null) return child;
|
||||||
return _fallback();
|
return _fallback(brand: showFallbackIcon);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _fallback() {
|
Widget _fallback({required bool brand}) {
|
||||||
|
final mark = brand
|
||||||
|
? LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final width = constraints.maxWidth.isFinite
|
||||||
|
? constraints.maxWidth
|
||||||
|
: 120.0;
|
||||||
|
return Center(
|
||||||
|
child: Image.asset(
|
||||||
|
'assets/icon/splash_logo.png',
|
||||||
|
key: fallbackIconKey,
|
||||||
|
width: width * 0.72,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: null;
|
||||||
final fallback = Container(
|
final fallback = Container(
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
color: fallbackColor,
|
color: brand ? AppColors.mediaBlack : fallbackColor,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: showFallbackIcon
|
child: mark,
|
||||||
? Icon(
|
|
||||||
Icons.image_not_supported_outlined,
|
|
||||||
key: fallbackIconKey,
|
|
||||||
color: AppColors.muted,
|
|
||||||
size: 32,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
final ratio = fallbackAspectRatio;
|
final ratio = fallbackAspectRatio;
|
||||||
if (ratio == null) return fallback;
|
if (ratio == null) return fallback;
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ const double _titleFontSize = 18;
|
|||||||
const double _subtitleFontSize = 12;
|
const double _subtitleFontSize = 12;
|
||||||
const double _actionGap = 8;
|
const double _actionGap = 8;
|
||||||
const double _iconSize = 22;
|
const double _iconSize = 22;
|
||||||
|
const double _backIconSize = 34;
|
||||||
const double _iconWeight = 600;
|
const double _iconWeight = 600;
|
||||||
|
const double _backIconWeight = 400;
|
||||||
const double _shadowBlur = 8;
|
const double _shadowBlur = 8;
|
||||||
|
|
||||||
/// 二级页面统一圆形操作按钮,返回、分享和更多共用同一尺寸与表面样式。
|
/// 二级页面统一圆形操作按钮,返回、分享和更多共用同一尺寸与表面样式。
|
||||||
@@ -24,6 +26,8 @@ class AppSubpageCircleButton extends StatelessWidget {
|
|||||||
required this.tooltip,
|
required this.tooltip,
|
||||||
required this.icon,
|
required this.icon,
|
||||||
required this.onPressed,
|
required this.onPressed,
|
||||||
|
this.iconSize = _iconSize,
|
||||||
|
this.iconWeight = _iconWeight,
|
||||||
this.dark = false,
|
this.dark = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -31,6 +35,8 @@ class AppSubpageCircleButton extends StatelessWidget {
|
|||||||
final String tooltip;
|
final String tooltip;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
|
final double iconSize;
|
||||||
|
final double iconWeight;
|
||||||
final bool dark;
|
final bool dark;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -65,8 +71,8 @@ class AppSubpageCircleButton extends StatelessWidget {
|
|||||||
child: Icon(
|
child: Icon(
|
||||||
icon,
|
icon,
|
||||||
color: dark ? AppColors.onSurface : AppColors.textPrimary,
|
color: dark ? AppColors.onSurface : AppColors.textPrimary,
|
||||||
size: _iconSize,
|
size: iconSize,
|
||||||
weight: _iconWeight,
|
weight: iconWeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -96,6 +102,8 @@ class AppSubpageBackButton extends StatelessWidget {
|
|||||||
buttonKey: backKey,
|
buttonKey: backKey,
|
||||||
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
|
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
|
||||||
icon: Icons.chevron_left_rounded,
|
icon: Icons.chevron_left_rounded,
|
||||||
|
iconSize: _backIconSize,
|
||||||
|
iconWeight: _backIconWeight,
|
||||||
dark: dark,
|
dark: dark,
|
||||||
onPressed: onBack ?? () => Navigator.of(context).maybePop(),
|
onPressed: onBack ?? () => Navigator.of(context).maybePop(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,6 +23,13 @@
|
|||||||
"authLandingSubtitle": "Sign in to sync progress, favorites and coins",
|
"authLandingSubtitle": "Sign in to sync progress, favorites and coins",
|
||||||
"comingSoon": "Coming soon",
|
"comingSoon": "Coming soon",
|
||||||
"authLegal": "By continuing, you agree to the Terms of Service and Privacy Policy.",
|
"authLegal": "By continuing, you agree to the Terms of Service and Privacy Policy.",
|
||||||
|
"authLegalLead": "By continuing, you agree to the",
|
||||||
|
"authTerms": "Terms of Service",
|
||||||
|
"authLegalJoin": "and",
|
||||||
|
"authPrivacy": "Privacy Policy",
|
||||||
|
"legalTerms": "Terms of Service",
|
||||||
|
"legalPrivacy": "Privacy Policy",
|
||||||
|
"legalOpenFailed": "Can't open this page right now",
|
||||||
"authContinueGoogle": "Continue with Google",
|
"authContinueGoogle": "Continue with Google",
|
||||||
"authPhoneSignIn": "Phone sign in",
|
"authPhoneSignIn": "Phone sign in",
|
||||||
"authEmailSignIn": "Email sign in",
|
"authEmailSignIn": "Email sign in",
|
||||||
@@ -212,6 +219,7 @@
|
|||||||
"postComment": "Post",
|
"postComment": "Post",
|
||||||
"commentPostSuccess": "Comment posted",
|
"commentPostSuccess": "Comment posted",
|
||||||
"loadMore": "Load more",
|
"loadMore": "Load more",
|
||||||
|
"noMoreItems": "No more",
|
||||||
"commentsLoadFailed": "Comments could not be loaded.",
|
"commentsLoadFailed": "Comments could not be loaded.",
|
||||||
"commentPostFailed": "Could not post your comment.",
|
"commentPostFailed": "Could not post your comment.",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
@@ -430,6 +438,22 @@
|
|||||||
"authPasswordLength": "Password must be 8-64 characters",
|
"authPasswordLength": "Password must be 8-64 characters",
|
||||||
"authPasswordWeak": "Password needs both letters and numbers",
|
"authPasswordWeak": "Password needs both letters and numbers",
|
||||||
"authNetworkError": "Network error, please try again",
|
"authNetworkError": "Network error, please try again",
|
||||||
|
"authServerError": "The service is busy. Please try again shortly.",
|
||||||
|
"apiErrorBadRequest": "Invalid request",
|
||||||
|
"apiErrorUnauthorized": "Sign in to continue",
|
||||||
|
"apiErrorForbidden": "You don't have permission",
|
||||||
|
"apiErrorNotFound": "Not found",
|
||||||
|
"apiErrorTooManyRequests": "Too many requests. Please try again later.",
|
||||||
|
"apiErrorLoginFailed": "Incorrect account or password",
|
||||||
|
"apiErrorAccountDisabled": "This account has been disabled",
|
||||||
|
"apiErrorCoinNotEnough": "Not enough coins",
|
||||||
|
"apiErrorEpisodeUnavailable": "This episode is unavailable",
|
||||||
|
"apiErrorEpisodeUnlocked": "This episode is already unlocked",
|
||||||
|
"apiErrorOrderInvalid": "This order is already paid or closed",
|
||||||
|
"apiErrorVipExpired": "Membership has expired",
|
||||||
|
"apiErrorDataExists": "This record already exists",
|
||||||
|
"apiErrorDataNotFound": "Not found",
|
||||||
|
"apiErrorNotAllowed": "This action isn't available right now",
|
||||||
"authSwitchToSignUp": "New here? Create an account",
|
"authSwitchToSignUp": "New here? Create an account",
|
||||||
"authSwitchToSignIn": "Already have an account? Sign in",
|
"authSwitchToSignIn": "Already have an account? Sign in",
|
||||||
"authGateTitle": "Sign in to continue",
|
"authGateTitle": "Sign in to continue",
|
||||||
@@ -586,7 +610,7 @@
|
|||||||
"accountUnverified": "Unverified",
|
"accountUnverified": "Unverified",
|
||||||
"accountDeactivateWarning": "Requests enter a 15-day cooling-off period. All devices are signed out immediately.",
|
"accountDeactivateWarning": "Requests enter a 15-day cooling-off period. All devices are signed out immediately.",
|
||||||
"accountDeactivateReason": "Reason (optional)",
|
"accountDeactivateReason": "Reason (optional)",
|
||||||
"accountDeactivateReasonHint": "Tell us why you are leaving",
|
"accountDeactivateReasonHint": "Add more detail here",
|
||||||
"accountRequestDeactivate": "Request account deletion",
|
"accountRequestDeactivate": "Request account deletion",
|
||||||
"accountConfirmDeactivateTitle": "Request account deletion?",
|
"accountConfirmDeactivateTitle": "Request account deletion?",
|
||||||
"accountConfirmDeactivateMessage": "All devices will be signed out immediately. You can cancel during the 15-day cooling-off period after signing in again.",
|
"accountConfirmDeactivateMessage": "All devices will be signed out immediately. You can cancel during the 15-day cooling-off period after signing in again.",
|
||||||
@@ -666,6 +690,8 @@
|
|||||||
"paymentPending": "Waiting for payment.",
|
"paymentPending": "Waiting for payment.",
|
||||||
"orderCreateFailed": "Could not create the order.",
|
"orderCreateFailed": "Could not create the order.",
|
||||||
"playbackQuality": "Quality",
|
"playbackQuality": "Quality",
|
||||||
|
"qualitySwitched": "Switched to {quality}",
|
||||||
|
"@qualitySwitched": { "placeholders": { "quality": { "type": "String" } } },
|
||||||
"qualityAuto": "Auto",
|
"qualityAuto": "Auto",
|
||||||
"qualityAutoHint": "HLS adjusts the bitrate automatically for your connection.",
|
"qualityAutoHint": "HLS adjusts the bitrate automatically for your connection.",
|
||||||
"searchFailed": "Search failed. Please try again.",
|
"searchFailed": "Search failed. Please try again.",
|
||||||
@@ -708,8 +734,7 @@
|
|||||||
"homeBadgeHot": "Hot",
|
"homeBadgeHot": "Hot",
|
||||||
"homeBadgeNew": "New",
|
"homeBadgeNew": "New",
|
||||||
"homeBadgeAnime": "Anime",
|
"homeBadgeAnime": "Anime",
|
||||||
"homeGridFilterEmpty": "No dramas match these filters",
|
"emptyContent": "No content yet",
|
||||||
"homeGridClearFilter": "Clear filters",
|
|
||||||
"recommendTopTab": "Recommend",
|
"recommendTopTab": "Recommend",
|
||||||
"playlistTopTab": "Playlists",
|
"playlistTopTab": "Playlists",
|
||||||
"allDramasTopTab": "All Dramas",
|
"allDramasTopTab": "All Dramas",
|
||||||
@@ -728,6 +753,10 @@
|
|||||||
"modernFilter": "Modern",
|
"modernFilter": "Modern",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"done": "Done",
|
"done": "Done",
|
||||||
|
"selectAll": "Select all",
|
||||||
|
"deselectAll": "Deselect all",
|
||||||
|
"cancelFollowing": "Unfollow",
|
||||||
|
"confirmCancelFollowing": "Unfollow the selected dramas?",
|
||||||
"visitor": "Visitor",
|
"visitor": "Visitor",
|
||||||
"copyUid": "Copy UID",
|
"copyUid": "Copy UID",
|
||||||
"uidCopied": "UID copied",
|
"uidCopied": "UID copied",
|
||||||
@@ -746,7 +775,7 @@
|
|||||||
"watchedToEpisode": "Watched to Episode {episode}",
|
"watchedToEpisode": "Watched to Episode {episode}",
|
||||||
"@watchedToEpisode": { "placeholders": { "episode": { "type": "int" } } },
|
"@watchedToEpisode": { "placeholders": { "episode": { "type": "int" } } },
|
||||||
"homeWatchAll": "Watch all",
|
"homeWatchAll": "Watch all",
|
||||||
"confirmRemove": "Remove this item?",
|
"confirmRemove": "Remove this watch history?",
|
||||||
"followingCountLabel": "Following",
|
"followingCountLabel": "Following",
|
||||||
"watchRecordsCountLabel": "Watch records",
|
"watchRecordsCountLabel": "Watch records",
|
||||||
"dataUnavailable": "—",
|
"dataUnavailable": "—",
|
||||||
|
|||||||
@@ -23,6 +23,13 @@
|
|||||||
"authLandingSubtitle": "Masuk untuk menyinkronkan progres, favorit, dan koin",
|
"authLandingSubtitle": "Masuk untuk menyinkronkan progres, favorit, dan koin",
|
||||||
"comingSoon": "Segera hadir",
|
"comingSoon": "Segera hadir",
|
||||||
"authLegal": "Dengan melanjutkan, Anda menyetujui Ketentuan Layanan dan Kebijakan Privasi.",
|
"authLegal": "Dengan melanjutkan, Anda menyetujui Ketentuan Layanan dan Kebijakan Privasi.",
|
||||||
|
"authLegalLead": "Dengan melanjutkan, Anda menyetujui",
|
||||||
|
"authTerms": "Ketentuan Layanan",
|
||||||
|
"authLegalJoin": "dan",
|
||||||
|
"authPrivacy": "Kebijakan Privasi",
|
||||||
|
"legalTerms": "Ketentuan Layanan",
|
||||||
|
"legalPrivacy": "Kebijakan Privasi",
|
||||||
|
"legalOpenFailed": "Halaman ini belum bisa dibuka",
|
||||||
"authContinueGoogle": "Lanjutkan dengan Google",
|
"authContinueGoogle": "Lanjutkan dengan Google",
|
||||||
"authPhoneSignIn": "Masuk dengan ponsel",
|
"authPhoneSignIn": "Masuk dengan ponsel",
|
||||||
"authEmailSignIn": "Masuk dengan email",
|
"authEmailSignIn": "Masuk dengan email",
|
||||||
@@ -186,6 +193,7 @@
|
|||||||
"postComment": "Kirim",
|
"postComment": "Kirim",
|
||||||
"commentPostSuccess": "Komentar terkirim",
|
"commentPostSuccess": "Komentar terkirim",
|
||||||
"loadMore": "Muat lebih banyak",
|
"loadMore": "Muat lebih banyak",
|
||||||
|
"noMoreItems": "Tidak ada lagi",
|
||||||
"commentsLoadFailed": "Komentar tidak dapat dimuat.",
|
"commentsLoadFailed": "Komentar tidak dapat dimuat.",
|
||||||
"commentPostFailed": "Komentar tidak dapat dikirim.",
|
"commentPostFailed": "Komentar tidak dapat dikirim.",
|
||||||
"delete": "Hapus",
|
"delete": "Hapus",
|
||||||
@@ -404,6 +412,22 @@
|
|||||||
"authPasswordLength": "Kata sandi harus 8-64 karakter",
|
"authPasswordLength": "Kata sandi harus 8-64 karakter",
|
||||||
"authPasswordWeak": "Kata sandi perlu huruf dan angka",
|
"authPasswordWeak": "Kata sandi perlu huruf dan angka",
|
||||||
"authNetworkError": "Jaringan bermasalah, coba lagi",
|
"authNetworkError": "Jaringan bermasalah, coba lagi",
|
||||||
|
"authServerError": "Layanan sedang sibuk. Coba lagi sebentar.",
|
||||||
|
"apiErrorBadRequest": "Permintaan tidak valid",
|
||||||
|
"apiErrorUnauthorized": "Masuk untuk melanjutkan",
|
||||||
|
"apiErrorForbidden": "Anda tidak memiliki izin",
|
||||||
|
"apiErrorNotFound": "Tidak ditemukan",
|
||||||
|
"apiErrorTooManyRequests": "Terlalu banyak permintaan. Coba lagi nanti.",
|
||||||
|
"apiErrorLoginFailed": "Akun atau kata sandi salah",
|
||||||
|
"apiErrorAccountDisabled": "Akun ini telah dinonaktifkan",
|
||||||
|
"apiErrorCoinNotEnough": "Koin tidak cukup",
|
||||||
|
"apiErrorEpisodeUnavailable": "Episode ini tidak tersedia",
|
||||||
|
"apiErrorEpisodeUnlocked": "Episode ini sudah terbuka",
|
||||||
|
"apiErrorOrderInvalid": "Pesanan ini sudah dibayar atau ditutup",
|
||||||
|
"apiErrorVipExpired": "Keanggotaan telah berakhir",
|
||||||
|
"apiErrorDataExists": "Data sudah ada",
|
||||||
|
"apiErrorDataNotFound": "Data tidak ditemukan",
|
||||||
|
"apiErrorNotAllowed": "Tindakan ini tidak tersedia saat ini",
|
||||||
"authSwitchToSignUp": "Baru di sini? Buat akun",
|
"authSwitchToSignUp": "Baru di sini? Buat akun",
|
||||||
"authSwitchToSignIn": "Sudah punya akun? Masuk",
|
"authSwitchToSignIn": "Sudah punya akun? Masuk",
|
||||||
"authGateTitle": "Masuk untuk melanjutkan",
|
"authGateTitle": "Masuk untuk melanjutkan",
|
||||||
@@ -550,7 +574,7 @@
|
|||||||
"accountUnverified": "Belum terverifikasi",
|
"accountUnverified": "Belum terverifikasi",
|
||||||
"accountDeactivateWarning": "Permintaan masuk masa tenang 15 hari. Semua perangkat langsung keluar.",
|
"accountDeactivateWarning": "Permintaan masuk masa tenang 15 hari. Semua perangkat langsung keluar.",
|
||||||
"accountDeactivateReason": "Alasan (opsional)",
|
"accountDeactivateReason": "Alasan (opsional)",
|
||||||
"accountDeactivateReasonHint": "Beri tahu alasan kamu",
|
"accountDeactivateReasonHint": "Tambahkan penjelasan di sini",
|
||||||
"accountRequestDeactivate": "Ajukan penghapusan akun",
|
"accountRequestDeactivate": "Ajukan penghapusan akun",
|
||||||
"accountConfirmDeactivateTitle": "Ajukan penghapusan akun?",
|
"accountConfirmDeactivateTitle": "Ajukan penghapusan akun?",
|
||||||
"accountConfirmDeactivateMessage": "Semua perangkat akan langsung keluar. Setelah masuk lagi, kamu dapat membatalkannya selama masa tenang 15 hari.",
|
"accountConfirmDeactivateMessage": "Semua perangkat akan langsung keluar. Setelah masuk lagi, kamu dapat membatalkannya selama masa tenang 15 hari.",
|
||||||
@@ -623,6 +647,8 @@
|
|||||||
"paymentPending": "Menunggu pembayaran.",
|
"paymentPending": "Menunggu pembayaran.",
|
||||||
"orderCreateFailed": "Gagal membuat pesanan.",
|
"orderCreateFailed": "Gagal membuat pesanan.",
|
||||||
"playbackQuality": "Kualitas",
|
"playbackQuality": "Kualitas",
|
||||||
|
"qualitySwitched": "Beralih ke {quality}",
|
||||||
|
"@qualitySwitched": { "placeholders": { "quality": { "type": "String" } } },
|
||||||
"qualityAuto": "Otomatis",
|
"qualityAuto": "Otomatis",
|
||||||
"qualityAutoHint": "HLS menyesuaikan bitrate secara otomatis dengan koneksi Anda.",
|
"qualityAutoHint": "HLS menyesuaikan bitrate secara otomatis dengan koneksi Anda.",
|
||||||
"searchFailed": "Pencarian gagal. Coba lagi.",
|
"searchFailed": "Pencarian gagal. Coba lagi.",
|
||||||
@@ -665,11 +691,10 @@
|
|||||||
"homeBadgeHot": "Populer",
|
"homeBadgeHot": "Populer",
|
||||||
"homeBadgeNew": "Baru",
|
"homeBadgeNew": "Baru",
|
||||||
"homeBadgeAnime": "Anime",
|
"homeBadgeAnime": "Anime",
|
||||||
"homeGridFilterEmpty": "Tidak ada drama yang cocok dengan filter",
|
"emptyContent": "Belum ada konten",
|
||||||
"homeGridClearFilter": "Hapus filter",
|
|
||||||
"recommendTopTab": "Rekomendasi",
|
"recommendTopTab": "Rekomendasi",
|
||||||
"playlistTopTab": "Daftar Putar",
|
"playlistTopTab": "Daftar Putar",
|
||||||
"allDramasTopTab": "Semua Drama",
|
"allDramasTopTab": "Semua",
|
||||||
"weeklyHitsTitle": "Hits Minggu Ini",
|
"weeklyHitsTitle": "Hits Minggu Ini",
|
||||||
"weeklyHitsSubtitle": "Drama terpopuler minggu ini, tonton sekaligus!",
|
"weeklyHitsSubtitle": "Drama terpopuler minggu ini, tonton sekaligus!",
|
||||||
"weeklyNewTitle": "Drama Baru Minggu Ini",
|
"weeklyNewTitle": "Drama Baru Minggu Ini",
|
||||||
@@ -685,6 +710,10 @@
|
|||||||
"modernFilter": "Modern",
|
"modernFilter": "Modern",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"done": "Selesai",
|
"done": "Selesai",
|
||||||
|
"selectAll": "Pilih semua",
|
||||||
|
"deselectAll": "Batal pilih",
|
||||||
|
"cancelFollowing": "Berhenti mengikuti",
|
||||||
|
"confirmCancelFollowing": "Berhenti mengikuti drama yang dipilih?",
|
||||||
"visitor": "Pengunjung",
|
"visitor": "Pengunjung",
|
||||||
"copyUid": "Salin UID",
|
"copyUid": "Salin UID",
|
||||||
"uidCopied": "UID disalin",
|
"uidCopied": "UID disalin",
|
||||||
@@ -703,7 +732,7 @@
|
|||||||
"watchedToEpisode": "Ditonton hingga Episode {episode}",
|
"watchedToEpisode": "Ditonton hingga Episode {episode}",
|
||||||
"@watchedToEpisode": { "placeholders": { "episode": { "type": "int" } } },
|
"@watchedToEpisode": { "placeholders": { "episode": { "type": "int" } } },
|
||||||
"homeWatchAll": "Tonton semua",
|
"homeWatchAll": "Tonton semua",
|
||||||
"confirmRemove": "Hapus item ini?",
|
"confirmRemove": "Hapus riwayat tontonan ini?",
|
||||||
"followingCountLabel": "Mengikuti",
|
"followingCountLabel": "Mengikuti",
|
||||||
"watchRecordsCountLabel": "Riwayat tontonan",
|
"watchRecordsCountLabel": "Riwayat tontonan",
|
||||||
"dataUnavailable": "—",
|
"dataUnavailable": "—",
|
||||||
|
|||||||
@@ -238,6 +238,48 @@ abstract class AppLocalizations {
|
|||||||
/// **'By continuing, you agree to the Terms of Service and Privacy Policy.'**
|
/// **'By continuing, you agree to the Terms of Service and Privacy Policy.'**
|
||||||
String get authLegal;
|
String get authLegal;
|
||||||
|
|
||||||
|
/// No description provided for @authLegalLead.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'By continuing, you agree to the'**
|
||||||
|
String get authLegalLead;
|
||||||
|
|
||||||
|
/// No description provided for @authTerms.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Terms of Service'**
|
||||||
|
String get authTerms;
|
||||||
|
|
||||||
|
/// No description provided for @authLegalJoin.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'and'**
|
||||||
|
String get authLegalJoin;
|
||||||
|
|
||||||
|
/// No description provided for @authPrivacy.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Privacy Policy'**
|
||||||
|
String get authPrivacy;
|
||||||
|
|
||||||
|
/// No description provided for @legalTerms.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Terms of Service'**
|
||||||
|
String get legalTerms;
|
||||||
|
|
||||||
|
/// No description provided for @legalPrivacy.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Privacy Policy'**
|
||||||
|
String get legalPrivacy;
|
||||||
|
|
||||||
|
/// No description provided for @legalOpenFailed.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Can\'t open this page right now'**
|
||||||
|
String get legalOpenFailed;
|
||||||
|
|
||||||
/// No description provided for @authContinueGoogle.
|
/// No description provided for @authContinueGoogle.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
@@ -952,6 +994,12 @@ abstract class AppLocalizations {
|
|||||||
/// **'Load more'**
|
/// **'Load more'**
|
||||||
String get loadMore;
|
String get loadMore;
|
||||||
|
|
||||||
|
/// No description provided for @noMoreItems.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No more'**
|
||||||
|
String get noMoreItems;
|
||||||
|
|
||||||
/// No description provided for @commentsLoadFailed.
|
/// No description provided for @commentsLoadFailed.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
@@ -1858,6 +1906,102 @@ abstract class AppLocalizations {
|
|||||||
/// **'Network error, please try again'**
|
/// **'Network error, please try again'**
|
||||||
String get authNetworkError;
|
String get authNetworkError;
|
||||||
|
|
||||||
|
/// No description provided for @authServerError.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'The service is busy. Please try again shortly.'**
|
||||||
|
String get authServerError;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorBadRequest.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Invalid request'**
|
||||||
|
String get apiErrorBadRequest;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorUnauthorized.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Sign in to continue'**
|
||||||
|
String get apiErrorUnauthorized;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorForbidden.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'You don\'t have permission'**
|
||||||
|
String get apiErrorForbidden;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorNotFound.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Not found'**
|
||||||
|
String get apiErrorNotFound;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorTooManyRequests.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Too many requests. Please try again later.'**
|
||||||
|
String get apiErrorTooManyRequests;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorLoginFailed.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Incorrect account or password'**
|
||||||
|
String get apiErrorLoginFailed;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorAccountDisabled.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This account has been disabled'**
|
||||||
|
String get apiErrorAccountDisabled;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorCoinNotEnough.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Not enough coins'**
|
||||||
|
String get apiErrorCoinNotEnough;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorEpisodeUnavailable.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This episode is unavailable'**
|
||||||
|
String get apiErrorEpisodeUnavailable;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorEpisodeUnlocked.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This episode is already unlocked'**
|
||||||
|
String get apiErrorEpisodeUnlocked;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorOrderInvalid.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This order is already paid or closed'**
|
||||||
|
String get apiErrorOrderInvalid;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorVipExpired.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Membership has expired'**
|
||||||
|
String get apiErrorVipExpired;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorDataExists.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This record already exists'**
|
||||||
|
String get apiErrorDataExists;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorDataNotFound.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Not found'**
|
||||||
|
String get apiErrorDataNotFound;
|
||||||
|
|
||||||
|
/// No description provided for @apiErrorNotAllowed.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This action isn\'t available right now'**
|
||||||
|
String get apiErrorNotAllowed;
|
||||||
|
|
||||||
/// No description provided for @authSwitchToSignUp.
|
/// No description provided for @authSwitchToSignUp.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
@@ -2437,7 +2581,7 @@ abstract class AppLocalizations {
|
|||||||
/// No description provided for @accountDeactivateReasonHint.
|
/// No description provided for @accountDeactivateReasonHint.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
/// **'Tell us why you are leaving'**
|
/// **'Add more detail here'**
|
||||||
String get accountDeactivateReasonHint;
|
String get accountDeactivateReasonHint;
|
||||||
|
|
||||||
/// No description provided for @accountRequestDeactivate.
|
/// No description provided for @accountRequestDeactivate.
|
||||||
@@ -2824,6 +2968,12 @@ abstract class AppLocalizations {
|
|||||||
/// **'Quality'**
|
/// **'Quality'**
|
||||||
String get playbackQuality;
|
String get playbackQuality;
|
||||||
|
|
||||||
|
/// No description provided for @qualitySwitched.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Switched to {quality}'**
|
||||||
|
String qualitySwitched(String quality);
|
||||||
|
|
||||||
/// No description provided for @qualityAuto.
|
/// No description provided for @qualityAuto.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
@@ -3058,17 +3208,11 @@ abstract class AppLocalizations {
|
|||||||
/// **'Anime'**
|
/// **'Anime'**
|
||||||
String get homeBadgeAnime;
|
String get homeBadgeAnime;
|
||||||
|
|
||||||
/// No description provided for @homeGridFilterEmpty.
|
/// No description provided for @emptyContent.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
/// **'No dramas match these filters'**
|
/// **'No content yet'**
|
||||||
String get homeGridFilterEmpty;
|
String get emptyContent;
|
||||||
|
|
||||||
/// No description provided for @homeGridClearFilter.
|
|
||||||
///
|
|
||||||
/// In en, this message translates to:
|
|
||||||
/// **'Clear filters'**
|
|
||||||
String get homeGridClearFilter;
|
|
||||||
|
|
||||||
/// No description provided for @recommendTopTab.
|
/// No description provided for @recommendTopTab.
|
||||||
///
|
///
|
||||||
@@ -3178,6 +3322,30 @@ abstract class AppLocalizations {
|
|||||||
/// **'Done'**
|
/// **'Done'**
|
||||||
String get done;
|
String get done;
|
||||||
|
|
||||||
|
/// No description provided for @selectAll.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Select all'**
|
||||||
|
String get selectAll;
|
||||||
|
|
||||||
|
/// No description provided for @deselectAll.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Deselect all'**
|
||||||
|
String get deselectAll;
|
||||||
|
|
||||||
|
/// No description provided for @cancelFollowing.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Unfollow'**
|
||||||
|
String get cancelFollowing;
|
||||||
|
|
||||||
|
/// No description provided for @confirmCancelFollowing.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Unfollow the selected dramas?'**
|
||||||
|
String get confirmCancelFollowing;
|
||||||
|
|
||||||
/// No description provided for @visitor.
|
/// No description provided for @visitor.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
@@ -3247,7 +3415,7 @@ abstract class AppLocalizations {
|
|||||||
/// No description provided for @confirmRemove.
|
/// No description provided for @confirmRemove.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
/// **'Remove this item?'**
|
/// **'Remove this watch history?'**
|
||||||
String get confirmRemove;
|
String get confirmRemove;
|
||||||
|
|
||||||
/// No description provided for @followingCountLabel.
|
/// No description provided for @followingCountLabel.
|
||||||
|
|||||||
@@ -80,6 +80,27 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
String get authLegal =>
|
String get authLegal =>
|
||||||
'By continuing, you agree to the Terms of Service and Privacy Policy.';
|
'By continuing, you agree to the Terms of Service and Privacy Policy.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authLegalLead => 'By continuing, you agree to the';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authTerms => 'Terms of Service';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authLegalJoin => 'and';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authPrivacy => 'Privacy Policy';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalTerms => 'Terms of Service';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalPrivacy => 'Privacy Policy';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalOpenFailed => 'Can\'t open this page right now';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authContinueGoogle => 'Continue with Google';
|
String get authContinueGoogle => 'Continue with Google';
|
||||||
|
|
||||||
@@ -465,6 +486,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get loadMore => 'Load more';
|
String get loadMore => 'Load more';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get noMoreItems => 'No more';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get commentsLoadFailed => 'Comments could not be loaded.';
|
String get commentsLoadFailed => 'Comments could not be loaded.';
|
||||||
|
|
||||||
@@ -943,6 +967,56 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authNetworkError => 'Network error, please try again';
|
String get authNetworkError => 'Network error, please try again';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authServerError =>
|
||||||
|
'The service is busy. Please try again shortly.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorBadRequest => 'Invalid request';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorUnauthorized => 'Sign in to continue';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorForbidden => 'You don\'t have permission';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorNotFound => 'Not found';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorTooManyRequests =>
|
||||||
|
'Too many requests. Please try again later.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorLoginFailed => 'Incorrect account or password';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorAccountDisabled => 'This account has been disabled';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorCoinNotEnough => 'Not enough coins';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorEpisodeUnavailable => 'This episode is unavailable';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorEpisodeUnlocked => 'This episode is already unlocked';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorOrderInvalid => 'This order is already paid or closed';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorVipExpired => 'Membership has expired';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorDataExists => 'This record already exists';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorDataNotFound => 'Not found';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorNotAllowed => 'This action isn\'t available right now';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authSwitchToSignUp => 'New here? Create an account';
|
String get authSwitchToSignUp => 'New here? Create an account';
|
||||||
|
|
||||||
@@ -1262,7 +1336,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
String get accountDeactivateReason => 'Reason (optional)';
|
String get accountDeactivateReason => 'Reason (optional)';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get accountDeactivateReasonHint => 'Tell us why you are leaving';
|
String get accountDeactivateReasonHint => 'Add more detail here';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get accountRequestDeactivate => 'Request account deletion';
|
String get accountRequestDeactivate => 'Request account deletion';
|
||||||
@@ -1472,6 +1546,11 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get playbackQuality => 'Quality';
|
String get playbackQuality => 'Quality';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String qualitySwitched(String quality) {
|
||||||
|
return 'Switched to $quality';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get qualityAuto => 'Auto';
|
String get qualityAuto => 'Auto';
|
||||||
|
|
||||||
@@ -1597,10 +1676,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
String get homeBadgeAnime => 'Anime';
|
String get homeBadgeAnime => 'Anime';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get homeGridFilterEmpty => 'No dramas match these filters';
|
String get emptyContent => 'No content yet';
|
||||||
|
|
||||||
@override
|
|
||||||
String get homeGridClearFilter => 'Clear filters';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get recommendTopTab => 'Recommend';
|
String get recommendTopTab => 'Recommend';
|
||||||
@@ -1656,6 +1732,18 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get done => 'Done';
|
String get done => 'Done';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get selectAll => 'Select all';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get deselectAll => 'Deselect all';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get cancelFollowing => 'Unfollow';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get confirmCancelFollowing => 'Unfollow the selected dramas?';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get visitor => 'Visitor';
|
String get visitor => 'Visitor';
|
||||||
|
|
||||||
@@ -1694,7 +1782,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
String get homeWatchAll => 'Watch all';
|
String get homeWatchAll => 'Watch all';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get confirmRemove => 'Remove this item?';
|
String get confirmRemove => 'Remove this watch history?';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get followingCountLabel => 'Following';
|
String get followingCountLabel => 'Following';
|
||||||
|
|||||||
@@ -80,6 +80,27 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
String get authLegal =>
|
String get authLegal =>
|
||||||
'Dengan melanjutkan, Anda menyetujui Ketentuan Layanan dan Kebijakan Privasi.';
|
'Dengan melanjutkan, Anda menyetujui Ketentuan Layanan dan Kebijakan Privasi.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authLegalLead => 'Dengan melanjutkan, Anda menyetujui';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authTerms => 'Ketentuan Layanan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authLegalJoin => 'dan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authPrivacy => 'Kebijakan Privasi';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalTerms => 'Ketentuan Layanan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalPrivacy => 'Kebijakan Privasi';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalOpenFailed => 'Halaman ini belum bisa dibuka';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authContinueGoogle => 'Lanjutkan dengan Google';
|
String get authContinueGoogle => 'Lanjutkan dengan Google';
|
||||||
|
|
||||||
@@ -466,6 +487,9 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get loadMore => 'Muat lebih banyak';
|
String get loadMore => 'Muat lebih banyak';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get noMoreItems => 'Tidak ada lagi';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get commentsLoadFailed => 'Komentar tidak dapat dimuat.';
|
String get commentsLoadFailed => 'Komentar tidak dapat dimuat.';
|
||||||
|
|
||||||
@@ -947,6 +971,55 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authNetworkError => 'Jaringan bermasalah, coba lagi';
|
String get authNetworkError => 'Jaringan bermasalah, coba lagi';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authServerError => 'Layanan sedang sibuk. Coba lagi sebentar.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorBadRequest => 'Permintaan tidak valid';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorUnauthorized => 'Masuk untuk melanjutkan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorForbidden => 'Anda tidak memiliki izin';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorNotFound => 'Tidak ditemukan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorTooManyRequests =>
|
||||||
|
'Terlalu banyak permintaan. Coba lagi nanti.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorLoginFailed => 'Akun atau kata sandi salah';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorAccountDisabled => 'Akun ini telah dinonaktifkan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorCoinNotEnough => 'Koin tidak cukup';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorEpisodeUnavailable => 'Episode ini tidak tersedia';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorEpisodeUnlocked => 'Episode ini sudah terbuka';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorOrderInvalid => 'Pesanan ini sudah dibayar atau ditutup';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorVipExpired => 'Keanggotaan telah berakhir';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorDataExists => 'Data sudah ada';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorDataNotFound => 'Data tidak ditemukan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorNotAllowed => 'Tindakan ini tidak tersedia saat ini';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authSwitchToSignUp => 'Baru di sini? Buat akun';
|
String get authSwitchToSignUp => 'Baru di sini? Buat akun';
|
||||||
|
|
||||||
@@ -1262,7 +1335,7 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
String get accountDeactivateReason => 'Alasan (opsional)';
|
String get accountDeactivateReason => 'Alasan (opsional)';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get accountDeactivateReasonHint => 'Beri tahu alasan kamu';
|
String get accountDeactivateReasonHint => 'Tambahkan penjelasan di sini';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get accountRequestDeactivate => 'Ajukan penghapusan akun';
|
String get accountRequestDeactivate => 'Ajukan penghapusan akun';
|
||||||
@@ -1472,6 +1545,11 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get playbackQuality => 'Kualitas';
|
String get playbackQuality => 'Kualitas';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String qualitySwitched(String quality) {
|
||||||
|
return 'Beralih ke $quality';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get qualityAuto => 'Otomatis';
|
String get qualityAuto => 'Otomatis';
|
||||||
|
|
||||||
@@ -1598,10 +1676,7 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
String get homeBadgeAnime => 'Anime';
|
String get homeBadgeAnime => 'Anime';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get homeGridFilterEmpty => 'Tidak ada drama yang cocok dengan filter';
|
String get emptyContent => 'Belum ada konten';
|
||||||
|
|
||||||
@override
|
|
||||||
String get homeGridClearFilter => 'Hapus filter';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get recommendTopTab => 'Rekomendasi';
|
String get recommendTopTab => 'Rekomendasi';
|
||||||
@@ -1610,7 +1685,7 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
String get playlistTopTab => 'Daftar Putar';
|
String get playlistTopTab => 'Daftar Putar';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get allDramasTopTab => 'Semua Drama';
|
String get allDramasTopTab => 'Semua';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get weeklyHitsTitle => 'Hits Minggu Ini';
|
String get weeklyHitsTitle => 'Hits Minggu Ini';
|
||||||
@@ -1659,6 +1734,18 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get done => 'Selesai';
|
String get done => 'Selesai';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get selectAll => 'Pilih semua';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get deselectAll => 'Batal pilih';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get cancelFollowing => 'Berhenti mengikuti';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get confirmCancelFollowing => 'Berhenti mengikuti drama yang dipilih?';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get visitor => 'Pengunjung';
|
String get visitor => 'Pengunjung';
|
||||||
|
|
||||||
@@ -1697,7 +1784,7 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
String get homeWatchAll => 'Tonton semua';
|
String get homeWatchAll => 'Tonton semua';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get confirmRemove => 'Hapus item ini?';
|
String get confirmRemove => 'Hapus riwayat tontonan ini?';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get followingCountLabel => 'Mengikuti';
|
String get followingCountLabel => 'Mengikuti';
|
||||||
|
|||||||
@@ -77,6 +77,27 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authLegal => '继续即代表同意《用户协议》与《隐私政策》';
|
String get authLegal => '继续即代表同意《用户协议》与《隐私政策》';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authLegalLead => '继续即代表同意';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authTerms => '《用户协议》';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authLegalJoin => '与';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authPrivacy => '《隐私政策》';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalTerms => '服务条款';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalPrivacy => '隐私协议';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get legalOpenFailed => '暂时无法打开协议页面';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authContinueGoogle => '使用 Google 继续';
|
String get authContinueGoogle => '使用 Google 继续';
|
||||||
|
|
||||||
@@ -460,6 +481,9 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get loadMore => '加载更多';
|
String get loadMore => '加载更多';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get noMoreItems => '没有更多了';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get commentsLoadFailed => '评论加载失败,请重试。';
|
String get commentsLoadFailed => '评论加载失败,请重试。';
|
||||||
|
|
||||||
@@ -931,6 +955,54 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authNetworkError => '网络异常,请稍后重试';
|
String get authNetworkError => '网络异常,请稍后重试';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authServerError => '服务繁忙,请稍后再试';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorBadRequest => '参数校验失败';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorUnauthorized => '未登录或登录已过期';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorForbidden => '无权限';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorNotFound => '资源不存在';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorTooManyRequests => '请求过于频繁,请稍后再试';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorLoginFailed => '账号或密码错误';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorAccountDisabled => '账号已停用';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorCoinNotEnough => '金币余额不足';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorEpisodeUnavailable => '剧集未发布或不存在';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorEpisodeUnlocked => '剧集已解锁';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorOrderInvalid => '订单已支付或已关闭';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorVipExpired => '会员已过期';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorDataExists => '数据已存在';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorDataNotFound => '数据不存在';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get apiErrorNotAllowed => '当前状态不允许该操作';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authSwitchToSignUp => '还没有账号?去注册';
|
String get authSwitchToSignUp => '还没有账号?去注册';
|
||||||
|
|
||||||
@@ -1240,7 +1312,7 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
String get accountDeactivateReason => '注销原因(选填)';
|
String get accountDeactivateReason => '注销原因(选填)';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get accountDeactivateReasonHint => '告诉我们你离开的原因';
|
String get accountDeactivateReasonHint => '也可以在这里补充说明';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get accountRequestDeactivate => '申请注销账号';
|
String get accountRequestDeactivate => '申请注销账号';
|
||||||
@@ -1449,6 +1521,11 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get playbackQuality => '清晰度';
|
String get playbackQuality => '清晰度';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String qualitySwitched(String quality) {
|
||||||
|
return '已切换至$quality';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get qualityAuto => '自动';
|
String get qualityAuto => '自动';
|
||||||
|
|
||||||
@@ -1573,10 +1650,7 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
String get homeBadgeAnime => '漫剧';
|
String get homeBadgeAnime => '漫剧';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get homeGridFilterEmpty => '没有符合筛选条件的短剧';
|
String get emptyContent => '暂无内容';
|
||||||
|
|
||||||
@override
|
|
||||||
String get homeGridClearFilter => '清除筛选';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get recommendTopTab => '推荐';
|
String get recommendTopTab => '推荐';
|
||||||
@@ -1632,6 +1706,18 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get done => '完成';
|
String get done => '完成';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get selectAll => '全选';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get deselectAll => '取消全选';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get cancelFollowing => '取消追剧';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get confirmCancelFollowing => '确定取消已选短剧的追剧吗?';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get visitor => '访客';
|
String get visitor => '访客';
|
||||||
|
|
||||||
@@ -1670,7 +1756,7 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
String get homeWatchAll => '观看全集';
|
String get homeWatchAll => '观看全集';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get confirmRemove => '确定移除这条内容吗?';
|
String get confirmRemove => '确定要移除该条观看记录吗?';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get followingCountLabel => '追剧数';
|
String get followingCountLabel => '追剧数';
|
||||||
|
|||||||