Fix issues on Samsung phones
This commit is contained in:
parent
d4d0ef78dc
commit
293e2cae95
9 changed files with 52 additions and 14 deletions
|
@ -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 {
|
||||
source '../..'
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class DatabaseHelper {
|
|||
static final columnUploadedFileId = 'uploaded_file_id';
|
||||
static final columnLocalId = 'local_id';
|
||||
static final columnLocalPath = 'local_path';
|
||||
static final columnRelativePath = 'relative_path';
|
||||
static final columnThumbnailPath = 'thumbnail_path';
|
||||
static final columnPath = 'path';
|
||||
static final columnHash = 'hash';
|
||||
|
@ -51,6 +52,7 @@ class DatabaseHelper {
|
|||
$columnLocalId TEXT,
|
||||
$columnUploadedFileId INTEGER NOT NULL,
|
||||
$columnLocalPath TEXT NOT NULL,
|
||||
$columnRelativePath TEXT NOT NULL,
|
||||
$columnThumbnailPath TEXT NOT NULL,
|
||||
$columnPath TEXT,
|
||||
$columnHash TEXT NOT NULL,
|
||||
|
@ -146,6 +148,7 @@ class DatabaseHelper {
|
|||
row[columnUploadedFileId] =
|
||||
photo.uploadedFileId == null ? -1 : photo.uploadedFileId;
|
||||
row[columnLocalPath] = photo.localPath;
|
||||
row[columnRelativePath] = photo.relativePath;
|
||||
row[columnThumbnailPath] = photo.thumbnailPath;
|
||||
row[columnPath] = photo.path;
|
||||
row[columnHash] = photo.hash;
|
||||
|
@ -160,6 +163,7 @@ class DatabaseHelper {
|
|||
photo.localId = row[columnLocalId];
|
||||
photo.uploadedFileId = row[columnUploadedFileId];
|
||||
photo.localPath = row[columnLocalPath];
|
||||
photo.relativePath = row[columnRelativePath];
|
||||
photo.thumbnailPath = row[columnThumbnailPath];
|
||||
photo.path = row[columnPath];
|
||||
photo.hash = row[columnHash];
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
|
||||
class Photo {
|
||||
|
@ -9,6 +11,7 @@ class Photo {
|
|||
String localId;
|
||||
String path;
|
||||
String localPath;
|
||||
String relativePath;
|
||||
String thumbnailPath;
|
||||
String hash;
|
||||
int createTimestamp;
|
||||
|
@ -26,12 +29,20 @@ class Photo {
|
|||
|
||||
static Future<Photo> fromAsset(AssetEntity asset) async {
|
||||
Photo photo = Photo();
|
||||
var file = (await asset.originFile);
|
||||
photo.uploadedFileId = -1;
|
||||
photo.localId = asset.id;
|
||||
var file = await asset.originFile;
|
||||
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.thumbnailPath = file.path;
|
||||
photo.thumbnailPath = photo.localPath;
|
||||
photo.createTimestamp = asset.createDateTime.microsecondsSinceEpoch;
|
||||
return photo;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,8 @@ class PhotoProvider extends ChangeNotifier {
|
|||
if (!result) {
|
||||
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) {
|
||||
return s2.assetCount.compareTo(s1.assetCount);
|
||||
|
@ -98,6 +99,13 @@ class PhotoProvider extends ChangeNotifier {
|
|||
this.list.addAll(galleryList);
|
||||
}
|
||||
|
||||
Future<void> refreshAllGalleryProperties() async {
|
||||
for (var gallery in list) {
|
||||
await gallery.refreshPathProperties();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
PathProvider getOrCreatePathProvider(AssetPathEntity pathEntity) {
|
||||
pathProviderMap[pathEntity] ??= PathProvider(pathEntity);
|
||||
return pathProviderMap[pathEntity];
|
||||
|
@ -149,13 +157,13 @@ class PathProvider extends ChangeNotifier {
|
|||
void delete(AssetEntity entity) async {
|
||||
final result = await PhotoManager.editor.deleteWithIds([entity.id]);
|
||||
if (result.isNotEmpty) {
|
||||
await path.refreshPathProperties(dt: path.fetchDatetime);
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
await provider.refreshAllGalleryProperties();
|
||||
final list =
|
||||
await path.getAssetListRange(start: 0, end: provider.list.length);
|
||||
await path.getAssetListRange(start: 0, end: this.list.length);
|
||||
printListLength("deleted");
|
||||
this.list.clear();
|
||||
this.list.addAll(list);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,6 @@ class PhotoSyncManager {
|
|||
|
||||
Future _downloadDiff(List<Photo> diff, SharedPreferences prefs) async {
|
||||
var externalPath = (await getApplicationDocumentsDirectory()).path;
|
||||
_logger.i("External path: " + externalPath);
|
||||
var path = externalPath + "/photos/";
|
||||
for (Photo photo in diff) {
|
||||
var localPath = path + basename(photo.path);
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:myapp/models/album.dart';
|
|||
import 'package:myapp/models/photo.dart';
|
||||
import 'package:myapp/ui/album_widget.dart';
|
||||
import 'package:myapp/ui/image_widget.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class AlbumListWidget extends StatefulWidget {
|
||||
final List<Photo> photos;
|
||||
|
@ -41,8 +42,7 @@ class _AlbumListWidgetState extends State<AlbumListWidget> {
|
|||
List<Album> _getAlbums(List<Photo> photos) {
|
||||
final albumMap = new LinkedHashMap<String, List<Photo>>();
|
||||
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)) {
|
||||
albumMap[folder] = new List<Photo>();
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import 'package:myapp/models/photo.dart';
|
||||
import 'package:myapp/utils/gallery_items_filter.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
class ImportantItemsFilter implements GalleryItemsFilter {
|
||||
@override
|
||||
bool shouldInclude(Photo photo) {
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ packages:
|
|||
name: photo_manager
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.8"
|
||||
version: "0.5.1-dev.5"
|
||||
photo_view:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -23,7 +23,7 @@ dependencies:
|
|||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
photo_manager: ^0.4.8
|
||||
photo_manager: ^0.5.1-dev.5
|
||||
provider: ^3.1.0
|
||||
sqflite: ^1.3.0
|
||||
path_provider: ^1.6.5
|
||||
|
|
Loading…
Add table
Reference in a new issue