2022-02-16 07:01:05 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/config/brand_colors.dart';
|
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
2022-05-14 02:54:40 +00:00
|
|
|
import 'package:selfprivacy/logic/models/json/backup.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
2022-02-16 07:01:05 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
2021-12-06 18:31:19 +00:00
|
|
|
|
|
|
|
class BackupDetails extends StatefulWidget {
|
2022-06-05 22:40:34 +00:00
|
|
|
const BackupDetails({final super.key});
|
2021-12-06 18:31:19 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<BackupDetails> createState() => _BackupDetailsState();
|
2021-12-06 18:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _BackupDetailsState extends State<BackupDetails>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2022-06-05 22:40:34 +00:00
|
|
|
final bool isBackupInitialized =
|
|
|
|
context.watch<BackupsCubit>().state.isInitialized;
|
|
|
|
final BackupStatusEnum backupStatus =
|
|
|
|
context.watch<BackupsCubit>().state.status;
|
2022-06-05 19:36:32 +00:00
|
|
|
final StateType providerState = isReady && isBackupInitialized
|
2021-12-06 18:31:19 +00:00
|
|
|
? (backupStatus == BackupStatusEnum.error
|
|
|
|
? StateType.warning
|
|
|
|
: StateType.stable)
|
|
|
|
: StateType.uninitialized;
|
2022-06-05 22:40:34 +00:00
|
|
|
final bool preventActions =
|
|
|
|
context.watch<BackupsCubit>().state.preventActions;
|
2022-06-05 19:36:32 +00:00
|
|
|
final double backupProgress = context.watch<BackupsCubit>().state.progress;
|
|
|
|
final String backupError = context.watch<BackupsCubit>().state.error;
|
|
|
|
final List<Backup> backups = context.watch<BackupsCubit>().state.backups;
|
|
|
|
final bool refreshing = context.watch<BackupsCubit>().state.refreshing;
|
2021-12-06 18:31:19 +00:00
|
|
|
|
2022-02-16 07:01:05 +00:00
|
|
|
return BrandHeroScreen(
|
|
|
|
heroIcon: BrandIcons.save,
|
|
|
|
heroTitle: 'providers.backup.card_title'.tr(),
|
|
|
|
heroSubtitle: 'providers.backup.bottom_sheet.1'.tr(),
|
|
|
|
children: [
|
|
|
|
if (isReady && !isBackupInitialized)
|
|
|
|
BrandButton.rised(
|
|
|
|
onPressed: preventActions
|
|
|
|
? null
|
|
|
|
: () async {
|
|
|
|
await context.read<BackupsCubit>().createBucket();
|
|
|
|
},
|
|
|
|
text: 'providers.backup.initialize'.tr(),
|
|
|
|
),
|
|
|
|
if (backupStatus == BackupStatusEnum.initializing)
|
|
|
|
BrandText.body1('providers.backup.waitingForRebuild'.tr()),
|
|
|
|
if (backupStatus != BackupStatusEnum.initializing &&
|
|
|
|
backupStatus != BackupStatusEnum.noKey)
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (backupStatus == BackupStatusEnum.initialized)
|
|
|
|
ListTile(
|
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () async {
|
|
|
|
await context.read<BackupsCubit>().createBackup();
|
|
|
|
},
|
2022-05-24 18:55:39 +00:00
|
|
|
leading: const Icon(
|
2022-02-16 07:01:05 +00:00
|
|
|
Icons.add_circle_outline_rounded,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.create_new'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (backupStatus == BackupStatusEnum.backingUp)
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.creating'.tr(
|
2022-06-05 22:40:34 +00:00
|
|
|
args: [(backupProgress * 100).round().toString()],
|
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
subtitle: LinearProgressIndicator(
|
|
|
|
value: backupProgress,
|
|
|
|
backgroundColor: Colors.grey.withOpacity(0.2),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (backupStatus == BackupStatusEnum.restoring)
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.restoring'.tr(
|
2022-06-05 22:40:34 +00:00
|
|
|
args: [(backupProgress * 100).round().toString()],
|
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
subtitle: LinearProgressIndicator(
|
|
|
|
backgroundColor: Colors.grey.withOpacity(0.2),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (backupStatus == BackupStatusEnum.error)
|
|
|
|
ListTile(
|
2022-05-24 18:55:39 +00:00
|
|
|
leading: const Icon(
|
2022-02-16 07:01:05 +00:00
|
|
|
Icons.error_outline,
|
|
|
|
color: BrandColors.red1,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.error_pending'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16),
|
2022-02-16 07:01:05 +00:00
|
|
|
// Card with a list of existing backups
|
|
|
|
// Each list item has a date
|
|
|
|
// When clicked, starts the restore action
|
|
|
|
if (backupStatus != BackupStatusEnum.initializing &&
|
|
|
|
backupStatus != BackupStatusEnum.noKey)
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ListTile(
|
2022-05-24 18:55:39 +00:00
|
|
|
leading: const Icon(
|
2022-02-16 07:01:05 +00:00
|
|
|
Icons.refresh,
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
title: Text(
|
|
|
|
'providers.backup.restore'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const Divider(
|
2022-02-16 07:01:05 +00:00
|
|
|
height: 1.0,
|
|
|
|
),
|
|
|
|
if (backups.isEmpty)
|
|
|
|
ListTile(
|
2022-05-24 18:55:39 +00:00
|
|
|
leading: const Icon(
|
2022-02-16 07:01:05 +00:00
|
|
|
Icons.error_outline,
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
title: Text('providers.backup.no_backups'.tr()),
|
|
|
|
),
|
|
|
|
if (backups.isNotEmpty)
|
|
|
|
Column(
|
2022-06-05 22:40:34 +00:00
|
|
|
children: backups
|
|
|
|
.map(
|
|
|
|
(final Backup backup) => ListTile(
|
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
final NavigationService nav =
|
|
|
|
getIt<NavigationService>();
|
|
|
|
nav.showPopUpDialog(
|
|
|
|
BrandAlert(
|
|
|
|
title:
|
|
|
|
'providers.backup.restoring'.tr(),
|
|
|
|
contentText:
|
|
|
|
'providers.backup.restore_alert'.tr(
|
|
|
|
args: [backup.time.toString()],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
ActionButton(
|
|
|
|
text: 'basis.cancel'.tr(),
|
|
|
|
),
|
|
|
|
ActionButton(
|
|
|
|
onPressed: () => {
|
|
|
|
context
|
|
|
|
.read<BackupsCubit>()
|
|
|
|
.restoreBackup(backup.id)
|
|
|
|
},
|
|
|
|
text: 'modals.yes'.tr(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
title: Text(
|
|
|
|
'${MaterialLocalizations.of(context).formatShortDate(backup.time)} ${TimeOfDay.fromDateTime(backup.time).format(context)}',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16),
|
2022-02-16 07:01:05 +00:00
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.refresh'.tr(),
|
|
|
|
),
|
|
|
|
onTap: refreshing
|
|
|
|
? null
|
|
|
|
: () => {context.read<BackupsCubit>().updateBackups()},
|
|
|
|
enabled: !refreshing,
|
|
|
|
),
|
|
|
|
if (providerState != StateType.uninitialized)
|
|
|
|
Column(
|
|
|
|
children: [
|
2022-05-24 18:55:39 +00:00
|
|
|
const Divider(
|
2022-02-16 07:01:05 +00:00
|
|
|
height: 1.0,
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.refetchBackups'.tr(),
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () => {
|
|
|
|
context
|
|
|
|
.read<BackupsCubit>()
|
|
|
|
.forceUpdateBackups()
|
|
|
|
},
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const Divider(
|
2022-02-16 07:01:05 +00:00
|
|
|
height: 1.0,
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.backup.reuploadKey'.tr(),
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () => {context.read<BackupsCubit>().reuploadKey()},
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-12-06 18:31:19 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
if (backupStatus == BackupStatusEnum.error)
|
|
|
|
BrandText.body1(backupError.toString()),
|
|
|
|
],
|
2021-12-06 18:31:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|