feat(mobile): add option to show asset owner name in asset list

This commit is contained in:
idubnori
2025-12-06 23:08:37 +09:00
parent 8416397589
commit f13a5ba418
13 changed files with 136 additions and 2 deletions

View File

@@ -2062,6 +2062,7 @@
"theme": "Theme",
"theme_selection": "Theme selection",
"theme_selection_description": "Automatically set the theme to light or dark based on your browser's system preference",
"theme_setting_asset_list_show_owner_name_title": "Show asset owner name",
"theme_setting_asset_list_storage_indicator_title": "Show storage indicator on asset tiles",
"theme_setting_asset_list_tiles_per_row_title": "Number of assets per row ({count})",
"theme_setting_colorful_interface_subtitle": "Apply primary color to background surfaces.",

View File

@@ -2022,6 +2022,7 @@
"theme": "テーマ",
"theme_selection": "テーマ選択",
"theme_selection_description": "ブラウザのシステム設定に基づいてテーマを明色または暗色に自動的に設定します",
"theme_setting_asset_list_show_owner_name_title": "アセット所有者名を表示",
"theme_setting_asset_list_storage_indicator_title": "ストレージに関する情報を表示",
"theme_setting_asset_list_tiles_per_row_title": "一行ごとの表示枚数: {count}",
"theme_setting_colorful_interface_subtitle": "アクセントカラーを背景にも使用する",

View File

@@ -9,7 +9,8 @@ enum Setting<T> {
autoPlayVideo<bool>(StoreKey.autoPlayVideo, true),
preferRemoteImage<bool>(StoreKey.preferRemoteImage, false),
advancedTroubleshooting<bool>(StoreKey.advancedTroubleshooting, false),
enableBackup<bool>(StoreKey.enableBackup, false);
enableBackup<bool>(StoreKey.enableBackup, false),
showOwnerName<bool>(StoreKey.showOwnerName, false);
const Setting(this.storeKey, this.defaultValue);

View File

@@ -72,6 +72,7 @@ enum StoreKey<T> {
autoPlayVideo<bool>._(139),
albumGridView<bool>._(140),
showOwnerName<bool>._(141),
// Experimental stuff
photoManagerCustomFilter<bool>._(1000),

View File

@@ -169,6 +169,10 @@ class Asset {
@Enumerated(EnumType.ordinal)
AssetVisibilityEnum visibility;
/// Transient field for storing owner name (used in shared albums)
@ignore
String? ownerName;
/// Returns null if the asset has no sync access to the exif info
@ignore
double? get aspectRatio {

View File

@@ -104,6 +104,7 @@ class AlbumViewer extends HookConsumerWidget {
MultiselectGrid(
key: const ValueKey("albumViewerMultiselectGrid"),
renderListProvider: albumTimelineProvider(album.id),
album: album,
topWidget: Container(
decoration: BoxDecoration(
gradient: LinearGradient(

View File

@@ -19,6 +19,7 @@ class ThumbnailTile extends ConsumerWidget {
this.showStorageIndicator = false,
this.lockSelection = false,
this.heroOffset,
this.ownerName,
super.key,
});
@@ -28,6 +29,7 @@ class ThumbnailTile extends ConsumerWidget {
final bool showStorageIndicator;
final bool lockSelection;
final int? heroOffset;
final String? ownerName;
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -45,6 +47,9 @@ class ThumbnailTile extends ConsumerWidget {
final bool storageIndicator =
ref.watch(settingsProvider.select((s) => s.get(Setting.showStorageIndicator))) && showStorageIndicator;
final bool showOwnerNameSetting = ref.watch(settingsProvider.select((s) => s.get(Setting.showOwnerName)));
final shouldShowOwnerName = showOwnerNameSetting && ownerName != null;
return Stack(
children: [
Container(color: lockSelection ? context.colorScheme.surfaceContainerHighest : assetContainerColor),
@@ -72,6 +77,14 @@ class ThumbnailTile extends ConsumerWidget {
alignment: Alignment.topRight,
child: _AssetTypeIcons(asset: asset),
),
if (shouldShowOwnerName)
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(right: 10.0, bottom: 6.0),
child: _OwnerNameLabel(ownerName: ownerName!),
),
),
if (storageIndicator && asset != null)
switch (asset.storage) {
AssetState.local => const Align(
@@ -229,3 +242,27 @@ class _AssetTypeIcons extends StatelessWidget {
);
}
}
class _OwnerNameLabel extends StatelessWidget {
final String ownerName;
const _OwnerNameLabel({required this.ownerName});
@override
Widget build(BuildContext context) {
return Container(
constraints: const BoxConstraints(maxWidth: 120),
child: Text(
ownerName,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w600,
shadows: [Shadow(blurRadius: 5.0, color: Color.fromRGBO(0, 0, 0, 0.6), offset: Offset(0.0, 0.0))],
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
);
}
}

View File

@@ -18,6 +18,7 @@ import 'package:immich_mobile/providers/asset_viewer/is_motion_video_playing.pro
import 'package:immich_mobile/providers/haptic_feedback.provider.dart';
import 'package:immich_mobile/providers/infrastructure/current_album.provider.dart';
import 'package:immich_mobile/providers/infrastructure/readonly_mode.provider.dart';
import 'package:immich_mobile/providers/infrastructure/remote_album.provider.dart';
import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart';
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
import 'package:immich_mobile/routing/router.dart';
@@ -191,6 +192,38 @@ class _AssetTileWidget extends ConsumerWidget {
return lockSelectionAssets.contains(asset);
}
String? _getOwnerName(WidgetRef ref) {
final album = ref.watch(currentRemoteAlbumProvider);
if (album == null || !album.isShared) {
return null;
}
if (asset case RemoteAsset remoteAsset) {
final ownerId = remoteAsset.ownerId;
// If owner matches album owner
if (album.ownerId == ownerId) {
return album.ownerName;
}
// Check shared users
final sharedUsersAsync = ref.watch(remoteAlbumSharedUsersProvider(album.id));
return sharedUsersAsync.maybeWhen(
data: (sharedUsers) {
for (final user in sharedUsers) {
if (user.id == ownerId) {
return user.name;
}
}
return null;
},
orElse: () => null,
);
}
return null;
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final heroOffset = TabsRouterScope.of(context)?.controller.activeIndex ?? 0;
@@ -198,6 +231,7 @@ class _AssetTileWidget extends ConsumerWidget {
final lockSelection = _getLockSelectionStatus(ref);
final showStorageIndicator = ref.watch(timelineArgsProvider.select((args) => args.showStorageIndicator));
final isReadonlyModeEnabled = ref.watch(readonlyModeProvider);
final ownerName = _getOwnerName(ref);
return RepaintBoundary(
child: GestureDetector(
@@ -208,6 +242,7 @@ class _AssetTileWidget extends ConsumerWidget {
lockSelection: lockSelection,
showStorageIndicator: showStorageIndicator,
heroOffset: heroOffset,
ownerName: ownerName,
),
),
);

View File

@@ -54,7 +54,8 @@ enum AppSettingsEnum<T> {
readonlyModeEnabled<bool>(StoreKey.readonlyModeEnabled, "readonlyModeEnabled", false),
albumGridView<bool>(StoreKey.albumGridView, "albumGridView", false),
backupRequireCharging<bool>(StoreKey.backupRequireCharging, null, false),
backupTriggerDelay<int>(StoreKey.backupTriggerDelay, null, 30);
backupTriggerDelay<int>(StoreKey.backupTriggerDelay, null, 30),
showOwnerName<bool>(StoreKey.showOwnerName, "showOwnerName", false);
const AppSettingsEnum(this.storeKey, this.hiveKey, this.defaultValue);

View File

@@ -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,
),
);
}

View File

@@ -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

View File

@@ -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,

View File

@@ -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(),
];