From f53a4f3827aebf28979ee072fea1b34ce9cdc9a0 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Fri, 28 Jun 2024 19:10:45 -0400 Subject: [PATCH] Add third-party F-Droid repo search to main search menu (#1681) --- lib/app_sources/fdroidrepo.dart | 2 +- lib/pages/add_app.dart | 31 ++++++++++++++++++++++++++---- lib/providers/source_provider.dart | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/app_sources/fdroidrepo.dart b/lib/app_sources/fdroidrepo.dart index 41e92df..2872459 100644 --- a/lib/app_sources/fdroidrepo.dart +++ b/lib/app_sources/fdroidrepo.dart @@ -9,7 +9,7 @@ class FDroidRepo extends AppSource { FDroidRepo() { name = tr('fdroidThirdPartyRepo'); canSearch = true; - excludeFromMassSearch = true; + includeAdditionalOptsInMainSearch = true; neverAutoSelect = true; showReleaseDateAsVersionToggle = true; diff --git a/lib/pages/add_app.dart b/lib/pages/add_app.dart index 5dc17b0..248c813 100644 --- a/lib/pages/add_app.dart +++ b/lib/pages/add_app.dart @@ -259,9 +259,7 @@ class AddAppPageState extends State { searching = true; }); var sourceStrings = >{}; - sourceProvider.sources - .where((e) => e.canSearch && !e.excludeFromMassSearch) - .forEach((s) { + sourceProvider.sources.where((e) => e.canSearch).forEach((s) { sourceStrings[s.name] = [s.name]; }); try { @@ -286,7 +284,32 @@ class AddAppPageState extends State { .where((e) => searchSources.contains(e.name)) .map((e) async { try { - return await e.search(searchQuery); + Map? querySettings = {}; + if (e.includeAdditionalOptsInMainSearch) { + querySettings = await showDialog?>( + context: context, + builder: (BuildContext ctx) { + return GeneratedFormModal( + title: tr('searchX', args: [e.name]), + items: [ + ...e.searchQuerySettingFormItems.map((e) => [e]), + [ + GeneratedFormTextField('url', + label: e.hosts.isNotEmpty + ? tr('overrideSource') + : plural('url', 1).substring(2), + defaultValue: + e.hosts.isNotEmpty ? e.hosts[0] : '', + required: true) + ], + ], + ); + }); + if (querySettings == null) { + return >{}; + } + } + return await e.search(searchQuery, querySettings: querySettings); } catch (err) { if (err is! CredsNeededError) { rethrow; diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 73d9b46..fded867 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -617,7 +617,7 @@ abstract class AppSource { } bool canSearch = false; - bool excludeFromMassSearch = false; + bool includeAdditionalOptsInMainSearch = false; List searchQuerySettingFormItems = []; Future>> search(String query, {Map querySettings = const {}}) {