浏览代码

Fix issues on Samsung phones

Vishnu Mohandas 5 年之前
父节点
当前提交
293e2cae95

+ 13 - 0
android/app/build.gradle

@@ -55,6 +55,19 @@ android {
     }
     }
 }
 }
 
 
+rootProject.allprojects {
+    subprojects {
+        project.configurations.all {
+            resolutionStrategy.eachDependency { details ->
+                if (details.requested.group == 'com.github.bumptech.glide'
+                        && details.requested.name.contains('glide')) {
+                    details.useVersion "4.9.0"
+                }
+            }
+        }
+    }
+}
+
 flutter {
 flutter {
     source '../..'
     source '../..'
 }
 }

+ 4 - 0
lib/db/db_helper.dart

@@ -15,6 +15,7 @@ class DatabaseHelper {
   static final columnUploadedFileId = 'uploaded_file_id';
   static final columnUploadedFileId = 'uploaded_file_id';
   static final columnLocalId = 'local_id';
   static final columnLocalId = 'local_id';
   static final columnLocalPath = 'local_path';
   static final columnLocalPath = 'local_path';
+  static final columnRelativePath = 'relative_path';
   static final columnThumbnailPath = 'thumbnail_path';
   static final columnThumbnailPath = 'thumbnail_path';
   static final columnPath = 'path';
   static final columnPath = 'path';
   static final columnHash = 'hash';
   static final columnHash = 'hash';
@@ -51,6 +52,7 @@ class DatabaseHelper {
             $columnLocalId TEXT,
             $columnLocalId TEXT,
             $columnUploadedFileId INTEGER NOT NULL,
             $columnUploadedFileId INTEGER NOT NULL,
             $columnLocalPath TEXT NOT NULL,
             $columnLocalPath TEXT NOT NULL,
+            $columnRelativePath TEXT NOT NULL,
             $columnThumbnailPath TEXT NOT NULL,
             $columnThumbnailPath TEXT NOT NULL,
             $columnPath TEXT,
             $columnPath TEXT,
             $columnHash TEXT NOT NULL,
             $columnHash TEXT NOT NULL,
@@ -146,6 +148,7 @@ class DatabaseHelper {
     row[columnUploadedFileId] =
     row[columnUploadedFileId] =
         photo.uploadedFileId == null ? -1 : photo.uploadedFileId;
         photo.uploadedFileId == null ? -1 : photo.uploadedFileId;
     row[columnLocalPath] = photo.localPath;
     row[columnLocalPath] = photo.localPath;
+    row[columnRelativePath] = photo.relativePath;
     row[columnThumbnailPath] = photo.thumbnailPath;
     row[columnThumbnailPath] = photo.thumbnailPath;
     row[columnPath] = photo.path;
     row[columnPath] = photo.path;
     row[columnHash] = photo.hash;
     row[columnHash] = photo.hash;
@@ -160,6 +163,7 @@ class DatabaseHelper {
     photo.localId = row[columnLocalId];
     photo.localId = row[columnLocalId];
     photo.uploadedFileId = row[columnUploadedFileId];
     photo.uploadedFileId = row[columnUploadedFileId];
     photo.localPath = row[columnLocalPath];
     photo.localPath = row[columnLocalPath];
+    photo.relativePath = row[columnRelativePath];
     photo.thumbnailPath = row[columnThumbnailPath];
     photo.thumbnailPath = row[columnThumbnailPath];
     photo.path = row[columnPath];
     photo.path = row[columnPath];
     photo.hash = row[columnHash];
     photo.hash = row[columnHash];

+ 13 - 2
lib/models/photo.dart

@@ -1,6 +1,8 @@
 import 'dart:io';
 import 'dart:io';
 
 
 import 'package:crypto/crypto.dart';
 import 'package:crypto/crypto.dart';
+import 'package:logger/logger.dart';
+import 'package:path/path.dart';
 import 'package:photo_manager/photo_manager.dart';
 import 'package:photo_manager/photo_manager.dart';
 
 
 class Photo {
 class Photo {
@@ -9,6 +11,7 @@ class Photo {
   String localId;
   String localId;
   String path;
   String path;
   String localPath;
   String localPath;
+  String relativePath;
   String thumbnailPath;
   String thumbnailPath;
   String hash;
   String hash;
   int createTimestamp;
   int createTimestamp;
@@ -26,12 +29,20 @@ class Photo {
 
 
   static Future<Photo> fromAsset(AssetEntity asset) async {
   static Future<Photo> fromAsset(AssetEntity asset) async {
     Photo photo = Photo();
     Photo photo = Photo();
-    var file = (await asset.originFile);
     photo.uploadedFileId = -1;
     photo.uploadedFileId = -1;
     photo.localId = asset.id;
     photo.localId = asset.id;
+    var file = await asset.originFile;
     photo.localPath = file.path;
     photo.localPath = file.path;
+    if (Platform.isAndroid) {
+      photo.relativePath = dirname((asset.relativePath.endsWith("/")
+              ? asset.relativePath
+              : asset.relativePath + "/") +
+          asset.title);
+    } else {
+      photo.relativePath = dirname(photo.localPath);
+    }
     photo.hash = getHash(file);
     photo.hash = getHash(file);
-    photo.thumbnailPath = file.path;
+    photo.thumbnailPath = photo.localPath;
     photo.createTimestamp = asset.createDateTime.microsecondsSinceEpoch;
     photo.createTimestamp = asset.createDateTime.microsecondsSinceEpoch;
     return photo;
     return photo;
   }
   }

+ 12 - 4
lib/photo_provider.dart

@@ -88,7 +88,8 @@ class PhotoProvider extends ChangeNotifier {
     if (!result) {
     if (!result) {
       print("Did not get permission");
       print("Did not get permission");
     }
     }
-    var galleryList = await PhotoManager.getAssetPathList(type: RequestType.image);
+    var galleryList =
+        await PhotoManager.getAssetPathList(type: RequestType.image);
 
 
     galleryList.sort((s1, s2) {
     galleryList.sort((s1, s2) {
       return s2.assetCount.compareTo(s1.assetCount);
       return s2.assetCount.compareTo(s1.assetCount);
@@ -98,6 +99,13 @@ class PhotoProvider extends ChangeNotifier {
     this.list.addAll(galleryList);
     this.list.addAll(galleryList);
   }
   }
 
 
+  Future<void> refreshAllGalleryProperties() async {
+    for (var gallery in list) {
+      await gallery.refreshPathProperties();
+    }
+    notifyListeners();
+  }
+
   PathProvider getOrCreatePathProvider(AssetPathEntity pathEntity) {
   PathProvider getOrCreatePathProvider(AssetPathEntity pathEntity) {
     pathProviderMap[pathEntity] ??= PathProvider(pathEntity);
     pathProviderMap[pathEntity] ??= PathProvider(pathEntity);
     return pathProviderMap[pathEntity];
     return pathProviderMap[pathEntity];
@@ -149,13 +157,13 @@ class PathProvider extends ChangeNotifier {
   void delete(AssetEntity entity) async {
   void delete(AssetEntity entity) async {
     final result = await PhotoManager.editor.deleteWithIds([entity.id]);
     final result = await PhotoManager.editor.deleteWithIds([entity.id]);
     if (result.isNotEmpty) {
     if (result.isNotEmpty) {
-      await path.refreshPathProperties(dt: path.fetchDatetime);
+      await Future.delayed(Duration(seconds: 3));
+      await provider.refreshAllGalleryProperties();
       final list =
       final list =
-          await path.getAssetListRange(start: 0, end: provider.list.length);
+          await path.getAssetListRange(start: 0, end: this.list.length);
       printListLength("deleted");
       printListLength("deleted");
       this.list.clear();
       this.list.clear();
       this.list.addAll(list);
       this.list.addAll(list);
-      notifyListeners();
     }
     }
   }
   }
 
 

+ 0 - 1
lib/photo_sync_manager.dart

@@ -96,7 +96,6 @@ class PhotoSyncManager {
 
 
   Future _downloadDiff(List<Photo> diff, SharedPreferences prefs) async {
   Future _downloadDiff(List<Photo> diff, SharedPreferences prefs) async {
     var externalPath = (await getApplicationDocumentsDirectory()).path;
     var externalPath = (await getApplicationDocumentsDirectory()).path;
-    _logger.i("External path: " + externalPath);
     var path = externalPath + "/photos/";
     var path = externalPath + "/photos/";
     for (Photo photo in diff) {
     for (Photo photo in diff) {
       var localPath = path + basename(photo.path);
       var localPath = path + basename(photo.path);

+ 2 - 2
lib/ui/album_list_widget.dart

@@ -6,6 +6,7 @@ import 'package:myapp/models/album.dart';
 import 'package:myapp/models/photo.dart';
 import 'package:myapp/models/photo.dart';
 import 'package:myapp/ui/album_widget.dart';
 import 'package:myapp/ui/album_widget.dart';
 import 'package:myapp/ui/image_widget.dart';
 import 'package:myapp/ui/image_widget.dart';
+import 'package:path/path.dart' as path;
 
 
 class AlbumListWidget extends StatefulWidget {
 class AlbumListWidget extends StatefulWidget {
   final List<Photo> photos;
   final List<Photo> photos;
@@ -41,8 +42,7 @@ class _AlbumListWidgetState extends State<AlbumListWidget> {
   List<Album> _getAlbums(List<Photo> photos) {
   List<Album> _getAlbums(List<Photo> photos) {
     final albumMap = new LinkedHashMap<String, List<Photo>>();
     final albumMap = new LinkedHashMap<String, List<Photo>>();
     for (Photo photo in photos) {
     for (Photo photo in photos) {
-      final splitPath = photo.localPath.split("/");
-      final folder = splitPath[splitPath.length - 2];
+      final folder = path.basename(photo.relativePath);
       if (!albumMap.containsKey(folder)) {
       if (!albumMap.containsKey(folder)) {
         albumMap[folder] = new List<Photo>();
         albumMap[folder] = new List<Photo>();
       }
       }

+ 6 - 3
lib/utils/important_items_filter.dart

@@ -1,12 +1,15 @@
 import 'package:myapp/models/photo.dart';
 import 'package:myapp/models/photo.dart';
 import 'package:myapp/utils/gallery_items_filter.dart';
 import 'package:myapp/utils/gallery_items_filter.dart';
+import 'package:path/path.dart';
 
 
 class ImportantItemsFilter implements GalleryItemsFilter {
 class ImportantItemsFilter implements GalleryItemsFilter {
   @override
   @override
   bool shouldInclude(Photo photo) {
   bool shouldInclude(Photo photo) {
     // TODO: Improve logic
     // TODO: Improve logic
-    return photo.localPath.contains("/Camera/") ||
-        photo.localPath.contains("/Download/") ||
-        photo.localPath.contains("/Screenshots/");
+    final String folder = basename(photo.relativePath);
+    return folder == "Camera" ||
+        folder == "DCIM" ||
+        folder == "Download" ||
+        folder == "Screenshot";
   }
   }
 }
 }

+ 1 - 1
pubspec.lock

@@ -190,7 +190,7 @@ packages:
       name: photo_manager
       name: photo_manager
       url: "https://pub.dartlang.org"
       url: "https://pub.dartlang.org"
     source: hosted
     source: hosted
-    version: "0.4.8"
+    version: "0.5.1-dev.5"
   photo_view:
   photo_view:
     dependency: "direct main"
     dependency: "direct main"
     description:
     description:

+ 1 - 1
pubspec.yaml

@@ -23,7 +23,7 @@ dependencies:
   # The following adds the Cupertino Icons font to your application.
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
   # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^0.1.2
   cupertino_icons: ^0.1.2
-  photo_manager: ^0.4.8
+  photo_manager: ^0.5.1-dev.5
   provider: ^3.1.0
   provider: ^3.1.0
   sqflite: ^1.3.0
   sqflite: ^1.3.0
   path_provider: ^1.6.5
   path_provider: ^1.6.5