mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
feat: new create album page
This commit is contained in:
parent
73733370a2
commit
adf7064b2c
@ -11,7 +11,7 @@ enum AlbumUserRole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Model for an album stored in the server
|
// Model for an album stored in the server
|
||||||
class Album {
|
class RemoteAlbum {
|
||||||
final String id;
|
final String id;
|
||||||
final String name;
|
final String name;
|
||||||
final String ownerId;
|
final String ownerId;
|
||||||
@ -24,7 +24,7 @@ class Album {
|
|||||||
final int assetCount;
|
final int assetCount;
|
||||||
final String ownerName;
|
final String ownerName;
|
||||||
|
|
||||||
const Album({
|
const RemoteAlbum({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.ownerId,
|
required this.ownerId,
|
||||||
@ -57,7 +57,7 @@ class Album {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
if (other is! Album) return false;
|
if (other is! RemoteAlbum) return false;
|
||||||
if (identical(this, other)) return true;
|
if (identical(this, other)) return true;
|
||||||
return id == other.id &&
|
return id == other.id &&
|
||||||
name == other.name &&
|
name == other.name &&
|
||||||
|
@ -1,33 +1,35 @@
|
|||||||
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
||||||
import 'package:immich_mobile/infrastructure/repositories/remote_album.repository.dart';
|
import 'package:immich_mobile/infrastructure/repositories/remote_album.repository.dart';
|
||||||
import 'package:immich_mobile/models/albums/album_search.model.dart';
|
import 'package:immich_mobile/models/albums/album_search.model.dart';
|
||||||
|
import 'package:immich_mobile/repositories/album_api.repository.dart';
|
||||||
import 'package:immich_mobile/utils/remote_album.utils.dart';
|
import 'package:immich_mobile/utils/remote_album.utils.dart';
|
||||||
|
|
||||||
class RemoteAlbumService {
|
class RemoteAlbumService {
|
||||||
final DriftRemoteAlbumRepository _repository;
|
final DriftRemoteAlbumRepository _repository;
|
||||||
|
final AlbumApiRepository _albumApiRepository;
|
||||||
|
|
||||||
const RemoteAlbumService(this._repository);
|
const RemoteAlbumService(this._repository, this._albumApiRepository);
|
||||||
|
|
||||||
Future<List<Album>> getAll() {
|
Future<List<RemoteAlbum>> getAll() {
|
||||||
return _repository.getAll();
|
return _repository.getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Album> sortAlbums(
|
List<RemoteAlbum> sortAlbums(
|
||||||
List<Album> albums,
|
List<RemoteAlbum> albums,
|
||||||
RemoteAlbumSortMode sortMode, {
|
RemoteAlbumSortMode sortMode, {
|
||||||
bool isReverse = false,
|
bool isReverse = false,
|
||||||
}) {
|
}) {
|
||||||
return sortMode.sortFn(albums, isReverse);
|
return sortMode.sortFn(albums, isReverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Album> searchAlbums(
|
List<RemoteAlbum> searchAlbums(
|
||||||
List<Album> albums,
|
List<RemoteAlbum> albums,
|
||||||
String query,
|
String query,
|
||||||
String? userId, [
|
String? userId, [
|
||||||
QuickFilterMode filterMode = QuickFilterMode.all,
|
QuickFilterMode filterMode = QuickFilterMode.all,
|
||||||
]) {
|
]) {
|
||||||
final lowerQuery = query.toLowerCase();
|
final lowerQuery = query.toLowerCase();
|
||||||
List<Album> filtered = albums;
|
List<RemoteAlbum> filtered = albums;
|
||||||
|
|
||||||
// Apply text search filter
|
// Apply text search filter
|
||||||
if (query.isNotEmpty) {
|
if (query.isNotEmpty) {
|
||||||
@ -57,4 +59,20 @@ class RemoteAlbumService {
|
|||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<RemoteAlbum> createAlbum({
|
||||||
|
required String title,
|
||||||
|
required List<String> assetIds,
|
||||||
|
String? description,
|
||||||
|
}) async {
|
||||||
|
final album = await _albumApiRepository.createDriftAlbum(
|
||||||
|
title,
|
||||||
|
description: description,
|
||||||
|
assetIds: assetIds,
|
||||||
|
);
|
||||||
|
|
||||||
|
await _repository.create(album);
|
||||||
|
|
||||||
|
return album;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
|
|||||||
final Drift _db;
|
final Drift _db;
|
||||||
const DriftRemoteAlbumRepository(this._db) : super(_db);
|
const DriftRemoteAlbumRepository(this._db) : super(_db);
|
||||||
|
|
||||||
Future<List<Album>> getAll({Set<SortRemoteAlbumsBy> sortBy = const {}}) {
|
Future<List<RemoteAlbum>> getAll({
|
||||||
|
Set<SortRemoteAlbumsBy> sortBy = const {},
|
||||||
|
}) {
|
||||||
final assetCount = _db.remoteAlbumAssetEntity.assetId.count();
|
final assetCount = _db.remoteAlbumAssetEntity.assetId.count();
|
||||||
|
|
||||||
final query = _db.remoteAlbumEntity.select().join([
|
final query = _db.remoteAlbumEntity.select().join([
|
||||||
@ -48,11 +50,27 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
|
|||||||
)
|
)
|
||||||
.get();
|
.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> create(RemoteAlbum album) {
|
||||||
|
final entity = RemoteAlbumEntityCompanion(
|
||||||
|
id: Value(album.id),
|
||||||
|
name: Value(album.name),
|
||||||
|
ownerId: Value(album.ownerId),
|
||||||
|
createdAt: Value(album.createdAt),
|
||||||
|
updatedAt: Value(album.updatedAt),
|
||||||
|
description: Value(album.description),
|
||||||
|
thumbnailAssetId: Value(album.thumbnailAssetId),
|
||||||
|
isActivityEnabled: Value(album.isActivityEnabled),
|
||||||
|
order: Value(album.order),
|
||||||
|
);
|
||||||
|
|
||||||
|
return _db.into(_db.remoteAlbumEntity).insert(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on RemoteAlbumEntityData {
|
extension on RemoteAlbumEntityData {
|
||||||
Album toDto({int assetCount = 0, required String ownerName}) {
|
RemoteAlbum toDto({int assetCount = 0, required String ownerName}) {
|
||||||
return Album(
|
return RemoteAlbum(
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
ownerId: ownerId,
|
ownerId: ownerId,
|
||||||
|
@ -97,7 +97,20 @@ class _DriftAlbumsPageState extends ConsumerState<DriftAlbumsPage> {
|
|||||||
onRefresh: onRefresh,
|
onRefresh: onRefresh,
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
const ImmichSliverAppBar(),
|
ImmichSliverAppBar(
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.add_rounded,
|
||||||
|
size: 28,
|
||||||
|
),
|
||||||
|
onPressed: () => context.pushRoute(
|
||||||
|
DriftCreateAlbumRoute(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
showUploadButton: false,
|
||||||
|
),
|
||||||
_SearchBar(
|
_SearchBar(
|
||||||
searchController: searchController,
|
searchController: searchController,
|
||||||
searchFocusNode: searchFocusNode,
|
searchFocusNode: searchFocusNode,
|
||||||
@ -475,7 +488,7 @@ class _AlbumList extends StatelessWidget {
|
|||||||
|
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
final String? error;
|
final String? error;
|
||||||
final List<Album> albums;
|
final List<RemoteAlbum> albums;
|
||||||
final String? userId;
|
final String? userId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -599,7 +612,7 @@ class _AlbumGrid extends StatelessWidget {
|
|||||||
required this.error,
|
required this.error,
|
||||||
});
|
});
|
||||||
|
|
||||||
final List<Album> albums;
|
final List<RemoteAlbum> albums;
|
||||||
final String? userId;
|
final String? userId;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
final String? error;
|
final String? error;
|
||||||
@ -674,7 +687,7 @@ class _GridAlbumCard extends StatelessWidget {
|
|||||||
required this.userId,
|
required this.userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Album album;
|
final RemoteAlbum album;
|
||||||
final String? userId;
|
final String? userId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
280
mobile/lib/presentation/pages/drift_create_album.page.dart
Normal file
280
mobile/lib/presentation/pages/drift_create_album.page.dart
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||||
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
|
import 'package:immich_mobile/models/albums/asset_selection_page_result.model.dart';
|
||||||
|
import 'package:immich_mobile/providers/album/album.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/album/album_title.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/album/album_viewer.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
|
||||||
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
|
import 'package:immich_mobile/widgets/album/album_action_filled_button.dart';
|
||||||
|
import 'package:immich_mobile/widgets/album/album_title_text_field.dart';
|
||||||
|
import 'package:immich_mobile/widgets/album/album_viewer_editable_description.dart';
|
||||||
|
import 'package:immich_mobile/widgets/album/shared_album_thumbnail_image.dart';
|
||||||
|
|
||||||
|
@RoutePage()
|
||||||
|
class DriftCreateAlbumPage extends HookConsumerWidget {
|
||||||
|
final List<RemoteAsset>? assets;
|
||||||
|
|
||||||
|
const DriftCreateAlbumPage({super.key, this.assets});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final albumTitleController =
|
||||||
|
useTextEditingController.fromValue(TextEditingValue.empty);
|
||||||
|
final albumTitleTextFieldFocusNode = useFocusNode();
|
||||||
|
final albumDescriptionTextFieldFocusNode = useFocusNode();
|
||||||
|
final isAlbumTitleTextFieldFocus = useState(false);
|
||||||
|
final isAlbumTitleEmpty = useState(true);
|
||||||
|
final selectedAssets = useState<Set<RemoteAsset>>(
|
||||||
|
assets != null ? Set.from(assets!) : const {},
|
||||||
|
);
|
||||||
|
|
||||||
|
void onBackgroundTapped() {
|
||||||
|
albumTitleTextFieldFocusNode.unfocus();
|
||||||
|
albumDescriptionTextFieldFocusNode.unfocus();
|
||||||
|
isAlbumTitleTextFieldFocus.value = false;
|
||||||
|
|
||||||
|
if (albumTitleController.text.isEmpty) {
|
||||||
|
albumTitleController.text = 'create_album_page_untitled'.tr();
|
||||||
|
isAlbumTitleEmpty.value = false;
|
||||||
|
ref
|
||||||
|
.watch(albumTitleProvider.notifier)
|
||||||
|
.setAlbumTitle('create_album_page_untitled'.tr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectPhotosButtonPressed() async {
|
||||||
|
// AssetSelectionPageResult? selectedAsset =
|
||||||
|
// await context.pushRoute<AssetSelectionPageResult?>(
|
||||||
|
// AlbumAssetSelectionRoute(
|
||||||
|
// existingAssets: selectedAssets.value,
|
||||||
|
// canDeselect: true,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// if (selectedAsset == null) {
|
||||||
|
// selectedAssets.value = const {};
|
||||||
|
// } else {
|
||||||
|
// selectedAssets.value = selectedAsset.selectedAssets;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTitleInputField() {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
right: 10,
|
||||||
|
left: 10,
|
||||||
|
),
|
||||||
|
child: AlbumTitleTextField(
|
||||||
|
isAlbumTitleEmpty: isAlbumTitleEmpty,
|
||||||
|
albumTitleTextFieldFocusNode: albumTitleTextFieldFocusNode,
|
||||||
|
albumTitleController: albumTitleController,
|
||||||
|
isAlbumTitleTextFieldFocus: isAlbumTitleTextFieldFocus,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
buildDescriptionInputField() {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
right: 10,
|
||||||
|
left: 10,
|
||||||
|
),
|
||||||
|
child: AlbumViewerEditableDescription(
|
||||||
|
albumDescription: '',
|
||||||
|
descriptionFocusNode: albumDescriptionTextFieldFocusNode,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTitle() {
|
||||||
|
if (selectedAssets.value.isEmpty) {
|
||||||
|
return SliverToBoxAdapter(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 200, left: 18),
|
||||||
|
child: Text(
|
||||||
|
'create_shared_album_page_share_add_assets',
|
||||||
|
style: context.textTheme.labelLarge,
|
||||||
|
).tr(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return const SliverToBoxAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
buildSelectPhotosButton() {
|
||||||
|
if (selectedAssets.value.isEmpty) {
|
||||||
|
return SliverToBoxAdapter(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 16, left: 16, right: 16),
|
||||||
|
child: FilledButton.icon(
|
||||||
|
style: FilledButton.styleFrom(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(vertical: 24, horizontal: 16),
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(10),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
backgroundColor: context.colorScheme.surfaceContainerHigh,
|
||||||
|
),
|
||||||
|
onPressed: onSelectPhotosButtonPressed,
|
||||||
|
icon: Icon(
|
||||||
|
Icons.add_rounded,
|
||||||
|
color: context.primaryColor,
|
||||||
|
),
|
||||||
|
label: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8.0),
|
||||||
|
child: Text(
|
||||||
|
'create_shared_album_page_share_select_photos',
|
||||||
|
style: context.textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: context.primaryColor,
|
||||||
|
),
|
||||||
|
).tr(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return const SliverToBoxAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
buildControlButton() {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 12.0, top: 16, bottom: 16),
|
||||||
|
child: SizedBox(
|
||||||
|
height: 42,
|
||||||
|
child: ListView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
children: [
|
||||||
|
AlbumActionFilledButton(
|
||||||
|
iconData: Icons.add_photo_alternate_outlined,
|
||||||
|
onPressed: onSelectPhotosButtonPressed,
|
||||||
|
labelText: "add_photos".tr(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
buildSelectedImageGrid() {
|
||||||
|
// if (selectedAssets.value.isNotEmpty) {
|
||||||
|
// return SliverPadding(
|
||||||
|
// padding: const EdgeInsets.only(top: 16),
|
||||||
|
// sliver: SliverGrid(
|
||||||
|
// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
// crossAxisCount: 3,
|
||||||
|
// crossAxisSpacing: 5.0,
|
||||||
|
// mainAxisSpacing: 5,
|
||||||
|
// ),
|
||||||
|
// delegate: SliverChildBuilderDelegate(
|
||||||
|
// (BuildContext context, int index) {
|
||||||
|
// return GestureDetector(
|
||||||
|
// onTap: onBackgroundTapped,
|
||||||
|
// child: SharedAlbumThumbnailImage(
|
||||||
|
// asset: selectedAssets.value.elementAt(index),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// childCount: selectedAssets.value.length,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
return const SliverToBoxAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> createAlbum() async {
|
||||||
|
onBackgroundTapped();
|
||||||
|
|
||||||
|
final description =
|
||||||
|
ref.read(albumViewerProvider.select((s) => s.editDescriptionText));
|
||||||
|
|
||||||
|
final newAlbum =
|
||||||
|
await ref.watch(remoteAlbumProvider.notifier).createAlbum(
|
||||||
|
title: ref.read(albumTitleProvider),
|
||||||
|
description: description,
|
||||||
|
// selectedAssets.value.map((e) => e.id).toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newAlbum != null) {
|
||||||
|
ref.read(albumProvider.notifier).refreshRemoteAlbums();
|
||||||
|
selectedAssets.value = {};
|
||||||
|
ref.read(albumTitleProvider.notifier).clearAlbumTitle();
|
||||||
|
ref.read(albumViewerProvider.notifier).disableEditAlbum();
|
||||||
|
// context.replaceRoute(AlbumViewerRoute(albumId: newAlbum.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
elevation: 0,
|
||||||
|
centerTitle: false,
|
||||||
|
backgroundColor: context.scaffoldBackgroundColor,
|
||||||
|
leading: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
selectedAssets.value = {};
|
||||||
|
context.maybePop();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.close_rounded),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'create_album',
|
||||||
|
).tr(),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed:
|
||||||
|
albumTitleController.text.isNotEmpty ? createAlbum : null,
|
||||||
|
child: Text(
|
||||||
|
'create'.tr(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: albumTitleController.text.isNotEmpty
|
||||||
|
? context.primaryColor
|
||||||
|
: context.themeData.disabledColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: GestureDetector(
|
||||||
|
onTap: onBackgroundTapped,
|
||||||
|
child: CustomScrollView(
|
||||||
|
slivers: [
|
||||||
|
SliverAppBar(
|
||||||
|
backgroundColor: context.scaffoldBackgroundColor,
|
||||||
|
elevation: 5,
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
pinned: true,
|
||||||
|
floating: false,
|
||||||
|
bottom: PreferredSize(
|
||||||
|
preferredSize: const Size.fromHeight(125.0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
buildTitleInputField(),
|
||||||
|
buildDescriptionInputField(),
|
||||||
|
if (selectedAssets.value.isNotEmpty) buildControlButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
buildTitle(),
|
||||||
|
buildSelectPhotosButton(),
|
||||||
|
buildSelectedImageGrid(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import 'package:immich_mobile/infrastructure/repositories/local_album.repository
|
|||||||
import 'package:immich_mobile/infrastructure/repositories/remote_album.repository.dart';
|
import 'package:immich_mobile/infrastructure/repositories/remote_album.repository.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/db.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/db.provider.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/remote_album.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/remote_album.provider.dart';
|
||||||
|
import 'package:immich_mobile/repositories/album_api.repository.dart';
|
||||||
|
|
||||||
final localAlbumRepository = Provider<DriftLocalAlbumRepository>(
|
final localAlbumRepository = Provider<DriftLocalAlbumRepository>(
|
||||||
(ref) => DriftLocalAlbumRepository(ref.watch(driftProvider)),
|
(ref) => DriftLocalAlbumRepository(ref.watch(driftProvider)),
|
||||||
@ -14,7 +15,10 @@ final remoteAlbumRepository = Provider<DriftRemoteAlbumRepository>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
final remoteAlbumServiceProvider = Provider<RemoteAlbumService>(
|
final remoteAlbumServiceProvider = Provider<RemoteAlbumService>(
|
||||||
(ref) => RemoteAlbumService(ref.watch(remoteAlbumRepository)),
|
(ref) => RemoteAlbumService(
|
||||||
|
ref.watch(remoteAlbumRepository),
|
||||||
|
ref.watch(albumApiRepositoryProvider),
|
||||||
|
),
|
||||||
dependencies: [remoteAlbumRepository],
|
dependencies: [remoteAlbumRepository],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -8,21 +8,21 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|||||||
import 'album.provider.dart';
|
import 'album.provider.dart';
|
||||||
|
|
||||||
class RemoteAlbumState {
|
class RemoteAlbumState {
|
||||||
final List<Album> albums;
|
final List<RemoteAlbum> albums;
|
||||||
final List<Album> filteredAlbums;
|
final List<RemoteAlbum> filteredAlbums;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
final String? error;
|
final String? error;
|
||||||
|
|
||||||
const RemoteAlbumState({
|
const RemoteAlbumState({
|
||||||
required this.albums,
|
required this.albums,
|
||||||
List<Album>? filteredAlbums,
|
List<RemoteAlbum>? filteredAlbums,
|
||||||
this.isLoading = false,
|
this.isLoading = false,
|
||||||
this.error,
|
this.error,
|
||||||
}) : filteredAlbums = filteredAlbums ?? albums;
|
}) : filteredAlbums = filteredAlbums ?? albums;
|
||||||
|
|
||||||
RemoteAlbumState copyWith({
|
RemoteAlbumState copyWith({
|
||||||
List<Album>? albums,
|
List<RemoteAlbum>? albums,
|
||||||
List<Album>? filteredAlbums,
|
List<RemoteAlbum>? filteredAlbums,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
String? error,
|
String? error,
|
||||||
}) {
|
}) {
|
||||||
@ -66,7 +66,7 @@ class RemoteAlbumNotifier extends Notifier<RemoteAlbumState> {
|
|||||||
return const RemoteAlbumState(albums: [], filteredAlbums: []);
|
return const RemoteAlbumState(albums: [], filteredAlbums: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Album>> getAll() async {
|
Future<List<RemoteAlbum>> getAll() async {
|
||||||
state = state.copyWith(isLoading: true, error: null);
|
state = state.copyWith(isLoading: true, error: null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -118,4 +118,31 @@ class RemoteAlbumNotifier extends Notifier<RemoteAlbumState> {
|
|||||||
.sortAlbums(state.filteredAlbums, sortMode, isReverse: isReverse);
|
.sortAlbums(state.filteredAlbums, sortMode, isReverse: isReverse);
|
||||||
state = state.copyWith(filteredAlbums: sortedAlbums);
|
state = state.copyWith(filteredAlbums: sortedAlbums);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<RemoteAlbum?> createAlbum({
|
||||||
|
required String title,
|
||||||
|
String? description,
|
||||||
|
List<String> assetIds = const [],
|
||||||
|
}) async {
|
||||||
|
state = state.copyWith(isLoading: true, error: null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final album = await _remoteAlbumService.createAlbum(
|
||||||
|
title: title,
|
||||||
|
description: description,
|
||||||
|
assetIds: assetIds,
|
||||||
|
);
|
||||||
|
|
||||||
|
state = state.copyWith(
|
||||||
|
albums: [...state.albums, album],
|
||||||
|
filteredAlbums: [...state.filteredAlbums, album],
|
||||||
|
);
|
||||||
|
|
||||||
|
state = state.copyWith(isLoading: false);
|
||||||
|
return album;
|
||||||
|
} catch (e) {
|
||||||
|
state = state.copyWith(isLoading: false, error: e.toString());
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/constants/enums.dart';
|
import 'package:immich_mobile/constants/enums.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/album/album.model.dart'
|
||||||
|
show AlbumAssetOrder, RemoteAlbum;
|
||||||
import 'package:immich_mobile/entities/album.entity.dart';
|
import 'package:immich_mobile/entities/album.entity.dart';
|
||||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||||
import 'package:immich_mobile/infrastructure/entities/user.entity.dart'
|
import 'package:immich_mobile/infrastructure/entities/user.entity.dart'
|
||||||
@ -50,6 +52,25 @@ class AlbumApiRepository extends ApiRepository {
|
|||||||
return _toAlbum(responseDto);
|
return _toAlbum(responseDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Change name after removing old method
|
||||||
|
Future<RemoteAlbum> createDriftAlbum(
|
||||||
|
String name, {
|
||||||
|
required Iterable<String> assetIds,
|
||||||
|
String? description,
|
||||||
|
}) async {
|
||||||
|
final responseDto = await checkNull(
|
||||||
|
_api.createAlbum(
|
||||||
|
CreateAlbumDto(
|
||||||
|
albumName: name,
|
||||||
|
description: description,
|
||||||
|
assetIds: assetIds.toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return _toRemoteAlbum(responseDto);
|
||||||
|
}
|
||||||
|
|
||||||
Future<Album> update(
|
Future<Album> update(
|
||||||
String albumId, {
|
String albumId, {
|
||||||
String? name,
|
String? name,
|
||||||
@ -170,4 +191,22 @@ class AlbumApiRepository extends ApiRepository {
|
|||||||
|
|
||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RemoteAlbum _toRemoteAlbum(AlbumResponseDto dto) {
|
||||||
|
return RemoteAlbum(
|
||||||
|
id: dto.id,
|
||||||
|
name: dto.albumName,
|
||||||
|
ownerId: dto.owner.id,
|
||||||
|
description: dto.description,
|
||||||
|
createdAt: dto.createdAt,
|
||||||
|
updatedAt: dto.updatedAt,
|
||||||
|
thumbnailAssetId: dto.albumThumbnailAssetId,
|
||||||
|
isActivityEnabled: dto.isActivityEnabled,
|
||||||
|
order: dto.order == AssetOrder.asc
|
||||||
|
? AlbumAssetOrder.asc
|
||||||
|
: AlbumAssetOrder.desc,
|
||||||
|
assetCount: dto.assetCount,
|
||||||
|
ownerName: dto.owner.name,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
import 'package:immich_mobile/domain/models/log.model.dart';
|
import 'package:immich_mobile/domain/models/log.model.dart';
|
||||||
import 'package:immich_mobile/domain/models/memory.model.dart';
|
import 'package:immich_mobile/domain/models/memory.model.dart';
|
||||||
import 'package:immich_mobile/domain/models/user.model.dart';
|
import 'package:immich_mobile/domain/models/user.model.dart';
|
||||||
@ -72,6 +73,7 @@ import 'package:immich_mobile/presentation/pages/dev/main_timeline.page.dart';
|
|||||||
import 'package:immich_mobile/presentation/pages/dev/media_stat.page.dart';
|
import 'package:immich_mobile/presentation/pages/dev/media_stat.page.dart';
|
||||||
import 'package:immich_mobile/presentation/pages/dev/remote_timeline.page.dart';
|
import 'package:immich_mobile/presentation/pages/dev/remote_timeline.page.dart';
|
||||||
import 'package:immich_mobile/presentation/pages/drift_album.page.dart';
|
import 'package:immich_mobile/presentation/pages/drift_album.page.dart';
|
||||||
|
import 'package:immich_mobile/presentation/pages/drift_create_album.page.dart';
|
||||||
import 'package:immich_mobile/presentation/pages/drift_memory.page.dart';
|
import 'package:immich_mobile/presentation/pages/drift_memory.page.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.page.dart';
|
import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.page.dart';
|
||||||
import 'package:immich_mobile/providers/api.provider.dart';
|
import 'package:immich_mobile/providers/api.provider.dart';
|
||||||
@ -392,6 +394,10 @@ class AppRouter extends RootStackRouter {
|
|||||||
page: DriftMemoryRoute.page,
|
page: DriftMemoryRoute.page,
|
||||||
guards: [_authGuard, _duplicateGuard],
|
guards: [_authGuard, _duplicateGuard],
|
||||||
),
|
),
|
||||||
|
AutoRoute(
|
||||||
|
page: DriftCreateAlbumRoute.page,
|
||||||
|
guards: [_authGuard, _duplicateGuard],
|
||||||
|
),
|
||||||
|
|
||||||
// required to handle all deeplinks in deep_link.service.dart
|
// required to handle all deeplinks in deep_link.service.dart
|
||||||
// auto_route_library#1722
|
// auto_route_library#1722
|
||||||
|
@ -618,6 +618,45 @@ class DriftAlbumsRoute extends PageRouteInfo<void> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// generated route for
|
||||||
|
/// [DriftCreateAlbumPage]
|
||||||
|
class DriftCreateAlbumRoute extends PageRouteInfo<DriftCreateAlbumRouteArgs> {
|
||||||
|
DriftCreateAlbumRoute({
|
||||||
|
Key? key,
|
||||||
|
List<RemoteAsset>? assets,
|
||||||
|
List<PageRouteInfo>? children,
|
||||||
|
}) : super(
|
||||||
|
DriftCreateAlbumRoute.name,
|
||||||
|
args: DriftCreateAlbumRouteArgs(key: key, assets: assets),
|
||||||
|
initialChildren: children,
|
||||||
|
);
|
||||||
|
|
||||||
|
static const String name = 'DriftCreateAlbumRoute';
|
||||||
|
|
||||||
|
static PageInfo page = PageInfo(
|
||||||
|
name,
|
||||||
|
builder: (data) {
|
||||||
|
final args = data.argsAs<DriftCreateAlbumRouteArgs>(
|
||||||
|
orElse: () => const DriftCreateAlbumRouteArgs(),
|
||||||
|
);
|
||||||
|
return DriftCreateAlbumPage(key: args.key, assets: args.assets);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DriftCreateAlbumRouteArgs {
|
||||||
|
const DriftCreateAlbumRouteArgs({this.key, this.assets});
|
||||||
|
|
||||||
|
final Key? key;
|
||||||
|
|
||||||
|
final List<RemoteAsset>? assets;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'DriftCreateAlbumRouteArgs{key: $key, assets: $assets}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// generated route for
|
/// generated route for
|
||||||
/// [DriftMemoryPage]
|
/// [DriftMemoryPage]
|
||||||
class DriftMemoryRoute extends PageRouteInfo<DriftMemoryRouteArgs> {
|
class DriftMemoryRoute extends PageRouteInfo<DriftMemoryRouteArgs> {
|
||||||
|
@ -1,38 +1,56 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
||||||
|
|
||||||
typedef AlbumSortFn = List<Album> Function(List<Album> albums, bool isReverse);
|
typedef AlbumSortFn = List<RemoteAlbum> Function(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
);
|
||||||
|
|
||||||
class _RemoteAlbumSortHandlers {
|
class _RemoteAlbumSortHandlers {
|
||||||
const _RemoteAlbumSortHandlers._();
|
const _RemoteAlbumSortHandlers._();
|
||||||
|
|
||||||
static const AlbumSortFn created = _sortByCreated;
|
static const AlbumSortFn created = _sortByCreated;
|
||||||
static List<Album> _sortByCreated(List<Album> albums, bool isReverse) {
|
static List<RemoteAlbum> _sortByCreated(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
) {
|
||||||
final sorted = albums.sortedBy((album) => album.createdAt);
|
final sorted = albums.sortedBy((album) => album.createdAt);
|
||||||
return (isReverse ? sorted.reversed : sorted).toList();
|
return (isReverse ? sorted.reversed : sorted).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AlbumSortFn title = _sortByTitle;
|
static const AlbumSortFn title = _sortByTitle;
|
||||||
static List<Album> _sortByTitle(List<Album> albums, bool isReverse) {
|
static List<RemoteAlbum> _sortByTitle(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
) {
|
||||||
final sorted = albums.sortedBy((album) => album.name);
|
final sorted = albums.sortedBy((album) => album.name);
|
||||||
return (isReverse ? sorted.reversed : sorted).toList();
|
return (isReverse ? sorted.reversed : sorted).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AlbumSortFn lastModified = _sortByLastModified;
|
static const AlbumSortFn lastModified = _sortByLastModified;
|
||||||
static List<Album> _sortByLastModified(List<Album> albums, bool isReverse) {
|
static List<RemoteAlbum> _sortByLastModified(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
) {
|
||||||
final sorted = albums.sortedBy((album) => album.updatedAt);
|
final sorted = albums.sortedBy((album) => album.updatedAt);
|
||||||
return (isReverse ? sorted.reversed : sorted).toList();
|
return (isReverse ? sorted.reversed : sorted).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AlbumSortFn assetCount = _sortByAssetCount;
|
static const AlbumSortFn assetCount = _sortByAssetCount;
|
||||||
static List<Album> _sortByAssetCount(List<Album> albums, bool isReverse) {
|
static List<RemoteAlbum> _sortByAssetCount(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
) {
|
||||||
final sorted =
|
final sorted =
|
||||||
albums.sorted((a, b) => a.assetCount.compareTo(b.assetCount));
|
albums.sorted((a, b) => a.assetCount.compareTo(b.assetCount));
|
||||||
return (isReverse ? sorted.reversed : sorted).toList();
|
return (isReverse ? sorted.reversed : sorted).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AlbumSortFn mostRecent = _sortByMostRecent;
|
static const AlbumSortFn mostRecent = _sortByMostRecent;
|
||||||
static List<Album> _sortByMostRecent(List<Album> albums, bool isReverse) {
|
static List<RemoteAlbum> _sortByMostRecent(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
) {
|
||||||
final sorted = albums.sorted((a, b) {
|
final sorted = albums.sorted((a, b) {
|
||||||
// For most recent, we sort by updatedAt in descending order
|
// For most recent, we sort by updatedAt in descending order
|
||||||
return b.updatedAt.compareTo(a.updatedAt);
|
return b.updatedAt.compareTo(a.updatedAt);
|
||||||
@ -41,7 +59,10 @@ class _RemoteAlbumSortHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const AlbumSortFn mostOldest = _sortByMostOldest;
|
static const AlbumSortFn mostOldest = _sortByMostOldest;
|
||||||
static List<Album> _sortByMostOldest(List<Album> albums, bool isReverse) {
|
static List<RemoteAlbum> _sortByMostOldest(
|
||||||
|
List<RemoteAlbum> albums,
|
||||||
|
bool isReverse,
|
||||||
|
) {
|
||||||
final sorted = albums.sorted((a, b) {
|
final sorted = albums.sorted((a, b) {
|
||||||
// For oldest, we sort by createdAt in ascending order
|
// For oldest, we sort by createdAt in ascending order
|
||||||
return a.createdAt.compareTo(b.createdAt);
|
return a.createdAt.compareTo(b.createdAt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user