mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 01:11:36 +03:00
feat(mobile): add option to show asset owner name in asset list
This commit is contained in:
@@ -11,6 +11,7 @@ import 'package:immich_mobile/widgets/asset_grid/asset_grid_data_structure.dart'
|
||||
import 'package:immich_mobile/widgets/asset_grid/immich_asset_grid_view.dart';
|
||||
import 'package:immich_mobile/providers/app_settings.provider.dart';
|
||||
import 'package:immich_mobile/services/app_settings.service.dart';
|
||||
import 'package:immich_mobile/entities/album.entity.dart';
|
||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||
|
||||
@@ -33,6 +34,7 @@ class ImmichAssetGrid extends HookConsumerWidget {
|
||||
final bool showDragScroll;
|
||||
final bool showDragScrollLabel;
|
||||
final bool showStack;
|
||||
final Album? album;
|
||||
|
||||
const ImmichAssetGrid({
|
||||
super.key,
|
||||
@@ -54,6 +56,7 @@ class ImmichAssetGrid extends HookConsumerWidget {
|
||||
this.showDragScroll = true,
|
||||
this.showDragScrollLabel = true,
|
||||
this.showStack = false,
|
||||
this.album,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -115,6 +118,7 @@ class ImmichAssetGrid extends HookConsumerWidget {
|
||||
showDragScroll: showDragScroll,
|
||||
showStack: showStack,
|
||||
showLabel: showDragScrollLabel,
|
||||
album: album,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fluttertoast/fluttertoast.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/utils/hash.dart';
|
||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||
import 'package:immich_mobile/extensions/collection_extensions.dart';
|
||||
import 'package:immich_mobile/extensions/theme_extensions.dart';
|
||||
@@ -55,6 +57,7 @@ class ImmichAssetGridView extends ConsumerStatefulWidget {
|
||||
final bool showDragScroll;
|
||||
final bool showStack;
|
||||
final bool showLabel;
|
||||
final Album? album;
|
||||
|
||||
const ImmichAssetGridView({
|
||||
super.key,
|
||||
@@ -76,6 +79,7 @@ class ImmichAssetGridView extends ConsumerStatefulWidget {
|
||||
this.showDragScroll = true,
|
||||
this.showStack = false,
|
||||
this.showLabel = true,
|
||||
this.album,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -153,6 +157,32 @@ class ImmichAssetGridViewState extends ConsumerState<ImmichAssetGridView> {
|
||||
return widget.selectionActive && assets.firstWhereOrNull((e) => !_selectedAssets.contains(e)) == null;
|
||||
}
|
||||
|
||||
String? _getOwnerName(Asset asset) {
|
||||
final album = widget.album;
|
||||
if (album == null || !album.shared) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Load owner and sharedUsers if not loaded
|
||||
album.owner.loadSync();
|
||||
album.sharedUsers.loadSync();
|
||||
|
||||
// Check if asset owner matches album owner
|
||||
final owner = album.owner.value;
|
||||
if (owner != null && asset.ownerId == fastHash(owner.id)) {
|
||||
return owner.name;
|
||||
}
|
||||
|
||||
// Check shared users
|
||||
for (final user in album.sharedUsers) {
|
||||
if (asset.ownerId == fastHash(user.id)) {
|
||||
return user.name;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _scrollToIndex(int index) async {
|
||||
// if the index is so far down, that the end of the list is reached on the screen
|
||||
// the scroll_position widget crashes. This is a workaround to prevent this.
|
||||
@@ -197,6 +227,7 @@ class ImmichAssetGridViewState extends ConsumerState<ImmichAssetGridView> {
|
||||
ref.read(showControlsProvider.notifier).show = false;
|
||||
}
|
||||
},
|
||||
getOwnerName: _getOwnerName,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -580,6 +611,7 @@ class _Section extends StatelessWidget {
|
||||
final int heroOffset;
|
||||
final bool showStorageIndicator;
|
||||
final void Function(Asset) onAssetTap;
|
||||
final String? Function(Asset)? getOwnerName;
|
||||
|
||||
const _Section({
|
||||
required this.section,
|
||||
@@ -598,6 +630,7 @@ class _Section extends StatelessWidget {
|
||||
required this.heroOffset,
|
||||
required this.showStorageIndicator,
|
||||
required this.onAssetTap,
|
||||
this.getOwnerName,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -651,6 +684,7 @@ class _Section extends StatelessWidget {
|
||||
onSelect: (asset) => selectAssets([asset]),
|
||||
onDeselect: (asset) => deselectAssets([asset]),
|
||||
onAssetTap: onAssetTap,
|
||||
getOwnerName: getOwnerName,
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -730,6 +764,7 @@ class _AssetRow extends StatelessWidget {
|
||||
final void Function(Asset)? onSelect;
|
||||
final void Function(Asset)? onDeselect;
|
||||
final bool isSelectionActive;
|
||||
final String? Function(Asset)? getOwnerName;
|
||||
|
||||
const _AssetRow({
|
||||
super.key,
|
||||
@@ -751,6 +786,7 @@ class _AssetRow extends StatelessWidget {
|
||||
required this.onAssetTap,
|
||||
this.onSelect,
|
||||
this.onDeselect,
|
||||
this.getOwnerName,
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -48,6 +48,7 @@ class MultiselectGrid extends HookConsumerWidget {
|
||||
this.unfavorite = false,
|
||||
this.downloadEnabled = true,
|
||||
this.emptyIndicator,
|
||||
this.album,
|
||||
});
|
||||
|
||||
final ProviderListenable<AsyncValue<RenderList>> renderListProvider;
|
||||
@@ -65,6 +66,7 @@ class MultiselectGrid extends HookConsumerWidget {
|
||||
final bool unfavorite;
|
||||
final bool editEnabled;
|
||||
final Widget? emptyIndicator;
|
||||
final Album? album;
|
||||
Widget buildDefaultLoadingIndicator() => const Center(child: CircularProgressIndicator());
|
||||
|
||||
Widget buildEmptyIndicator() => emptyIndicator ?? Center(child: const Text("no_assets_to_show").tr());
|
||||
@@ -418,6 +420,7 @@ class MultiselectGrid extends HookConsumerWidget {
|
||||
topWidget: topWidget,
|
||||
showStack: stackEnabled,
|
||||
showDragScrollLabel: dragScrollLabelEnabled,
|
||||
album: album,
|
||||
),
|
||||
error: (error, _) => Center(child: Text(error.toString())),
|
||||
loading: buildLoadingIndicator ?? buildDefaultLoadingIndicator,
|
||||
|
||||
@@ -17,6 +17,7 @@ class AssetListSettings extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final showStorageIndicator = useAppSettingsState(AppSettingsEnum.storageIndicator);
|
||||
final showOwnerName = useAppSettingsState(AppSettingsEnum.showOwnerName);
|
||||
|
||||
final assetListSetting = [
|
||||
SettingsSwitchListTile(
|
||||
@@ -27,6 +28,14 @@ class AssetListSettings extends HookConsumerWidget {
|
||||
ref.invalidate(settingsProvider);
|
||||
},
|
||||
),
|
||||
SettingsSwitchListTile(
|
||||
valueNotifier: showOwnerName,
|
||||
title: 'theme_setting_asset_list_show_owner_name_title'.tr(),
|
||||
onChanged: (_) {
|
||||
ref.invalidate(appSettingsServiceProvider);
|
||||
ref.invalidate(settingsProvider);
|
||||
},
|
||||
),
|
||||
const LayoutSettings(),
|
||||
const GroupSettings(),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user