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:async';
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.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:future_loading_dialog/future_loading_dialog.dart';
|
||||||
import 'package:http/http.dart' hide Client;
|
import 'package:http/http.dart' hide Client;
|
||||||
import 'package:matrix/matrix.dart';
|
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:vrouter/vrouter.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/client_manager.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 '../../widgets/matrix.dart';
|
||||||
import 'import_archive_dialog.dart';
|
import 'import_archive_dialog.dart';
|
||||||
import 'settings_emotes_view.dart';
|
import 'settings_emotes_view.dart';
|
||||||
|
|
@ -343,32 +340,10 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
||||||
|
|
||||||
if (output == null) return;
|
if (output == null) return;
|
||||||
|
|
||||||
if (kIsWeb || PlatformInfos.isMobile) {
|
MatrixFile(
|
||||||
await Share.shareXFiles(
|
name: fileName,
|
||||||
[XFile(fileName, bytes: Uint8List.fromList(output))],
|
bytes: Uint8List.fromList(output),
|
||||||
);
|
).save(context);
|
||||||
} 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))),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import 'package:fluffychat/widgets/mxc_image.dart';
|
||||||
import '../../widgets/matrix.dart';
|
import '../../widgets/matrix.dart';
|
||||||
import 'settings_emotes.dart';
|
import 'settings_emotes.dart';
|
||||||
|
|
||||||
|
enum PopupMenuEmojiActions { import, export }
|
||||||
|
|
||||||
class EmotesSettingsView extends StatelessWidget {
|
class EmotesSettingsView extends StatelessWidget {
|
||||||
final EmotesSettingsController controller;
|
final EmotesSettingsController controller;
|
||||||
|
|
||||||
|
|
@ -23,6 +25,31 @@ class EmotesSettingsView extends StatelessWidget {
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: const BackButton(),
|
leading: const BackButton(),
|
||||||
title: Text(L10n.of(context)!.emoteSettings),
|
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: controller.showSave
|
||||||
? FloatingActionButton(
|
? FloatingActionButton(
|
||||||
|
|
@ -33,20 +60,6 @@ class EmotesSettingsView extends StatelessWidget {
|
||||||
body: MaxWidthBody(
|
body: MaxWidthBody(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
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)
|
if (!controller.readonly)
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
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…
Add table
Add a link
Reference in a new issue