Skip to content

Commit

Permalink
Adding from custom fdroid repos is easier (name based)
Browse files Browse the repository at this point in the history
  • Loading branch information
Imran Remtulla committed Dec 16, 2022
1 parent f6ca5d4 commit 049b023
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"removeAppQuestion": "Remove App?",
"yesMarkUpdated": "Yes, Mark as Updated",
"fdroid": "F-Droid",
"appId": "App ID",
"appIdOrName": "App ID or Name",
"appWithIdOrNameNotFound": "No App was found with that ID or Name",
"reposHaveMultipleApps": "Repos may contain multiple Apps",
"fdroidThirdPartyRepo": "F-Droid Third-Party Repo",
"tooManyRequestsTryAgainInMinutes": {
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"removeAppQuestion": "Rimuovere App?",
"yesMarkUpdated": "Sì, contrassegna come aggiornato",
"fdroid": "F-Droid",
"appId": "App ID",
"appIdOrName": "App ID or Name",
"appWithIdOrNameNotFound": "No App was found with that ID or Name",
"reposHaveMultipleApps": "Repos may contain multiple Apps",
"fdroidThirdPartyRepo": "F-Droid Third-Party Repo",
"tooManyRequestsTryAgainInMinutes": {
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"removeAppQuestion": "Remove App?",
"yesMarkUpdated": "Yes, Mark as Updated",
"fdroid": "F-Droid",
"appId": "App ID",
"appIdOrName": "App ID or Name",
"appWithIdOrNameNotFound": "No App was found with that ID or Name",
"reposHaveMultipleApps": "Repos may contain multiple Apps",
"fdroidThirdPartyRepo": "F-Droid Third-Party Repo",
"tooManyRequestsTryAgainInMinutes": {
Expand Down
51 changes: 30 additions & 21 deletions lib/app_sources/fdroidRepo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class FDroidRepo extends AppSource {
additionalSourceAppSpecificFormItems = [
[
GeneratedFormItem(
label: tr('appId'),
label: tr('appIdOrName'),
hint: tr('reposHaveMultipleApps'),
required: true,
key: 'appId')
key: 'appIdOrName')
]
];
}
Expand All @@ -31,37 +31,46 @@ class FDroidRepo extends AppSource {
return url.substring(0, match.end);
}

@override
String? tryInferringAppId(String standardUrl,
{List<String> additionalData = const []}) {
return findGeneratedFormValueByKey(
additionalSourceAppSpecificFormItems
.reduce((value, element) => [...value, ...element]),
additionalData,
'appId');
}

@override
Future<APKDetails> getLatestAPKDetails(
String standardUrl, List<String> additionalData,
{bool trackOnly = false}) async {
String? appId =
tryInferringAppId(standardUrl, additionalData: additionalData);
if (appId == null) {
String? appIdOrName = findGeneratedFormValueByKey(
additionalSourceAppSpecificFormItems
.reduce((value, element) => [...value, ...element]),
additionalData,
'appIdOrName');
if (appIdOrName == null) {
throw NoReleasesError();
}
var res = await get(Uri.parse('$standardUrl/index.xml'));
if (res.statusCode == 200) {
var body = parse(res.body);
var foundApps = body
.querySelectorAll('application')
.where((element) => element.attributes['id'] == appId)
.toList();
var foundApps = body.querySelectorAll('application').where((element) {
return element.attributes['id'] == appIdOrName;
}).toList();
if (foundApps.isEmpty) {
foundApps = body.querySelectorAll('application').where((element) {
return element.querySelector('name')?.innerHtml.toLowerCase() ==
appIdOrName.toLowerCase();
}).toList();
}
if (foundApps.isEmpty) {
foundApps = body.querySelectorAll('application').where((element) {
return element
.querySelector('name')
?.innerHtml
.toLowerCase()
.contains(appIdOrName.toLowerCase()) ??
false;
}).toList();
}
if (foundApps.isEmpty) {
throw NoReleasesError();
throw ObtainiumError(tr('appWithIdOrNameNotFound'));
}
var authorName = body.querySelector('repo')?.attributes['name'] ?? name;
var appName = foundApps[0].querySelector('name')?.innerHtml ?? appId;
var appName =
foundApps[0].querySelector('name')?.innerHtml ?? appIdOrName;
var releases = foundApps[0].querySelectorAll('package');
String? latestVersion = releases[0].querySelector('version')?.innerHtml;
if (latestVersion == null) {
Expand Down

0 comments on commit 049b023

Please sign in to comment.