in Android/app/src/main/java/com/harvard/studyappmodule/StudyFragment.java [225:630]
private void setStudyList(boolean offline) {
if (!offline) {
dbServiceSubscriber.saveStudyListToDB(context, study);
}
ArrayList<StudyList> activeInprogress = new ArrayList<>();
ArrayList<StudyList> activeYetToJoin = new ArrayList<>();
ArrayList<StudyList> activeOthers = new ArrayList<>();
ArrayList<StudyList> activeOthersSort = new ArrayList<>();
ArrayList<StudyList> paused = new ArrayList<>();
ArrayList<StudyList> pausedSort = new ArrayList<>();
ArrayList<StudyList> closed = new ArrayList<>();
ArrayList<StudyList> closedSort = new ArrayList<>();
ArrayList<StudyList> others = new ArrayList<>();
ArrayList<CompletionAdherence> activeInprogressCompletionAdherenceCalc = new ArrayList<>();
ArrayList<CompletionAdherence> activeYetToJoinCompletionAdherenceCalc = new ArrayList<>();
ArrayList<CompletionAdherence> activeOthersCompletionAdherenceCalc = new ArrayList<>();
ArrayList<CompletionAdherence> pausedCompletionAdherenceCalc = new ArrayList<>();
ArrayList<CompletionAdherence> closedCompletionAdherenceCalc = new ArrayList<>();
ArrayList<CompletionAdherence> othersCompletionAdherenceCalc = new ArrayList<>();
CompletionAdherence completionAdherenceCalc;
CompletionAdherence completionAdherenceCalcSort = null;
SurveyScheduler survayScheduler = new SurveyScheduler(dbServiceSubscriber, realm);
for (int i = 0; i < studyListArrayList.size(); i++) {
if (!AppController.getHelperSharedPreference()
.readPreference(context, context.getResources().getString(R.string.userid), "")
.equalsIgnoreCase("")) {
completionAdherenceCalc =
survayScheduler.completionAndAdherenceCalculation(
studyListArrayList.get(i).getStudyId(), context);
if (completionAdherenceCalc.isActivityAvailable()) {
completionAdherenceCalcSort = completionAdherenceCalc;
} else {
Studies studies =
dbServiceSubscriber.getStudies(studyListArrayList.get(i).getStudyId(), realm);
if (studies != null) {
try {
CompletionAdherence completionAdherenceCalculation = new CompletionAdherence();
completionAdherenceCalculation.setCompletion(studies.getCompletion());
completionAdherenceCalculation.setAdherence(studies.getAdherence());
completionAdherenceCalculation.setActivityAvailable(false);
completionAdherenceCalcSort = completionAdherenceCalculation;
} catch (Exception e) {
CompletionAdherence completionAdherenceCalculation = new CompletionAdherence();
completionAdherenceCalculation.setAdherence(0);
completionAdherenceCalculation.setCompletion(0);
completionAdherenceCalculation.setActivityAvailable(false);
completionAdherenceCalcSort = completionAdherenceCalculation;
Logger.log(e);
}
} else {
CompletionAdherence completionAdherenceCalculation = new CompletionAdherence();
completionAdherenceCalculation.setAdherence(0);
completionAdherenceCalculation.setCompletion(0);
completionAdherenceCalculation.setActivityAvailable(false);
completionAdherenceCalcs.add(completionAdherenceCalculation);
completionAdherenceCalcSort = completionAdherenceCalculation;
}
}
}
if (studyListArrayList.get(i).getStatus().equalsIgnoreCase(ACTIVE)
&& studyListArrayList.get(i).getStudyStatus().equalsIgnoreCase(IN_PROGRESS)) {
activeInprogress.add(studyListArrayList.get(i));
try {
activeInprogressCompletionAdherenceCalc.add(completionAdherenceCalcSort);
} catch (Exception e) {
Logger.log(e);
}
} else if (studyListArrayList.get(i).getStatus().equalsIgnoreCase(ACTIVE)
&& studyListArrayList.get(i).getStudyStatus().equalsIgnoreCase(YET_TO_JOIN)) {
activeYetToJoin.add(studyListArrayList.get(i));
try {
activeYetToJoinCompletionAdherenceCalc.add(completionAdherenceCalcSort);
} catch (Exception e) {
Logger.log(e);
}
} else if (studyListArrayList.get(i).getStatus().equalsIgnoreCase(ACTIVE)) {
activeOthers.add(studyListArrayList.get(i));
try {
activeOthersCompletionAdherenceCalc.add(completionAdherenceCalcSort);
} catch (Exception e) {
Logger.log(e);
}
} else if (studyListArrayList.get(i).getStatus().equalsIgnoreCase(PAUSED)) {
paused.add(studyListArrayList.get(i));
try {
pausedCompletionAdherenceCalc.add(completionAdherenceCalcSort);
} catch (Exception e) {
Logger.log(e);
}
} else if (studyListArrayList.get(i).getStatus().equalsIgnoreCase(CLOSED)) {
closed.add(studyListArrayList.get(i));
try {
closedCompletionAdherenceCalc.add(completionAdherenceCalcSort);
} catch (Exception e) {
Logger.log(e);
}
} else {
others.add(studyListArrayList.get(i));
try {
othersCompletionAdherenceCalc.add(completionAdherenceCalcSort);
} catch (Exception e) {
Logger.log(e);
}
}
}
for (int i = 0; i < activeOthers.size(); i++) {
if (activeOthers.get(i).getStudyStatus().equalsIgnoreCase("completed")) {
activeOthersSort.add(activeOthers.get(i));
}
}
for (int i = 0; i < activeOthers.size(); i++) {
if (activeOthers.get(i).getStudyStatus().equalsIgnoreCase("withdrawn")) {
activeOthersSort.add(activeOthers.get(i));
}
}
for (int i = 0; i < activeOthers.size(); i++) {
if (activeOthers.get(i).getStudyStatus().equalsIgnoreCase("notEligible")) {
activeOthersSort.add(activeOthers.get(i));
}
}
for (int i = 0; i < paused.size(); i++) {
if (paused.get(i).getStudyStatus().equalsIgnoreCase("enrolled")) {
pausedSort.add(paused.get(i));
}
}
for (int i = 0; i < paused.size(); i++) {
if (paused.get(i).getStudyStatus().equalsIgnoreCase("yetToEnroll")) {
pausedSort.add(paused.get(i));
}
}
for (int i = 0; i < paused.size(); i++) {
if (paused.get(i).getStudyStatus().equalsIgnoreCase("completed")) {
pausedSort.add(paused.get(i));
}
}
for (int i = 0; i < paused.size(); i++) {
if (paused.get(i).getStudyStatus().equalsIgnoreCase("withdrawn")) {
pausedSort.add(paused.get(i));
}
}
for (int i = 0; i < paused.size(); i++) {
if (paused.get(i).getStudyStatus().equalsIgnoreCase("notEligible")) {
pausedSort.add(paused.get(i));
}
}
for (int i = 0; i < closed.size(); i++) {
if (closed.get(i).getStudyStatus().equalsIgnoreCase("enrolled")) {
closedSort.add(closed.get(i));
}
}
for (int i = 0; i < closed.size(); i++) {
if (closed.get(i).getStudyStatus().equalsIgnoreCase("yetToEnroll")) {
closedSort.add(closed.get(i));
}
}
for (int i = 0; i < closed.size(); i++) {
if (closed.get(i).getStudyStatus().equalsIgnoreCase("completed")) {
closedSort.add(closed.get(i));
}
}
for (int i = 0; i < closed.size(); i++) {
if (closed.get(i).getStudyStatus().equalsIgnoreCase("withdrawn")) {
closedSort.add(closed.get(i));
}
}
for (int i = 0; i < closed.size(); i++) {
if (closed.get(i).getStudyStatus().equalsIgnoreCase("notEligible")) {
closedSort.add(closed.get(i));
}
}
if (offline) {
try {
studyListArrayList = dbServiceSubscriber.clearStudyList(studyListArrayList, realm);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList =
dbServiceSubscriber.updateStudyList(studyListArrayList, activeInprogress, realm);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList =
dbServiceSubscriber.updateStudyList(studyListArrayList, activeYetToJoin, realm);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList =
dbServiceSubscriber.updateStudyList(studyListArrayList, activeOthersSort, realm);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList =
dbServiceSubscriber.updateStudyList(studyListArrayList, pausedSort, realm);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList =
dbServiceSubscriber.updateStudyList(studyListArrayList, closedSort, realm);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList = dbServiceSubscriber.updateStudyList(studyListArrayList, others, realm);
} catch (Exception e) {
Logger.log(e);
}
} else {
try {
studyListArrayList.clear();
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList.addAll(activeInprogress);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList.addAll(activeYetToJoin);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList.addAll(activeOthersSort);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList.addAll(pausedSort);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList.addAll(closedSort);
} catch (Exception e) {
Logger.log(e);
}
try {
studyListArrayList.addAll(others);
} catch (Exception e) {
Logger.log(e);
}
}
try {
completionAdherenceCalcs.clear();
} catch (Exception e) {
Logger.log(e);
}
try {
completionAdherenceCalcs.addAll(activeInprogressCompletionAdherenceCalc);
} catch (Exception e) {
Logger.log(e);
}
try {
completionAdherenceCalcs.addAll(activeYetToJoinCompletionAdherenceCalc);
} catch (Exception e) {
Logger.log(e);
}
try {
completionAdherenceCalcs.addAll(activeOthersCompletionAdherenceCalc);
} catch (Exception e) {
Logger.log(e);
}
try {
completionAdherenceCalcs.addAll(pausedCompletionAdherenceCalc);
} catch (Exception e) {
Logger.log(e);
}
try {
completionAdherenceCalcs.addAll(closedCompletionAdherenceCalc);
} catch (Exception e) {
Logger.log(e);
}
try {
completionAdherenceCalcs.addAll(othersCompletionAdherenceCalc);
} catch (Exception e) {
Logger.log(e);
}
activeInprogress.clear();
activeInprogress = null;
activeInprogressCompletionAdherenceCalc.clear();
activeInprogressCompletionAdherenceCalc = null;
activeYetToJoin.clear();
activeYetToJoin = null;
activeYetToJoinCompletionAdherenceCalc.clear();
activeYetToJoinCompletionAdherenceCalc = null;
activeOthers.clear();
activeOthersSort.clear();
activeOthers = null;
activeOthersSort = null;
activeOthersCompletionAdherenceCalc.clear();
activeOthersCompletionAdherenceCalc = null;
paused.clear();
pausedSort.clear();
paused = null;
pausedSort = null;
pausedCompletionAdherenceCalc.clear();
pausedCompletionAdherenceCalc = null;
closed.clear();
closedSort.clear();
closed = null;
closedSort = null;
closedCompletionAdherenceCalc.clear();
closedCompletionAdherenceCalc = null;
others.clear();
others = null;
othersCompletionAdherenceCalc.clear();
othersCompletionAdherenceCalc = null;
studyRecyclerView.setLayoutManager(new LinearLayoutManager(context));
studyRecyclerView.setNestedScrollingEnabled(false);
String jsonObjectString;
try {
jsonObjectString =
AppController.getHelperSharedPreference()
.readPreference(context, getContext().getString(R.string.json_object_filter), "");
} catch (Exception e) {
jsonObjectString = "";
}
// cheking filtered conditin is ther ; if "" means no filtered condition
if (jsonObjectString.equalsIgnoreCase("")) {
// chkng for showing search list (scenario search--->go details screen----> return back; )
String searchKey;
try {
searchKey = ((StudyActivity) getActivity()).getSearchKey();
} catch (Exception e) {
searchKey = null;
}
if (searchKey != null) {
// search list retain
studyListAdapter =
new StudyListAdapter(
context,
searchResult(searchKey),
StudyFragment.this,
filteredCompletionAdherenceCalcs);
} else {
studyListAdapter =
new StudyListAdapter(
context,
copyOfFilteredStudyList(),
StudyFragment.this,
filteredCompletionAdherenceCalcs);
}
} else {
addFilterCriteria(jsonObjectString, completionAdherenceCalcs);
}
studyRecyclerView.setAdapter(studyListAdapter);
if (!AppController.getHelperSharedPreference()
.readPreference(context, context.getResources().getString(R.string.userid), "")
.equalsIgnoreCase("")
&& AppController.getHelperSharedPreference()
.readPreference(context, "firstStudyState", "")
.equalsIgnoreCase("")) {
studyRecyclerView.setVisibility(View.GONE);
} else {
studyRecyclerView.setVisibility(View.VISIBLE);
}
}