Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Remove unused code

ashilkn0d920a35e78d
diff --git a/mobile/lib/ui/viewer/file/video_controls.dart b/mobile/lib/ui/viewer/file/video_controls.dart
deleted file mode 100644
index 3ce9b66e84..0000000000
--- a/mobile/lib/ui/viewer/file/video_controls.dart
+++ /dev/null
@@ -1,310 +0,0 @@
-import 'dart:async';
-
-import 'package:chewie/chewie.dart';
-import 'package:chewie/src/material/material_progress_bar.dart';
-import 'package:flutter/material.dart';
-import 'package:photos/ente_theme_data.dart';
-import 'package:photos/utils/date_time_util.dart';
-import 'package:video_player/video_player.dart';
-
-class VideoControls extends StatefulWidget {
- const VideoControls({Key? key}) : super(key: key);
-
- @override
- State<StatefulWidget> createState() {
- return _VideoControlsState();
- }
-}
-
-class _VideoControlsState extends State<VideoControls> {
- VideoPlayerValue? _latestValue;
- bool _hideStuff = true;
- Timer? _hideTimer;
- Timer? _initTimer;
- Timer? _showAfterExpandCollapseTimer;
- bool _dragging = false;
- bool _displayTapped = false;
-
- final barHeight = 120.0;
- final marginSize = 5.0;
-
- late VideoPlayerController controller;
- ChewieController? chewieController;
-
- @override
- Widget build(BuildContext context) {
- if (_latestValue!.hasError) {
- return chewieController!.errorBuilder != null
- ? chewieController!.errorBuilder!(
- context,
- chewieController!.videoPlayerController.value.errorDescription!,
- )
- : Center(
- child: Icon(
- Icons.error,
- color: Theme.of(context).colorScheme.onSurface,
- size: 42,
- ),
- );
- }
-
- return MouseRegion(
- onHover: (_) {
- _cancelAndRestartTimer();
- },
- child: GestureDetector(
- onTap: () => _cancelAndRestartTimer(),
- child: AbsorbPointer(
- absorbing: _hideStuff,
- child: Stack(
- children: <Widget>[
- Column(
- children: [
- _latestValue != null &&
- !_latestValue!.isPlaying &&
- _latestValue!.isBuffering
- ? const Center(
- child: CircularProgressIndicator(),
- )
- : _buildHitArea(),
- ],
- ),
- Align(
- alignment: Alignment.bottomCenter,
- child: _buildBottomBar(context),
- ),
- ],
- ),
- ),
- ),
- );
- }
-
- @override
- void dispose() {
- _dispose();
- super.dispose();
- }
-
- void _dispose() {
- controller.removeListener(_updateState);
- _hideTimer?.cancel();
- _initTimer?.cancel();
- _showAfterExpandCollapseTimer?.cancel();
- }
-
- @override
- void didChangeDependencies() {
- final oldController = chewieController;
- chewieController = ChewieController.of(context);
- controller = chewieController!.videoPlayerController;
-
- if (oldController != chewieController) {
- _dispose();
- _initialize();
- }
-
- super.didChangeDependencies();
- }
-
- Widget _buildBottomBar(
- BuildContext context,
- ) {
- final iconColor = Theme.of(context).textTheme.labelLarge!.color;
-
- return Container(
- padding: const EdgeInsets.only(bottom: 60),
- child: AnimatedOpacity(
- opacity: _hideStuff ? 0.0 : 1.0,
- duration: const Duration(milliseconds: 300),
- child: Container(
- height: barHeight,
- color: Colors.transparent,
- child: Row(
- children: <Widget>[
- _buildCurrentPosition(iconColor),
- chewieController!.isLive ? const SizedBox() : _buildProgressBar(),
- _buildTotalDuration(iconColor),
- ],
- ),
- ),
- ),
- );
- }
-
- Expanded _buildHitArea() {
- return Expanded(
- child: GestureDetector(
- onTap: () {
- if (_latestValue != null) {
- if (_displayTapped) {
- setState(() {
- _hideStuff = true;
- });
- } else {
- _cancelAndRestartTimer();
- }
- } else {
- _playPause();
-
- setState(() {
- _hideStuff = true;
- });
- }
- },
- child: Container(
- color: Colors.transparent,
- child: Center(
- child: AnimatedOpacity(
- opacity:
- _latestValue != null && !_hideStuff && !_dragging ? 1.0 : 0.0,
- duration: const Duration(milliseconds: 300),
- child: GestureDetector(
- onTap: _playPause,
- child: Padding(
- padding: const EdgeInsets.all(12.0),
- child: Icon(
- _latestValue!.isPlaying ? Icons.pause : Icons.play_arrow,
- color: Colors.white, // same for both themes
- size: 64.0,
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- );
- }
-
- Widget _buildCurrentPosition(Color? iconColor) {
- final position =
- _latestValue != null ? _latestValue!.position : Duration.zero;
-
- return Container(
- margin: const EdgeInsets.only(left: 20.0, right: 16.0),
- child: Text(
- formatDuration(position),
- style: const TextStyle(
- fontSize: 12.0,
- color: Colors.white,
- ),
- ),
- );
- }
-
- Widget _buildTotalDuration(Color? iconColor) {
- final duration =
- _latestValue != null ? _latestValue!.duration : Duration.zero;
-
- return Padding(
- padding: const EdgeInsets.only(right: 20.0),
- child: Text(
- formatDuration(duration),
- style: const TextStyle(
- fontSize: 12.0,
- color: Colors.white,
- ),
- ),
- );
- }
-
- void _cancelAndRestartTimer() {
- _hideTimer?.cancel();
- _startHideTimer();
-
- setState(() {
- _hideStuff = false;
- _displayTapped = true;
- });
- }
-
- Future<void> _initialize() async {
- controller.addListener(_updateState);
-
- _updateState();
-
- if ((controller.value.isPlaying) || chewieController!.autoPlay) {
- _startHideTimer();
- }
-
- if (chewieController!.showControlsOnInitialize) {
- _initTimer = Timer(const Duration(milliseconds: 200), () {
- setState(() {
- _hideStuff = false;
- });
- });
- }
- }
-
- void _playPause() {
- final bool isFinished = _latestValue!.position >= _latestValue!.duration;
-
- setState(() {
- if (controller.value.isPlaying) {
- _hideStuff = false;
- _hideTimer?.cancel();
- controller.pause();
- } else {
- _cancelAndRestartTimer();
-
- if (!controller.value.isInitialized) {
- controller.initialize().then((_) {
- controller.play();
- });
- } else {
- if (isFinished) {
- controller.seekTo(const Duration(seconds: 0));
- }
- controller.play();
- }
- }
- });
- }
-
- void _startHideTimer() {
- _hideTimer = Timer(const Duration(seconds: 2), () {
- setState(() {
- _hideStuff = true;
- });
- });
- }
-
- void _updateState() {
- setState(() {
- _latestValue = controller.value;
- });
- }
-
- Widget _buildProgressBar() {
- return Expanded(
- child: Padding(
- padding: const EdgeInsets.only(right: 16.0),
- child: MaterialVideoProgressBar(
- controller,
- onDragStart: () {
- setState(() {
- _dragging = true;
- });
-
- _hideTimer?.cancel();
- },
- onDragEnd: () {
- setState(() {
- _dragging = false;
- });
-
- _startHideTimer();
- },
- colors: chewieController!.materialProgressColors ??
- ChewieProgressColors(
- playedColor: Theme.of(context).colorScheme.greenAlternative,
- handleColor: Colors.white,
- bufferedColor: Colors.white,
- backgroundColor: Theme.of(context).disabledColor,
- ),
- ),
- ),
- );
- }
-}
diff --git a/mobile/lib/ui/viewer/file/video_widget_chewie.dart b/mobile/lib/ui/viewer/file/video_widget_chewie.dart
deleted file mode 100644
index a81c3bcbed..0000000000
--- a/mobile/lib/ui/viewer/file/video_widget_chewie.dart
+++ /dev/null
@@ -1,299 +0,0 @@
-import 'dart:async';
-import 'dart:io';
-
-import 'package:chewie/chewie.dart';
-import 'package:flutter/cupertino.dart';
-import 'package:flutter/material.dart';
-import 'package:logging/logging.dart';
-import 'package:photos/core/constants.dart';
-import "package:photos/core/event_bus.dart";
-import "package:photos/events/guest_view_event.dart";
-import "package:photos/generated/l10n.dart";
-import "package:photos/models/file/extensions/file_props.dart";
-import 'package:photos/models/file/file.dart';
-import "package:photos/service_locator.dart";
-import 'package:photos/services/files_service.dart';
-import "package:photos/ui/actions/file/file_actions.dart";
-import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
-import 'package:photos/ui/viewer/file/video_controls.dart';
-import "package:photos/utils/dialog_util.dart";
-import 'package:photos/utils/file_util.dart';
-import 'package:photos/utils/toast_util.dart';
-import "package:photos/utils/wakelock_util.dart";
-import 'package:video_player/video_player.dart';
-import 'package:visibility_detector/visibility_detector.dart';
-
-class VideoWidgetChewie extends StatefulWidget {
- final EnteFile file;
- final bool? autoPlay;
- final String? tagPrefix;
- final Function(bool)? playbackCallback;
-
- const VideoWidgetChewie(
- this.file, {
- this.autoPlay = false,
- this.tagPrefix,
- this.playbackCallback,
- super.key,
- });
-
- @override
- State<VideoWidgetChewie> createState() => _VideoWidgetChewieState();
-}
-
-class _VideoWidgetChewieState extends State<VideoWidgetChewie> {
- final _logger = Logger("VideoWidget");
- VideoPlayerController? _videoPlayerController;
- ChewieController? _chewieController;
- final _progressNotifier = ValueNotifier<double?>(null);
- bool _isPlaying = false;
- final EnteWakeLock _wakeLock = EnteWakeLock();
- bool isGuestView = false;
- late final StreamSubscription<GuestViewEvent> _guestViewEventSubscription;
-
- @override
- void initState() {
- super.initState();
- if (widget.file.isRemoteFile) {
- _loadNetworkVideo();
- _setFileSizeIfNull();
- } else if (widget.file.isSharedMediaToAppSandbox) {
- final localFile = File(getSharedMediaFilePath(widget.file));
- if (localFile.existsSync()) {
- _logger.fine("loading from app cache");
- _setVideoPlayerController(file: localFile);
- } else if (widget.file.uploadedFileID != null) {
- _loadNetworkVideo();
- }
- } else {
- widget.file.getAsset.then((asset) async {
- if (asset == null || !(await asset.exists)) {
- if (widget.file.uploadedFileID != null) {
- _loadNetworkVideo();
- }
- } else {
- // ignore: unawaited_futures
- asset.getMediaUrl().then((url) {
- _setVideoPlayerController(url: url);
- });
- }
- });
- }
- _guestViewEventSubscription =
- Bus.instance.on<GuestViewEvent>().listen((event) {
- setState(() {
- isGuestView = event.isGuestView;
- });
- });
- }
-
- void _setFileSizeIfNull() {
- if (widget.file.fileSize == null && widget.file.canEditMetaInfo) {
- FilesService.instance
- .getFileSize(widget.file.uploadedFileID!)
- .then((value) {
- widget.file.fileSize = value;
- if (mounted) {
- setState(() {});
- }
- });
- }
- }
-
- void _loadNetworkVideo() {
- getFileFromServer(
- widget.file,
- progressCallback: (count, total) {
- if (!mounted) {
- return;
- }
- _progressNotifier.value = count / (widget.file.fileSize ?? total);
- if (_progressNotifier.value == 1) {
- if (mounted) {
- showShortToast(context, S.of(context).decryptingVideo);
- }
- }
- },
- ).then((file) {
- if (file != null && mounted) {
- _setVideoPlayerController(file: file);
- }
- }).onError((error, stackTrace) {
- if (mounted) {
- showErrorDialog(
- context,
- S.of(context).error,
- S.of(context).failedToDownloadVideo,
- );
- }
- });
- }
-
- @override
- void dispose() {
- _guestViewEventSubscription.cancel();
- removeCallBack(widget.file);
- _videoPlayerController?.dispose();
- _chewieController?.dispose();
- _progressNotifier.dispose();
- _wakeLock.dispose();
- super.dispose();
- }
-
- void _setVideoPlayerController({
- String? url,
- File? file,
- }) {
- if (!mounted) {
- // Note: Do not initiale video player if widget is not mounted.
- // On Android, if multiple instance of ExoPlayer is created, it will start
- // resulting in playback errors for videos. See https://github.com/google/ExoPlayer/issues/6168
- return;
- }
- VideoPlayerController videoPlayerController;
- if (url != null) {
- videoPlayerController = VideoPlayerController.network(url);
- } else {
- videoPlayerController = VideoPlayerController.file(file!);
- }
-
- debugPrint("videoPlayerController: $videoPlayerController");
- _videoPlayerController = videoPlayerController
- ..initialize().whenComplete(() {
- if (mounted) {
- setState(() {});
- }
- }).onError(
- (error, stackTrace) {
- if (mounted && flagService.internalUser) {
- if (error is Exception) {
- showErrorDialogForException(
- context: context,
- exception: error,
- message:
- S.of(context).failedToPlayVideo + "\n" + error.toString(),
- );
- } else {
- showToast(context, S.of(context).failedToPlayVideo);
- }
- }
- },
- );
- }
-
- @override
- Widget build(BuildContext context) {
- final content = _videoPlayerController != null &&
- _videoPlayerController!.value.isInitialized
- ? _getVideoPlayer()
- : _getLoadingWidget();
- final contentWithDetector = GestureDetector(
- onVerticalDragUpdate: isGuestView
- ? null
- : (d) => {
- if (d.delta.dy > dragSensitivity)
- {
- Navigator.of(context).pop(),
- }
- else if (d.delta.dy < (dragSensitivity * -1))
- {
- showDetailsSheet(context, widget.file),
- },
- },
- child: content,
- );
- return VisibilityDetector(
- key: Key(widget.file.tag),
- onVisibilityChanged: (info) {
- if (info.visibleFraction < 1) {
- if (mounted && _chewieController != null) {
- _chewieController!.pause();
- }
- }
- },
- child: Hero(
- tag: widget.tagPrefix! + widget.file.tag,
- child: contentWithDetector,
- ),
- );
- }
-
- Widget _getLoadingWidget() {
- return Stack(
- children: [
- _getThumbnail(),
- Container(
- color: Colors.black12,
- constraints: const BoxConstraints.expand(),
- ),
- Center(
- child: SizedBox.fromSize(
- size: const Size.square(20),
- child: ValueListenableBuilder(
- valueListenable: _progressNotifier,
- builder: (BuildContext context, double? progress, _) {
- return progress == null || progress == 1
- ? const CupertinoActivityIndicator(
- color: Colors.white,
- )
- : CircularProgressIndicator(
- backgroundColor: Colors.black,
- value: progress,
- valueColor: const AlwaysStoppedAnimation<Color>(
- Color.fromRGBO(45, 194, 98, 1.0),
- ),
- );
- },
- ),
- ),
- ),
- ],
- );
- }
-
- Widget _getThumbnail() {
- return Container(
- color: Colors.black,
- constraints: const BoxConstraints.expand(),
- child: ThumbnailWidget(
- widget.file,
- fit: BoxFit.contain,
- ),
- );
- }
-
- Future<void> _keepScreenAliveOnPlaying(bool isPlaying) async {
- if (isPlaying) {
- _wakeLock.enable();
- }
- if (!isPlaying) {
- _wakeLock.disable();
- }
- }
-
- Widget _getVideoPlayer() {
- _videoPlayerController!.addListener(() {
- if (_isPlaying != _videoPlayerController!.value.isPlaying) {
- _isPlaying = _videoPlayerController!.value.isPlaying;
- if (widget.playbackCallback != null) {
- widget.playbackCallback!(_isPlaying);
- }
- unawaited(_keepScreenAliveOnPlaying(_isPlaying));
- }
- });
- _chewieController = ChewieController(
- videoPlayerController: _videoPlayerController!,
- aspectRatio: _videoPlayerController!.value.aspectRatio,
- autoPlay: widget.autoPlay!,
- autoInitialize: true,
- looping: true,
- allowMuting: true,
- allowFullScreen: false,
- customControls: const VideoControls(),
- );
- return Container(
- color: Colors.black,
- child: Chewie(controller: _chewieController!),
- );
- }
-}
diff --git a/mobile/lib/ui/viewer/file/zoomable_live_image.dart b/mobile/lib/ui/viewer/file/zoomable_live_image.dart
deleted file mode 100644
index f7e2aa55af..0000000000
--- a/mobile/lib/ui/viewer/file/zoomable_live_image.dart
+++ /dev/null
@@ -1,210 +0,0 @@
-import "dart:io";
-
-import 'package:chewie/chewie.dart';
-import 'package:flutter/material.dart';
-import 'package:logging/logging.dart';
-import 'package:motion_photos/motion_photos.dart';
-import "package:photos/generated/l10n.dart";
-import "package:photos/models/file/extensions/file_props.dart";
-import 'package:photos/models/file/file.dart';
-import "package:photos/models/metadata/file_magic.dart";
-import "package:photos/services/file_magic_service.dart";
-import 'package:photos/ui/viewer/file/zoomable_image.dart';
-import 'package:photos/utils/file_util.dart';
-import 'package:photos/utils/toast_util.dart';
-import 'package:video_player/video_player.dart';
-
-class ZoomableLiveImage extends StatefulWidget {
- final EnteFile enteFile;
- final Function(bool)? shouldDisableScroll;
- final String? tagPrefix;
- final Decoration? backgroundDecoration;
-
- const ZoomableLiveImage(
- this.enteFile, {
- Key? key,
- this.shouldDisableScroll,
- required this.tagPrefix,
- this.backgroundDecoration,
- }) : super(key: key);
-
- @override
- State<ZoomableLiveImage> createState() => _ZoomableLiveImageState();
-}
-
-class _ZoomableLiveImageState extends State<ZoomableLiveImage>
- with SingleTickerProviderStateMixin {
- final Logger _logger = Logger("ZoomableLiveImage");
- late EnteFile _enteFile;
- bool _showVideo = false;
- bool _isLoadingVideoPlayer = false;
-
- VideoPlayerController? _videoPlayerController;
- ChewieController? _chewieController;
-
- @override
- void initState() {
- _enteFile = widget.enteFile;
- _logger.info('initState for ${_enteFile.generatedID} with tag ${_enteFile
- .tag} and name ${_enteFile.displayName}');
- super.initState();
- }
-
- void _onLongPressEvent(bool isPressed) {
- if (_videoPlayerController != null && isPressed == false) {
- // stop playing video
- _videoPlayerController!.pause();
- }
- if (mounted) {
- setState(() {
- _showVideo = isPressed;
- });
- }
- }
-
- @override
- Widget build(BuildContext context) {
- Widget content;
- // check is long press is selected but videoPlayer is not configured yet
- if (_showVideo && _videoPlayerController == null) {
- _loadLiveVideo();
- }
-
- if (_showVideo && _videoPlayerController != null) {
- content = _getVideoPlayer();
- } else {
- content = ZoomableImage(
- _enteFile,
- tagPrefix: widget.tagPrefix,
- shouldDisableScroll: widget.shouldDisableScroll,
- backgroundDecoration: widget.backgroundDecoration,
- );
- }
- return GestureDetector(
- onLongPressStart: (_) => {_onLongPressEvent(true)},
- onLongPressEnd: (_) => {_onLongPressEvent(false)},
- child: content,
- );
- }
-
- @override
- void dispose() {
- if (_videoPlayerController != null) {
- _videoPlayerController!.pause();
- _videoPlayerController!.dispose();
- }
- if (_chewieController != null) {
- _chewieController!.dispose();
- }
- super.dispose();
- }
-
- Widget _getVideoPlayer() {
- _videoPlayerController!.seekTo(Duration.zero);
- _chewieController = ChewieController(
- videoPlayerController: _videoPlayerController!,
- aspectRatio: _videoPlayerController!.value.aspectRatio,
- autoPlay: true,
- autoInitialize: true,
- looping: true,
- allowFullScreen: false,
- showControls: false,
- );
- return Container(
- color: Colors.black,
- child: Chewie(controller: _chewieController!), // same for both theme
- );
- }
-
- Future<void> _loadLiveVideo() async {
- // do nothing is already loading or loaded
- if (_isLoadingVideoPlayer || _videoPlayerController != null) {
- return;
- }
- _isLoadingVideoPlayer = true;
- // For non-live photo, with fileType as Image, we still call _getMotionPhoto
- // to check if it is a motion photo. This is needed to handle earlier
- // uploads and upload from desktop
- final File? videoFile = _enteFile.isLivePhoto
- ? await _getLivePhotoVideo()
- : await _getMotionPhotoVideo();
-
- if (videoFile != null && videoFile.existsSync()) {
- _setVideoPlayerController(file: videoFile);
- } else if (_enteFile.isLivePhoto) {
- showShortToast(context, S.of(context).downloadFailed);
- }
- _isLoadingVideoPlayer = false;
- }
-
- Future<File?> _getLivePhotoVideo() async {
- if (_enteFile.isRemoteFile && !(await isFileCached(_enteFile, liveVideo: true))) {
- showShortToast(context, S.of(context).downloading);
- }
-
- File? videoFile = await getFile(widget.enteFile, liveVideo: true)
- .timeout(const Duration(seconds: 15))
- .onError((dynamic e, s) {
- _logger.info("getFile failed ${_enteFile.tag}", e);
- return null;
- });
-
- // FixMe: Here, we are fetching video directly when getFile failed
- // getFile with liveVideo as true can fail for file with localID when
- // the live photo was downloaded from remote.
- if ((videoFile == null || !videoFile.existsSync()) &&
- _enteFile.uploadedFileID != null) {
- videoFile = await getFileFromServer(widget.enteFile, liveVideo: true)
- .timeout(const Duration(seconds: 15))
- .onError((dynamic e, s) {
- _logger.info("getRemoteFile failed ${_enteFile.tag}", e);
- return null;
- });
- }
- return videoFile;
- }
-
- Future<File?> _getMotionPhotoVideo() async {
- if (_enteFile.isRemoteFile && !(await isFileCached(_enteFile))) {
- showShortToast(context, S.of(context).downloading);
- }
-
- final File? imageFile = await getFile(
- widget.enteFile,
- isOrigin: !Platform.isAndroid,
- ).timeout(const Duration(seconds: 15)).onError((dynamic e, s) {
- _logger.info("getFile failed ${_enteFile.tag}", e);
- return null;
- });
- if (imageFile != null) {
- final motionPhoto = MotionPhotos(imageFile.path);
- final index = await motionPhoto.getMotionVideoIndex();
- if (index != null) {
- // Update the metadata if it is not updated
- if (!_enteFile.isMotionPhoto && _enteFile.canEditMetaInfo) {
- FileMagicService.instance.updatePublicMagicMetadata(
- [_enteFile],
- {motionVideoIndexKey: index.start},
- ).ignore();
- }
- return motionPhoto.getMotionVideoFile(
- index: index,
- );
- }
- }
- return null;
- }
-
- VideoPlayerController _setVideoPlayerController({required File file}) {
- final videoPlayerController = VideoPlayerController.file(file);
- return _videoPlayerController = videoPlayerController
- ..initialize().whenComplete(() {
- if (mounted) {
- setState(() {
- _showVideo = true;
- });
- }
- });
- }
-
-}