Search in sources :

Example 6 with UsersDataModel

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

the class NewChatFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    // binding fragment with nav_map by using navHostFragment, throw this block of code in there and that allows you to switch to other fragments
    ChatNewFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.chat_new_fragment, container, false);
    NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    // TODO: navCont created for side bar(still need to be implemented)
    NavController navController = navHostFragment.getNavController();
    firestoreDatabase = new FirestoreDatabase();
    db = FirebaseFirestore.getInstance();
    activeUser = (ActiveUser) getActivity();
    if (activeUser != null) {
        user = activeUser.getActive();
    }
    listOfUsers = new ArrayList<>();
    populateUserList();
    listOfNewUsers = new ArrayList<>();
    NewChatRecyclerViewAdapter.ItemClickListener userClickListener = ((view, position, data) -> {
        // remove user
        listOfNewUsers.remove(data);
        newChatRecyclerViewAdapter.notifyDataSetChanged();
    });
    RecyclerView newChatRecyclerView = binding.newChatRecyclerView;
    newChatRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    newChatRecyclerViewAdapter = new NewChatRecyclerViewAdapter(getContext(), listOfNewUsers);
    newChatRecyclerViewAdapter.setClickListener(userClickListener);
    newChatRecyclerView.setAdapter(newChatRecyclerViewAdapter);
    newChatRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7) {
            newChatRecyclerView.removeOnLayoutChangeListener(this);
        // newChatRecyclerView.scrollToPosition(newChatRecyclerView.getAdapter().getItemCount() - 1);
        }
    });
    binding.newChatAddUserFab.setOnClickListener(v -> {
        String newUserName = binding.newChatUsersEditText.getText().toString();
        UsersDataModel result = listOfUsers.stream().filter(u -> newUserName.equals(u.getFull_name())).findAny().orElse(null);
        // If user exists, is not the current user, and has not already been added
        if (result != null && !result.getDocumentId().equals(user.getDocumentId()) && !listOfNewUsers.contains(result)) {
            binding.newChatErrorMsg.setText("");
            listOfNewUsers.add(result);
            newChatRecyclerViewAdapter.notifyDataSetChanged();
        } else {
            binding.newChatErrorMsg.setText("User not found");
        }
    });
    binding.newChatCreateConfirm.setOnClickListener(v -> {
        String chatName = binding.newChatChatNameEditText.getText().toString();
        if (listOfNewUsers.size() == 0) {
            binding.newChatErrorMsg.setText("Must add users to the chat");
        } else if (chatName.length() == 0) {
            binding.newChatErrorMsg.setText("Chat name must not be blank");
        } else {
            listOfNewUsers.add(user);
            firestoreDatabase.addChat(chatName, listOfNewUsers);
        }
        NavDirections action = NewChatFragmentDirections.actionNewChatFragmentToChatGroupFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    return binding.getRoot();
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) NavController(androidx.navigation.NavController) NewChatRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.NewChatRecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ChatNewFragmentBinding(com.example.first_responder_app.databinding.ChatNewFragmentBinding) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavDirections(androidx.navigation.NavDirections) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavHostFragment(androidx.navigation.fragment.NavHostFragment) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase)

Example 7 with UsersDataModel

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

the class SearchUserFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    SearchUserFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.search_user_fragment, container, false);
    activeUser = AppUtil.getActiveUser(getActivity());
    listOfAllFireDepartmentUsers = new ArrayList<>();
    adapter = new SearchUserAdapter(getContext(), listOfAllFireDepartmentUsers);
    searchView = binding.search;
    listView = binding.listview;
    fillList();
    listView.setOnItemClickListener((parent, view, position, id) -> {
        UsersDataModel selectedUser = listOfAllFireDepartmentUsers.get(position);
        // Go to admin edit user
        mViewModel = new ViewModelProvider(requireActivity()).get(SearchUserViewModel.class);
        mViewModel.setSelectedUser(selectedUser);
        NavDirections action = SearchUserFragmentDirections.actionSearchUserFragmentToAdminEditUserFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    final SwipeRefreshLayout pullToRefresh = binding.searchUserSwipe;
    pullToRefresh.setOnRefreshListener(() -> {
        fillList();
        pullToRefresh.setRefreshing(false);
    });
    listView.setAdapter(adapter);
    searchView.setOnQueryTextListener(this);
    return binding.getRoot();
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) SearchUserAdapter(com.example.first_responder_app.SearchUserAdapter) SearchUserFragmentBinding(com.example.first_responder_app.databinding.SearchUserFragmentBinding) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ViewModelProvider(androidx.lifecycle.ViewModelProvider) SearchUserViewModel(com.example.first_responder_app.viewModels.SearchUserViewModel) NavDirections(androidx.navigation.NavDirections)

Example 8 with UsersDataModel

use of com.example.first_responder_app.dataModels.UsersDataModel 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 9 with UsersDataModel

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

the class FirestoreDatabase method userModelMembersToStringMembers.

private List<String> userModelMembersToStringMembers(List<UsersDataModel> userModelMembers) {
    ArrayList<String> stringMembers = new ArrayList<String>();
    for (UsersDataModel u : userModelMembers) {
        String memberName = u.getFull_name() + "/" + u.getDocumentId();
        stringMembers.add(memberName);
    }
    return stringMembers;
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ArrayList(java.util.ArrayList)

Example 10 with UsersDataModel

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

the class MainActivity method setActive.

/**
 * Set the logged in user
 * @param user the user who just logged in
 */
@Override
public void setActive(UsersDataModel user) {
    Log.d(TAG, "setActive: " + user);
    if (user == null) {
        this.activeUser = null;
        if (userListener != null) {
            userListener.remove();
            userListener = null;
        }
        if (incidentListener != null) {
            incidentListener.remove();
            incidentListener = null;
        }
        stopETA();
        return;
    }
    this.activeUser = user;
    NavigationView navView = findViewById(R.id.navView);
    View header = navView.getHeaderView(0);
    TextView name = header.findViewById(R.id.nav_name);
    TextView username = header.findViewById(R.id.nav_username);
    String fullName = user.getFirst_name() + " " + user.getLast_name();
    name.setText(fullName);
    username.setText(user.getUsername());
    // Ensure that the active user data is updated if database is updated
    if (userListener == null) {
        DocumentReference docRef = FirestoreDatabase.getInstance().getDb().collection("users").document(user.getDocumentId());
        userListener = docRef.addSnapshotListener((snapshot, err) -> {
            Log.d(TAG, "READ DATABASE - MAIN ACTIVITY");
            if (err != null) {
                System.err.println("Listen failed: " + err);
                return;
            }
            if (snapshot != null && snapshot.exists()) {
                activeUser = snapshot.toObject(UsersDataModel.class);
                // Find the address of the department and determine where they are responding
                setRespAddr();
                // Download profile pic
                try {
                    if (activeUser.getRemote_path_to_profile_picture() != null) {
                        final File localFile = File.createTempFile("Images", "bmp");
                        StorageReference ref = FirestoreDatabase.profilePictureRef.child(activeUser.getRemote_path_to_profile_picture());
                        ref.getFile(localFile).addOnSuccessListener(bytes -> {
                            try {
                                ((ImageView) findViewById(R.id.appDrawerProfilePicImageView)).setImageBitmap(BitmapFactory.decodeFile(localFile.getAbsolutePath()));
                            } catch (Exception e) {
                                Log.d(TAG, "onCreateView: No profile picture found");
                            }
                        }).addOnFailureListener(e -> {
                            Log.w(TAG, "getUserProfile: Could not load profile picture!", e);
                        });
                    }
                } catch (IOException e) {
                    Log.e(TAG, "onCreateView: Failed creating temp file", e);
                } catch (NullPointerException e) {
                    Log.e(TAG, "onCreate: Cannot get user", e);
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "onCreate: User has no image", e);
                }
            } else {
                System.out.print("Current data: null");
            }
        });
    }
}
Also used : Address(android.location.Address) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) ImageView(android.widget.ImageView) LocationListener(android.location.LocationListener) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Drawable(android.graphics.drawable.Drawable) NavController(androidx.navigation.NavController) ActionBar(androidx.appcompat.app.ActionBar) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) Manifest(android.Manifest) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Locale(java.util.Locale) ETA(com.example.first_responder_app.DirectionAPI.ETA) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) MenuCompat(androidx.core.view.MenuCompat) NavHostFragment(androidx.navigation.fragment.NavHostFragment) Log(android.util.Log) LatLng(com.google.android.gms.maps.model.LatLng) Geocoder(android.location.Geocoder) IncidentFragment(com.example.first_responder_app.fragments.IncidentFragment) List(java.util.List) TextView(android.widget.TextView) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) StorageReference(com.google.firebase.storage.StorageReference) Toolbar(androidx.appcompat.widget.Toolbar) Location(android.location.Location) LocationManager(android.location.LocationManager) Context(android.content.Context) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) NavigationView(com.google.android.material.navigation.NavigationView) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration) BitmapFactory(android.graphics.BitmapFactory) DrawerLocker(com.example.first_responder_app.interfaces.DrawerLocker) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) DocumentReference(com.google.firebase.firestore.DocumentReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) NavigationUI(androidx.navigation.ui.NavigationUI) Toast(android.widget.Toast) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) TAG(android.content.ContentValues.TAG) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) FragmentManager(androidx.fragment.app.FragmentManager) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ActivityCompat(androidx.core.app.ActivityCompat) GravityCompat(androidx.core.view.GravityCompat) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) IOException(java.io.IOException) File(java.io.File) FireDepartmentDataModel(com.example.first_responder_app.dataModels.FireDepartmentDataModel) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) SharedPreferences(android.content.SharedPreferences) RefreshETAs(com.example.first_responder_app.interfaces.RefreshETAs) PreferenceManager(androidx.preference.PreferenceManager) NavigationView(com.google.android.material.navigation.NavigationView) StorageReference(com.google.firebase.storage.StorageReference) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) NavigationView(com.google.android.material.navigation.NavigationView) IOException(java.io.IOException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) File(java.io.File) DocumentReference(com.google.firebase.firestore.DocumentReference)

Aggregations

UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)26 ArrayList (java.util.ArrayList)10 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)9 ActiveUser (com.example.first_responder_app.interfaces.ActiveUser)8 SuppressLint (android.annotation.SuppressLint)6 View (android.view.View)6 ViewModelProvider (androidx.lifecycle.ViewModelProvider)6 NavDirections (androidx.navigation.NavDirections)6 NonNull (androidx.annotation.NonNull)5 NavHostFragment (androidx.navigation.fragment.NavHostFragment)5 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)5 TAG (android.content.ContentValues.TAG)4 Context (android.content.Context)4 Bundle (android.os.Bundle)4 Log (android.util.Log)4 Toast (android.widget.Toast)4 Fragment (androidx.fragment.app.Fragment)4 UserViewModel (com.example.first_responder_app.viewModels.UserViewModel)4 List (java.util.List)4 Manifest (android.Manifest)3