KonectarApp/lib/viewmodel/eventsprovider.dart

560 lines
18 KiB
Dart
Raw Normal View History

2024-09-06 06:30:31 +00:00
import 'dart:async';
2024-10-07 12:45:45 +00:00
import 'dart:math';
2024-09-06 06:30:31 +00:00
2024-11-19 12:57:30 +00:00
import 'package:connectivity_plus/connectivity_plus.dart';
2024-09-06 06:30:31 +00:00
import 'package:flutter/material.dart';
2024-11-19 12:57:30 +00:00
import 'package:flutter/services.dart';
2024-09-06 06:30:31 +00:00
import 'package:hive_flutter/hive_flutter.dart';
2024-11-19 12:57:30 +00:00
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_event_k2.dart';
2024-10-07 12:45:45 +00:00
import 'package:konectar_events/model/affiliationsmodel.dart';
import 'package:konectar_events/model/allsessionnotesmodel.dart';
2024-12-03 05:59:45 +00:00
import 'package:konectar_events/model/events_details.dart';
2024-11-19 12:57:30 +00:00
import 'package:konectar_events/model/events_list_resp_2.dart';
2024-12-03 05:59:45 +00:00
import 'package:konectar_events/model/events_speakers_k1.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/eventsdetailmodel.dart';
import 'package:konectar_events/model/eventsmodel.dart';
2024-10-07 12:45:45 +00:00
import 'package:konectar_events/model/eventsoverview.dart';
2024-11-19 12:57:30 +00:00
import 'package:konectar_events/model/eventspeakers.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/keywords_model.dart';
2024-11-19 12:57:30 +00:00
import 'package:konectar_events/model/my_events_list_model.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/neweventsmodel.dart';
import 'package:konectar_events/model/scope_model.dart';
import 'package:konectar_events/model/sessionnotesmodel.dart';
2024-10-07 12:45:45 +00:00
import 'package:konectar_events/model/specialtymodel.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/topics_cloud_model.dart';
import 'package:konectar_events/utils/apicall.dart';
import 'package:konectar_events/utils/dateformater.dart';
import 'package:konectar_events/widgets/word_cloud.dart';
class EventsProvider extends ChangeNotifier {
List<Keyword> keywordList = [];
List<Therapeutic> therapeuticList = [];
List<EventsList> eventList = [];
2024-11-19 12:57:30 +00:00
List<EventsListingData> neweventList = [];
2024-09-06 06:30:31 +00:00
List<EventsList> searchList = [];
List<EventsList> myEvents = [];
2024-11-19 12:57:30 +00:00
List<EventsList> offlineEvents = [];
2024-09-06 06:30:31 +00:00
List<Eventsdetail> eventdetailList = [];
List<Eventsdetail> srcheventdetailList = [];
List<String> selectedTherapeutic = [];
List<SessionNotesModel> addedSessionNotes = [];
2024-12-03 05:59:45 +00:00
List<EventSpeakersData> speakersList = [];
2024-11-19 12:57:30 +00:00
List<String> myEventids = [];
bool showCheckbox = false;
bool offlineExists = false;
2024-09-06 06:30:31 +00:00
int eventSessionCount = 0;
String message = "";
2024-11-19 12:57:30 +00:00
int speakercount = 0;
2024-09-06 06:30:31 +00:00
late Box<EventsList> box;
2024-11-19 12:57:30 +00:00
// late Box<MyEventsList> myeventsbox;
2024-09-06 06:30:31 +00:00
late Box<SessionNotesModel> sessionBox;
bool isAllSelected = true;
2024-11-19 12:57:30 +00:00
bool isFavSeleted = true;
2024-09-06 06:30:31 +00:00
bool isSearch = false;
bool isSearchSpeakers = false;
List<FlutterHashtag> kFlutterHashtags = [];
List<TopicsCloudData> topics = [];
2024-10-07 12:45:45 +00:00
List<Specialty> specialtyList = [];
EventsOverviewData overviewData = EventsOverviewData(
arrEvents: [], topSpeakers: [], eventSponsers: [], eventTopics: []);
Affiliations affiliations =
Affiliations(affiliationCount: [], affiliationNames: []);
List<AllSessionNotesResponse> allSessionNotes = [];
2024-11-19 12:57:30 +00:00
late StreamSubscription<List<ConnectivityResult>> connectivitySubscription;
bool isLoadingInsights = true;
2024-11-19 12:57:30 +00:00
Future<void> onSelectAll(int page) async {
isFavSeleted = false;
isAllSelected = !isAllSelected;
eventList = await getEvents(page);
2024-09-06 06:30:31 +00:00
notifyListeners();
}
2024-11-19 12:57:30 +00:00
Future<void> onSelectMy() async {
isFavSeleted = !isFavSeleted;
eventList = [];
eventList = await getMyEvents(1);
2024-09-06 06:30:31 +00:00
notifyListeners();
}
2024-12-03 05:59:45 +00:00
bool checkIfUserInterested(String eventid) {
bool user = false;
if (eventList.isNotEmpty) {
int index = eventList.indexWhere(
(element) => element.eventId == eventid,
);
print("FOR EVENT ID :$eventid : ${eventList[index].eventUserInterest}");
user = eventList[index].eventUserInterest ?? false;
2024-09-06 06:30:31 +00:00
}
2024-12-03 05:59:45 +00:00
return user;
}
2024-09-06 06:30:31 +00:00
2024-12-03 05:59:45 +00:00
List<EventsList> OnSearch(String searchtxt) {
print("Searching.......");
// // searchtxt = searchtxt.toLowerCase();
// isSearch = true;
// if (isFavSeleted) {
// searchList = eventList
// .where((element) => element.name1!.toLowerCase().contains(searchtxt))
// // (element.city != "" &&
// // element.city!.toLowerCase().contains(searchtxt)) ||
// // (element.region != "" &&
// // element.region!.toLowerCase().contains(searchtxt)) ||
// // (element.country != "" &&
// // element.country!.toLowerCase().contains(searchtxt)))
// .toList();
// } else {
// eventList =
// await ApiCall().getSearchedEventsFromK2(1, "event_name", searchtxt);
// // searchList = eventList
// // .where((element) => element.name1!.toLowerCase().contains(searchtxt))
// // // element.city!.toLowerCase().contains(searchtxt) ||
// // // element.region!.toLowerCase().contains(searchtxt) ||
// // // element.country!.toLowerCase().contains(searchtxt))
// // .toList();
// }
List<EventsList> searchList = eventList
..where((element) => element.name1!.toLowerCase().contains(searchtxt));
return searchList;
// print("###$searchList@@@");
// notifyListeners();
2024-09-06 06:30:31 +00:00
}
2024-11-19 12:57:30 +00:00
bool ifOfflineExists(String eventid) {
if (offlineEvents.isNotEmpty) {
offlineEvents.forEach(
(element) {
if (element.eventId == eventid) {
offlineExists = true;
} else {
offlineExists = false;
}
},
);
}
return offlineExists;
}
2024-12-03 05:59:45 +00:00
getSessionCount() {
2024-09-06 06:30:31 +00:00
List<String> sessions = [];
eventSessionCount = 0;
2024-12-03 05:59:45 +00:00
2024-11-19 12:57:30 +00:00
for (var obj in speakersList) {
2024-12-03 05:59:45 +00:00
sessions.addAll(obj.sessionName!.split(','));
2024-09-06 06:30:31 +00:00
}
print("Count ${sessions.toSet().toList().length}");
print("Count2 ${sessions.toList().length}");
print("SEE SESSIONS ${sessions.toSet().toList()}");
eventSessionCount = sessions.toSet().toList().length;
notifyListeners();
}
OnFilters() {
isSearch = true;
if (isFavSeleted) {
searchList = myEvents
.where((element) =>
selectedTherapeutic.contains(element.therapeuticArea))
.toList();
} else {
searchList = myEvents
.where((element) =>
selectedTherapeutic.contains(element.therapeuticArea))
.toList();
}
print("###$searchList@@@");
notifyListeners();
}
onFilterReset() async {
if (isFavSeleted) {
2024-11-19 12:57:30 +00:00
myEvents = await getMyEvents(1);
2024-09-06 06:30:31 +00:00
} else {
2024-11-19 12:57:30 +00:00
eventList = await getEvents(1);
2024-09-06 06:30:31 +00:00
}
isSearch = false;
searchList.clear();
notifyListeners();
}
onSearchReset() async {
if (isFavSeleted) {
2024-11-19 12:57:30 +00:00
myEvents = await getMyEvents(1);
2024-09-06 06:30:31 +00:00
} else {
2024-11-19 12:57:30 +00:00
eventList = await getEvents(1);
2024-09-06 06:30:31 +00:00
}
isSearch = false;
searchList.clear();
notifyListeners();
}
OnSearchSpeakers(String searchtxt) {
searchtxt = searchtxt.toLowerCase();
isSearchSpeakers = true;
srcheventdetailList = eventdetailList
.where((element) =>
element.kolFullName!.toLowerCase().contains(searchtxt) ||
element.eventTopics!.toLowerCase().contains(searchtxt))
.toList();
notifyListeners();
}
onSearchSpeakersReset(String eventid) async {
eventdetailList = await getEventsDetails(eventid);
isSearchSpeakers = false;
srcheventdetailList.clear();
notifyListeners();
}
initFiltersData() async {
// keywordList = await ApiCall().getkeywords('');
2024-10-07 12:45:45 +00:00
// therapeuticList = await ApiCall().getscopes();
2024-09-06 06:30:31 +00:00
notifyListeners();
}
Future<List<Keyword>> getKeywordList(String keyword) async {
keywordList = await ApiCall().getkeywords(keyword);
return keywordList;
//notifyListeners();
}
2024-11-19 12:57:30 +00:00
Future<List<EventsList>> getEvents(int page,
{String? searchtxt, String? startdate, String? enddate}) async {
// eventList = await getAllEventsData();
eventList.clear();
eventList = [];
offlineEvents = await getOfflineMyEvents();
eventList = isFavSeleted
? await ApiCall().getEventsFromK1(type: 2)
2024-11-19 12:57:30 +00:00
: await ApiCall().getEventsFromK1();
print("see the list : $neweventList");
2024-09-06 06:30:31 +00:00
if (eventList.isEmpty) {
2024-11-19 12:57:30 +00:00
// eventList = (await ApiCall().getEvents())!;
eventList = isFavSeleted
? await ApiCall().getEventsFromK1(type: 2)
2024-11-19 12:57:30 +00:00
: await ApiCall().getEventsFromK1();
2024-10-07 12:45:45 +00:00
//eventList = (await ApiCall().getStagingEvents())!;
2024-09-06 06:30:31 +00:00
for (var events in eventList) {
await saveEventsData(events);
}
}
2024-12-03 05:59:45 +00:00
if (searchtxt != "") {
return OnSearch(searchtxt!);
}
//add to favs old
2024-11-19 12:57:30 +00:00
if (myEventids.isNotEmpty) {
for (var events in eventList) {
if (myEventids.contains(events.eventId)) {
events.isfav = true;
}
}
}
2024-09-06 06:30:31 +00:00
return eventList;
2024-11-19 12:57:30 +00:00
//notifyListeners();
}
Future<List<EventsList>> getMyEvents(int page) async {
// eventList = await getAllEventsData();
myEvents = await ApiCall().getEventsFromK1(type: 2);
2024-11-19 12:57:30 +00:00
print("see the list : $myEvents");
if (myEvents.isEmpty) {
// eventList = (await ApiCall().getEvents())!;
myEvents = await ApiCall().getEventsFromK1(type: 2);
2024-11-19 12:57:30 +00:00
//eventList = (await ApiCall().getStagingEvents())!;
}
for (var events in myEvents) {
myEventids.add(events.eventId!);
}
return myEvents;
2024-09-06 06:30:31 +00:00
//notifyListeners();
}
Future<List<SessionNotesModel>> getAddedSessionNotes() async {
addedSessionNotes = await getAllSessionNotesList();
if (addedSessionNotes.isEmpty && eventList.isNotEmpty) {
addedSessionNotes = (await ApiCall().getSessionNotes())!;
for (SessionNotesModel notes in addedSessionNotes) {
int i =
eventList.indexWhere((element) => element.name1 == notes.eventname);
if (i != -1) {
notes.eventid = eventList[i].eventId;
}
notes.addedBy = "user";
notes.addedDate = CustomDateFormatter().formatDate();
await saveSessionDataFromResp(notes);
}
}
return addedSessionNotes;
//notifyListeners();
}
Future<List<Eventsdetail>> getEventsDetails(String eventid) async {
2024-11-19 12:57:30 +00:00
eventdetailList = (await ApiCall().getLocalEventsDetail("142682"))!;
2024-09-06 06:30:31 +00:00
return eventdetailList;
//notifyListeners();
}
2024-12-03 05:59:45 +00:00
Future<List<EventSpeakersData>> getInitialSpeakersDetails(String eventid,
{required String searchkey}) async {
speakersList = await ApiCall().getEventsSpeakersFromK1(eventid);
2024-12-03 05:59:45 +00:00
getSessionCount();
if (searchkey.length != 0) {
List<EventSpeakersData> searchspeakers = speakersList
.where((element) =>
element.kolFullName!.toLowerCase().contains(searchkey))
.toList();
if (searchspeakers.isEmpty) {
searchspeakers = speakersList
.where((element) =>
element.eventTopics!.toLowerCase().contains(searchkey))
.toList();
}
return searchspeakers;
} else {
return await ApiCall().getEventsSpeakersFromK1(eventid);
}
//return speakersList = (await ApiCall().getEventsSpeakersFromK1(eventid));
// notifyListeners();
}
Future<List<EventSpeakersData>> getSpeakersDetails(int page, String eventid,
String event_unique_id, String searchkey, int lastIndex) async {
2024-11-19 12:57:30 +00:00
// speakercount = data["count"];
2024-12-03 05:59:45 +00:00
speakersList = (await ApiCall().getEventsSpeakersFromK1(eventid));
2024-11-19 12:57:30 +00:00
// getSessionCount();
2024-12-03 05:59:45 +00:00
// if (speakersList.isEmpty) {
//
// }
if (page == 0) {
speakersList = speakersList.getRange(0, lastIndex).toList();
} else if (page > 0) {
int nextIndex = lastIndex + 40;
if (nextIndex < speakersList.length) {
speakersList = speakersList.getRange(lastIndex, nextIndex).toList();
} else {
speakersList =
speakersList.getRange(lastIndex, speakersList.length - 1).toList();
}
}
// if (searchkey.length != 0) {
// List<EventSpeakersData> searchspeakers = speakersList
// .where((element) =>
// element.kolFullName!.toLowerCase().contains(searchkey))
// .toList();
// return searchspeakers;
// } else {
2024-11-19 12:57:30 +00:00
return speakersList;
2024-12-03 05:59:45 +00:00
// }
2024-11-19 12:57:30 +00:00
//notifyListeners();
}
2024-09-06 06:30:31 +00:00
Future<String> addEventsToFavs(String eventid) async {
2024-11-19 12:57:30 +00:00
message = await ApiCall().followUnfollowEvent("1", eventid);
if (myEventids.isNotEmpty) {
if (!myEventids.contains(eventid)) {
myEventids.add(eventid);
}
} else {
myEventids.add(eventid);
}
return message;
//notifyListeners();
}
Future<String> attendNotAttendEvent(String eventid, String flag) async {
message = await ApiCall().attendNotAttendEvent(flag, eventid);
2024-09-06 06:30:31 +00:00
return message;
//notifyListeners();
}
2024-11-19 12:57:30 +00:00
Future<String> removeEventsToFavs(String eventid) async {
message = await ApiCall().followUnfollowEvent("0", eventid);
if (myEventids.isNotEmpty) {
if (myEventids.contains(eventid)) {
myEventids.remove(eventid);
}
}
return message;
//notifyListeners();
}
2024-09-06 06:30:31 +00:00
Future<String> markAttending(String eventid) async {
message = await ApiCall().attendEvents(eventid);
return message;
//notifyListeners();
}
FutureOr saveEventsData(EventsList eventsData) async {
box = await Hive.openBox<EventsList>('EventsListBox');
box.add(eventsData);
2024-11-19 12:57:30 +00:00
offlineEvents.clear();
offlineEvents = await getOfflineMyEvents();
print("OFFLINE TOTAL :${offlineEvents.length}");
2024-09-06 06:30:31 +00:00
notifyListeners();
}
FutureOr favsEventsData(EventsList eventsData) async {
box = await Hive.openBox<EventsList>('EventsListBox');
List<EventsList> data = box.values.toList();
int index = data.indexWhere(
(element) => element.eventId == eventsData.eventId,
);
box.putAt(index, eventsData);
2024-11-19 12:57:30 +00:00
// List<EventsList> eventsData2 = await getMyEventsData();
2024-09-06 06:30:31 +00:00
notifyListeners();
}
2024-11-19 12:57:30 +00:00
Future<List<EventsList>> getOfflineMyEvents() async {
2024-09-06 06:30:31 +00:00
box = await Hive.openBox<EventsList>('EventsListBox');
Iterable<EventsList> data = box.values;
myEvents = data.toList();
// EventsList eventsdata = EventsList();
// for (var obj in data) {
// eventsdata = new EventsList.fromJson(obj.toJson());
// }
return myEvents;
}
Future<List<SessionNotesModel>> getAllSessionNotesList() async {
sessionBox = await Hive.openBox<SessionNotesModel>('SessionNotesModelBox');
Iterable<SessionNotesModel> data = sessionBox.values;
addedSessionNotes = data.toList();
// EventsList eventsdata = EventsList();
// for (var obj in data) {
// eventsdata = new EventsList.fromJson(obj.toJson());
// }
return addedSessionNotes;
}
FutureOr deleteAllEventsData() async {
box = await Hive.openBox<EventsList>('EventsListBox');
box.clear();
}
2024-11-19 12:57:30 +00:00
FutureOr delateOfflineEvent(EventsList event) async {
2024-09-06 06:30:31 +00:00
//DELETE
// box = await Hive.openBox<EventsList>('EventsListBox');
// List<EventsList> data = box.values.toList();
// int index = data.indexWhere(
// (element) => element.eventId == eventid,
// );
// await box.deleteAt(index);
//REMOVE FROM FAVS
box = await Hive.openBox<EventsList>('EventsListBox');
List<EventsList> data = box.values.toList();
int index = data.indexWhere(
(element) => element.eventId == event.eventId,
);
event.isfav = false;
2024-11-19 12:57:30 +00:00
// box.putAt(index, event);
box.deleteAt(index);
//eventList = await getMyEventsData();
offlineEvents.clear();
offlineEvents = await getOfflineMyEvents();
2024-09-06 06:30:31 +00:00
notifyListeners();
}
FutureOr saveSessionDataFromResp(SessionNotesModel notesModel) async {
sessionBox = await Hive.openBox<SessionNotesModel>('SessionNotesModelBox');
sessionBox.add(notesModel);
notifyListeners();
}
FutureOr getTopicsCloud(EventsList event, {bool? client}) async {
List<TopicsCloudData> topics = await ApiCall().insightsTopicsCloud(
eventid: event.eventId!,
startDate: CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.start!)),
endDate: CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.end!)),
client: client ?? false);
2024-09-06 06:30:31 +00:00
// for (var events in eventList) {
// await saveEventsData(events);
// }
//notifyListeners();
kFlutterHashtags = [];
for (var topic in topics) {
kFlutterHashtags.add(
FlutterHashtag(topic.topic!, int.parse(topic.total!) + 500, false));
2024-09-06 06:30:31 +00:00
}
notifyListeners();
}
2024-10-07 12:45:45 +00:00
FutureOr getSpecialtyData(EventsList event, {bool? client}) async {
String date = CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.start!));
print("Formatted_DATE :$date");
specialtyList = await ApiCall().specialtyOfSpeakers(
2024-12-03 05:59:45 +00:00
eventid: event.eventId!,
startDate: CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.start!)),
endDate: CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.end!)),
client: client ?? false);
//isLoadingInsights = false;
2024-10-07 12:45:45 +00:00
notifyListeners();
}
FutureOr getAffiliations(EventsList event, {bool? client}) async {
// isLoadingInsights = true;
affiliations = await ApiCall().insightsBarChart(
eventid: event.eventId!,
startDate: CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.start!)),
endDate: CustomDateFormatter().formatYearDate(
CustomDateFormatter().convertStringToDate(event.end!)),
client: client ?? false);
//isLoadingInsights = false;
2024-10-07 12:45:45 +00:00
notifyListeners();
}
FutureOr getOverviewData(
String eventid, String startDate, String endDate) async {
overviewData =
(await ApiCall().getEventsOverview(eventid, startDate, endDate));
notifyListeners();
}
2024-11-19 12:57:30 +00:00
FutureOr getAllSessionNotesFromApi(String eid) async {
print("Check hcp id");
// print("$eid,$hcpid");
allSessionNotes = await ApiCall().getAllSessionNotes(eid);
notifyListeners();
}
FutureOr callInsightsDataForClientSpecific(
EventsList event, bool client) async {
await getTopicsCloud(event, client: client);
await getSpecialtyData(event, client: client);
await getAffiliations(event, client: client);
isLoadingInsights = false;
}
2024-11-19 12:57:30 +00:00
//INTERNET CONNECTIVITY
2024-09-06 06:30:31 +00:00
}