2021-08-29 09:50:24 +00:00
|
|
|
import 'package:bloc/bloc.dart';
|
|
|
|
import 'package:equatable/equatable.dart';
|
2021-08-29 13:54:28 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:selfprivacy/config/hive_config.dart';
|
|
|
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
2021-08-29 09:50:24 +00:00
|
|
|
|
|
|
|
part 'services_state.dart';
|
|
|
|
|
|
|
|
class ServicesCubit extends Cubit<ServicesState> {
|
2021-08-29 13:54:28 +00:00
|
|
|
ServicesCubit() : super(ServicesState.allOff());
|
2021-08-29 09:50:24 +00:00
|
|
|
|
2021-08-29 13:54:28 +00:00
|
|
|
Box box = Hive.box(BNames.servicesState);
|
|
|
|
|
|
|
|
void load() {
|
|
|
|
emit(
|
|
|
|
ServicesState(
|
|
|
|
isPasswordManagerEnable:
|
|
|
|
box.get(ServiceTypes.passwordManager.txt, defaultValue: false),
|
|
|
|
isCloudEnable: box.get(ServiceTypes.cloud.txt, defaultValue: false),
|
|
|
|
isGitEnable: box.get(ServiceTypes.git.txt, defaultValue: false),
|
|
|
|
isSocialNetworkEnable:
|
|
|
|
box.get(ServiceTypes.socialNetwork.txt, defaultValue: false),
|
|
|
|
isVpnEnable: box.get(ServiceTypes.vpn.txt, defaultValue: false),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void allOn() {
|
|
|
|
box.put(ServiceTypes.passwordManager.txt, true);
|
|
|
|
box.put(ServiceTypes.cloud.txt, true);
|
|
|
|
box.put(ServiceTypes.git.txt, true);
|
|
|
|
box.put(ServiceTypes.socialNetwork.txt, true);
|
|
|
|
box.put(ServiceTypes.vpn.txt, true);
|
|
|
|
|
|
|
|
emit(ServicesState.allOn());
|
|
|
|
}
|
|
|
|
|
|
|
|
void allOff() {
|
|
|
|
box.put(ServiceTypes.passwordManager.txt, false);
|
|
|
|
box.put(ServiceTypes.cloud.txt, false);
|
|
|
|
box.put(ServiceTypes.git.txt, false);
|
|
|
|
box.put(ServiceTypes.socialNetwork.txt, false);
|
|
|
|
box.put(ServiceTypes.vpn.txt, false);
|
|
|
|
|
|
|
|
emit(ServicesState.allOff());
|
|
|
|
}
|
|
|
|
|
|
|
|
void turnOffList(List<ServiceTypes> list) {
|
|
|
|
for (final service in list) {
|
|
|
|
box.put(service.txt, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit(state.disableList(list));
|
|
|
|
}
|
|
|
|
|
|
|
|
void turnOnist(List<ServiceTypes> list) {
|
|
|
|
for (final service in list) {
|
|
|
|
box.put(service.txt, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit(state.enableList(list));
|
|
|
|
}
|
2021-08-29 09:50:24 +00:00
|
|
|
}
|