Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8b9a090e0 | ||
|
|
3ad371aa9d | ||
|
|
7463d3ee26 | ||
|
|
59fbd33059 | ||
|
|
8c1662475a | ||
|
|
7f65fe4d48 | ||
|
|
613147c20c | ||
|
|
731638b31b | ||
|
|
c4adbd0665 | ||
|
|
a833d62c50 | ||
|
|
bc01716449 | ||
|
|
12b1a11bd3 | ||
|
|
66c03ee245 | ||
|
|
a3ac007759 | ||
|
|
8ec6df2be5 | ||
|
|
5ec4db151a | ||
|
|
525f58c150 | ||
|
|
a47af8c3ad | ||
|
|
0a02620564 | ||
|
|
2ddf9ee1c6 | ||
|
|
3bc79ad8e2 | ||
|
|
78a33cd4f1 | ||
|
|
c307903c42 | ||
|
|
c5b94633f1 | ||
|
|
fd2ba0bf43 | ||
|
|
aed9ee2b01 | ||
|
|
335e5dc286 | ||
|
|
e8610b7aed | ||
|
|
2f4593a46e | ||
|
|
7509cf2ecd | ||
|
|
501bc66282 | ||
|
|
19196ceb8e | ||
|
|
9ef8eb15b0 | ||
|
|
53e8c924a6 | ||
|
|
e7399fa3fd | ||
|
|
22cc669bbe | ||
|
|
26321e3348 | ||
|
|
3590cd0c55 | ||
|
|
c311985601 | ||
|
|
4dd37b2588 | ||
|
|
543d0aadd5 | ||
|
|
d5bcda54d3 | ||
|
|
79463e65c2 | ||
|
|
ad7aba3daf | ||
|
|
47fdd4a29d | ||
|
|
fe49527dd8 | ||
|
|
4aaa5bbd60 | ||
|
|
5649e4c3d4 | ||
|
|
9f7301305e | ||
|
|
63191b4692 | ||
|
|
0f777b19f2 | ||
|
|
fb9001a02d | ||
|
|
1b80f841be | ||
|
|
3e89c71f50 | ||
|
|
2ce92aa7dd | ||
|
|
a6d6b66d31 | ||
|
|
57f84c45bd | ||
|
|
a4d08e7c1e | ||
|
|
9c9a277217 | ||
|
|
1be8ebf1f9 | ||
|
|
70be941755 | ||
|
|
351d0afd09 | ||
|
|
7d32324a2d | ||
|
|
1d4ab5e0e6 | ||
|
|
799f3d1b7d | ||
|
|
08aa6903d2 | ||
|
|
4de9417e27 | ||
|
|
e269d5dce5 | ||
|
|
78f464f2a4 | ||
|
|
9983d42015 | ||
|
|
bfe0df62dc | ||
|
|
df2654c9d6 | ||
|
|
496b1cb797 | ||
|
|
85dedf20fa | ||
|
|
43e60e29ec | ||
|
|
5346be40a9 | ||
|
|
de7da64886 | ||
|
|
709972245f | ||
|
|
d5d13549f5 | ||
|
|
c027acc91f | ||
|
|
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 | ||
|
|
76429628ec | ||
|
|
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 | ||
|
|
43f3593218 | ||
|
|
b83b5799e3 | ||
|
|
d4ae8f427f | ||
|
|
0eca7ecc31 | ||
|
|
98d7debfb5 | ||
|
|
b5e9deb4bd | ||
|
|
af5d8f9d80 | ||
|
|
47df002d8e | ||
|
|
4f1feeadbd | ||
|
|
8b50b5bd06 | ||
|
|
b84a5368d6 | ||
|
|
67e178c89d | ||
|
|
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 | ||
|
|
56d7abc6b1 | ||
|
|
345cc2ad28 | ||
|
|
41bd4683c3 | ||
|
|
d868ce9336 | ||
|
|
928ac1de19 | ||
|
|
6b3d870c93 | ||
|
|
281f13a810 | ||
|
|
8637f5da21 | ||
|
|
0319f8a6a8 | ||
|
|
9aa797504b | ||
|
|
933333b0fe | ||
|
|
bbc759473c | ||
|
|
9ddd7fc833 | ||
|
|
5794dd4e4d | ||
|
|
76c4b528d3 | ||
|
|
68ccfa21c0 | ||
|
|
78d0166eb7 | ||
|
|
4140c4eb50 | ||
|
|
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
@@ -0,0 +1,25 @@
|
|||||||
|
# Author: fruit.com.cn
|
||||||
|
# ReelShort 客户端 CI:静态分析 + 测试门禁
|
||||||
|
name: flutter-ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [develop, main]
|
||||||
|
pull_request:
|
||||||
|
branches: [develop, main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: subosito/flutter-action@v2
|
||||||
|
with:
|
||||||
|
channel: stable
|
||||||
|
cache: true
|
||||||
|
- name: 依赖
|
||||||
|
run: flutter pub get
|
||||||
|
- name: 静态分析(零告警门禁)
|
||||||
|
run: dart analyze --fatal-infos
|
||||||
|
- name: 单元测试(全绿门禁)
|
||||||
|
run: flutter test -r expanded
|
||||||
@@ -65,3 +65,6 @@ app.*.map.json
|
|||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
|
||||||
|
# IDE 的 Flutter Widget Preview 生成目录。
|
||||||
|
.widget_preview/
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
# FruitShorts(ReelShort)客户端
|
# FruitShorts(ReelShort)客户端
|
||||||
|
|
||||||
FruitShorts 是面向印尼市场的短剧 Flutter 客户端。当前版本已连接
|
FruitShorts 是面向印尼市场的短剧 Flutter 客户端,已连接 `FruitServer` 的
|
||||||
`FruitServer` 的 `/app/**` 接口,支持沉浸播放、找剧、账号、观看记录、收藏、
|
`/app/**` 接口。功能覆盖:四 tab 主页(推荐视频流 / 找剧 / 追剧 / 我的)、
|
||||||
下载授权、评论互动、站内通知和中英印尼三语界面。
|
沉浸式播放与全屏剧集播放器、清晰度切换、剧单与排行榜、新剧页、搜索、观看记录、
|
||||||
|
收藏短剧、评论与点赞、站内通知、钱包与商品、下载落盘与离线播放、中英印尼三语,
|
||||||
|
以及 Android / iOS 双端画中画(退到后台自动进小窗)。
|
||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
|
|
||||||
- Flutter 3.47.7 / Dart 3.13.5
|
- Flutter 3.47.7 / Dart 3.13.5(`environment.sdk: ^3.12.2`)
|
||||||
- Provider 状态管理与依赖注入
|
- Provider 状态管理与依赖注入
|
||||||
- dio 网络请求
|
- dio 网络请求
|
||||||
- video_player 播放
|
- video_player 播放
|
||||||
- shared_preferences 与 `SharedPreferencesAsync` 本地配置
|
- shared_preferences 与 `SharedPreferencesAsync` 本地配置
|
||||||
|
- path_provider + dart:io 下载落盘(先写 `.part`,完成后原子改名)
|
||||||
- flutter_localizations,支持 `en`、`zh`、`id`
|
- flutter_localizations,支持 `en`、`zh`、`id`
|
||||||
- Android 系统画中画
|
- 画中画:Android 用 `floating` + `permission_handler`(需悬浮窗权限);
|
||||||
|
iOS 用原生 `AVPictureInPictureController` + 影子播放器(`ios/Runner/AppDelegate.swift`)
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
|
|
||||||
@@ -22,7 +26,7 @@ lib/
|
|||||||
config/ 地址、语言和运行时配置
|
config/ 地址、语言和运行时配置
|
||||||
data/ models、remote API、repository、controller
|
data/ models、remote API、repository、controller
|
||||||
formatting/ 文案与日期格式化
|
formatting/ 文案与日期格式化
|
||||||
platform/ 触觉等平台能力
|
platform/ 平台能力:画中画通道、设备号、触觉
|
||||||
theme/ 颜色与主题
|
theme/ 颜色与主题
|
||||||
widgets/ 跨页面复用组件
|
widgets/ 跨页面复用组件
|
||||||
l10n/ 三语 ARB 与生成代码
|
l10n/ 三语 ARB 与生成代码
|
||||||
@@ -36,20 +40,21 @@ assets/ 图标、图片和本地媒体文件
|
|||||||
|
|
||||||
## 已接接口
|
## 已接接口
|
||||||
|
|
||||||
以下接口均在 `lib/core/data/remote/` 中有实际调用,共 26 个不同路径、
|
以下接口均在 `lib/core/data/remote/` 中有实际调用,共 47 个不同路径。
|
||||||
31 个 HTTP 方法级调用。
|
|
||||||
|
|
||||||
| 分组 | 契约 | 接口 |
|
| 分组 | 接口 |
|
||||||
| --- | --- | --- |
|
| --- | --- |
|
||||||
| 账号 | §1.1 | `POST /app/auth/register`、`/login`、`/refresh`、`/logout` |
|
| 账号 | `POST /app/auth/register`、`/login`、`/refresh`、`/logout`、`/otp`;`GET /app/me`、`/app/me/devices`、`/app/me/export`;`POST /app/me/deactivate`、`/app/me/deactivate/cancel` |
|
||||||
| 内容 | §1.3、§1.4 | `GET /app/home/feed`、`/app/discover/feed`、`/app/categories`、`/app/dramas/{id}`、`/app/episodes/{id}/play` |
|
| 内容 | `GET /app/home/feed`、`/app/feed`、`/app/discover/feed`、`/app/categories`、`/app/categories/{id}/dramas`、`/app/drama-categories`、`/app/dramas/page`、`/app/dramas/{id}`、`/app/tags`、`/app/search`、`/app/playlists`、`/app/playlists/{id}` |
|
||||||
| 观看记录 | §1.5 | `POST/GET /app/watch/progress`、`GET /app/watch/recent`、`DELETE /app/watch/progress/{dramaId}`、`DELETE /app/watch/progress` |
|
| 播放 | `GET /app/episodes/{id}/play`、`/app/episodes/{id}/stats`;`POST /app/episodes/{id}/unlock` |
|
||||||
| 收藏 | §1.5 | `POST /app/favorites/toggle`、`GET /app/favorites`、`DELETE /app/favorites/{dramaId}` |
|
| 观看记录 | `POST/GET /app/watch/progress`、`GET /app/watch/recent`、`DELETE /app/watch/progress/{dramaId}`、`DELETE /app/watch/progress` |
|
||||||
| 下载授权 | §1.6 | `GET /app/downloads/policy`、`PUT /app/downloads/settings`、`POST/GET /app/downloads`、`GET /app/downloads/{episodeId}/url`、`POST /app/downloads/{episodeId}/progress`、`DELETE /app/downloads/{episodeId}`、`DELETE /app/downloads` |
|
| 收藏 | `POST /app/favorites/toggle`、`GET /app/favorites`、`DELETE /app/favorites/{dramaId}`、`POST /app/favorites/remove` |
|
||||||
| 互动 | §1.7 | `GET/POST /app/comments`、`DELETE /app/comments/{id}`、`POST /app/likes/toggle`、`POST /app/reports` |
|
| 下载 | `GET /app/downloads/policy`、`PUT /app/downloads/settings`、`POST/GET /app/downloads`、`GET /app/downloads/{id}/url`、`POST /app/downloads/{id}/progress`、`DELETE /app/downloads/{id}`、`DELETE /app/downloads` |
|
||||||
| 公告 | §1.9.2 | `GET /app/notices` |
|
| 互动 | `GET/POST /app/comments`、`DELETE /app/comments/{id}`、`GET /app/comments/count`、`POST /app/likes/toggle`、`POST /app/reports` |
|
||||||
|
| 商业化 | `GET /app/wallet`、`/app/products`、`/app/orders` |
|
||||||
|
| 公告 | `GET /app/notices` |
|
||||||
|
|
||||||
客户端没有调用 `/app/config` 或创作者入驻接口。
|
客户端没有调用 `/app/config` 和创作者入驻接口。
|
||||||
|
|
||||||
## 运行
|
## 运行
|
||||||
|
|
||||||
@@ -66,39 +71,60 @@ flutter pub get
|
|||||||
```bash
|
```bash
|
||||||
adb devices
|
adb devices
|
||||||
adb reverse tcp:8081 tcp:8081
|
adb reverse tcp:8081 tcp:8081
|
||||||
flutter run -d <device> \
|
flutter run -d <device>
|
||||||
--dart-define=API_BASE_URL=http://127.0.0.1:8081
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`adb reverse` 将手机的 `127.0.0.1:8081` 转发到电脑;USB 断开或重新连接后需要
|
`adb reverse` 将手机的 `127.0.0.1:8081` 转发到电脑;USB 断开或重新连接后需要
|
||||||
重新执行。
|
重新执行。此时用调试条把地址改成 `http://127.0.0.1:8081`(见下节)。
|
||||||
|
|
||||||
Android 模拟器访问宿主机时使用:
|
Android 模拟器访问宿主机时,同样在调试条里填 `http://10.0.2.2:8081`。
|
||||||
|
|
||||||
```bash
|
|
||||||
flutter run --dart-define=API_BASE_URL=http://10.0.2.2:8081
|
|
||||||
```
|
|
||||||
|
|
||||||
### iOS
|
### iOS
|
||||||
|
|
||||||
手机与 Mac 需在同一网络,首次启动允许“本地网络”权限:
|
iOS 模拟器直接访问 Mac 本机服务,默认地址为 `http://127.0.0.1:8081`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
flutter run -d <udid> \
|
flutter run -d <simulator-udid>
|
||||||
--dart-define=API_BASE_URL=http://<Mac局域网IP>:8081
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debug 运行时地址
|
iPhone 真机不能用 `127.0.0.1` 访问 Mac;真机联调时需让手机与 Mac 位于同一网络,
|
||||||
|
并通过调试入口临时填写 Mac 的局域网地址。
|
||||||
|
|
||||||
debug 版本可在「我的 → 设置 → 服务器地址」修改后端地址,保存后重启 App 生效。
|
### 服务地址配置
|
||||||
地址优先级:
|
|
||||||
|
|
||||||
```text
|
地址是代码里的一个开关,**不做任何网络探测**,也不用传构建参数。两套环境各占
|
||||||
本地运行时设置 > --dart-define(API_BASE_URL) > 平台默认地址
|
一个文件:
|
||||||
|
|
||||||
|
| 文件 | 用途 | 默认值 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `lib/core/config/dev_config.dart` | 开发 / 联调 | `http://127.0.0.1:8081` |
|
||||||
|
| `lib/core/config/prod_config.dart` | 生产 | `http://39.162.50.99:8081` |
|
||||||
|
|
||||||
|
切换环境只改 `lib/core/config/app_config.dart` 里的一个布尔值:
|
||||||
|
|
||||||
|
```dart
|
||||||
|
static const bool useDevConfig = true; // false 即用生产地址
|
||||||
```
|
```
|
||||||
|
|
||||||
因此不带 `--dart-define` 构建的 debug APK 也可在安装后改成当前电脑 IP。
|
真机或 Android 模拟器联调时,通过调试入口覆盖地址,不修改默认开发配置。打生产包前把
|
||||||
release 版本不显示入口,也不会读取本地覆盖。
|
`useDevConfig` 改成 `false`;release 构建若仍为 `true` 会在启动时直接报错,
|
||||||
|
避免线上包连到开发机。
|
||||||
|
|
||||||
|
debug 包在找剧页加载失败时会显示调试条,点「修改服务器地址」可临时改成当前
|
||||||
|
电脑 IP,保存后立即重载、不需要重新打包,该覆盖保存在本地偏好里(仅 debug
|
||||||
|
生效,release 不读取)。
|
||||||
|
|
||||||
|
## 画中画
|
||||||
|
|
||||||
|
| 平台 | 行为 |
|
||||||
|
| --- | --- |
|
||||||
|
| Android | 首次点播放页小窗按钮时申请悬浮窗权限;授权后退出 App 自动进入系统小窗。沉浸流与独立播放页共用一份引用计数,任一处活跃都算「在播」,避免互相顶掉 |
|
||||||
|
| iOS | 原生影子播放器承载 `AVPictureInPictureController`,只有播放页处于活跃状态时退到后台才自动进小窗;停在剧单等页面退后台不会触发 |
|
||||||
|
|
||||||
|
- 小窗内切集直接换源,不走页面翻页,可连续自动播放
|
||||||
|
- iOS 从系统小窗还原时用原生过渡层盖住纹理黑帧,等首帧就绪后再淡出
|
||||||
|
- 播放页「更多」面板里有「退出自动小窗」开关(仅支持自动小窗的平台显示),关掉后
|
||||||
|
退到后台不再进入小窗
|
||||||
|
|
||||||
## 环境注意
|
## 环境注意
|
||||||
|
|
||||||
@@ -131,46 +157,56 @@ xcodebuild -resolvePackageDependencies \
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
adb uninstall com.stormg.lumadrama
|
adb uninstall com.stormg.lumadrama
|
||||||
flutter run -d <device> \
|
flutter run -d <device>
|
||||||
--dart-define=API_BASE_URL=http://127.0.0.1:8081
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 生产打包(Android)
|
## 生产打包(Android)
|
||||||
|
|
||||||
生产包只包含以下两个 ABI,**打成一个 APK**,不做 split:
|
两个渠道出两种产物,源码同一套:
|
||||||
|
|
||||||
| ABI | 适用设备 |
|
| 渠道 | 产物 | 命令 | 体积 |
|
||||||
| --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `arm64-v8a` | 现代手机(64 位) |
|
| Google Play | AAB(按设备下发) | `flutter build appbundle --release` | 上传 28MB,用户下载约 8MB |
|
||||||
| `armeabi-v7a` | 老 32 位机 |
|
| 国内各大市场 | 通用 APK(arm64 + v7) | `flutter build apk --release` | 约 13MB |
|
||||||
|
|
||||||
```bash
|
|
||||||
flutter build apk --release --target-platform android-arm64,android-arm
|
|
||||||
# 产出单个:build/app/outputs/flutter-apk/app-release.apk(约 37MB)
|
|
||||||
```
|
|
||||||
|
|
||||||
说明:
|
说明:
|
||||||
|
|
||||||
- `android/app/build.gradle.kts` 的 `release` 已配置 `abiFilters`,只保留 `arm64-v8a` 与 `armeabi-v7a`,插件也不会再带入 `x86_64` 原生库。
|
- `android/app/build.gradle.kts` 的 `release` 已配置 `abiFilters`,只保留 `arm64-v8a` 与 `armeabi-v7a`,插件也不会再带入 `x86_64` 原生库。
|
||||||
- `x86_64` 只用于模拟器,不进入生产包。
|
- `android/gradle.properties` 里固定了 `split-debug-info=build/symbols` 与 `dart-obfuscation=true`,**IDE 里点 Build APK / Build App Bundle 也会生效**:`libapp.so` 从 ~8MB/ABI 降到 ~1.1MB/ABI。
|
||||||
- 不要直接运行 `flutter build apk --release`:默认会编译三套原生库,包体约 57MB。
|
- `useLegacyPackaging = true`:原生库以压缩形式存储,这是国内 APK 从 40MB 降到 13MB 的主要原因;代价是安装时解压。
|
||||||
- 只有需要进一步压缩单机下载体积时,才考虑 `--split-per-abi` 出分架构包(arm64 约 21MB、armv7 约 19MB),默认不用。
|
- **每次发版都要归档 `build/symbols`**,线上崩溃栈需要它还原。
|
||||||
|
- release 仍在用 debug 签名(`build.gradle.kts` 的 TODO),上架前必须换成正式 keystore。
|
||||||
|
- 不要用 `--split-per-abi`:与 `abiFilters` 冲突;Play 的 AAB 已经按设备拆好。
|
||||||
|
|
||||||
|
## 生产打包(iOS)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 正式签名(需要 iOS Distribution 证书 + App Store 描述文件)
|
||||||
|
flutter build ipa --release
|
||||||
|
|
||||||
|
# 只有 Apple Development 证书时:出开发签名 IPA,只能装已注册设备
|
||||||
|
flutter build ipa --release --export-method development
|
||||||
|
```
|
||||||
|
|
||||||
|
产物在 `build/ios/ipa/*.ipa`。画中画依赖 `UIBackgroundModes` 里的 `audio` 与
|
||||||
|
`AVPictureInPictureController`,改动 `ios/Runner/Info.plist` 或 `AppDelegate.swift`
|
||||||
|
后要重新构建,热重载不会生效。
|
||||||
|
|
||||||
## 门禁
|
## 门禁
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart analyze lib test
|
dart analyze
|
||||||
flutter test
|
flutter test
|
||||||
flutter build apk --debug
|
flutter build apk --debug
|
||||||
```
|
```
|
||||||
|
|
||||||
测试文件按模块放在 `test/` 下,用例名使用
|
当前基线:`dart analyze` 仅 1 条既存 info(`intl` 未在 `pubspec.yaml` 声明);
|
||||||
|
`flutter test` 全量 775 例通过。测试文件按模块放在 `test/` 下,用例名使用
|
||||||
`should_<期望>_when_<条件>`。真实后端联调测试在服务未启动时会跳过。
|
`should_<期望>_when_<条件>`。真实后端联调测试在服务未启动时会跳过。
|
||||||
|
|
||||||
## 当前边界
|
## 当前边界
|
||||||
|
|
||||||
- 下载仅管理服务端授权,不落盘、不续传、不支持离线播放。
|
- 下载会落盘并支持离线播放,但不支持断点续传:中途失败会丢弃 `.part` 重下。
|
||||||
- 没有独立搜索接口,搜索能力尚未形成完整闭环。
|
- 支付与金币:客户端已有钱包、商品、下单接口与页面,商店票据校验依赖服务端配置凭据。
|
||||||
- 站内通知没有已读/未读和红点状态。
|
- 站内通知没有已读/未读和红点状态。
|
||||||
- 支付、金币和会员权益尚未形成客户端闭环。
|
- 播放清晰度切换会保留旧画面 500ms 掩盖闪屏,切换瞬间的进度以相对位置续播。
|
||||||
- Android 支持系统画中画;iOS 画中画尚未接入。
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
/.gradle
|
/.gradle
|
||||||
|
/build/
|
||||||
/captures/
|
/captures/
|
||||||
/local.properties
|
/local.properties
|
||||||
GeneratedPluginRegistrant.java
|
GeneratedPluginRegistrant.java
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.stormg.lumadrama"
|
namespace = "com.stormg.lumadrama"
|
||||||
compileSdk = flutter.compileSdkVersion
|
// permission_handler_android 14 的 AAR 元数据要求依赖方 compileSdk >= 37,
|
||||||
|
// 固定为 37(比 Flutter 默认的 36 高一档,只影响编译期 API 可见性)。
|
||||||
|
compileSdk = 37
|
||||||
ndkVersion = flutter.ndkVersion
|
ndkVersion = flutter.ndkVersion
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -33,6 +35,13 @@ android {
|
|||||||
ndk {
|
ndk {
|
||||||
abiFilters += listOf("arm64-v8a", "armeabi-v7a")
|
abiFilters += listOf("arm64-v8a", "armeabi-v7a")
|
||||||
}
|
}
|
||||||
|
// R8 裁剪未使用的 Java/Kotlin 代码与资源,减小 dex 与 res。
|
||||||
|
isMinifyEnabled = true
|
||||||
|
isShrinkResources = true
|
||||||
|
proguardFiles(
|
||||||
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
|
"proguard-rules.pro",
|
||||||
|
)
|
||||||
// TODO: Add your own signing config for the release build.
|
// TODO: Add your own signing config for the release build.
|
||||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||||
signingConfig = signingConfigs.getByName("debug")
|
signingConfig = signingConfigs.getByName("debug")
|
||||||
@@ -50,6 +59,9 @@ kotlin {
|
|||||||
androidComponents {
|
androidComponents {
|
||||||
onVariants(selector().withBuildType("release")) { variant ->
|
onVariants(selector().withBuildType("release")) { variant ->
|
||||||
variant.packaging.jniLibs.excludes.add("lib/x86_64/**")
|
variant.packaging.jniLibs.excludes.add("lib/x86_64/**")
|
||||||
|
// 原生库随 APK 压缩存储:下载体积明显小于解压后的体积,代价是安装时解压。
|
||||||
|
// 本包 90% 体积是 so,这一项对国内商店的 APK 分发影响最大。
|
||||||
|
variant.packaging.jniLibs.useLegacyPackaging = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Author: fruit.com.cn
|
||||||
|
#
|
||||||
|
# R8 保号规则:Flutter 引擎与插件自带的 consumer rules 已覆盖大部分场景,
|
||||||
|
# 这里只补本项目原生层通过反射/通道访问、裁剪后容易失效的入口。
|
||||||
|
|
||||||
|
# 画中画与权限通道由 MainActivity 直接注册,保留应用包名下的入口类。
|
||||||
|
-keep class com.stormg.lumadrama.** { *; }
|
||||||
|
|
||||||
|
# Flutter 引擎在 release 下通过 JNI 回调这些类,禁止改名。
|
||||||
|
-keep class io.flutter.** { *; }
|
||||||
|
-dontwarn io.flutter.embedding.**
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
<!-- Author: fruit.com.cn -->
|
<!-- Author: fruit.com.cn -->
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission
|
||||||
|
android:name="android.permission.INTERNET"/>
|
||||||
|
<!-- 画中画自动触发依赖的「显示在其他应用上层」权限(部分 ROM 用它管控 PiP) -->
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
<application
|
<application
|
||||||
android:label="FruitShorts"
|
android:label="ymb"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true">
|
||||||
@@ -23,9 +26,8 @@
|
|||||||
while the Flutter UI initializes. After that, this theme continues
|
while the Flutter UI initializes. After that, this theme continues
|
||||||
to determine the Window background behind the Flutter UI. -->
|
to determine the Window background behind the Flutter UI. -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="io.flutter.embedding.android.NormalTheme"
|
android:name="io.flutter.embedding.android.NormalTheme"
|
||||||
android:resource="@style/NormalTheme"
|
android:resource="@style/NormalTheme"/>
|
||||||
/>
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
@@ -35,7 +37,7 @@
|
|||||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2"/>
|
||||||
</application>
|
</application>
|
||||||
<!-- Required to query activities that can process text, see:
|
<!-- Required to query activities that can process text, see:
|
||||||
https://developer.android.com/training/package-visibility and
|
https://developer.android.com/training/package-visibility and
|
||||||
@@ -44,8 +46,10 @@
|
|||||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
<action
|
||||||
<data android:mimeType="text/plain"/>
|
android:name="android.intent.action.PROCESS_TEXT"/>
|
||||||
|
<data
|
||||||
|
android:mimeType="text/plain"/>
|
||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -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
|
||||||
@@ -238,6 +284,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val TAG = "FruitPip"
|
||||||
private const val thumbnailMaxWidth = 240
|
private const val thumbnailMaxWidth = 240
|
||||||
private const val thumbnailJpegQuality = 70
|
private const val thumbnailJpegQuality = 70
|
||||||
private const val thumbnailTimeoutMs = 1500L
|
private const val thumbnailTimeoutMs = 1500L
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 9.1 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: 43 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: 69 B After Width: | Height: | Size: 69 B |
@@ -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 After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 69 B After Width: | Height: | Size: 69 B |
@@ -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,5 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@mipmap/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground>
|
||||||
|
<inset
|
||||||
|
android:drawable="@drawable/ic_launcher_foreground"
|
||||||
|
android:inset="16%" />
|
||||||
|
</foreground>
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 156 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 113 B |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 216 B |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 384 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 623 B |
@@ -1,11 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Author: fruit.com.cn -->
|
<!-- Author: fruit.com.cn -->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||||
<item name="android:windowSplashScreenBackground">@color/splash_background</item>
|
<item name="android:forceDarkAllowed">false</item>
|
||||||
|
<item name="android:windowFullscreen">false</item>
|
||||||
|
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
<item name="android:windowSplashScreenBackground">#000000</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</item>
|
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</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>
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Author: fruit.com.cn -->
|
<!-- Author: fruit.com.cn -->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||||
<item name="android:windowSplashScreenBackground">@color/splash_background</item>
|
<item name="android:forceDarkAllowed">false</item>
|
||||||
|
<item name="android:windowFullscreen">false</item>
|
||||||
|
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
<item name="android:windowSplashScreenBackground">#000000</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</item>
|
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</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>
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
<!-- Author: fruit.com.cn -->
|
<!-- Author: fruit.com.cn -->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<color name="splash_background">#1F1B16</color>
|
<color name="splash_background">#000000</color>
|
||||||
</resources>
|
<color name="ic_launcher_background">#000000</color>
|
||||||
|
</resources>
|
||||||
@@ -6,3 +6,8 @@ android.useAndroidX=true
|
|||||||
android.newDsl=false
|
android.newDsl=false
|
||||||
# This builtInKotlin flag was added by the Flutter template
|
# This builtInKotlin flag was added by the Flutter template
|
||||||
android.builtInKotlin=false
|
android.builtInKotlin=false
|
||||||
|
|
||||||
|
# release 包默认剥离 Dart 调试符号并混淆:libapp.so 由 ~8MB 降到 ~1MB/ABI。
|
||||||
|
# 符号表输出到 build/symbols,崩溃分析时用它还原堆栈,发布前务必归档。
|
||||||
|
split-debug-info=build/symbols
|
||||||
|
dart-obfuscation=true
|
||||||
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -1294,3 +1294,28 @@ $ flutter test
|
|||||||
- 首页榜单 tab 改为独立领奖台 + 单列排行布局,不再复用三列网格。
|
- 首页榜单 tab 改为独立领奖台 + 单列排行布局,不再复用三列网格。
|
||||||
- 前三名按 2/1/3 排列,冠军放大并上移;第 4 名起使用大号描边名次与横向信息行。
|
- 前三名按 2/1/3 排列,冠军放大并上移;第 4 名起使用大号描边名次与横向信息行。
|
||||||
- 榜单沿用现有播放热度排序、分页和播放逻辑;`flutter analyze`:No issues found。
|
- 榜单沿用现有播放热度排序、分页和播放逻辑;`flutter analyze`:No issues found。
|
||||||
|
|
||||||
|
## 2026-10-22 播放器双击点赞与飘心
|
||||||
|
|
||||||
|
- 沉浸式播放器改用 onTapUp + 280ms Timer 判定双击,双击取消单击,长按左右倍速与中间更多保持不变。
|
||||||
|
- 双击和右侧心形共用点赞方法,成功后控制器通知并点亮红色实心心形,失败由 controller 回滚并使用 Toast。
|
||||||
|
- 飘心层使用独立 IgnorePointer Stack,动画完成后自动移除;`flutter analyze`:No issues found。
|
||||||
|
- `flutter test test/player/double_tap_like_test.dart`:2 项测试全部通过。
|
||||||
|
- 移除视频表面点击识别器,双击后增加 300ms 暂停防护;飘心收敛为 3~4 颗、20~26、±18、90~120dp、600~700ms。
|
||||||
|
- 双击窗口延长至 320ms,单击 Timer 使用点击序号校验,双击后保留 350ms 播放切换保护。
|
||||||
|
- `double_tap_like_test.dart` 覆盖 120/250/300ms 双击与 500ms 单击恢复:2 项测试全部通过。
|
||||||
|
|
||||||
|
## 2026-10-22 统一二级搜索页
|
||||||
|
|
||||||
|
- 首页与推荐/剧单/全部短剧搜索入口统一 push SearchPage,不再切换推荐 tab 聚焦。
|
||||||
|
- 搜索页提供返回、自动聚焦输入框与取消,复用 `/app/search` 逻辑和首页三列卡片。
|
||||||
|
- 清理旧的 searchRequest/focusSearch/syncSearch 参数;`flutter analyze`:No issues found。
|
||||||
|
- 搜索页结果改为独立两列卡片,左右 14、列距 12、行距 16,并移除 HomeFeedCard 复用。
|
||||||
|
- 搜索结果支持下拉刷新:保留旧结果按当前关键词重取第一页,空关键词直接回弹且不改变焦点。
|
||||||
|
|
||||||
|
## 2026-10-22 App 图标与开屏更新
|
||||||
|
|
||||||
|
- Launcher/Android 12 启动背景统一纯黑,自适应图标背景改为品牌橙。
|
||||||
|
- Android/iOS 图标与启动资源已重新生成;应用内开屏固定 splash_logo,宽 200 等比居中。
|
||||||
|
- `flutter analyze`:No issues found。
|
||||||
|
- 移除 Flutter 内 `_startupSplash` 与 `startup-splash`,只保留系统原生开屏;最新斜体字标素材已重新生成。
|
||||||
@@ -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 */,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import Flutter
|
import Flutter
|
||||||
import UIKit
|
import UIKit
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
import AVKit
|
||||||
|
|
||||||
|
private let thumbnailHTTPHeaderFieldsKey = "AVURLAssetHTTPHeaderFieldsKey"
|
||||||
|
|
||||||
private final class ThumbnailResponseGate {
|
private final class ThumbnailResponseGate {
|
||||||
private let lock = NSLock()
|
private let lock = NSLock()
|
||||||
@@ -29,12 +32,325 @@ 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// iOS 影子播放器:独立 AVPlayer + AVPlayerLayer 专供画中画窗口。
|
||||||
|
/// Flutter 的 video_player 走纹理渲染,没有 AVPlayerLayer,无法直接创建
|
||||||
|
/// AVPictureInPictureController;小窗的画面与声音由影子接管,退出时把
|
||||||
|
/// 影子进度回传给 Dart,由 Flutter 播放器 seek 对齐后继续。
|
||||||
|
final class PipShadowCoordinator: NSObject, AVPictureInPictureControllerDelegate {
|
||||||
|
static let shared = PipShadowCoordinator()
|
||||||
|
|
||||||
|
private var player: AVPlayer?
|
||||||
|
private var playerLayer: AVPlayerLayer?
|
||||||
|
private var controller: AVPictureInPictureController?
|
||||||
|
private var endObserver: NSObjectProtocol?
|
||||||
|
private var possibleObservation: NSKeyValueObservation?
|
||||||
|
/// 画中画还原过渡层:原生窗口级红晕渐变,在系统还原动画开始时立即盖上,
|
||||||
|
/// 避免回前台瞬间 Flutter 表面未恢复显示黑帧;视频出帧后由 Dart 通知淡出。
|
||||||
|
private var restoreOverlay: UIView?
|
||||||
|
/// 系统要求 playerLayer 位于真实的 view 层级中才会判定画中画可用,
|
||||||
|
/// 因此用 1x1 透明宿主 view 承载,而不是直接挂在 window.layer 上。
|
||||||
|
private var hostView: UIView?
|
||||||
|
/// 影子图层就绪稍晚于创建,置位后由 KVO 自动拉起画中画。
|
||||||
|
private var pendingStart = false
|
||||||
|
private var startRetryWorkItems: [DispatchWorkItem] = []
|
||||||
|
|
||||||
|
weak var channel: FlutterMethodChannel?
|
||||||
|
|
||||||
|
/// active 变化回调;停止时把影子最终进度(毫秒)一并提供。
|
||||||
|
var onPipChanged: ((Bool, Int64) -> Void)?
|
||||||
|
/// 影子在画中画里播完当前集。
|
||||||
|
var onPlaybackEnded: (() -> Void)?
|
||||||
|
|
||||||
|
static var isSupported: Bool {
|
||||||
|
AVPictureInPictureController.isPictureInPictureSupported()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var keyWindow: UIWindow? {
|
||||||
|
UIApplication.shared.connectedScenes
|
||||||
|
.compactMap { $0 as? UIWindowScene }
|
||||||
|
.flatMap { $0.windows }
|
||||||
|
.first { $0.isKeyWindow }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 首次创建影子:1x1 图层挂在 keyWindow 的宿主 view 里(肉眼不可见),静音待命。
|
||||||
|
/// [autoEnter] 为 true 时退后台由系统自动拉起画中画(需影子在播,见 armAutoEnter)。
|
||||||
|
func prepare(urlString: String, positionMs: Int64, autoEnter: Bool) {
|
||||||
|
teardown()
|
||||||
|
log("prepare begin supported=\(PipShadowCoordinator.isSupported) autoEnter=\(autoEnter)")
|
||||||
|
guard Self.isSupported else { return }
|
||||||
|
guard let url = URL(string: urlString) else {
|
||||||
|
log("prepare failed bad url \(urlString)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard let window = keyWindow else {
|
||||||
|
log("prepare failed no key window")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let item = AVPlayerItem(url: url)
|
||||||
|
let p = AVPlayer(playerItem: item)
|
||||||
|
p.isMuted = true
|
||||||
|
p.actionAtItemEnd = .pause
|
||||||
|
let layer = AVPlayerLayer()
|
||||||
|
layer.player = p
|
||||||
|
let host = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||||
|
host.isUserInteractionEnabled = false
|
||||||
|
host.backgroundColor = .clear
|
||||||
|
window.addSubview(host)
|
||||||
|
layer.frame = host.bounds
|
||||||
|
host.layer.addSublayer(layer)
|
||||||
|
hostView = host
|
||||||
|
guard let c = AVPictureInPictureController(playerLayer: layer) else {
|
||||||
|
p.pause()
|
||||||
|
log("prepare failed no pip controller")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.canStartPictureInPictureAutomaticallyFromInline = autoEnter
|
||||||
|
c.delegate = self
|
||||||
|
player = p
|
||||||
|
playerLayer = layer
|
||||||
|
controller = c
|
||||||
|
// 静音起播让 item 完成首帧解码,isPictureInPicturePossible 才会变 true。
|
||||||
|
p.play()
|
||||||
|
possibleObservation = c.observe(
|
||||||
|
\.isPictureInPicturePossible,
|
||||||
|
options: [.new, .initial]
|
||||||
|
) { [weak self] controller, change in
|
||||||
|
let value = change.newValue ?? controller.isPictureInPicturePossible
|
||||||
|
self?.log("possible changed to \(value)")
|
||||||
|
guard let self, self.pendingStart, controller.isPictureInPicturePossible else { return }
|
||||||
|
self.pendingStart = false
|
||||||
|
// 刚翻 true 的同一 runloop 里调用会被系统静默拒绝,推到下一拍再进。
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
guard self.controller === controller, controller.isPictureInPicturePossible else {
|
||||||
|
self.log("start via kvo aborted (shadow replaced)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.log("start via kvo")
|
||||||
|
controller.startPictureInPicture()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log("shadow ready, seeking to \(positionMs)ms")
|
||||||
|
if positionMs > 0 {
|
||||||
|
p.seek(
|
||||||
|
to: CMTime(value: positionMs, timescale: 1000),
|
||||||
|
toleranceBefore: .zero,
|
||||||
|
toleranceAfter: .zero
|
||||||
|
)
|
||||||
|
}
|
||||||
|
registerEndObserver(for: item)
|
||||||
|
activateAudioSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 退出 App 前(inactive)把影子对齐到当前进度并静音起播:
|
||||||
|
/// auto PiP 只在「player 正在播放 + 图层离屏」时由系统触发。
|
||||||
|
func armAutoEnter(positionMs: Int64) {
|
||||||
|
guard let player, let controller else {
|
||||||
|
log("arm failed, shadow missing")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard controller.canStartPictureInPictureAutomaticallyFromInline else {
|
||||||
|
log("arm failed, autoEnter disabled on shadow")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log("arm auto enter at \(positionMs)ms")
|
||||||
|
if positionMs > 0 {
|
||||||
|
player.seek(
|
||||||
|
to: CMTime(value: positionMs, timescale: 1000),
|
||||||
|
toleranceBefore: CMTime(value: 800, timescale: 1000),
|
||||||
|
toleranceAfter: CMTime(value: 800, timescale: 1000)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 回前台后取消待命:影子暂停回静音,等待下一次退后台。
|
||||||
|
func disarmAutoEnter() {
|
||||||
|
guard let player else { return }
|
||||||
|
log("disarm auto enter")
|
||||||
|
player.pause()
|
||||||
|
player.isMuted = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 进入画中画:图层就绪则立即进入,否则 KVO/延时重试在就绪后自动进入。
|
||||||
|
/// 仅当影子从未创建成功(prepare 失败)时返回 false。
|
||||||
|
func start() -> Bool {
|
||||||
|
guard let controller else {
|
||||||
|
log("start failed, shadow not created")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
log("start requested possible=\(controller.isPictureInPicturePossible)")
|
||||||
|
pendingStart = true
|
||||||
|
if controller.isPictureInPicturePossible {
|
||||||
|
pendingStart = false
|
||||||
|
controller.startPictureInPicture()
|
||||||
|
}
|
||||||
|
scheduleStartRetries()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// KVO 偶发不触发或流加载较慢时兜底:就绪后再试两次。
|
||||||
|
private func scheduleStartRetries() {
|
||||||
|
startRetryWorkItems.forEach { $0.cancel() }
|
||||||
|
startRetryWorkItems.removeAll()
|
||||||
|
for delay in [1.0, 2.5] {
|
||||||
|
let item = DispatchWorkItem { [weak self] in
|
||||||
|
guard
|
||||||
|
let self,
|
||||||
|
self.pendingStart,
|
||||||
|
let controller = self.controller,
|
||||||
|
controller.isPictureInPicturePossible
|
||||||
|
else { return }
|
||||||
|
self.log("start via retry after \(delay)s")
|
||||||
|
self.pendingStart = false
|
||||||
|
controller.startPictureInPicture()
|
||||||
|
}
|
||||||
|
startRetryWorkItems.append(item)
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 画中画内换集:只换 AVPlayerItem,不动 player/layer,窗口不中断。
|
||||||
|
func replaceItem(urlString: String, positionMs: Int64) {
|
||||||
|
guard let player, let url = URL(string: urlString) else { return }
|
||||||
|
let item = AVPlayerItem(url: url)
|
||||||
|
player.replaceCurrentItem(with: item)
|
||||||
|
registerEndObserver(for: item)
|
||||||
|
if positionMs > 0 {
|
||||||
|
player.seek(
|
||||||
|
to: CMTime(value: positionMs, timescale: 1000),
|
||||||
|
toleranceBefore: .zero,
|
||||||
|
toleranceAfter: .zero
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 进入画中画后解除静音并起播(此时 Flutter 播放器已被暂停)。
|
||||||
|
func unmuteAndPlay() {
|
||||||
|
player?.isMuted = false
|
||||||
|
player?.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
func positionMs() -> Int64 {
|
||||||
|
Int64(max(0, player?.currentTime().seconds ?? 0) * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopPip() {
|
||||||
|
controller?.stopPictureInPicture()
|
||||||
|
}
|
||||||
|
|
||||||
|
func teardown() {
|
||||||
|
startRetryWorkItems.forEach { $0.cancel() }
|
||||||
|
startRetryWorkItems.removeAll()
|
||||||
|
possibleObservation?.invalidate()
|
||||||
|
possibleObservation = nil
|
||||||
|
pendingStart = false
|
||||||
|
if let endObserver {
|
||||||
|
NotificationCenter.default.removeObserver(endObserver)
|
||||||
|
}
|
||||||
|
endObserver = nil
|
||||||
|
player?.pause()
|
||||||
|
player?.replaceCurrentItem(with: nil)
|
||||||
|
playerLayer?.removeFromSuperlayer()
|
||||||
|
playerLayer = nil
|
||||||
|
hostView?.removeFromSuperview()
|
||||||
|
hostView = nil
|
||||||
|
controller?.delegate = nil
|
||||||
|
controller = nil
|
||||||
|
player = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 诊断日志:NSLog 之外同步转发到 Dart,便于在 flutter run 控制台观察。
|
||||||
|
private func log(_ message: String) {
|
||||||
|
NSLog("pip: %@", message)
|
||||||
|
channel?.invokeMethod("pipDebug", arguments: message)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func registerEndObserver(for item: AVPlayerItem) {
|
||||||
|
if let endObserver {
|
||||||
|
NotificationCenter.default.removeObserver(endObserver)
|
||||||
|
}
|
||||||
|
endObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: .AVPlayerItemDidPlayToEndTime,
|
||||||
|
object: item,
|
||||||
|
queue: .main
|
||||||
|
) { [weak self] _ in
|
||||||
|
self?.log("item did play to end")
|
||||||
|
self?.onPlaybackEnded?()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 画中画的声音走影子播放器,需要 playback 类别的音频会话保活。
|
||||||
|
private func activateAudioSession() {
|
||||||
|
do {
|
||||||
|
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)
|
||||||
|
try AVAudioSession.sharedInstance().setActive(true)
|
||||||
|
} catch {
|
||||||
|
// 会话激活失败只影响后台出声,不阻断画中画。
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pictureInPictureControllerWillStartPictureInPicture(
|
||||||
|
_ pictureInPictureController: AVPictureInPictureController
|
||||||
|
) {
|
||||||
|
log("will start")
|
||||||
|
pendingStart = false
|
||||||
|
onPipChanged?(true, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pictureInPictureControllerWillStopPictureInPicture(
|
||||||
|
_ pictureInPictureController: AVPictureInPictureController
|
||||||
|
) {
|
||||||
|
log("will stop, showing restore overlay")
|
||||||
|
showRestoreOverlay()
|
||||||
|
}
|
||||||
|
|
||||||
|
func pictureInPictureControllerDidStopPictureInPicture(
|
||||||
|
_ pictureInPictureController: AVPictureInPictureController
|
||||||
|
) {
|
||||||
|
log("did stop")
|
||||||
|
showRestoreOverlay()
|
||||||
|
onPipChanged?(false, positionMs())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 盖原生过渡层(幂等):主题红晕渐变,不依赖 Flutter 渲染。
|
||||||
|
func showRestoreOverlay() {
|
||||||
|
guard let window = keyWindow else { return }
|
||||||
|
restoreOverlay?.removeFromSuperview()
|
||||||
|
let overlay = UIView(frame: window.bounds)
|
||||||
|
overlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||||
|
let gradient = CAGradientLayer()
|
||||||
|
gradient.frame = overlay.bounds
|
||||||
|
gradient.colors = [
|
||||||
|
UIColor(red: 0.298, green: 0.086, blue: 0.102, alpha: 1).cgColor,
|
||||||
|
UIColor(red: 0.118, green: 0.043, blue: 0.047, alpha: 1).cgColor,
|
||||||
|
UIColor(red: 0.063, green: 0.063, blue: 0.071, alpha: 1).cgColor,
|
||||||
|
]
|
||||||
|
gradient.locations = [0, 0.22, 0.62]
|
||||||
|
gradient.startPoint = CGPoint(x: 0.5, y: 0)
|
||||||
|
gradient.endPoint = CGPoint(x: 0.5, y: 1)
|
||||||
|
overlay.layer.addSublayer(gradient)
|
||||||
|
window.addSubview(overlay)
|
||||||
|
restoreOverlay = overlay
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 淡出并移除过渡层(视频首帧已确认后由 Dart 调用)。
|
||||||
|
func hideRestoreOverlay() {
|
||||||
|
guard let overlay = restoreOverlay else { return }
|
||||||
|
restoreOverlay = nil
|
||||||
|
UIView.animate(
|
||||||
|
withDuration: 0.25,
|
||||||
|
animations: { overlay.alpha = 0 }
|
||||||
|
) { _ in overlay.removeFromSuperview() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 +364,20 @@ 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)
|
||||||
|
registerPipChannel(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()
|
||||||
@@ -58,15 +386,29 @@ final class RunnerFlutterViewController: FlutterViewController {
|
|||||||
guard call.method == "shareText",
|
guard call.method == "shareText",
|
||||||
let arguments = call.arguments as? [String: Any],
|
let arguments = call.arguments as? [String: Any],
|
||||||
let text = arguments["text"] as? String,
|
let text = arguments["text"] as? String,
|
||||||
!text.isEmpty,
|
!text.isEmpty else {
|
||||||
let controller = self?.window?.rootViewController else {
|
|
||||||
result(FlutterError(code: "share_unavailable", message: "Share sheet is unavailable", details: nil))
|
result(FlutterError(code: "share_unavailable", message: "Share sheet is unavailable", details: nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let activity = UIActivityViewController(activityItems: [text], applicationActivities: nil)
|
DispatchQueue.main.async {
|
||||||
activity.popoverPresentationController?.sourceView = controller.view
|
guard let controller = self?.sharePresenter() else {
|
||||||
activity.completionWithItemsHandler = { _, _, _, _ in result(nil) }
|
result(FlutterError(code: "share_unavailable", message: "Share sheet is unavailable", details: nil))
|
||||||
controller.present(activity, animated: true)
|
return
|
||||||
|
}
|
||||||
|
let activity = UIActivityViewController(activityItems: [text], applicationActivities: nil)
|
||||||
|
if let popover = activity.popoverPresentationController {
|
||||||
|
popover.sourceView = controller.view
|
||||||
|
popover.sourceRect = CGRect(
|
||||||
|
x: controller.view.bounds.midX,
|
||||||
|
y: controller.view.bounds.midY,
|
||||||
|
width: 0,
|
||||||
|
height: 0
|
||||||
|
)
|
||||||
|
popover.permittedArrowDirections = []
|
||||||
|
}
|
||||||
|
activity.completionWithItemsHandler = { _, _, _, _ in result(nil) }
|
||||||
|
controller.present(activity, animated: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let thumbnailChannel = FlutterMethodChannel(
|
let thumbnailChannel = FlutterMethodChannel(
|
||||||
@@ -104,7 +446,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 +472,158 @@ final class RunnerFlutterViewController: FlutterViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 当前前台 Scene 的根控制器之上,最适合展示系统分享面板的控制器。
|
||||||
|
private func sharePresenter() -> UIViewController? {
|
||||||
|
let keyWindow = UIApplication.shared.connectedScenes
|
||||||
|
.compactMap { $0 as? UIWindowScene }
|
||||||
|
.first { $0.activationState == .foregroundActive }?
|
||||||
|
.windows.first { $0.isKeyWindow }
|
||||||
|
guard let rootController = keyWindow?.rootViewController else { return nil }
|
||||||
|
let presenter = topPresentedController(from: rootController)
|
||||||
|
guard presenter.viewIfLoaded?.window != nil else { return nil }
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 解析已展示页面、导航栈和标签页中的当前可见控制器。
|
||||||
|
private func topPresentedController(from controller: UIViewController) -> UIViewController {
|
||||||
|
if let presented = controller.presentedViewController {
|
||||||
|
return topPresentedController(from: presented)
|
||||||
|
}
|
||||||
|
if let navigation = controller as? UINavigationController,
|
||||||
|
let visible = navigation.visibleViewController {
|
||||||
|
return topPresentedController(from: visible)
|
||||||
|
}
|
||||||
|
if let tabs = controller as? UITabBarController,
|
||||||
|
let selected = tabs.selectedViewController {
|
||||||
|
return topPresentedController(from: selected)
|
||||||
|
}
|
||||||
|
return controller
|
||||||
|
}
|
||||||
|
|
||||||
|
/// iOS 画中画:影子播放器通道,与 Android 共用同一 channel 名。
|
||||||
|
private func registerPipChannel(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||||
|
let channel = FlutterMethodChannel(
|
||||||
|
name: "com.stormg.lumadrama/pip",
|
||||||
|
binaryMessenger: engineBridge.applicationRegistrar.messenger()
|
||||||
|
)
|
||||||
|
let pip = PipShadowCoordinator.shared
|
||||||
|
pip.channel = channel
|
||||||
|
channel.setMethodCallHandler { call, result in
|
||||||
|
switch call.method {
|
||||||
|
case "isAvailable":
|
||||||
|
result(PipShadowCoordinator.isSupported)
|
||||||
|
case "enter":
|
||||||
|
guard let args = call.arguments as? [String: Any],
|
||||||
|
let url = args["url"] as? String else {
|
||||||
|
result(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let positionMs = (args["positionMs"] as? NSNumber)?.int64Value ?? 0
|
||||||
|
pip.prepare(urlString: url, positionMs: positionMs, autoEnter: false)
|
||||||
|
// 等一拍让 AVPlayerLayer 完成挂载再请求进入画中画。
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
result(pip.start())
|
||||||
|
}
|
||||||
|
case "prepareShadow":
|
||||||
|
guard let args = call.arguments as? [String: Any],
|
||||||
|
let url = args["url"] as? String else {
|
||||||
|
result(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pip.prepare(
|
||||||
|
urlString: url,
|
||||||
|
positionMs: (args["positionMs"] as? NSNumber)?.int64Value ?? 0,
|
||||||
|
autoEnter: (args["autoEnter"] as? NSNumber)?.boolValue ?? false
|
||||||
|
)
|
||||||
|
result(nil)
|
||||||
|
case "armAutoEnter":
|
||||||
|
pip.armAutoEnter(
|
||||||
|
positionMs: (call.arguments as? [String: Any])?["positionMs"] as? Int64 ?? 0
|
||||||
|
)
|
||||||
|
result(nil)
|
||||||
|
case "showRestoreOverlay":
|
||||||
|
pip.showRestoreOverlay()
|
||||||
|
result(nil)
|
||||||
|
case "hideRestoreOverlay":
|
||||||
|
pip.hideRestoreOverlay()
|
||||||
|
result(nil)
|
||||||
|
case "disarmAutoEnter":
|
||||||
|
pip.disarmAutoEnter()
|
||||||
|
result(nil)
|
||||||
|
case "unmute":
|
||||||
|
pip.unmuteAndPlay()
|
||||||
|
result(nil)
|
||||||
|
case "replaceItem":
|
||||||
|
guard let args = call.arguments as? [String: Any],
|
||||||
|
let url = args["url"] as? String else {
|
||||||
|
result(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pip.replaceItem(
|
||||||
|
urlString: url,
|
||||||
|
positionMs: (args["positionMs"] as? NSNumber)?.int64Value ?? 0
|
||||||
|
)
|
||||||
|
result(nil)
|
||||||
|
case "stop":
|
||||||
|
pip.stopPip()
|
||||||
|
result(nil)
|
||||||
|
case "teardown":
|
||||||
|
pip.teardown()
|
||||||
|
result(nil)
|
||||||
|
default:
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pip.onPipChanged = { active, positionMs in
|
||||||
|
channel.invokeMethod(
|
||||||
|
"onPipChanged",
|
||||||
|
arguments: ["active": active, "positionMs": positionMs]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
pip.onPlaybackEnded = {
|
||||||
|
channel.invokeMethod("onPipPlaybackEnded", arguments: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备标识: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: 48 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 866 B After Width: | Height: | Size: 361 B |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 799 B |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 587 B |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 799 B |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 69 B After Width: | Height: | Size: 69 B |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 20 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="1152" height="1152"/>
|
<image name="LaunchImage" width="390" height="844"/>
|
||||||
<image name="LaunchBackground" width="1" height="1"/>
|
|
||||||
</resources>
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>FruitShorts</string>
|
<string>ymb</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>FruitShorts</string>
|
<string>ymb</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
@@ -41,14 +41,7 @@
|
|||||||
<key>NSIncludesSubdomains</key>
|
<key>NSIncludesSubdomains</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
<key>localhost</key>
|
<key>192.168.31.243</key>
|
||||||
<dict>
|
|
||||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
|
||||||
<true/>
|
|
||||||
<key>NSIncludesSubdomains</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
<key>192.168.31.187</key>
|
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||||
<true/>
|
<true/>
|
||||||
@@ -62,6 +55,13 @@
|
|||||||
<key>NSIncludesSubdomains</key>
|
<key>NSIncludesSubdomains</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>localhost</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSIncludesSubdomains</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<key>NSLocalNetworkUsageDescription</key>
|
<key>NSLocalNetworkUsageDescription</key>
|
||||||
@@ -89,10 +89,16 @@
|
|||||||
</dict>
|
</dict>
|
||||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>UIBackgroundModes</key>
|
||||||
|
<array>
|
||||||
|
<string>audio</string>
|
||||||
|
</array>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>LaunchScreen</string>
|
<string>LaunchScreen</string>
|
||||||
<key>UIMainStoryboardFile</key>
|
<key>UIMainStoryboardFile</key>
|
||||||
<string>Main</string>
|
<string>Main</string>
|
||||||
|
<key>UIStatusBarHidden</key>
|
||||||
|
<false/>
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
|
|||||||
@@ -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,8 @@ 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/config_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,9 +32,11 @@ 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';
|
||||||
|
import 'core/data/services/app_config_controller.dart';
|
||||||
import 'core/data/services/auth_controller.dart';
|
import 'core/data/services/auth_controller.dart';
|
||||||
import 'core/data/services/auth_session_store.dart';
|
import 'core/data/services/auth_session_store.dart';
|
||||||
import 'core/data/services/catalog_controller.dart';
|
import 'core/data/services/catalog_controller.dart';
|
||||||
@@ -41,9 +45,11 @@ 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';
|
||||||
|
import 'core/data/services/unlocked_episode_registry.dart';
|
||||||
import 'core/data/services/video_player_port.dart';
|
import 'core/data/services/video_player_port.dart';
|
||||||
import 'core/data/services/wallet_controller.dart';
|
import 'core/data/services/wallet_controller.dart';
|
||||||
import 'core/navigation/app_route_observer.dart';
|
import 'core/navigation/app_route_observer.dart';
|
||||||
@@ -83,6 +89,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 +110,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 +121,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 +135,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 +146,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 +182,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));
|
||||||
|
|
||||||
@@ -198,15 +210,25 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
|
|
||||||
late final LocaleController _localeController = LocaleController();
|
late final LocaleController _localeController = LocaleController();
|
||||||
|
|
||||||
|
/// 后台下发的启动配置(登录页背景等);拉不到就用本地默认。
|
||||||
|
late final AppConfigController _appConfigController = AppConfigController(
|
||||||
|
ConfigApi(_apiClient),
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 登录期内共享的「已解锁收费集」:播放页进出、feed 与全屏切换都要沿用。
|
||||||
|
late final UnlockedEpisodeRegistry _unlockedEpisodes =
|
||||||
|
UnlockedEpisodeRegistry();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// 恢复本地令牌与设备号;未登录也能正常浏览,不阻塞首屏
|
// 恢复本地令牌与设备号;未登录也能正常浏览,不阻塞首屏
|
||||||
_auth.load();
|
_auth.load();
|
||||||
unawaited(_localeController.load());
|
unawaited(_localeController.load());
|
||||||
|
unawaited(_appConfigController.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());
|
||||||
}
|
}
|
||||||
@@ -217,11 +239,14 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
if (_auth.isSignedIn == _wasSignedIn) return;
|
if (_auth.isSignedIn == _wasSignedIn) return;
|
||||||
_wasSignedIn = _auth.isSignedIn;
|
_wasSignedIn = _auth.isSignedIn;
|
||||||
_interactionController.clear();
|
_interactionController.clear();
|
||||||
|
// 解锁结论属于账号:换人登录后不能沿用上一个人的可播判断。
|
||||||
|
_unlockedEpisodes.clear();
|
||||||
if (_auth.isSignedIn) {
|
if (_auth.isSignedIn) {
|
||||||
unawaited(_favoriteController.load());
|
unawaited(_favoriteController.load());
|
||||||
unawaited(_walletController.load());
|
unawaited(_walletController.load());
|
||||||
} else {
|
} else {
|
||||||
_favoriteController.clear();
|
_favoriteController.clear();
|
||||||
|
unawaited(_favoriteController.load());
|
||||||
_downloadController.reset();
|
_downloadController.reset();
|
||||||
_walletController.reset();
|
_walletController.reset();
|
||||||
}
|
}
|
||||||
@@ -235,20 +260,36 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
_walletController.dispose();
|
_walletController.dispose();
|
||||||
_interactionController.dispose();
|
_interactionController.dispose();
|
||||||
_localeController.dispose();
|
_localeController.dispose();
|
||||||
|
_appConfigController.dispose();
|
||||||
_apiClient.close();
|
_apiClient.close();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CategoryController _createCategories() {
|
||||||
|
final controller = CategoryController(_categoryRepository);
|
||||||
|
if (widget.catalogRepository == null) {
|
||||||
|
final api = CategoryApi(_apiClient);
|
||||||
|
controller.dramaPageLoader = api.dramas;
|
||||||
|
controller.rankingLoader = api.ranking;
|
||||||
|
}
|
||||||
|
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<UnlockedEpisodeRegistry>.value(value: _unlockedEpisodes),
|
||||||
Provider<WatchHistoryRepository>.value(value: _watchHistory),
|
Provider<WatchHistoryRepository>.value(value: _watchHistory),
|
||||||
Provider<FavoriteRepository>.value(value: _favorites),
|
Provider<FavoriteRepository>.value(value: _favorites),
|
||||||
Provider<CommentRepository>.value(value: _commentRepository),
|
Provider<CommentRepository>.value(value: _commentRepository),
|
||||||
@@ -260,16 +301,21 @@ 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),
|
||||||
ChangeNotifierProvider.value(value: _interactionController),
|
ChangeNotifierProvider.value(value: _interactionController),
|
||||||
ChangeNotifierProvider.value(value: _localeController),
|
ChangeNotifierProvider.value(value: _localeController),
|
||||||
|
ChangeNotifierProvider.value(value: _appConfigController),
|
||||||
ChangeNotifierProvider.value(value: _auth),
|
ChangeNotifierProvider.value(value: _auth),
|
||||||
],
|
],
|
||||||
child: Consumer<LocaleController>(
|
child: Consumer<LocaleController>(
|
||||||
|
|||||||
@@ -1,165 +1,51 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
/// 客户端与后端约定的运行时配置。
|
import 'dev_config.dart';
|
||||||
|
import 'prod_config.dart';
|
||||||
|
|
||||||
|
/// 客户端运行时配置。
|
||||||
///
|
///
|
||||||
/// 接口地址优先级:运行时设置 > `--dart-define=API_BASE_URL=...` > 平台默认值。
|
/// 两套环境各一个文件:
|
||||||
/// 开发机的局域网地址会随网络变化,换网络后改 [devHostBaseUrl] 即可。
|
/// - `dev_config.dart`:[DevConfig](本机联调)
|
||||||
class AppConfig {
|
/// - `prod_config.dart`:[ProdConfig](生产)
|
||||||
const AppConfig._();
|
///
|
||||||
|
/// Debug 使用开发环境,Release 自动使用生产环境,不做网络探测。
|
||||||
|
abstract final class AppConfig {
|
||||||
|
/// **环境开关**:Debug 使用开发环境,Release 使用生产环境。
|
||||||
|
static const bool useDevConfig = !kReleaseMode;
|
||||||
|
|
||||||
/// 开发调试默认服务地址,当前指向本机局域网 IP。
|
/// 当前选中的环境地址。
|
||||||
///
|
static String get baseUrl =>
|
||||||
/// 换网络时只改这一行,地址不要带结尾斜杠。
|
useDevConfig ? DevConfig.baseUrl : ProdConfig.baseUrl;
|
||||||
static const String devHostBaseUrl = 'http://192.168.31.187:8081';
|
|
||||||
|
|
||||||
/// 本机后端地址:通过 `adb reverse tcp:8081 tcp:8081` 映射到开发机,
|
|
||||||
/// 探测可达时 App 直连本机服务;不可达时回落到公网地址。
|
|
||||||
static const String lanBaseUrl = 'http://127.0.0.1:8081';
|
|
||||||
|
|
||||||
/// 公网地址(远程/移动网络访问时使用)。
|
|
||||||
static const String publicBaseUrl = 'http://39.162.50.99:8081';
|
|
||||||
|
|
||||||
static const String _overrideBaseUrl = String.fromEnvironment('API_BASE_URL');
|
|
||||||
|
|
||||||
|
/// 调试面板手改的地址(见 `ServerEndpoint`);为空表示用上面的环境地址。
|
||||||
static String _runtimeBaseUrl = '';
|
static String _runtimeBaseUrl = '';
|
||||||
|
|
||||||
|
/// 启动期异步准备(iOS 无线数据权限弹窗),目录请求前等待它。
|
||||||
static Future<void>? _ready;
|
static Future<void>? _ready;
|
||||||
|
|
||||||
/// 启动地址探测完成信号;默认已完成,避免影响既有测试与调用方。
|
/// 启动准备完成信号;默认已完成,避免影响既有测试与调用方。
|
||||||
static Future<void> get ready => _ready ?? Future<void>.value();
|
static Future<void> get ready => _ready ?? Future<void>.value();
|
||||||
static set ready(Future<void> value) => _ready = value;
|
static set ready(Future<void> value) => _ready = value;
|
||||||
|
|
||||||
static const Duration _probeTimeout = Duration(seconds: 2);
|
static const Duration requestTimeout = Duration(seconds: 8);
|
||||||
static const List<String> _probeCandidates = [
|
|
||||||
lanBaseUrl,
|
|
||||||
devHostBaseUrl,
|
|
||||||
if (devHostBaseUrl != publicBaseUrl) publicBaseUrl,
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Build-time server URL supplied through `--dart-define=API_BASE_URL`.
|
/// 实际使用的服务地址:运行时手改优先,否则用环境开关选中的地址。
|
||||||
static String get compiledBaseUrl => _overrideBaseUrl;
|
static String get apiBaseUrl =>
|
||||||
|
_runtimeBaseUrl.isNotEmpty ? _runtimeBaseUrl : baseUrl;
|
||||||
|
|
||||||
/// Existing platform-aware fallback used when no runtime or build override exists.
|
/// 应用一个已经规范化的运行时地址;传 null 表示清除。
|
||||||
static String get defaultBaseUrl => _defaultBaseUrl;
|
|
||||||
|
|
||||||
/// Effective server URL, including the debug-only runtime override.
|
|
||||||
static String get apiBaseUrl => _runtimeBaseUrl.isNotEmpty
|
|
||||||
? _runtimeBaseUrl
|
|
||||||
: (compiledBaseUrl.isNotEmpty ? compiledBaseUrl : defaultBaseUrl);
|
|
||||||
|
|
||||||
static final String _defaultBaseUrl = _runsOnDevMachine
|
|
||||||
? lanBaseUrl
|
|
||||||
: devHostBaseUrl;
|
|
||||||
|
|
||||||
/// 模拟器、桌面端与开发机同机,环回地址可用;iOS 真机不满足。
|
|
||||||
/// Android 没有等价的探测方式,统一按真机处理(模拟器用
|
|
||||||
/// `--dart-define=API_BASE_URL=http://10.0.2.2:8081` 覆盖)。
|
|
||||||
static final bool _runsOnDevMachine =
|
|
||||||
kIsWeb ||
|
|
||||||
defaultTargetPlatform == TargetPlatform.macOS ||
|
|
||||||
defaultTargetPlatform == TargetPlatform.windows ||
|
|
||||||
defaultTargetPlatform == TargetPlatform.linux ||
|
|
||||||
(defaultTargetPlatform == TargetPlatform.iOS &&
|
|
||||||
Platform.environment.containsKey('SIMULATOR_DEVICE_NAME'));
|
|
||||||
|
|
||||||
/// Applies an already normalized runtime URL. Passing null clears it.
|
|
||||||
static void applyRuntimeBaseUrl(String? value) {
|
static void applyRuntimeBaseUrl(String? value) {
|
||||||
_runtimeBaseUrl = value ?? '';
|
_runtimeBaseUrl = value ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clears the in-memory runtime override, mainly for tests and restarts.
|
/// 清除运行时地址,主要给测试与重启流程用。
|
||||||
static void clearRuntimeBaseUrl() {
|
static void clearRuntimeBaseUrl() {
|
||||||
_runtimeBaseUrl = '';
|
_runtimeBaseUrl = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Duration requestTimeout = Duration(seconds: 8);
|
|
||||||
|
|
||||||
/// 按环回、开发机、公网顺序探测,写入首个返回 200 的地址。
|
|
||||||
///
|
|
||||||
/// 全部不可达时使用平台默认地址,真机保留开发机地址,避免退回公网。
|
|
||||||
static Future<void> probeAndApplyBaseUrl({
|
|
||||||
Future<bool> Function(String baseUrl)? probe,
|
|
||||||
String? fallbackBaseUrl,
|
|
||||||
|
|
||||||
/// 编译期地址测试注入;未传时读取 `API_BASE_URL`。
|
|
||||||
String? compiledOverride,
|
|
||||||
}) async {
|
|
||||||
final compiled = compiledOverride ?? compiledBaseUrl;
|
|
||||||
if (compiled.isNotEmpty) {
|
|
||||||
if (_runtimeBaseUrl.isEmpty) applyRuntimeBaseUrl(compiled);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final candidates = <String>[
|
|
||||||
if (_runtimeBaseUrl.isNotEmpty) _runtimeBaseUrl,
|
|
||||||
for (final candidate in _probeCandidates)
|
|
||||||
if (candidate != _runtimeBaseUrl) candidate,
|
|
||||||
];
|
|
||||||
final results = await Future.wait([
|
|
||||||
for (final candidate in candidates)
|
|
||||||
probe == null
|
|
||||||
? _probeBaseUrl(candidate)
|
|
||||||
: _runInjectedProbe(candidate, probe),
|
|
||||||
]);
|
|
||||||
for (var index = 0; index < candidates.length; index++) {
|
|
||||||
final candidate = candidates[index];
|
|
||||||
final result = results[index];
|
|
||||||
if (kDebugMode) {
|
|
||||||
final status = result.ok
|
|
||||||
? 'ok'
|
|
||||||
: 'fail(${result.reason ?? 'request failed'})';
|
|
||||||
debugPrint('[probe] $candidate -> $status');
|
|
||||||
}
|
|
||||||
if (result.ok) {
|
|
||||||
applyRuntimeBaseUrl(candidate);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
applyRuntimeBaseUrl(fallbackBaseUrl ?? defaultBaseUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<_ProbeResult> _runInjectedProbe(
|
|
||||||
String baseUrl,
|
|
||||||
Future<bool> Function(String baseUrl) probe,
|
|
||||||
) async {
|
|
||||||
try {
|
|
||||||
return _ProbeResult(ok: await probe(baseUrl));
|
|
||||||
} catch (error) {
|
|
||||||
return _ProbeResult(ok: false, reason: error.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<_ProbeResult> _probeBaseUrl(String baseUrl) async {
|
|
||||||
final client = HttpClient()..connectionTimeout = _probeTimeout;
|
|
||||||
try {
|
|
||||||
return await _requestCategories(
|
|
||||||
client,
|
|
||||||
Uri.parse('$baseUrl/app/categories'),
|
|
||||||
).timeout(_probeTimeout);
|
|
||||||
} catch (error) {
|
|
||||||
return _ProbeResult(ok: false, reason: error.toString());
|
|
||||||
} finally {
|
|
||||||
client.close(force: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<_ProbeResult> _requestCategories(
|
|
||||||
HttpClient client,
|
|
||||||
Uri uri,
|
|
||||||
) async {
|
|
||||||
final request = await client.getUrl(uri);
|
|
||||||
final response = await request.close();
|
|
||||||
await response.drain<void>();
|
|
||||||
final ok = response.statusCode == 200;
|
|
||||||
return _ProbeResult(
|
|
||||||
ok: ok,
|
|
||||||
reason: ok ? null : 'HTTP ${response.statusCode}',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 后端返回的是相对路径(/files/...),这里补上服务地址。
|
/// 后端返回的是相对路径(/files/...),这里补上服务地址。
|
||||||
static String mediaUrl(String path) {
|
static String mediaUrl(String path) {
|
||||||
if (path.isEmpty) return '';
|
if (path.isEmpty) return '';
|
||||||
@@ -167,10 +53,3 @@ class AppConfig {
|
|||||||
return '$apiBaseUrl$path';
|
return '$apiBaseUrl$path';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ProbeResult {
|
|
||||||
const _ProbeResult({required this.ok, this.reason});
|
|
||||||
|
|
||||||
final bool ok;
|
|
||||||
final String? reason;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
/// 开发环境配置。
|
||||||
|
///
|
||||||
|
/// 本机联调用:模拟器与桌面端可直接用回环地址,但 iOS/Android 真机必须用
|
||||||
|
/// 开发机的局域网 IP(真机上的 127.0.0.1 指向手机自己)。地址不要带结尾斜杠。
|
||||||
|
abstract final class DevConfig {
|
||||||
|
/// 开发机后端地址(Mac 当前 Wi-Fi 地址,换网络后需要同步修改)。
|
||||||
|
static const String baseUrl = 'http://192.168.31.243:8081';
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
/// 生产环境配置。
|
||||||
|
///
|
||||||
|
/// 发版前确认这里的 [baseUrl],地址不要带结尾斜杠。
|
||||||
|
abstract final class ProdConfig {
|
||||||
|
/// 生产后端地址。
|
||||||
|
static const String baseUrl = 'http://39.162.50.99:8081';
|
||||||
|
}
|
||||||
@@ -22,16 +22,9 @@ abstract final class ServerEndpoint {
|
|||||||
return value.replaceFirst(RegExp(r'/+$'), '');
|
return value.replaceFirst(RegExp(r'/+$'), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves runtime > dart-define > default using normalized valid values.
|
/// 运行时手改优先,其次构建期默认地址;两者都必须先通过规范校验。
|
||||||
static String resolve({
|
static String resolve({required String? stored, required String fallback}) {
|
||||||
required String? stored,
|
return normalize(stored) ?? normalize(fallback) ?? fallback;
|
||||||
required String compiled,
|
|
||||||
required String fallback,
|
|
||||||
}) {
|
|
||||||
return normalize(stored) ??
|
|
||||||
normalize(compiled) ??
|
|
||||||
normalize(fallback) ??
|
|
||||||
fallback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads the persisted override before the app creates its ApiClient.
|
/// Loads the persisted override before the app creates its ApiClient.
|
||||||
@@ -46,11 +39,7 @@ abstract final class ServerEndpoint {
|
|||||||
final prefs = preferences ?? SharedPreferencesAsync();
|
final prefs = preferences ?? SharedPreferencesAsync();
|
||||||
final stored = await prefs.getString(preferenceKey);
|
final stored = await prefs.getString(preferenceKey);
|
||||||
AppConfig.applyRuntimeBaseUrl(
|
AppConfig.applyRuntimeBaseUrl(
|
||||||
resolve(
|
resolve(stored: stored, fallback: AppConfig.baseUrl),
|
||||||
stored: stored,
|
|
||||||
compiled: AppConfig.compiledBaseUrl,
|
|
||||||
fallback: AppConfig.defaultBaseUrl,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
AppConfig.clearRuntimeBaseUrl();
|
AppConfig.clearRuntimeBaseUrl();
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'drama.dart';
|
||||||
|
import 'locale_text.dart';
|
||||||
|
|
||||||
|
/// 服务端推荐榜快照;顺序和排名均不可在客户端重算。
|
||||||
|
class CategoryRanking {
|
||||||
|
const CategoryRanking({
|
||||||
|
required this.id,
|
||||||
|
required this.code,
|
||||||
|
required this.revision,
|
||||||
|
required this.entries,
|
||||||
|
this.locales = const {},
|
||||||
|
this.generatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String id;
|
||||||
|
final String code;
|
||||||
|
final String revision;
|
||||||
|
final Map<String, String> locales;
|
||||||
|
final DateTime? generatedAt;
|
||||||
|
final List<CategoryRankingEntry> entries;
|
||||||
|
|
||||||
|
/// 解析 `GET /app/categories/{id}/ranking`。
|
||||||
|
factory CategoryRanking.fromJson(Map<String, dynamic> json) {
|
||||||
|
final rawList = json['list'];
|
||||||
|
final entries = rawList is List
|
||||||
|
? rawList
|
||||||
|
.whereType<Map>()
|
||||||
|
.map(
|
||||||
|
(item) =>
|
||||||
|
CategoryRankingEntry.fromJson(item.cast<String, dynamic>()),
|
||||||
|
)
|
||||||
|
.toList(growable: false)
|
||||||
|
: const <CategoryRankingEntry>[];
|
||||||
|
return CategoryRanking(
|
||||||
|
id: (json['id'] ?? '').toString(),
|
||||||
|
code: json['code'] as String? ?? '',
|
||||||
|
revision: (json['revision'] ?? '1').toString(),
|
||||||
|
locales: localeMap(json['locales']),
|
||||||
|
generatedAt: DateTime.tryParse(json['generatedAt'] as String? ?? ''),
|
||||||
|
entries: entries,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 推荐榜中的一部短剧及其服务端排名。
|
||||||
|
class CategoryRankingEntry {
|
||||||
|
const CategoryRankingEntry({required this.rank, required this.drama});
|
||||||
|
|
||||||
|
final int rank;
|
||||||
|
final Drama drama;
|
||||||
|
|
||||||
|
factory CategoryRankingEntry.fromJson(Map<String, dynamic> json) {
|
||||||
|
final rawDrama = json['drama'];
|
||||||
|
return CategoryRankingEntry(
|
||||||
|
rank: (json['rank'] as num?)?.toInt() ?? 0,
|
||||||
|
drama: Drama.fromCardJson(
|
||||||
|
rawDrama is Map<String, dynamic>
|
||||||
|
? rawDrama
|
||||||
|
: rawDrama is Map
|
||||||
|
? rawDrama.cast<String, dynamic>()
|
||||||
|
: const <String, dynamic>{},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,48 @@
|
|||||||
// 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.code = '',
|
||||||
|
this.layoutType = gridLayout,
|
||||||
|
this.revision = '1',
|
||||||
|
this.locales = const {},
|
||||||
|
});
|
||||||
|
|
||||||
|
static const String gridLayout = 'GRID';
|
||||||
|
static const String rankingLayout = 'RANKING';
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
final String code;
|
||||||
|
final String layoutType;
|
||||||
|
final String revision;
|
||||||
|
|
||||||
|
/// 中文名称,与 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) {
|
||||||
|
final locales = localeMap(json['locales']);
|
||||||
|
final name = json['name'] as String? ?? locales['zh'] ?? '';
|
||||||
return ContentCategory(
|
return ContentCategory(
|
||||||
id: (json['id'] ?? '').toString(),
|
id: (json['id'] ?? '').toString(),
|
||||||
name: json['name'] as String? ?? '',
|
name: name,
|
||||||
|
code: json['code'] as String? ?? '',
|
||||||
|
layoutType: json['layoutType'] as String? ?? gridLayout,
|
||||||
|
revision: (json['revision'] ?? '1').toString(),
|
||||||
|
locales: locales,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get isRanking => layoutType == rankingLayout;
|
||||||
|
|
||||||
|
/// 按界面语言取名称。缺对应语言时回落到中文。
|
||||||
|
String localizedName(String languageCode) {
|
||||||
|
return localizedText(languageCode, name, locales);
|
||||||
|
}
|
||||||
}
|
}
|
||||||