TF-123 Implement refresh all mailbox
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
|
||||
abstract class CacheConfig {
|
||||
Future initializeDatabase();
|
||||
|
||||
void registerAdapter();
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
abstract class CacheClient<T> {
|
||||
abstract class HiveCacheClient<T> {
|
||||
|
||||
String get tableName;
|
||||
|
||||
@@ -13,7 +13,7 @@ abstract class CacheClient<T> {
|
||||
|
||||
Future<T?> getItem(String key);
|
||||
|
||||
Future<List<T>> getListItem();
|
||||
Future<List<T>> getAll();
|
||||
|
||||
Future<void> updateItem(String key, T newObject);
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:model/caching/mailbox/mailbox_rights_cache.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:path_provider/path_provider.dart' as pathProvider;
|
||||
import 'package:tmail_ui_user/features/caching/config/cache_config.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';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
||||
|
||||
class HiveCacheConfig extends CacheConfig {
|
||||
class HiveCacheConfig {
|
||||
|
||||
Future setUp() async {
|
||||
await initializeDatabase();
|
||||
registerAdapter();
|
||||
}
|
||||
|
||||
@override
|
||||
Future initializeDatabase() async {
|
||||
Directory directory = await pathProvider.getApplicationDocumentsDirectory();
|
||||
Hive.init(directory.path);
|
||||
}
|
||||
|
||||
@override
|
||||
void registerAdapter() {
|
||||
Hive.registerAdapter(MailboxCacheAdapter());
|
||||
Hive.registerAdapter(MailboxRightsCacheAdapter());
|
||||
Hive.registerAdapter(StateDaoAdapter());
|
||||
Hive.registerAdapter(StateCacheAdapter());
|
||||
Hive.registerAdapter(StateTypeAdapter());
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
|
||||
|
||||
class MailboxCacheClient extends CacheClient<MailboxCache> {
|
||||
class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
|
||||
|
||||
@override
|
||||
String get tableName => 'MailboxCache';
|
||||
@@ -51,7 +51,7 @@ class MailboxCacheClient extends CacheClient<MailboxCache> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<MailboxCache>> getListItem() {
|
||||
Future<List<MailboxCache>> getAll() {
|
||||
return Future.sync(() async {
|
||||
final boxMailbox = await openTable();
|
||||
return boxMailbox.values.toList();
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
|
||||
|
||||
class StateCacheClient extends CacheClient<StateDao> {
|
||||
class StateCacheClient extends HiveCacheClient<StateCache> {
|
||||
|
||||
@override
|
||||
String get tableName => 'StateCache';
|
||||
|
||||
@override
|
||||
Future<Box<StateDao>> openTable() {
|
||||
Future<Box<StateCache>> openTable() {
|
||||
return Future.sync(() async {
|
||||
if (Hive.isBoxOpen(tableName)) {
|
||||
return Hive.box<StateDao>(tableName);
|
||||
return Hive.box<StateCache>(tableName);
|
||||
}
|
||||
return await Hive.openBox<StateDao>(tableName);
|
||||
return await Hive.openBox<StateCache>(tableName);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
@@ -41,7 +41,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<StateDao?> getItem(String key) {
|
||||
Future<StateCache?> getItem(String key) {
|
||||
return Future.sync(() async {
|
||||
final boxState = await openTable();
|
||||
return boxState.get(key);
|
||||
@@ -51,7 +51,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<StateDao>> getListItem() {
|
||||
Future<List<StateCache>> getAll() {
|
||||
return Future.sync(() async {
|
||||
final boxState = await openTable();
|
||||
return boxState.values.toList();
|
||||
@@ -61,7 +61,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> insertItem(String key, StateDao newObject) {
|
||||
Future<void> insertItem(String key, StateCache newObject) {
|
||||
return Future.sync(() async {
|
||||
final boxState = await openTable();
|
||||
boxState.put(key, newObject);
|
||||
@@ -71,7 +71,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> insertMultipleItem(Map<String, StateDao> mapObject) {
|
||||
Future<void> insertMultipleItem(Map<String, StateCache> mapObject) {
|
||||
return Future.sync(() async {
|
||||
final boxState = await openTable();
|
||||
boxState.putAll(mapObject);
|
||||
@@ -81,7 +81,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateItem(String key, StateDao newObject) {
|
||||
Future<void> updateItem(String key, StateCache newObject) {
|
||||
return Future.sync(() async {
|
||||
final boxState = await openTable();
|
||||
boxState.put(key, newObject);
|
||||
@@ -110,7 +110,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateMultipleItem(Map<String, StateDao> mapObject) {
|
||||
Future<void> updateMultipleItem(Map<String, StateCache> mapObject) {
|
||||
return Future.sync(() async {
|
||||
final boxState = await openTable();
|
||||
boxState.putAll(mapObject);
|
||||
|
||||
Reference in New Issue
Block a user