Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
View Binding
public class WeeklySurveyFragment extends SmartFragment implements WeeklySurveyView, OnWebserviceResponse {
...
@Override
public void onResume() {
super.onResume();
appetiteDecreaseSeverityResponse = getView().findViewById(R.id.appetite_decrease_severity_response);
appetiteDecreaseInterferenceResponse = getView().findViewById(R.id.appetite_decrease_interference_response);
nauseaFrequencyResponse = getView().findViewById(R.id.nausea_frequency_response);
nauseaSeverityResponse = getView().findViewById(R.id.nausea_severity_response);
vomitingFrequencyResponse = getView().findViewById(R.id.vomiting_frequency_response);
vomitingSeverityResponse = getView().findViewById(R.id.vomiting_severity_response);
constipationSeverityResponse = getView().findViewById(R.id.constipation_severity_response);
diarrheaFrequencyResponse = getView().findViewById(R.id.diarrhea_frequency_response);
abdominalPainFrequencyResponse = getView().findViewById(R.id.abdominal_pain_frequency_response);
abdominalPainSeverityResponse = getView().findViewById(R.id.abdominal_pain_severity_response);
abdominalPainInterferenceResponse = getView().findViewById(R.id.abdominal_pain_interference_response);
shortnessOfBreathSeverityResponse = getView().findViewById(R.id.shortness_of_breath_severity_response);
shortnessOfBreathInterferenceResponse = getView().findViewById(R.id.shortness_of_breath_interference_response);
coughSeverityResponse = getView().findViewById(R.id.cough_severity_response);
coughInterferenceResponse = getView().findViewById(R.id.cough_interference_response);
numbnessSeverityResponse = getView().findViewById(R.id.numbness_severity_response);
numbnessInterferenceResponse = getView().findViewById(R.id.numbness_interference_response);
painFrequencyResponse = getView().findViewById(R.id.pain_frequency_response);
painSeverityResponse = getView().findViewById(R.id.pain_severity_response);
painInterferenceResponse = getView().findViewById(R.id.pain_interference_response);
fatigueSeverityResponse = getView().findViewById(R.id.fatigue_severity_response);
fatigueInterferenceResponse = getView().findViewById(R.id.fatigue_interference_response);
urinationDiscomfortSeverityResponse = getView().findViewById(R.id.urination_discomfort_severity_response);
hotFlashFrequencyResponse = getView().findViewById(R.id.hot_flash_frequency_response);
hotFlashSeverityResponse = getView().findViewById(R.id.hot_flash_severity_response);
final OnWebserviceResponse apiCallRecipient = this;
surveyResponses = new HashMap<>();
surveyResponses.put("appetiteDecreaseSeverityResponse", appetiteDecreaseSeverityResponse);
surveyResponses.put("appetiteDecreaseInterferenceResponse", appetiteDecreaseInterferenceResponse);
surveyResponses.put("nauseaFrequencyResponse", nauseaFrequencyResponse);
surveyResponses.put("nauseaSeverityResponse", nauseaSeverityResponse);
surveyResponses.put("vomitingFrequencyResponse", vomitingFrequencyResponse);
surveyResponses.put("vomitingSeverityResponse", vomitingSeverityResponse);
surveyResponses.put("constipationSeverityResponse", constipationSeverityResponse);
surveyResponses.put("diarrheaFrequencyResponse", diarrheaFrequencyResponse);
surveyResponses.put("abdominalPainFrequencyResponse", abdominalPainFrequencyResponse);
surveyResponses.put("abdominalPainSeverityResponse", abdominalPainSeverityResponse);
surveyResponses.put("abdominalPainInterferenceResponse", abdominalPainInterferenceResponse);
surveyResponses.put("shortnessOfBreathSeverityResponse", shortnessOfBreathSeverityResponse);
surveyResponses.put("shortnessOfBreathInterferenceResponse", shortnessOfBreathInterferenceResponse);
surveyResponses.put("coughSeverityResponse", coughSeverityResponse);
surveyResponses.put("coughInterferenceResponse", coughInterferenceResponse);
surveyResponses.put("numbnessSeverityResponse", numbnessSeverityResponse);
surveyResponses.put("numbnessInterferenceResponse", numbnessInterferenceResponse);
surveyResponses.put("painFrequencyResponse", painFrequencyResponse);
surveyResponses.put("painSeverityResponse", painSeverityResponse);
surveyResponses.put("painInterferenceResponse", painInterferenceResponse);
surveyResponses.put("fatigueSeverityResponse", fatigueSeverityResponse);
surveyResponses.put("fatigueInterferenceResponse", fatigueInterferenceResponse);
surveyResponses.put("urinationDiscomfortSeverityResponse", urinationDiscomfortSeverityResponse);
surveyResponses.put("hotFlashFrequencyResponse", hotFlashFrequencyResponse);
surveyResponses.put("hotFlashSeverityResponse", hotFlashSeverityResponse);
submitSurveyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isFormValid = true;
WeeklySurveyDao weeklySurveyDao = ((AmieApplication) getActivity().getApplication()).getDaoSession().getWeeklySurveyDao();
WeeklySurvey weeklySurvey = new WeeklySurvey();
weeklySurvey.setDate(new Date());
Iterator hmIterator = surveyResponses.entrySet().iterator();
while (hmIterator.hasNext()) {
Map.Entry mapElement = (Map.Entry) hmIterator.next();
String response = extractResponseFor((View) mapElement.getValue());
weeklySurvey.set((String) mapElement.getKey(), response);
}
if (isFormValid) {
sendSurveyResults(weeklySurvey, apiCallRecipient);
DailyQuestionFragment dailyQuestionFragment = DailyQuestionFragment.getInstance();
originPresenter.getFragmentTransaction(dailyQuestionFragment, true).commit();
} else {
weeklySurveyDao.insert(weeklySurvey);
showMessage("", "Oops! Please answer all the questions.", new SmartSuperFragment.OnMessageClick() {
@Override
public void onMessageClick(DialogInterface dialog) {
//dismiss
}
});
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.