mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-27 19:48:37 +00:00
opt android orientation
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -49,7 +49,7 @@ import 'package:easy_debounce/easy_throttle.dart';
|
|||||||
import 'package:floating/floating.dart';
|
import 'package:floating/floating.dart';
|
||||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart' show HapticFeedback;
|
import 'package:flutter/services.dart' show HapticFeedback, DeviceOrientation;
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:flutter_volume_controller/flutter_volume_controller.dart';
|
import 'package:flutter_volume_controller/flutter_volume_controller.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@@ -516,32 +516,41 @@ class PlPlayerController with BlockConfigMixin {
|
|||||||
|
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
|
||||||
StreamSubscription<NativeDeviceOrientation>? _orientationListener;
|
DeviceOrientation? _orientation;
|
||||||
|
late final checkIsAutoRotate = Platform.isAndroid && mode != .gravity;
|
||||||
|
StreamSubscription<OrientationParams>? _orientationListener;
|
||||||
|
|
||||||
void _stopOrientationListener() {
|
void _stopOrientationListener() {
|
||||||
_orientationListener?.cancel();
|
_orientationListener?.cancel();
|
||||||
_orientationListener = null;
|
_orientationListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onOrientationChanged(NativeDeviceOrientation value) {
|
void _onOrientationChanged(OrientationParams param) {
|
||||||
if (!visible) return;
|
if (!visible) return;
|
||||||
switch (value) {
|
final orientation = _orientation = param.orientation;
|
||||||
|
final isFullScreen = this.isFullScreen.value;
|
||||||
|
if (checkIsAutoRotate &&
|
||||||
|
param.isAutoRotate != true &&
|
||||||
|
(!isFullScreen || _isVertical || orientation == .portraitUp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (orientation) {
|
||||||
case .portraitUp:
|
case .portraitUp:
|
||||||
if (!_isVertical && controlsLock.value) return;
|
if (!_isVertical && controlsLock.value) return;
|
||||||
if (!horizontalScreen && !_isVertical && isFullScreen.value) {
|
if (!horizontalScreen && !_isVertical && isFullScreen) {
|
||||||
triggerFullScreen(status: false, orientation: value);
|
triggerFullScreen(status: false, orientation: orientation);
|
||||||
} else {
|
} else {
|
||||||
portraitUpMode();
|
portraitUpMode();
|
||||||
}
|
}
|
||||||
case .landscapeLeft:
|
case .landscapeLeft:
|
||||||
if (!horizontalScreen && !isFullScreen.value) {
|
if (!horizontalScreen && !isFullScreen) {
|
||||||
triggerFullScreen(orientation: value);
|
triggerFullScreen(orientation: orientation);
|
||||||
} else {
|
} else {
|
||||||
landscapeLeftMode();
|
landscapeLeftMode();
|
||||||
}
|
}
|
||||||
case .landscapeRight:
|
case .landscapeRight:
|
||||||
if (!horizontalScreen && !isFullScreen.value) {
|
if (!horizontalScreen && !isFullScreen) {
|
||||||
triggerFullScreen(orientation: value);
|
triggerFullScreen(orientation: orientation);
|
||||||
} else {
|
} else {
|
||||||
landscapeRightMode();
|
landscapeRightMode();
|
||||||
}
|
}
|
||||||
@@ -551,11 +560,11 @@ class PlPlayerController with BlockConfigMixin {
|
|||||||
|
|
||||||
// 添加一个私有构造函数
|
// 添加一个私有构造函数
|
||||||
PlPlayerController._() {
|
PlPlayerController._() {
|
||||||
if (PlatformUtils.isMobile) {
|
if (PlatformUtils.isMobile && !horizontalScreen) {
|
||||||
_orientationListener = NativeDeviceOrientationPlatform.instance
|
_orientationListener = NativeDeviceOrientationPlatform.instance
|
||||||
.onOrientationChanged(
|
.onOrientationChanged(
|
||||||
useSensor: Platform.isAndroid,
|
useSensor: Platform.isAndroid,
|
||||||
checkIsAutoRotate: mode != .gravity,
|
checkIsAutoRotate: checkIsAutoRotate,
|
||||||
)
|
)
|
||||||
.listen(_onOrientationChanged);
|
.listen(_onOrientationChanged);
|
||||||
}
|
}
|
||||||
@@ -1412,7 +1421,7 @@ class PlPlayerController with BlockConfigMixin {
|
|||||||
Future<void> triggerFullScreen({
|
Future<void> triggerFullScreen({
|
||||||
bool status = true,
|
bool status = true,
|
||||||
bool inAppFullScreen = false,
|
bool inAppFullScreen = false,
|
||||||
NativeDeviceOrientation? orientation,
|
DeviceOrientation? orientation,
|
||||||
}) async {
|
}) async {
|
||||||
if (isDesktopPip) return;
|
if (isDesktopPip) return;
|
||||||
if (isFullScreen.value == status) return;
|
if (isFullScreen.value == status) return;
|
||||||
@@ -1424,6 +1433,7 @@ class PlPlayerController with BlockConfigMixin {
|
|||||||
if (status) {
|
if (status) {
|
||||||
if (PlatformUtils.isMobile) {
|
if (PlatformUtils.isMobile) {
|
||||||
hideStatusBar();
|
hideStatusBar();
|
||||||
|
if (horizontalScreen) return;
|
||||||
if (orientation == null && mode == .none) {
|
if (orientation == null && mode == .none) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1437,7 +1447,7 @@ class PlPlayerController with BlockConfigMixin {
|
|||||||
// https://github.com/flutter/flutter/issues/73651
|
// https://github.com/flutter/flutter/issues/73651
|
||||||
// https://github.com/flutter/flutter/issues/183708
|
// https://github.com/flutter/flutter/issues/183708
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
if (orientation == .landscapeRight) {
|
if ((orientation ?? _orientation) == .landscapeRight) {
|
||||||
await landscapeRightMode();
|
await landscapeRightMode();
|
||||||
} else {
|
} else {
|
||||||
await landscapeLeftMode();
|
await landscapeLeftMode();
|
||||||
@@ -1569,9 +1579,7 @@ class PlPlayerController with BlockConfigMixin {
|
|||||||
bool get isCloseAll => _isCloseAll;
|
bool get isCloseAll => _isCloseAll;
|
||||||
|
|
||||||
void resetScreenRotation() {
|
void resetScreenRotation() {
|
||||||
if (horizontalScreen) {
|
if (!horizontalScreen) {
|
||||||
fullMode();
|
|
||||||
} else {
|
|
||||||
portraitUpMode();
|
portraitUpMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ Future<void>? portraitUpMode() {
|
|||||||
return _setPreferredOrientations(const [.portraitUp]);
|
return _setPreferredOrientations(const [.portraitUp]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void>? portraitDownMode() {
|
||||||
|
return _setPreferredOrientations(const [.portraitDown]);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void>? landscapeLeftMode() {
|
Future<void>? landscapeLeftMode() {
|
||||||
return _setPreferredOrientations(const [.landscapeLeft]);
|
return _setPreferredOrientations(const [.landscapeLeft]);
|
||||||
}
|
}
|
||||||
@@ -54,7 +58,7 @@ Future<void>? landscapeRightMode() {
|
|||||||
|
|
||||||
Future<void>? fullMode() {
|
Future<void>? fullMode() {
|
||||||
return _setPreferredOrientations(
|
return _setPreferredOrientations(
|
||||||
const [.portraitUp, .landscapeLeft, .landscapeRight],
|
const [.portraitUp, .portraitDown, .landscapeLeft, .landscapeRight],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1235,7 +1235,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: master
|
ref: master
|
||||||
resolved-ref: "42454199133e83a9a31f0fb0107d14af1f96f959"
|
resolved-ref: "64cbc7886f5a5a5ecb09a34aab0d8b9ee48d03d2"
|
||||||
url: "https://github.com/bggRGjQaUbCoE/flutter_native_device_orientation.git"
|
url: "https://github.com/bggRGjQaUbCoE/flutter_native_device_orientation.git"
|
||||||
source: git
|
source: git
|
||||||
version: "2.0.5"
|
version: "2.0.5"
|
||||||
|
|||||||
Reference in New Issue
Block a user