TF-1068 add recent url

This commit is contained in:
sherlockvn
2022-10-20 14:17:20 +07:00
committed by Dat H. Pham
parent 69e7715734
commit 36e3634c71
14 changed files with 312 additions and 0 deletions
@@ -0,0 +1,18 @@
import 'package:hive/hive.dart';
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
class UriAdapter extends TypeAdapter<Uri> {
@override
final int typeId = CachingConstants.URI_CACHE_IDENTITY;
@override
Uri read(BinaryReader reader) {
return Uri.parse(reader.readString());
}
@override
void write(BinaryWriter writer, Uri obj) {
writer.writeString(obj.toString());
}
}
@@ -6,10 +6,12 @@ import 'package:core/utils/app_logger.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path_provider;
import 'package:tmail_ui_user/features/caching/adapter/uri_adapter.dart';
import 'package:tmail_ui_user/features/login/data/local/encryption_key_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
import 'package:tmail_ui_user/features/login/data/model/encryption_key_cache.dart';
import 'package:tmail_ui_user/features/login/data/model/recent_login_url_cache.dart';
import 'package:tmail_ui_user/features/login/data/model/token_oidc_cache.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart';
@@ -74,6 +76,8 @@ class HiveCacheConfig {
Hive.registerAdapter(AccountCacheAdapter());
Hive.registerAdapter(EncryptionKeyCacheAdapter());
Hive.registerAdapter(AuthenticationInfoCacheAdapter());
Hive.registerAdapter(UriAdapter());
Hive.registerAdapter(RecentLoginUrlCacheAdapter());
}
Future closeHive() async {
@@ -0,0 +1,126 @@
import 'package:hive/hive.dart';
import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart';
import 'package:tmail_ui_user/features/login/data/model/recent_login_url_cache.dart';
class RecentLoginUrlCacheClient extends HiveCacheClient<RecentLoginUrlCache> {
@override
String get tableName => 'RecentLoginUrlCache';
@override
Future<void> clearAllData() {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.clear();
}).catchError((error) {
throw error;
});
}
@override
Future<void> deleteItem(String key) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.delete(key);
}).catchError((error) {
throw error;
});
}
@override
Future<void> deleteMultipleItem(List<String> listKey) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.deleteAll(listKey);
}).catchError((error) {
throw error;
});
}
@override
Future<List<RecentLoginUrlCache>> getAll() {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.values.toList();
}).catchError((error) {
throw error;
});
}
@override
Future<RecentLoginUrlCache?> getItem(String key) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.get(key);
}).catchError((error) {
throw error;
});
}
@override
Future<void> insertItem(String key, RecentLoginUrlCache newObject) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.put(key, newObject);
}).catchError((error) {
throw error;
});
}
@override
Future<void> insertMultipleItem(Map<String, RecentLoginUrlCache> mapObject) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.putAll(mapObject);
}).catchError((error) {
throw error;
});
}
@override
Future<bool> isExistItem(String key) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.containsKey(key);
}).catchError((error) {
throw error;
});
}
@override
Future<bool> isExistTable() {
return Future.sync(() async {
return Hive.boxExists(tableName);
}).catchError((error) {
throw error;
});
}
@override
Future<Box<RecentLoginUrlCache>> openBox() async {
if (Hive.isBoxOpen(tableName)) {
return Hive.box<RecentLoginUrlCache>(tableName);
}
return Hive.openBox<RecentLoginUrlCache>(tableName);
}
@override
Future<void> updateItem(String key, RecentLoginUrlCache newObject) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.put(key, newObject);
}).catchError((error) {
throw error;
});
}
@override
Future<void> updateMultipleItem(Map<String, RecentLoginUrlCache> mapObject) {
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.putAll(mapObject);
}).catchError((error) {
throw error;
});
}
}
@@ -11,4 +11,6 @@ class CachingConstants {
static const int ACCOUNT_HIVE_CACHE_IDENTIFY = 9;
static const int ENCRYPTION_KEY_HIVE_CACHE_IDENTIFY = 10;
static const int AUTHENTICATION_INFO_HIVE_CACHE_IDENTIFY = 11;
static const int URI_CACHE_IDENTITY = 12;
static const int LOGIN_URL_CACHE_IDENTITY = 13;
}