use of com.example.first_responder_app.interfaces.RefreshETAs in project FirstResponse by mattpost1700.
the class IncidentFragment method respondingButtonClicked.
/**
* When responding button is clicked update active users responding status
*
* @param b the button that was clicked
*/
public void respondingButtonClicked(View b) {
Log.d(TAG, "respondingButtonClicked: " + ((Button) b).getText());
String text = ((Button) b).getText().toString();
String id = incidentDataModel.getDocumentId();
// Get active user id
ActiveUser active = (ActiveUser) getActivity();
UsersDataModel activeUser = null;
if (active != null) {
activeUser = active.getActive();
}
if (activeUser == null && context != null) {
Toast.makeText(context, "You must be logged in", Toast.LENGTH_LONG).show();
} else if (activeUser != null) {
List<String> responses = activeUser.getResponses();
if (!AppUtil.timeIsWithin(activeUser.getResponding_time(), requireContext())) {
responses = new ArrayList<>();
}
// TODO: remove hardcoded string
if (text.equals("Unavailable")) {
FirestoreDatabase.getInstance().responding(activeUser.getDocumentId(), incidentDataModel, text, false, responses, null);
setActiveButton(text);
} else {
FirestoreDatabase.getInstance().responding(activeUser.getDocumentId(), incidentDataModel, text, true, responses, () -> {
RefreshETAs refreshETAs = (RefreshETAs) getActivity();
refreshETAs.refresh();
});
setActiveButton(text);
}
}
}
Aggregations