selfprivacy.org.app/lib/logic/cubit/app_config/app_config_state.dart

236 lines
7 KiB
Dart
Raw Normal View History

2021-01-06 17:35:57 +00:00
part of 'app_config_cubit.dart';
2021-10-11 21:10:04 +00:00
abstract class AppConfigState extends Equatable {
2021-01-06 17:35:57 +00:00
const AppConfigState({
2021-03-15 15:39:44 +00:00
required this.hetznerKey,
required this.cloudFlareKey,
required this.backblazeCredential,
required this.cloudFlareDomain,
required this.rootUser,
required this.hetznerServer,
required this.isServerStarted,
2021-03-31 11:37:39 +00:00
required this.isServerResetedFirstTime,
required this.isServerResetedSecondTime,
2021-01-06 17:35:57 +00:00
});
@override
2021-03-15 15:39:44 +00:00
List<Object?> get props => [
2021-01-06 17:35:57 +00:00
hetznerKey,
cloudFlareKey,
2021-02-03 20:26:38 +00:00
backblazeCredential,
2021-01-06 17:35:57 +00:00
cloudFlareDomain,
rootUser,
2021-01-21 07:35:38 +00:00
hetznerServer,
2021-02-16 18:48:15 +00:00
isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime,
2021-01-06 17:35:57 +00:00
];
2021-03-15 15:39:44 +00:00
final String? hetznerKey;
final String? cloudFlareKey;
final BackblazeCredential? backblazeCredential;
final CloudFlareDomain? cloudFlareDomain;
final User? rootUser;
final HetznerServerDetails? hetznerServer;
2021-03-23 19:50:11 +00:00
final bool isServerStarted;
2021-03-31 11:37:39 +00:00
final bool isServerResetedFirstTime;
final bool isServerResetedSecondTime;
2021-01-06 17:35:57 +00:00
bool get isHetznerFilled => hetznerKey != null;
bool get isCloudFlareFilled => cloudFlareKey != null;
2021-02-03 20:26:38 +00:00
bool get isBackblazeFilled => backblazeCredential != null;
2021-01-06 17:35:57 +00:00
bool get isDomainFilled => cloudFlareDomain != null;
bool get isUserFilled => rootUser != null;
2021-02-16 18:48:15 +00:00
bool get isServerCreated => hetznerServer != null;
2021-01-21 21:01:42 +00:00
2021-10-13 21:49:24 +00:00
bool get isFullyInitilized => _fulfilementList.every((el) => el!);
int get progress => _fulfilementList.where((el) => el!).length;
2021-06-20 21:08:52 +00:00
int get porgressBar {
if (progress < 6) {
return progress;
} else if (progress < 10) {
return 6;
} else {
return 7;
}
}
2021-01-06 17:35:57 +00:00
2021-03-25 08:32:00 +00:00
List<bool?> get _fulfilementList {
var res = [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime,
isServerResetedSecondTime,
2021-03-25 08:32:00 +00:00
];
2021-03-30 17:38:40 +00:00
2021-03-25 08:32:00 +00:00
return res;
}
2021-01-06 17:35:57 +00:00
}
class TimerState extends AppConfigNotFinished {
2021-02-15 18:58:29 +00:00
TimerState({
2021-03-15 15:39:44 +00:00
required this.dataState,
2021-02-15 18:58:29 +00:00
this.timerStart,
this.duration,
2021-03-15 15:39:44 +00:00
required bool isLoading,
2021-02-16 18:48:15 +00:00
}) : super(
hetznerKey: dataState.hetznerKey,
cloudFlareKey: dataState.cloudFlareKey,
backblazeCredential: dataState.backblazeCredential,
cloudFlareDomain: dataState.cloudFlareDomain,
rootUser: dataState.rootUser,
hetznerServer: dataState.hetznerServer,
isServerStarted: dataState.isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
2021-02-16 18:48:15 +00:00
isLoading: isLoading,
);
2021-02-15 18:58:29 +00:00
final AppConfigNotFinished dataState;
2021-03-15 15:39:44 +00:00
final DateTime? timerStart;
final Duration? duration;
2021-02-15 18:58:29 +00:00
@override
2021-03-15 15:39:44 +00:00
List<Object?> get props => [
2021-02-15 18:58:29 +00:00
dataState,
timerStart,
duration,
];
}
class AppConfigNotFinished extends AppConfigState {
final bool isLoading;
AppConfigNotFinished({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
CloudFlareDomain? cloudFlareDomain,
User? rootUser,
HetznerServerDetails? hetznerServer,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
required this.isLoading,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
cloudFlareDomain: cloudFlareDomain,
rootUser: rootUser,
hetznerServer: hetznerServer,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
cloudFlareDomain,
rootUser,
hetznerServer,
isServerStarted,
isServerResetedFirstTime,
isLoading
];
AppConfigNotFinished copyWith({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
CloudFlareDomain? cloudFlareDomain,
User? rootUser,
HetznerServerDetails? hetznerServer,
bool? isServerStarted,
bool? isServerResetedFirstTime,
bool? isServerResetedSecondTime,
bool? isLoading,
}) =>
AppConfigNotFinished(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
cloudFlareDomain: cloudFlareDomain ?? this.cloudFlareDomain,
rootUser: rootUser ?? this.rootUser,
hetznerServer: hetznerServer ?? this.hetznerServer,
isServerStarted: isServerStarted ?? this.isServerStarted,
isServerResetedFirstTime:
isServerResetedFirstTime ?? this.isServerResetedFirstTime,
isServerResetedSecondTime:
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
isLoading: isLoading ?? this.isLoading,
);
AppConfigFinished finish() => AppConfigFinished(
hetznerKey: hetznerKey!,
cloudFlareKey: cloudFlareKey!,
backblazeCredential: backblazeCredential!,
cloudFlareDomain: cloudFlareDomain!,
rootUser: rootUser!,
hetznerServer: hetznerServer!,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
}
class AppConfigEmpty extends AppConfigNotFinished {
AppConfigEmpty()
: super(
hetznerKey: null,
cloudFlareKey: null,
backblazeCredential: null,
cloudFlareDomain: null,
rootUser: null,
hetznerServer: null,
isServerStarted: false,
isServerResetedFirstTime: false,
isServerResetedSecondTime: false,
isLoading: false,
);
}
class AppConfigFinished extends AppConfigState {
const AppConfigFinished({
required String hetznerKey,
required String cloudFlareKey,
required BackblazeCredential backblazeCredential,
required CloudFlareDomain cloudFlareDomain,
required User rootUser,
required HetznerServerDetails hetznerServer,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
cloudFlareDomain: cloudFlareDomain,
rootUser: rootUser,
hetznerServer: hetznerServer,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
cloudFlareDomain,
rootUser,
hetznerServer,
isServerStarted,
isServerResetedFirstTime,
];
}