Forráskód Böngészése

Merge remote-tracking branch 'origin/master' into live_photos

Neeraj Gupta 3 éve
szülő
commit
512247a515

+ 13 - 3
lib/main.dart

@@ -216,17 +216,27 @@ Future<void> _killBGTask(String taskId) async {
   BackgroundFetch.finish(taskId);
 }
 
-class EnteApp extends StatelessWidget with WidgetsBindingObserver {
+class EnteApp extends StatefulWidget {
   static const _homeWidget = HomeWidget();
 
   @override
-  Widget build(BuildContext context) {
+  _EnteAppState createState() => _EnteAppState();
+}
+
+class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
+  @override
+  void initState() {
+    super.initState();
     WidgetsBinding.instance.addObserver(this);
     _configureBackgroundFetch();
+  }
+
+  @override
+  Widget build(BuildContext context) {
     return MaterialApp(
       title: "ente",
       theme: themeData,
-      home: _homeWidget,
+      home: EnteApp._homeWidget,
       debugShowCheckedModeBanner: false,
       builder: EasyLoading.init(),
     );

+ 3 - 2
lib/models/file.dart

@@ -163,8 +163,9 @@ class File {
 
   @override
   String toString() {
-    return '''File(uploadedFileId: $uploadedFileID, ownerID: $ownerID,
-      collectionID: $collectionID, updationTime: $updationTime)''';
+    return '''File(generatedID: $generatedID, localID: $localID, 
+      uploadedFileId: $uploadedFileID, modificationTime: $modificationTime, 
+      ownerID: $ownerID, collectionID: $collectionID, updationTime: $updationTime)''';
   }
 
   @override

+ 2 - 1
lib/services/collections_service.dart

@@ -281,7 +281,8 @@ class CollectionsService {
   }
 
   Future<Collection> getOrCreateForPath(String path) async {
-    if (_localCollections.containsKey(path)) {
+    if (_localCollections.containsKey(path) &&
+        _localCollections[path].owner.id == _config.getUserID()) {
       return _localCollections[path];
     }
     final key = CryptoUtil.generateKey();

+ 2 - 0
lib/services/local_sync_service.dart

@@ -52,6 +52,8 @@ class LocalSyncService {
       return;
     }
     final existingLocalFileIDs = await _db.getExistingLocalFileIDs();
+    _logger.info(
+        existingLocalFileIDs.length.toString() + " localIDs were discovered");
     final editedFileIDs = getEditedFileIDs().toSet();
     final downloadedFileIDs = getDownloadedFileIDs().toSet();
     final syncStartTime = DateTime.now().microsecondsSinceEpoch;

+ 7 - 24
lib/ui/lock_screen.dart

@@ -3,7 +3,6 @@ import 'package:flutter/widgets.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/ui/app_lock.dart';
 import 'package:photos/ui/common_elements.dart';
-import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/utils/auth_util.dart';
 
 class LockScreen extends StatefulWidget {
@@ -15,7 +14,6 @@ class LockScreen extends StatefulWidget {
 
 class _LockScreenState extends State<LockScreen> {
   final _logger = Logger("LockScreen");
-  bool _isUnlocking = true;
 
   @override
   void initState() {
@@ -31,21 +29,13 @@ class _LockScreenState extends State<LockScreen> {
           width: double.infinity,
           height: 64,
           padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
-          child: _isUnlocking
-              ? Padding(
-                  padding: const EdgeInsets.only(top: 24),
-                  child: loadWidget,
-                )
-              : button(
-                  "unlock",
-                  fontSize: 18,
-                  onPressed: () async {
-                    setState(() {
-                      _isUnlocking = true;
-                    });
-                    _showLockScreen();
-                  },
-                ),
+          child: button(
+            "unlock",
+            fontSize: 18,
+            onPressed: () async {
+              _showLockScreen();
+            },
+          ),
         ),
       ),
     );
@@ -57,16 +47,9 @@ class _LockScreenState extends State<LockScreen> {
       final result = await requestAuthentication();
       if (result) {
         AppLock.of(context).didUnlock();
-      } else {
-        setState(() {
-          _isUnlocking = false;
-        });
       }
     } catch (e) {
       _logger.severe(e);
-      setState(() {
-        _isUnlocking = false;
-      });
     }
   }
 }

+ 18 - 5
lib/ui/settings/account_section_widget.dart

@@ -2,7 +2,10 @@ import 'dart:io';
 
 import 'package:flutter/material.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
+import 'package:logging/logging.dart';
+import 'package:photos/core/configuration.dart';
 import 'package:photos/services/user_service.dart';
+import 'package:photos/ui/app_lock.dart';
 import 'package:photos/ui/change_email_dialog.dart';
 import 'package:photos/ui/password_entry_page.dart';
 import 'package:photos/ui/recovery_key_dialog.dart';
@@ -53,8 +56,12 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
+            AppLock.of(context).setEnabled(false);
             final result = await requestAuthentication();
+            AppLock.of(context)
+                .setEnabled(Configuration.instance.shouldShowLockScreen());
             if (!result) {
+              Logger("harami").info("Showing toast");
               showToast("please authenticate to view your recovery key");
               return;
             }
@@ -88,11 +95,14 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            // final result = await requestAuthentication();
-            // if (!result) {
-            //   showToast("please authenticate to change your email");
-            //   return;
-            // }
+            AppLock.of(context).setEnabled(false);
+            final result = await requestAuthentication();
+            AppLock.of(context)
+                .setEnabled(Configuration.instance.shouldShowLockScreen());
+            if (!result) {
+              showToast("please authenticate to change your email");
+              return;
+            }
             showDialog(
               context: context,
               builder: (BuildContext context) {
@@ -113,7 +123,10 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
+            AppLock.of(context).setEnabled(false);
             final result = await requestAuthentication();
+            AppLock.of(context)
+                .setEnabled(Configuration.instance.shouldShowLockScreen());
             if (!result) {
               showToast("please authenticate to change your password");
               return;

+ 3 - 0
lib/ui/settings/security_section_widget.dart

@@ -65,7 +65,10 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
                       return Switch(
                         value: snapshot.data,
                         onChanged: (value) async {
+                          AppLock.of(context).setEnabled(false);
                           final result = await requestAuthentication();
+                          AppLock.of(context).setEnabled(
+                              Configuration.instance.shouldShowLockScreen());
                           if (!result) {
                             showToast(
                                 "please authenticate to configure two-factor authentication");

+ 6 - 3
lib/ui/thumbnail_widget.dart

@@ -9,6 +9,7 @@ import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/ui/common_elements.dart';
+import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/thumbnail_util.dart';
 
 class ThumbnailWidget extends StatefulWidget {
@@ -199,9 +200,11 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
           FilesDB.instance.update(widget.file);
           _loadNetworkImage();
         } else {
-          _logger.info("Deleting file " + widget.file.tag());
-          FilesDB.instance.deleteLocalFile(widget.file);
-          Bus.instance.fire(LocalPhotosUpdatedEvent([widget.file]));
+          if (await doesLocalFileExist(widget.file) == false) {
+            _logger.info("Deleting file " + widget.file.tag());
+            FilesDB.instance.deleteLocalFile(widget.file);
+            Bus.instance.fire(LocalPhotosUpdatedEvent([widget.file]));
+          }
         }
         return;
       }

+ 16 - 14
lib/utils/auth_util.dart

@@ -4,19 +4,21 @@ import 'package:logging/logging.dart';
 
 Future<bool> requestAuthentication() async {
   Logger("AuthUtil").info("Requesting authentication");
+  await LocalAuthentication().stopAuthentication();
   return await LocalAuthentication().authenticate(
-      localizedReason: "please authenticate to view your memories",
-      androidAuthStrings: AndroidAuthMessages(
-        biometricHint: "verify identity",
-        biometricNotRecognized: "not recognized, try again",
-        biometricRequiredTitle: "biometric required",
-        biometricSuccess: "successfully verified",
-        cancelButton: "cancel",
-        deviceCredentialsRequiredTitle: "device credentials required",
-        deviceCredentialsSetupDescription: "device credentials required",
-        goToSettingsButton: "go to settings",
-        goToSettingsDescription:
-            "authentication is not setup on your device, go to Settings > Security to set it up",
-        signInTitle: "authentication required",
-      ));
+    localizedReason: "please authenticate to view your memories",
+    androidAuthStrings: AndroidAuthMessages(
+      biometricHint: "verify identity",
+      biometricNotRecognized: "not recognized, try again",
+      biometricRequiredTitle: "biometric required",
+      biometricSuccess: "successfully verified",
+      cancelButton: "cancel",
+      deviceCredentialsRequiredTitle: "device credentials required",
+      deviceCredentialsSetupDescription: "device credentials required",
+      goToSettingsButton: "go to settings",
+      goToSettingsDescription:
+          "authentication is not setup on your device, go to Settings > Security to set it up",
+      signInTitle: "authentication required",
+    ),
+  );
 }

+ 5 - 2
lib/utils/file_uploader_util.dart

@@ -89,10 +89,13 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
   }
 
   thumbnailData = await asset.thumbDataWithSize(
-    kThumbnailSmallSize,
-    kThumbnailSmallSize,
+    kThumbnailLargeSize,
+    kThumbnailLargeSize,
     quality: kThumbnailQuality,
   );
+  if (thumbnailData == null) {
+    throw InvalidFileError();
+  }
   int compressionAttempts = 0;
   while (thumbnailData.length > kThumbnailDataLimit &&
       compressionAttempts < kMaximumThumbnailCompressionAttempts) {

+ 4 - 0
lib/utils/file_util.dart

@@ -44,6 +44,10 @@ Future<io.File> getFile(ente.File file,
   }
 }
 
+Future<bool> doesLocalFileExist(ente.File file) async {
+  return await _getLocalDiskFile(file) != null;
+}
+
 Future<io.File> _getLocalDiskFile(ente.File file, {bool liveVideo = false}) async {
   if (file.isSharedMediaToAppSandbox()) {
     var localFile = io.File(getSharedMediaFilePath(file));

+ 3 - 2
lib/utils/thumbnail_util.dart

@@ -60,8 +60,9 @@ Future<Uint8List> getThumbnailFromServer(File file) async {
 
 Future<Uint8List> getThumbnailFromLocal(File file,
     {int size = kThumbnailSmallSize, int quality = kThumbnailQuality}) async {
-  if (ThumbnailLruCache.get(file, size) != null) {
-    return ThumbnailLruCache.get(file);
+  final lruCachedThumbnail = ThumbnailLruCache.get(file, size);
+  if (lruCachedThumbnail != null) {
+    return lruCachedThumbnail;
   }
   final cachedThumbnail = getCachedThumbnail(file);
   if (cachedThumbnail.existsSync()) {

+ 2 - 1
lib/utils/toast_util.dart

@@ -4,8 +4,9 @@ import 'package:flutter/material.dart';
 import 'package:flutter_easyloading/flutter_easyloading.dart';
 import 'package:fluttertoast/fluttertoast.dart';
 
-Future<void> showToast(String message, {toastLength = Toast.LENGTH_LONG}) {
+Future<void> showToast(String message, {toastLength = Toast.LENGTH_LONG}) async {
   if (Platform.isAndroid) {
+    await Fluttertoast.cancel();
     return Fluttertoast.showToast(
         msg: message,
         toastLength: toastLength,

+ 1 - 1
pubspec.yaml

@@ -11,7 +11,7 @@ description: ente photos application
 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
-version: 0.3.6+216
+version: 0.3.11+221
 
 environment:
   sdk: ">=2.10.0 <3.0.0"