2022-02-05 00:44:18 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:matrix_homeserver_recommendations/matrix_homeserver_recommendations.dart';
|
|
|
|
import 'package:url_launcher/link.dart';
|
|
|
|
|
2022-03-12 12:48:34 +01:00
|
|
|
import 'package:fluffychat/pages/homeserver_picker/homeserver_picker.dart';
|
|
|
|
|
2022-02-05 00:44:18 +01:00
|
|
|
class HomeserverTile extends StatelessWidget {
|
|
|
|
final HomeserverBenchmarkResult benchmark;
|
2022-03-12 12:48:34 +01:00
|
|
|
final HomeserverPickerController controller;
|
2022-02-05 00:44:18 +01:00
|
|
|
|
|
|
|
const HomeserverTile(
|
2022-03-12 12:48:34 +01:00
|
|
|
{Key? key, required this.benchmark, required this.controller})
|
2022-02-05 00:44:18 +01:00
|
|
|
: super(key: key);
|
2022-03-12 12:48:34 +01:00
|
|
|
|
2022-02-05 00:44:18 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-12 12:48:34 +01:00
|
|
|
final domain = benchmark.homeserver.baseUrl.host;
|
2022-02-05 00:44:18 +01:00
|
|
|
return ExpansionTile(
|
2022-03-12 12:48:34 +01:00
|
|
|
leading: Radio(
|
|
|
|
value: domain,
|
|
|
|
groupValue: controller.domain,
|
|
|
|
onChanged: controller.domain == domain
|
|
|
|
? (s) => controller.unsetDomain
|
|
|
|
: controller.setDomain),
|
|
|
|
onExpansionChanged: controller.domain == domain
|
|
|
|
? (o) => controller.unsetDomain()
|
|
|
|
: (o) => controller.setDomain(domain),
|
2022-02-05 00:44:18 +01:00
|
|
|
title: Text(benchmark.homeserver.baseUrl.host),
|
|
|
|
subtitle: benchmark.homeserver.description != null
|
|
|
|
? Text(benchmark.homeserver.description!)
|
|
|
|
: null,
|
|
|
|
children: [
|
|
|
|
benchmark.homeserver.antiFeatures != null &&
|
|
|
|
benchmark.homeserver.antiFeatures!.isNotEmpty
|
|
|
|
? ListTile(
|
|
|
|
leading: const Icon(Icons.thumb_down),
|
|
|
|
title: Text(benchmark.homeserver.antiFeatures!),
|
|
|
|
subtitle: Text(L10n.of(context)!.antiFeatures),
|
|
|
|
)
|
|
|
|
: ListTile(
|
|
|
|
leading: const Icon(Icons.recommend),
|
|
|
|
title: Text(L10n.of(context)!.noAntiFeaturesRecorded),
|
|
|
|
),
|
|
|
|
if (benchmark.homeserver.jurisdiction != null)
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.public),
|
|
|
|
title: Text(benchmark.homeserver.jurisdiction!),
|
|
|
|
subtitle: Text(L10n.of(context)!.jurisdiction),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.speed),
|
|
|
|
title: Text("${benchmark.responseTime!.inMilliseconds} ms"),
|
|
|
|
subtitle: Text(L10n.of(context)!.responseTime),
|
|
|
|
),
|
|
|
|
ButtonBar(
|
|
|
|
/* spacing: 8,
|
|
|
|
runSpacing: 8,
|
|
|
|
alignment: WrapAlignment.end,
|
|
|
|
runAlignment: WrapAlignment.center,
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center, */
|
|
|
|
children: [
|
|
|
|
if (benchmark.homeserver.privacyPolicy != null)
|
|
|
|
Link(
|
|
|
|
uri: benchmark.homeserver.privacyPolicy!,
|
|
|
|
target: LinkTarget.blank,
|
|
|
|
builder: (context, callback) => TextButton(
|
|
|
|
onPressed: callback,
|
|
|
|
child: Text(L10n.of(context)!.privacy),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (benchmark.homeserver.rules != null)
|
|
|
|
Link(
|
|
|
|
uri: benchmark.homeserver.rules!,
|
|
|
|
target: LinkTarget.blank,
|
|
|
|
builder: (context, callback) => TextButton(
|
|
|
|
onPressed: callback,
|
|
|
|
child: Text(L10n.of(context)!.serverRules),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:48:34 +01:00
|
|
|
class CustomHomeserverTile extends StatelessWidget {
|
|
|
|
final String domain;
|
|
|
|
final VoidCallback onSelect;
|
|
|
|
|
|
|
|
const CustomHomeserverTile(
|
|
|
|
{Key? key, required this.domain, required this.onSelect})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(domain),
|
|
|
|
subtitle: Text(L10n.of(context)!.customHomeserver),
|
|
|
|
trailing: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_forward),
|
|
|
|
onPressed: onSelect,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 00:44:18 +01:00
|
|
|
class JoinMatrixAttributionTile extends StatelessWidget {
|
|
|
|
final parser = JoinmatrixOrgParser();
|
|
|
|
|
|
|
|
JoinMatrixAttributionTile({Key? key}) : super(key: key);
|
2022-03-12 12:48:34 +01:00
|
|
|
|
2022-02-05 00:44:18 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(L10n.of(context)!.serverListJoinMatrix),
|
|
|
|
subtitle: ButtonBar(children: [
|
|
|
|
Link(
|
|
|
|
uri: parser.externalUri,
|
|
|
|
target: LinkTarget.blank,
|
|
|
|
builder: (context, callback) => TextButton(
|
|
|
|
onPressed: callback,
|
|
|
|
child: Text(L10n.of(context)!.openServerList),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Link(
|
|
|
|
uri: parser.errorReportUrl,
|
|
|
|
target: LinkTarget.blank,
|
|
|
|
builder: (context, callback) => TextButton(
|
|
|
|
onPressed: callback,
|
|
|
|
child: Text(L10n.of(context)!.reportServerListProblem),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|