initial offline mode, hive setup, home display, mzansi rofile display completed
This commit is contained in:
parent
3d5fdde322
commit
f19a316be8
20 changed files with 981 additions and 304 deletions
16
mih_ui/lib/mih_hive/hive_adapters.dart
Normal file
16
mih_ui/lib/mih_hive/hive_adapters.dart
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// hive_adapters.dart
|
||||
import 'package:hive_ce/hive_ce.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
|
||||
@GenerateAdapters([
|
||||
AdapterSpec<AppUser>(),
|
||||
AdapterSpec<Business>(),
|
||||
AdapterSpec<BusinessUser>(),
|
||||
AdapterSpec<UserConsent>(),
|
||||
AdapterSpec<ProfileLink>(),
|
||||
])
|
||||
part 'hive_adapters.g.dart';
|
||||
285
mih_ui/lib/mih_hive/hive_adapters.g.dart
Normal file
285
mih_ui/lib/mih_hive/hive_adapters.g.dart
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'hive_adapters.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// AdaptersGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class AppUserAdapter extends TypeAdapter<AppUser> {
|
||||
@override
|
||||
final typeId = 0;
|
||||
|
||||
@override
|
||||
AppUser read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return AppUser(
|
||||
(fields[0] as num).toInt(),
|
||||
fields[1] as String,
|
||||
fields[2] as String,
|
||||
fields[3] as String,
|
||||
fields[4] as String,
|
||||
fields[5] as String,
|
||||
fields[6] as String,
|
||||
fields[7] as String,
|
||||
fields[8] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, AppUser obj) {
|
||||
writer
|
||||
..writeByte(9)
|
||||
..writeByte(0)
|
||||
..write(obj.idUser)
|
||||
..writeByte(1)
|
||||
..write(obj.email)
|
||||
..writeByte(2)
|
||||
..write(obj.fname)
|
||||
..writeByte(3)
|
||||
..write(obj.lname)
|
||||
..writeByte(4)
|
||||
..write(obj.type)
|
||||
..writeByte(5)
|
||||
..write(obj.app_id)
|
||||
..writeByte(6)
|
||||
..write(obj.username)
|
||||
..writeByte(7)
|
||||
..write(obj.pro_pic_path)
|
||||
..writeByte(8)
|
||||
..write(obj.purpose);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is AppUserAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class BusinessAdapter extends TypeAdapter<Business> {
|
||||
@override
|
||||
final typeId = 1;
|
||||
|
||||
@override
|
||||
Business read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return Business(
|
||||
fields[0] as String,
|
||||
fields[1] as String,
|
||||
fields[2] as String,
|
||||
fields[3] as String,
|
||||
fields[4] as String,
|
||||
fields[5] as String,
|
||||
fields[6] as String,
|
||||
fields[7] as String,
|
||||
fields[8] as String,
|
||||
fields[9] as String,
|
||||
fields[10] as String,
|
||||
fields[11] as String,
|
||||
fields[12] as String,
|
||||
fields[13] as String,
|
||||
fields[14] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Business obj) {
|
||||
writer
|
||||
..writeByte(15)
|
||||
..writeByte(0)
|
||||
..write(obj.business_id)
|
||||
..writeByte(1)
|
||||
..write(obj.Name)
|
||||
..writeByte(2)
|
||||
..write(obj.type)
|
||||
..writeByte(3)
|
||||
..write(obj.registration_no)
|
||||
..writeByte(4)
|
||||
..write(obj.logo_name)
|
||||
..writeByte(5)
|
||||
..write(obj.logo_path)
|
||||
..writeByte(6)
|
||||
..write(obj.contact_no)
|
||||
..writeByte(7)
|
||||
..write(obj.bus_email)
|
||||
..writeByte(8)
|
||||
..write(obj.app_id)
|
||||
..writeByte(9)
|
||||
..write(obj.gps_location)
|
||||
..writeByte(10)
|
||||
..write(obj.practice_no)
|
||||
..writeByte(11)
|
||||
..write(obj.vat_no)
|
||||
..writeByte(12)
|
||||
..write(obj.website)
|
||||
..writeByte(13)
|
||||
..write(obj.rating)
|
||||
..writeByte(14)
|
||||
..write(obj.mission_vision);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BusinessAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class BusinessUserAdapter extends TypeAdapter<BusinessUser> {
|
||||
@override
|
||||
final typeId = 2;
|
||||
|
||||
@override
|
||||
BusinessUser read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return BusinessUser(
|
||||
(fields[0] as num).toInt(),
|
||||
fields[1] as String,
|
||||
fields[2] as String,
|
||||
fields[3] as String,
|
||||
fields[4] as String,
|
||||
fields[5] as String,
|
||||
fields[6] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, BusinessUser obj) {
|
||||
writer
|
||||
..writeByte(7)
|
||||
..writeByte(0)
|
||||
..write(obj.idbusiness_users)
|
||||
..writeByte(1)
|
||||
..write(obj.business_id)
|
||||
..writeByte(2)
|
||||
..write(obj.app_id)
|
||||
..writeByte(3)
|
||||
..write(obj.signature)
|
||||
..writeByte(4)
|
||||
..write(obj.sig_path)
|
||||
..writeByte(5)
|
||||
..write(obj.title)
|
||||
..writeByte(6)
|
||||
..write(obj.access);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BusinessUserAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class UserConsentAdapter extends TypeAdapter<UserConsent> {
|
||||
@override
|
||||
final typeId = 3;
|
||||
|
||||
@override
|
||||
UserConsent read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return UserConsent(
|
||||
app_id: fields[0] as String,
|
||||
privacy_policy_accepted: fields[1] as DateTime,
|
||||
terms_of_services_accepted: fields[2] as DateTime,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, UserConsent obj) {
|
||||
writer
|
||||
..writeByte(3)
|
||||
..writeByte(0)
|
||||
..write(obj.app_id)
|
||||
..writeByte(1)
|
||||
..write(obj.privacy_policy_accepted)
|
||||
..writeByte(2)
|
||||
..write(obj.terms_of_services_accepted);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is UserConsentAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class ProfileLinkAdapter extends TypeAdapter<ProfileLink> {
|
||||
@override
|
||||
final typeId = 4;
|
||||
|
||||
@override
|
||||
ProfileLink read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ProfileLink(
|
||||
idprofile_links: (fields[0] as num).toInt(),
|
||||
app_id: fields[1] as String,
|
||||
business_id: fields[2] as String,
|
||||
site_name: fields[3] as String,
|
||||
custom_name: fields[4] as String,
|
||||
destination: fields[5] as String,
|
||||
order: (fields[6] as num).toInt(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ProfileLink obj) {
|
||||
writer
|
||||
..writeByte(7)
|
||||
..writeByte(0)
|
||||
..write(obj.idprofile_links)
|
||||
..writeByte(1)
|
||||
..write(obj.app_id)
|
||||
..writeByte(2)
|
||||
..write(obj.business_id)
|
||||
..writeByte(3)
|
||||
..write(obj.site_name)
|
||||
..writeByte(4)
|
||||
..write(obj.custom_name)
|
||||
..writeByte(5)
|
||||
..write(obj.destination)
|
||||
..writeByte(6)
|
||||
..write(obj.order);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ProfileLinkAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
107
mih_ui/lib/mih_hive/hive_adapters.g.yaml
Normal file
107
mih_ui/lib/mih_hive/hive_adapters.g.yaml
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
# Generated by Hive CE
|
||||
# Manual modifications may be necessary for certain migrations
|
||||
# Check in to version control
|
||||
nextTypeId: 5
|
||||
types:
|
||||
AppUser:
|
||||
typeId: 0
|
||||
nextIndex: 9
|
||||
fields:
|
||||
idUser:
|
||||
index: 0
|
||||
email:
|
||||
index: 1
|
||||
fname:
|
||||
index: 2
|
||||
lname:
|
||||
index: 3
|
||||
type:
|
||||
index: 4
|
||||
app_id:
|
||||
index: 5
|
||||
username:
|
||||
index: 6
|
||||
pro_pic_path:
|
||||
index: 7
|
||||
purpose:
|
||||
index: 8
|
||||
Business:
|
||||
typeId: 1
|
||||
nextIndex: 15
|
||||
fields:
|
||||
business_id:
|
||||
index: 0
|
||||
Name:
|
||||
index: 1
|
||||
type:
|
||||
index: 2
|
||||
registration_no:
|
||||
index: 3
|
||||
logo_name:
|
||||
index: 4
|
||||
logo_path:
|
||||
index: 5
|
||||
contact_no:
|
||||
index: 6
|
||||
bus_email:
|
||||
index: 7
|
||||
app_id:
|
||||
index: 8
|
||||
gps_location:
|
||||
index: 9
|
||||
practice_no:
|
||||
index: 10
|
||||
vat_no:
|
||||
index: 11
|
||||
website:
|
||||
index: 12
|
||||
rating:
|
||||
index: 13
|
||||
mission_vision:
|
||||
index: 14
|
||||
BusinessUser:
|
||||
typeId: 2
|
||||
nextIndex: 7
|
||||
fields:
|
||||
idbusiness_users:
|
||||
index: 0
|
||||
business_id:
|
||||
index: 1
|
||||
app_id:
|
||||
index: 2
|
||||
signature:
|
||||
index: 3
|
||||
sig_path:
|
||||
index: 4
|
||||
title:
|
||||
index: 5
|
||||
access:
|
||||
index: 6
|
||||
UserConsent:
|
||||
typeId: 3
|
||||
nextIndex: 3
|
||||
fields:
|
||||
app_id:
|
||||
index: 0
|
||||
privacy_policy_accepted:
|
||||
index: 1
|
||||
terms_of_services_accepted:
|
||||
index: 2
|
||||
ProfileLink:
|
||||
typeId: 4
|
||||
nextIndex: 7
|
||||
fields:
|
||||
idprofile_links:
|
||||
index: 0
|
||||
app_id:
|
||||
index: 1
|
||||
business_id:
|
||||
index: 2
|
||||
site_name:
|
||||
index: 3
|
||||
custom_name:
|
||||
index: 4
|
||||
destination:
|
||||
index: 5
|
||||
order:
|
||||
index: 6
|
||||
26
mih_ui/lib/mih_hive/hive_registrar.g.dart
Normal file
26
mih_ui/lib/mih_hive/hive_registrar.g.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Generated by Hive CE
|
||||
// Do not modify
|
||||
// Check in to version control
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_hive/hive_adapters.dart';
|
||||
|
||||
extension HiveRegistrar on HiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(AppUserAdapter());
|
||||
registerAdapter(BusinessAdapter());
|
||||
registerAdapter(BusinessUserAdapter());
|
||||
registerAdapter(ProfileLinkAdapter());
|
||||
registerAdapter(UserConsentAdapter());
|
||||
}
|
||||
}
|
||||
|
||||
extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(AppUserAdapter());
|
||||
registerAdapter(BusinessAdapter());
|
||||
registerAdapter(BusinessUserAdapter());
|
||||
registerAdapter(ProfileLinkAdapter());
|
||||
registerAdapter(UserConsentAdapter());
|
||||
}
|
||||
}
|
||||
116
mih_ui/lib/mih_hive/mzansi_profile_hive_data.dart
Normal file
116
mih_ui/lib/mih_hive/mzansi_profile_hive_data.dart
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import 'package:hive_ce_flutter/hive_ce_flutter.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_profile_links_service.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_consent_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
|
||||
class MzansiProfileHiveData {
|
||||
final Box<AppUser> _userBox = Hive.box<AppUser>('user_box');
|
||||
final Box<Business> _businessBox = Hive.box<Business>('business_box');
|
||||
final Box<BusinessUser> _businessUserBox =
|
||||
Hive.box<BusinessUser>('business_user_box');
|
||||
final Box<UserConsent> _userConsentBox =
|
||||
Hive.box<UserConsent>('user_consent_box');
|
||||
final Box<ProfileLink> _personalProfileLinksBox =
|
||||
Hive.box<ProfileLink>('personal_profile_links_box');
|
||||
|
||||
final Box<String> _resolvedUrlsBox = Hive.box<String>('image_urls_box');
|
||||
|
||||
static const String kUserKey = 'current_user';
|
||||
static const String kBusinessKey = 'current_business';
|
||||
static const String kBusinessUserKey = 'current_business_user';
|
||||
static const String kConsentKey = 'current_consent';
|
||||
static const String kUserPicUrlKey = 'user_pic_url';
|
||||
static const String kBusinessPicUrlKey = 'business_pic_url';
|
||||
static const String kSignatureUrlKey = 'signature_url';
|
||||
|
||||
AppUser? getCachedUser() => _userBox.get(kUserKey);
|
||||
Business? getCachedBusiness() => _businessBox.get(kBusinessKey);
|
||||
BusinessUser? getCachedBusinessUser() =>
|
||||
_businessUserBox.get(kBusinessUserKey);
|
||||
UserConsent? getCachedConsent() => _userConsentBox.get(kConsentKey);
|
||||
String? getCachedUserPicUrl() => _resolvedUrlsBox.get(kUserPicUrlKey);
|
||||
String? getCachedBusinessPicUrl() => _resolvedUrlsBox.get(kBusinessPicUrlKey);
|
||||
String? getCachedSignatureUrl() => _resolvedUrlsBox.get(kSignatureUrlKey);
|
||||
List<ProfileLink> getCachedPersonalProfileLinks() {
|
||||
final links = _personalProfileLinksBox.values.toList();
|
||||
links.sort((a, b) => a.order.compareTo(b.order));
|
||||
return links;
|
||||
}
|
||||
|
||||
Future<void> cacheUserData(AppUser remoteUser) async {
|
||||
await _userBox.put(kUserKey, remoteUser);
|
||||
if (remoteUser.pro_pic_path.isNotEmpty) {
|
||||
String userPicUrl =
|
||||
await MihFileApi.getMinioFileUrl(remoteUser.pro_pic_path);
|
||||
await _resolvedUrlsBox.put(kUserPicUrlKey, userPicUrl);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> cacheUserConsentData(UserConsent remoteConsent) async {
|
||||
await _userConsentBox.put(kConsentKey, remoteConsent);
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessData(Business remoteBusiness) async {
|
||||
await _businessBox.put(kBusinessKey, remoteBusiness);
|
||||
if (remoteBusiness.logo_path.isNotEmpty) {
|
||||
String logoUrl =
|
||||
await MihFileApi.getMinioFileUrl(remoteBusiness.logo_path);
|
||||
await _resolvedUrlsBox.put(kBusinessPicUrlKey, logoUrl);
|
||||
}
|
||||
BusinessUser? remoteBizUser =
|
||||
await MihMyBusinessUserServices().getBusinessUserV2();
|
||||
if (remoteBizUser != null) {
|
||||
cacheBusinessUserData(remoteBizUser);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessUserData(BusinessUser remoteBizUser) async {
|
||||
await _businessUserBox.put(kBusinessUserKey, remoteBizUser);
|
||||
if (remoteBizUser.sig_path.isNotEmpty) {
|
||||
String signatureUrl =
|
||||
await MihFileApi.getMinioFileUrl(remoteBizUser.sig_path);
|
||||
await _resolvedUrlsBox.put(kSignatureUrlKey, signatureUrl);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> cachePersonalProfileLinksData(
|
||||
List<ProfileLink> remoteLinks) async {
|
||||
await _personalProfileLinksBox.clear();
|
||||
await _personalProfileLinksBox.addAll(remoteLinks);
|
||||
}
|
||||
|
||||
Future<void> syncProfileDataWithServer() async {
|
||||
try {
|
||||
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
|
||||
if (remoteUser != null) {
|
||||
cacheUserData(remoteUser);
|
||||
|
||||
UserConsent? remoteConsent =
|
||||
await MihUserConsentServices().getUserConsentStatusV2();
|
||||
if (remoteConsent != null) {
|
||||
cacheUserConsentData(remoteConsent);
|
||||
}
|
||||
final remoteLinks = await MihProfileLinksServices.getUserProfileLinksV2(
|
||||
remoteUser.app_id);
|
||||
await cachePersonalProfileLinksData(remoteLinks);
|
||||
}
|
||||
Business? remoteBusiness =
|
||||
await MihBusinessDetailsServices().getBusinessDetailsByUserV2();
|
||||
if (remoteBusiness != null) {
|
||||
cacheBusinessData(remoteBusiness);
|
||||
}
|
||||
} catch (error) {
|
||||
KenLogger.warning("App operating offline mode. Sync paused");
|
||||
// KenLogger.warning("App operating offline mode. Sync paused: $error");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue