Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Krille/import emoji improvements #468

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 5 additions & 30 deletions lib/pages/settings_emotes/settings_emotes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -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';
Expand Down Expand Up @@ -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);
},
);
}
Expand Down
46 changes: 27 additions & 19 deletions lib/pages/settings_emotes/settings_emotes_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,6 +25,31 @@ class EmotesSettingsView extends StatelessWidget {
appBar: AppBar(
leading: const BackButton(),
title: Text(L10n.of(context)!.emoteSettings),
actions: [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly prefer the prominent buttons but I can understand it's not anyone's preference. LGTM hence apart from the comment above.

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(
Expand All @@ -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(
Expand Down Expand Up @@ -217,11 +230,6 @@ class EmotesSettingsView extends StatelessWidget {
},
),
),
const Divider(),
ListTile(
title: Text(L10n.of(context)!.exportEmotePack),
onTap: controller.exportAsZip,
),
],
),
),
Expand Down