mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
fix(mobile): download asset to Camera folder on Android (#12355)
* fix(mobile): download asset to Camera folder on Android * remove unused import * better message * linting
This commit is contained in:
parent
0148005931
commit
77904a54d8
4 changed files with 26 additions and 18 deletions
|
@ -252,9 +252,10 @@
|
||||||
"home_page_share_err_local": "Can not share local assets via link, skipping",
|
"home_page_share_err_local": "Can not share local assets via link, skipping",
|
||||||
"home_page_upload_err_limit": "Can only upload a maximum of 30 assets at a time, skipping",
|
"home_page_upload_err_limit": "Can only upload a maximum of 30 assets at a time, skipping",
|
||||||
"image_saved_successfully": "Image saved",
|
"image_saved_successfully": "Image saved",
|
||||||
"image_viewer_page_state_provider_download_error": "Download Error",
|
"download_error": "Download Error",
|
||||||
"image_viewer_page_state_provider_download_started": "Download Started",
|
"download_started": "Download started",
|
||||||
"image_viewer_page_state_provider_download_success": "Download Success",
|
"download_sucess": "Download success",
|
||||||
|
"download_sucess_android": "The media has been downloaded to DCIM/Immich",
|
||||||
"image_viewer_page_state_provider_share_error": "Share Error",
|
"image_viewer_page_state_provider_share_error": "Share Error",
|
||||||
"invalid_date": "Invalid date",
|
"invalid_date": "Invalid date",
|
||||||
"invalid_date_format": "Invalid date format",
|
"invalid_date_format": "Invalid date format",
|
||||||
|
@ -585,4 +586,4 @@
|
||||||
"viewer_remove_from_stack": "Remove from Stack",
|
"viewer_remove_from_stack": "Remove from Stack",
|
||||||
"viewer_stack_use_as_main_asset": "Use as Main Asset",
|
"viewer_stack_use_as_main_asset": "Use as Main Asset",
|
||||||
"viewer_unstack": "Un-Stack"
|
"viewer_unstack": "Un-Stack"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
|
@ -31,19 +33,21 @@ class ImageViewerStateNotifier extends StateNotifier<AssetViewerPageState> {
|
||||||
|
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
context: context,
|
context: context,
|
||||||
msg: 'image_viewer_page_state_provider_download_started'.tr(),
|
msg: 'download_started'.tr(),
|
||||||
toastType: ToastType.info,
|
toastType: ToastType.info,
|
||||||
gravity: ToastGravity.BOTTOM,
|
gravity: ToastGravity.BOTTOM,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool isSuccess = await _imageViewerService.downloadAssetToDevice(asset);
|
bool isSuccess = await _imageViewerService.downloadAsset(asset);
|
||||||
|
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
state = state.copyWith(downloadAssetStatus: DownloadAssetStatus.success);
|
state = state.copyWith(downloadAssetStatus: DownloadAssetStatus.success);
|
||||||
|
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
context: context,
|
context: context,
|
||||||
msg: 'image_viewer_page_state_provider_download_success'.tr(),
|
msg: Platform.isAndroid
|
||||||
|
? 'download_sucess_android'.tr()
|
||||||
|
: 'download_sucess'.tr(),
|
||||||
toastType: ToastType.success,
|
toastType: ToastType.success,
|
||||||
gravity: ToastGravity.BOTTOM,
|
gravity: ToastGravity.BOTTOM,
|
||||||
);
|
);
|
||||||
|
@ -52,7 +56,7 @@ class ImageViewerStateNotifier extends StateNotifier<AssetViewerPageState> {
|
||||||
state = state.copyWith(downloadAssetStatus: DownloadAssetStatus.error);
|
state = state.copyWith(downloadAssetStatus: DownloadAssetStatus.error);
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
context: context,
|
context: context,
|
||||||
msg: 'image_viewer_page_state_provider_download_error'.tr(),
|
msg: 'download_error'.tr(),
|
||||||
toastType: ToastType.error,
|
toastType: ToastType.error,
|
||||||
gravity: ToastGravity.BOTTOM,
|
gravity: ToastGravity.BOTTOM,
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ImageViewerService {
|
||||||
|
|
||||||
ImageViewerService(this._apiService);
|
ImageViewerService(this._apiService);
|
||||||
|
|
||||||
Future<bool> downloadAssetToDevice(Asset asset) async {
|
Future<bool> downloadAsset(Asset asset) async {
|
||||||
File? imageFile;
|
File? imageFile;
|
||||||
File? videoFile;
|
File? videoFile;
|
||||||
try {
|
try {
|
||||||
|
@ -82,18 +82,23 @@ class ImageViewerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
final AssetEntity? entity;
|
final AssetEntity? entity;
|
||||||
|
final relativePath = Platform.isAndroid ? 'DCIM/Immich' : null;
|
||||||
|
|
||||||
if (asset.isImage) {
|
if (asset.isImage) {
|
||||||
entity = await PhotoManager.editor.saveImage(
|
entity = await PhotoManager.editor.saveImage(
|
||||||
res.bodyBytes,
|
res.bodyBytes,
|
||||||
title: asset.fileName,
|
title: asset.fileName,
|
||||||
|
relativePath: relativePath,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
videoFile = await File('${tempDir.path}/${asset.fileName}').create();
|
videoFile = await File('${tempDir.path}/${asset.fileName}').create();
|
||||||
videoFile.writeAsBytesSync(res.bodyBytes);
|
videoFile.writeAsBytesSync(res.bodyBytes);
|
||||||
entity = await PhotoManager.editor
|
entity = await PhotoManager.editor.saveVideo(
|
||||||
.saveVideo(videoFile, title: asset.fileName);
|
videoFile,
|
||||||
|
title: asset.fileName,
|
||||||
|
relativePath: relativePath,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return entity != null;
|
return entity != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,10 @@ class GalleryAppBar extends ConsumerWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleDownloadAsset() {
|
||||||
|
ref.read(imageViewerStateProvider.notifier).downloadAsset(asset, context);
|
||||||
|
}
|
||||||
|
|
||||||
return IgnorePointer(
|
return IgnorePointer(
|
||||||
ignoring: !ref.watch(showControlsProvider),
|
ignoring: !ref.watch(showControlsProvider),
|
||||||
child: AnimatedOpacity(
|
child: AnimatedOpacity(
|
||||||
|
@ -109,13 +113,7 @@ class GalleryAppBar extends ConsumerWidget {
|
||||||
onFavorite: toggleFavorite,
|
onFavorite: toggleFavorite,
|
||||||
onRestorePressed: () => handleRestore(asset),
|
onRestorePressed: () => handleRestore(asset),
|
||||||
onUploadPressed: asset.isLocal ? () => handleUpload(asset) : null,
|
onUploadPressed: asset.isLocal ? () => handleUpload(asset) : null,
|
||||||
onDownloadPressed: asset.isLocal
|
onDownloadPressed: asset.isLocal ? null : handleDownloadAsset,
|
||||||
? null
|
|
||||||
: () =>
|
|
||||||
ref.read(imageViewerStateProvider.notifier).downloadAsset(
|
|
||||||
asset,
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
onToggleMotionVideo: onToggleMotionVideo,
|
onToggleMotionVideo: onToggleMotionVideo,
|
||||||
onAddToAlbumPressed: () => addToAlbum(asset),
|
onAddToAlbumPressed: () => addToAlbum(asset),
|
||||||
onActivitiesPressed: handleActivities,
|
onActivitiesPressed: handleActivities,
|
||||||
|
|
Loading…
Reference in a new issue