mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-04-30 05:54:26 +02:00
feat: Show recommendation version when possible
This commit is contained in:
parent
d0fb6ac3c0
commit
ce6f11f3f2
@ -50,7 +50,10 @@
|
|||||||
"widgetTitle": "Select application",
|
"widgetTitle": "Select application",
|
||||||
"widgetTitleSelected": "Selected application",
|
"widgetTitleSelected": "Selected application",
|
||||||
"widgetSubtitle": "No application selected.",
|
"widgetSubtitle": "No application selected.",
|
||||||
"noAppsLabel": "No applications found."
|
"noAppsLabel": "No applications found.",
|
||||||
|
"currentVersion": "Current",
|
||||||
|
"recommendedVersion": "Recommended",
|
||||||
|
"anyVersion": "any"
|
||||||
},
|
},
|
||||||
"patchSelectorCard": {
|
"patchSelectorCard": {
|
||||||
"widgetTitle": "Select patches",
|
"widgetTitle": "Select patches",
|
||||||
|
@ -220,4 +220,32 @@ class PatcherAPI {
|
|||||||
log.writeAsStringSync(logs);
|
log.writeAsStringSync(logs);
|
||||||
ShareExtend.share(log.path, 'file');
|
ShareExtend.share(log.path, 'file');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getRecommendedVersion(String packageName) {
|
||||||
|
Map<String, int> versions = {};
|
||||||
|
for (Patch patch in _patches) {
|
||||||
|
Package? package = patch.compatiblePackages.firstWhereOrNull(
|
||||||
|
(pack) => pack.name == packageName,
|
||||||
|
);
|
||||||
|
if (package != null) {
|
||||||
|
for (String version in package.versions) {
|
||||||
|
versions.update(
|
||||||
|
version,
|
||||||
|
(value) => versions[version]! + 1,
|
||||||
|
ifAbsent: () => 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (versions.isNotEmpty) {
|
||||||
|
var entries = versions.entries.toList()
|
||||||
|
..sort((a, b) => a.value.compareTo(b.value));
|
||||||
|
versions
|
||||||
|
..clear()
|
||||||
|
..addEntries(entries);
|
||||||
|
versions.removeWhere((key, value) => value != versions.values.last);
|
||||||
|
return (versions.keys.toList()..sort()).last;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,4 +79,32 @@ class PatcherViewModel extends BaseViewModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getAppSelectionString() {
|
||||||
|
String text = '${selectedApp!.name} (${selectedApp!.packageName})';
|
||||||
|
if (text.length > 32) {
|
||||||
|
text = '${text.substring(0, 32)}...)';
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getRecommendedVersionString(BuildContext context) {
|
||||||
|
String recommendedVersion =
|
||||||
|
_patcherAPI.getRecommendedVersion(selectedApp!.packageName);
|
||||||
|
if (recommendedVersion.isEmpty) {
|
||||||
|
recommendedVersion = FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'appSelectorCard.anyVersion',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
recommendedVersion = 'v$recommendedVersion';
|
||||||
|
}
|
||||||
|
return '${FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'appSelectorCard.currentVersion',
|
||||||
|
)}: v${selectedApp!.version}\n${FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'appSelectorCard.recommendedVersion',
|
||||||
|
)}: $recommendedVersion';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class AppSelectorCard extends StatelessWidget {
|
|||||||
: Row(
|
: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 16.0,
|
height: 18.0,
|
||||||
child: ClipOval(
|
child: ClipOval(
|
||||||
child: Image.memory(
|
child: Image.memory(
|
||||||
locator<PatcherViewModel>().selectedApp == null
|
locator<PatcherViewModel>().selectedApp == null
|
||||||
@ -49,8 +49,23 @@ class AppSelectorCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 6),
|
||||||
Text(_getAppSelection()),
|
Text(locator<PatcherViewModel>().getAppSelectionString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
locator<PatcherViewModel>().selectedApp == null
|
||||||
|
? Container()
|
||||||
|
: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 20),
|
||||||
|
child: Text(
|
||||||
|
locator<PatcherViewModel>()
|
||||||
|
.getRecommendedVersionString(context),
|
||||||
|
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -58,10 +73,4 @@ class AppSelectorCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getAppSelection() {
|
|
||||||
String name = locator<PatcherViewModel>().selectedApp!.name;
|
|
||||||
String version = locator<PatcherViewModel>().selectedApp!.version;
|
|
||||||
return '$name (v$version)';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user