mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: pip aspectRatio
related #543 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -519,14 +519,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
// }
|
||||
|
||||
void enterPip() {
|
||||
if (Get.currentRoute.startsWith('/video')) {
|
||||
videoDetailController.floating?.enable(
|
||||
EnableManual(
|
||||
aspectRatio: Rational(
|
||||
videoDetailController.data.dash!.video!.first.width!,
|
||||
videoDetailController.data.dash!.video!.first.height!,
|
||||
),
|
||||
),
|
||||
if (Get.currentRoute.startsWith('/video') &&
|
||||
videoDetailController.floating != null) {
|
||||
Utils.enterPip(
|
||||
videoDetailController.floating!,
|
||||
videoDetailController.data.dash!.video!.first.width!,
|
||||
videoDetailController.data.dash!.video!.first.height!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,14 +558,12 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
// }
|
||||
|
||||
void enterPip() {
|
||||
if (Get.currentRoute.startsWith('/video')) {
|
||||
videoDetailController.floating?.enable(
|
||||
EnableManual(
|
||||
aspectRatio: Rational(
|
||||
videoDetailController.data.dash!.video!.first.width!,
|
||||
videoDetailController.data.dash!.video!.first.height!,
|
||||
),
|
||||
),
|
||||
if (Get.currentRoute.startsWith('/video') &&
|
||||
videoDetailController.floating != null) {
|
||||
Utils.enterPip(
|
||||
videoDetailController.floating!,
|
||||
videoDetailController.data.dash!.video!.first.width!,
|
||||
videoDetailController.data.dash!.video!.first.height!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2451,17 +2451,15 @@ class HeaderControlState extends State<HeaderControl> {
|
||||
await Future.delayed(
|
||||
const Duration(seconds: 3), () {});
|
||||
}
|
||||
final Rational aspectRatio = Rational(
|
||||
if (!context.mounted) return;
|
||||
Utils.enterPip(
|
||||
widget.floating!,
|
||||
widget
|
||||
.videoDetailCtr.data.dash!.video!.first.width!,
|
||||
widget
|
||||
.videoDetailCtr.data.dash!.video!.first.height!,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
await widget.floating!.enable(EnableManual(
|
||||
aspectRatio: aspectRatio,
|
||||
));
|
||||
} else {}
|
||||
}
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.picture_in_picture_outlined,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/hero_dialog_route.dart';
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -122,3 +123,16 @@ extension BrightnessExt on Brightness {
|
||||
Brightness get reverse =>
|
||||
this == Brightness.light ? Brightness.dark : Brightness.light;
|
||||
}
|
||||
|
||||
extension RationalExt on Rational {
|
||||
/// Checks whether given [Rational] instance fits into Android requirements
|
||||
/// or not.
|
||||
///
|
||||
/// Android docs specified boundaries as inclusive.
|
||||
bool get fitsInAndroidRequirements {
|
||||
final aspectRatio = numerator / denominator;
|
||||
final min = 1 / 2.39;
|
||||
final max = 2.39;
|
||||
return (min <= aspectRatio) && (aspectRatio <= max);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import 'package:crypto/crypto.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flex_seed_scheme/flex_seed_scheme.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -58,6 +59,19 @@ class Utils {
|
||||
|
||||
static final _numRegExp = RegExp(r'([\d\.]+)([千万亿])?');
|
||||
|
||||
static void enterPip(Floating floating, int width, int height) {
|
||||
Rational aspectRatio = Rational(width, height);
|
||||
floating.enable(
|
||||
EnableManual(
|
||||
aspectRatio: aspectRatio.fitsInAndroidRequirements
|
||||
? aspectRatio
|
||||
: height > width
|
||||
? const Rational.vertical()
|
||||
: const Rational.landscape(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static ThemeData getThemeData({
|
||||
required ColorScheme colorScheme,
|
||||
required bool isDynamic,
|
||||
|
||||
Reference in New Issue
Block a user