Added URL selection menu for mass imports

This commit is contained in:
Imran Remtulla
2022-09-28 22:33:55 -04:00
parent 1a68b8abe6
commit e706661062

View File

@@ -267,30 +267,44 @@ class _ImportExportPageState extends State<ImportExportPage> {
); );
}).then((values) { }).then((values) {
if (values != null) { if (values != null) {
source
.getUrls(values)
.then((urls) {
setState(() { setState(() {
importInProgress = true; importInProgress = true;
}); });
addApps(urls) source
.then((errors) { .getUrls(values)
if (errors.isEmpty) { .then((urls) {
ScaffoldMessenger.of( showDialog<List<String>?>(
context)
.showSnackBar(
SnackBar(
content: Text(
'Imported ${urls.length} Apps')),
);
} else {
showDialog(
context: context, context: context,
builder:
(BuildContext
ctx) {
return UrlSelectionModal(
urls: urls);
})
.then((selectedUrls) {
if (selectedUrls !=
null) {
addApps(selectedUrls)
.then((errors) {
if (errors
.isEmpty) {
ScaffoldMessenger
.of(context)
.showSnackBar(
SnackBar(
content: Text(
'Imported ${selectedUrls.length} Apps')),
);
} else {
showDialog(
context:
context,
builder: builder:
(BuildContext (BuildContext
ctx) { ctx) {
return ImportErrorDialog( return ImportErrorDialog(
urlsLength: urls urlsLength:
selectedUrls
.length, .length,
errors: errors:
errors); errors);
@@ -302,7 +316,18 @@ class _ImportExportPageState extends State<ImportExportPage> {
false; false;
}); });
}); });
} else {
setState(() {
importInProgress =
false;
});
}
});
}).catchError((e) { }).catchError((e) {
setState(() {
importInProgress =
false;
});
ScaffoldMessenger.of( ScaffoldMessenger.of(
context) context)
.showSnackBar( .showSnackBar(
@@ -376,3 +401,67 @@ class _ImportErrorDialogState extends State<ImportErrorDialog> {
); );
} }
} }
// ignore: must_be_immutable
class UrlSelectionModal extends StatefulWidget {
UrlSelectionModal({super.key, required this.urls});
List<String> urls;
@override
State<UrlSelectionModal> createState() => _UrlSelectionModalState();
}
class _UrlSelectionModalState extends State<UrlSelectionModal> {
Map<String, bool> urlSelections = {};
@override
void initState() {
super.initState();
for (var url in widget.urls) {
urlSelections.putIfAbsent(url, () => true);
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
scrollable: true,
title: const Text('Select URLs to Import'),
content: Column(children: [
...urlSelections.keys.map((url) {
return Row(children: [
Checkbox(
value: urlSelections[url],
onChanged: (value) {
setState(() {
urlSelections[url] = value ?? false;
});
}),
const SizedBox(
width: 8,
),
Expanded(
child: Text(
Uri.parse(url).path.substring(1),
))
]);
})
]),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel')),
TextButton(
onPressed: () {
Navigator.of(context).pop(urlSelections.keys
.where((url) => urlSelections[url] ?? false)
.toList());
},
child: Text(
'Import ${urlSelections.values.where((b) => b).length} URLs'))
],
);
}
}