fix: New json url for homeserver list

This commit is contained in:
krille-chan 2023-12-23 08:22:43 +01:00
commit 33839c4df8
No known key found for this signature in database
8 changed files with 138 additions and 54 deletions

View file

@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:matrix_homeserver_recommendations/matrix_homeserver_recommendations.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/homeserver_picker/public_homeserver.dart';
import 'homeserver_bottom_sheet.dart';
import 'homeserver_picker.dart';
@ -15,16 +15,26 @@ class HomeserverAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TypeAheadField<HomeserverBenchmarkResult>(
return TypeAheadField<PublicHomeserver>(
suggestionsBoxDecoration: SuggestionsBoxDecoration(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
elevation: Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4,
shadowColor: Theme.of(context).appBarTheme.shadowColor ?? Colors.black,
constraints: const BoxConstraints(maxHeight: 256),
),
noItemsFoundBuilder: (context) => ListTile(
leading: const Icon(Icons.search_outlined),
title: Text(L10n.of(context)!.nothingFound),
),
loadingBuilder: (context) => ListTile(
leading: const CircularProgressIndicator.adaptive(strokeWidth: 2),
title: Text(L10n.of(context)!.loadingPleaseWait),
),
itemBuilder: (context, homeserver) => ListTile(
title: Text(homeserver.homeserver.baseUrl.toString()),
subtitle: Text(homeserver.homeserver.description ?? ''),
title: Text(homeserver.name),
subtitle: homeserver.description == null
? null
: Text(homeserver.description ?? ''),
trailing: IconButton(
icon: const Icon(Icons.info_outlined),
onPressed: () => showModalBottomSheet(
@ -36,17 +46,25 @@ class HomeserverAppBar extends StatelessWidget {
),
),
suggestionsCallback: (pattern) async {
final homeserverList =
await const JoinmatrixOrgParser().fetchHomeservers();
final benchmark = await HomeserverListProvider.benchmarkHomeserver(
homeserverList,
timeout: const Duration(seconds: 3),
);
return benchmark;
pattern = pattern.toLowerCase().trim();
final homeservers = await controller.loadHomeserverList();
final matches = homeservers
.where(
(homeserver) =>
homeserver.name.toLowerCase().contains(pattern) ||
(homeserver.description?.toLowerCase().contains(pattern) ??
false),
)
.toList();
if (pattern.contains('.') &&
pattern.split('.').any((part) => part.isNotEmpty) &&
!matches.any((homeserver) => homeserver.name == pattern)) {
matches.add(PublicHomeserver(name: pattern));
}
return matches;
},
onSuggestionSelected: (suggestion) {
controller.homeserverController.text =
suggestion.homeserver.baseUrl.host;
controller.homeserverController.text = suggestion.name;
controller.checkHomeserverAction();
},
textFieldConfiguration: TextFieldConfiguration(