Skip to content

Commit

Permalink
Merge pull request #31 from GuardianLabs/dev
Browse files Browse the repository at this point in the history
Merge branch 'dev'
  • Loading branch information
dmitrsosnin authored Jun 22, 2023
2 parents 8e370a6 + 71d8df9 commit 1cd598f
Show file tree
Hide file tree
Showing 66 changed files with 1,311 additions and 1,116 deletions.
4 changes: 2 additions & 2 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:get_it/get_it.dart';

import 'package:guardian_keyper/ui/theme/theme.dart';
import 'package:guardian_keyper/ui/screens/splash_screen.dart';
import 'package:guardian_keyper/feature/home/ui/home_screen.dart';

import 'package:guardian_keyper/data/network_manager.dart';
import 'package:guardian_keyper/feature/home/ui/home_screen.dart';
import 'package:guardian_keyper/feature/network/data/network_manager.dart';
import 'package:guardian_keyper/feature/vault/domain/use_case/vault_interactor.dart';
import 'package:guardian_keyper/feature/message/domain/use_case/message_interactor.dart';

Expand Down
40 changes: 13 additions & 27 deletions lib/app/di.dart
Original file line number Diff line number Diff line change
@@ -1,65 +1,51 @@
import 'dart:typed_data';
import 'package:get_it/get_it.dart';
import 'package:hive_flutter/hive_flutter.dart';

import 'package:guardian_keyper/feature/auth/domain/auth_interactor.dart';
import 'package:guardian_keyper/feature/auth/data/auth_manager.dart';
import 'package:guardian_keyper/feature/network/data/network_manager.dart';

import 'package:guardian_keyper/feature/vault/data/vault_repository.dart';
import 'package:guardian_keyper/feature/vault/domain/use_case/vault_interactor.dart';

import 'package:guardian_keyper/feature/message/data/message_repository.dart';
import 'package:guardian_keyper/feature/message/domain/use_case/message_interactor.dart';

import 'package:guardian_keyper/feature/settings/data/settings_manager.dart';
import 'package:guardian_keyper/feature/settings/domain/settings_interactor.dart';

import '../data/network_manager.dart';
import '../data/services/platform_service.dart';
import '../data/services/analytics_service.dart';
import '../data/services/preferences_service.dart';

/// Data layer (Managers\Repositories) depends on Services
/// Domain layer (Interactors) depends on Data layer
class DI {
static bool _isInited = false;

const DI();

bool get isInited => _isInited;

bool get isNotInited => !_isInited;

Future<void> init() async {
if (_isInited) return;

// DATA LAYER
// Services
GetIt.I.registerSingleton<PreferencesService>(
await PreferencesService().init(),
);
GetIt.I.registerSingleton<PlatformService>(PlatformService());
final preferencesService = await PreferencesService.init();
GetIt.I.registerSingleton<PreferencesService>(preferencesService);
GetIt.I.registerSingleton<AnalyticsService>(await AnalyticsService.init());

// Managers
GetIt.I.registerSingleton<NetworkManager>(
await NetworkManager().init(),
);
GetIt.I.registerSingleton<SettingsManager>(
await SettingsManager().init(),
);

GetIt.I.registerSingleton<AuthManager>(await AuthManager().init());
GetIt.I.registerSingleton<NetworkManager>(await NetworkManager().init());
// Repositories
await Hive.initFlutter('data_v1');
final seed = await preferencesService.get<Uint8List>(keySeed);
final cipher = HiveAesCipher(seed!);
GetIt.I.registerSingleton<VaultRepository>(await VaultRepository().init());
GetIt.I.registerSingleton<MessageRepository>(
await getMessageRepository(cipher),
);
GetIt.I.registerSingleton<VaultRepository>(
await getVaultRepository(cipher),
await MessageRepository().init(),
);

// DOMAIN LAYER
// Interactors
GetIt.I.registerSingleton<SettingsInteractor>(SettingsInteractor());
GetIt.I.registerSingleton<MessageInteractor>(MessageInteractor());
GetIt.I.registerSingleton<VaultInteractor>(VaultInteractor());
GetIt.I.registerSingleton<AuthInteractor>(AuthInteractor());

_isInited = true;
}
Expand Down
184 changes: 0 additions & 184 deletions lib/data/network_manager.dart

This file was deleted.

65 changes: 0 additions & 65 deletions lib/data/services/platform_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,17 @@ import 'dart:io';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:wakelock/wakelock.dart';
import 'package:vibration/vibration.dart';
import 'package:local_auth/local_auth.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:connectivity_plus/connectivity_plus.dart';

import 'package:guardian_keyper/consts.dart';

typedef ConnectivityState = ({bool hasConnectivity, bool hasWiFi});

class PlatformService {
static final _connectivity = Connectivity();
static final _localAuth = LocalAuthentication();

final share = Share.share;
final vibrate = Vibration.vibrate;
final wakelockEnable = Wakelock.enable;
final wakelockDisable = Wakelock.disable;
final hasStringsInClipboard = Clipboard.hasStrings;

late final onConnectivityChanged =
_connectivity.onConnectivityChanged.map<ConnectivityState>((type) {
_connectivityType = type;
return (
hasConnectivity: type != ConnectivityResult.none,
hasWiFi: type == ConnectivityResult.wifi,
);
});

bool get hasWiFi => _connectivityType == ConnectivityResult.wifi;
bool get hasConnectivity => _connectivityType != ConnectivityResult.none;
bool get hasNoConnectivity => _connectivityType == ConnectivityResult.none;

ConnectivityResult _connectivityType = ConnectivityResult.none;

Future<String?> copyFromClipboard() async =>
(await Clipboard.getData(Clipboard.kTextPlain))?.text;

Expand All @@ -50,46 +25,6 @@ class PlatformService {
}
}

Future<bool> checkConnectivity() async {
_connectivityType = await _connectivity.checkConnectivity();
return hasConnectivity;
}

Future<Set<InternetAddress>> getIPs() async {
final result = <InternetAddress>{};
for (final nIf in await NetworkInterface.list()) {
result.addAll(nIf.addresses);
}
return result;
}

Future<String> getDeviceName([String undefinedName = 'Undefined']) async {
if (Platform.isAndroid) {
return (await DeviceInfoPlugin().androidInfo).model;
}
if (Platform.isIOS) {
return (await DeviceInfoPlugin().iosInfo).model ?? undefinedName;
}
return undefinedName;
}

Future<bool> getHasBiometrics() =>
_localAuth.getAvailableBiometrics().then((value) => value.isNotEmpty);

Future<bool> localAuthenticate({
bool biometricOnly = true,
String localizedReason = 'Please authenticate to log into the app',
}) async {
try {
return await _localAuth.authenticate(
localizedReason: localizedReason,
options: AuthenticationOptions(biometricOnly: biometricOnly),
);
} catch (_) {
return false;
}
}

Future<bool> openMarket() =>
launchUrl(Uri.parse(Platform.isAndroid ? urlPlayMarket : urlAppStore));
}
Loading

0 comments on commit 1cd598f

Please sign in to comment.