Skip to content

Commit

Permalink
Improve auto backup (#56)
Browse files Browse the repository at this point in the history
* Improve auto-backup

* Improve auto-backup
  • Loading branch information
cp-pratik-k authored Nov 19, 2024
1 parent 939b07f commit 64554c1
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 33 deletions.
10 changes: 10 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/lib/components/thumbnail_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AppMediaImage extends StatelessWidget {
child: Hero(
tag: heroTag ?? '',
child: Image(
image: AppMediaImageProvider(media: media, thumbnailSize: size),
image: AppMediaImageProvider(media: media, thumbnailSize: size * 2),
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress != null) {
return AppMediaPlaceHolder(
Expand Down
12 changes: 7 additions & 5 deletions app/lib/ui/flow/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
size: 36,
backgroundColor: context.colorScheme.containerNormal,
onPressed: () {
TransferRoute().push(context);
onPressed: () async {
await TransferRoute().push(context);
_notifier.loadMedias();
},
icon: Icon(
CupertinoIcons.arrow_up_arrow_down,
Expand All @@ -137,8 +138,9 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
size: 36,
backgroundColor: context.colorScheme.containerNormal,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
AccountRoute().push(context);
onPressed: () async {
await AccountRoute().push(context);
_notifier.loadMedias();
},
icon: Icon(
CupertinoIcons.person,
Expand Down Expand Up @@ -261,7 +263,7 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
startFrom: media.id,
),
).push(context);
_notifier.loadLocalMedia();
_notifier.loadMedias();
}
},
onLongTap: () {
Expand Down
23 changes: 5 additions & 18 deletions app/lib/ui/flow/home/home_screen_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import '../../../domain/extensions/map_extensions.dart';
import '../../../domain/extensions/media_list_extension.dart';
import 'package:collection/collection.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';
Expand Down Expand Up @@ -61,7 +60,7 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
_listenUserGoogleAccount();
_googleDriveProcessRepo.setBackUpFolderId(_backUpFolderId);
_googleDriveProcessRepo.addListener(_listenGoogleDriveProcess);
_loadInitialMedia();
loadMedias();
_checkAutoBackUp();
}

Expand All @@ -75,17 +74,7 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>

void _checkAutoBackUp() {
if (_autoBackUpStatus) {
_googleDriveProcessRepo.uploadMediasInGoogleDrive(
medias: state.medias.valuesWhere(
(element) =>
element.isLocalStored &&
state.mediaProcesses.firstWhereOrNull(
(process) => process.id == element.id,
) ==
null,
),
isFromAutoBackup: true,
);
_googleDriveProcessRepo.autoBackInGoogleDrive();
}
}

Expand Down Expand Up @@ -157,8 +146,8 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
);
}

Future<void> _loadInitialMedia() async {
state = state.copyWith(loading: true, error: null);
Future<void> loadMedias() async {
state = state.copyWith(loading: state.medias.isEmpty, error: null);
final hasAccess = await _localMediaService.requestPermission();
state = state.copyWith(hasLocalMediaAccess: hasAccess, loading: false);
if (hasAccess) {
Expand Down Expand Up @@ -364,9 +353,7 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
)
.toList();

_googleDriveProcessRepo.uploadMediasInGoogleDrive(
medias: medias,
);
_googleDriveProcessRepo.uploadMedia(medias);
state = state.copyWith(selectedMedias: []);
} catch (error) {
state = state.copyWith(error: error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MediaPreviewStateNotifier extends StateNotifier<MediaPreviewState> {
}

Future<void> uploadMediaInGoogleDrive({required AppMedia media}) async {
_googleDriveProcessRepo.uploadMediasInGoogleDrive(medias: [media]);
_googleDriveProcessRepo.uploadMedia([media]);
}

void updateVideoPosition(Duration position) {
Expand Down
Loading

0 comments on commit 64554c1

Please sign in to comment.