mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
feat(mobile): archive action (#19630)
* feat(mobile): archive action * fix: lint * Update i18n/en.json Co-authored-by: Alex <alex.tran1502@gmail.com> * fix: lint * fix: lint --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
53020852ec
commit
32a7087883
@ -427,6 +427,7 @@
|
|||||||
"app_settings": "App Settings",
|
"app_settings": "App Settings",
|
||||||
"appears_in": "Appears in",
|
"appears_in": "Appears in",
|
||||||
"archive": "Archive",
|
"archive": "Archive",
|
||||||
|
"archive_action_prompt": "{count} added to Archive",
|
||||||
"archive_or_unarchive_photo": "Archive or unarchive photo",
|
"archive_or_unarchive_photo": "Archive or unarchive photo",
|
||||||
"archive_page_no_archived_assets": "No archived assets found",
|
"archive_page_no_archived_assets": "No archived assets found",
|
||||||
"archive_page_title": "Archive ({count})",
|
"archive_page_title": "Archive ({count})",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.drift.dart';
|
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.drift.dart';
|
||||||
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/db.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/db.provider.dart';
|
||||||
@ -23,4 +24,16 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> updateVisibility(List<String> ids, AssetVisibility visibility) {
|
||||||
|
return _db.batch((batch) async {
|
||||||
|
for (final id in ids) {
|
||||||
|
batch.update(
|
||||||
|
_db.remoteAssetEntity,
|
||||||
|
RemoteAssetEntityCompanion(visibility: Value(visibility)),
|
||||||
|
where: (e) => e.id.equals(id),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,73 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/constants/enums.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart';
|
||||||
|
import 'package:immich_mobile/providers/infrastructure/action.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/user.provider.dart';
|
||||||
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
||||||
|
|
||||||
class ArchiveActionButton extends ConsumerWidget {
|
class ArchiveActionButton extends ConsumerWidget {
|
||||||
const ArchiveActionButton({super.key});
|
final ActionSource source;
|
||||||
|
|
||||||
|
const ArchiveActionButton({super.key, required this.source});
|
||||||
|
|
||||||
|
onAction(BuildContext context, WidgetRef ref) {
|
||||||
|
switch (source) {
|
||||||
|
case ActionSource.timeline:
|
||||||
|
timelineAction(context, ref);
|
||||||
|
case ActionSource.viewer:
|
||||||
|
viewerAction(ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void timelineAction(BuildContext context, WidgetRef ref) {
|
||||||
|
final user = ref.read(currentUserProvider);
|
||||||
|
if (user == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ids = ref
|
||||||
|
.read(multiSelectProvider.select((value) => value.selectedAssets))
|
||||||
|
.whereType<RemoteAsset>()
|
||||||
|
.where((asset) => asset.ownerId == user.id)
|
||||||
|
.map((asset) => asset.id)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (ids.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.read(actionProvider.notifier).archive(ids);
|
||||||
|
ref.read(multiSelectProvider.notifier).reset();
|
||||||
|
|
||||||
|
final toastMessage = 'archive_action_prompt'.t(
|
||||||
|
context: context,
|
||||||
|
args: {'count': ids.length.toString()},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ImmichToast.show(
|
||||||
|
context: context,
|
||||||
|
msg: toastMessage,
|
||||||
|
gravity: ToastGravity.BOTTOM,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void viewerAction(WidgetRef _) {
|
||||||
|
UnimplementedError("Viewer action for archive is not implemented yet.");
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return BaseActionButton(
|
return BaseActionButton(
|
||||||
iconData: Icons.archive_outlined,
|
iconData: Icons.archive_outlined,
|
||||||
label: "archive".t(context: context),
|
label: "archive".t(context: context),
|
||||||
|
onPressed: () => onAction(context, ref),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class HomeBottomAppBar extends ConsumerWidget {
|
|||||||
const ShareActionButton(),
|
const ShareActionButton(),
|
||||||
if (multiselect.hasRemote) ...[
|
if (multiselect.hasRemote) ...[
|
||||||
const ShareLinkActionButton(source: ActionSource.timeline),
|
const ShareLinkActionButton(source: ActionSource.timeline),
|
||||||
const ArchiveActionButton(),
|
const ArchiveActionButton(source: ActionSource.timeline),
|
||||||
const FavoriteActionButton(source: ActionSource.timeline),
|
const FavoriteActionButton(source: ActionSource.timeline),
|
||||||
const DownloadActionButton(),
|
const DownloadActionButton(),
|
||||||
isTrashEnable
|
isTrashEnable
|
||||||
|
@ -25,4 +25,12 @@ class ActionNotifier extends Notifier<void> {
|
|||||||
Future<void> unFavorite(List<String> ids) async {
|
Future<void> unFavorite(List<String> ids) async {
|
||||||
await _service.unFavorite(ids);
|
await _service.unFavorite(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> archive(List<String> ids) async {
|
||||||
|
await _service.archive(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> unArchive(List<String> ids) async {
|
||||||
|
await _service.unArchive(ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:immich_mobile/constants/enums.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
import 'package:immich_mobile/infrastructure/repositories/remote_asset.repository.dart';
|
import 'package:immich_mobile/infrastructure/repositories/remote_asset.repository.dart';
|
||||||
import 'package:immich_mobile/repositories/asset_api.repository.dart';
|
import 'package:immich_mobile/repositories/asset_api.repository.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
@ -33,4 +35,34 @@ class ActionService {
|
|||||||
debugPrint('Error unfavoriting assets: $e');
|
debugPrint('Error unfavoriting assets: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> archive(List<String> remoteIds) async {
|
||||||
|
try {
|
||||||
|
await _assetApiRepository.updateVisibility(
|
||||||
|
remoteIds,
|
||||||
|
AssetVisibilityEnum.archive,
|
||||||
|
);
|
||||||
|
await _remoteAssetRepository.updateVisibility(
|
||||||
|
remoteIds,
|
||||||
|
AssetVisibility.archive,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error archive assets: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> unArchive(List<String> remoteIds) async {
|
||||||
|
try {
|
||||||
|
await _assetApiRepository.updateVisibility(
|
||||||
|
remoteIds,
|
||||||
|
AssetVisibilityEnum.timeline,
|
||||||
|
);
|
||||||
|
await _remoteAssetRepository.updateVisibility(
|
||||||
|
remoteIds,
|
||||||
|
AssetVisibility.timeline,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error unarchive assets: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ class ApiService implements Authentication {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await setEndpoint(serverUrl);
|
await setEndpoint(serverUrl);
|
||||||
await serverInfoApi.pingServer().timeout(const Duration(seconds: 5));
|
await serverInfoApi.pingServer().timeout(const Duration(seconds: 60));
|
||||||
} on TimeoutException catch (_) {
|
} on TimeoutException catch (_) {
|
||||||
return false;
|
return false;
|
||||||
} on SocketException catch (_) {
|
} on SocketException catch (_) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user