in Android/app/src/main/java/com/harvard/studyappmodule/StudyFragment.java [831:1036]
public <T> void asyncResponse(T response, int responseCode) {
if (responseCode == STUDY_LIST) {
if (response != null) {
study = (Study) response;
studyListArrayList = study.getStudies();
Collections.sort(
studyListArrayList,
new Comparator<StudyList>() {
@Override
public int compare(StudyList studyList, StudyList t1) {
return studyList.getTitle().compareTo(t1.getTitle());
}
});
if (AppController.getHelperSharedPreference()
.readPreference(context, context.getString(R.string.userid), "")
.equalsIgnoreCase("")) {
if (count == 1) {
AppController.getHelperProgressDialog().dismissDialog();
}
onItemsLoadComplete();
webserviceCall = false;
setStudyList(false);
} else {
HashMap<String, String> header = new HashMap();
header.put(
"Authorization",
"Bearer "
+ AppController.getHelperSharedPreference()
.readPreference(context, getResources().getString(R.string.auth), ""));
header.put(
"userId",
AppController.getHelperSharedPreference()
.readPreference(context, getResources().getString(R.string.userid), ""));
header.put("deviceType", android.os.Build.MODEL);
header.put("deviceOS", Build.VERSION.RELEASE);
header.put("mobilePlatform", "ANDROID");
ParticipantEnrollmentDatastoreConfigEvent participantEnrollmentDatastoreConfigEvent =
new ParticipantEnrollmentDatastoreConfigEvent(
"get",
Urls.STUDY_STATE,
GET_PREFERENCES,
context,
StudyData.class,
null,
header,
null,
false,
this);
GetPreferenceEvent getPreferenceEvent = new GetPreferenceEvent();
getPreferenceEvent.setParticipantEnrollmentDatastoreConfigEvent(
participantEnrollmentDatastoreConfigEvent);
UserModulePresenter userModulePresenter = new UserModulePresenter();
userModulePresenter.performGetUserPreference(getPreferenceEvent);
}
} else {
webserviceCall = false;
AppController.getHelperProgressDialog().dismissDialog();
onItemsLoadComplete();
Toast.makeText(context, R.string.unable_to_parse, Toast.LENGTH_SHORT).show();
}
} else if (responseCode == CONSENT_METADATA) {
AppController.getHelperProgressDialog().dismissDialog();
eligibilityConsent = (EligibilityConsent) response;
if (eligibilityConsent != null) {
eligibilityConsent.setStudyId(studyId);
saveConsentToDB(context, eligibilityConsent);
startConsent(
eligibilityConsent.getConsent(), eligibilityConsent.getEligibility().getType());
} else {
Toast.makeText(context, R.string.unable_to_parse, Toast.LENGTH_SHORT).show();
}
} else if (responseCode == GET_PREFERENCES) {
AppController.getHelperSharedPreference().writePreference(context, "firstStudyState", "Done");
AppController.getHelperProgressDialog().dismissDialog();
onItemsLoadComplete();
webserviceCall = false;
StudyData studies = (StudyData) response;
if (studies != null) {
studies.setUserId(
AppController.getHelperSharedPreference()
.readPreference(context, getString(R.string.userid), ""));
dbServiceSubscriber.saveStudyPreferencesToDB(context, studies);
RealmList<Studies> userPreferenceStudies = studies.getStudies();
if (userPreferenceStudies != null) {
for (int i = 0; i < userPreferenceStudies.size(); i++) {
for (int j = 0; j < studyListArrayList.size(); j++) {
if (userPreferenceStudies
.get(i)
.getStudyId()
.equalsIgnoreCase(studyListArrayList.get(j).getStudyId())) {
studyListArrayList.get(j).setStudyStatus(userPreferenceStudies.get(i).getStatus());
}
// update study completed status
}
}
} else {
Toast.makeText(context, R.string.error_retriving_data, Toast.LENGTH_SHORT).show();
}
setStudyList(false);
((StudyActivity) getContext())
.checkForNotification(((StudyActivity) getContext()).getIntent());
} else {
Toast.makeText(context, R.string.unable_to_parse, Toast.LENGTH_SHORT).show();
}
} else if (responseCode == UPDATE_PREFERENCES) {
LoginData loginData = (LoginData) response;
AppController.getHelperProgressDialog().dismissDialog();
if (loginData != null && loginData.getMessage().equalsIgnoreCase("success")) {
Toast.makeText(context, R.string.update_success, Toast.LENGTH_SHORT).show();
dbServiceSubscriber.updateStudyPreferenceToDb(
context, lastUpdatedStudyId, lastUpdatedStatusStatus);
studyListAdapter.notifyItemChanged(lastUpdatedPosition);
/// delete offline row
dbServiceSubscriber.deleteOfflineDataRow(context, deleteIndexNumberDb);
}
} else if (responseCode == STUDY_UPDATES) {
StudyUpdate studyUpdate = (StudyUpdate) response;
studyUpdate.setStudyId(studyId);
StudyUpdateListdata studyUpdateListdata = new StudyUpdateListdata();
RealmList<StudyUpdate> studyUpdates = new RealmList<>();
studyUpdates.add(studyUpdate);
studyUpdateListdata.setStudyUpdates(studyUpdates);
dbServiceSubscriber.saveStudyUpdateListdataToDB(context, studyUpdateListdata);
if (studyUpdate.getStudyUpdateData().isResources()) {
dbServiceSubscriber.deleteResourcesFromDb(context, studyId);
}
if (studyUpdate.getStudyUpdateData().isInfo()) {
dbServiceSubscriber.deleteStudyInfoFromDb(context, studyId);
}
if (studyUpdate.getStudyUpdateData().isConsent() && studyUpdate.isEnrollAgain()) {
callConsentMetaDataWebservice();
} else {
AppController.getHelperProgressDialog().dismissDialog();
Intent intent = new Intent(context, SurveyActivity.class);
intent.putExtra("studyId", studyId);
intent.putExtra("to", calledFor);
intent.putExtra("from", from);
intent.putExtra("activityId", activityId);
intent.putExtra("localNotification", localNotification);
context.startActivity(intent);
}
} else if (responseCode == GET_CONSENT_DOC) {
ConsentDocumentData consentDocumentData = (ConsentDocumentData) response;
consentDocumentData.setStudyId(studyId);
dbServiceSubscriber.saveConsentDocumentToDB(context, consentDocumentData);
latestConsentVersion = consentDocumentData.getConsent().getVersion();
enrollAgain = consentDocumentData.isEnrollAgain();
callGetConsentPdfWebservice();
} else if (responseCode == CONSENTPDF) {
String version = "";
ConsentPDF consentPdfData = (ConsentPDF) response;
StudyData studyData = dbServiceSubscriber.getStudyPreferencesListFromDB(realm);
for (int i = 0; i < studyData.getStudies().size(); i++) {
if (studyData.getStudies().get(i).getStudyId().equalsIgnoreCase(studyId)) {
version = studyData.getStudies().get(i).getUserStudyVersion();
}
}
if (version != null && (!latestConsentVersion.equalsIgnoreCase(version))) {
if (!consentPdfData.getConsent().getVersion().equalsIgnoreCase(latestConsentVersion)) {
callConsentMetaDataWebservice();
} else {
AppController.getHelperProgressDialog().dismissDialog();
Intent intent = new Intent(context, SurveyActivity.class);
intent.putExtra("studyId", studyId);
intent.putExtra("to", calledFor);
intent.putExtra("from", from);
intent.putExtra("activityId", activityId);
intent.putExtra("localNotification", localNotification);
context.startActivity(intent);
}
} else if (enrollAgain
&& latestConsentVersion != null
&& consentPdfData != null
&& consentPdfData.getConsent() != null
&& consentPdfData.getConsent().getVersion() != null) {
if (!consentPdfData.getConsent().getVersion().equalsIgnoreCase(latestConsentVersion)) {
callConsentMetaDataWebservice();
} else {
AppController.getHelperProgressDialog().dismissDialog();
Intent intent = new Intent(context, SurveyActivity.class);
intent.putExtra("studyId", studyId);
intent.putExtra("to", calledFor);
intent.putExtra("from", from);
intent.putExtra("activityId", activityId);
intent.putExtra("localNotification", localNotification);
context.startActivity(intent);
}
} else {
AppController.getHelperProgressDialog().dismissDialog();
Intent intent = new Intent(context, SurveyActivity.class);
intent.putExtra("studyId", studyId);
intent.putExtra("to", calledFor);
intent.putExtra("from", from);
intent.putExtra("activityId", activityId);
intent.putExtra("localNotification", localNotification);
context.startActivity(intent);
}
}
}