Skip to content

Commit

Permalink
feat(album): album view sort order (immich-app#14648)
Browse files Browse the repository at this point in the history
* feat(mobile): album view sort order

* feat: add error message

* refactor(mobile): album page (immich-app#14659)

* refactor album page

* update lint rule

* const record

* fix: updating sort order when pull to refresh

---------

Co-authored-by: Alex <[email protected]>

* Move sort toggle button to bottom sheet menu

* chore: revert multiselectgrid loading status

* chore: revert multiselectgrid loading status

---------

Co-authored-by: Mert <[email protected]>
  • Loading branch information
2 people authored and yosit committed Dec 20, 2024
1 parent 5856988 commit 0c39899
Show file tree
Hide file tree
Showing 32 changed files with 711 additions and 336 deletions.
2 changes: 1 addition & 1 deletion mobile/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ custom_lint:
# acceptable exceptions for the time being (until Isar is fully replaced)
- integration_test/test_utils/general_helper.dart
- lib/main.dart
- lib/pages/common/album_asset_selection.page.dart
- lib/pages/album/album_asset_selection.page.dart
- lib/routing/router.dart
- lib/services/immich_logger.service.dart # not really a service... more a util
- lib/utils/{db,migration,renderlist_generator}.dart
Expand Down
2 changes: 2 additions & 0 deletions mobile/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"change_display_order": "Change display order",
"error_change_sort_album": "Failed to change album sort order",
"action_common_back": "Back",
"action_common_cancel": "Cancel",
"action_common_clear": "Clear",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class BackgroundSyncWorker {
result(false)
break
default:
result(FlutterError())
result(FlutterError())
self.complete(UIBackgroundFetchResult.failed)
}
}
Expand Down
4 changes: 4 additions & 0 deletions mobile/lib/constants/enums.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum SortOrder {
asc,
desc,
}
9 changes: 9 additions & 0 deletions mobile/lib/entities/album.entity.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/constants/enums.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/entities/user.entity.dart';
import 'package:immich_mobile/utils/datetime_comparison.dart';
Expand All @@ -23,6 +24,7 @@ class Album {
this.lastModifiedAssetTimestamp,
required this.shared,
required this.activityEnabled,
this.sortOrder = SortOrder.desc,
});

// fields stored in DB
Expand All @@ -39,6 +41,8 @@ class Album {
DateTime? lastModifiedAssetTimestamp;
bool shared;
bool activityEnabled;
@enumerated
SortOrder sortOrder;
final IsarLink<User> owner = IsarLink<User>();
final IsarLink<Asset> thumbnail = IsarLink<Asset>();
final IsarLinks<User> sharedUsers = IsarLinks<User>();
Expand Down Expand Up @@ -154,6 +158,11 @@ class Album {
);
a.remoteAssetCount = dto.assetCount;
a.owner.value = await db.users.getById(dto.ownerId);
if (dto.order != null) {
a.sortOrder =
dto.order == AssetOrder.asc ? SortOrder.asc : SortOrder.desc;
}

if (dto.albumThumbnailAssetId != null) {
a.thumbnail.value = await db.assets
.where()
Expand Down
116 changes: 113 additions & 3 deletions mobile/lib/entities/album.entity.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mobile/lib/interfaces/album_api.interface.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:immich_mobile/constants/enums.dart';
import 'package:immich_mobile/entities/album.entity.dart';

abstract interface class IAlbumApiRepository {
Expand All @@ -17,6 +18,7 @@ abstract interface class IAlbumApiRepository {
String? thumbnailAssetId,
String? description,
bool? activityEnabled,
SortOrder? sortOrder,
});

Future<void> delete(String albumId);
Expand Down
53 changes: 53 additions & 0 deletions mobile/lib/pages/album/album_control_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/providers/album/current_album.provider.dart';
import 'package:immich_mobile/providers/auth.provider.dart';
import 'package:immich_mobile/widgets/album/album_action_filled_button.dart';

// ignore: must_be_immutable
class AlbumControlButton extends ConsumerWidget {
void Function() onAddPhotosPressed;
void Function() onAddUsersPressed;

AlbumControlButton({
super.key,
required this.onAddPhotosPressed,
required this.onAddUsersPressed,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final userId = ref.watch(authProvider).userId;
final isOwner = ref.watch(
currentAlbumProvider.select((album) {
return album?.ownerId == userId;
}),
);

return Padding(
padding: const EdgeInsets.only(left: 16.0, top: 8, bottom: 16),
child: SizedBox(
height: 40,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
AlbumActionFilledButton(
key: const ValueKey('add_photos_button'),
iconData: Icons.add_photo_alternate_outlined,
onPressed: onAddPhotosPressed,
labelText: "share_add_photos".tr(),
),
if (isOwner)
AlbumActionFilledButton(
key: const ValueKey('add_users_button'),
iconData: Icons.person_add_alt_rounded,
onPressed: onAddUsersPressed,
labelText: "album_viewer_page_share_add_users".tr(),
),
],
),
),
);
}
}
61 changes: 61 additions & 0 deletions mobile/lib/pages/album/album_date_range.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/providers/album/current_album.provider.dart';

class AlbumDateRange extends ConsumerWidget {
const AlbumDateRange({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final data = ref.watch(
currentAlbumProvider.select((album) {
if (album == null || album.assets.isEmpty) {
return null;
}

final startDate = album.startDate;
final endDate = album.endDate;
if (startDate == null || endDate == null) {
return null;
}
return (startDate, endDate, album.shared);
}),
);

if (data == null) {
return const SizedBox();
}
final (startDate, endDate, shared) = data;

return Padding(
padding: shared
? const EdgeInsets.only(
left: 16.0,
bottom: 0.0,
)
: const EdgeInsets.only(left: 16.0, bottom: 8.0),
child: Text(
_getDateRangeText(startDate, endDate),
style: context.textTheme.labelLarge,
),
);
}

@pragma('vm:prefer-inline')
String _getDateRangeText(DateTime startDate, DateTime endDate) {
if (startDate.day == endDate.day &&
startDate.month == endDate.month &&
startDate.year == endDate.year) {
return DateFormat.yMMMd().format(startDate);
}

final String startDateText = (startDate.year == endDate.year
? DateFormat.MMMd()
: DateFormat.yMMMd())
.format(startDate);
final String endDateText = DateFormat.yMMMd().format(endDate);
return "$startDateText - $endDateText";
}
}
Loading

0 comments on commit 0c39899

Please sign in to comment.