Skip to content

Commit

Permalink
Fix id issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Apr 12, 2024
1 parent 690d907 commit 3ebd9b1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app/lib/ui/flow/home/home_screen_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -211,7 +210,9 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
List<AppMedia> googleDriveMedia = [];
List<AppMedia> 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);
Expand Down
9 changes: 6 additions & 3 deletions app/lib/ui/flow/home/home_view_model_helper_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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));
});
}
}
2 changes: 1 addition & 1 deletion data/lib/models/media/media.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions data/lib/models/media/media_extension.dart
Original file line number Diff line number Diff line change
@@ -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<bool> get isExist async {
return await File(path).exists();
}

Future<Uint8List?> loadThumbnail({Size size = const Size(300, 300)}) async {
var rootToken = RootIsolateToken.instance!;
final ThumbNailParameter thumbNailParameter =
Expand Down
2 changes: 1 addition & 1 deletion data/lib/services/google_drive_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions data/lib/services/local_media_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ final localMediaServiceProvider = Provider<LocalMediaService>(
class LocalMediaService {
const LocalMediaService();


Future<bool> isLocalFileExist({required AppMediaType type, required String id}) async {
return await AssetEntity(id: id, typeInt: type.index, width: 0, height: 0).isLocallyAvailable();
}

Future<bool> requestPermission() async {
final state = await PhotoManager.requestPermissionExtend();
return state.hasAccess;
Expand Down

0 comments on commit 3ebd9b1

Please sign in to comment.