mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: remove after save
This commit is contained in:
committed by
bggRGjQaUbCoE
parent
f50965862d
commit
47ad1adfdc
@@ -34,7 +34,7 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
|
|||||||
late final RxBool readOnly = false.obs;
|
late final RxBool readOnly = false.obs;
|
||||||
late final RxBool enablePublish = false.obs;
|
late final RxBool enablePublish = false.obs;
|
||||||
|
|
||||||
bool? hasPub;
|
bool hasPub = false;
|
||||||
void initPubState();
|
void initPubState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -57,7 +57,7 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
if (hasPub != true) {
|
if (!hasPub) {
|
||||||
onSave();
|
onSave();
|
||||||
}
|
}
|
||||||
focusNode.dispose();
|
focusNode.dispose();
|
||||||
|
|||||||
@@ -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/models_new/upload_bfs/data.dart';
|
||||||
import 'package:PiliPlus/pages/common/publish/common_publish_page.dart';
|
import 'package:PiliPlus/pages/common/publish/common_publish_page.dart';
|
||||||
import 'package:PiliPlus/pages/dynamics_mention/view.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/feed_back.dart';
|
||||||
import 'package:PiliPlus/utils/page_utils.dart';
|
import 'package:PiliPlus/utils/page_utils.dart';
|
||||||
import 'package:dio/dio.dart' show CancelToken;
|
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
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
editController.richStyle = null;
|
editController.richStyle = null;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import 'package:PiliPlus/utils/utils.dart';
|
|||||||
import 'package:flutter/material.dart' hide TextField;
|
import 'package:flutter/material.dart' hide TextField;
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart' hide ContextExtensionss;
|
import 'package:get/get.dart' hide ContextExtensionss;
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
|
|
||||||
class ReplyPage extends CommonRichTextPubPage {
|
class ReplyPage extends CommonRichTextPubPage {
|
||||||
final int oid;
|
final int oid;
|
||||||
@@ -377,9 +376,8 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
|
|||||||
.videoPlayerController
|
.videoPlayerController
|
||||||
?.screenshot(format: 'image/png');
|
?.screenshot(format: 'image/png');
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final file = File(
|
||||||
File file = File(
|
'${await Utils.temporaryDirectory}/${Utils.generateRandomString(8)}.png',
|
||||||
'${tempDir.path}/${Utils.generateRandomString(8)}.png',
|
|
||||||
);
|
);
|
||||||
await file.writeAsBytes(res);
|
await file.writeAsBytes(res);
|
||||||
pathList.add(file.path);
|
pathList.add(file.path);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pbenum.dart'
|
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pbenum.dart'
|
||||||
show IMSettingType, ThreeDotItemType;
|
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 {
|
extension SizeExt on Size {
|
||||||
bool get isPortrait => width < 600 || height >= width;
|
bool get isPortrait => width < 600 || height >= width;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:intl/intl.dart' show DateFormat;
|
import 'package:intl/intl.dart' show DateFormat;
|
||||||
import 'package:live_photo_maker/live_photo_maker.dart';
|
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:permission_handler/permission_handler.dart';
|
||||||
import 'package:saver_gallery/saver_gallery.dart';
|
import 'package:saver_gallery/saver_gallery.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
@@ -24,17 +23,19 @@ class ImageUtil {
|
|||||||
static Future<void> onShareImg(String url) async {
|
static Future<void> onShareImg(String url) async {
|
||||||
try {
|
try {
|
||||||
SmartDialog.showLoading();
|
SmartDialog.showLoading();
|
||||||
final temp = await getTemporaryDirectory();
|
final path =
|
||||||
var path = '${temp.path}/${Utils.getFileName(url)}';
|
'${await Utils.temporaryDirectory}/${Utils.getFileName(url)}';
|
||||||
var res = await Request().downloadFile(url.http2https, path);
|
final res = await Request().downloadFile(url.http2https, path);
|
||||||
SmartDialog.dismiss();
|
SmartDialog.dismiss();
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
SharePlus.instance.share(
|
await SharePlus.instance
|
||||||
ShareParams(
|
.share(
|
||||||
files: [XFile(path)],
|
ShareParams(
|
||||||
sharePositionOrigin: await Utils.sharePositionOrigin,
|
files: [XFile(path)],
|
||||||
),
|
sharePositionOrigin: await Utils.sharePositionOrigin,
|
||||||
);
|
),
|
||||||
|
)
|
||||||
|
.whenComplete(() => File(path).delSync());
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
SmartDialog.showToast(e.toString());
|
SmartDialog.showToast(e.toString());
|
||||||
@@ -108,7 +109,7 @@ class ImageUtil {
|
|||||||
}
|
}
|
||||||
if (!silentDownImg) SmartDialog.showLoading(msg: '正在下载');
|
if (!silentDownImg) SmartDialog.showLoading(msg: '正在下载');
|
||||||
|
|
||||||
String tmpPath = (await getTemporaryDirectory()).path;
|
String tmpPath = await Utils.temporaryDirectory;
|
||||||
late String imageName = "cover_${Utils.getFileName(url)}";
|
late String imageName = "cover_${Utils.getFileName(url)}";
|
||||||
late String imagePath = '$tmpPath/$imageName';
|
late String imagePath = '$tmpPath/$imageName';
|
||||||
String videoName = "video_${Utils.getFileName(liveUrl)}";
|
String videoName = "video_${Utils.getFileName(liveUrl)}";
|
||||||
@@ -121,13 +122,19 @@ class ImageUtil {
|
|||||||
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}';
|
||||||
if (!silentDownImg) SmartDialog.showLoading(msg: '正在保存');
|
if (!silentDownImg) SmartDialog.showLoading(msg: '正在保存');
|
||||||
bool success = await LivePhotoMaker.create(
|
bool success =
|
||||||
coverImage: imagePath,
|
await LivePhotoMaker.create(
|
||||||
imagePath: null,
|
coverImage: imagePath,
|
||||||
voicePath: videoPath,
|
imagePath: null,
|
||||||
width: width,
|
voicePath: videoPath,
|
||||||
height: height,
|
width: width,
|
||||||
);
|
height: height,
|
||||||
|
).whenComplete(
|
||||||
|
() {
|
||||||
|
File(videoPath).delSync();
|
||||||
|
File(imagePath).delSync();
|
||||||
|
},
|
||||||
|
);
|
||||||
if (success) {
|
if (success) {
|
||||||
SmartDialog.showToast(' Live Photo 已保存 ');
|
SmartDialog.showToast(' Live Photo 已保存 ');
|
||||||
} else {
|
} else {
|
||||||
@@ -141,7 +148,7 @@ class ImageUtil {
|
|||||||
fileName: videoName,
|
fileName: videoName,
|
||||||
androidRelativePath: "Pictures/PiliPlus",
|
androidRelativePath: "Pictures/PiliPlus",
|
||||||
skipIfExists: false,
|
skipIfExists: false,
|
||||||
);
|
).whenComplete(() => File(videoPath).delSync());
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
SmartDialog.showToast(' 已保存 ');
|
SmartDialog.showToast(' 已保存 ');
|
||||||
} else {
|
} else {
|
||||||
@@ -174,12 +181,12 @@ class ImageUtil {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final isAndroid = Platform.isAndroid;
|
final isAndroid = Platform.isAndroid;
|
||||||
final tempPath = (await getTemporaryDirectory()).path;
|
final tempPath = await Utils.temporaryDirectory;
|
||||||
final futures = imgList.map((url) async {
|
final futures = imgList.map((url) async {
|
||||||
var name = Utils.getFileName(url);
|
final name = Utils.getFileName(url);
|
||||||
var filePath = '$tempPath/$name';
|
final filePath = '$tempPath/$name';
|
||||||
|
|
||||||
var response = await Request().downloadFile(
|
final response = await Request().downloadFile(
|
||||||
url.http2https,
|
url.http2https,
|
||||||
filePath,
|
filePath,
|
||||||
cancelToken: cancelToken,
|
cancelToken: cancelToken,
|
||||||
@@ -192,25 +199,26 @@ class ImageUtil {
|
|||||||
fileName: name,
|
fileName: name,
|
||||||
androidRelativePath: "Pictures/PiliPlus",
|
androidRelativePath: "Pictures/PiliPlus",
|
||||||
skipIfExists: false,
|
skipIfExists: false,
|
||||||
);
|
).whenComplete(() => File(filePath).delSync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return (
|
||||||
'filePath': filePath,
|
filePath: filePath,
|
||||||
'name': name,
|
name: name,
|
||||||
'statusCode': response.statusCode,
|
statusCode: response.statusCode,
|
||||||
};
|
);
|
||||||
});
|
});
|
||||||
final result = await Future.wait(futures, eagerError: true);
|
final result = await Future.wait(futures, eagerError: true);
|
||||||
if (!isAndroid) {
|
if (!isAndroid) {
|
||||||
for (Map res in result) {
|
for (var res in result) {
|
||||||
if (res['statusCode'] == 200) {
|
if (res.statusCode == 200) {
|
||||||
await SaverGallery.saveFile(
|
await SaverGallery.saveFile(
|
||||||
filePath: res['filePath'],
|
filePath: res.filePath,
|
||||||
fileName: res['name'],
|
fileName: res.name,
|
||||||
androidRelativePath: "Pictures/PiliPlus",
|
androidRelativePath: "Pictures/PiliPlus",
|
||||||
skipIfExists: false,
|
skipIfExists: false,
|
||||||
);
|
);
|
||||||
|
File(res.filePath).delSync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
@@ -21,30 +22,26 @@ class Utils {
|
|||||||
static int? _sdkInt;
|
static int? _sdkInt;
|
||||||
|
|
||||||
static Future<int> get sdkInt async {
|
static Future<int> get sdkInt async {
|
||||||
if (_sdkInt != null) {
|
return _sdkInt ??= (await DeviceInfoPlugin().androidInfo).version.sdkInt;
|
||||||
return _sdkInt!;
|
|
||||||
}
|
|
||||||
_sdkInt = (await DeviceInfoPlugin().androidInfo).version.sdkInt;
|
|
||||||
return _sdkInt!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool? _isIpad;
|
static bool? _isIpad;
|
||||||
|
|
||||||
static Future<bool> isIpad() async {
|
static Future<bool> get isIpad async {
|
||||||
if (_isIpad != null) {
|
if (!Platform.isIOS) return false;
|
||||||
return _isIpad!;
|
return _isIpad ??= (await DeviceInfoPlugin().iosInfo).model
|
||||||
}
|
.toLowerCase()
|
||||||
if (!Platform.isIOS) {
|
.contains('ipad');
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
static String? _tempDir;
|
||||||
IosDeviceInfo info = await deviceInfo.iosInfo;
|
|
||||||
_isIpad = info.model.toLowerCase().contains("ipad");
|
static Future<String> get temporaryDirectory async {
|
||||||
return _isIpad!;
|
return _tempDir ??= (await getTemporaryDirectory()).path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Rect?> get sharePositionOrigin async {
|
static Future<Rect?> get sharePositionOrigin async {
|
||||||
if (await Utils.isIpad()) {
|
if (await isIpad) {
|
||||||
final size = Get.size;
|
final size = Get.size;
|
||||||
return Rect.fromLTWH(
|
return Rect.fromLTWH(
|
||||||
0,
|
0,
|
||||||
@@ -58,7 +55,7 @@ class Utils {
|
|||||||
|
|
||||||
static Future<void> shareText(String text) async {
|
static Future<void> shareText(String text) async {
|
||||||
try {
|
try {
|
||||||
SharePlus.instance.share(
|
await SharePlus.instance.share(
|
||||||
ShareParams(
|
ShareParams(
|
||||||
text: text,
|
text: text,
|
||||||
sharePositionOrigin: await sharePositionOrigin,
|
sharePositionOrigin: await sharePositionOrigin,
|
||||||
|
|||||||
Reference in New Issue
Block a user