opt: filter added apps

This commit is contained in:
bggRGjQaUbCoE
2024-10-31 10:38:49 +08:00
parent 970161529c
commit d5160458e0
2 changed files with 54 additions and 28 deletions

View File

@@ -50,4 +50,18 @@ class AppInfo {
String toString() {
return toJson().toString();
}
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other is AppInfo) {
return packageName == other.packageName;
}
return false;
}
@override
int get hashCode => packageName.hashCode;
}

View File

@@ -75,21 +75,24 @@ class _AppWhitelistState extends State<AppWhitelist> {
actions: [
IconButton(
icon: const Icon(Icons.add),
onPressed: () {
onPressed: () async {
//添加
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const InstalledAppsWidget()))
.then((value) {
if (value != null) {
if (configuration.appWhitelist.contains(value)) {
return;
List<AppInfo> list = await Future.wait(appWhitelist);
if (context.mounted) {
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return InstalledAppsWidget(addedList: list);
})).then((value) {
if (value != null) {
if (configuration.appWhitelist.contains(value)) {
return;
}
setState(() {
configuration.appWhitelist.add(value);
changed = true;
});
}
setState(() {
configuration.appWhitelist.add(value);
changed = true;
});
}
});
});
}
},
),
],
@@ -203,22 +206,25 @@ class _AppBlacklistState extends State<AppBlacklist> {
actions: [
IconButton(
icon: const Icon(Icons.add),
onPressed: () {
onPressed: () async {
//添加
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const InstalledAppsWidget()))
.then((value) {
if (value != null) {
if (configuration.appBlacklist?.contains(value) == true) {
return;
List<AppInfo> list = await Future.wait(appBlacklist);
if (context.mounted) {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => InstalledAppsWidget(addedList: list)))
.then((value) {
if (value != null) {
if (configuration.appBlacklist?.contains(value) == true) {
return;
}
setState(() {
configuration.appBlacklist ??= [];
configuration.appBlacklist?.add(value);
changed = true;
});
}
setState(() {
configuration.appBlacklist ??= [];
configuration.appBlacklist?.add(value);
changed = true;
});
}
});
});
}
},
),
],
@@ -267,7 +273,12 @@ class _AppBlacklistState extends State<AppBlacklist> {
///已安装的app列表
class InstalledAppsWidget extends StatefulWidget {
const InstalledAppsWidget({super.key});
const InstalledAppsWidget({
super.key,
required this.addedList,
});
final List<AppInfo> addedList;
@override
State<InstalledAppsWidget> createState() => _InstalledAppsWidgetState();
@@ -306,6 +317,7 @@ class _InstalledAppsWidgetState extends State<InstalledAppsWidget> {
builder: (BuildContext context, AsyncSnapshot<List<AppInfo>> snapshot) {
if (snapshot.hasData) {
List<AppInfo> appInfoList = snapshot.data!;
appInfoList = appInfoList.toSet().difference(widget.addedList.toSet()).toList();
if (keyword != null && keyword!.trim().isNotEmpty) {
appInfoList = appInfoList
.where((element) =>