mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-30 21:13:28 +01:00 
			
		
		
		
	URL selection modal improvements (incl. #460)
This commit is contained in:
		| @@ -506,7 +506,7 @@ class _UrlSelectionModalState extends State<UrlSelectionModal> { | |||||||
|           widget.onlyOneSelectionAllowed ? tr('selectURL') : tr('selectURLs')), |           widget.onlyOneSelectionAllowed ? tr('selectURL') : tr('selectURLs')), | ||||||
|       content: Column(children: [ |       content: Column(children: [ | ||||||
|         ...urlWithDescriptionSelections.keys.map((urlWithD) { |         ...urlWithDescriptionSelections.keys.map((urlWithD) { | ||||||
|           select(bool? value) { |           selectThis(bool? value) { | ||||||
|             setState(() { |             setState(() { | ||||||
|               value ??= false; |               value ??= false; | ||||||
|               if (value! && widget.onlyOneSelectionAllowed) { |               if (value! && widget.onlyOneSelectionAllowed) { | ||||||
| @@ -517,11 +517,56 @@ class _UrlSelectionModalState extends State<UrlSelectionModal> { | |||||||
|             }); |             }); | ||||||
|           } |           } | ||||||
|  |  | ||||||
|           return Row(children: [ |           var urlLink = GestureDetector( | ||||||
|  |               onTap: () { | ||||||
|  |                 launchUrlString(urlWithD.key, | ||||||
|  |                     mode: LaunchMode.externalApplication); | ||||||
|  |               }, | ||||||
|  |               child: Text( | ||||||
|  |                 Uri.parse(urlWithD.key).path.substring(1), | ||||||
|  |                 style: const TextStyle(decoration: TextDecoration.underline), | ||||||
|  |                 textAlign: TextAlign.start, | ||||||
|  |               )); | ||||||
|  |  | ||||||
|  |           var descriptionText = Text( | ||||||
|  |             urlWithD.value.length > 128 | ||||||
|  |                 ? '${urlWithD.value.substring(0, 128)}...' | ||||||
|  |                 : urlWithD.value, | ||||||
|  |             style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 12), | ||||||
|  |           ); | ||||||
|  |  | ||||||
|  |           var selectedUrlsWithDs = urlWithDescriptionSelections.entries | ||||||
|  |               .where((e) => e.value) | ||||||
|  |               .toList(); | ||||||
|  |  | ||||||
|  |           var singleSelectTile = ListTile( | ||||||
|  |             title: urlLink, | ||||||
|  |             subtitle: GestureDetector( | ||||||
|  |               onTap: () { | ||||||
|  |                 setState(() { | ||||||
|  |                   selectOnlyOne(urlWithD.key); | ||||||
|  |                 }); | ||||||
|  |               }, | ||||||
|  |               child: descriptionText, | ||||||
|  |             ), | ||||||
|  |             leading: Radio<String>( | ||||||
|  |               value: urlWithD.key, | ||||||
|  |               groupValue: selectedUrlsWithDs.isEmpty | ||||||
|  |                   ? null | ||||||
|  |                   : selectedUrlsWithDs.first.key.key, | ||||||
|  |               onChanged: (value) { | ||||||
|  |                 setState(() { | ||||||
|  |                   selectOnlyOne(urlWithD.key); | ||||||
|  |                 }); | ||||||
|  |               }, | ||||||
|  |             ), | ||||||
|  |           ); | ||||||
|  |  | ||||||
|  |           var multiSelectTile = Row(children: [ | ||||||
|             Checkbox( |             Checkbox( | ||||||
|                 value: urlWithDescriptionSelections[urlWithD], |                 value: urlWithDescriptionSelections[urlWithD], | ||||||
|                 onChanged: (value) { |                 onChanged: (value) { | ||||||
|                   select(value); |                   selectThis(value); | ||||||
|                 }), |                 }), | ||||||
|             const SizedBox( |             const SizedBox( | ||||||
|               width: 8, |               width: 8, | ||||||
| @@ -534,28 +579,13 @@ class _UrlSelectionModalState extends State<UrlSelectionModal> { | |||||||
|                 const SizedBox( |                 const SizedBox( | ||||||
|                   height: 8, |                   height: 8, | ||||||
|                 ), |                 ), | ||||||
|  |                 urlLink, | ||||||
|                 GestureDetector( |                 GestureDetector( | ||||||
|                   onTap: () { |                   onTap: () { | ||||||
|                       launchUrlString(urlWithD.key, |                     selectThis( | ||||||
|                           mode: LaunchMode.externalApplication); |                         !(urlWithDescriptionSelections[urlWithD] ?? false)); | ||||||
|                   }, |                   }, | ||||||
|                     child: Text( |                   child: descriptionText, | ||||||
|                       Uri.parse(urlWithD.key).path.substring(1), |  | ||||||
|                       style: |  | ||||||
|                           const TextStyle(decoration: TextDecoration.underline), |  | ||||||
|                       textAlign: TextAlign.start, |  | ||||||
|                     )), |  | ||||||
|                 GestureDetector( |  | ||||||
|                   onTap: () { |  | ||||||
|                     select(!(urlWithDescriptionSelections[urlWithD] ?? false)); |  | ||||||
|                   }, |  | ||||||
|                   child: Text( |  | ||||||
|                     urlWithD.value.length > 128 |  | ||||||
|                         ? '${urlWithD.value.substring(0, 128)}...' |  | ||||||
|                         : urlWithD.value, |  | ||||||
|                     style: const TextStyle( |  | ||||||
|                         fontStyle: FontStyle.italic, fontSize: 12), |  | ||||||
|                   ), |  | ||||||
|                 ), |                 ), | ||||||
|                 const SizedBox( |                 const SizedBox( | ||||||
|                   height: 8, |                   height: 8, | ||||||
| @@ -563,6 +593,10 @@ class _UrlSelectionModalState extends State<UrlSelectionModal> { | |||||||
|               ], |               ], | ||||||
|             )) |             )) | ||||||
|           ]); |           ]); | ||||||
|  |  | ||||||
|  |           return widget.onlyOneSelectionAllowed | ||||||
|  |               ? singleSelectTile | ||||||
|  |               : multiSelectTile; | ||||||
|         }) |         }) | ||||||
|       ]), |       ]), | ||||||
|       actions: [ |       actions: [ | ||||||
|   | |||||||
| @@ -913,7 +913,7 @@ class AppsProvider with ChangeNotifier { | |||||||
|  |  | ||||||
|   Future<List<List<String>>> addAppsByURL(List<String> urls) async { |   Future<List<List<String>>> addAppsByURL(List<String> urls) async { | ||||||
|     List<dynamic> results = await SourceProvider().getAppsByURLNaive(urls, |     List<dynamic> results = await SourceProvider().getAppsByURLNaive(urls, | ||||||
|         ignoreUrls: apps.values.map((e) => e.app.url).toList()); |         alreadyAddedUrls: apps.values.map((e) => e.app.url).toList()); | ||||||
|     List<App> pps = results[0]; |     List<App> pps = results[0]; | ||||||
|     Map<String, dynamic> errorsMap = results[1]; |     Map<String, dynamic> errorsMap = results[1]; | ||||||
|     for (var app in pps) { |     for (var app in pps) { | ||||||
|   | |||||||
| @@ -519,11 +519,14 @@ class SourceProvider { | |||||||
|  |  | ||||||
|   // Returns errors in [results, errors] instead of throwing them |   // Returns errors in [results, errors] instead of throwing them | ||||||
|   Future<List<dynamic>> getAppsByURLNaive(List<String> urls, |   Future<List<dynamic>> getAppsByURLNaive(List<String> urls, | ||||||
|       {List<String> ignoreUrls = const []}) async { |       {List<String> alreadyAddedUrls = const []}) async { | ||||||
|     List<App> apps = []; |     List<App> apps = []; | ||||||
|     Map<String, dynamic> errors = {}; |     Map<String, dynamic> errors = {}; | ||||||
|     for (var url in urls.where((element) => !ignoreUrls.contains(element))) { |     for (var url in urls) { | ||||||
|       try { |       try { | ||||||
|  |         if (alreadyAddedUrls.contains(url)) { | ||||||
|  |           throw ObtainiumError(tr('appAlreadyAdded')); | ||||||
|  |         } | ||||||
|         var source = getSource(url); |         var source = getSource(url); | ||||||
|         apps.add(await getApp( |         apps.add(await getApp( | ||||||
|             source, |             source, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user