mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: Hide empty patches category labels (#1439)
This commit is contained in:
parent
ba44fa620f
commit
0be568bbbd
@ -3,9 +3,7 @@ import 'package:flutter_i18n/flutter_i18n.dart';
|
|||||||
import 'package:revanced_manager/app/app.locator.dart';
|
import 'package:revanced_manager/app/app.locator.dart';
|
||||||
import 'package:revanced_manager/services/manager_api.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
|
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
|
||||||
import 'package:revanced_manager/ui/widgets/patchesSelectorView/patch_item.dart';
|
|
||||||
import 'package:revanced_manager/ui/widgets/shared/search_bar.dart';
|
import 'package:revanced_manager/ui/widgets/shared/search_bar.dart';
|
||||||
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
|
|
||||||
import 'package:stacked/stacked.dart';
|
import 'package:stacked/stacked.dart';
|
||||||
|
|
||||||
class PatchesSelectorView extends StatefulWidget {
|
class PatchesSelectorView extends StatefulWidget {
|
||||||
@ -182,187 +180,39 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (model.newPatchExists())
|
if (model.getQueriedPatches(_query).any((patch) => model.isPatchNew(patch)))
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
model.getPatchCategory(context, 'patchesSelectorView.newPatches'),
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 10.0,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 10.0,
|
|
||||||
bottom: 10.0,
|
|
||||||
left: 5.0,
|
|
||||||
),
|
|
||||||
child: I18nText(
|
|
||||||
'patchesSelectorView.newPatches',
|
|
||||||
child: Text(
|
|
||||||
'',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...model.getQueriedPatches(_query).map((patch) {
|
...model.getQueriedPatches(_query).map((patch) {
|
||||||
if (model.isPatchNew(patch)) {
|
if (model.isPatchNew(patch)) {
|
||||||
return PatchItem(
|
return model.getPatchItem(context, patch);
|
||||||
name: patch.name,
|
|
||||||
simpleName: patch.getSimpleName(),
|
|
||||||
description: patch.description ?? '',
|
|
||||||
packageVersion:
|
|
||||||
model.getAppInfo().version,
|
|
||||||
supportedPackageVersions:
|
|
||||||
model.getSupportedVersions(patch),
|
|
||||||
isUnsupported: !isPatchSupported(patch),
|
|
||||||
isChangeEnabled:
|
|
||||||
_managerAPI.isPatchesChangeEnabled(),
|
|
||||||
hasUnsupportedPatchOption:
|
|
||||||
hasUnsupportedRequiredOption(
|
|
||||||
patch.options,
|
|
||||||
patch,
|
|
||||||
),
|
|
||||||
options: patch.options,
|
|
||||||
isSelected: model.isSelected(patch),
|
|
||||||
navigateToOptions: (options) =>
|
|
||||||
model.navigateToPatchOptions(
|
|
||||||
options,
|
|
||||||
patch,
|
|
||||||
),
|
|
||||||
onChanged: (value) => model.selectPatch(
|
|
||||||
patch,
|
|
||||||
value,
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Padding(
|
if (model.getQueriedPatches(_query).any((patch) => !model.isPatchNew(patch) && patch.compatiblePackages.isNotEmpty))
|
||||||
padding: const EdgeInsets.symmetric(
|
model.getPatchCategory(context, 'patchesSelectorView.patches'),
|
||||||
vertical: 10.0,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 10.0,
|
|
||||||
bottom: 10.0,
|
|
||||||
left: 5.0,
|
|
||||||
),
|
|
||||||
child: I18nText(
|
|
||||||
'patchesSelectorView.patches',
|
|
||||||
child: Text(
|
|
||||||
'',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
...model.getQueriedPatches(_query).map(
|
...model.getQueriedPatches(_query).map(
|
||||||
(patch) {
|
(patch) {
|
||||||
if (patch.compatiblePackages.isNotEmpty) {
|
if (patch.compatiblePackages.isNotEmpty && !model.isPatchNew(patch)) {
|
||||||
return PatchItem(
|
return model.getPatchItem(context, patch);
|
||||||
name: patch.name,
|
|
||||||
simpleName: patch.getSimpleName(),
|
|
||||||
description: patch.description ?? '',
|
|
||||||
packageVersion: model.getAppInfo().version,
|
|
||||||
supportedPackageVersions:
|
|
||||||
model.getSupportedVersions(patch),
|
|
||||||
isUnsupported: !isPatchSupported(patch),
|
|
||||||
isChangeEnabled:
|
|
||||||
_managerAPI.isPatchesChangeEnabled(),
|
|
||||||
hasUnsupportedPatchOption:
|
|
||||||
hasUnsupportedRequiredOption(
|
|
||||||
patch.options,
|
|
||||||
patch,
|
|
||||||
),
|
|
||||||
options: patch.options,
|
|
||||||
isSelected: model.isSelected(patch),
|
|
||||||
navigateToOptions: (options) =>
|
|
||||||
model.navigateToPatchOptions(
|
|
||||||
options,
|
|
||||||
patch,
|
|
||||||
),
|
|
||||||
onChanged: (value) => model.selectPatch(
|
|
||||||
patch,
|
|
||||||
value,
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (_managerAPI.areUniversalPatchesEnabled())
|
if (model.getQueriedPatches(_query).any((patch) => patch.compatiblePackages.isEmpty))
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
model.getPatchCategory(context, 'patchesSelectorView.universalPatches'),
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 10.0,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 10.0,
|
|
||||||
bottom: 10.0,
|
|
||||||
left: 5.0,
|
|
||||||
),
|
|
||||||
child: I18nText(
|
|
||||||
'patchesSelectorView.universalPatches',
|
|
||||||
child: Text(
|
|
||||||
'',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...model.getQueriedPatches(_query).map((patch) {
|
...model.getQueriedPatches(_query).map((patch) {
|
||||||
if (patch.compatiblePackages.isEmpty) {
|
if (patch.compatiblePackages.isEmpty && !model.isPatchNew(patch)) {
|
||||||
return PatchItem(
|
return model.getPatchItem(context, patch);
|
||||||
name: patch.name,
|
|
||||||
simpleName: patch.getSimpleName(),
|
|
||||||
description: patch.description ?? '',
|
|
||||||
packageVersion:
|
|
||||||
model.getAppInfo().version,
|
|
||||||
supportedPackageVersions:
|
|
||||||
model.getSupportedVersions(patch),
|
|
||||||
isUnsupported: !isPatchSupported(patch),
|
|
||||||
isChangeEnabled:
|
|
||||||
_managerAPI.isPatchesChangeEnabled(),
|
|
||||||
hasUnsupportedPatchOption:
|
|
||||||
hasUnsupportedRequiredOption(
|
|
||||||
patch.options,
|
|
||||||
patch,
|
|
||||||
),
|
|
||||||
options: patch.options,
|
|
||||||
isSelected: model.isSelected(patch),
|
|
||||||
navigateToOptions: (options) =>
|
|
||||||
model.navigateToPatchOptions(
|
|
||||||
options,
|
|
||||||
patch,
|
|
||||||
),
|
|
||||||
onChanged: (value) => model.selectPatch(
|
|
||||||
patch,
|
|
||||||
value,
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import 'package:revanced_manager/services/manager_api.dart';
|
|||||||
import 'package:revanced_manager/services/patcher_api.dart';
|
import 'package:revanced_manager/services/patcher_api.dart';
|
||||||
import 'package:revanced_manager/services/toast.dart';
|
import 'package:revanced_manager/services/toast.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||||
|
import 'package:revanced_manager/ui/widgets/patchesSelectorView/patch_item.dart';
|
||||||
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
|
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
|
||||||
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
|
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
|
||||||
import 'package:stacked/stacked.dart';
|
import 'package:stacked/stacked.dart';
|
||||||
@ -224,6 +225,57 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget getPatchItem(BuildContext context, Patch patch) {
|
||||||
|
return PatchItem(
|
||||||
|
name: patch.name,
|
||||||
|
simpleName: patch.getSimpleName(),
|
||||||
|
description: patch.description ?? '',
|
||||||
|
packageVersion: getAppInfo().version,
|
||||||
|
supportedPackageVersions: getSupportedVersions(patch),
|
||||||
|
isUnsupported: !isPatchSupported(patch),
|
||||||
|
isChangeEnabled: _managerAPI.isPatchesChangeEnabled(),
|
||||||
|
hasUnsupportedPatchOption: hasUnsupportedRequiredOption(
|
||||||
|
patch.options,
|
||||||
|
patch,
|
||||||
|
),
|
||||||
|
options: patch.options,
|
||||||
|
isSelected: isSelected(patch),
|
||||||
|
navigateToOptions: (options) => navigateToPatchOptions(
|
||||||
|
options,
|
||||||
|
patch,
|
||||||
|
),
|
||||||
|
onChanged: (value) => selectPatch(
|
||||||
|
patch,
|
||||||
|
value,
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget getPatchCategory(BuildContext context, String category) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 10.0,
|
||||||
|
),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10.0,
|
||||||
|
bottom: 10.0,
|
||||||
|
left: 5.0,
|
||||||
|
),
|
||||||
|
child: I18nText(
|
||||||
|
category,
|
||||||
|
child: Text(
|
||||||
|
'',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
PatchedApplication getAppInfo() {
|
PatchedApplication getAppInfo() {
|
||||||
return locator<PatcherViewModel>().selectedApp!;
|
return locator<PatcherViewModel>().selectedApp!;
|
||||||
}
|
}
|
||||||
@ -239,12 +291,6 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool newPatchExists() {
|
|
||||||
return patches.any(
|
|
||||||
(patch) => isPatchNew(patch),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> getSupportedVersions(Patch patch) {
|
List<String> getSupportedVersions(Patch patch) {
|
||||||
final PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
|
final PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
|
||||||
final Package? package = patch.compatiblePackages.firstWhereOrNull(
|
final Package? package = patch.compatiblePackages.firstWhereOrNull(
|
||||||
|
Loading…
Reference in New Issue
Block a user