Added categorize in multi select menu

This commit is contained in:
Imran Remtulla
2022-12-27 20:15:56 -05:00
parent 8ddeb3d776
commit 8f16f745be
9 changed files with 106 additions and 19 deletions

View File

@@ -55,7 +55,8 @@ class AppsPageState extends State<AppsPage> {
var appsProvider = context.watch<AppsProvider>();
var settingsProvider = context.watch<SettingsProvider>();
var sortedApps = appsProvider.apps.values.toList();
var currentFilterIsUpdatesOnly = filter.isIdenticalTo(updatesOnlyFilter);
var currentFilterIsUpdatesOnly =
filter.isIdenticalTo(updatesOnlyFilter, settingsProvider);
selectedApps = selectedApps
.where((element) => sortedApps.map((e) => e.app).contains(element))
@@ -348,6 +349,7 @@ class AppsPageState extends State<AppsPage> {
children: [
selectedApps.isEmpty
? IconButton(
visualDensity: VisualDensity.compact,
onPressed: () {
selectThese(sortedApps.map((e) => e.app).toList());
},
@@ -357,6 +359,8 @@ class AppsPageState extends State<AppsPage> {
),
tooltip: tr('selectAll'))
: TextButton.icon(
style:
const ButtonStyle(visualDensity: VisualDensity.compact),
onPressed: () {
selectedApps.isEmpty
? selectThese(sortedApps.map((e) => e.app).toList())
@@ -501,6 +505,73 @@ class AppsPageState extends State<AppsPage> {
icon: const Icon(
Icons.file_download_outlined,
)),
selectedApps.isEmpty
? const SizedBox()
: IconButton(
visualDensity: VisualDensity.compact,
onPressed: () async {
try {
Set<String>? preselected;
var showPrompt = false;
for (var element in selectedApps) {
var currentCats = element.categories.toSet();
if (preselected == null) {
preselected = currentCats;
} else {
if (!settingsProvider.setEqual(
currentCats, preselected)) {
showPrompt = true;
break;
}
}
}
var cont = true;
if (showPrompt) {
cont = await showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
title: tr('categorize'),
items: const [],
initValid: true,
message:
tr('selectedCategorizeWarning'),
);
}) !=
null;
}
if (cont) {
await showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
title: tr('categorize'),
items: const [],
initValid: true,
singleNullReturnButton: tr('ok'),
additionalWidgets: [
CategoryEditorSelector(
preselected: preselected ?? {},
showLabelWhenNotEmpty: false,
onSelected: (categories) {
appsProvider
.saveApps(selectedApps.map((e) {
e.categories = categories;
return e;
}).toList());
},
)
],
);
});
}
} catch (err) {
showError(err, context);
}
},
tooltip: tr('categorize'),
icon: const Icon(Icons.category_outlined),
),
selectedApps.isEmpty
? const SizedBox()
: IconButton(
@@ -697,12 +768,15 @@ class AppsPageState extends State<AppsPage> {
appsProvider.apps.isEmpty
? const SizedBox()
: TextButton.icon(
style:
const ButtonStyle(visualDensity: VisualDensity.compact),
label: Text(
filter.isIdenticalTo(neutralFilter)
filter.isIdenticalTo(neutralFilter, settingsProvider)
? tr('filter')
: tr('filterActive'),
style: TextStyle(
fontWeight: filter.isIdenticalTo(neutralFilter)
fontWeight: filter.isIdenticalTo(
neutralFilter, settingsProvider)
? FontWeight.normal
: FontWeight.bold),
),
@@ -794,12 +868,10 @@ class AppsFilter {
includeNonInstalled = values['nonInstalledApps'];
}
bool isIdenticalTo(AppsFilter other) =>
bool isIdenticalTo(AppsFilter other, SettingsProvider settingsProvider) =>
authorFilter.trim() == other.authorFilter.trim() &&
nameFilter.trim() == other.nameFilter.trim() &&
includeUptodate == other.includeUptodate &&
includeNonInstalled == other.includeNonInstalled &&
categoryFilter.length == other.categoryFilter.length &&
categoryFilter.union(other.categoryFilter).length ==
categoryFilter.length;
settingsProvider.setEqual(categoryFilter, other.categoryFilter);
}