Added category filter

This commit is contained in:
Imran Remtulla
2022-12-21 04:15:39 -05:00
parent 26f953dbb0
commit 118460ccb9
3 changed files with 46 additions and 36 deletions

View File

@@ -177,20 +177,8 @@ class _AppPageState extends State<AppPage> {
title: 'Pick a Category',
items: [
[
GeneratedFormItem(
'category', // TODO
label: 'Category',
opts: [
MapEntry('',
'No Category'),
...categories
.entries
.map((e) =>
MapEntry(
e.key,
e.key))
.toList()
])
settingsProvider
.getCategoryFormItem()
]
]);
}).then((value) {

View File

@@ -80,9 +80,7 @@ class AppsPageState extends State<AppsPage> {
!(filter!.includeNonInstalled)) {
return false;
}
if (filter!.nameFilter.isEmpty && filter!.authorFilter.isEmpty) {
return true;
}
if (filter!.nameFilter.isNotEmpty || filter!.authorFilter.isNotEmpty) {
List<String> nameTokens = filter!.nameFilter
.split(' ')
.where((element) => element.trim().isNotEmpty)
@@ -103,6 +101,11 @@ class AppsPageState extends State<AppsPage> {
return false;
}
}
}
if (filter!.categoryFilter.isNotEmpty &&
filter!.categoryFilter != app.app.category) {
return false;
}
return true;
}).toList();
}
@@ -726,6 +729,10 @@ class AppsPageState extends State<AppsPage> {
label: tr('nonInstalledApps'),
type: FormItemType.bool,
defaultValue: vals['nonInstalledApps'])
], // TODO
[
settingsProvider.getCategoryFormItem(
initCategory: vals['category'] ?? '')
]
]);
}).then((values) {
@@ -752,19 +759,22 @@ class AppsFilter {
late String authorFilter;
late bool includeUptodate;
late bool includeNonInstalled;
late String categoryFilter;
AppsFilter(
{this.nameFilter = '',
this.authorFilter = '',
this.includeUptodate = true,
this.includeNonInstalled = true});
this.includeNonInstalled = true,
this.categoryFilter = ''});
Map<String, String> toValuesMap() {
return {
'appName': nameFilter,
'author': authorFilter,
'upToDateApps': includeUptodate ? 'true' : '',
'nonInstalledApps': includeNonInstalled ? 'true' : ''
'nonInstalledApps': includeNonInstalled ? 'true' : '',
'category': categoryFilter
};
}
@@ -773,11 +783,13 @@ class AppsFilter {
authorFilter = values['author']!;
includeUptodate = values['upToDateApps'] == 'true';
includeNonInstalled = values['nonInstalledApps'] == 'true';
categoryFilter = values['category']!;
}
bool isIdenticalTo(AppsFilter other) =>
authorFilter.trim() == other.authorFilter.trim() &&
nameFilter.trim() == other.nameFilter.trim() &&
includeUptodate == other.includeUptodate &&
includeNonInstalled == other.includeNonInstalled;
includeNonInstalled == other.includeNonInstalled &&
categoryFilter.trim() == other.categoryFilter.trim();
}

View File

@@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:obtainium/app_sources/github.dart';
import 'package:obtainium/components/generated_form.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -153,4 +154,13 @@ class SettingsProvider with ChangeNotifier {
set categories(Map<String, int> cats) {
prefs?.setString('categories', jsonEncode(cats));
}
getCategoryFormItem({String initCategory = ''}) =>
GeneratedFormItem('category', // TODO
label: 'Category',
opts: [
const MapEntry('', 'No Category'),
...categories.entries.map((e) => MapEntry(e.key, e.key)).toList()
],
defaultValue: initCategory);
}