Search in sources :

Example 1 with EventsDataModel

use of com.example.first_responder_app.dataModels.EventsDataModel in project FirstResponse by mattpost1700.

the class FirestoreDatabase method addEvent.

// TODO: Add event correctly
public void addEvent(String location, String title, String description, Date date, int duration) {
    Timestamp eventTime = new Timestamp(date);
    EventsDataModel newEvent = new EventsDataModel(activeUserFireDepartmentId, "TEMP_GROUP_ID", activeUser.getDocumentId(), eventTime, title, description, location, duration);
    db.collection(EVENTS_COLLECTION_DIR).add(newEvent).addOnSuccessListener(documentReference -> Log.d("new event page", "new event has been successfully created in the DB")).addOnFailureListener(e -> Log.d("new event page", "failed to create new event"));
}
Also used : Context(android.content.Context) ChatViewModel(com.example.first_responder_app.viewModels.ChatViewModel) NonNull(androidx.annotation.NonNull) Date(java.util.Date) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChatRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.ChatRecyclerViewAdapter) EventsDataModel(com.example.first_responder_app.dataModels.EventsDataModel) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) Map(java.util.Map) TAG(android.content.ContentValues.TAG) Log(android.util.Log) Message(com.example.first_responder_app.messaging.Message) FirebaseStorage(com.google.firebase.storage.FirebaseStorage) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) Timestamp(com.google.firebase.Timestamp) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) List(java.util.List) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) StorageReference(com.google.firebase.storage.StorageReference) AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel) Pattern(java.util.regex.Pattern) RanksDataModel(com.example.first_responder_app.dataModels.RanksDataModel) EventsDataModel(com.example.first_responder_app.dataModels.EventsDataModel) Timestamp(com.google.firebase.Timestamp)

Example 2 with EventsDataModel

use of com.example.first_responder_app.dataModels.EventsDataModel in project FirstResponse by mattpost1700.

the class EventGroupFragment method populateEventList.

private void populateEventList() {
    db.collection("events").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).orderBy("event_time", Query.Direction.ASCENDING).whereGreaterThanOrEqualTo("event_time", Timestamp.now()).get().addOnCompleteListener(eventTask -> {
        Log.d(TAG, "READ DATABASE - EVENT GROUP FRAGMENT");
        if (eventTask.isSuccessful()) {
            ArrayList<EventsDataModel> temp = new ArrayList<>();
            for (QueryDocumentSnapshot eventDoc : eventTask.getResult()) {
                EventsDataModel eventDataModel = eventDoc.toObject(EventsDataModel.class);
                temp.add(eventDataModel);
            }
            Log.d(TAG, "populateEventList: " + temp.size());
            listOfEvents.clear();
            listOfEvents.addAll(temp);
            checkEventsEmpty();
            eventGroupRecyclerViewAdapter.notifyDataSetChanged();
        } else {
            Log.d(TAG, "db get failed in event page " + eventTask.getException());
        }
    });
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) EventsDataModel(com.example.first_responder_app.dataModels.EventsDataModel)

Example 3 with EventsDataModel

use of com.example.first_responder_app.dataModels.EventsDataModel in project FirstResponse by mattpost1700.

the class EventGroupRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    EventsDataModel events = mData.get(position);
    holder.title.setText(events.getTitle());
    if (events.getEvent_time() != null) {
        Date date = events.getEvent_time().toDate();
        String time = new SimpleDateFormat("MM/dd/yy\nh:mm aa", Locale.getDefault()).format(date);
        holder.date.setText(time);
    }
    holder.location.setText(events.getLocation());
    holder.data = events;
}
Also used : EventsDataModel(com.example.first_responder_app.dataModels.EventsDataModel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

EventsDataModel (com.example.first_responder_app.dataModels.EventsDataModel)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 TAG (android.content.ContentValues.TAG)1 Context (android.content.Context)1 Log (android.util.Log)1 NonNull (androidx.annotation.NonNull)1 AnnouncementsDataModel (com.example.first_responder_app.dataModels.AnnouncementsDataModel)1 IncidentDataModel (com.example.first_responder_app.dataModels.IncidentDataModel)1 RanksDataModel (com.example.first_responder_app.dataModels.RanksDataModel)1 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)1 ActiveUser (com.example.first_responder_app.interfaces.ActiveUser)1 Message (com.example.first_responder_app.messaging.Message)1 ChatRecyclerViewAdapter (com.example.first_responder_app.recyclerViews.ChatRecyclerViewAdapter)1 ChatViewModel (com.example.first_responder_app.viewModels.ChatViewModel)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 Timestamp (com.google.firebase.Timestamp)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1