2023-02-24 16:45:32 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2024-01-31 05:14:23 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-04 18:58:25 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
import 'package:selfprivacy/config/brand_theme.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2021-08-29 15:02:51 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
2022-10-04 18:58:25 +00:00
|
|
|
import 'package:selfprivacy/logic/models/service.dart';
|
2021-03-18 00:55:38 +00:00
|
|
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
2023-09-24 01:17:54 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
2023-09-24 01:17:54 +00:00
|
|
|
import 'package:selfprivacy/ui/helpers/empty_page_placeholder.dart';
|
2023-02-24 16:45:32 +00:00
|
|
|
import 'package:selfprivacy/ui/router/router.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/utils/breakpoints.dart';
|
2023-01-17 13:23:26 +00:00
|
|
|
import 'package:selfprivacy/utils/launch_url.dart';
|
2021-03-26 13:38:39 +00:00
|
|
|
import 'package:selfprivacy/utils/ui_helpers.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2020-12-01 19:08:19 +00:00
|
|
|
class ServicesPage extends StatefulWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const ServicesPage({super.key});
|
2020-12-01 19:08:19 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<ServicesPage> createState() => _ServicesPageState();
|
2020-12-01 19:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _ServicesPageState extends State<ServicesPage> {
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2022-12-31 05:08:25 +00:00
|
|
|
final services = [...context.watch<ServicesCubit>().state.services];
|
|
|
|
services
|
|
|
|
.sort((final a, final b) => a.status.index.compareTo(b.status.index));
|
|
|
|
|
2020-12-01 19:08:19 +00:00
|
|
|
return Scaffold(
|
2023-02-23 14:49:14 +00:00
|
|
|
appBar: Breakpoints.small.isActive(context)
|
|
|
|
? PreferredSize(
|
|
|
|
preferredSize: const Size.fromHeight(52),
|
|
|
|
child: BrandHeader(
|
|
|
|
title: 'basis.services'.tr(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2023-09-24 01:17:54 +00:00
|
|
|
body: !isReady
|
|
|
|
? EmptyPagePlaceholder(
|
|
|
|
showReadyCard: true,
|
|
|
|
title: 'service_page.nothing_here'.tr(),
|
|
|
|
description: 'basis.please_connect'.tr(),
|
2023-09-26 17:20:13 +00:00
|
|
|
iconData: BrandIcons.box,
|
2023-03-27 17:02:44 +00:00
|
|
|
)
|
2023-09-24 01:17:54 +00:00
|
|
|
: RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
|
|
|
await context.read<ServicesCubit>().reload();
|
|
|
|
},
|
|
|
|
child: ListView(
|
|
|
|
padding: paddingH15V0,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'basis.services_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
...services.map(
|
|
|
|
(final service) => Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
bottom: 30,
|
|
|
|
),
|
|
|
|
child: _Card(service: service),
|
|
|
|
),
|
2023-11-06 13:15:38 +00:00
|
|
|
),
|
2023-09-24 01:17:54 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2020-12-01 19:08:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _Card extends StatelessWidget {
|
2022-10-04 18:58:25 +00:00
|
|
|
const _Card({required this.service});
|
2020-12-01 19:08:19 +00:00
|
|
|
|
2022-10-04 18:58:25 +00:00
|
|
|
final Service service;
|
2020-12-01 19:08:19 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2021-08-29 15:02:51 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final config = context.watch<ServerInstallationCubit>().state;
|
|
|
|
final domainName = UiHelpers.getDomainName(config);
|
2021-12-23 13:52:12 +00:00
|
|
|
|
2022-12-31 02:31:59 +00:00
|
|
|
StateType getStatus(final ServiceStatus status) {
|
|
|
|
switch (status) {
|
|
|
|
case ServiceStatus.active:
|
|
|
|
return StateType.stable;
|
|
|
|
case ServiceStatus.activating:
|
|
|
|
return StateType.stable;
|
|
|
|
case ServiceStatus.deactivating:
|
|
|
|
return StateType.uninitialized;
|
|
|
|
case ServiceStatus.inactive:
|
|
|
|
return StateType.uninitialized;
|
|
|
|
case ServiceStatus.failed:
|
|
|
|
return StateType.error;
|
|
|
|
case ServiceStatus.off:
|
|
|
|
return StateType.uninitialized;
|
|
|
|
case ServiceStatus.reloading:
|
|
|
|
return StateType.stable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:45:32 +00:00
|
|
|
return Card(
|
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
child: InkResponse(
|
|
|
|
highlightShape: BoxShape.rectangle,
|
|
|
|
onTap: isReady
|
2023-03-27 17:29:02 +00:00
|
|
|
? () => context.pushRoute(
|
|
|
|
ServiceRoute(serviceId: service.id),
|
2023-02-24 16:45:32 +00:00
|
|
|
)
|
|
|
|
: null,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
IconStatusMask(
|
|
|
|
status: getStatus(service.status),
|
|
|
|
icon: SvgPicture.string(
|
|
|
|
service.svgIcon,
|
|
|
|
width: 30.0,
|
|
|
|
height: 30.0,
|
|
|
|
colorFilter: const ColorFilter.mode(
|
|
|
|
Colors.white,
|
|
|
|
BlendMode.srcIn,
|
|
|
|
),
|
|
|
|
),
|
2022-10-04 18:58:25 +00:00
|
|
|
),
|
2023-09-18 15:42:40 +00:00
|
|
|
const SizedBox(width: 8),
|
2023-09-18 15:22:37 +00:00
|
|
|
Text(
|
|
|
|
service.displayName,
|
|
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
|
|
),
|
2023-02-24 16:45:32 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2021-09-02 19:32:07 +00:00
|
|
|
children: [
|
2023-03-27 17:02:44 +00:00
|
|
|
const SizedBox(height: 8),
|
2023-02-24 16:45:32 +00:00
|
|
|
if (service.url != '' && service.url != null)
|
|
|
|
Column(
|
|
|
|
children: [
|
2023-03-27 17:02:44 +00:00
|
|
|
_ServiceLink(
|
|
|
|
url: service.url ?? '',
|
2021-12-23 13:52:12 +00:00
|
|
|
),
|
2023-09-18 15:42:40 +00:00
|
|
|
const SizedBox(height: 8),
|
2023-02-24 16:45:32 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
if (service.id == 'mailserver')
|
|
|
|
Column(
|
|
|
|
children: [
|
2023-03-27 17:02:44 +00:00
|
|
|
_ServiceLink(
|
|
|
|
url: domainName,
|
|
|
|
isActive: false,
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2023-09-18 15:42:40 +00:00
|
|
|
const SizedBox(height: 8),
|
2023-02-24 16:45:32 +00:00
|
|
|
],
|
|
|
|
),
|
2023-03-27 17:02:44 +00:00
|
|
|
Text(
|
2023-09-16 03:45:15 +00:00
|
|
|
service.description,
|
2023-03-27 17:02:44 +00:00
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
2023-09-18 15:42:40 +00:00
|
|
|
const SizedBox(height: 8),
|
2023-03-27 17:02:44 +00:00
|
|
|
Text(
|
2023-09-16 03:45:15 +00:00
|
|
|
service.loginInfo,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
2023-03-27 17:02:44 +00:00
|
|
|
),
|
2023-09-18 15:42:40 +00:00
|
|
|
const SizedBox(height: 8),
|
2021-09-02 19:32:07 +00:00
|
|
|
],
|
2023-11-06 13:15:38 +00:00
|
|
|
),
|
2023-02-24 16:45:32 +00:00
|
|
|
],
|
|
|
|
),
|
2021-03-18 00:55:38 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-03-27 17:02:44 +00:00
|
|
|
|
|
|
|
class _ServiceLink extends StatelessWidget {
|
|
|
|
const _ServiceLink({
|
|
|
|
required this.url,
|
|
|
|
this.isActive = true,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String url;
|
|
|
|
final bool isActive;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => GestureDetector(
|
|
|
|
onTap: isActive
|
|
|
|
? () => launchURL(
|
|
|
|
url,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
child: Text(
|
|
|
|
url,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|