Added "Group by Category" setting

This commit is contained in:
Imran Remtulla
2023-03-30 23:40:32 -04:00
parent 814e269d1d
commit 4e17bbcfd1
13 changed files with 118 additions and 16 deletions

View File

@@ -21,7 +21,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart';
// ignore: implementation_imports
import 'package:easy_localization/src/localization.dart';
const String currentVersion = '0.11.16';
const String currentVersion = '0.11.17';
const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES

View File

@@ -187,6 +187,25 @@ class AppsPageState extends State<AppsPage> {
}
listedApps = [...tempPinned, ...tempNotPinned];
List<String?> getListedCategories() {
var temp = listedApps
.map((e) => e.app.categories.isNotEmpty ? e.app.categories : [null]);
return temp.isNotEmpty
? {
...temp.reduce((v, e) => [...v, ...e])
}.toList()
: [];
}
var listedCategories = getListedCategories();
listedCategories.sort((a, b) {
return a != null && b != null
? a.compareTo(b)
: a == null
? 1
: -1;
});
showChangeLogDialog(
String? changesUrl, AppSource appSource, String changeLog, int index) {
showDialog(
@@ -402,17 +421,37 @@ class AppsPageState extends State<AppsPage> {
],
);
var transparent = const Color.fromARGB(0, 0, 0, 0).value;
var transparent =
Theme.of(context).colorScheme.background.withAlpha(0).value;
List<double> stops = [
...listedApps[index]
.app
.categories
.asMap()
.entries
.map((e) =>
((e.key / (listedApps[index].app.categories.length - 1))))
.toList(),
1
];
if (stops.length == 2) {
stops[0] = 1;
}
return Container(
decoration: BoxDecoration(
border: Border.symmetric(
vertical: BorderSide(
width: 4,
color: Color(listedApps[index].app.categories.isNotEmpty
? settingsProvider.categories[
listedApps[index].app.categories.first] ??
transparent
: transparent)))),
gradient: LinearGradient(
stops: stops,
begin: const Alignment(-1, 0),
end: const Alignment(-0.97, 0),
colors: [
...listedApps[index]
.app
.categories
.map((e) =>
Color(settingsProvider.categories[e]!).withAlpha(255))
.toList(),
Color(transparent)
])),
child: ListTile(
tileColor: listedApps[index].app.pinned
? Colors.grey.withOpacity(0.1)
@@ -465,6 +504,28 @@ class AppsPageState extends State<AppsPage> {
));
}
getCategoryCollapsibleTile(int index) {
var tiles = listedApps
.asMap()
.entries
.where((e) =>
e.value.app.categories.contains(listedCategories[index]) ||
e.value.app.categories.isEmpty && listedCategories[index] == null)
.map((e) => getSingleAppHorizTile(e.key))
.toList();
capFirstChar(String str) => str[0].toUpperCase() + str.substring(1);
return ExpansionTile(
initiallyExpanded: true,
title: Text(
capFirstChar(listedCategories[index] ?? tr('noCategory')),
style: const TextStyle(fontWeight: FontWeight.bold),
),
controlAffinity: ListTileControlAffinity.leading,
trailing: Text(tiles.length.toString()),
children: tiles);
}
getSelectAllButton() {
return selectedApps.isEmpty
? TextButton.icon(
@@ -903,6 +964,22 @@ class AppsPageState extends State<AppsPage> {
);
}
getDisplayedList() {
return settingsProvider.groupByCategory &&
!(listedCategories.isEmpty ||
(listedCategories.length == 1 && listedCategories[0] == null))
? SliverList(
delegate:
SliverChildBuilderDelegate((BuildContext context, int index) {
return getCategoryCollapsibleTile(index);
}, childCount: listedCategories.length))
: SliverList(
delegate:
SliverChildBuilderDelegate((BuildContext context, int index) {
return getSingleAppHorizTile(index);
}, childCount: listedApps.length));
}
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: RefreshIndicator(
@@ -922,11 +999,7 @@ class AppsPageState extends State<AppsPage> {
child: CustomScrollView(slivers: <Widget>[
CustomAppBar(title: tr('appsString')),
...getLoadingWidgets(),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return getSingleAppHorizTile(index);
}, childCount: listedApps.length))
getDisplayedList()
])),
persistentFooterButtons: appsProvider.apps.isEmpty
? null

View File

@@ -262,6 +262,18 @@ class _SettingsPageState extends State<SettingsPage> {
})
],
),
height16,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(tr('groupByCategory')),
Switch(
value: settingsProvider.groupByCategory,
onChanged: (value) {
settingsProvider.groupByCategory = value;
})
],
),
const Divider(
height: 16,
),

View File

@@ -139,6 +139,15 @@ class SettingsProvider with ChangeNotifier {
notifyListeners();
}
bool get groupByCategory {
return prefs?.getBool('groupByCategory') ?? false;
}
set groupByCategory(bool show) {
prefs?.setBool('groupByCategory', show);
notifyListeners();
}
String? getSettingString(String settingId) {
return prefs?.getString(settingId);
}