Search in sources :

Example 1 with AnnouncementsDataModel

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

the class AnnouncementFragment method populateAnnouncmentList.

private void populateAnnouncmentList() {
    Task getAnnoucementsForGroups = db.collection("announcements").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereIn("intended_group_id", activeUser.getGroup_ids()).orderBy(FirestoreDatabase.FIELD_CREATED_AT, Query.Direction.DESCENDING).get();
    Task getAnnouncementsForAll = db.collection("announcements").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereEqualTo("intended_group_id", null).orderBy(FirestoreDatabase.FIELD_CREATED_AT, Query.Direction.DESCENDING).get();
    Tasks.whenAllSuccess(getAnnoucementsForGroups, getAnnouncementsForAll).addOnSuccessListener(objects -> {
        ArrayList<AnnouncementsDataModel> temp = new ArrayList<>();
        for (Object fakeQuerySnapshot : objects) {
            QuerySnapshot querySnapshot = ((QuerySnapshot) fakeQuerySnapshot);
            for (QueryDocumentSnapshot announcementDoc : querySnapshot) {
                AnnouncementsDataModel announcementDataModel = announcementDoc.toObject(AnnouncementsDataModel.class);
                temp.add(announcementDataModel);
            }
        }
        listOfAnnouncements.clear();
        listOfAnnouncements.addAll(temp);
        checkAnnouncementEmpty();
        announcementAdapter.notifyDataSetChanged();
    }).addOnFailureListener(e -> Log.e(TAG, "populateAnnouncmentList: db get failed in announcement page", e));
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Query(com.google.firebase.firestore.Query) Task(com.google.android.gms.tasks.Task) NavController(androidx.navigation.NavController) ArrayList(java.util.ArrayList) AnnouncementViewModel(com.example.first_responder_app.viewModels.AnnouncementViewModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) FragmentAnnouncementBinding(com.example.first_responder_app.databinding.FragmentAnnouncementBinding) RecyclerView(androidx.recyclerview.widget.RecyclerView) TAG(android.content.ContentValues.TAG) Log(android.util.Log) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) AnnouncementRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.AnnouncementRecyclerViewAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) AppUtil(com.example.first_responder_app.AppUtil) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) ViewGroup(android.view.ViewGroup) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) List(java.util.List) Nullable(androidx.annotation.Nullable) Tasks(com.google.android.gms.tasks.Tasks) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel) Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 2 with AnnouncementsDataModel

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

the class FirestoreDatabase method addAnnouncement.

// TODO: Add group id
public void addAnnouncement(String title, String description, UsersDataModel user) {
    setActiveUser(user);
    AnnouncementsDataModel newAnnoun = new AnnouncementsDataModel(activeUserFireDepartmentId, user.getDocumentId(), activeUser.getDocumentId(), title, description);
    db.collection(ANNOUNCEMENTS_COLLECTION_DIR).add(newAnnoun).addOnSuccessListener(documentReference -> Log.d("new announcement page", "new announcement has been successfully created in the DB")).addOnFailureListener(e -> Log.d("new announcement page", "failed to create new announcement"));
}
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) AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel)

Example 3 with AnnouncementsDataModel

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

the class AnnouncementRecyclerViewAdapter method onBindViewHolder.

// binds the data to the TextView in each row
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    AnnouncementsDataModel announ = mData.get(position);
    holder.title.setText(announ.getTitle());
    holder.des.setText(announ.getDescription());
    String dateString = new SimpleDateFormat("MM/dd h:mm aa", Locale.getDefault()).format(announ.getCreated_at().toDate());
    holder.annoucementTime.setText(dateString);
}
Also used : AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AnnouncementsDataModel (com.example.first_responder_app.dataModels.AnnouncementsDataModel)3 TAG (android.content.ContentValues.TAG)2 Log (android.util.Log)2 NonNull (androidx.annotation.NonNull)2 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)2 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Context (android.content.Context)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Toast (android.widget.Toast)1 Nullable (androidx.annotation.Nullable)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 Fragment (androidx.fragment.app.Fragment)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavController (androidx.navigation.NavController)1 NavDirections (androidx.navigation.NavDirections)1