Skip to content

Commit

Permalink
Implement auto back-up (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k authored Mar 12, 2024
1 parent f6efd79 commit 05c379a
Show file tree
Hide file tree
Showing 12 changed files with 371 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

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

10 changes: 9 additions & 1 deletion app/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@
"system_theme_text": "System",

"add_account_title": "Add account",
"version_text": "Version"
"version_text": "Version",

"greetings_hey_there_text": "Hey There!",
"greetings_hey_text": "Hey",

"hint_google_sign_in_message": "Sign in with Google and effortlessly link your Google Drive to your Cloud Gallery. Enjoy quick access to all your awesome content in one spot",
"hint_google_auto_backup_message": "Enable Auto Back Up to Google Drive and never lose your precious memories. Your photos and videos will be automatically backed up to your Google Drive",
"hint_action_auto_backup": "Enable Auto Back Up"

}
16 changes: 11 additions & 5 deletions app/lib/ui/flow/accounts/accounts_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:cloud_gallery/domain/extensions/context_extensions.dart';
import 'package:cloud_gallery/domain/extensions/widget_extensions.dart';
import 'package:cloud_gallery/ui/flow/accounts/accounts_screen_view_model.dart';
import 'package:cloud_gallery/ui/flow/accounts/components/settings_action_list.dart';
import 'package:data/storage/app_preferences.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -43,19 +44,24 @@ class _AccountsScreenState extends ConsumerState<AccountsScreen> {
children: [
if (googleAccount != null)
AccountsTab(
name: googleAccount.displayName ?? "Anonymous",
name: googleAccount.displayName ?? googleAccount.email,
serviceDescription: context.l10n.common_google_drive,
profileImage: googleAccount.photoUrl,
actionList: ActionList(buttons: [
ActionListButton(
title: context.l10n.common_auto_back_up,
trailing: Consumer(
builder: (context, ref, child) {
final autoBackUp = ref.watch(accountsStateNotifierProvider
.select((value) => value.autoBackUp));
final googleDriveAutoBackUp = ref
.watch(AppPreferences.canTakeAutoBackUpInGoogleDrive);
return AppSwitch(
value: autoBackUp,
onChanged: notifier.setAutoBackUp,
value: googleDriveAutoBackUp,
onChanged: (bool value) {
ref
.read(AppPreferences
.canTakeAutoBackUpInGoogleDrive.notifier)
.state = value;
},
);
},
),
Expand Down
25 changes: 17 additions & 8 deletions app/lib/ui/flow/accounts/accounts_screen_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:data/services/auth_service.dart';
import 'package:data/services/device_service.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -17,20 +18,34 @@ final accountsStateNotifierProvider =
class AccountsStateNotifier extends StateNotifier<AccountsState> {
final DeviceService _deviceService;
final AuthService _authService;
StreamSubscription? _googleAccountSubscription;

AccountsStateNotifier(
this._deviceService,
this._authService,
) : super(AccountsState(googleAccount: _authService.user));
) : super(AccountsState(googleAccount: _authService.googleAccount));

Future<void> init() async {
_getAppVersion();
_googleAccountSubscription =
_authService.onGoogleAccountChange.listen((event) {
updateUser(event);
});
}

@override
void dispose() {
_googleAccountSubscription?.cancel();
super.dispose();
}

void updateUser(GoogleSignInAccount? account) {
state = state.copyWith(googleAccount: account);
}

Future<void> signInWithGoogle() async {
try {
await _authService.signInWithGoogle();
state = state.copyWith(googleAccount: _authService.user);
} catch (e) {
state = state.copyWith(error: e);
}
Expand All @@ -39,7 +54,6 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
Future<void> signOutWithGoogle() async {
try {
await _authService.signOutWithGoogle();
state = state.copyWith(googleAccount: _authService.user);
} catch (e) {
state = state.copyWith(error: e);
}
Expand All @@ -49,10 +63,6 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
final version = await _deviceService.version;
state = state.copyWith(version: version);
}

void setAutoBackUp(bool value) {
state = state.copyWith(autoBackUp: value);
}
}

@freezed
Expand All @@ -61,6 +71,5 @@ class AccountsState with _$AccountsState {
String? version,
Object? error,
GoogleSignInAccount? googleAccount,
@Default(false) bool autoBackUp,
}) = _AccountsState;
}
40 changes: 7 additions & 33 deletions app/lib/ui/flow/accounts/accounts_screen_view_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mixin _$AccountsState {
String? get version => throw _privateConstructorUsedError;
Object? get error => throw _privateConstructorUsedError;
GoogleSignInAccount? get googleAccount => throw _privateConstructorUsedError;
bool get autoBackUp => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$AccountsStateCopyWith<AccountsState> get copyWith =>
Expand All @@ -33,10 +32,7 @@ abstract class $AccountsStateCopyWith<$Res> {
_$AccountsStateCopyWithImpl<$Res, AccountsState>;
@useResult
$Res call(
{String? version,
Object? error,
GoogleSignInAccount? googleAccount,
bool autoBackUp});
{String? version, Object? error, GoogleSignInAccount? googleAccount});
}

/// @nodoc
Expand All @@ -55,7 +51,6 @@ class _$AccountsStateCopyWithImpl<$Res, $Val extends AccountsState>
Object? version = freezed,
Object? error = freezed,
Object? googleAccount = freezed,
Object? autoBackUp = null,
}) {
return _then(_value.copyWith(
version: freezed == version
Expand All @@ -67,10 +62,6 @@ class _$AccountsStateCopyWithImpl<$Res, $Val extends AccountsState>
? _value.googleAccount
: googleAccount // ignore: cast_nullable_to_non_nullable
as GoogleSignInAccount?,
autoBackUp: null == autoBackUp
? _value.autoBackUp
: autoBackUp // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
Expand All @@ -84,10 +75,7 @@ abstract class _$$AccountsStateImplCopyWith<$Res>
@override
@useResult
$Res call(
{String? version,
Object? error,
GoogleSignInAccount? googleAccount,
bool autoBackUp});
{String? version, Object? error, GoogleSignInAccount? googleAccount});
}

/// @nodoc
Expand All @@ -104,7 +92,6 @@ class __$$AccountsStateImplCopyWithImpl<$Res>
Object? version = freezed,
Object? error = freezed,
Object? googleAccount = freezed,
Object? autoBackUp = null,
}) {
return _then(_$AccountsStateImpl(
version: freezed == version
Expand All @@ -116,33 +103,25 @@ class __$$AccountsStateImplCopyWithImpl<$Res>
? _value.googleAccount
: googleAccount // ignore: cast_nullable_to_non_nullable
as GoogleSignInAccount?,
autoBackUp: null == autoBackUp
? _value.autoBackUp
: autoBackUp // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}

/// @nodoc
class _$AccountsStateImpl implements _AccountsState {
const _$AccountsStateImpl(
{this.version, this.error, this.googleAccount, this.autoBackUp = false});
const _$AccountsStateImpl({this.version, this.error, this.googleAccount});

@override
final String? version;
@override
final Object? error;
@override
final GoogleSignInAccount? googleAccount;
@override
@JsonKey()
final bool autoBackUp;

@override
String toString() {
return 'AccountsState(version: $version, error: $error, googleAccount: $googleAccount, autoBackUp: $autoBackUp)';
return 'AccountsState(version: $version, error: $error, googleAccount: $googleAccount)';
}

@override
Expand All @@ -153,14 +132,12 @@ class _$AccountsStateImpl implements _AccountsState {
(identical(other.version, version) || other.version == version) &&
const DeepCollectionEquality().equals(other.error, error) &&
(identical(other.googleAccount, googleAccount) ||
other.googleAccount == googleAccount) &&
(identical(other.autoBackUp, autoBackUp) ||
other.autoBackUp == autoBackUp));
other.googleAccount == googleAccount));
}

@override
int get hashCode => Object.hash(runtimeType, version,
const DeepCollectionEquality().hash(error), googleAccount, autoBackUp);
const DeepCollectionEquality().hash(error), googleAccount);

@JsonKey(ignore: true)
@override
Expand All @@ -173,8 +150,7 @@ abstract class _AccountsState implements AccountsState {
const factory _AccountsState(
{final String? version,
final Object? error,
final GoogleSignInAccount? googleAccount,
final bool autoBackUp}) = _$AccountsStateImpl;
final GoogleSignInAccount? googleAccount}) = _$AccountsStateImpl;

@override
String? get version;
Expand All @@ -183,8 +159,6 @@ abstract class _AccountsState implements AccountsState {
@override
GoogleSignInAccount? get googleAccount;
@override
bool get autoBackUp;
@override
@JsonKey(ignore: true)
_$$AccountsStateImplCopyWith<_$AccountsStateImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
6 changes: 5 additions & 1 deletion app/lib/ui/flow/home/components/app_media_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class _AppMediaItemState extends State<AppMediaItem>
height: 12,
width: 12,
),
if (widget.isUploading) const AppCircularProgressIndicator(size: 12),
if (widget.isUploading)
const Padding(
padding: EdgeInsets.all(2),
child: AppCircularProgressIndicator(size: 12),
),
],
),
);
Expand Down
Loading

0 comments on commit 05c379a

Please sign in to comment.