diff --git a/lib/http/video.dart b/lib/http/video.dart index 04039efd..17f84200 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -241,10 +241,11 @@ class VideoHttp { // 获取投币状态 static Future hasCoinVideo({required String bvid}) async { var res = await Request().get(Api.hasCoinVideo, data: {'bvid': bvid}); + print('res: $res'); if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { - return {'status': true, 'data': []}; + return {'status': false, 'data': []}; } } @@ -378,7 +379,7 @@ class VideoHttp { if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { - return {'status': true, 'data': []}; + return {'status': false, 'data': []}; } } @@ -394,7 +395,7 @@ class VideoHttp { if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { - return {'status': true, 'data': []}; + return {'status': false, 'data': []}; } } @@ -472,10 +473,7 @@ class VideoHttp { 'data': AiConclusionModel.fromJson(res.data['data']), }; } else { - return { - 'status': false, - 'data': [] - }; + return {'status': false, 'data': []}; } } } diff --git a/lib/models/common/dynamic_badge_mode.dart b/lib/models/common/dynamic_badge_mode.dart new file mode 100644 index 00000000..2609c5e2 --- /dev/null +++ b/lib/models/common/dynamic_badge_mode.dart @@ -0,0 +1,9 @@ +enum DynamicBadgeMode { hidden, point, number } + +extension DynamicBadgeModeDesc on DynamicBadgeMode { + String get description => ['隐藏', '红点', '数字'][index]; +} + +extension DynamicBadgeModeCode on DynamicBadgeMode { + int get code => [0, 1, 2][index]; +} diff --git a/lib/models/github/latest.dart b/lib/models/github/latest.dart index 8730a4ba..c4b88b63 100644 --- a/lib/models/github/latest.dart +++ b/lib/models/github/latest.dart @@ -17,8 +17,9 @@ class LatestDataModel { url = json['url']; tagName = json['tag_name']; createdAt = json['created_at']; - assets = - json['assets'].map((e) => AssetItem.fromJson(e)).toList(); + assets = json['assets'] != null + ? json['assets'].map((e) => AssetItem.fromJson(e)).toList() + : []; body = json['body']; } } diff --git a/lib/pages/main/controller.dart b/lib/pages/main/controller.dart index a55c143e..6f33d9cd 100644 --- a/lib/pages/main/controller.dart +++ b/lib/pages/main/controller.dart @@ -11,6 +11,7 @@ import 'package:pilipala/pages/home/view.dart'; import 'package:pilipala/pages/media/index.dart'; import 'package:pilipala/utils/storage.dart'; import 'package:pilipala/utils/utils.dart'; +import '../../models/common/dynamic_badge_mode.dart'; class MainController extends GetxController { List pages = [ @@ -65,6 +66,7 @@ class MainController extends GetxController { int selectedIndex = 0; Box userInfoCache = GStrorage.userInfo; RxBool userLogin = false.obs; + late Rx dynamicBadgeType = DynamicBadgeMode.number.obs; @override void onInit() { @@ -75,7 +77,12 @@ class MainController extends GetxController { hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true); var userInfo = userInfoCache.get('userInfoCache'); userLogin.value = userInfo != null; - getUnreadDynamic(); + dynamicBadgeType.value = DynamicBadgeMode.values[setting.get( + SettingBoxKey.dynamicBadgeMode, + defaultValue: DynamicBadgeMode.number.code)]; + if (dynamicBadgeType.value != DynamicBadgeMode.hidden) { + getUnreadDynamic(); + } } void onBackPressed(BuildContext context) { diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 8a0af8f8..04e0f087 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; +import 'package:pilipala/models/common/dynamic_badge_mode.dart'; import 'package:pilipala/pages/dynamics/index.dart'; import 'package:pilipala/pages/home/index.dart'; import 'package:pilipala/pages/media/index.dart'; @@ -127,16 +128,21 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { destinations: [ ..._mainController.navigationBars.map((e) { return NavigationDestination( - icon: Badge( - backgroundColor: - Theme.of(context).colorScheme.primary, - textColor: Theme.of(context) - .colorScheme - .onInverseSurface, - label: Text(e['count'].toString()), - padding: const EdgeInsets.fromLTRB(6, 0, 6, 0), - isLabelVisible: e['count'] > 0, - child: e['icon'], + icon: Obx( + () => Badge( + label: + _mainController.dynamicBadgeType.value == + DynamicBadgeMode.number + ? Text(e['count'].toString()) + : null, + padding: + const EdgeInsets.fromLTRB(6, 0, 6, 0), + isLabelVisible: + _mainController.dynamicBadgeType.value != + DynamicBadgeMode.hidden && + e['count'] > 0, + child: e['icon'], + ), ), selectedIcon: e['selectIcon'], label: e['label'], @@ -153,16 +159,21 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { items: [ ..._mainController.navigationBars.map((e) { return BottomNavigationBarItem( - icon: Badge( - backgroundColor: - Theme.of(context).colorScheme.primary, - textColor: Theme.of(context) - .colorScheme - .onInverseSurface, - label: Text(e['count'].toString()), - padding: const EdgeInsets.fromLTRB(6, 0, 6, 0), - isLabelVisible: e['count'] > 0, - child: e['icon'], + icon: Obx( + () => Badge( + label: + _mainController.dynamicBadgeType.value == + DynamicBadgeMode.number + ? Text(e['count'].toString()) + : null, + padding: + const EdgeInsets.fromLTRB(6, 0, 6, 0), + isLabelVisible: + _mainController.dynamicBadgeType.value != + DynamicBadgeMode.hidden && + e['count'] > 0, + child: e['icon'], + ), ), activeIcon: e['selectIcon'], label: e['label'], diff --git a/lib/pages/setting/controller.dart b/lib/pages/setting/controller.dart index afd14156..2e6680e5 100644 --- a/lib/pages/setting/controller.dart +++ b/lib/pages/setting/controller.dart @@ -7,6 +7,9 @@ import 'package:pilipala/models/common/theme_type.dart'; import 'package:pilipala/utils/feed_back.dart'; import 'package:pilipala/utils/login.dart'; import 'package:pilipala/utils/storage.dart'; +import '../../models/common/dynamic_badge_mode.dart'; +import '../main/index.dart'; +import 'widgets/select_dialog.dart'; class SettingController extends GetxController { Box userInfoCache = GStrorage.userInfo; @@ -19,6 +22,7 @@ class SettingController extends GetxController { RxInt picQuality = 10.obs; Rx themeType = ThemeType.system.obs; var userInfo; + Rx dynamicBadgeType = DynamicBadgeMode.number.obs; @override void onInit() { @@ -33,6 +37,9 @@ class SettingController extends GetxController { setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode, defaultValue: ThemeType.system.code)]; + dynamicBadgeType.value = DynamicBadgeMode.values[setting.get( + SettingBoxKey.dynamicBadgeMode, + defaultValue: DynamicBadgeMode.number.code)]; } loginOut() async { @@ -76,4 +83,31 @@ class SettingController extends GetxController { feedBackEnable.value = !feedBackEnable.value; setting.put(SettingBoxKey.feedBackEnable, feedBackEnable.value); } + + // 设置动态未读标记 + setDynamicBadgeMode(BuildContext context) async { + DynamicBadgeMode? result = await showDialog( + context: context, + builder: (context) { + return SelectDialog( + title: '动态未读标记', + value: dynamicBadgeType.value, + values: DynamicBadgeMode.values.map((e) { + return {'title': e.description, 'value': e}; + }).toList(), + ); + }, + ); + if (result != null) { + dynamicBadgeType.value = result; + setting.put(SettingBoxKey.dynamicBadgeMode, result.code); + MainController mainController = Get.put(MainController()); + mainController.dynamicBadgeType.value = + DynamicBadgeMode.values[result.code]; + if (mainController.dynamicBadgeType.value != DynamicBadgeMode.hidden) { + mainController.getUnreadDynamic(); + } + SmartDialog.showToast('设置成功'); + } + } } diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index df1df9c0..ba2f2276 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -10,6 +10,7 @@ import 'package:pilipala/pages/setting/widgets/select_dialog.dart'; import 'package:pilipala/pages/setting/widgets/slide_dialog.dart'; import 'package:pilipala/utils/storage.dart'; +import '../../models/common/dynamic_badge_mode.dart'; import 'controller.dart'; import 'widgets/switch_item.dart'; @@ -244,6 +245,14 @@ class _StyleSettingState extends State { '当前模式:${settingController.themeType.value.description}', style: subTitleStyle)), ), + ListTile( + dense: false, + onTap: () => settingController.setDynamicBadgeMode(context), + title: Text('动态未读标记', style: titleStyle), + subtitle: Obx(() => Text( + '当前标记样式:${settingController.dynamicBadgeType.value.description}', + style: subTitleStyle)), + ), ListTile( dense: false, onTap: () => Get.toNamed('/colorSetting'), diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 1deadb07..d1298fcc 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -148,7 +148,9 @@ class VideoIntroController extends GetxController { // 获取投币状态 Future queryHasCoinVideo() async { var result = await VideoHttp.hasCoinVideo(bvid: bvid); - hasCoin.value = result["data"]['multiply'] == 0 ? false : true; + if (result['status']) { + hasCoin.value = result["data"]['multiply'] == 0 ? false : true; + } } // 获取收藏状态 @@ -208,6 +210,10 @@ class VideoIntroController extends GetxController { // (取消)点赞 Future actionLikeVideo() async { + if (userInfo == null) { + SmartDialog.showToast('账号未登录'); + return; + } var result = await VideoHttp.likeVideo(bvid: bvid, type: !hasLike.value); if (result['status']) { // hasLike.value = result["data"] == 1 ? true : false; diff --git a/lib/services/audio_handler.dart b/lib/services/audio_handler.dart index 61b32b96..ad510e7d 100644 --- a/lib/services/audio_handler.dart +++ b/lib/services/audio_handler.dart @@ -147,8 +147,8 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { processingState: AudioProcessingState.idle, playing: false, )); - _item.removeLast(); if (_item.isNotEmpty) { + _item.removeLast(); setMediaItem(_item.last); } if (_item.isEmpty) { diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index f12e4cb9..1bc94e58 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -139,7 +139,8 @@ class SettingBoxKey { enableMYBar = 'enableMYBar', hideSearchBar = 'hideSearchBar', // 收起顶栏 hideTabBar = 'hideTabBar', // 收起底栏 - tabbarSort = 'tabbarSort'; // 首页tabbar + tabbarSort = 'tabbarSort', // 首页tabbar + dynamicBadgeMode = 'dynamicBadgeMode'; } class LocalCacheKey { diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 27aae06b..3e9762fd 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -301,16 +301,18 @@ class Utils { // [arm64-v8a] String abi = androidInfo.supportedAbis.first; late String downloadUrl; - for (var i in data.assets) { - if (i.downloadUrl.contains(abi)) { - downloadUrl = i.downloadUrl; + if (data.assets.isNotEmpty) { + for (var i in data.assets) { + if (i.downloadUrl.contains(abi)) { + downloadUrl = i.downloadUrl; + } } + // 应用外下载 + launchUrl( + Uri.parse(downloadUrl), + mode: LaunchMode.externalApplication, + ); } - // 应用外下载 - launchUrl( - Uri.parse(downloadUrl), - mode: LaunchMode.externalApplication, - ); } } diff --git a/pubspec.lock b/pubspec.lock index 3babcab8..2639cebc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -500,10 +500,11 @@ packages: floating: dependency: "direct main" description: - name: floating - sha256: d9d563089e34fbd714ffdcdd2df447ec41b40c9226dacae6b4f78847aef8b991 - url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" - source: hosted + path: "." + ref: main + resolved-ref: d2d8421c4d80f6113f832404109853684721e11a + url: "https://github.com/guozhigq/floating.git" + source: git version: "2.0.1" flutter: dependency: "direct main" diff --git a/pubspec.yaml b/pubspec.yaml index f4b8fe61..16df4ad7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -124,7 +124,10 @@ dependencies: # 代理 system_proxy: ^0.1.0 # pip - floating: ^2.0.1 + floating: + git: + url: https://github.com/guozhigq/floating.git + ref: main # html解析 html: ^0.15.4 # html渲染