Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mobile): add album preview images in backup selection #14950

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
18 changes: 4 additions & 14 deletions mobile/lib/pages/backup/album_preview.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/album.entity.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/extensions/theme_extensions.dart';
import 'package:immich_mobile/repositories/album_media.repository.dart';
import 'package:immich_mobile/widgets/common/immich_thumbnail.dart';

Expand All @@ -19,9 +17,12 @@ class AlbumPreviewPage extends HookConsumerWidget {
final assets = useState<List<Asset>>([]);

getAssetsInAlbum() async {
assets.value = await ref
final results = await ref
.read(albumMediaRepositoryProvider)
.getAssets(album.localId!);
if (context.mounted) {
assets.value = results;
}
}

useEffect(
Expand All @@ -41,17 +42,6 @@ class AlbumPreviewPage extends HookConsumerWidget {
album.name,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Text(
"ID ${album.id}",
style: TextStyle(
fontSize: 10,
color: context.colorScheme.onSurfaceSecondary,
fontWeight: FontWeight.bold,
),
),
),
],
),
leading: IconButton(
Expand Down
75 changes: 30 additions & 45 deletions mobile/lib/pages/backup/backup_album_selection.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import 'package:immich_mobile/providers/album/album.provider.dart';
import 'package:immich_mobile/providers/backup/backup.provider.dart';
import 'package:immich_mobile/services/app_settings.service.dart';
import 'package:immich_mobile/utils/hooks/app_settings_update_hook.dart';
import 'package:immich_mobile/widgets/backup/album_info_card.dart';
import 'package:immich_mobile/widgets/backup/album_info_list_tile.dart';
import 'package:immich_mobile/widgets/backup/album_info_block.dart';
import 'package:immich_mobile/widgets/common/immich_loading_indicator.dart';
import 'package:immich_mobile/widgets/settings/settings_switch_list_tile.dart';

Expand All @@ -33,7 +32,7 @@ class BackupAlbumSelectionPage extends HookConsumerWidget {
[],
);

buildAlbumSelectionList() {
buildAlbumSelection(AlbumInfoBlockMode mode) {
if (albums.isEmpty) {
return const SliverToBoxAdapter(
child: Center(
Expand All @@ -44,43 +43,29 @@ class BackupAlbumSelectionPage extends HookConsumerWidget {

return SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
((context, index) {
return AlbumInfoListTile(
album: albums[index],
);
}),
childCount: albums.length,
),
),
);
}

buildAlbumSelectionGrid() {
if (albums.isEmpty) {
return const SliverToBoxAdapter(
child: Center(
child: ImmichLoadingIndicator(),
),
);
}

return SliverPadding(
padding: const EdgeInsets.all(12.0),
sliver: SliverGrid.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 300,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
),
itemCount: albums.length,
itemBuilder: ((context, index) {
return AlbumInfoCard(
album: albums[index],
);
}),
),
sliver: mode == AlbumInfoBlockMode.grid
? SliverGrid.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 300,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
),
itemCount: albums.length,
itemBuilder: ((context, index) {
return AlbumInfoBlock(
album: albums[index],
mode: AlbumInfoBlockMode.grid,
);
}),
)
: SliverList(
delegate: SliverChildBuilderDelegate(
((context, index) {
return AlbumInfoBlock(album: albums[index], mode: mode);
}),
childCount: albums.length,
),
),
);
}

Expand Down Expand Up @@ -284,11 +269,11 @@ class BackupAlbumSelectionPage extends HookConsumerWidget {
),
SliverLayoutBuilder(
builder: (context, constraints) {
if (constraints.crossAxisExtent > 600) {
return buildAlbumSelectionGrid();
} else {
return buildAlbumSelectionList();
}
return buildAlbumSelection(
constraints.crossAxisExtent > 600
? AlbumInfoBlockMode.grid
: AlbumInfoBlockMode.list,
);
},
),
],
Expand Down
5 changes: 4 additions & 1 deletion mobile/lib/repositories/album_media.repository.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/album.entity.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
Expand All @@ -15,7 +16,9 @@ class AlbumMediaRepository implements IAlbumMediaRepository {
await PhotoManager.getAssetPathList(
hasAll: true,
);
return assetPathEntities.map(_toAlbum).toList();
return assetPathEntities.map(_toAlbum).sortedBy((a) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be sorted from the page that needs the sorted info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't think of any examples where you wouldn't want the album's in a "sane/expected order", hence putting it here. There's no real performance impact (since it's a cheap operation).
Let me know if you disagree and I'll move it.

return a.isAll ? "" : a.name.toLowerCase();
}).toList();
}

@override
Expand Down
Loading
Loading