WIP
This commit is contained in:
parent
c90b8e20dc
commit
3c106d6957
|
@ -0,0 +1 @@
|
|||
export 'profile_local_data_source.dart';
|
|
@ -5,18 +5,13 @@ import 'package:hub/shared/constants/index.dart';
|
|||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
abstract class ProfileLocalDataSource {
|
||||
Future<void> init();
|
||||
Future<String?> get(String key);
|
||||
Future<void> set<T>(String key, T value);
|
||||
Future<void> delete(String key);
|
||||
Future<void> clearAll();
|
||||
}
|
||||
abstract class ProfileLocalDataSource implements DatabaseStorage {}
|
||||
|
||||
class ProfileLocalDataSourceImpl implements BaseStorage {
|
||||
ProfileLocalDataSourceImpl._();
|
||||
|
||||
static final ProfileLocalDataSourceImpl instance = ProfileLocalDataSourceImpl._();
|
||||
static final ProfileLocalDataSourceImpl instance =
|
||||
ProfileLocalDataSourceImpl._();
|
||||
|
||||
bool _isInitialized = false;
|
||||
|
||||
|
@ -29,7 +24,8 @@ class ProfileLocalDataSourceImpl implements BaseStorage {
|
|||
|
||||
@override
|
||||
Future<String?> get(String key) async {
|
||||
var response = await DatabaseService.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]);
|
||||
var response = await DatabaseService.database
|
||||
.query(tableKeychain, where: 'key = ?', whereArgs: [key]);
|
||||
if (response.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
@ -56,7 +52,8 @@ class ProfileLocalDataSourceImpl implements BaseStorage {
|
|||
|
||||
@override
|
||||
Future<void> delete(String key) async {
|
||||
await DatabaseService.database.delete(tableKeychain, where: 'key = ?', whereArgs: [key]);
|
||||
await DatabaseService.database
|
||||
.delete(tableKeychain, where: 'key = ?', whereArgs: [key]);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export 'services/index.dart';
|
|
@ -1 +0,0 @@
|
|||
export 'database_service.dart';
|
|
@ -1,3 +0,0 @@
|
|||
export 'database_data_source.dart';
|
||||
export 'secure_data_source.dart';
|
||||
export 'shared_data_source.dart';
|
|
@ -1,3 +0,0 @@
|
|||
export 'data_sources/index.dart';
|
||||
export 'repositories/index.dart';
|
||||
export 'models/index.dart';
|
|
@ -1,160 +0,0 @@
|
|||
import 'package:hub/features/storage/index.dart';
|
||||
|
||||
abstract class DatabaseStorageKey implements IDatabaseStorage {
|
||||
final String key;
|
||||
const DatabaseStorageKey(this.key);
|
||||
List<String> get values => [];
|
||||
}
|
||||
|
||||
class ProfileStorageKey extends DatabaseStorageKey {
|
||||
const ProfileStorageKey._(String key) : super(key);
|
||||
|
||||
static const String table = 'profileTable';
|
||||
|
||||
static const ProfileStorageKey userEmail = ProfileStorageKey._('fre_userEmail');
|
||||
static const ProfileStorageKey devUUID = ProfileStorageKey._('fre_devUUID');
|
||||
static const ProfileStorageKey userUUID = ProfileStorageKey._('fre_userUUID');
|
||||
static const ProfileStorageKey userDevUUID = ProfileStorageKey._('fre_userDevUUID');
|
||||
static const ProfileStorageKey status = ProfileStorageKey._('fre_status');
|
||||
static const ProfileStorageKey userName = ProfileStorageKey._('fre_userName');
|
||||
static const ProfileStorageKey clientUUID = ProfileStorageKey._('fre_cliUUID');
|
||||
static const ProfileStorageKey ownerUUID = ProfileStorageKey._('fre_ownerUUID');
|
||||
static const ProfileStorageKey clientName = ProfileStorageKey._('fre_cliName');
|
||||
static const ProfileStorageKey ownerName = ProfileStorageKey._('fre_ownerName');
|
||||
|
||||
@override
|
||||
List<String> get values => [
|
||||
userEmail.key,
|
||||
devUUID.key,
|
||||
userUUID.key,
|
||||
userDevUUID.key,
|
||||
status.key,
|
||||
userName.key,
|
||||
clientUUID.key,
|
||||
ownerUUID.key,
|
||||
clientName.key,
|
||||
ownerName.key,
|
||||
];
|
||||
}
|
||||
|
||||
class LocalsStorageKey extends DatabaseStorageKey {
|
||||
const LocalsStorageKey._(String key) : super(key);
|
||||
|
||||
static const table = 'localTable';
|
||||
|
||||
static const LocalsStorageKey petAmount = LocalsStorageKey._('fre_petAmountRegister');
|
||||
static const LocalsStorageKey whatsapp = LocalsStorageKey._('fre_whatsapp');
|
||||
static const LocalsStorageKey provisional = LocalsStorageKey._('fre_provisional');
|
||||
static const LocalsStorageKey pets = LocalsStorageKey._('fre_pets');
|
||||
static const LocalsStorageKey local = LocalsStorageKey._('fre_local');
|
||||
static const LocalsStorageKey notify = LocalsStorageKey._('fre_notify');
|
||||
static const LocalsStorageKey fingerprint = LocalsStorageKey._('fre_fingerprint');
|
||||
static const LocalsStorageKey access = LocalsStorageKey._('fre_access');
|
||||
static const LocalsStorageKey panic = LocalsStorageKey._('fre_panic');
|
||||
static const LocalsStorageKey person = LocalsStorageKey._('fre_person');
|
||||
static const LocalsStorageKey requestOSNotification = LocalsStorageKey._('fre_requestOSnotification');
|
||||
static const LocalsStorageKey isNewVersion = LocalsStorageKey._('fre_isNewVersion');
|
||||
|
||||
@override
|
||||
List<String> get values => [
|
||||
petAmount.key,
|
||||
whatsapp.key,
|
||||
provisional.key,
|
||||
pets.key,
|
||||
local.key,
|
||||
notify.key,
|
||||
fingerprint.key,
|
||||
access.key,
|
||||
panic.key,
|
||||
person.key,
|
||||
requestOSNotification.key,
|
||||
isNewVersion.key,
|
||||
];
|
||||
}
|
||||
|
||||
// enum DatabaseStorageKey implements IDatabaseStorage {
|
||||
// devUUID,
|
||||
// userUUID,
|
||||
// userDevUUID,
|
||||
// status,
|
||||
// userName,
|
||||
// userEmail,
|
||||
// clientUUID,
|
||||
// ownerName,
|
||||
// ownerUUID,
|
||||
// clientName,
|
||||
// petAmount,
|
||||
// whatsapp,
|
||||
// provisional,
|
||||
// pets,
|
||||
// local,
|
||||
// notify,
|
||||
// fingerprint,
|
||||
// access,
|
||||
// panic,
|
||||
// person,
|
||||
// requestOSNotification,
|
||||
// isNewVersion,
|
||||
// }
|
||||
|
||||
// extension ProfileStorageKeyExtension on DatabaseStorageKey {
|
||||
// String get profile {
|
||||
// switch (this) {
|
||||
// case DatabaseStorageKey.userEmail:
|
||||
// return 'fre_userEmail';
|
||||
// case DatabaseStorageKey.devUUID:
|
||||
// return 'fre_devUUID';
|
||||
// case DatabaseStorageKey.userUUID:
|
||||
// return 'fre_userUUID';
|
||||
// case DatabaseStorageKey.userDevUUID:
|
||||
// return 'fre_userDevUUID';
|
||||
// case DatabaseStorageKey.status:
|
||||
// return 'fre_status';
|
||||
// case DatabaseStorageKey.userName:
|
||||
// return 'fre_userName';
|
||||
// case DatabaseStorageKey.clientUUID:
|
||||
// return 'fre_cliUUID';
|
||||
// case DatabaseStorageKey.ownerUUID:
|
||||
// return 'fre_ownerUUID';
|
||||
// case DatabaseStorageKey.clientName:
|
||||
// return 'fre_cliName';
|
||||
// case DatabaseStorageKey.ownerName:
|
||||
// return 'fre_ownerName';
|
||||
// default:
|
||||
// return '';
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// extension LocalsStorageKeyExtension on DatabaseStorageKey {
|
||||
// String get locals {
|
||||
// switch (this) {
|
||||
// case DatabaseStorageKey.petAmount:
|
||||
// return 'fre_petAmountRegister';
|
||||
// case DatabaseStorageKey.whatsapp:
|
||||
// return 'fre_whatsapp';
|
||||
// case DatabaseStorageKey.provisional:
|
||||
// return 'fre_provisional';
|
||||
// case DatabaseStorageKey.pets:
|
||||
// return 'fre_pets';
|
||||
// case DatabaseStorageKey.local:
|
||||
// return 'fre_local';
|
||||
// case DatabaseStorageKey.notify:
|
||||
// return 'fre_notify';
|
||||
// case DatabaseStorageKey.fingerprint:
|
||||
// return 'fre_fingerprint';
|
||||
// case DatabaseStorageKey.access:
|
||||
// return 'fre_access';
|
||||
// case DatabaseStorageKey.panic:
|
||||
// return 'fre_panic';
|
||||
// case DatabaseStorageKey.person:
|
||||
// return 'fre_person';
|
||||
// case DatabaseStorageKey.requestOSNotification:
|
||||
// return 'fre_requestOSnotification';
|
||||
// case DatabaseStorageKey.isNewVersion:
|
||||
// return 'fre_isNewVersion';
|
||||
// default:
|
||||
// return '';
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -1 +0,0 @@
|
|||
export 'storage_repository.dart';
|
|
@ -1,3 +0,0 @@
|
|||
export 'entities/index.dart';
|
||||
export 'respositories/index.dart';
|
||||
export 'usecases/index.dart';
|
|
@ -0,0 +1,47 @@
|
|||
abstract class DatabaseStorageKey {}
|
||||
|
||||
enum ProfileStorageKey implements DatabaseStorageKey {
|
||||
userEmail('fre_userEmail'),
|
||||
devUUID('fre_devUUID'),
|
||||
userUUID('fre_userUUID'),
|
||||
userDevUUID('fre_userDevUUID'),
|
||||
status('fre_status'),
|
||||
userName('fre_userName'),
|
||||
clientUUID('fre_cliUUID'),
|
||||
ownerUUID('fre_ownerUUID'),
|
||||
clientName('fre_cliName'),
|
||||
ownerName('fre_ownerName');
|
||||
|
||||
final String key;
|
||||
|
||||
const ProfileStorageKey(this.key);
|
||||
|
||||
static const String table = 'profileTable';
|
||||
|
||||
static List<String> get values =>
|
||||
ProfileStorageKey.values.map((e) => e.key).toList();
|
||||
}
|
||||
|
||||
enum LocalsStorageKey implements DatabaseStorageKey {
|
||||
petAmount('fre_petAmountRegister'),
|
||||
whatsapp('fre_whatsapp'),
|
||||
provisional('fre_provisional'),
|
||||
pets('fre_pets'),
|
||||
local('fre_local'),
|
||||
notify('fre_notify'),
|
||||
fingerprint('fre_fingerprint'),
|
||||
access('fre_access'),
|
||||
panic('fre_panic'),
|
||||
person('fre_person'),
|
||||
requestOSNotification('fre_requestOSnotification'),
|
||||
isNewVersion('fre_isNewVersion');
|
||||
|
||||
final String key;
|
||||
|
||||
const LocalsStorageKey(this.key);
|
||||
|
||||
static const String table = 'LocalsStorageKey';
|
||||
|
||||
static List<String> get values =>
|
||||
LocalsStorageKey.values.map((e) => e.key).toList();
|
||||
}
|
|
@ -1,29 +1,24 @@
|
|||
import 'package:hub/features/profile/index.dart';
|
||||
import 'package:hub/features/storage/index.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
class DatabaseStorage implements BaseStorage {
|
||||
DatabaseStorage._();
|
||||
|
||||
static final DatabaseStorage instance = DatabaseStorage._();
|
||||
|
||||
late final Database _database;
|
||||
bool _isInitialized = false;
|
||||
// static final DatabaseStorage instance = DatabaseStorage._();
|
||||
|
||||
// late final Database _database;
|
||||
// bool _isInitialized = false;
|
||||
|
||||
static DatabaseStorageKey getInstanceByKey(String key) {
|
||||
if (ProfileStorageKey.values.map((e) => e.value).toList().contains(key)) {
|
||||
return ProfileStorageKey.instance;
|
||||
} else (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) {
|
||||
return LocalsStorageKey.instance;
|
||||
|
||||
static BaseStorage getInstanceByKey(String key) {
|
||||
if (ProfileStorageKey.values.contains(key))
|
||||
return ProfileLocalDataSourceImpl.instance(key);
|
||||
else //if (LocalsStorageKey.values.contains(key));
|
||||
return LocalsStorageKey.instance(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearAll() => throw UnimplementedError();
|
||||
Future<void> clearAll() => throw UnimplementedError();
|
||||
@override
|
||||
Future<void> delete(String key) => throw UnimplementedError();
|
||||
@override
|
||||
|
@ -32,4 +27,4 @@ class DatabaseStorage implements BaseStorage {
|
|||
Future<void> init() => throw UnimplementedError();
|
||||
@override
|
||||
Future<void> set<T>(String key, T value) => throw UnimplementedError();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export 'dabase_storage_helper.dart';
|
||||
export 'secure_storage_helper.dart';
|
||||
export 'shared_storage_helper.dart';
|
|
@ -1,3 +1,5 @@
|
|||
export 'data/index.dart';
|
||||
export 'domain/index.dart';
|
||||
export 'application/index.dart';
|
||||
export 'interfaces/index.dart';
|
||||
export 'enums/index.dart';
|
||||
export 'helpers/index.dart';
|
||||
export 'repositories/index.dart';
|
||||
export 'services/index.dart';
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
export 'storage_repository.dart';
|
||||
export 'storage_repository_impl.dart';
|
|
@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:hub/features/profile/data/data_sources/profile_local_data_source.dart';
|
||||
import 'package:hub/features/storage/index.dart';
|
||||
|
||||
class StorageHelper {
|
||||
class StorageHelper implements StorageRepository {
|
||||
static final StorageHelper _instance = StorageHelper._internal();
|
||||
factory StorageHelper() => _instance;
|
||||
StorageHelper._internal();
|
||||
|
@ -22,11 +22,13 @@ class StorageHelper {
|
|||
await SharedPreferencesStorage.instance.init();
|
||||
await ProfileLocalDataSourceImpl.instance.init();
|
||||
|
||||
String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value);
|
||||
String? isFirstRun = await SharedPreferencesStorage.instance
|
||||
.get(SharedPreferencesKey.isFirstRun.value);
|
||||
|
||||
if (isFirstRun != 'false') {
|
||||
log('First run');
|
||||
await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false);
|
||||
await SharedPreferencesStorage.instance
|
||||
.set(SharedPreferencesKey.isFirstRun.value, false);
|
||||
await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false);
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +47,13 @@ class StorageHelper {
|
|||
static BaseStorage getInstanceByKey(String key) {
|
||||
if (SecureStorageKey.values.map((e) => e.value).toList().contains(key)) {
|
||||
return SecureStorage.instance;
|
||||
} else if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) {
|
||||
} else if (SharedPreferencesKey.values
|
||||
.map((e) => e.value)
|
||||
.toList()
|
||||
.contains(key)) {
|
||||
return SharedPreferencesStorage.instance;
|
||||
} else {
|
||||
return ProfileLocalDataSourceImpl.instance;
|
||||
return DatabaseStorage.instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
export 'database_storage_service.dart';
|
||||
export 'secure_storage_service.dart';
|
||||
export 'shared_storage_service.dart';
|
||||
export 'storage_service.dart';
|
Loading…
Reference in New Issue