From 105a29f311e363ce0d4e529f269047cea522847e Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 8 Mar 2024 22:56:16 +0800 Subject: [PATCH 01/12] feat: disable Battery Optimization --- lib/main.dart | 2 ++ lib/services/disable_battery_opt.dart | 40 +++++++++++++++++++++++++++ lib/utils/storage.dart | 4 +++ pubspec.lock | 8 ++++++ pubspec.yaml | 2 ++ 5 files changed, 56 insertions(+) create mode 100644 lib/services/disable_battery_opt.dart diff --git a/lib/main.dart b/lib/main.dart index fc2149ded..44bb1dcd6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,6 +16,7 @@ import 'package:pilipala/pages/search/index.dart'; import 'package:pilipala/pages/video/detail/index.dart'; import 'package:pilipala/router/app_pages.dart'; import 'package:pilipala/pages/main/view.dart'; +import 'package:pilipala/services/disable_battery_opt.dart'; import 'package:pilipala/services/service_locator.dart'; import 'package:pilipala/utils/app_scheme.dart'; import 'package:pilipala/utils/data.dart'; @@ -71,6 +72,7 @@ void main() async { )); Data.init(); PiliSchame.init(); + DisableBatteryOpt(); }); } diff --git a/lib/services/disable_battery_opt.dart b/lib/services/disable_battery_opt.dart new file mode 100644 index 000000000..ae0189775 --- /dev/null +++ b/lib/services/disable_battery_opt.dart @@ -0,0 +1,40 @@ +import 'dart:io'; + +import 'package:disable_battery_optimization/disable_battery_optimization.dart'; +import 'package:pilipala/utils/storage.dart'; + +void DisableBatteryOpt() async { + if (!Platform.isAndroid) { + return; + } + // 本地缓存中读取 是否禁用了电池优化 默认未禁用 + bool isDisableBatteryOptLocal = + GStrorage.localCache.get('isDisableBatteryOptLocal', defaultValue: false); + if (!isDisableBatteryOptLocal) { + final isBatteryOptimizationDisabled = + await DisableBatteryOptimization.isBatteryOptimizationDisabled; + if (isBatteryOptimizationDisabled == false) { + final hasDisabled = await DisableBatteryOptimization + .showDisableBatteryOptimizationSettings(); + // 设置为已禁用 + GStrorage.localCache.put('isDisableBatteryOptLocal', hasDisabled == true); + } + } + + bool isManufacturerBatteryOptimizationDisabled = GStrorage.localCache + .get('isManufacturerBatteryOptimizationDisabled', defaultValue: false); + if (!isManufacturerBatteryOptimizationDisabled) { + final isManBatteryOptimizationDisabled = await DisableBatteryOptimization + .isManufacturerBatteryOptimizationDisabled; + if (isManBatteryOptimizationDisabled == false) { + final hasDisabled = await DisableBatteryOptimization + .showDisableManufacturerBatteryOptimizationSettings( + "当前设备可能有额外的电池优化", + "按照步骤操作以禁用电池优化,以保证应用在后台正常运行", + ); + // 设置为已禁用 + GStrorage.localCache.put( + 'isManufacturerBatteryOptimizationDisabled', hasDisabled == true); + } + } +} diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index fea31d569..44a3c3d7f 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -170,6 +170,10 @@ class LocalCacheKey { // 代理host port systemProxyHost = 'systemProxyHost', systemProxyPort = 'systemProxyPort'; + + static const String isDisableBatteryOptLocal = 'isDisableBatteryOptLocal', + isManufacturerBatteryOptimizationDisabled = + 'isManufacturerBatteryOptimizationDisabled'; } class VideoBoxKey { diff --git a/pubspec.lock b/pubspec.lock index bfef5f266..8972ef459 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -393,6 +393,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.4.0" + disable_battery_optimization: + dependency: "direct main" + description: + name: disable_battery_optimization + sha256: "6b2ba802f984af141faf1b6b5fb956d5ef01f9cd555597c35b9cc335a03185ba" + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.1" dismissible_page: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index a5d103f6e..5c25f0442 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -140,6 +140,8 @@ dependencies: catcher_2: ^1.1.0 logger: ^2.0.2+1 path: 1.8.3 + # 电池优化 + disable_battery_optimization: ^1.1.1 dev_dependencies: flutter_test: From 6fdfcb888d968a871aa80cb9dd63530fba2fa6bb Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 10 Mar 2024 19:41:23 +0800 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20=E6=92=AD=E6=94=BE=E5=99=A8?= =?UTF-8?q?=E5=BA=95=E9=83=A8=E6=8E=A7=E5=88=B6=E6=A0=8F=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pl_player/models/bottom_control_type.dart | 10 + lib/plugin/pl_player/view.dart | 300 ++++++++++++------ .../pl_player/widgets/bottom_control.dart | 177 ++++++----- 3 files changed, 296 insertions(+), 191 deletions(-) create mode 100644 lib/plugin/pl_player/models/bottom_control_type.dart diff --git a/lib/plugin/pl_player/models/bottom_control_type.dart b/lib/plugin/pl_player/models/bottom_control_type.dart new file mode 100644 index 000000000..599f6e4fe --- /dev/null +++ b/lib/plugin/pl_player/models/bottom_control_type.dart @@ -0,0 +1,10 @@ +enum BottomControlType { + pre, + playOrPause, + next, + time, + space, + fit, + speed, + fullscreen, +} diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 988ec26db..0b2e652e4 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -8,7 +8,6 @@ import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:media_kit/media_kit.dart'; import 'package:media_kit_video/media_kit_video.dart'; -import 'package:nil/nil.dart'; import 'package:pilipala/models/common/gesture_mode.dart'; import 'package:pilipala/plugin/pl_player/controller.dart'; import 'package:pilipala/plugin/pl_player/models/duration.dart'; @@ -19,12 +18,14 @@ import 'package:pilipala/utils/storage.dart'; import 'package:screen_brightness/screen_brightness.dart'; import '../../utils/global_data.dart'; +import 'models/bottom_control_type.dart'; import 'models/bottom_progress_behavior.dart'; import 'widgets/app_bar_ani.dart'; import 'widgets/backward_seek.dart'; import 'widgets/bottom_control.dart'; import 'widgets/common_btn.dart'; import 'widgets/forward_seek.dart'; +import 'widgets/play_pause_btn.dart'; class PLVideoPlayer extends StatefulWidget { const PLVideoPlayer({ @@ -32,6 +33,7 @@ class PLVideoPlayer extends StatefulWidget { this.headerControl, this.bottomControl, this.danmuWidget, + this.bottomList, super.key, }); @@ -39,6 +41,7 @@ class PLVideoPlayer extends StatefulWidget { final PreferredSizeWidget? headerControl; final PreferredSizeWidget? bottomControl; final Widget? danmuWidget; + final List? bottomList; @override State createState() => _PLVideoPlayerState(); @@ -48,26 +51,22 @@ class _PLVideoPlayerState extends State with TickerProviderStateMixin { late AnimationController animationController; late VideoController videoController; - final PLVideoPlayerController _ctr = Get.put(PLVideoPlayerController()); - // bool _mountSeekBackwardButton = false; - // bool _mountSeekForwardButton = false; - // bool _hideSeekBackwardButton = false; - // bool _hideSeekForwardButton = false; + final RxBool _mountSeekBackwardButton = false.obs; + final RxBool _mountSeekForwardButton = false.obs; + final RxBool _hideSeekBackwardButton = false.obs; + final RxBool _hideSeekForwardButton = false.obs; - // double _brightnessValue = 0.0; - // bool _brightnessIndicator = false; + final RxDouble _brightnessValue = 0.0.obs; + final RxBool _brightnessIndicator = false.obs; Timer? _brightnessTimer; - // double _volumeValue = 0.0; - // bool _volumeIndicator = false; + final RxDouble _volumeValue = 0.0.obs; + final RxBool _volumeIndicator = false.obs; Timer? _volumeTimer; - double _distance = 0.0; - // 初始手指落下位置 - // double _initTapPositoin = 0.0; - - // bool _volumeInterceptEventStream = false; + final RxDouble _distance = 0.0.obs; + final RxBool _volumeInterceptEventStream = false.obs; Box setting = GStrorage.setting; late FullScreenMode mode; @@ -82,11 +81,11 @@ class _PLVideoPlayerState extends State DateTime? lastFullScreenToggleTime; void onDoubleTapSeekBackward() { - _ctr.onDoubleTapSeekBackward(); + _mountSeekBackwardButton.value = true; } void onDoubleTapSeekForward() { - _ctr.onDoubleTapSeekForward(); + _mountSeekForwardButton.value = true; } // 双击播放、暂停 @@ -138,10 +137,10 @@ class _PLVideoPlayerState extends State Future.microtask(() async { try { FlutterVolumeController.updateShowSystemUI(true); - _ctr.volumeValue.value = (await FlutterVolumeController.getVolume())!; + _volumeValue.value = (await FlutterVolumeController.getVolume())!; FlutterVolumeController.addListener((double value) { - if (mounted && !_ctr.volumeInterceptEventStream.value) { - _ctr.volumeValue.value = value; + if (mounted && !_volumeInterceptEventStream.value) { + _volumeValue.value = value; } }); } catch (_) {} @@ -149,10 +148,10 @@ class _PLVideoPlayerState extends State Future.microtask(() async { try { - _ctr.brightnessValue.value = await ScreenBrightness().current; + _brightnessValue.value = await ScreenBrightness().current; ScreenBrightness().onCurrentBrightnessChanged.listen((double value) { if (mounted) { - _ctr.brightnessValue.value = value; + _brightnessValue.value = value; } }); } catch (_) {} @@ -164,14 +163,14 @@ class _PLVideoPlayerState extends State FlutterVolumeController.updateShowSystemUI(false); await FlutterVolumeController.setVolume(value); } catch (_) {} - _ctr.volumeValue.value = value; - _ctr.volumeIndicator.value = true; - _ctr.volumeInterceptEventStream.value = true; + _volumeValue.value = value; + _volumeIndicator.value = true; + _volumeInterceptEventStream.value = true; _volumeTimer?.cancel(); _volumeTimer = Timer(const Duration(milliseconds: 200), () { if (mounted) { - _ctr.volumeIndicator.value = false; - _ctr.volumeInterceptEventStream.value = false; + _volumeIndicator.value = false; + _volumeInterceptEventStream.value = false; } }); } @@ -180,11 +179,11 @@ class _PLVideoPlayerState extends State try { await ScreenBrightness().setScreenBrightness(value); } catch (_) {} - _ctr.brightnessIndicator.value = true; + _brightnessIndicator.value = true; _brightnessTimer?.cancel(); _brightnessTimer = Timer(const Duration(milliseconds: 200), () { if (mounted) { - _ctr.brightnessIndicator.value = false; + _brightnessIndicator.value = false; } }); widget.controller.brightness.value = value; @@ -197,6 +196,134 @@ class _PLVideoPlayerState extends State super.dispose(); } + // 动态构建底部控制条 + List buildBottomControl() { + const TextStyle textStyle = TextStyle( + color: Colors.white, + fontSize: 12, + ); + final PlPlayerController _ = widget.controller; + Map videoProgressWidgets = { + /// 上一集 + BottomControlType.pre: ComBtn( + icon: const Icon( + Icons.skip_previous_outlined, + size: 15, + color: Colors.white, + ), + fuc: () {}, + ), + + /// 播放暂停 + BottomControlType.playOrPause: PlayOrPauseButton( + controller: _, + ), + + /// 下一集 + BottomControlType.next: ComBtn( + icon: const Icon( + Icons.last_page_outlined, + size: 15, + color: Colors.white, + ), + fuc: () {}, + ), + + /// 时间进度 + BottomControlType.time: Row( + children: [ + Obx(() { + return Text( + _.durationSeconds.value >= 3600 + ? printDurationWithHours( + Duration(seconds: _.positionSeconds.value)) + : printDuration(Duration(seconds: _.positionSeconds.value)), + style: textStyle, + ); + }), + const SizedBox(width: 2), + const Text('/', style: textStyle), + const SizedBox(width: 2), + Obx( + () => Text( + _.durationSeconds.value >= 3600 + ? printDurationWithHours( + Duration(seconds: _.durationSeconds.value)) + : printDuration(Duration(seconds: _.durationSeconds.value)), + style: textStyle, + ), + ), + ], + ), + + /// 空白占位 + BottomControlType.space: const Spacer(), + + /// 画面比例 + BottomControlType.fit: SizedBox( + height: 30, + child: TextButton( + onPressed: () => _.toggleVideoFit(), + style: ButtonStyle( + padding: MaterialStateProperty.all(EdgeInsets.zero), + ), + child: Obx( + () => Text( + _.videoFitDEsc.value, + style: const TextStyle(color: Colors.white, fontSize: 13), + ), + ), + ), + ), + + /// 播放速度 + BottomControlType.speed: SizedBox( + width: 45, + height: 34, + child: TextButton( + style: ButtonStyle( + padding: MaterialStateProperty.all(EdgeInsets.zero), + ), + onPressed: () {}, + child: Obx( + () => Text( + '${_.playbackSpeed.toString()}X', + style: textStyle, + ), + ), + ), + ), + + /// 字幕 + /// 全屏 + BottomControlType.fullscreen: ComBtn( + icon: Obx( + () => Icon( + _.isFullScreen.value + ? FontAwesomeIcons.compress + : FontAwesomeIcons.expand, + size: 15, + color: Colors.white, + ), + ), + fuc: () => _.triggerFullScreen(), + ), + }; + final List list = []; + var userSpecifyItem = widget.bottomList ?? + [ + BottomControlType.playOrPause, + BottomControlType.time, + BottomControlType.space, + BottomControlType.fit, + BottomControlType.fullscreen, + ]; + for (var i = 0; i < userSpecifyItem.length; i++) { + list.add(videoProgressWidgets[userSpecifyItem[i]]!); + } + return list; + } + @override Widget build(BuildContext context) { final PlPlayerController _ = widget.controller; @@ -316,7 +443,7 @@ class _PLVideoPlayerState extends State () => Align( child: AnimatedOpacity( curve: Curves.easeInOut, - opacity: _ctr.volumeIndicator.value ? 1.0 : 0.0, + opacity: _volumeIndicator.value ? 1.0 : 0.0, duration: const Duration(milliseconds: 150), child: Container( alignment: Alignment.center, @@ -335,9 +462,9 @@ class _PLVideoPlayerState extends State width: 28.0, alignment: Alignment.centerRight, child: Icon( - _ctr.volumeValue.value == 0.0 + _volumeValue.value == 0.0 ? Icons.volume_off - : _ctr.volumeValue.value < 0.5 + : _volumeValue.value < 0.5 ? Icons.volume_down : Icons.volume_up, color: const Color(0xFFFFFFFF), @@ -346,7 +473,7 @@ class _PLVideoPlayerState extends State ), Expanded( child: Text( - '${(_ctr.volumeValue.value * 100.0).round()}%', + '${(_volumeValue.value * 100.0).round()}%', textAlign: TextAlign.center, style: const TextStyle( fontSize: 13.0, @@ -367,7 +494,7 @@ class _PLVideoPlayerState extends State () => Align( child: AnimatedOpacity( curve: Curves.easeInOut, - opacity: _ctr.brightnessIndicator.value ? 1.0 : 0.0, + opacity: _brightnessIndicator.value ? 1.0 : 0.0, duration: const Duration(milliseconds: 150), child: Container( alignment: Alignment.center, @@ -386,9 +513,9 @@ class _PLVideoPlayerState extends State width: 28.0, alignment: Alignment.centerRight, child: Icon( - _ctr.brightnessValue.value < 1.0 / 3.0 + _brightnessValue.value < 1.0 / 3.0 ? Icons.brightness_low - : _ctr.brightnessValue.value < 2.0 / 3.0 + : _brightnessValue.value < 2.0 / 3.0 ? Icons.brightness_medium : Icons.brightness_high, color: const Color(0xFFFFFFFF), @@ -398,7 +525,7 @@ class _PLVideoPlayerState extends State const SizedBox(width: 2.0), Expanded( child: Text( - '${(_ctr.brightnessValue.value * 100.0).round()}%', + '${(_brightnessValue.value * 100.0).round()}%', textAlign: TextAlign.center, style: const TextStyle( fontSize: 13.0, @@ -489,7 +616,6 @@ class _PLVideoPlayerState extends State pos.clamp(Duration.zero, _.duration.value); _.onUpdatedSliderProgress(result); _.onChangedSliderStart(); - // _initTapPositoin = tapPosition; }, onHorizontalDragEnd: (DragEndDetails details) { if (_.videoType.value == 'live' || _.controlsLock.value) { @@ -521,7 +647,7 @@ class _PLVideoPlayerState extends State : screenWidth * 9 / 16) * 3; final double brightness = - _ctr.brightnessValue.value - delta / level; + _brightnessValue.value - delta / level; final double result = brightness.clamp(0.0, 1.0); setBrightness(result); } else if (tapPosition < sectionWidth * 2) { @@ -530,29 +656,29 @@ class _PLVideoPlayerState extends State const double threshold = 7.0; // 滑动阈值 final bool flag = fullScreenGestureMode != FullScreenGestureMode.values.last; - if (dy > _distance && dy > threshold) { + if (dy > _distance.value && dy > threshold) { if (_.isFullScreen.value ^ flag) { lastFullScreenToggleTime = DateTime.now(); // 下滑退出全屏 await widget.controller.triggerFullScreen(status: flag); } - _distance = 0.0; - } else if (dy < _distance && dy < -threshold) { + _distance.value = 0.0; + } else if (dy < _distance.value && dy < -threshold) { if (!_.isFullScreen.value ^ flag) { lastFullScreenToggleTime = DateTime.now(); // 上滑进入全屏 await widget.controller.triggerFullScreen(status: !flag); } - _distance = 0.0; + _distance.value = 0.0; } - _distance = dy; + _distance.value = dy; } else { // 右边区域 👈 final double level = (_.isFullScreen.value ? Get.size.height : screenWidth * 9 / 16) * 3; - final double volume = _ctr.volumeValue.value - delta / level; + final double volume = _volumeValue.value - delta / level; final double result = volume.clamp(0.0, 1.0); setVolume(result); } @@ -585,9 +711,10 @@ class _PLVideoPlayerState extends State position: 'bottom', child: widget.bottomControl ?? BottomControl( - controller: widget.controller, - triggerFullScreen: - widget.controller.triggerFullScreen), + controller: widget.controller, + triggerFullScreen: _.triggerFullScreen, + buildBottomControl: buildBottomControl(), + ), ), ), ], @@ -607,23 +734,23 @@ class _PLVideoPlayerState extends State } if (defaultBtmProgressBehavior == BtmProgresBehavior.alwaysHide.code) { - return nil; + return const SizedBox(); } if (defaultBtmProgressBehavior == BtmProgresBehavior.onlyShowFullScreen.code && !_.isFullScreen.value) { - return nil; + return const SizedBox(); } else if (defaultBtmProgressBehavior == BtmProgresBehavior.onlyHideFullScreen.code && _.isFullScreen.value) { - return nil; + return const SizedBox(); } if (_.videoType.value == 'live') { return const SizedBox(); } if (value > max || max <= 0) { - return nil; + return const SizedBox(); } return Positioned( bottom: -1.5, @@ -720,18 +847,17 @@ class _PLVideoPlayerState extends State /// 点击 快进/快退 Obx( () => Visibility( - visible: _ctr.mountSeekBackwardButton.value || - _ctr.mountSeekForwardButton.value, + visible: + _mountSeekBackwardButton.value || _mountSeekForwardButton.value, child: Positioned.fill( child: Row( children: [ Expanded( - child: _ctr.mountSeekBackwardButton.value + child: _mountSeekBackwardButton.value ? TweenAnimationBuilder( tween: Tween( begin: 0.0, - end: - _ctr.hideSeekBackwardButton.value ? 0.0 : 1.0, + end: _hideSeekBackwardButton.value ? 0.0 : 1.0, ), duration: const Duration(milliseconds: 500), builder: (BuildContext context, double value, @@ -741,17 +867,15 @@ class _PLVideoPlayerState extends State child: child, ), onEnd: () { - if (_ctr.hideSeekBackwardButton.value) { - _ctr.hideSeekBackwardButton.value = false; - _ctr.mountSeekBackwardButton.value = false; + if (_hideSeekBackwardButton.value) { + _hideSeekBackwardButton.value = false; + _mountSeekBackwardButton.value = false; } }, child: BackwardSeekIndicator( - onChanged: (Duration value) { - // _seekBarDeltaValueNotifier.value = -value; - }, + onChanged: (Duration value) => {}, onSubmitted: (Duration value) { - _ctr.hideSeekBackwardButton.value = true; + _hideSeekBackwardButton.value = true; final Player player = widget.controller.videoPlayerController!; Duration result = player.state.position - value; @@ -764,7 +888,7 @@ class _PLVideoPlayerState extends State }, ), ) - : nil, + : const SizedBox(), ), Expanded( child: SizedBox( @@ -772,11 +896,11 @@ class _PLVideoPlayerState extends State ), ), Expanded( - child: _ctr.mountSeekForwardButton.value + child: _mountSeekForwardButton.value ? TweenAnimationBuilder( tween: Tween( begin: 0.0, - end: _ctr.hideSeekForwardButton.value ? 0.0 : 1.0, + end: _hideSeekForwardButton.value ? 0.0 : 1.0, ), duration: const Duration(milliseconds: 500), builder: (BuildContext context, double value, @@ -786,17 +910,15 @@ class _PLVideoPlayerState extends State child: child, ), onEnd: () { - if (_ctr.hideSeekForwardButton.value) { - _ctr.hideSeekForwardButton.value = false; - _ctr.mountSeekForwardButton.value = false; + if (_hideSeekForwardButton.value) { + _hideSeekForwardButton.value = false; + _mountSeekForwardButton.value = false; } }, child: ForwardSeekIndicator( - onChanged: (Duration value) { - // _seekBarDeltaValueNotifier.value = value; - }, + onChanged: (Duration value) => {}, onSubmitted: (Duration value) { - _ctr.hideSeekForwardButton.value = true; + _hideSeekForwardButton.value = true; final Player player = widget.controller.videoPlayerController!; Duration result = player.state.position + value; @@ -809,7 +931,7 @@ class _PLVideoPlayerState extends State }, ), ) - : nil, + : const SizedBox(), ), ], ), @@ -820,31 +942,3 @@ class _PLVideoPlayerState extends State ); } } - -class PLVideoPlayerController extends GetxController { - RxBool mountSeekBackwardButton = false.obs; - RxBool mountSeekForwardButton = false.obs; - RxBool hideSeekBackwardButton = false.obs; - RxBool hideSeekForwardButton = false.obs; - - RxDouble brightnessValue = 0.0.obs; - RxBool brightnessIndicator = false.obs; - - RxDouble volumeValue = 0.0.obs; - RxBool volumeIndicator = false.obs; - - RxDouble distance = 0.0.obs; - // 初始手指落下位置 - RxDouble initTapPositoin = 0.0.obs; - - RxBool volumeInterceptEventStream = false.obs; - - // 双击快进 展示样式 - void onDoubleTapSeekForward() { - mountSeekForwardButton.value = true; - } - - void onDoubleTapSeekBackward() { - mountSeekBackwardButton.value = true; - } -} diff --git a/lib/plugin/pl_player/widgets/bottom_control.dart b/lib/plugin/pl_player/widgets/bottom_control.dart index 8f21fc175..ebb71b54c 100644 --- a/lib/plugin/pl_player/widgets/bottom_control.dart +++ b/lib/plugin/pl_player/widgets/bottom_control.dart @@ -1,17 +1,20 @@ import 'package:audio_video_progress_bar/audio_video_progress_bar.dart'; import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; import 'package:nil/nil.dart'; import 'package:pilipala/plugin/pl_player/index.dart'; -import 'package:pilipala/plugin/pl_player/widgets/play_pause_btn.dart'; import 'package:pilipala/utils/feed_back.dart'; class BottomControl extends StatelessWidget implements PreferredSizeWidget { final PlPlayerController? controller; final Function? triggerFullScreen; - const BottomControl({this.controller, this.triggerFullScreen, Key? key}) - : super(key: key); + final List? buildBottomControl; + const BottomControl({ + this.controller, + this.triggerFullScreen, + this.buildBottomControl, + Key? key, + }) : super(key: key); @override Size get preferredSize => const Size(double.infinity, kToolbarHeight); @@ -20,11 +23,6 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { Widget build(BuildContext context) { Color colorTheme = Theme.of(context).colorScheme.primary; final _ = controller!; - const textStyle = TextStyle( - color: Colors.white, - fontSize: 12, - ); - return Container( color: Colors.transparent, height: 90, @@ -71,86 +69,89 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { }, ), Row( - children: [ - PlayOrPauseButton( - controller: _, - ), - const SizedBox(width: 4), - // 播放时间 - Obx(() { - return Text( - _.durationSeconds.value >= 3600 - ? printDurationWithHours( - Duration(seconds: _.positionSeconds.value)) - : printDuration( - Duration(seconds: _.positionSeconds.value)), - style: textStyle, - ); - }), - const SizedBox(width: 2), - const Text('/', style: textStyle), - const SizedBox(width: 2), - Obx( - () => Text( - _.durationSeconds.value >= 3600 - ? printDurationWithHours( - Duration(seconds: _.durationSeconds.value)) - : printDuration( - Duration(seconds: _.durationSeconds.value)), - style: textStyle, - ), - ), - const Spacer(), - // 倍速 - // Obx( - // () => SizedBox( - // width: 45, - // height: 34, - // child: TextButton( - // style: ButtonStyle( - // padding: MaterialStateProperty.all(EdgeInsets.zero), - // ), - // onPressed: () { - // _.togglePlaybackSpeed(); - // }, - // child: Text( - // '${_.playbackSpeed.toString()}X', - // style: textStyle, - // ), - // ), - // ), - // ), - SizedBox( - height: 30, - child: TextButton( - onPressed: () => _.toggleVideoFit(), - style: ButtonStyle( - padding: MaterialStateProperty.all(EdgeInsets.zero), - ), - child: Obx( - () => Text( - _.videoFitDEsc.value, - style: const TextStyle(color: Colors.white, fontSize: 13), - ), - ), - ), - ), - const SizedBox(width: 10), - // 全屏 - Obx( - () => ComBtn( - icon: Icon( - _.isFullScreen.value - ? FontAwesomeIcons.compress - : FontAwesomeIcons.expand, - size: 15, - color: Colors.white, - ), - fuc: () => triggerFullScreen!(), - ), - ), - ], + children: [...buildBottomControl!], ), + // Row( + // children: [ + // PlayOrPauseButton( + // controller: _, + // ), + // const SizedBox(width: 4), + // // 播放时间 + // Obx(() { + // return Text( + // _.durationSeconds.value >= 3600 + // ? printDurationWithHours( + // Duration(seconds: _.positionSeconds.value)) + // : printDuration( + // Duration(seconds: _.positionSeconds.value)), + // style: textStyle, + // ); + // }), + // const SizedBox(width: 2), + // const Text('/', style: textStyle), + // const SizedBox(width: 2), + // Obx( + // () => Text( + // _.durationSeconds.value >= 3600 + // ? printDurationWithHours( + // Duration(seconds: _.durationSeconds.value)) + // : printDuration( + // Duration(seconds: _.durationSeconds.value)), + // style: textStyle, + // ), + // ), + // const Spacer(), + // // 倍速 + // // Obx( + // // () => SizedBox( + // // width: 45, + // // height: 34, + // // child: TextButton( + // // style: ButtonStyle( + // // padding: MaterialStateProperty.all(EdgeInsets.zero), + // // ), + // // onPressed: () { + // // _.togglePlaybackSpeed(); + // // }, + // // child: Text( + // // '${_.playbackSpeed.toString()}X', + // // style: textStyle, + // // ), + // // ), + // // ), + // // ), + // SizedBox( + // height: 30, + // child: TextButton( + // onPressed: () => _.toggleVideoFit(), + // style: ButtonStyle( + // padding: MaterialStateProperty.all(EdgeInsets.zero), + // ), + // child: Obx( + // () => Text( + // _.videoFitDEsc.value, + // style: const TextStyle(color: Colors.white, fontSize: 13), + // ), + // ), + // ), + // ), + // const SizedBox(width: 10), + // // 全屏 + // Obx( + // () => ComBtn( + // icon: Icon( + // _.isFullScreen.value + // ? FontAwesomeIcons.compress + // : FontAwesomeIcons.expand, + // size: 15, + // color: Colors.white, + // ), + // fuc: () => triggerFullScreen!(), + // ), + // ), + // ], + // ), const SizedBox(height: 12), ], ), From 98aaca286bd7e5b7eedf88cd95bf613606968d60 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Mon, 11 Mar 2024 00:02:11 +0800 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20=E7=9B=B4=E6=92=AD=E7=94=BB?= =?UTF-8?q?=E8=B4=A8=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/live/quality.dart | 43 +++++++++++++++++++ lib/pages/live_room/controller.dart | 34 ++++++++++++++- .../live_room/widgets/bottom_control.dart | 25 +++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 lib/models/live/quality.dart diff --git a/lib/models/live/quality.dart b/lib/models/live/quality.dart new file mode 100644 index 000000000..479384162 --- /dev/null +++ b/lib/models/live/quality.dart @@ -0,0 +1,43 @@ +enum LiveQuality { + dolby, + super4K, + origin, + veryHigh, + bluRay, + superHD, + smooth, + flunt, +} + +extension LiveQualityCode on LiveQuality { + static final List _codeList = [ + 30000, + 20000, + 10000, + 400, + 250, + 150, + 80, + ]; + int get code => _codeList[index]; + + static LiveQuality? fromCode(int code) { + final index = _codeList.indexOf(code); + if (index != -1) { + return LiveQuality.values[index]; + } + return null; + } +} + +extension VideoQualityDesc on LiveQuality { + static final List _descList = [ + '杜比', + '4K', + '原画', + '蓝光', + '超清', + '流畅', + ]; + get description => _descList[index]; +} diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index 2bb1cd0a7..a1878c74f 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -1,6 +1,7 @@ import 'package:get/get.dart'; import 'package:pilipala/http/constants.dart'; import 'package:pilipala/http/live.dart'; +import 'package:pilipala/models/live/quality.dart'; import 'package:pilipala/models/live/room_info.dart'; import 'package:pilipala/plugin/pl_player/index.dart'; import '../../models/live/room_info_h5.dart'; @@ -19,10 +20,14 @@ class LiveRoomController extends GetxController { PlPlayerController.getInstance(videoType: 'live'); Rx roomInfoH5 = RoomInfoH5Model().obs; late bool enableCDN; + late int currentQn; + late List> acceptQnList; + RxString currentQnDesc = ''.obs; @override void onInit() { super.onInit(); + currentQn = 10000; roomId = int.parse(Get.parameters['roomid']!); if (Get.arguments != null) { liveItem = Get.arguments['liveItem']; @@ -57,11 +62,26 @@ class LiveRoomController extends GetxController { } Future queryLiveInfo() async { - var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000); + /// TODO 默认获取预设质量的直播资源 + var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: currentQn); if (res['status']) { List codec = res['data'].playurlInfo.playurl.stream.first.format.first.codec; CodecItem item = codec.first; + // 以服务端返回的码率为准 + currentQn = item.currentQn!; + List acceptQn = item.acceptQn!; + acceptQnList = acceptQn.map((e) { + return { + 'code': e, + 'desc': LiveQuality.values + .firstWhere((element) => element.code == e) + .description, + }; + }).toList(); + currentQnDesc.value = LiveQuality.values + .firstWhere((element) => element.code == currentQn) + .description; String videoUrl = enableCDN ? VideoUtils.getCdnUrl(item) : (item.urlInfo?.first.host)! + @@ -90,4 +110,16 @@ class LiveRoomController extends GetxController { } return res; } + + // 修改画质 + void changeQn(int qn) async { + if (currentQn == qn) { + return; + } + currentQn = qn; + currentQnDesc.value = LiveQuality.values + .firstWhere((element) => element.code == currentQn) + .description; + await queryLiveInfo(); + } } diff --git a/lib/pages/live_room/widgets/bottom_control.dart b/lib/pages/live_room/widgets/bottom_control.dart index a00f3d92f..0dcedc2c6 100644 --- a/lib/pages/live_room/widgets/bottom_control.dart +++ b/lib/pages/live_room/widgets/bottom_control.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:floating/floating.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:pilipala/models/video/play/url.dart'; import 'package:pilipala/pages/live_room/index.dart'; @@ -113,6 +114,30 @@ class _BottomControlState extends State { ), const SizedBox(width: 4), ], + SizedBox( + width: 30, + child: PopupMenuButton( + padding: EdgeInsets.zero, + onSelected: (value) { + widget.liveRoomCtr!.changeQn(value); + }, + child: Obx( + () => Text( + widget.liveRoomCtr!.currentQnDesc.value, + style: const TextStyle(color: Colors.white, fontSize: 13), + ), + ), + itemBuilder: (BuildContext context) { + return widget.liveRoomCtr!.acceptQnList.map((e) { + return PopupMenuItem( + value: e['code'], + child: Text(e['desc']), + ); + }).toList(); + }, + ), + ), + const SizedBox(width: 10), ComBtn( icon: const Icon( Icons.fullscreen, From 882957e2f842a0d54b1b134e21b9cb08869a80ff Mon Sep 17 00:00:00 2001 From: guohaonan <972101775@qq.com> Date: Tue, 12 Mar 2024 14:34:32 +0800 Subject: [PATCH 04/12] =?UTF-8?q?feature:=E5=8A=A8=E6=80=81=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E6=8C=89=E9=92=AE=E5=9C=A8=E6=9C=AA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81=E4=B8=8B=E7=9A=84=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=B8=BA=E7=9B=B4=E6=8E=A5=E8=B7=B3=E8=BD=AC=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/dynamics/view.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 4a92cdfb8..5fa06c91e 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -14,6 +14,7 @@ import 'package:pilipala/pages/main/index.dart'; import 'package:pilipala/utils/feed_back.dart'; import 'package:pilipala/utils/storage.dart'; +import '../mine/controller.dart'; import 'controller.dart'; import 'widgets/dynamic_panel.dart'; import 'widgets/up_panel.dart'; @@ -28,6 +29,7 @@ class DynamicsPage extends StatefulWidget { class _DynamicsPageState extends State with AutomaticKeepAliveClientMixin { final DynamicsController _dynamicsController = Get.put(DynamicsController()); + final MineController mineController = Get.put(MineController()); late Future _futureBuilderFuture; late Future _futureBuilderFutureUp; Box userInfoCache = GStrorage.userInfo; @@ -256,6 +258,16 @@ class _DynamicsPageState extends State } }, ); + } else if (data['msg'] == "账号未登录") { + return HttpError( + errMsg: data['msg'], + btnText: "去登录", + fn: () { + setState(() { + mineController.onLogin(); + }); + }, + ); } else { return HttpError( errMsg: data['msg'], From bc9ea43cd2c8bc5203968911da744dca10e7ad8d Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 12 Mar 2024 23:45:22 +0800 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20=E8=A7=86=E9=A2=91=E7=95=AA?= =?UTF-8?q?=E5=89=A7=E8=AF=A6=E6=83=85=E9=A1=B5=E4=BB=A3=E7=A0=81=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bangumi/introduction/controller.dart | 57 +- lib/pages/bangumi/introduction/view.dart | 494 ++++++---------- .../video/detail/introduction/controller.dart | 27 - lib/pages/video/detail/introduction/view.dart | 529 +++++++----------- .../introduction/widgets/action_item.dart | 28 +- 5 files changed, 405 insertions(+), 730 deletions(-) diff --git a/lib/pages/bangumi/introduction/controller.dart b/lib/pages/bangumi/introduction/controller.dart index 6b3123ea2..12f0c0536 100644 --- a/lib/pages/bangumi/introduction/controller.dart +++ b/lib/pages/bangumi/introduction/controller.dart @@ -25,13 +25,6 @@ class BangumiIntroController extends GetxController { ? int.tryParse(Get.parameters['epId']!) : null; - // 是否预渲染 骨架屏 - bool preRender = false; - - // 视频详情 上个页面传入 - Map? videoItem = {}; - BangumiInfoModel? bangumiItem; - // 请求状态 RxBool isLoading = false.obs; @@ -63,27 +56,6 @@ class BangumiIntroController extends GetxController { @override void onInit() { super.onInit(); - if (Get.arguments.isNotEmpty as bool) { - if (Get.arguments.containsKey('bangumiItem') as bool) { - preRender = true; - bangumiItem = Get.arguments['bangumiItem']; - // bangumiItem!['pic'] = args.pic; - // if (args.title is String) { - // videoItem!['title'] = args.title; - // } else { - // String str = ''; - // for (Map map in args.title) { - // str += map['text']; - // } - // videoItem!['title'] = str; - // } - // if (args.stat != null) { - // videoItem!['stat'] = args.stat; - // } - // videoItem!['pubdate'] = args.pubdate; - // videoItem!['owner'] = args.owner; - } - } userInfo = userInfoCache.get('userInfoCache'); userLogin = userInfo != null; } @@ -183,20 +155,21 @@ class BangumiIntroController extends GetxController { actions: [ TextButton(onPressed: () => Get.back(), child: const Text('取消')), TextButton( - onPressed: () async { - var res = await VideoHttp.coinVideo( - bvid: bvid, multiply: _tempThemeValue); - if (res['status']) { - SmartDialog.showToast('投币成功 👏'); - hasCoin.value = true; - bangumiDetail.value.stat!['coins'] = - bangumiDetail.value.stat!['coins'] + _tempThemeValue; - } else { - SmartDialog.showToast(res['msg']); - } - Get.back(); - }, - child: const Text('确定')) + onPressed: () async { + var res = await VideoHttp.coinVideo( + bvid: bvid, multiply: _tempThemeValue); + if (res['status']) { + SmartDialog.showToast('投币成功 👏'); + hasCoin.value = true; + bangumiDetail.value.stat!['coins'] = + bangumiDetail.value.stat!['coins'] + _tempThemeValue; + } else { + SmartDialog.showToast(res['msg']); + } + Get.back(); + }, + child: const Text('确定'), + ) ], ); }); diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index f9efc66c5..551d91d74 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -12,11 +12,10 @@ import 'package:pilipala/models/bangumi/info.dart'; import 'package:pilipala/pages/bangumi/widgets/bangumi_panel.dart'; import 'package:pilipala/pages/video/detail/index.dart'; import 'package:pilipala/pages/video/detail/introduction/widgets/action_item.dart'; -import 'package:pilipala/pages/video/detail/introduction/widgets/action_row_item.dart'; import 'package:pilipala/pages/video/detail/introduction/widgets/fav_panel.dart'; import 'package:pilipala/utils/feed_back.dart'; import 'package:pilipala/utils/storage.dart'; - +import '../../../common/widgets/http_error.dart'; import 'controller.dart'; import 'widgets/intro_detail.dart'; @@ -51,9 +50,6 @@ class _BangumiIntroPanelState extends State cid = widget.cid!; bangumiIntroController = Get.put(BangumiIntroController(), tag: heroTag); videoDetailCtr = Get.find(tag: heroTag); - bangumiIntroController.bangumiDetail.listen((BangumiInfoModel value) { - bangumiDetail = value; - }); _futureBuilderFuture = bangumiIntroController.queryBangumiIntro(); videoDetailCtr.cid.listen((int p0) { cid = p0; @@ -68,27 +64,32 @@ class _BangumiIntroPanelState extends State future: _futureBuilderFuture, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.data == null) { + return const SliverToBoxAdapter(child: SizedBox()); + } if (snapshot.data['status']) { // 请求成功 - - return BangumiInfo( - loadingStatus: false, - bangumiDetail: bangumiDetail, - cid: cid, + return Obx( + () => BangumiInfo( + bangumiDetail: bangumiIntroController.bangumiDetail.value, + cid: cid, + ), ); } else { // 请求错误 - // return HttpError( - // errMsg: snapshot.data['msg'], - // fn: () => Get.back(), - // ); - return const SizedBox(); + return HttpError( + errMsg: snapshot.data['msg'], + fn: () => Get.back(), + ); } } else { - return BangumiInfo( - loadingStatus: true, - bangumiDetail: bangumiDetail, - cid: cid, + return const SliverToBoxAdapter( + child: SizedBox( + height: 100, + child: Center( + child: CircularProgressIndicator(), + ), + ), ); } }, @@ -99,12 +100,10 @@ class _BangumiIntroPanelState extends State class BangumiInfo extends StatefulWidget { const BangumiInfo({ super.key, - this.loadingStatus = false, this.bangumiDetail, this.cid, }); - final bool loadingStatus; final BangumiInfoModel? bangumiDetail; final int? cid; @@ -117,7 +116,6 @@ class _BangumiInfoState extends State { late final BangumiIntroController bangumiIntroController; late final VideoDetailController videoDetailCtr; Box localCache = GStrorage.localCache; - late final BangumiInfoModel? bangumiItem; late double sheetHeight; int? cid; bool isProcessing = false; @@ -136,13 +134,10 @@ class _BangumiInfoState extends State { super.initState(); bangumiIntroController = Get.put(BangumiIntroController(), tag: heroTag); videoDetailCtr = Get.find(tag: heroTag); - bangumiItem = bangumiIntroController.bangumiItem; sheetHeight = localCache.get('sheetHeight'); cid = widget.cid!; - print('cid: $cid'); videoDetailCtr.cid.listen((p0) { cid = p0; - print('cid: $cid'); setState(() {}); }); } @@ -182,207 +177,154 @@ class _BangumiInfoState extends State { padding: const EdgeInsets.only( left: StyleString.safeSpace, right: StyleString.safeSpace, top: 20), sliver: SliverToBoxAdapter( - child: !widget.loadingStatus || bangumiItem != null - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Stack( children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Stack( - children: [ - NetworkImgLayer( - width: 105, - height: 160, - src: !widget.loadingStatus - ? widget.bangumiDetail!.cover! - : bangumiItem!.cover!, - ), - if (bangumiItem != null && - bangumiItem!.rating != null) - PBadge( - text: - '评分 ${!widget.loadingStatus ? widget.bangumiDetail!.rating!['score']! : bangumiItem!.rating!['score']!}', - top: null, - right: 6, - bottom: 6, - left: null, - ), - ], - ), - const SizedBox(width: 10), - Expanded( - child: InkWell( - onTap: () => showIntroDetail(), - child: SizedBox( - height: 158, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Row( - children: [ - Expanded( - child: Text( - !widget.loadingStatus - ? widget.bangumiDetail!.title! - : bangumiItem!.title!, - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - const SizedBox(width: 20), - SizedBox( - width: 34, - height: 34, - child: IconButton( - style: ButtonStyle( - padding: MaterialStateProperty.all( - EdgeInsets.zero), - backgroundColor: - MaterialStateProperty.resolveWith( - (Set states) { - return t - .colorScheme.primaryContainer - .withOpacity(0.7); - }), - ), - onPressed: () => - bangumiIntroController.bangumiAdd(), - icon: Icon( - Icons.favorite_border_rounded, - color: t.colorScheme.primary, - size: 22, - ), - ), - ), - ], - ), - Row( - children: [ - StatView( - theme: 'gray', - view: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['views'] - : bangumiItem!.stat!['views'], - size: 'medium', - ), - const SizedBox(width: 6), - StatDanMu( - theme: 'gray', - danmu: !widget.loadingStatus - ? widget - .bangumiDetail!.stat!['danmakus'] - : bangumiItem!.stat!['danmakus'], - size: 'medium', - ), - ], - ), - const SizedBox(height: 6), - Row( - children: [ - Text( - !widget.loadingStatus - ? (widget.bangumiDetail!.areas! - .isNotEmpty - ? widget.bangumiDetail!.areas! - .first['name'] - : '') - : (bangumiItem!.areas!.isNotEmpty - ? bangumiItem! - .areas!.first['name'] - : ''), - style: TextStyle( - fontSize: 12, - color: t.colorScheme.outline, - ), - ), - const SizedBox(width: 6), - Text( - !widget.loadingStatus - ? widget.bangumiDetail! - .publish!['pub_time_show'] - : bangumiItem! - .publish!['pub_time_show'], - style: TextStyle( - fontSize: 12, - color: t.colorScheme.outline, - ), - ), - ], + NetworkImgLayer( + width: 105, + height: 160, + src: widget.bangumiDetail!.cover!, + ), + PBadge( + text: '评分 ${widget.bangumiDetail!.rating!['score']!}', + top: null, + right: 6, + bottom: 6, + left: null, + ), + ], + ), + const SizedBox(width: 10), + Expanded( + child: InkWell( + onTap: () => showIntroDetail(), + child: SizedBox( + height: 158, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + Expanded( + child: Text( + widget.bangumiDetail!.title!, + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, ), - // const SizedBox(height: 4), - Text( - !widget.loadingStatus - ? widget.bangumiDetail!.newEp!['desc'] - : bangumiItem!.newEp!['desc'], - style: TextStyle( - fontSize: 12, - color: t.colorScheme.outline, - ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox(width: 20), + SizedBox( + width: 34, + height: 34, + child: IconButton( + style: ButtonStyle( + padding: MaterialStateProperty.all( + EdgeInsets.zero), + backgroundColor: + MaterialStateProperty.resolveWith( + (Set states) { + return t.colorScheme.primaryContainer + .withOpacity(0.7); + }), ), - // const SizedBox(height: 10), - const Spacer(), - Text( - '简介:${!widget.loadingStatus ? widget.bangumiDetail!.evaluate! : bangumiItem!.evaluate!}', - maxLines: 3, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 13, - color: t.colorScheme.outline, - ), + onPressed: () => + bangumiIntroController.bangumiAdd(), + icon: Icon( + Icons.favorite_border_rounded, + color: t.colorScheme.primary, + size: 22, ), - ], + ), + ), + ], + ), + Row( + children: [ + StatView( + theme: 'gray', + view: widget.bangumiDetail!.stat!['views'], + size: 'medium', + ), + const SizedBox(width: 6), + StatDanMu( + theme: 'gray', + danmu: widget.bangumiDetail!.stat!['danmakus'], + size: 'medium', ), + ], + ), + const SizedBox(height: 6), + Row( + children: [ + Text( + (widget.bangumiDetail!.areas!.isNotEmpty + ? widget.bangumiDetail!.areas!.first['name'] + : ''), + style: TextStyle( + fontSize: 12, + color: t.colorScheme.outline, + ), + ), + const SizedBox(width: 6), + Text( + widget.bangumiDetail!.publish!['pub_time_show'], + style: TextStyle( + fontSize: 12, + color: t.colorScheme.outline, + ), + ), + ], + ), + Text( + widget.bangumiDetail!.newEp!['desc'], + style: TextStyle( + fontSize: 12, + color: t.colorScheme.outline, + ), + ), + const Spacer(), + Text( + '简介:${widget.bangumiDetail!.evaluate!}', + maxLines: 3, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 13, + color: t.colorScheme.outline, ), ), - ), - ], + ], + ), ), - const SizedBox(height: 6), - // 点赞收藏转发 布局样式1 - // SingleChildScrollView( - // padding: const EdgeInsets.only(top: 7, bottom: 7), - // scrollDirection: Axis.horizontal, - // child: actionRow( - // context, - // bangumiIntroController, - // videoDetailCtr, - // ), - // ), - // 点赞收藏转发 布局样式2 - actionGrid(context, bangumiIntroController), - // 番剧分p - if ((!widget.loadingStatus && - widget.bangumiDetail!.episodes!.isNotEmpty) || - bangumiItem != null && - bangumiItem!.episodes!.isNotEmpty) ...[ - BangumiPanel( - pages: bangumiItem != null - ? bangumiItem!.episodes! - : widget.bangumiDetail!.episodes!, - cid: cid ?? - (bangumiItem != null - ? bangumiItem!.episodes!.first.cid - : widget.bangumiDetail!.episodes!.first.cid), - sheetHeight: sheetHeight, - changeFuc: (bvid, cid, aid) => bangumiIntroController - .changeSeasonOrbangu(bvid, cid, aid), - ) - ], - ], - ) - : const SizedBox( - height: 100, - child: Center( - child: CircularProgressIndicator(), ), ), - ), + ], + ), + const SizedBox(height: 6), + + /// 点赞收藏转发 + actionGrid(context, bangumiIntroController), + // 番剧分p + if (widget.bangumiDetail!.episodes!.isNotEmpty) ...[ + BangumiPanel( + pages: widget.bangumiDetail!.episodes!, + cid: cid ?? widget.bangumiDetail!.episodes!.first.cid, + sheetHeight: sheetHeight, + changeFuc: (bvid, cid, aid) => + bangumiIntroController.changeSeasonOrbangu(bvid, cid, aid), + ) + ], + ], + )), ); } @@ -402,57 +344,44 @@ class _BangumiInfoState extends State { children: [ Obx( () => ActionItem( - icon: const Icon(FontAwesomeIcons.thumbsUp), - selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), - onTap: - handleState(bangumiIntroController.actionLikeVideo), - selectStatus: bangumiIntroController.hasLike.value, - loadingStatus: false, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['likes']!.toString() - : bangumiItem!.stat!['likes']!.toString()), + icon: const Icon(FontAwesomeIcons.thumbsUp), + selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), + onTap: handleState(bangumiIntroController.actionLikeVideo), + selectStatus: bangumiIntroController.hasLike.value, + text: widget.bangumiDetail!.stat!['likes']!.toString(), + ), ), Obx( () => ActionItem( - icon: const Icon(FontAwesomeIcons.b), - selectIcon: const Icon(FontAwesomeIcons.b), - onTap: - handleState(bangumiIntroController.actionCoinVideo), - selectStatus: bangumiIntroController.hasCoin.value, - loadingStatus: false, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['coins']!.toString() - : bangumiItem!.stat!['coins']!.toString()), + icon: const Icon(FontAwesomeIcons.b), + selectIcon: const Icon(FontAwesomeIcons.b), + onTap: handleState(bangumiIntroController.actionCoinVideo), + selectStatus: bangumiIntroController.hasCoin.value, + text: widget.bangumiDetail!.stat!['coins']!.toString(), + ), ), Obx( () => ActionItem( - icon: const Icon(FontAwesomeIcons.star), - selectIcon: const Icon(FontAwesomeIcons.solidStar), - onTap: () => showFavBottomSheet(), - selectStatus: bangumiIntroController.hasFav.value, - loadingStatus: false, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['favorite']!.toString() - : bangumiItem!.stat!['favorite']!.toString()), + icon: const Icon(FontAwesomeIcons.star), + selectIcon: const Icon(FontAwesomeIcons.solidStar), + onTap: () => showFavBottomSheet(), + selectStatus: bangumiIntroController.hasFav.value, + text: widget.bangumiDetail!.stat!['favorite']!.toString(), + ), ), ActionItem( icon: const Icon(FontAwesomeIcons.comment), selectIcon: const Icon(FontAwesomeIcons.reply), onTap: () => videoDetailCtr.tabCtr.animateTo(1), selectStatus: false, - loadingStatus: false, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['reply']!.toString() - : bangumiItem!.stat!['reply']!.toString(), + text: widget.bangumiDetail!.stat!['reply']!.toString(), ), ActionItem( - icon: const Icon(FontAwesomeIcons.shareFromSquare), - onTap: () => bangumiIntroController.actionShareVideo(), - selectStatus: false, - loadingStatus: false, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['share']!.toString() - : bangumiItem!.stat!['share']!.toString()), + icon: const Icon(FontAwesomeIcons.shareFromSquare), + onTap: () => bangumiIntroController.actionShareVideo(), + selectStatus: false, + text: widget.bangumiDetail!.stat!['share']!.toString(), + ), ], ), ), @@ -460,63 +389,4 @@ class _BangumiInfoState extends State { ); }); } - - Widget actionRow(BuildContext context, videoIntroController, videoDetailCtr) { - return Row(children: [ - Obx( - () => ActionRowItem( - icon: const Icon(FontAwesomeIcons.thumbsUp), - onTap: handleState(videoIntroController.actionLikeVideo), - selectStatus: videoIntroController.hasLike.value, - loadingStatus: widget.loadingStatus, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['likes']!.toString() - : '-', - ), - ), - const SizedBox(width: 8), - Obx( - () => ActionRowItem( - icon: const Icon(FontAwesomeIcons.b), - onTap: handleState(videoIntroController.actionCoinVideo), - selectStatus: videoIntroController.hasCoin.value, - loadingStatus: widget.loadingStatus, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['coins']!.toString() - : '-', - ), - ), - const SizedBox(width: 8), - Obx( - () => ActionRowItem( - icon: const Icon(FontAwesomeIcons.heart), - onTap: () => showFavBottomSheet(), - selectStatus: videoIntroController.hasFav.value, - loadingStatus: widget.loadingStatus, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['favorite']!.toString() - : '-', - ), - ), - const SizedBox(width: 8), - ActionRowItem( - icon: const Icon(FontAwesomeIcons.comment), - onTap: () { - videoDetailCtr.tabCtr.animateTo(1); - }, - selectStatus: false, - loadingStatus: widget.loadingStatus, - text: !widget.loadingStatus - ? widget.bangumiDetail!.stat!['reply']!.toString() - : '-', - ), - const SizedBox(width: 8), - ActionRowItem( - icon: const Icon(FontAwesomeIcons.share), - onTap: () => videoIntroController.actionShareVideo(), - selectStatus: false, - loadingStatus: widget.loadingStatus, - text: '转发'), - ]); - } } diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index c7f22b131..6714b8876 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -25,13 +25,6 @@ class VideoIntroController extends GetxController { VideoIntroController({required this.bvid}); // 视频bvid String bvid; - - // 是否预渲染 骨架屏 - bool preRender = false; - - // 视频详情 上个页面传入 - Map? videoItem = {}; - // 请求状态 RxBool isLoading = false.obs; @@ -74,26 +67,6 @@ class VideoIntroController extends GetxController { try { heroTag = Get.arguments['heroTag']; } catch (_) {} - if (Get.arguments.isNotEmpty) { - if (Get.arguments.containsKey('videoItem')) { - preRender = true; - var args = Get.arguments['videoItem']; - var keys = Get.arguments.keys.toList(); - videoItem!['pic'] = args.pic; - if (args.title is String) { - videoItem!['title'] = args.title; - } else { - String str = ''; - for (Map map in args.title) { - str += map['text']; - } - videoItem!['title'] = str; - } - videoItem!['stat'] = keys.contains('stat') && args.stat; - videoItem!['pubdate'] = keys.contains('pubdate') && args.pubdate; - videoItem!['owner'] = keys.contains('owner') && args.owner; - } - } userLogin = userInfo != null; lastPlayCid.value = int.parse(Get.parameters['cid']!); isShowOnlineTotal = diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index bed37bb55..5e24220b1 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -15,9 +15,7 @@ import 'package:pilipala/pages/video/detail/widgets/ai_detail.dart'; import 'package:pilipala/utils/feed_back.dart'; import 'package:pilipala/utils/storage.dart'; import 'package:pilipala/utils/utils.dart'; - import 'widgets/action_item.dart'; -import 'widgets/action_row_item.dart'; import 'widgets/fav_panel.dart'; import 'widgets/intro_detail.dart'; import 'widgets/page.dart'; @@ -78,7 +76,6 @@ class _VideoIntroPanelState extends State // 请求成功 return Obx( () => VideoInfo( - loadingStatus: false, videoDetail: videoIntroController.videoDetail.value, heroTag: heroTag, bvid: widget.bvid, @@ -96,11 +93,13 @@ class _VideoIntroPanelState extends State ); } } else { - return VideoInfo( - loadingStatus: true, - videoDetail: videoDetail, - heroTag: heroTag, - bvid: widget.bvid, + return const SliverToBoxAdapter( + child: SizedBox( + height: 100, + child: Center( + child: CircularProgressIndicator(), + ), + ), ); } }, @@ -109,14 +108,12 @@ class _VideoIntroPanelState extends State } class VideoInfo extends StatefulWidget { - final bool loadingStatus; final VideoDetailData? videoDetail; final String? heroTag; final String bvid; const VideoInfo({ Key? key, - this.loadingStatus = false, this.videoDetail, this.heroTag, required this.bvid, @@ -127,18 +124,12 @@ class VideoInfo extends StatefulWidget { } class _VideoInfoState extends State with TickerProviderStateMixin { - // final String heroTag = Get.arguments['heroTag']; late String heroTag; late final VideoIntroController videoIntroController; late final VideoDetailController videoDetailCtr; - late final Map videoItem; - final Box localCache = GStrorage.localCache; final Box setting = GStrorage.setting; late double sheetHeight; - - late final bool loadingStatus; // 加载状态 - late final dynamic owner; late final dynamic follower; late final dynamic followStatus; @@ -163,14 +154,10 @@ class _VideoInfoState extends State with TickerProviderStateMixin { videoIntroController = Get.put(VideoIntroController(bvid: widget.bvid), tag: heroTag); videoDetailCtr = Get.find(tag: heroTag); - videoItem = videoIntroController.videoItem!; sheetHeight = localCache.get('sheetHeight'); - loadingStatus = widget.loadingStatus; - owner = loadingStatus ? videoItem['owner'] : widget.videoDetail!.owner; - follower = loadingStatus - ? '-' - : Utils.numFormat(videoIntroController.userStat['follower']); + owner = widget.videoDetail!.owner; + follower = Utils.numFormat(videoIntroController.userStat['follower']); followStatus = videoIntroController.followStatus; enableAi = setting.get(SettingBoxKey.enableAi, defaultValue: true); } @@ -224,9 +211,6 @@ class _VideoInfoState extends State with TickerProviderStateMixin { // 视频介绍 showIntroDetail() { - if (loadingStatus) { - return; - } feedBack(); showBottomSheet( context: context, @@ -240,13 +224,9 @@ class _VideoInfoState extends State with TickerProviderStateMixin { // 用户主页 onPushMember() { feedBack(); - mid = !loadingStatus - ? widget.videoDetail!.owner!.mid - : videoItem['owner'].mid; + mid = widget.videoDetail!.owner!.mid!; memberHeroTag = Utils.makeHeroTag(mid); - String face = !loadingStatus - ? widget.videoDetail!.owner!.face - : videoItem['owner'].face; + String face = widget.videoDetail!.owner!.face!; Get.toNamed('/member?mid=$mid', arguments: {'face': face, 'heroTag': memberHeroTag}); } @@ -270,221 +250,181 @@ class _VideoInfoState extends State with TickerProviderStateMixin { padding: const EdgeInsets.only( left: StyleString.safeSpace, right: StyleString.safeSpace, top: 10), sliver: SliverToBoxAdapter( - child: !loadingStatus - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: () => showIntroDetail(), - child: Text( - !loadingStatus - ? widget.videoDetail!.title - : videoItem['title'], - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), - ), - Stack( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: () => showIntroDetail(), + child: Text( + widget.videoDetail!.title!, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + maxLines: 2, + overflow: TextOverflow.ellipsis, + ), + ), + Stack( + children: [ + GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: () => showIntroDetail(), + child: Padding( + padding: const EdgeInsets.only(top: 7, bottom: 6), + child: Row( children: [ - GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: () => showIntroDetail(), - child: Padding( - padding: const EdgeInsets.only(top: 7, bottom: 6), - child: Row( - children: [ - StatView( - theme: 'gray', - view: !loadingStatus - ? widget.videoDetail!.stat!.view - : videoItem['stat'].view, - size: 'medium', - ), - const SizedBox(width: 10), - StatDanMu( - theme: 'gray', - danmu: !loadingStatus - ? widget.videoDetail!.stat!.danmaku - : videoItem['stat'].danmaku, - size: 'medium', - ), - const SizedBox(width: 10), - Text( - Utils.dateFormat( - !loadingStatus - ? widget.videoDetail!.pubdate - : videoItem['pubdate'], - formatType: 'detail'), - style: TextStyle( - fontSize: 12, - color: t.colorScheme.outline, - ), - ), - const SizedBox(width: 10), - if (videoIntroController.isShowOnlineTotal) - Obx( - () => Text( - '${videoIntroController.total.value}人在看', - style: TextStyle( - fontSize: 12, - color: t.colorScheme.outline, - ), - ), - ), - ], - ), - ), + StatView( + theme: 'gray', + view: widget.videoDetail!.stat!.view, + size: 'medium', ), - if (enableAi) - Positioned( - right: 10, - top: 6, - child: GestureDetector( - onTap: () async { - final res = - await videoIntroController.aiConclusion(); - if (res['status']) { - showAiBottomSheet(); - } - }, - child: - Image.asset('assets/images/ai.png', height: 22), - ), - ) - ], - ), - // 点赞收藏转发 布局样式1 - // SingleChildScrollView( - // padding: const EdgeInsets.only(top: 7, bottom: 7), - // scrollDirection: Axis.horizontal, - // child: actionRow( - // context, - // videoIntroController, - // videoDetailCtr, - // ), - // ), - // 点赞收藏转发 布局样式2 - actionGrid(context, videoIntroController), - // 合集 - if (!loadingStatus && - widget.videoDetail!.ugcSeason != null) ...[ - Obx( - () => SeasonPanel( - ugcSeason: widget.videoDetail!.ugcSeason!, - cid: videoIntroController.lastPlayCid.value != 0 - ? videoIntroController.lastPlayCid.value - : widget.videoDetail!.pages!.first.cid, - sheetHeight: sheetHeight, - changeFuc: (bvid, cid, aid) => videoIntroController - .changeSeasonOrbangu(bvid, cid, aid), + const SizedBox(width: 10), + StatDanMu( + theme: 'gray', + danmu: widget.videoDetail!.stat!.danmaku, + size: 'medium', ), - ) - ], - if (!loadingStatus && - widget.videoDetail!.pages != null && - widget.videoDetail!.pages!.length > 1) ...[ - Obx(() => PagesPanel( - pages: widget.videoDetail!.pages!, - cid: videoIntroController.lastPlayCid.value, - sheetHeight: sheetHeight, - changeFuc: (cid) => - videoIntroController.changeSeasonOrbangu( - videoIntroController.bvid, cid, null), - )) - ], - GestureDetector( - onTap: onPushMember, - child: Container( - padding: const EdgeInsets.symmetric( - vertical: 12, horizontal: 4), - child: Row( - children: [ - NetworkImgLayer( - type: 'avatar', - src: loadingStatus - ? owner.face - : widget.videoDetail!.owner!.face, - width: 34, - height: 34, - fadeInDuration: Duration.zero, - fadeOutDuration: Duration.zero, - ), - const SizedBox(width: 10), - Text(owner.name, - style: const TextStyle(fontSize: 13)), - const SizedBox(width: 6), - Text( - follower, + const SizedBox(width: 10), + Text( + Utils.dateFormat(widget.videoDetail!.pubdate, + formatType: 'detail'), + style: TextStyle( + fontSize: 12, + color: t.colorScheme.outline, + ), + ), + const SizedBox(width: 10), + if (videoIntroController.isShowOnlineTotal) + Obx( + () => Text( + '${videoIntroController.total.value}人在看', style: TextStyle( - fontSize: t.textTheme.labelSmall!.fontSize, - color: outline, + fontSize: 12, + color: t.colorScheme.outline, ), ), - const Spacer(), - Obx(() => AnimatedOpacity( - opacity: loadingStatus || - videoIntroController - .followStatus.isEmpty - ? 0 - : 1, - duration: const Duration(milliseconds: 50), - child: SizedBox( - height: 32, - child: Obx( - () => videoIntroController - .followStatus.isNotEmpty - ? TextButton( - onPressed: videoIntroController - .actionRelationMod, - style: TextButton.styleFrom( - padding: const EdgeInsets.only( - left: 8, right: 8), - foregroundColor: - followStatus['attribute'] != 0 - ? outline - : t.colorScheme.onPrimary, - backgroundColor: - followStatus['attribute'] != 0 - ? t.colorScheme - .onInverseSurface - : t.colorScheme - .primary, // 设置按钮背景色 - ), - child: Text( - followStatus['attribute'] != 0 - ? '已关注' - : '关注', - style: TextStyle( - fontSize: t.textTheme - .labelMedium!.fontSize), - ), - ) - : ElevatedButton( - onPressed: videoIntroController - .actionRelationMod, - child: const Text('关注'), - ), - ), - ), - )), - ], - ), + ), + ], + ), + ), + ), + if (enableAi) + Positioned( + right: 10, + top: 6, + child: GestureDetector( + onTap: () async { + final res = await videoIntroController.aiConclusion(); + if (res['status']) { + showAiBottomSheet(); + } + }, + child: Image.asset('assets/images/ai.png', height: 22), + ), + ) + ], + ), + + /// 点赞收藏转发 + actionGrid(context, videoIntroController), + // 合集 + if (widget.videoDetail!.ugcSeason != null) ...[ + Obx( + () => SeasonPanel( + ugcSeason: widget.videoDetail!.ugcSeason!, + cid: videoIntroController.lastPlayCid.value != 0 + ? videoIntroController.lastPlayCid.value + : widget.videoDetail!.pages!.first.cid, + sheetHeight: sheetHeight, + changeFuc: (bvid, cid, aid) => + videoIntroController.changeSeasonOrbangu(bvid, cid, aid), + ), + ) + ], + if (widget.videoDetail!.pages != null && + widget.videoDetail!.pages!.length > 1) ...[ + Obx(() => PagesPanel( + pages: widget.videoDetail!.pages!, + cid: videoIntroController.lastPlayCid.value, + sheetHeight: sheetHeight, + changeFuc: (cid) => videoIntroController.changeSeasonOrbangu( + videoIntroController.bvid, cid, null), + )) + ], + GestureDetector( + onTap: onPushMember, + child: Container( + padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 4), + child: Row( + children: [ + NetworkImgLayer( + type: 'avatar', + src: widget.videoDetail!.owner!.face, + width: 34, + height: 34, + fadeInDuration: Duration.zero, + fadeOutDuration: Duration.zero, + ), + const SizedBox(width: 10), + Text(owner.name, style: const TextStyle(fontSize: 13)), + const SizedBox(width: 6), + Text( + follower, + style: TextStyle( + fontSize: t.textTheme.labelSmall!.fontSize, + color: outline, ), ), + const Spacer(), + Obx(() => AnimatedOpacity( + opacity: + videoIntroController.followStatus.isEmpty ? 0 : 1, + duration: const Duration(milliseconds: 50), + child: SizedBox( + height: 32, + child: Obx( + () => videoIntroController.followStatus.isNotEmpty + ? TextButton( + onPressed: + videoIntroController.actionRelationMod, + style: TextButton.styleFrom( + padding: const EdgeInsets.only( + left: 8, right: 8), + foregroundColor: + followStatus['attribute'] != 0 + ? outline + : t.colorScheme.onPrimary, + backgroundColor: + followStatus['attribute'] != 0 + ? t.colorScheme.onInverseSurface + : t.colorScheme + .primary, // 设置按钮背景色 + ), + child: Text( + followStatus['attribute'] != 0 + ? '已关注' + : '关注', + style: TextStyle( + fontSize: t + .textTheme.labelMedium!.fontSize), + ), + ) + : ElevatedButton( + onPressed: + videoIntroController.actionRelationMod, + child: const Text('关注'), + ), + ), + ), + )), ], - ) - : const SizedBox( - height: 100, - child: Center( - child: CircularProgressIndicator(), - ), ), - ), + ), + ), + ], + )), ); } @@ -506,10 +446,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), onTap: handleState(videoIntroController.actionLikeVideo), selectStatus: videoIntroController.hasLike.value, - loadingStatus: loadingStatus, - text: !loadingStatus - ? widget.videoDetail!.stat!.like!.toString() - : '-'), + text: widget.videoDetail!.stat!.like!.toString()), ), // ActionItem( // icon: const Icon(FontAwesomeIcons.clock), @@ -519,104 +456,38 @@ class _VideoInfoState extends State with TickerProviderStateMixin { // text: '稍后再看'), Obx( () => ActionItem( - icon: const Icon(FontAwesomeIcons.b), - selectIcon: const Icon(FontAwesomeIcons.b), - onTap: handleState(videoIntroController.actionCoinVideo), - selectStatus: videoIntroController.hasCoin.value, - loadingStatus: loadingStatus, - text: !loadingStatus - ? widget.videoDetail!.stat!.coin!.toString() - : '-'), + icon: const Icon(FontAwesomeIcons.b), + selectIcon: const Icon(FontAwesomeIcons.b), + onTap: handleState(videoIntroController.actionCoinVideo), + selectStatus: videoIntroController.hasCoin.value, + text: widget.videoDetail!.stat!.coin!.toString(), + ), ), Obx( () => ActionItem( - icon: const Icon(FontAwesomeIcons.star), - selectIcon: const Icon(FontAwesomeIcons.solidStar), - onTap: () => showFavBottomSheet(), - onLongPress: () => showFavBottomSheet(type: 'longPress'), - selectStatus: videoIntroController.hasFav.value, - loadingStatus: loadingStatus, - text: !loadingStatus - ? widget.videoDetail!.stat!.favorite!.toString() - : '-'), + icon: const Icon(FontAwesomeIcons.star), + selectIcon: const Icon(FontAwesomeIcons.solidStar), + onTap: () => showFavBottomSheet(), + onLongPress: () => showFavBottomSheet(type: 'longPress'), + selectStatus: videoIntroController.hasFav.value, + text: widget.videoDetail!.stat!.favorite!.toString(), + ), ), ActionItem( - icon: const Icon(FontAwesomeIcons.comment), - onTap: () => videoDetailCtr.tabCtr.animateTo(1), - selectStatus: false, - loadingStatus: loadingStatus, - text: !loadingStatus - ? widget.videoDetail!.stat!.reply!.toString() - : '评论'), + icon: const Icon(FontAwesomeIcons.comment), + onTap: () => videoDetailCtr.tabCtr.animateTo(1), + selectStatus: false, + text: widget.videoDetail!.stat!.reply!.toString(), + ), ActionItem( - icon: const Icon(FontAwesomeIcons.shareFromSquare), - onTap: () => videoIntroController.actionShareVideo(), - selectStatus: false, - loadingStatus: loadingStatus, - text: '分享'), + icon: const Icon(FontAwesomeIcons.shareFromSquare), + onTap: () => videoIntroController.actionShareVideo(), + selectStatus: false, + text: '分享', + ), ], ), ); }); } - - Widget actionRow(BuildContext context, videoIntroController, videoDetailCtr) { - return Row(children: [ - Obx( - () => ActionRowItem( - icon: const Icon(FontAwesomeIcons.thumbsUp), - onTap: handleState(videoIntroController.actionLikeVideo), - selectStatus: videoIntroController.hasLike.value, - loadingStatus: loadingStatus, - text: - !loadingStatus ? widget.videoDetail!.stat!.like!.toString() : '-', - ), - ), - const SizedBox(width: 8), - Obx( - () => ActionRowItem( - icon: const Icon(FontAwesomeIcons.b), - onTap: handleState(videoIntroController.actionCoinVideo), - selectStatus: videoIntroController.hasCoin.value, - loadingStatus: loadingStatus, - text: - !loadingStatus ? widget.videoDetail!.stat!.coin!.toString() : '-', - ), - ), - const SizedBox(width: 8), - Obx( - () => ActionRowItem( - icon: const Icon(FontAwesomeIcons.heart), - onTap: () => showFavBottomSheet(), - onLongPress: () => showFavBottomSheet(type: 'longPress'), - selectStatus: videoIntroController.hasFav.value, - loadingStatus: loadingStatus, - text: !loadingStatus - ? widget.videoDetail!.stat!.favorite!.toString() - : '-', - ), - ), - const SizedBox(width: 8), - ActionRowItem( - icon: const Icon(FontAwesomeIcons.comment), - onTap: () { - videoDetailCtr.tabCtr.animateTo(1); - }, - selectStatus: false, - loadingStatus: loadingStatus, - text: - !loadingStatus ? widget.videoDetail!.stat!.reply!.toString() : '-', - ), - const SizedBox(width: 8), - ActionRowItem( - icon: const Icon(FontAwesomeIcons.share), - onTap: () => videoIntroController.actionShareVideo(), - selectStatus: false, - loadingStatus: loadingStatus, - // text: !loadingStatus - // ? widget.videoDetail!.stat!.share!.toString() - // : '-', - text: '转发'), - ]); - } } diff --git a/lib/pages/video/detail/introduction/widgets/action_item.dart b/lib/pages/video/detail/introduction/widgets/action_item.dart index 95ac103b8..022d9223e 100644 --- a/lib/pages/video/detail/introduction/widgets/action_item.dart +++ b/lib/pages/video/detail/introduction/widgets/action_item.dart @@ -7,7 +7,6 @@ class ActionItem extends StatelessWidget { final Icon? selectIcon; final Function? onTap; final Function? onLongPress; - final bool? loadingStatus; final String? text; final bool selectStatus; @@ -17,7 +16,6 @@ class ActionItem extends StatelessWidget { this.selectIcon, this.onTap, this.onLongPress, - this.loadingStatus, this.text, this.selectStatus = false, }) : super(key: key); @@ -43,25 +41,15 @@ class ActionItem extends StatelessWidget { : Icon(icon!.icon!, size: 18, color: Theme.of(context).colorScheme.outline), const SizedBox(height: 6), - AnimatedOpacity( - opacity: loadingStatus! ? 0 : 1, - duration: const Duration(milliseconds: 200), - child: AnimatedSwitcher( - duration: const Duration(milliseconds: 300), - transitionBuilder: (Widget child, Animation animation) { - return ScaleTransition(scale: animation, child: child); - }, - child: Text( - text ?? '', - key: ValueKey(text ?? ''), - style: TextStyle( - color: selectStatus - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.outline, - fontSize: Theme.of(context).textTheme.labelSmall!.fontSize), - ), + Text( + text ?? '', + style: TextStyle( + color: selectStatus + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.outline, + fontSize: Theme.of(context).textTheme.labelSmall!.fontSize, ), - ), + ) ], ), ); From da2bbeedffdfd08143a4353a1cf6abd0719d41c0 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 13 Mar 2024 23:12:34 +0800 Subject: [PATCH 06/12] =?UTF-8?q?mod:=20=E9=BB=98=E8=AE=A4=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E7=94=BB=E8=B4=A8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/live/quality.dart | 2 +- lib/pages/live_room/controller.dart | 4 +- .../live_room/widgets/bottom_control.dart | 50 +++++++++---------- lib/pages/setting/play_setting.dart | 36 +++++++++++-- lib/utils/storage.dart | 1 + 5 files changed, 62 insertions(+), 31 deletions(-) diff --git a/lib/models/live/quality.dart b/lib/models/live/quality.dart index 479384162..677d615b4 100644 --- a/lib/models/live/quality.dart +++ b/lib/models/live/quality.dart @@ -2,7 +2,6 @@ enum LiveQuality { dolby, super4K, origin, - veryHigh, bluRay, superHD, smooth, @@ -37,6 +36,7 @@ extension VideoQualityDesc on LiveQuality { '原画', '蓝光', '超清', + '高清', '流畅', ]; get description => _descList[index]; diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index a1878c74f..f785da635 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -27,7 +27,8 @@ class LiveRoomController extends GetxController { @override void onInit() { super.onInit(); - currentQn = 10000; + currentQn = setting.get(SettingBoxKey.defaultLiveQa, + defaultValue: LiveQuality.values.last.code); roomId = int.parse(Get.parameters['roomid']!); if (Get.arguments != null) { liveItem = Get.arguments['liveItem']; @@ -62,7 +63,6 @@ class LiveRoomController extends GetxController { } Future queryLiveInfo() async { - /// TODO 默认获取预设质量的直播资源 var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: currentQn); if (res['status']) { List codec = diff --git a/lib/pages/live_room/widgets/bottom_control.dart b/lib/pages/live_room/widgets/bottom_control.dart index 0dcedc2c6..c98a80ae0 100644 --- a/lib/pages/live_room/widgets/bottom_control.dart +++ b/lib/pages/live_room/widgets/bottom_control.dart @@ -85,6 +85,30 @@ class _BottomControlState extends State { // ), // ), // const SizedBox(width: 4), + SizedBox( + width: 30, + child: PopupMenuButton( + padding: EdgeInsets.zero, + onSelected: (value) { + widget.liveRoomCtr!.changeQn(value); + }, + child: Obx( + () => Text( + widget.liveRoomCtr!.currentQnDesc.value, + style: const TextStyle(color: Colors.white, fontSize: 13), + ), + ), + itemBuilder: (BuildContext context) { + return widget.liveRoomCtr!.acceptQnList.map((e) { + return PopupMenuItem( + value: e['code'], + child: Text(e['desc']), + ); + }).toList(); + }, + ), + ), + const SizedBox(width: 10), if (Platform.isAndroid) ...[ SizedBox( width: 34, @@ -112,32 +136,8 @@ class _BottomControlState extends State { ), ), ), - const SizedBox(width: 4), + const SizedBox(width: 10), ], - SizedBox( - width: 30, - child: PopupMenuButton( - padding: EdgeInsets.zero, - onSelected: (value) { - widget.liveRoomCtr!.changeQn(value); - }, - child: Obx( - () => Text( - widget.liveRoomCtr!.currentQnDesc.value, - style: const TextStyle(color: Colors.white, fontSize: 13), - ), - ), - itemBuilder: (BuildContext context) { - return widget.liveRoomCtr!.acceptQnList.map((e) { - return PopupMenuItem( - value: e['code'], - child: Text(e['desc']), - ); - }).toList(); - }, - ), - ), - const SizedBox(width: 10), ComBtn( icon: const Icon( Icons.fullscreen, diff --git a/lib/pages/setting/play_setting.dart b/lib/pages/setting/play_setting.dart index bfd5db5fc..03e912121 100644 --- a/lib/pages/setting/play_setting.dart +++ b/lib/pages/setting/play_setting.dart @@ -9,6 +9,7 @@ import 'package:pilipala/plugin/pl_player/index.dart'; import 'package:pilipala/services/service_locator.dart'; import 'package:pilipala/utils/storage.dart'; +import '../../models/live/quality.dart'; import 'widgets/switch_item.dart'; class PlaySetting extends StatefulWidget { @@ -21,6 +22,7 @@ class PlaySetting extends StatefulWidget { class _PlaySettingState extends State { Box setting = GStrorage.setting; late dynamic defaultVideoQa; + late dynamic defaultLiveQa; late dynamic defaultAudioQa; late dynamic defaultDecode; late int defaultFullScreenMode; @@ -31,6 +33,8 @@ class _PlaySettingState extends State { super.initState(); defaultVideoQa = setting.get(SettingBoxKey.defaultVideoQa, defaultValue: VideoQuality.values.last.code); + defaultLiveQa = setting.get(SettingBoxKey.defaultLiveQa, + defaultValue: LiveQuality.values.last.code); defaultAudioQa = setting.get(SettingBoxKey.defaultAudioQa, defaultValue: AudioQuality.values.last.code); defaultDecode = setting.get(SettingBoxKey.defaultDecode, @@ -148,9 +152,9 @@ class _PlaySettingState extends State { ), ListTile( dense: false, - title: Text('默认画质', style: titleStyle), + title: Text('默认视频画质', style: titleStyle), subtitle: Text( - '当前画质${VideoQualityCode.fromCode(defaultVideoQa)!.description!}', + '当前默认画质${VideoQualityCode.fromCode(defaultVideoQa)!.description!}', style: subTitleStyle, ), onTap: () async { @@ -158,7 +162,7 @@ class _PlaySettingState extends State { context: context, builder: (context) { return SelectDialog( - title: '默认画质', + title: '默认视频画质', value: defaultVideoQa, values: VideoQuality.values.reversed.map((e) { return {'title': e.description, 'value': e.code}; @@ -172,6 +176,32 @@ class _PlaySettingState extends State { } }, ), + ListTile( + dense: false, + title: Text('默认直播画质', style: titleStyle), + subtitle: Text( + '当前默认画质${LiveQualityCode.fromCode(defaultLiveQa)!.description!}', + style: subTitleStyle, + ), + onTap: () async { + int? result = await showDialog( + context: context, + builder: (context) { + return SelectDialog( + title: '默认直播画质', + value: defaultLiveQa, + values: LiveQuality.values.reversed.map((e) { + return {'title': e.description, 'value': e.code}; + }).toList()); + }, + ); + if (result != null) { + defaultLiveQa = result; + setting.put(SettingBoxKey.defaultLiveQa, result); + setState(() {}); + } + }, + ), ListTile( dense: false, title: Text('默认音质', style: titleStyle), diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 16cef4639..47fd75968 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -77,6 +77,7 @@ class SettingBoxKey { autoUpgradeEnable = 'autoUpgradeEnable', feedBackEnable = 'feedBackEnable', defaultVideoQa = 'defaultVideoQa', + defaultLiveQa = 'defaultLiveQa', defaultAudioQa = 'defaultAudioQa', autoPlayEnable = 'autoPlayEnable', fullScreenMode = 'fullScreenMode', From 357133fa975d0c059e897117db849536d5444be4 Mon Sep 17 00:00:00 2001 From: guohaonan <972101775@qq.com> Date: Thu, 14 Mar 2024 10:00:32 +0800 Subject: [PATCH 07/12] =?UTF-8?q?fix:=E5=8E=BB=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84setState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/dynamics/view.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 5fa06c91e..fe594a43f 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -263,9 +263,7 @@ class _DynamicsPageState extends State errMsg: data['msg'], btnText: "去登录", fn: () { - setState(() { - mineController.onLogin(); - }); + mineController.onLogin(); }, ); } else { From b13d7b475b47203e9172065103db02816744406e Mon Sep 17 00:00:00 2001 From: guozhigq Date: Thu, 14 Mar 2024 23:49:36 +0800 Subject: [PATCH 08/12] =?UTF-8?q?feat:=20=E9=9D=9E=E5=85=A8=E5=B1=8F?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=B8=8B=E9=9A=90=E8=97=8F=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugin/pl_player/view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 988ec26db..203f6c978 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -672,7 +672,7 @@ class _PLVideoPlayerState extends State // 锁 Obx( () => Visibility( - visible: _.videoType.value != 'live', + visible: _.videoType.value != 'live' && _.isFullScreen.value, child: Align( alignment: Alignment.centerLeft, child: FractionalTranslation( From 491bc87251047a6d1284660337101798f7323cd0 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 15 Mar 2024 23:26:43 +0800 Subject: [PATCH 09/12] =?UTF-8?q?fix:=20=E7=A7=81=E4=BF=A1=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=B8=B2=E6=9F=93=E5=BC=82=E5=B8=B8=20issues=20#295?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/msg.dart | 4 ++-- lib/pages/whisper/view.dart | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/http/msg.dart b/lib/http/msg.dart index 4ba2f8184..d1d319588 100644 --- a/lib/http/msg.dart +++ b/lib/http/msg.dart @@ -31,14 +31,14 @@ class MsgHttp { } catch (err) { return { 'status': false, - 'date': [], + 'data': [], 'msg': err.toString(), }; } } else { return { 'status': false, - 'date': [], + 'data': [], 'msg': res.data['message'], }; } diff --git a/lib/pages/whisper/view.dart b/lib/pages/whisper/view.dart index f1c586505..fa7ad60b2 100644 --- a/lib/pages/whisper/view.dart +++ b/lib/pages/whisper/view.dart @@ -180,7 +180,8 @@ class _WhisperPageState extends State { sessionList[i] .lastMsg .content[ - 'reply_content']) + 'reply_content'] ?? + '不支持的消息类型') : '不支持的消息类型', maxLines: 1, overflow: TextOverflow.ellipsis, From 13c77957fe3de669896b8dc130c0ffaaab6cbdd6 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 16 Mar 2024 22:48:47 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix:=20=E7=95=AA=E5=89=A7badge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/bangumi/introduction/view.dart | 22 +++++----- lib/pages/bangumi/widgets/bangumi_panel.dart | 42 +++++++++----------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index f9efc66c5..3b2cf1223 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -362,17 +362,17 @@ class _BangumiInfoState extends State { bangumiItem != null && bangumiItem!.episodes!.isNotEmpty) ...[ BangumiPanel( - pages: bangumiItem != null - ? bangumiItem!.episodes! - : widget.bangumiDetail!.episodes!, - cid: cid ?? - (bangumiItem != null - ? bangumiItem!.episodes!.first.cid - : widget.bangumiDetail!.episodes!.first.cid), - sheetHeight: sheetHeight, - changeFuc: (bvid, cid, aid) => bangumiIntroController - .changeSeasonOrbangu(bvid, cid, aid), - ) + pages: bangumiItem != null + ? bangumiItem!.episodes! + : widget.bangumiDetail!.episodes!, + cid: cid ?? + (bangumiItem != null + ? bangumiItem!.episodes!.first.cid + : widget.bangumiDetail!.episodes!.first.cid), + sheetHeight: sheetHeight, + changeFuc: (bvid, cid, aid) => bangumiIntroController + .changeSeasonOrbangu(bvid, cid, aid), + bangumiDetail: widget.bangumiDetail ?? bangumiItem) ], ], ) diff --git a/lib/pages/bangumi/widgets/bangumi_panel.dart b/lib/pages/bangumi/widgets/bangumi_panel.dart index 05889f16a..791cc1080 100644 --- a/lib/pages/bangumi/widgets/bangumi_panel.dart +++ b/lib/pages/bangumi/widgets/bangumi_panel.dart @@ -14,12 +14,14 @@ class BangumiPanel extends StatefulWidget { this.cid, this.sheetHeight, this.changeFuc, + this.bangumiDetail, }); final List pages; final int? cid; final double? sheetHeight; final Function? changeFuc; + final BangumiInfoModel? bangumiDetail; @override State createState() => _BangumiPanelState(); @@ -87,7 +89,7 @@ class _BangumiPanelState extends State { ) : null, title: Text( - '第${index + 1}话 ${page.longTitle!}', + '第${page.title}话 ${page.longTitle!}', style: TextStyle( fontSize: 14, color: isCurrentIndex @@ -96,9 +98,11 @@ class _BangumiPanelState extends State { ), ), trailing: page.badge != null - ? Image.asset( - 'assets/images/big-vip.png', - height: 20, + ? Text( + page.badge!, + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), ) : const SizedBox(), ); @@ -201,11 +205,11 @@ class _BangumiPanelState extends State { return Column( children: [ Padding( - padding: const EdgeInsets.only(top: 10, bottom: 6), + padding: const EdgeInsets.only(top: 10, bottom: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const Text('合集 '), + const Text('选集 '), Expanded( child: Text( ' 正在播放:${widget.pages[currentIndex].longTitle}', @@ -225,7 +229,7 @@ class _BangumiPanelState extends State { ), onPressed: () => showBangumiPanel(), child: Text( - '全${widget.pages.length}话', + '${widget.bangumiDetail!.newEp!['desc']}', style: const TextStyle(fontSize: 13), ), ), @@ -278,23 +282,15 @@ class _BangumiPanelState extends State { ), const SizedBox(width: 2), if (widget.pages[i].badge != null) ...[ - if (widget.pages[i].badge == '会员') ...[ - Image.asset( - 'assets/images/big-vip.png', - height: 16, + const Spacer(), + Text( + widget.pages[i].badge!, + style: TextStyle( + fontSize: 12, + color: + Theme.of(context).colorScheme.primary, ), - ], - if (widget.pages[i].badge != '会员') ...[ - const Spacer(), - Text( - widget.pages[i].badge!, - style: TextStyle( - fontSize: 11, - color: - Theme.of(context).colorScheme.primary, - ), - ), - ], + ), ] ], ), From 33d28f51d1819f9f28451bf315a0ad8ee16188ad Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 17 Mar 2024 00:36:00 +0800 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=E6=9C=AA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=88=87=E6=8D=A2=E7=9B=B4=E6=92=AD=E7=94=BB?= =?UTF-8?q?=E8=B4=A8=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/live_room/controller.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index f785da635..5c2a9800d 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -1,3 +1,4 @@ +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/constants.dart'; import 'package:pilipala/http/live.dart'; @@ -21,6 +22,7 @@ class LiveRoomController extends GetxController { Rx roomInfoH5 = RoomInfoH5Model().obs; late bool enableCDN; late int currentQn; + int? tempCurrentQn; late List> acceptQnList; RxString currentQnDesc = ''.obs; @@ -70,6 +72,9 @@ class LiveRoomController extends GetxController { CodecItem item = codec.first; // 以服务端返回的码率为准 currentQn = item.currentQn!; + if (tempCurrentQn != null && tempCurrentQn == currentQn) { + SmartDialog.showToast('画质切换失败,请检查登录状态'); + } List acceptQn = item.acceptQn!; acceptQnList = acceptQn.map((e) { return { @@ -113,6 +118,7 @@ class LiveRoomController extends GetxController { // 修改画质 void changeQn(int qn) async { + tempCurrentQn = currentQn; if (currentQn == qn) { return; } From e04a7e5702961340cdcbde71f9b187b42bdeae0f Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 17 Mar 2024 14:29:39 +0800 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=91=BD=E5=90=8D=E3=80=81=E8=B4=A8=E9=87=8F=E3=80=81?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/download.dart | 76 +++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/lib/utils/download.dart b/lib/utils/download.dart index ad008f6d8..a9c56ec0e 100644 --- a/lib/utils/download.dart +++ b/lib/utils/download.dart @@ -1,40 +1,94 @@ import 'dart:typed_data'; import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:saver_gallery/saver_gallery.dart'; class DownloadUtils { // 获取存储权限 - static requestStoragePer() async { - Map statuses = await [ - Permission.storage, - Permission.photos, - ].request(); - statuses[Permission.storage].toString(); + static Future requestStoragePer() async { + await Permission.storage.request(); + PermissionStatus status = await Permission.storage.status; + if (status == PermissionStatus.denied || + status == PermissionStatus.permanentlyDenied) { + SmartDialog.show( + useSystem: true, + animationType: SmartAnimationType.centerFade_otherSlide, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('提示'), + content: const Text('存储权限未授权'), + actions: [ + TextButton( + onPressed: () async { + openAppSettings(); + }, + child: const Text('去授权'), + ) + ], + ); + }, + ); + return false; + } else { + return true; + } + } + + // 获取相册权限 + static Future requestPhotoPer() async { + await Permission.photos.request(); + PermissionStatus status = await Permission.photos.status; + if (status == PermissionStatus.denied || + status == PermissionStatus.permanentlyDenied) { + SmartDialog.show( + useSystem: true, + animationType: SmartAnimationType.centerFade_otherSlide, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('提示'), + content: const Text('相册权限未授权'), + actions: [ + TextButton( + onPressed: () async { + openAppSettings(); + }, + child: const Text('去授权'), + ) + ], + ); + }, + ); + return false; + } else { + return true; + } } static Future downloadImg(String imgUrl, {String imgType = 'cover'}) async { try { - await requestStoragePer(); + if (!await requestPhotoPer()) { + return false; + } SmartDialog.showLoading(msg: '保存中'); var response = await Dio() .get(imgUrl, options: Options(responseType: ResponseType.bytes)); + final String imgSuffix = imgUrl.split('.').last; String picName = - "plpl_${imgType}_${DateTime.now().toString().split('-').join()}"; + "plpl_${imgType}_${DateTime.now().toString().replaceAll(RegExp(r'[- :]'), '').split('.').first}"; final SaveResult result = await SaverGallery.saveImage( Uint8List.fromList(response.data), - quality: 60, - name: picName, + name: '$picName.$imgSuffix', // 保存到 PiliPala文件夹 androidRelativePath: "Pictures/PiliPala", androidExistNotSave: false, ); SmartDialog.dismiss(); if (result.isSuccess) { - await SmartDialog.showToast('「$picName」已保存 '); + await SmartDialog.showToast('「${'$picName.$imgSuffix'}」已保存 '); } return true; } catch (err) {