Skip to content

Commit

Permalink
feat(mobile): shared album activity disable handling (#4890)
Browse files Browse the repository at this point in the history
* feat(mobile): shared album activity disable handling

* not show comment/like option on non-shared album, alternative text when activity is disabled

---------

Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
  • Loading branch information
3 people authored Nov 8, 2023
1 parent bb28cae commit 664b710
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 121 deletions.
5 changes: 4 additions & 1 deletion mobile/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,8 @@
"app_bar_signout_dialog_ok": "Yes",
"shared_album_activities_input_hint": "Say something",
"shared_album_activity_remove_title": "Delete Activity",
"shared_album_activity_remove_content": "Do you want to delete this activity?"
"shared_album_activity_remove_content": "Do you want to delete this activity?",
"shared_album_activity_setting_title": "Comments & likes",
"shared_album_activity_setting_subtitle": "Let others respond",
"shared_album_activities_input_disable": "Comment is disabled"
}
2 changes: 1 addition & 1 deletion mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 599d8aeb73728400c15364e734525722250a5382

COCOAPODS: 1.12.1
COCOAPODS: 1.11.3
124 changes: 66 additions & 58 deletions mobile/lib/modules/activities/views/activities_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class ActivitiesPage extends HookConsumerWidget {
final bool withAssetThumbs;
final String appBarTitle;
final bool isOwner;
final bool isReadOnly;
const ActivitiesPage(
this.albumId, {
this.appBarTitle = "",
this.assetId,
this.withAssetThumbs = true,
this.isOwner = false,
this.isReadOnly = false,
super.key,
});

Expand All @@ -45,6 +47,7 @@ class ActivitiesPage extends HookConsumerWidget {
},
[],
);

buildTitleWithTimestamp(Activity activity, {bool leftAlign = true}) {
final textColor = Theme.of(context).brightness == Brightness.dark
? Colors.white
Expand Down Expand Up @@ -116,6 +119,7 @@ class ActivitiesPage extends HookConsumerWidget {
padding: const EdgeInsets.only(bottom: 10),
child: TextField(
controller: inputController,
enabled: !isReadOnly,
focusNode: inputFocusNode,
textInputAction: TextInputAction.send,
autofocus: false,
Expand Down Expand Up @@ -150,7 +154,9 @@ class ActivitiesPage extends HookConsumerWidget {
),
),
suffixIconColor: liked ? Colors.red[700] : null,
hintText: 'shared_album_activities_input_hint'.tr(),
hintText: isReadOnly
? 'shared_album_activities_input_disable'.tr()
: 'shared_album_activities_input_hint'.tr(),
hintStyle: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 14,
Expand Down Expand Up @@ -240,70 +246,72 @@ class ActivitiesPage extends HookConsumerWidget {
a.assetId == assetId,
);

return Stack(
children: [
ListView.builder(
controller: listViewScrollController,
itemCount: data.length + 1,
itemBuilder: (context, index) {
// Vertical gap after the last element
if (index == data.length) {
return const SizedBox(
height: 80,
);
}
return SafeArea(
child: Stack(
children: [
ListView.builder(
controller: listViewScrollController,
itemCount: data.length + 1,
itemBuilder: (context, index) {
// Vertical gap after the last element
if (index == data.length) {
return const SizedBox(
height: 80,
);
}

final activity = data[index];
final canDelete =
activity.user.id == currentUser?.id || isOwner;
final activity = data[index];
final canDelete =
activity.user.id == currentUser?.id || isOwner;

return Padding(
padding: const EdgeInsets.all(5),
child: activity.type == ActivityType.comment
? getDismissibleWidget(
ListTile(
minVerticalPadding: 15,
leading: UserCircleAvatar(user: activity.user),
title: buildTitleWithTimestamp(
activity,
leftAlign:
withAssetThumbs && activity.assetId != null,
return Padding(
padding: const EdgeInsets.all(5),
child: activity.type == ActivityType.comment
? getDismissibleWidget(
ListTile(
minVerticalPadding: 15,
leading: UserCircleAvatar(user: activity.user),
title: buildTitleWithTimestamp(
activity,
leftAlign: withAssetThumbs &&
activity.assetId != null,
),
titleAlignment: ListTileTitleAlignment.top,
trailing: buildAssetThumbnail(activity),
subtitle: Text(activity.comment!),
),
titleAlignment: ListTileTitleAlignment.top,
trailing: buildAssetThumbnail(activity),
subtitle: Text(activity.comment!),
),
activity,
canDelete,
)
: getDismissibleWidget(
ListTile(
minVerticalPadding: 15,
leading: Container(
width: 44,
alignment: Alignment.center,
child: Icon(
Icons.favorite_rounded,
color: Colors.red[700],
activity,
canDelete,
)
: getDismissibleWidget(
ListTile(
minVerticalPadding: 15,
leading: Container(
width: 44,
alignment: Alignment.center,
child: Icon(
Icons.favorite_rounded,
color: Colors.red[700],
),
),
title: buildTitleWithTimestamp(activity),
trailing: buildAssetThumbnail(activity),
),
title: buildTitleWithTimestamp(activity),
trailing: buildAssetThumbnail(activity),
activity,
canDelete,
),
activity,
canDelete,
),
);
},
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: buildTextField(liked?.id),
);
},
),
),
],
Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: buildTextField(liked?.id),
),
),
],
),
);
},
),
Expand Down
16 changes: 15 additions & 1 deletion mobile/lib/modules/album/providers/shared_album.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/modules/album/providers/album_detail.provider.dart';
import 'package:immich_mobile/modules/album/services/album.service.dart';
import 'package:immich_mobile/shared/models/album.dart';
import 'package:immich_mobile/shared/models/asset.dart';
Expand All @@ -10,14 +11,15 @@ import 'package:immich_mobile/shared/providers/db.provider.dart';
import 'package:isar/isar.dart';

class SharedAlbumNotifier extends StateNotifier<List<Album>> {
SharedAlbumNotifier(this._albumService, Isar db) : super([]) {
SharedAlbumNotifier(this._albumService, Isar db, this._ref) : super([]) {
final query = db.albums.filter().sharedEqualTo(true).sortByCreatedAtDesc();
query.findAll().then((value) => state = value);
_streamSub = query.watch().listen((data) => state = data);
}

final AlbumService _albumService;
late final StreamSubscription<List<Album>> _streamSub;
final Ref _ref;

Future<Album?> createSharedAlbum(
String albumName,
Expand Down Expand Up @@ -66,6 +68,17 @@ class SharedAlbumNotifier extends StateNotifier<List<Album>> {
return result;
}

Future<bool> setActivityEnabled(Album album, bool activityEnabled) async {
final result =
await _albumService.setActivityEnabled(album, activityEnabled);

if (result) {
_ref.invalidate(albumDetailProvider(album.id));
}

return result;
}

@override
void dispose() {
_streamSub.cancel();
Expand All @@ -78,5 +91,6 @@ final sharedAlbumProvider =
return SharedAlbumNotifier(
ref.watch(albumServiceProvider),
ref.watch(dbProvider),
ref,
);
});
17 changes: 17 additions & 0 deletions mobile/lib/modules/album/services/album.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ class AlbumService {
return false;
}

Future<bool> setActivityEnabled(Album album, bool enabled) async {
try {
final result = await _apiService.albumApi.updateAlbumInfo(
album.remoteId!,
UpdateAlbumDto(isActivityEnabled: enabled),
);
if (result != null) {
album.activityEnabled = enabled;
await _db.writeTxn(() => _db.albums.put(album));
return true;
}
} catch (e) {
debugPrint("Error setActivityEnabled ${e.toString()}");
}
return false;
}

Future<bool> deleteAlbum(Album album) async {
try {
final userId = Store.get(StoreKey.currentUser).isarId;
Expand Down
53 changes: 29 additions & 24 deletions mobile/lib/modules/album/ui/album_viewer_appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,32 +216,36 @@ class AlbumViewerAppbar extends HookConsumerWidget
).tr(),
onTap: () => onShareAssetsTo(),
),
album.ownerId == userId ? ListTile(
leading: const Icon(Icons.delete_sweep_rounded),
title: const Text(
'album_viewer_appbar_share_remove',
style: TextStyle(fontWeight: FontWeight.bold),
).tr(),
onTap: () => onRemoveFromAlbumPressed(),
) : const SizedBox(),
album.ownerId == userId
? ListTile(
leading: const Icon(Icons.delete_sweep_rounded),
title: const Text(
'album_viewer_appbar_share_remove',
style: TextStyle(fontWeight: FontWeight.bold),
).tr(),
onTap: () => onRemoveFromAlbumPressed(),
)
: const SizedBox(),
];
} else {
return [
album.ownerId == userId ? ListTile(
leading: const Icon(Icons.delete_forever_rounded),
title: const Text(
'album_viewer_appbar_share_delete',
style: TextStyle(fontWeight: FontWeight.bold),
).tr(),
onTap: () => onDeleteAlbumPressed(),
) : ListTile(
leading: const Icon(Icons.person_remove_rounded),
title: const Text(
'album_viewer_appbar_share_leave',
style: TextStyle(fontWeight: FontWeight.bold),
).tr(),
onTap: () => onLeaveAlbumPressed(),
),
album.ownerId == userId
? ListTile(
leading: const Icon(Icons.delete_forever_rounded),
title: const Text(
'album_viewer_appbar_share_delete',
style: TextStyle(fontWeight: FontWeight.bold),
).tr(),
onTap: () => onDeleteAlbumPressed(),
)
: ListTile(
leading: const Icon(Icons.person_remove_rounded),
title: const Text(
'album_viewer_appbar_share_leave',
style: TextStyle(fontWeight: FontWeight.bold),
).tr(),
onTap: () => onLeaveAlbumPressed(),
),
];
}
}
Expand Down Expand Up @@ -390,7 +394,8 @@ class AlbumViewerAppbar extends HookConsumerWidget
title: selected.isNotEmpty ? Text('${selected.length}') : null,
centerTitle: false,
actions: [
if (album.shared) buildActivitiesButton(),
if (album.shared && (album.activityEnabled || comments != 0))
buildActivitiesButton(),
if (album.isRemote)
IconButton(
splashRadius: 25,
Expand Down
26 changes: 26 additions & 0 deletions mobile/lib/modules/album/views/album_options_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AlbumOptionsPage extends HookConsumerWidget {
final sharedUsers = useState(album.sharedUsers.toList());
final owner = album.owner.value;
final userId = ref.watch(authenticationProvider).userId;
final activityEnabled = useState(album.activityEnabled);
final isOwner = owner?.id == userId;

void showErrorMessage() {
Expand Down Expand Up @@ -195,6 +196,31 @@ class AlbumOptionsPage extends HookConsumerWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (isOwner && album.shared)
SwitchListTile.adaptive(
value: activityEnabled.value,
onChanged: (bool value) async {
activityEnabled.value = value;
if (await ref
.read(sharedAlbumProvider.notifier)
.setActivityEnabled(album, value)) {
album.activityEnabled = value;
}
},
activeColor: activityEnabled.value
? Theme.of(context).primaryColor
: Theme.of(context).disabledColor,
dense: true,
title: Text(
"shared_album_activity_setting_title",
style: Theme.of(context)
.textTheme
.labelLarge
?.copyWith(fontWeight: FontWeight.bold),
).tr(),
subtitle:
const Text("shared_album_activity_setting_subtitle").tr(),
),
buildSectionTitle("PEOPLE"),
buildOwnerInfo(),
buildSharedUsersList(),
Expand Down
4 changes: 3 additions & 1 deletion mobile/lib/modules/album/views/album_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class AlbumViewerPage extends HookConsumerWidget {
albumId: album.remoteId!,
appBarTitle: album.name,
isOwner: userId == album.ownerId,
isReadOnly: !album.activityEnabled,
),
);
}
Expand Down Expand Up @@ -279,7 +280,8 @@ class AlbumViewerPage extends HookConsumerWidget {
],
),
isOwner: userId == data.ownerId,
sharedAlbumId: data.remoteId,
sharedAlbumId:
data.shared && data.activityEnabled ? data.remoteId : null,
),
),
),
Expand Down
Loading

0 comments on commit 664b710

Please sign in to comment.