fix: emoji import from ZIP file
- fix invalid Navigator scope in Emoji import dialog - add progress bar to Emoji import dialog Fixes: #623 Signed-off-by: The one with the braid <info@braid.business>
This commit is contained in:
parent
fbaeb1807f
commit
fd35f31cb2
2 changed files with 53 additions and 39 deletions
|
|
@ -33,6 +33,8 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
|
||||||
|
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
|
|
||||||
|
double _progress = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_importFileMap();
|
_importFileMap();
|
||||||
|
|
@ -44,7 +46,11 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text(L10n.of(context)!.importEmojis),
|
title: Text(L10n.of(context)!.importEmojis),
|
||||||
content: _loading
|
content: _loading
|
||||||
? const Center(child: CircularProgressIndicator())
|
? Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: _progress,
|
||||||
|
),
|
||||||
|
)
|
||||||
: SingleChildScrollView(
|
: SingleChildScrollView(
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
alignment: WrapAlignment.spaceEvenly,
|
alignment: WrapAlignment.spaceEvenly,
|
||||||
|
|
@ -97,6 +103,7 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
|
||||||
Future<void> _addEmotePack() async {
|
Future<void> _addEmotePack() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
_loading = true;
|
_loading = true;
|
||||||
|
_progress = 0;
|
||||||
});
|
});
|
||||||
final imports = _importMap;
|
final imports = _importMap;
|
||||||
final successfulUploads = <String>{};
|
final successfulUploads = <String>{};
|
||||||
|
|
@ -134,52 +141,56 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final entry in imports.entries) {
|
for (final entry in imports.entries) {
|
||||||
|
setState(() {
|
||||||
|
_progress += 1 / imports.length;
|
||||||
|
});
|
||||||
final file = entry.key;
|
final file = entry.key;
|
||||||
final imageCode = entry.value;
|
final imageCode = entry.value;
|
||||||
|
|
||||||
// try {
|
|
||||||
var mxcFile = MatrixImageFile(
|
|
||||||
bytes: file.content,
|
|
||||||
name: file.name,
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
mxcFile = (await mxcFile.generateThumbnail(
|
var mxcFile = MatrixImageFile(
|
||||||
|
bytes: file.content,
|
||||||
|
name: file.name,
|
||||||
|
);
|
||||||
|
|
||||||
|
final thumbnail = (await mxcFile.generateThumbnail(
|
||||||
nativeImplementations: ClientManager.nativeImplementations,
|
nativeImplementations: ClientManager.nativeImplementations,
|
||||||
))!;
|
));
|
||||||
} catch (e, s) {
|
if (thumbnail == null) {
|
||||||
Logs().w('Unable to create thumbnail', e, s);
|
Logs().w('Unable to create thumbnail');
|
||||||
}
|
|
||||||
final uri = await Matrix.of(context).client.uploadContent(
|
|
||||||
mxcFile.bytes,
|
|
||||||
filename: mxcFile.name,
|
|
||||||
contentType: mxcFile.mimeType,
|
|
||||||
);
|
|
||||||
|
|
||||||
final info = <String, dynamic>{
|
|
||||||
...mxcFile.info,
|
|
||||||
};
|
|
||||||
|
|
||||||
// normalize width / height to 256, required for stickers
|
|
||||||
if (info['w'] is int && info['h'] is int) {
|
|
||||||
final ratio = info['w'] / info['h'];
|
|
||||||
if (info['w'] > info['h']) {
|
|
||||||
info['w'] = 256;
|
|
||||||
info['h'] = (256.0 / ratio).round();
|
|
||||||
} else {
|
} else {
|
||||||
info['h'] = 256;
|
mxcFile = thumbnail;
|
||||||
info['w'] = (ratio * 256.0).round();
|
|
||||||
}
|
}
|
||||||
}
|
final uri = await Matrix.of(context).client.uploadContent(
|
||||||
widget.controller.pack!.images[imageCode] =
|
mxcFile.bytes,
|
||||||
ImagePackImageContent.fromJson(<String, dynamic>{
|
filename: mxcFile.name,
|
||||||
'url': uri.toString(),
|
contentType: mxcFile.mimeType,
|
||||||
'info': info,
|
);
|
||||||
});
|
|
||||||
successfulUploads.add(file.name);
|
|
||||||
/*} catch (e) {
|
|
||||||
|
|
||||||
Logs().d('Could not upload emote $imageCode');
|
final info = <String, dynamic>{
|
||||||
}*/
|
...mxcFile.info,
|
||||||
|
};
|
||||||
|
|
||||||
|
// normalize width / height to 256, required for stickers
|
||||||
|
if (info['w'] is int && info['h'] is int) {
|
||||||
|
final ratio = info['w'] / info['h'];
|
||||||
|
if (info['w'] > info['h']) {
|
||||||
|
info['w'] = 256;
|
||||||
|
info['h'] = (256.0 / ratio).round();
|
||||||
|
} else {
|
||||||
|
info['h'] = 256;
|
||||||
|
info['w'] = (ratio * 256.0).round();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
widget.controller.pack!.images[imageCode] =
|
||||||
|
ImagePackImageContent.fromJson(<String, dynamic>{
|
||||||
|
'url': uri.toString(),
|
||||||
|
'info': info,
|
||||||
|
});
|
||||||
|
successfulUploads.add(file.name);
|
||||||
|
} catch (e) {
|
||||||
|
Logs().d('Could not upload emote $imageCode');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await widget.controller.save(context);
|
await widget.controller.save(context);
|
||||||
|
|
@ -188,6 +199,7 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
|
||||||
);
|
);
|
||||||
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
|
_progress = 0;
|
||||||
|
|
||||||
// in case we have unhandled / duplicated emotes left, don't pop
|
// in case we have unhandled / duplicated emotes left, don't pop
|
||||||
if (mounted) setState(() {});
|
if (mounted) setState(() {});
|
||||||
|
|
|
||||||
|
|
@ -309,6 +309,8 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
||||||
|
|
||||||
await showDialog(
|
await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
// breaks [Matrix.of] calls otherwise
|
||||||
|
useRootNavigator: false,
|
||||||
builder: (context) => ImportEmoteArchiveDialog(
|
builder: (context) => ImportEmoteArchiveDialog(
|
||||||
controller: this,
|
controller: this,
|
||||||
archive: archive,
|
archive: archive,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue