Search in sources :

Example 1 with RefreshETAs

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);
        }
    }
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) Button(android.widget.Button) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) ArrayList(java.util.ArrayList) ColorStateList(android.content.res.ColorStateList) List(java.util.List) ArrayList(java.util.ArrayList) RefreshETAs(com.example.first_responder_app.interfaces.RefreshETAs)

Aggregations

ColorStateList (android.content.res.ColorStateList)1 Button (android.widget.Button)1 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)1 ActiveUser (com.example.first_responder_app.interfaces.ActiveUser)1 RefreshETAs (com.example.first_responder_app.interfaces.RefreshETAs)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1