mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-17 23:56:13 +08:00
custom silent down img
Closes #1030 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -26,6 +26,7 @@ import 'package:PiliPlus/utils/accounts.dart';
|
|||||||
import 'package:PiliPlus/utils/cache_manage.dart';
|
import 'package:PiliPlus/utils/cache_manage.dart';
|
||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/feed_back.dart';
|
import 'package:PiliPlus/utils/feed_back.dart';
|
||||||
|
import 'package:PiliPlus/utils/image_util.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:PiliPlus/utils/storage_key.dart';
|
import 'package:PiliPlus/utils/storage_key.dart';
|
||||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
@@ -731,6 +732,15 @@ List<SettingsModel> get extraSettings => [
|
|||||||
defaultVal: true,
|
defaultVal: true,
|
||||||
needReboot: true,
|
needReboot: true,
|
||||||
),
|
),
|
||||||
|
SettingsModel(
|
||||||
|
settingsType: SettingsType.sw1tch,
|
||||||
|
title: '静默下载图片',
|
||||||
|
subtitle: '不显示下载 Loading 弹窗',
|
||||||
|
leading: const Icon(Icons.download_for_offline_outlined),
|
||||||
|
setKey: SettingBoxKey.silentDownImg,
|
||||||
|
defaultVal: false,
|
||||||
|
onChanged: (value) => ImageUtil.silentDownImg = value,
|
||||||
|
),
|
||||||
SettingsModel(
|
SettingsModel(
|
||||||
settingsType: SettingsType.sw1tch,
|
settingsType: SettingsType.sw1tch,
|
||||||
setKey: SettingBoxKey.feedBackEnable,
|
setKey: SettingBoxKey.feedBackEnable,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
import 'package:PiliPlus/http/init.dart';
|
import 'package:PiliPlus/http/init.dart';
|
||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/global_data.dart';
|
import 'package:PiliPlus/utils/global_data.dart';
|
||||||
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -17,6 +18,7 @@ import 'package:share_plus/share_plus.dart';
|
|||||||
class ImageUtil {
|
class ImageUtil {
|
||||||
static String get time =>
|
static String get time =>
|
||||||
DateFormat('yyyy-MM-dd_HH-mm-ss').format(DateTime.now());
|
DateFormat('yyyy-MM-dd_HH-mm-ss').format(DateTime.now());
|
||||||
|
static bool silentDownImg = Pref.silentDownImg;
|
||||||
|
|
||||||
// 图片分享
|
// 图片分享
|
||||||
static Future<void> onShareImg(String url) async {
|
static Future<void> onShareImg(String url) async {
|
||||||
@@ -104,7 +106,7 @@ class ImageUtil {
|
|||||||
if (!await checkPermissionDependOnSdkInt(context)) {
|
if (!await checkPermissionDependOnSdkInt(context)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SmartDialog.showLoading(msg: '正在下载');
|
if (!silentDownImg) SmartDialog.showLoading(msg: '正在下载');
|
||||||
|
|
||||||
String tmpPath = (await getTemporaryDirectory()).path;
|
String tmpPath = (await getTemporaryDirectory()).path;
|
||||||
late String imageName = "cover_${Utils.getFileName(url)}";
|
late String imageName = "cover_${Utils.getFileName(url)}";
|
||||||
@@ -118,7 +120,7 @@ class ImageUtil {
|
|||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
final res1 = await Request().downloadFile(url.http2https, imagePath);
|
final res1 = await Request().downloadFile(url.http2https, imagePath);
|
||||||
if (res1.statusCode != 200) throw '${res1.statusCode}';
|
if (res1.statusCode != 200) throw '${res1.statusCode}';
|
||||||
SmartDialog.showLoading(msg: '正在保存');
|
if (!silentDownImg) SmartDialog.showLoading(msg: '正在保存');
|
||||||
bool success = await LivePhotoMaker.create(
|
bool success = await LivePhotoMaker.create(
|
||||||
coverImage: imagePath,
|
coverImage: imagePath,
|
||||||
imagePath: null,
|
imagePath: null,
|
||||||
@@ -126,33 +128,33 @@ class ImageUtil {
|
|||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
);
|
);
|
||||||
SmartDialog.dismiss();
|
|
||||||
if (success) {
|
if (success) {
|
||||||
SmartDialog.showToast(' Live Photo 已保存 ');
|
SmartDialog.showToast(' Live Photo 已保存 ');
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast('保存失败');
|
SmartDialog.showToast('保存失败');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showLoading(msg: '正在保存');
|
if (!silentDownImg) SmartDialog.showLoading(msg: '正在保存');
|
||||||
final SaveResult result = await SaverGallery.saveFile(
|
final SaveResult result = await SaverGallery.saveFile(
|
||||||
filePath: videoPath,
|
filePath: videoPath,
|
||||||
fileName: videoName,
|
fileName: videoName,
|
||||||
androidRelativePath: "Pictures/PiliPlus",
|
androidRelativePath: "Pictures/PiliPlus",
|
||||||
skipIfExists: false,
|
skipIfExists: false,
|
||||||
);
|
);
|
||||||
SmartDialog.dismiss();
|
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
SmartDialog.showToast(' 已保存 ');
|
SmartDialog.showToast(' 已保存 ');
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast('保存失败,${result.errorMessage}');
|
SmartDialog.showToast('保存失败,${result.errorMessage}');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
SmartDialog.dismiss();
|
|
||||||
SmartDialog.showToast(err.toString());
|
SmartDialog.showToast(err.toString());
|
||||||
return false;
|
return false;
|
||||||
|
} finally {
|
||||||
|
if (!silentDownImg) SmartDialog.dismiss(status: SmartStatus.loading);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,12 +163,15 @@ class ImageUtil {
|
|||||||
List<String> imgList,
|
List<String> imgList,
|
||||||
) async {
|
) async {
|
||||||
if (!await checkPermissionDependOnSdkInt(context)) return false;
|
if (!await checkPermissionDependOnSdkInt(context)) return false;
|
||||||
final cancelToken = CancelToken();
|
CancelToken? cancelToken;
|
||||||
SmartDialog.showLoading(
|
if (!silentDownImg) {
|
||||||
msg: '正在下载原图',
|
cancelToken = CancelToken();
|
||||||
clickMaskDismiss: true,
|
SmartDialog.showLoading(
|
||||||
onDismiss: cancelToken.cancel,
|
msg: '正在下载原图',
|
||||||
);
|
clickMaskDismiss: true,
|
||||||
|
onDismiss: cancelToken.cancel,
|
||||||
|
);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final isAndroid = Platform.isAndroid;
|
final isAndroid = Platform.isAndroid;
|
||||||
final tempPath = (await getTemporaryDirectory()).path;
|
final tempPath = (await getTemporaryDirectory()).path;
|
||||||
@@ -209,7 +214,7 @@ class ImageUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelToken.isCancelled) {
|
if (cancelToken?.isCancelled == true) {
|
||||||
SmartDialog.showToast('已取消下载');
|
SmartDialog.showToast('已取消下载');
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -217,14 +222,14 @@ class ImageUtil {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (cancelToken.isCancelled) {
|
if (cancelToken?.isCancelled == true) {
|
||||||
SmartDialog.showToast('已取消下载');
|
SmartDialog.showToast('已取消下载');
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast(e.toString());
|
SmartDialog.showToast(e.toString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
SmartDialog.dismiss(status: SmartStatus.loading);
|
if (!silentDownImg) SmartDialog.dismiss(status: SmartStatus.loading);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ class SettingBoxKey {
|
|||||||
dynamicDetailRatio = 'dynamicDetailRatio',
|
dynamicDetailRatio = 'dynamicDetailRatio',
|
||||||
directExitOnBack = 'directExitOnBack',
|
directExitOnBack = 'directExitOnBack',
|
||||||
quickFavId = 'quickFavId',
|
quickFavId = 'quickFavId',
|
||||||
showFsScreenshotBtn = 'showFsScreenshotBtn';
|
showFsScreenshotBtn = 'showFsScreenshotBtn',
|
||||||
|
silentDownImg = 'silentDownImg';
|
||||||
|
|
||||||
static const String subtitlePreferenceV2 = 'subtitlePreferenceV2',
|
static const String subtitlePreferenceV2 = 'subtitlePreferenceV2',
|
||||||
enableDragSubtitle = 'enableDragSubtitle',
|
enableDragSubtitle = 'enableDragSubtitle',
|
||||||
|
|||||||
@@ -794,4 +794,7 @@ class Pref {
|
|||||||
|
|
||||||
static bool get showFsScreenshotBtn =>
|
static bool get showFsScreenshotBtn =>
|
||||||
_setting.get(SettingBoxKey.showFsScreenshotBtn, defaultValue: true);
|
_setting.get(SettingBoxKey.showFsScreenshotBtn, defaultValue: true);
|
||||||
|
|
||||||
|
static bool get silentDownImg =>
|
||||||
|
_setting.get(SettingBoxKey.silentDownImg, defaultValue: false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user