mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 07:05:15 +00:00
krille/import emoji improvements (#468)
* refactor: Move GUI into Popupmenu * refactor: Reuse save file method from MatrixFile
This commit is contained in:
parent
0c70017cd8
commit
e94fe74473
2 changed files with 32 additions and 49 deletions
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -11,12 +10,10 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:http/http.dart' hide Client;
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/utils/client_manager.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'import_archive_dialog.dart';
|
||||
import 'settings_emotes_view.dart';
|
||||
|
@ -343,32 +340,10 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
|
||||
if (output == null) return;
|
||||
|
||||
if (kIsWeb || PlatformInfos.isMobile) {
|
||||
await Share.shareXFiles(
|
||||
[XFile(fileName, bytes: Uint8List.fromList(output))],
|
||||
);
|
||||
} else {
|
||||
String? savePath = await FilePicker.platform
|
||||
.saveFile(fileName: fileName, allowedExtensions: ['zip']);
|
||||
|
||||
if (savePath == null) {
|
||||
// workaround for broken `xdg-desktop-portal-termfilechooser`
|
||||
if (PlatformInfos.isLinux) {
|
||||
final dir = await getDownloadsDirectory();
|
||||
if (dir == null) return;
|
||||
savePath = dir.uri.resolve(fileName).toFilePath();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final file = File(savePath);
|
||||
await file.writeAsBytes(output);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.savedEmotePack(savePath))),
|
||||
);
|
||||
}
|
||||
MatrixFile(
|
||||
name: fileName,
|
||||
bytes: Uint8List.fromList(output),
|
||||
).save(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import 'package:fluffychat/widgets/mxc_image.dart';
|
|||
import '../../widgets/matrix.dart';
|
||||
import 'settings_emotes.dart';
|
||||
|
||||
enum PopupMenuEmojiActions { import, export }
|
||||
|
||||
class EmotesSettingsView extends StatelessWidget {
|
||||
final EmotesSettingsController controller;
|
||||
|
||||
|
@ -23,6 +25,31 @@ class EmotesSettingsView extends StatelessWidget {
|
|||
appBar: AppBar(
|
||||
leading: const BackButton(),
|
||||
title: Text(L10n.of(context)!.emoteSettings),
|
||||
actions: [
|
||||
PopupMenuButton<PopupMenuEmojiActions>(
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case PopupMenuEmojiActions.export:
|
||||
controller.exportAsZip();
|
||||
break;
|
||||
case PopupMenuEmojiActions.import:
|
||||
controller.importEmojiZip();
|
||||
break;
|
||||
}
|
||||
},
|
||||
enabled: !controller.readonly,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: PopupMenuEmojiActions.import,
|
||||
child: Text(L10n.of(context)!.importFromZipFile),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: PopupMenuEmojiActions.export,
|
||||
child: Text(L10n.of(context)!.exportEmotePack),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: controller.showSave
|
||||
? FloatingActionButton(
|
||||
|
@ -33,20 +60,6 @@ class EmotesSettingsView extends StatelessWidget {
|
|||
body: MaxWidthBody(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
if (!controller.readonly)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: ListTile(
|
||||
title: Text(L10n.of(context)!.importFromZipFile),
|
||||
trailing: IconButton(
|
||||
tooltip: L10n.of(context)!.importZipFile,
|
||||
icon: const Icon(Icons.file_open),
|
||||
onPressed: controller.importEmojiZip,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!controller.readonly)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
|
@ -217,11 +230,6 @@ class EmotesSettingsView extends StatelessWidget {
|
|||
},
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.exportEmotePack),
|
||||
onTap: controller.exportAsZip,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue