switch to new image api strat and fix onboarding cache strat
This commit is contained in:
parent
48b434dad9
commit
a5bdee892c
39 changed files with 540 additions and 791 deletions
|
|
@ -9,6 +9,16 @@ class AboutMihHiveData {
|
|||
static const String kUserCountKey = 'current_user_count';
|
||||
static const String kBusinessCountKey = 'current_business_count';
|
||||
|
||||
// Clear Local Cache
|
||||
Future<void> clearAboutMIHCache() async {
|
||||
try {
|
||||
await _mihUserBusinessCountBox.clear();
|
||||
KenLogger.success("Cleared Local About MIH Cache.");
|
||||
} catch (error) {
|
||||
KenLogger.error("Failed to clear local about mih cache.");
|
||||
}
|
||||
}
|
||||
|
||||
// Get Data from local storage
|
||||
int? getcachedUserCount() => _mihUserBusinessCountBox.get(kUserCountKey);
|
||||
int? getcachedBusinessCount() =>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,25 @@ class MzansiProfileHiveData {
|
|||
Hive.box<ProfileLink>('business_profile_links_box');
|
||||
final Box<BusinessEmployee> _businessEmployeesBox =
|
||||
Hive.box<BusinessEmployee>('business_Employees_box');
|
||||
final Box<Map> _modificationsQueue =
|
||||
Hive.box<Map>('profile_modifications_queue');
|
||||
|
||||
// Set offline data
|
||||
Future<void> clearProfileCache() async {
|
||||
try {
|
||||
await _userBox.clear();
|
||||
await _businessBox.clear();
|
||||
await _businessUserBox.clear();
|
||||
await _userConsentBox.clear();
|
||||
await _personalProfileLinksBox.clear();
|
||||
await _businessProfileLinksBox.clear();
|
||||
await _businessEmployeesBox.clear();
|
||||
await _modificationsQueue.clear();
|
||||
KenLogger.success("Cleared Local Profile Cache.");
|
||||
} catch (error) {
|
||||
KenLogger.error("Failed to clear local profile cache.");
|
||||
}
|
||||
}
|
||||
|
||||
static const String kUserKey = 'current_user';
|
||||
static const String kBusinessKey = 'current_business';
|
||||
|
|
@ -144,4 +163,58 @@ class MzansiProfileHiveData {
|
|||
// KenLogger.warning("App operating offline mode. Sync paused: $error");
|
||||
}
|
||||
}
|
||||
|
||||
// Set Offline Data
|
||||
Future<bool> addUserConsentLocally(UserConsent newConsent) async {
|
||||
try {
|
||||
await _userConsentBox.put(kConsentKey, newConsent);
|
||||
KenLogger.success("Consent Saved Locally.");
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Modification Processing
|
||||
Future<void> queuAddConsentModification(UserConsent newConsent) async {
|
||||
await _modificationsQueue.add({
|
||||
'action': 'ADD',
|
||||
'type': 'CONSENT',
|
||||
'payload': newConsent,
|
||||
});
|
||||
KenLogger.success("Add Consent Queues for Online Sync");
|
||||
}
|
||||
|
||||
Future<bool> processModificationsQueue() async {
|
||||
if (_modificationsQueue.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
final List<dynamic> queueKeys = _modificationsQueue.keys.toList();
|
||||
for (var taskKey in queueKeys) {
|
||||
final task = _modificationsQueue.get(taskKey);
|
||||
if (task == null) {
|
||||
continue;
|
||||
}
|
||||
final String action = task['action'];
|
||||
final String type = task['type'];
|
||||
if (type == 'CONSENT') {
|
||||
final UserConsent consentTask = task['payload'];
|
||||
if (action == 'ADD') {
|
||||
final responseCode =
|
||||
await MihUserConsentServices().insertUserConsentStatusV2(
|
||||
consentTask,
|
||||
);
|
||||
if (responseCode != null && responseCode == 201) {
|
||||
await _modificationsQueue.delete(taskKey);
|
||||
KenLogger.success("Add User Consent to MIH Server");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isModificationsNotEmpty() {
|
||||
return _modificationsQueue.values.toList().isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,18 @@ class MzansiWalletHiveData {
|
|||
final Box<Map> _modificationsQueue =
|
||||
Hive.box<Map>('wallet_modifications_queue');
|
||||
|
||||
// Set offline data
|
||||
Future<void> clearWalletCache() async {
|
||||
try {
|
||||
await _loyaltyCardBox.clear();
|
||||
await _favLoyaltyCardBox.clear();
|
||||
await _modificationsQueue.clear();
|
||||
KenLogger.success("Cleared Local Wallet Cache.");
|
||||
} catch (error) {
|
||||
KenLogger.error("Failed to clear local wallet cache.");
|
||||
}
|
||||
}
|
||||
|
||||
// Get Offline Data
|
||||
List<MIHLoyaltyCard> getCachedLoyaltyCards() {
|
||||
final cards = _loyaltyCardBox.values.toList();
|
||||
|
|
@ -204,8 +216,6 @@ class MzansiWalletHiveData {
|
|||
}
|
||||
final String action = task['action'];
|
||||
final MIHLoyaltyCard taskCard = task['payload'];
|
||||
KenLogger.warning(
|
||||
"Card Details: id=${taskCard.idloyalty_cards}, shop=${taskCard.shop_name}, Nunber=${taskCard.card_number}, offline_id=${taskCard.offline_id}");
|
||||
if (action == 'ADD') {
|
||||
dynamic deleteCardTaskKey;
|
||||
for (var entry in _modificationsQueue.toMap().entries) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue