feat: remove after save

This commit is contained in:
My-Responsitories
2025-08-21 20:48:04 +08:00
committed by bggRGjQaUbCoE
parent f50965862d
commit 47ad1adfdc
6 changed files with 81 additions and 57 deletions

View File

@@ -34,7 +34,7 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
late final RxBool readOnly = false.obs;
late final RxBool enablePublish = false.obs;
bool? hasPub;
bool hasPub = false;
void initPubState();
@override
@@ -57,7 +57,7 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
@override
void dispose() {
if (hasPub != true) {
if (!hasPub) {
onSave();
}
focusNode.dispose();

View File

@@ -13,6 +13,7 @@ import 'package:PiliPlus/models_new/live/live_emote/emoticon.dart';
import 'package:PiliPlus/models_new/upload_bfs/data.dart';
import 'package:PiliPlus/pages/common/publish/common_publish_page.dart';
import 'package:PiliPlus/pages/dynamics_mention/view.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/feed_back.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:dio/dio.dart' show CancelToken;
@@ -58,6 +59,16 @@ abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
}
}
@override
void dispose() {
if (hasPub) {
for (var i in pathList) {
File(i).delSync();
}
}
super.dispose();
}
@override
void didChangeDependencies() {
editController.richStyle = null;

View File

@@ -25,7 +25,6 @@ import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart' hide TextField;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart' hide ContextExtensionss;
import 'package:path_provider/path_provider.dart';
class ReplyPage extends CommonRichTextPubPage {
final int oid;
@@ -377,9 +376,8 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
.videoPlayerController
?.screenshot(format: 'image/png');
if (res != null) {
final tempDir = await getTemporaryDirectory();
File file = File(
'${tempDir.path}/${Utils.generateRandomString(8)}.png',
final file = File(
'${await Utils.temporaryDirectory}/${Utils.generateRandomString(8)}.png',
);
await file.writeAsBytes(res);
pathList.add(file.path);

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pbenum.dart'
show IMSettingType, ThreeDotItemType;
@@ -210,6 +212,14 @@ extension ThreeDotItemTypeExt on ThreeDotItemType {
}
}
extension FileExt on File {
void delSync({bool recursive = false}) {
try {
deleteSync(recursive: recursive);
} catch (_) {}
}
}
extension SizeExt on Size {
bool get isPortrait => width < 600 || height >= width;
}

View File

@@ -10,7 +10,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:intl/intl.dart' show DateFormat;
import 'package:live_photo_maker/live_photo_maker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:saver_gallery/saver_gallery.dart';
import 'package:share_plus/share_plus.dart';
@@ -24,17 +23,19 @@ class ImageUtil {
static Future<void> onShareImg(String url) async {
try {
SmartDialog.showLoading();
final temp = await getTemporaryDirectory();
var path = '${temp.path}/${Utils.getFileName(url)}';
var res = await Request().downloadFile(url.http2https, path);
final path =
'${await Utils.temporaryDirectory}/${Utils.getFileName(url)}';
final res = await Request().downloadFile(url.http2https, path);
SmartDialog.dismiss();
if (res.statusCode == 200) {
SharePlus.instance.share(
ShareParams(
files: [XFile(path)],
sharePositionOrigin: await Utils.sharePositionOrigin,
),
);
await SharePlus.instance
.share(
ShareParams(
files: [XFile(path)],
sharePositionOrigin: await Utils.sharePositionOrigin,
),
)
.whenComplete(() => File(path).delSync());
}
} catch (e) {
SmartDialog.showToast(e.toString());
@@ -108,7 +109,7 @@ class ImageUtil {
}
if (!silentDownImg) SmartDialog.showLoading(msg: '正在下载');
String tmpPath = (await getTemporaryDirectory()).path;
String tmpPath = await Utils.temporaryDirectory;
late String imageName = "cover_${Utils.getFileName(url)}";
late String imagePath = '$tmpPath/$imageName';
String videoName = "video_${Utils.getFileName(liveUrl)}";
@@ -121,13 +122,19 @@ class ImageUtil {
final res1 = await Request().downloadFile(url.http2https, imagePath);
if (res1.statusCode != 200) throw '${res1.statusCode}';
if (!silentDownImg) SmartDialog.showLoading(msg: '正在保存');
bool success = await LivePhotoMaker.create(
coverImage: imagePath,
imagePath: null,
voicePath: videoPath,
width: width,
height: height,
);
bool success =
await LivePhotoMaker.create(
coverImage: imagePath,
imagePath: null,
voicePath: videoPath,
width: width,
height: height,
).whenComplete(
() {
File(videoPath).delSync();
File(imagePath).delSync();
},
);
if (success) {
SmartDialog.showToast(' Live Photo 已保存 ');
} else {
@@ -141,7 +148,7 @@ class ImageUtil {
fileName: videoName,
androidRelativePath: "Pictures/PiliPlus",
skipIfExists: false,
);
).whenComplete(() => File(videoPath).delSync());
if (result.isSuccess) {
SmartDialog.showToast(' 已保存 ');
} else {
@@ -174,12 +181,12 @@ class ImageUtil {
}
try {
final isAndroid = Platform.isAndroid;
final tempPath = (await getTemporaryDirectory()).path;
final tempPath = await Utils.temporaryDirectory;
final futures = imgList.map((url) async {
var name = Utils.getFileName(url);
var filePath = '$tempPath/$name';
final name = Utils.getFileName(url);
final filePath = '$tempPath/$name';
var response = await Request().downloadFile(
final response = await Request().downloadFile(
url.http2https,
filePath,
cancelToken: cancelToken,
@@ -192,25 +199,26 @@ class ImageUtil {
fileName: name,
androidRelativePath: "Pictures/PiliPlus",
skipIfExists: false,
);
).whenComplete(() => File(filePath).delSync());
}
}
return {
'filePath': filePath,
'name': name,
'statusCode': response.statusCode,
};
return (
filePath: filePath,
name: name,
statusCode: response.statusCode,
);
});
final result = await Future.wait(futures, eagerError: true);
if (!isAndroid) {
for (Map res in result) {
if (res['statusCode'] == 200) {
for (var res in result) {
if (res.statusCode == 200) {
await SaverGallery.saveFile(
filePath: res['filePath'],
fileName: res['name'],
filePath: res.filePath,
fileName: res.name,
androidRelativePath: "Pictures/PiliPlus",
skipIfExists: false,
);
File(res.filePath).delSync();
}
}
}

View File

@@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
class Utils {
@@ -21,30 +22,26 @@ class Utils {
static int? _sdkInt;
static Future<int> get sdkInt async {
if (_sdkInt != null) {
return _sdkInt!;
}
_sdkInt = (await DeviceInfoPlugin().androidInfo).version.sdkInt;
return _sdkInt!;
return _sdkInt ??= (await DeviceInfoPlugin().androidInfo).version.sdkInt;
}
static bool? _isIpad;
static Future<bool> isIpad() async {
if (_isIpad != null) {
return _isIpad!;
}
if (!Platform.isIOS) {
return false;
}
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo info = await deviceInfo.iosInfo;
_isIpad = info.model.toLowerCase().contains("ipad");
return _isIpad!;
static Future<bool> get isIpad async {
if (!Platform.isIOS) return false;
return _isIpad ??= (await DeviceInfoPlugin().iosInfo).model
.toLowerCase()
.contains('ipad');
}
static String? _tempDir;
static Future<String> get temporaryDirectory async {
return _tempDir ??= (await getTemporaryDirectory()).path;
}
static Future<Rect?> get sharePositionOrigin async {
if (await Utils.isIpad()) {
if (await isIpad) {
final size = Get.size;
return Rect.fromLTWH(
0,
@@ -58,7 +55,7 @@ class Utils {
static Future<void> shareText(String text) async {
try {
SharePlus.instance.share(
await SharePlus.instance.share(
ShareParams(
text: text,
sharePositionOrigin: await sharePositionOrigin,