Skip to content

Commit

Permalink
Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Jan 3, 2025
1 parent 3e314dd commit db3077a
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 113 deletions.
25 changes: 25 additions & 0 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: 2 additions & 0 deletions app/lib/components/app_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class AppPage extends StatelessWidget {
: AppBar(
centerTitle: true,
backgroundColor: barBackgroundColor,
scrolledUnderElevation: 0.5,
shadowColor: context.colorScheme.textDisabled,
title: titleWidget ?? _title(context),
actions: [...?actions, const SizedBox(width: 16)],
leading: leading,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/ui/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class _CloudGalleryAppState extends ConsumerState<CloudGalleryApp> {
routes: $appRoutes,
redirect: (context, state) {
if (state.uri.path.contains('/auth')) {
return '/';
return AppRoutePath.accounts;
}
return null;
},
Expand Down
27 changes: 17 additions & 10 deletions app/lib/ui/flow/albums/add/add_album_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:style/buttons/action_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/indicators/circular_progress_indicator.dart';
import 'package:style/text/app_text_field.dart';
import 'package:style/text/app_text_style.dart';
import '../../../../components/app_page.dart';
Expand Down Expand Up @@ -66,16 +67,22 @@ class _AddAlbumScreenState extends ConsumerState<AddAlbumScreen> {
title: context.l10n.add_album_screen_title,
body: _body(context: context, state: state),
actions: [
ActionButton(
onPressed: state.allowSave ? _notifier.createAlbum : null,
icon: Icon(
Icons.check,
size: 24,
color: state.allowSave
? context.colorScheme.textPrimary
: context.colorScheme.textDisabled,
),
),
state.loading
? const SizedBox(
height: 24,
width: 24,
child: AppCircularProgressIndicator(),
)
: ActionButton(
onPressed: state.allowSave ? _notifier.createAlbum : null,
icon: Icon(
Icons.check,
size: 24,
color: state.allowSave
? context.colorScheme.textPrimary
: context.colorScheme.textDisabled,
),
),
],
);
}
Expand Down
2 changes: 2 additions & 0 deletions app/lib/ui/flow/albums/add/add_album_state_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class AddAlbumStateNotifier extends StateNotifier<AddAlbumsState> {
AddAlbumsState(
albumNameController: TextEditingController(text: editAlbum?.name),
mediaSource: editAlbum?.source ?? AppMediaSource.local,
googleAccount: googleAccount,
dropboxAccount: dropboxAccount,
),
);

Expand Down
47 changes: 38 additions & 9 deletions app/lib/ui/flow/albums/albums_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:data/models/media/media.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:style/animations/fade_in_switcher.dart';
import 'package:style/animations/on_tap_scale.dart';
Expand All @@ -18,6 +19,7 @@ import '../../../components/place_holder_screen.dart';
import '../../../components/snack_bar.dart';
import '../../../components/thumbnail_builder.dart';
import '../../../domain/extensions/context_extensions.dart';
import '../../../gen/assets.gen.dart';
import '../../navigation/app_route.dart';
import 'albums_view_notifier.dart';

Expand Down Expand Up @@ -74,7 +76,7 @@ class _AlbumsScreenState extends ConsumerState<AlbumsScreen> {
Widget _body({required BuildContext context}) {
final state = ref.watch(albumStateNotifierProvider);

if (state.loading) {
if (state.loading && state.albums.isEmpty) {
return const Center(child: AppCircularProgressIndicator());
} else if (state.error != null) {
return ErrorScreen(
Expand All @@ -94,21 +96,22 @@ class _AlbumsScreenState extends ConsumerState<AlbumsScreen> {
}

return GridView(
padding: EdgeInsets.all(16),
padding: EdgeInsets.all(8),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.9,
crossAxisSpacing: 16,
crossAxisSpacing: 8,
mainAxisSpacing: 16,
),
children: state.albums
.map(
(album) => AlbumItem(
album: album,
onTap: () {
AlbumMediaListRoute(
onTap: () async {
await AlbumMediaListRoute(
$extra: album,
).push(context);
_notifier.loadAlbums();
},
onLongTap: () {
showAppSheet(
Expand Down Expand Up @@ -204,10 +207,36 @@ class AlbumItem extends StatelessWidget {
),
),
const SizedBox(height: 10),
Text(
album.name,
style: AppTextStyles.subtitle1.copyWith(
color: context.colorScheme.textPrimary,
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
children: [
if (album.source == AppMediaSource.dropbox) ...[
SvgPicture.asset(
Assets.images.icDropbox,
width: 18,
height: 18,
),
const SizedBox(width: 4),
],
if (album.source == AppMediaSource.googleDrive) ...[
SvgPicture.asset(
Assets.images.icGoogleDrive,
width: 18,
height: 18,
),
const SizedBox(width: 4),
],
Expanded(
child: Text(
album.name,
style: AppTextStyles.subtitle1.copyWith(
color: context.colorScheme.textPrimary,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
),
],
Expand Down
7 changes: 6 additions & 1 deletion app/lib/ui/flow/albums/albums_view_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ class AlbumStateNotifier extends StateNotifier<AlbumsState> {
this._logger,
GoogleSignInAccount? googleAccount,
DropboxAccount? dropboxAccount,
) : super(const AlbumsState()) {
) : super(
AlbumsState(
googleAccount: googleAccount,
dropboxAccount: dropboxAccount,
),
) {
loadAlbums();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _AlbumMediaListScreenState extends ConsumerState<AlbumMediaListScreen> {
.push(context);

if (res != null && res is List<String>) {
await _notifier.addMedias(res);
await _notifier.updateAlbumMedias(medias: res);
}
},
icon: Icon(
Expand All @@ -76,7 +76,7 @@ class _AlbumMediaListScreenState extends ConsumerState<AlbumMediaListScreen> {
title: context.l10n.common_edit,
onPressed: () async {
context.pop();
final res = await AddAlbumRoute($extra: widget.album)
final res = await AddAlbumRoute($extra: state.album)
.push(context);
if (res == true) {
await _notifier.reloadAlbum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ class AlbumMediaListStateNotifier extends StateNotifier<AlbumMediaListState> {
}
}

Future<void> addMedias(List<String> medias) async {
Future<void> updateAlbumMedias({
required List<String> medias,
bool append = true,
}) async {
try {
state = state.copyWith(actionError: null);
if (state.album.source == AppMediaSource.local) {
await _localMediaService.updateAlbum(
state.album.copyWith(
medias: [
...state.album.medias,
...medias,
],
medias: append ? [...state.album.medias, ...medias] : medias,
),
);
} else if (state.album.source == AppMediaSource.googleDrive) {
Expand All @@ -132,19 +132,13 @@ class AlbumMediaListStateNotifier extends StateNotifier<AlbumMediaListState> {
await _googleDriveService.updateAlbum(
folderId: _backupFolderId!,
album: state.album.copyWith(
medias: [
...state.album.medias,
...medias,
],
medias: append ? [...state.album.medias, ...medias] : medias,
),
);
} else if (state.album.source == AppMediaSource.dropbox) {
await _dropboxService.updateAlbum(
state.album.copyWith(
medias: [
...state.album.medias,
...medias,
],
medias: append ? [...state.album.medias, ...medias] : medias,
),
);
}
Expand All @@ -160,6 +154,7 @@ class AlbumMediaListStateNotifier extends StateNotifier<AlbumMediaListState> {
}

Future<void> loadMedia({bool reload = false}) async {
///TODO: remove deleted media
try {
if (state.loading) return;

Expand All @@ -175,14 +170,13 @@ class AlbumMediaListStateNotifier extends StateNotifier<AlbumMediaListState> {
final loadedMediaIds = state.medias.map((e) => e.id).toList();
final moreMediaIds = state.album.medias
.where((element) => !loadedMediaIds.contains(element))
.take(30)
.toList();

medias = await Future.wait(
moreMediaIds
.take(moreMediaIds.length > 30 ? 30 : moreMediaIds.length)
.map(
(id) => _localMediaService.getMedia(id: id),
),
moreMediaIds.map(
(id) => _localMediaService.getMedia(id: id),
),
).then(
(value) => value.nonNulls.toList(),
);
Expand All @@ -191,13 +185,12 @@ class AlbumMediaListStateNotifier extends StateNotifier<AlbumMediaListState> {
state.medias.map((e) => e.driveMediaRefId).nonNulls.toList();
final moreMediaIds = state.album.medias
.where((element) => !loadedMediaIds.contains(element))
.take(30)
.toList();
medias = await Future.wait(
moreMediaIds
.take(moreMediaIds.length > 30 ? 30 : moreMediaIds.length)
.map(
(id) => _googleDriveService.getMedia(id: id),
),
moreMediaIds.map(
(id) => _googleDriveService.getMedia(id: id),
),
).then(
(value) => value.nonNulls.toList(),
);
Expand All @@ -206,13 +199,12 @@ class AlbumMediaListStateNotifier extends StateNotifier<AlbumMediaListState> {
state.medias.map((e) => e.dropboxMediaRefId).nonNulls.toList();
final moreMediaIds = state.album.medias
.where((element) => !loadedMediaIds.contains(element))
.take(30)
.toList();
medias = await Future.wait(
moreMediaIds
.take(moreMediaIds.length > 30 ? 30 : moreMediaIds.length)
.map(
(id) => _dropboxService.getMedia(id: id),
),
moreMediaIds.map(
(id) => _dropboxService.getMedia(id: id),
),
).then(
(value) => value.nonNulls.toList(),
);
Expand Down
Loading

0 comments on commit db3077a

Please sign in to comment.