Skip to content

Commit

Permalink
Account Ui Improvement (#76)
Browse files Browse the repository at this point in the history
* Account Ui Improvement

* Fix rate us on ios

* Fix rate us on ios

* Fix notification permission error on ios

* Fix notification permission error on ios

* FIx lint
  • Loading branch information
cp-pratik-k authored Dec 18, 2024
1 parent ac3ff37 commit fb84e50
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 143 deletions.
1 change: 0 additions & 1 deletion app/lib/ui/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class _CloudGalleryAppState extends ConsumerState<CloudGalleryApp> {
if (res?.didNotificationLaunchApp == true) {
///TODO: manage notification tap
}
_notificationHandler.requestPermission();
}

@override
Expand Down
132 changes: 64 additions & 68 deletions app/lib/ui/flow/accounts/accounts_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,47 +108,45 @@ class _AccountsScreenState extends ConsumerState<AccountsScreen>
serviceDescription:
"${context.l10n.common_google_drive} - ${googleAccount.email}",
profileImage: googleAccount.photoUrl,
actionList: ActionList(
buttons: [
ActionListButton(
leading: Icon(
CupertinoIcons.arrow_2_circlepath,
color: context.colorScheme.textPrimary,
size: 22,
),
title: context.l10n.auto_back_up_title,
trailing: Consumer(
builder: (context, ref, child) {
final googleDriveAutoBackUp =
ref.watch(AppPreferences.googleDriveAutoBackUp);
return AppSwitch(
value: googleDriveAutoBackUp,
onChanged: notifier.toggleAutoBackupInGoogleDrive,
);
},
),
actions: [
ActionListItem(
leading: Icon(
CupertinoIcons.arrow_2_circlepath,
color: context.colorScheme.textPrimary,
size: 22,
),
title: context.l10n.auto_back_up_title,
trailing: Consumer(
builder: (context, ref, child) {
final googleDriveAutoBackUp =
ref.watch(AppPreferences.googleDriveAutoBackUp);
return AppSwitch(
value: googleDriveAutoBackUp,
onChanged: notifier.toggleAutoBackupInGoogleDrive,
);
},
),
ActionListButton(
leading: SvgPicture.asset(
Assets.images.icLogout,
height: 22,
width: 22,
colorFilter: ColorFilter.mode(
context.colorScheme.textPrimary,
BlendMode.srcATop,
),
),
ActionListItem(
leading: SvgPicture.asset(
Assets.images.icLogout,
height: 22,
width: 22,
colorFilter: ColorFilter.mode(
context.colorScheme.textPrimary,
BlendMode.srcATop,
),
title: context.l10n.sign_out_title,
onPressed: notifier.signOutWithGoogle,
),
],
),
backgroundColor: AppColors.googleDriveColor.withAlpha(50),
title: context.l10n.sign_out_title,
onPressed: notifier.signOutWithGoogle,
),
],
backgroundColor: AppColors.googleDriveColor,
);
}
return ActionList(
buttons: [
ActionListButton(
ActionListItem(
leading: SvgPicture.asset(
Assets.images.icGoogleDrive,
height: 22,
Expand Down Expand Up @@ -176,47 +174,45 @@ class _AccountsScreenState extends ConsumerState<AccountsScreen>
serviceDescription:
"${context.l10n.common_dropbox} - ${dropboxAccount.email}",
profileImage: dropboxAccount.profile_photo_url,
actionList: ActionList(
buttons: [
ActionListButton(
leading: Icon(
CupertinoIcons.arrow_2_circlepath,
color: context.colorScheme.textPrimary,
size: 22,
),
title: context.l10n.auto_back_up_title,
trailing: Consumer(
builder: (context, ref, child) {
final dropboxAutoBackUp =
ref.watch(AppPreferences.dropboxAutoBackUp);
return AppSwitch(
value: dropboxAutoBackUp,
onChanged: notifier.toggleAutoBackupInDropbox,
);
},
),
actions: [
ActionListItem(
leading: Icon(
CupertinoIcons.arrow_2_circlepath,
color: context.colorScheme.textPrimary,
size: 22,
),
title: context.l10n.auto_back_up_title,
trailing: Consumer(
builder: (context, ref, child) {
final dropboxAutoBackUp =
ref.watch(AppPreferences.dropboxAutoBackUp);
return AppSwitch(
value: dropboxAutoBackUp,
onChanged: notifier.toggleAutoBackupInDropbox,
);
},
),
ActionListButton(
leading: SvgPicture.asset(
Assets.images.icLogout,
height: 22,
width: 22,
colorFilter: ColorFilter.mode(
context.colorScheme.textPrimary,
BlendMode.srcATop,
),
),
ActionListItem(
leading: SvgPicture.asset(
Assets.images.icLogout,
height: 22,
width: 22,
colorFilter: ColorFilter.mode(
context.colorScheme.textPrimary,
BlendMode.srcATop,
),
title: context.l10n.sign_out_title,
onPressed: notifier.signOutWithDropbox,
),
],
),
backgroundColor: AppColors.dropBoxColor.withAlpha(50),
title: context.l10n.sign_out_title,
onPressed: notifier.signOutWithDropbox,
),
],
backgroundColor: AppColors.dropBoxColor,
);
}
return ActionList(
buttons: [
ActionListButton(
ActionListItem(
leading: SvgPicture.asset(
Assets.images.icDropbox,
height: 22,
Expand Down
72 changes: 58 additions & 14 deletions app/lib/ui/flow/accounts/accounts_screen_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:async';
import 'dart:io';
import 'package:data/handlers/notification_handler.dart';
import 'package:data/log/logger.dart';
import 'package:data/models/media_process/media_process.dart';
import 'package:data/repositories/media_process_repository.dart';
import 'package:data/services/auth_service.dart';
Expand All @@ -9,6 +11,7 @@ import 'package:data/storage/provider/preferences_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:logger/logger.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

Expand All @@ -22,6 +25,8 @@ final accountsStateNotifierProvider =
ref.read(AppPreferences.dropboxAutoBackUp.notifier),
ref.read(AppPreferences.googleDriveAutoBackUp.notifier),
ref.read(mediaProcessRepoProvider),
ref.read(notificationHandlerProvider),
ref.read(loggerProvider),
),
);

Expand All @@ -31,6 +36,8 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
final PreferenceNotifier<bool?> _autoBackupInGoogleDriveController;
final PreferenceNotifier<bool?> _autoBackupInDropboxController;
final MediaProcessRepo _mediaProcessRepo;
final NotificationHandler _notificationHandler;
final Logger _logger;
StreamSubscription? _googleAccountSubscription;

AccountsStateNotifier(
Expand All @@ -39,6 +46,8 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
this._autoBackupInDropboxController,
this._autoBackupInGoogleDriveController,
this._mediaProcessRepo,
this._notificationHandler,
this._logger,
) : super(AccountsState(googleAccount: _authService.googleAccount)) {
init();
updateNotificationsPermissionStatus();
Expand All @@ -63,16 +72,22 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
}) async {
try {
state = state.copyWith(error: null);
PermissionStatus status = await Permission.notification.request();
if ((status.isDenied || status.isPermanentlyDenied) &&
openSettingsIfPermanentlyDenied) {
bool isNotificationEnabled =
await _notificationHandler.checkPermissionIsEnabled() ?? false;
if (!isNotificationEnabled && openSettingsIfPermanentlyDenied) {
await openAppSettings();
status = await Permission.notification.request();
isNotificationEnabled =
await _notificationHandler.checkPermissionIsEnabled() ?? false;
}

state = state.copyWith(notificationsPermissionStatus: status.isGranted);
} catch (e) {
state =
state.copyWith(notificationsPermissionStatus: isNotificationEnabled);
} catch (e, s) {
state = state.copyWith(error: e);
_logger.e(
"AccountsStateNotifier: unable to request permission",
error: e,
stackTrace: s,
);
}
}

Expand All @@ -88,19 +103,28 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
await file.delete();
}
}
await Future.delayed(const Duration(seconds: 1));
state = state.copyWith(clearCacheLoading: false);
} catch (e) {
} catch (e, s) {
state = state.copyWith(error: e, clearCacheLoading: false);
_logger.e(
"AccountsStateNotifier: unable to clear cache",
error: e,
stackTrace: s,
);
}
}

Future<void> rateUs() async {
try {
state = state.copyWith(error: null);
await _deviceService.rateApp();
} catch (e) {
} catch (e, s) {
state = state.copyWith(error: e);
_logger.e(
"AccountsStateNotifier: unable to rate app",
error: e,
stackTrace: s,
);
}
}

Expand All @@ -112,8 +136,13 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
try {
state = state.copyWith(error: null);
await _authService.signInWithGoogle();
} catch (e) {
} catch (e, s) {
state = state.copyWith(error: e);
_logger.e(
"AccountsStateNotifier: unable to sign in with google",
error: e,
stackTrace: s,
);
}
}

Expand All @@ -123,17 +152,27 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
_mediaProcessRepo
.removeAllWaitingUploadsOfProvider(MediaProvider.googleDrive);
await _authService.signOutWithGoogle();
} catch (e) {
} catch (e, s) {
state = state.copyWith(error: e);
_logger.e(
"AccountsStateNotifier: unable to sign out with google",
error: e,
stackTrace: s,
);
}
}

Future<void> signInWithDropbox() async {
try {
state = state.copyWith(error: null);
await _authService.signInWithDropBox();
} catch (e) {
} catch (e, s) {
state = state.copyWith(error: e);
_logger.e(
"AccountsStateNotifier: unable to sign in with dropbox",
error: e,
stackTrace: s,
);
}
}

Expand All @@ -143,8 +182,13 @@ class AccountsStateNotifier extends StateNotifier<AccountsState> {
_mediaProcessRepo
.removeAllWaitingUploadsOfProvider(MediaProvider.dropbox);
await _authService.signOutWithDropBox();
} catch (e) {
} catch (e, s) {
state = state.copyWith(error: e);
_logger.e(
"AccountsStateNotifier: unable to sign out with dropbox",
error: e,
stackTrace: s,
);
}
}

Expand Down
Loading

0 comments on commit fb84e50

Please sign in to comment.