From 3ebd9b1ace12d58300d6bc1bc9beacd124df6f4f Mon Sep 17 00:00:00 2001 From: Pratik-canopas Date: Fri, 12 Apr 2024 18:04:14 +0530 Subject: [PATCH] Fix id issue --- app/lib/ui/flow/home/home_screen_view_model.dart | 5 +++-- app/lib/ui/flow/home/home_view_model_helper_mixin.dart | 9 ++++++--- data/lib/models/media/media.dart | 2 +- data/lib/models/media/media_extension.dart | 5 ----- data/lib/services/google_drive_service.dart | 2 +- data/lib/services/local_media_service.dart | 5 +++++ 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/lib/ui/flow/home/home_screen_view_model.dart b/app/lib/ui/flow/home/home_screen_view_model.dart index 2994fb4..3892933 100644 --- a/app/lib/ui/flow/home/home_screen_view_model.dart +++ b/app/lib/ui/flow/home/home_screen_view_model.dart @@ -3,7 +3,6 @@ import 'package:cloud_gallery/domain/extensions/map_extensions.dart'; import 'package:cloud_gallery/domain/extensions/media_list_extension.dart'; import 'package:data/models/app_process/app_process.dart'; import 'package:data/models/media/media.dart'; -import 'package:data/models/media/media_extension.dart'; import 'package:data/repositories/google_drive_process_repo.dart'; import 'package:data/services/auth_service.dart'; import 'package:data/services/google_drive_service.dart'; @@ -211,7 +210,9 @@ class HomeViewStateNotifier extends StateNotifier List googleDriveMedia = []; List uploadedMedia = []; for (var media in driveMedias) { - if (await media.isExist) { + if (media.path.trim().isNotEmpty && + await _localMediaService.isLocalFileExist( + type: media.type, id: media.path)) { uploadedMedia.add(media); } else { googleDriveMedia.add(media); diff --git a/app/lib/ui/flow/home/home_view_model_helper_mixin.dart b/app/lib/ui/flow/home/home_view_model_helper_mixin.dart index b258dea..9665c37 100644 --- a/app/lib/ui/flow/home/home_view_model_helper_mixin.dart +++ b/app/lib/ui/flow/home/home_view_model_helper_mixin.dart @@ -23,7 +23,7 @@ mixin HomeViewModelHelperMixin { // Add common media to mergedMedias and remove them from the lists. for (AppMedia localMedia in localMedias.toList()) { googleDriveMedias - .where((googleDriveMedia) => googleDriveMedia.path == localMedia.path) + .where((googleDriveMedia) => googleDriveMedia.path == localMedia.id) .forEach((googleDriveMedia) { localMedias.removeWhere((media) => media.id == localMedia.id); @@ -73,8 +73,11 @@ mixin HomeViewModelHelperMixin { }) { final processIds = process.map((e) => e.id).toList(); return medias.map((key, value) { - return MapEntry(key, - value..replaceMediaRefInMedias(process: process, processIds: processIds)); + return MapEntry( + key, + value + ..replaceMediaRefInMedias( + process: process, processIds: processIds)); }); } } diff --git a/data/lib/models/media/media.dart b/data/lib/models/media/media.dart index f7d629c..4a7bf67 100644 --- a/data/lib/models/media/media.dart +++ b/data/lib/models/media/media.dart @@ -124,7 +124,7 @@ class AppMedia with _$AppMedia { : null; return AppMedia( id: file.id!, - path: file.description ?? file.thumbnailLink ?? '', + path: file.description ?? '', thumbnailLink: file.thumbnailLink, name: file.name, driveMediaRefId: file.id, diff --git a/data/lib/models/media/media_extension.dart b/data/lib/models/media/media_extension.dart index be7857a..8707149 100644 --- a/data/lib/models/media/media_extension.dart +++ b/data/lib/models/media/media_extension.dart @@ -1,15 +1,10 @@ import 'dart:async'; -import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:photo_manager/photo_manager.dart'; import 'media.dart'; extension AppMediaExtension on AppMedia { - Future get isExist async { - return await File(path).exists(); - } - Future loadThumbnail({Size size = const Size(300, 300)}) async { var rootToken = RootIsolateToken.instance!; final ThumbNailParameter thumbNailParameter = diff --git a/data/lib/services/google_drive_service.dart b/data/lib/services/google_drive_service.dart index 6191b62..d4fc2f7 100644 --- a/data/lib/services/google_drive_service.dart +++ b/data/lib/services/google_drive_service.dart @@ -103,7 +103,7 @@ class GoogleDriveService { final file = drive.File( name: media.name ?? localFile.path.split('/').last, - description: media.path, + description: media.id, parents: [folderID], ); final fileLength = localFile.lengthSync(); diff --git a/data/lib/services/local_media_service.dart b/data/lib/services/local_media_service.dart index 501c3d2..7a1dac0 100644 --- a/data/lib/services/local_media_service.dart +++ b/data/lib/services/local_media_service.dart @@ -15,6 +15,11 @@ final localMediaServiceProvider = Provider( class LocalMediaService { const LocalMediaService(); + + Future isLocalFileExist({required AppMediaType type, required String id}) async { + return await AssetEntity(id: id, typeInt: type.index, width: 0, height: 0).isLocallyAvailable(); + } + Future requestPermission() async { final state = await PhotoManager.requestPermissionExtend(); return state.hasAccess;