Skip to content

Commit

Permalink
Add storage info to drive info dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Jun 11, 2023
1 parent 822955a commit 5dde4ac
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
47 changes: 28 additions & 19 deletions lib/src/accounts/components/drive_info_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,39 @@ class DriveInfoDialogWidget extends HookConsumerWidget {
title: const Text('Drive info'),
contentPadding: const EdgeInsets.all(24),
children: [
Stack(
children: [
SizedBox(
width: 75,
height: 75,
child: Center(
child: Text(
'${(model.usedStorage / model.remainingStorage * 100).toStringAsFixed(2)} %\nused',
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.w500,
Center(
child: Stack(
children: [
SizedBox(
width: 75,
height: 75,
child: Center(
child: Text(
'${(model.usedStorage / model.remainingStorage * 100).toStringAsFixed(2)} %\nused',
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
),
),
),
SizedBox(
width: 75,
height: 75,
child: CircularProgressIndicator(
value: model.usedStorage / model.remainingStorage,
SizedBox(
width: 75,
height: 75,
child: CircularProgressIndicator(
value: model.usedStorage / model.remainingStorage,
),
),
),
],
],
),
),
// ! Use cards to display
Text(
'Used - ${(model.usedStorage / (1000 * 1000)).toStringAsFixed(0)} MB',
),
Text(
'Remaining - ${(model.remainingStorage / (1000 * 1000)).toStringAsFixed(0)} MB',
)
],
);
}
Expand Down
19 changes: 13 additions & 6 deletions lib/src/accounts/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ final class DropBoxAuth implements AuthService {
options: authOptions,
);

return response.data!;
return Either.tryCatch(
() => FolderInfoModel(
remainingStorage: (response.data!['allocation']['allocated'] as int) -
(response.data!['used'] as int),
usedStorage: response.data!['used']),
(o, s) => o.toString(),
);
}
}

Expand Down Expand Up @@ -222,8 +228,6 @@ final class OneDriveAuth implements AuthService {
email: user['mail'],
name: user['displayName'],
createdAt: DateTime.now().toIso8601String(),
// remainingStorage: drive['quota']['remaining'],
// usedStorage: drive['quota']['used'],
folderId: id,
),
);
Expand Down Expand Up @@ -251,8 +255,6 @@ final class OneDriveAuth implements AuthService {
options: options,
);

// print(response.data!["access_token"]);

return model.copyWith(
accessToken: response.data!['access_token'],
expiresIn: response.data!['expires_in'],
Expand Down Expand Up @@ -291,6 +293,11 @@ final class OneDriveAuth implements AuthService {
options: authOptions,
);

return response.data!;
return Either.tryCatch(
() => FolderInfoModel(
remainingStorage: response.data!['quota']['remaining'],
usedStorage: response.data!['quota']['used']),
(o, s) => o.toString(),
);
}
}
21 changes: 15 additions & 6 deletions lib/src/accounts/views/account_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class AccountView extends ConsumerWidget {
],
),
onTap: () async {
await ref
.watch(authProvider.notifier)
.refresh(e);
// ! Call refresh and drive info in new provider method
final model = switch (e.provider) {
AuthProviderType.oneDrive =>
await OneDriveAuth()
Expand All @@ -111,12 +115,17 @@ class AccountView extends ConsumerWidget {
.getDriveInfo(e.accessToken),
};

await Future.delayed(
Duration.zero,
() => showDialog(
context: context,
builder: (ctx) => DriveInfoDialogWidget(
model: model,
model.match(
(l) => ctx.showErrorSnackBar(
'Error fetching drive information',
),
(r) async => await Future.delayed(
Duration.zero,
() => showDialog(
context: context,
builder: (ctx) => DriveInfoDialogWidget(
model: r,
),
),
),
);
Expand Down

0 comments on commit 5dde4ac

Please sign in to comment.