Skip to content

armgit / ente

Public Imported from GitHub
0

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

-mRefactor

Neeraj Gupta6166aa5e0046
diff --git a/mobile/lib/models/file/extensions/file_props.dart b/mobile/lib/models/file/extensions/file_props.dart
index 64436ef2e3..6f68f916b9 100644
--- a/mobile/lib/models/file/extensions/file_props.dart
+++ b/mobile/lib/models/file/extensions/file_props.dart
@@ -16,6 +16,22 @@ extension FilePropsExtn on EnteFile {
bool get isVideo => fileType == FileType.video;
+ bool get hasDims => height > 0 && width > 0;
+
+ // return true if the file is a panorama image, null if the dimensions are not available
+ bool? isPanorama() {
+ if (fileType != FileType.image) {
+ return false;
+ }
+ if (hasDims) {
+ if (height > width) {
+ return height / width >= 2.0;
+ }
+ return width / height >= 2.0;
+ }
+ return null;
+ }
+
bool get canEditMetaInfo => isUploaded && isOwner;
bool get isTrash => this is TrashFile;
diff --git a/mobile/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/lib/ui/viewer/file/file_bottom_bar.dart
index 5861b8ed9b..1f31819118 100644
--- a/mobile/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/lib/ui/viewer/file/file_bottom_bar.dart
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import "package:logging/logging.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/file/file_type.dart';
import 'package:photos/models/file/trash_file.dart';
@@ -42,11 +43,25 @@ class FileBottomBar extends StatefulWidget {
class FileBottomBarState extends State<FileBottomBar> {
final GlobalKey shareButtonKey = GlobalKey();
- bool isPanorama = false;
+ late bool isPanorama;
bool _isPanoramaCheckInitiated = false;
+ @override
+ void initState() {
+ super.initState();
+ isPanorama = widget.file.isPanorama() ?? false;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ _checkPanorama();
+ return _getBottomBar();
+ }
+
+ // _checkPanorama() method is used to check if the file is a panorama image.
+ // This handles the case when the the file dims (width and height) are not available.
Future<void> _checkPanorama() async {
- if (_isPanoramaCheckInitiated) {
+ if (_isPanoramaCheckInitiated || widget.file.hasDims) {
return;
}
_isPanoramaCheckInitiated = true;
@@ -57,12 +72,6 @@ class FileBottomBarState extends State<FileBottomBar> {
}
}
- @override
- Widget build(BuildContext context) {
- _checkPanorama();
- return _getBottomBar();
- }
-
void safeRefresh() {
if (mounted) {
setState(() {});
diff --git a/mobile/lib/utils/panorama_util.dart b/mobile/lib/utils/panorama_util.dart
index 1ff1051907..d4fee93669 100644
--- a/mobile/lib/utils/panorama_util.dart
+++ b/mobile/lib/utils/panorama_util.dart
@@ -1,19 +1,17 @@
import "package:flutter/painting.dart";
+import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/utils/file_util.dart";
+/// Check if the file is a panorama image.
Future<bool> checkIfPanorama(EnteFile enteFile) async {
if (enteFile.fileType != FileType.image) {
return false;
}
- if (enteFile.height > 0 && enteFile.width > 0) {
- if (enteFile.height > enteFile.width) {
- return enteFile.height / enteFile.width >= 2.0;
- }
- return enteFile.width / enteFile.height >= 2.0;
+ if (enteFile.isPanorama() != null) {
+ return enteFile.isPanorama()!;
}
-
final file = await getFile(enteFile);
if (file == null) {
return false;