feat: live photo

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-28 14:19:59 +08:00
parent b761c35d10
commit f5d7dc6b6a
15 changed files with 227 additions and 73 deletions

View File

@@ -6,6 +6,7 @@ import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:saver_gallery/saver_gallery.dart';
import 'dart:io';
@@ -85,6 +86,38 @@ class DownloadUtils {
return await requestStoragePer(context);
}
static Future downloadVideo(BuildContext context, String url) async {
try {
if (!await checkPermissionDependOnSdkInt(context)) {
return;
}
SmartDialog.showLoading(msg: '正在下载');
String videoName =
"video_${DateTime.now().toString().replaceAll(' ', '_').replaceAll(':', '-').split('.').first}.${url.split('.').lastOrNull ?? 'mp4'}";
String savePath = '${(await getTemporaryDirectory()).path}/$videoName';
await Request.dio.download(url, savePath);
SmartDialog.showLoading(msg: '正在保存');
final SaveResult result = await SaverGallery.saveFile(
filePath: savePath,
fileName: videoName,
androidRelativePath: "Pictures/PiliPlus",
skipIfExists: false,
);
SmartDialog.dismiss();
if (result.isSuccess) {
SmartDialog.showToast('$videoName」已保存 ');
} else {
SmartDialog.showToast('保存失败,${result.errorMessage}');
}
return true;
} catch (err) {
SmartDialog.dismiss();
SmartDialog.showToast(err.toString());
return false;
}
}
static Future downloadImg(
BuildContext context,
List<String> imgList, {

View File

@@ -73,15 +73,13 @@ extension BuildContextExt on BuildContext {
void imageView({
int? initialPage,
required List<String> imgList,
required List<SourceModel> imgList,
ValueChanged<int>? onDismissed,
bool? isFile,
}) {
Navigator.of(this).push(
HeroDialogRoute(
builder: (context) => InteractiveviewerGallery(
sources: imgList,
isFile: isFile,
initIndex: initialPage ?? 0,
onPageChanged: (int pageIndex) {},
onDismissed: onDismissed,

View File

@@ -354,6 +354,9 @@ class GStorage {
static bool get showDynDecorate =>
GStorage.setting.get(SettingBoxKey.showDynDecorate, defaultValue: true);
static bool get enableLivePhoto =>
GStorage.setting.get(SettingBoxKey.enableLivePhoto, defaultValue: true);
static List<double> get dynamicDetailRatio => List<double>.from(setting
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
@@ -581,6 +584,7 @@ class SettingBoxKey {
mainTabBarView = 'mainTabBarView',
searchSuggestion = 'searchSuggestion',
showDynDecorate = 'showDynDecorate',
enableLivePhoto = 'enableLivePhoto',
// Sponsor Block
enableSponsorBlock = 'enableSponsorBlock',