From 22fd92212585d819fb13518b28ac8b8a97201e60 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Mon, 26 Dec 2022 11:32:29 +0800 Subject: [PATCH] Add loop control in video player --- app/lib/l10n/app_en.arb | 4 +++ app/lib/l10n/untranslated-messages.txt | 29 +++++++++++------ app/lib/widget/video_viewer.dart | 44 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index 4d7490c4..dc479b46 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -1497,6 +1497,10 @@ "@initialSyncMessage": { "description": "After adding a new account, the app need to sync with the server before showing anything. This message will be shown on screen instead with a proper progress bar and the folder being synced." }, + "loopTooltip": "Loop", + "@loopTooltip": { + "description": "Enable or disable loop in the video player" + }, "errorUnauthenticated": "Unauthenticated access. Please sign-in again if the problem continues", "@errorUnauthenticated": { diff --git a/app/lib/l10n/untranslated-messages.txt b/app/lib/l10n/untranslated-messages.txt index 82a23890..55e65dc7 100644 --- a/app/lib/l10n/untranslated-messages.txt +++ b/app/lib/l10n/untranslated-messages.txt @@ -181,6 +181,7 @@ "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", "initialSyncMessage", + "loopTooltip", "errorAlbumDowngrade" ], @@ -378,6 +379,7 @@ "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", "initialSyncMessage", + "loopTooltip", "errorAlbumDowngrade" ], @@ -465,13 +467,15 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "es": [ "connectingToServerInstruction", "settingsEnhanceMaxResolutionTitle2", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "fi": [ @@ -481,7 +485,8 @@ "settingsSeedColorTitle", "settingsSeedColorDescription", "settingsSeedColorPickerTitle", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "fr": [ @@ -588,7 +593,8 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "pl": [ @@ -712,7 +718,8 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "pt": [ @@ -815,7 +822,8 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "ru": [ @@ -918,7 +926,8 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "zh": [ @@ -1021,7 +1030,8 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ], "zh_Hant": [ @@ -1124,6 +1134,7 @@ "imageSaveOptionDialogContent", "imageSaveOptionDialogDeviceButtonLabel", "imageSaveOptionDialogServerButtonLabel", - "initialSyncMessage" + "initialSyncMessage", + "loopTooltip" ] } diff --git a/app/lib/widget/video_viewer.dart b/app/lib/widget/video_viewer.dart index ed951901..bebf5877 100644 --- a/app/lib/widget/video_viewer.dart +++ b/app/lib/widget/video_viewer.dart @@ -213,6 +213,7 @@ class _VideoViewerState extends State ), ), const SizedBox(width: 4), + _LoopToggle(controller: _controller), Tooltip( message: _controller.value.volume == 0 ? L10n.global().unmuteTooltip @@ -311,6 +312,49 @@ class _VideoViewerState extends State var _isFinished = false; } +class _LoopToggle extends StatefulWidget { + const _LoopToggle({ + required this.controller, + }); + + @override + State createState() => _LoopToggleState(); + + final VideoPlayerController controller; +} + +class _LoopToggleState extends State<_LoopToggle> { + @override + Widget build(BuildContext context) { + return Tooltip( + message: L10n.global().loopTooltip, + child: InkWell( + borderRadius: const BorderRadius.all(Radius.circular(32)), + onTap: () { + setState(() { + widget.controller.setLooping(!widget.controller.value.isLooping); + }); + }, + child: Padding( + padding: const EdgeInsets.all(4), + child: AnimatedSwitcher( + duration: k.animationDurationNormal, + child: widget.controller.value.isLooping + ? const Icon( + Icons.loop, + key: Key("loop_on"), + ) + : const Icon( + Icons.sync_disabled, + key: Key("loop_off"), + ), + ), + ), + ), + ); + } +} + String _durationToString(Duration duration) { String product = ""; if (duration.inHours > 0) {