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

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