diff --git a/assets/api_constants.json b/assets/api_constants.json new file mode 100644 index 0000000..ab6f221 --- /dev/null +++ b/assets/api_constants.json @@ -0,0 +1,80 @@ +[ + { + "api": "loadFutureEvents", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "saveUserInterestedEvent", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "saveUserAttendingEvent", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "getSpecialitiesDonutChart", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "getTopicCloudChart", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "getTopAffiliationBarChart", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "eventSpeakers", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "saveEventsTopicNote", + "interval": 5, + "method": "POST", + "module": "eventapis" + }, + { + "api": "eventUserAnalytics", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "saveEventOffline", + "interval": 0, + "method": "POST", + "module": "eventapis" + }, + { + "api": "contactslistapi", + "interval": 5, + "method": "POST", + "module": "contactsapi" + }, + { + "api": "saveContactsOffline", + "interval": 0, + "method": "POST", + "module": "contactsapi" + }, + { + "api": "saveInteraction", + "interval": 0, + "method": "POST", + "module": "contactsapi" + } + ] \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 24ca5f0..198c6e3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -64,6 +64,7 @@ import 'package:konectar_events/contacts_module/ui_screen/interactionform/model/ import 'package:konectar_events/contacts_module/ui_screen/interactionform/repository/hive_repository.dart'; import 'package:konectar_events/contacts_module/ui_screen/interactionform/viewinteractionprovider.dart'; import 'package:konectar_events/firebaseexample.dart'; +import 'package:konectar_events/model/hive_api_constants.dart'; import 'package:konectar_events/model/myeventsmodel.dart'; import 'package:konectar_events/model/neweventsmodel.dart'; import 'package:konectar_events/model/sessionnotesmodel.dart'; @@ -175,11 +176,13 @@ Future main() async { Hive.registerAdapter(ProAdapter()); Hive.registerAdapter(Training1Adapter()); Hive.registerAdapter(SpeAdapter()); + Hive.registerAdapter(HiveApiConstantsAdapter()); await Hive.openBox("UserDataBox"); await Hive.openBox("EventsListBox"); await Hive.openBox("SessionNotesModelBox"); await Hive.openBox("MyEventsBox"); + await Hive.openBox("hiveApiConstants"); WidgetsFlutterBinding.ensureInitialized(); // FirebaseMessaging.instance.getToken().then((value) { @@ -259,38 +262,34 @@ Future main() async { ], child: SafeArea( top: true, - child: new OverlaySupport.global( - toastTheme: ToastThemeData(background: Colors.green), - child: MaterialApp( - theme: ThemeData( - //fontFamily: "SourceSerif", - ), - debugShowCheckedModeBanner: false, - title: 'Dynamic Links Example', - initialRoute: '/', - routes: { - '/': (BuildContext context) => FutureBuilder( - future: SessionManager().isLoggedIn(), - builder: (context, snapshot) { - print("Data_is : $snapshot"); - if (snapshot.connectionState == - ConnectionState.waiting) { - return const CircularProgressIndicator(); - } else if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); - } else { - final isLoggedIn = snapshot.data ?? false; - print("isLoggedIn_is : $isLoggedIn"); - print("secret : $secretkey"); - return isLoggedIn - ? IntroductionAnimationScreen() - : IntroductionAnimationScreen(); - } - }, - ), //userInfo != null ? const Home() : OpenidScreen(credential: credential,), - // '/details': (BuildContext context) => const HomeScreen(), - }, - ), + child: MaterialApp( + theme: ThemeData( + //fontFamily: "SourceSerif", + ), + debugShowCheckedModeBanner: false, + title: 'Dynamic Links Example', + initialRoute: '/', + routes: { + '/': (BuildContext context) => FutureBuilder( + future: SessionManager().isLoggedIn(), + builder: (context, snapshot) { + print("Data_is : $snapshot"); + if (snapshot.connectionState == ConnectionState.waiting) { + return const CircularProgressIndicator(); + } else if (snapshot.hasError) { + return Text('Error: ${snapshot.error}'); + } else { + final isLoggedIn = snapshot.data ?? false; + print("isLoggedIn_is : $isLoggedIn"); + print("secret : $secretkey"); + return isLoggedIn + ? IntroductionAnimationScreen() + : IntroductionAnimationScreen(); + } + }, + ), //userInfo != null ? const Home() : OpenidScreen(credential: credential,), + // '/details': (BuildContext context) => const HomeScreen(), + }, ), ), ), diff --git a/lib/model/api_constants_model.dart b/lib/model/api_constants_model.dart new file mode 100644 index 0000000..70ef9d6 --- /dev/null +++ b/lib/model/api_constants_model.dart @@ -0,0 +1,62 @@ +// To parse this JSON data, do +// +// final apiConstantsResponse = apiConstantsResponseFromJson(jsonString); + +import 'dart:convert'; + +List apiConstantsResponseFromJson(List json) => + List.from( + json.map((x) => ApiConstantsResponse.fromJson(x))); + +String apiConstantsResponseToJson(List data) => + json.encode(List.from(data.map((x) => x.toJson()))); + +class ApiConstantsResponse { + String? api; + int? interval; + String? method; + String? module; + + ApiConstantsResponse({ + this.api, + this.interval, + this.method, + this.module, + }); + + factory ApiConstantsResponse.fromJson(Map json) => + ApiConstantsResponse( + api: json["api"], + interval: json["interval"], + method: json["method"], + module: json["module"], + ); + + Map toJson() => { + "api": api, + "interval": interval, + "method": method, + "module": module, + }; +} + +enum Method { POST } + +final methodValues = EnumValues({"POST": Method.POST}); + +enum Module { CONTACTSAPI, EVENTAPIS } + +final moduleValues = EnumValues( + {"contactsapi": Module.CONTACTSAPI, "eventapis": Module.EVENTAPIS}); + +class EnumValues { + Map map; + late Map reverseMap; + + EnumValues(this.map); + + Map get reverse { + reverseMap = map.map((k, v) => MapEntry(v, k)); + return reverseMap; + } +} diff --git a/lib/model/hive_api_constants.dart b/lib/model/hive_api_constants.dart index 37abcc6..8fb45b5 100644 --- a/lib/model/hive_api_constants.dart +++ b/lib/model/hive_api_constants.dart @@ -1,5 +1,6 @@ import 'package:hive_flutter/hive_flutter.dart'; import 'package:konectar_events/utils/hivetypeids.dart'; +part 'hive_api_constants.g.dart'; @HiveType(typeId: HiveTypeIdConstants.hiveApiConstantsId) class HiveApiConstants { @@ -7,6 +8,11 @@ class HiveApiConstants { String? functionName; @HiveField(1) int? interval; + @HiveField(2) + String? method; + @HiveField(3) + String? module; - HiveApiConstants({this.functionName, this.interval}); + HiveApiConstants( + {this.functionName, this.interval, this.method, this.module}); } diff --git a/lib/model/hive_api_constants.g.dart b/lib/model/hive_api_constants.g.dart new file mode 100644 index 0000000..93fa11e --- /dev/null +++ b/lib/model/hive_api_constants.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'hive_api_constants.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class HiveApiConstantsAdapter extends TypeAdapter { + @override + final int typeId = 106; + + @override + HiveApiConstants read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return HiveApiConstants( + functionName: fields[0] as String?, + interval: fields[1] as int?, + ) + ..method = fields[2] as String? + ..module = fields[3] as String?; + } + + @override + void write(BinaryWriter writer, HiveApiConstants obj) { + writer + ..writeByte(4) + ..writeByte(0) + ..write(obj.functionName) + ..writeByte(1) + ..write(obj.interval) + ..writeByte(2) + ..write(obj.method) + ..writeByte(3) + ..write(obj.module); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is HiveApiConstantsAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/lib/utils/apicall.dart b/lib/utils/apicall.dart index 0c5f2cb..468beee 100644 --- a/lib/utils/apicall.dart +++ b/lib/utils/apicall.dart @@ -7,6 +7,7 @@ import 'package:dio/io.dart'; import 'package:flutter/services.dart'; import 'package:konectar_events/model/affiliationsmodel.dart'; import 'package:konectar_events/model/allsessionnotesmodel.dart'; +import 'package:konectar_events/model/api_constants_model.dart'; import 'package:konectar_events/model/events_details.dart'; import 'package:konectar_events/model/events_list_resp_2.dart'; import 'package:konectar_events/model/events_speakers_k1.dart'; @@ -14,6 +15,7 @@ import 'package:konectar_events/model/eventsdetailmodel.dart'; import 'package:konectar_events/model/eventsmodel.dart'; import 'package:konectar_events/model/eventsoverview.dart'; import 'package:konectar_events/model/eventspeakers.dart'; +import 'package:konectar_events/model/hive_api_constants.dart'; import 'package:konectar_events/model/keywords_model.dart'; import 'package:konectar_events/model/neweventsmodel.dart'; import 'package:konectar_events/model/scope_model.dart'; @@ -22,6 +24,7 @@ import 'package:konectar_events/model/sessionstopics_model.dart'; import 'package:konectar_events/model/specialtymodel.dart'; import 'package:konectar_events/model/topics_cloud_model.dart'; import 'package:konectar_events/utils/constants.dart'; +import 'package:konectar_events/viewmodel/hive_repository.dart'; class ApiCall { final dio = Dio(); @@ -540,6 +543,39 @@ class ApiCall { } return data; } + + //LOCAL API CONSTANTS + + Future fetchApiConstants() async { + dynamic jsonResult = + jsonDecode(await rootBundle.loadString("assets/api_constants.json")); + //dynamic jsonResult = await MockApiCall().getConfigDataMedical(); + + List responseData = + apiConstantsResponseFromJson(jsonResult); + print('Response_data_is: $responseData'); + List eventslist = responseData + .where( + (element) => element.module == EventsConstants.moduleName, + ) + .toList(); + List hiveApiConstantsList = []; + if (eventslist.isNotEmpty) { + for (ApiConstantsResponse obj in eventslist) { + HiveApiConstants hiveApiConstants = HiveApiConstants( + functionName: obj.api, + interval: obj.interval, + method: obj.method, + module: obj.module); + hiveApiConstantsList.add(hiveApiConstants); + } + } + print("APICONST LIST LENGTH:${hiveApiConstantsList.length}"); + if (hiveApiConstantsList.isNotEmpty) { + HiveOperations.saveApiConstants(hiveApiConstantsList); + } + } + //************ K2 API CALLS *********************************************************************************************************************************** Future> getEventsFromK2(int page, String search, diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index f8f24fc..f11adcf 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -19,31 +19,37 @@ class EventsConstants { static const String domainUrl = "http://192.168.2.109:8007/api/method/"; //192.0.0.2:8007 - iphone - // 192.168.2.109:8007 - office + // 192.168.2.109:8007 - office jkqehjkq //K1 API~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + static const String moduleName = "eventapis"; + static const String stagingUrl = - "https://cardio-staging.konectar.io/eventapis/"; + "https://cardio-staging.konectar.io/$moduleName/"; static const String url = stagingUrl; static const String devUrl = - "http://192.168.2.130/konectar-sandbox/eventapis/"; - static const String eventslistapi = "loadFutureEvents/"; - static const String followUnfollowEvent = "saveUserInterestedEvent/"; - static const String attendNotAttendEvent = "saveUserAttendingEvent/"; + "http://192.168.2.130/konectar-sandbox/$moduleName/"; + + static const String eventslistapi = "loadFutureEvents"; + static const String followUnfollowEvent = "saveUserInterestedEvent"; + static const String attendNotAttendEvent = "saveUserAttendingEvent"; static const String specialtyOfSpeakers = "getSpecialitiesDonutChart"; - static const String insightsTopicsCloud = "getTopicCloudChart/"; - static const String insightsBarChart = "getTopAffiliationBarChart/"; + static const String insightsTopicsCloud = "getTopicCloudChart"; + static const String insightsBarChart = "getTopAffiliationBarChart"; static const String speakerslistapi = "eventSpeakers"; static const String eventdetailsapi = "eventOverview"; static const String showEventsTopicsAndSession = "showEventsTopicsAndSession"; static const String getTopicNotes = "getTopicNotes"; static const String saveEventsTopicNote = "saveEventsTopicNote"; static const String eventUserAnalytics = "eventUserAnalytics"; + //MY CONSTANTS + static const String saveEventOffline = "saveEventOffline"; + static const String contactsListapi = "contactslistapi"; //Hive /* { -{ +"contacts":{ name:"loadFutureEvents", interval:5, method:POST, diff --git a/lib/view/login.dart b/lib/view/login.dart index dc888f8..e052df4 100644 --- a/lib/view/login.dart +++ b/lib/view/login.dart @@ -389,10 +389,14 @@ class _LoginScreenState extends State { // _displaySnackBar(textFieldsValidation(provider)); // } // }, - onPressed: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => NavigationHomeScreen()), + onPressed: () async { + await ApiCall().fetchApiConstants().then( + (value) { + Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => NavigationHomeScreen()), + ); + }, ); }, textColor: Colors.white, diff --git a/lib/view/navigation_home_screen.dart b/lib/view/navigation_home_screen.dart index 53e101a..74540fc 100644 --- a/lib/view/navigation_home_screen.dart +++ b/lib/view/navigation_home_screen.dart @@ -10,6 +10,7 @@ import 'package:konectar_events/utils/constants.dart'; import 'package:konectar_events/utils/dateformater.dart'; import 'package:konectar_events/view/helpdesk.dart'; import 'package:konectar_events/view/home.dart'; +import 'package:konectar_events/viewmodel/hive_repository.dart'; import 'package:konectar_events/widgets/drawerusercontroller.dart'; import 'package:konectar_events/widgets/home_drawer.dart'; import 'package:provider/provider.dart'; @@ -44,8 +45,13 @@ class _NavigationHomeScreenState extends State { body: DrawerUserController( screenIndex: drawerIndex, drawerWidth: MediaQuery.of(context).size.width * 0.75, - onDrawerCall: (DrawerIndex drawerIndexdata) { - changeIndex(drawerIndexdata); + onDrawerCall: (DrawerIndex drawerIndexdata) async { + bool checkContacts = await HiveOperations.checkIfApiExists( + EventsConstants.contactsListapi); + if (!checkContacts && drawerIndexdata.name == "Contacts") { + } else { + changeIndex(drawerIndexdata); + } //callback from drawer for replace screen as user need with passing DrawerIndex(Enum index) }, screenView: screenView, @@ -218,7 +224,7 @@ class _NavigationHomeScreenState extends State { screenView = const HomeScreen(); }); break; - case DrawerIndex.Help: + case DrawerIndex.Contacts: setState(() { screenView = Contacts1(); }); diff --git a/lib/viewmodel/hive_repository.dart b/lib/viewmodel/hive_repository.dart new file mode 100644 index 0000000..bec0869 --- /dev/null +++ b/lib/viewmodel/hive_repository.dart @@ -0,0 +1,28 @@ +import 'package:hive_flutter/hive_flutter.dart'; +import 'package:konectar_events/model/hive_api_constants.dart'; + +class HiveOperations { + static Future saveApiConstants(List hiveList) async { + late Box hiveApiConstantsBox; + hiveApiConstantsBox = + await Hive.openBox('hiveApiConstants'); + + hiveApiConstantsBox.addAll(hiveList); + } + + static Future checkIfApiExists( + String api, + ) async { + late Box hiveApiConstantsBox; + hiveApiConstantsBox = + await Hive.openBox('hiveApiConstants'); + + List list = hiveApiConstantsBox.values.toList(); + return list.indexWhere( + (element) => element.functionName == api, + ) == + -1 + ? false + : true; + } +} diff --git a/lib/viewmodel/loginprovider.dart b/lib/viewmodel/loginprovider.dart index 7a9ae4f..480cd49 100644 --- a/lib/viewmodel/loginprovider.dart +++ b/lib/viewmodel/loginprovider.dart @@ -1,12 +1,16 @@ import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import 'package:konectar_events/model/hive_api_constants.dart'; import 'package:konectar_events/model/userdata_model.dart'; import 'package:konectar_events/utils/apicall.dart'; import 'package:flutter/services.dart'; +import 'package:konectar_events/utils/constants.dart'; +import 'package:konectar_events/viewmodel/hive_repository.dart'; import 'package:mobile_device_identifier/mobile_device_identifier.dart'; class LoginProvider extends ChangeNotifier { late Box box; + bool showCodeField = false; bool showMessage = false; bool loading = false; @@ -37,6 +41,79 @@ class LoginProvider extends ChangeNotifier { print(userData2.imageBytes); } + Future saveApiData() async { + List hiveList = [ + HiveApiConstants( + functionName: "loadFutureEvents", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "saveUserInterestedEvent", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "saveUserAttendingEvent", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "getSpecialitiesDonutChart", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "getTopicCloudChart", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "getTopAffiliationBarChart", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "eventSpeakers", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "eventOverview", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "showEventsTopicsAndSession", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "getTopicNotes", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "saveEventsTopicNote", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "eventUserAnalytics", + interval: 0, + method: "POST", + module: "eventapis"), + HiveApiConstants( + functionName: "saveEventOffline", + interval: 0, + method: "POST", + module: "eventapis"), + // HiveApiConstants(functionName: "contactslistapi", interval: 0), + ]; + + HiveOperations.saveApiConstants(hiveList); + } + Future getUserData() async { box = await Hive.openBox('UserDataBox'); Iterable data = box.values; diff --git a/lib/widgets/home_drawer.dart b/lib/widgets/home_drawer.dart index 075b9e0..d3a8c86 100644 --- a/lib/widgets/home_drawer.dart +++ b/lib/widgets/home_drawer.dart @@ -4,6 +4,7 @@ import 'package:konectar_events/utils/app_theme.dart'; import 'package:konectar_events/utils/constants.dart'; import 'package:konectar_events/utils/sessionmanager.dart'; import 'package:konectar_events/view/login.dart'; +import 'package:konectar_events/viewmodel/hive_repository.dart'; import 'package:shared_preferences/shared_preferences.dart'; class HomeDrawer extends StatefulWidget { @@ -40,42 +41,75 @@ class _HomeDrawerState extends State { super.initState(); } - void setDrawerListArray() { - drawerList = [ - DrawerList( - index: DrawerIndex.Help, - labelName: 'Contacts', - icon: Icon(Icons.account_circle), - // isAssetsImage: true, - // imageName: 'assets/images/supportIcon.png', - ), - DrawerList( - index: DrawerIndex.HOME, - labelName: 'Events', - icon: Icon(Icons.event), - ), + void setDrawerListArray() async { + bool checkContacts = + await HiveOperations.checkIfApiExists(EventsConstants.contactsListapi); + if (!checkContacts) { + drawerList = [ + DrawerList( + index: DrawerIndex.HOME, + labelName: 'Events', + icon: Icon(Icons.event), + ), - DrawerList( - index: DrawerIndex.FeedBack, - labelName: 'HelpDesk', - icon: Icon(Icons.help), - ), - DrawerList( - index: DrawerIndex.Invite, - labelName: 'Medical Insight', - icon: Icon(Icons.group), - ), - // DrawerList( - // index: DrawerIndex.Share, - // labelName: 'Rate the app', - // icon: Icon(Icons.share), - // ), - // DrawerList( - // index: DrawerIndex.About, - // labelName: 'About Us', - // icon: Icon(Icons.info), - // ), - ]; + DrawerList( + index: DrawerIndex.FeedBack, + labelName: 'HelpDesk', + icon: Icon(Icons.help), + ), + DrawerList( + index: DrawerIndex.Invite, + labelName: 'Medical Insight', + icon: Icon(Icons.group), + ), + // DrawerList( + // index: DrawerIndex.Share, + // labelName: 'Rate the app', + // icon: Icon(Icons.share), + // ), + // DrawerList( + // index: DrawerIndex.About, + // labelName: 'About Us', + // icon: Icon(Icons.info), + // ), + ]; + } else { + drawerList = [ + DrawerList( + index: DrawerIndex.Contacts, + labelName: 'Contacts', + icon: Icon(Icons.account_circle), + // isAssetsImage: true, + // imageName: 'assets/images/supportIcon.png', + ), + DrawerList( + index: DrawerIndex.HOME, + labelName: 'Events', + icon: Icon(Icons.event), + ), + + DrawerList( + index: DrawerIndex.FeedBack, + labelName: 'HelpDesk', + icon: Icon(Icons.help), + ), + DrawerList( + index: DrawerIndex.Invite, + labelName: 'Medical Insight', + icon: Icon(Icons.group), + ), + // DrawerList( + // index: DrawerIndex.Share, + // labelName: 'Rate the app', + // icon: Icon(Icons.share), + // ), + // DrawerList( + // index: DrawerIndex.About, + // labelName: 'About Us', + // icon: Icon(Icons.info), + // ), + ]; + } } @override @@ -345,7 +379,7 @@ class _HomeDrawerState extends State { enum DrawerIndex { HOME, FeedBack, - Help, + Contacts, Share, About, Invite,