From d2af690a4f1fc4a7a08f15d42dfca2ff755ca7a6 Mon Sep 17 00:00:00 2001 From: Salzeem Date: Mon, 21 Nov 2022 16:58:35 -0500 Subject: [PATCH 01/14] First Push; Edit groups --- .idea/deploymentTargetDropDown.xml | 17 ----- .../example/android/CreateGroupFragment.java | 70 +++++++++++++++---- .../com/example/android/GroupFragment.java | 54 +++++++++++++- .../com/example/android/MainActivity.java | 4 +- build.gradle | 4 +- 5 files changed, 115 insertions(+), 34 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index c5dca4c..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/example/android/CreateGroupFragment.java b/app/src/main/java/com/example/android/CreateGroupFragment.java index aab71e1..c23532d 100644 --- a/app/src/main/java/com/example/android/CreateGroupFragment.java +++ b/app/src/main/java/com/example/android/CreateGroupFragment.java @@ -15,19 +15,26 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast; +import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnFailureListener; import com.google.android.gms.tasks.OnSuccessListener; +import com.google.android.gms.tasks.Task; import com.google.android.material.chip.Chip; import com.google.android.material.progressindicator.LinearProgressIndicator; import com.google.android.material.snackbar.Snackbar; import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.QueryDocumentSnapshot; +import com.google.firebase.firestore.QuerySnapshot; +import com.google.firebase.firestore.auth.User; import java.util.ArrayList; import java.util.HashMap; @@ -41,8 +48,7 @@ public class CreateGroupFragment extends Fragment { protected static final String FRAGMENT_NAME="CreateGroupFragment"; - - + String first_name; protected FirebaseFirestore db = FirebaseFirestore.getInstance(); protected static final int MAXIMUM = 3; protected Spinner StudentSpinner; @@ -60,11 +66,11 @@ public class CreateGroupFragment extends Fragment { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM1 = "userID"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters - private String mParam1; + private String UserId; private String mParam2; public CreateGroupFragment() { @@ -93,7 +99,7 @@ public static CreateGroupFragment newInstance(String param1, String param2) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); + UserId = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @@ -103,7 +109,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflated_view=inflater.inflate(R.layout.fragment_create_group, container, false); -// Chip chip=inflated_view.findViewById(R.id.AddGroup); @@ -118,6 +123,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, + adapter = ArrayAdapter.createFromResource(this.getContext(), R.array.sudent_list, android.R.layout.simple_spinner_item ); adapter2 = ArrayAdapter.createFromResource(this.getContext(), R.array.courses_list, android.R.layout.simple_spinner_item ); adapter.setDropDownViewResource(android.R.layout.simple_selectable_list_item); @@ -137,6 +143,18 @@ public void onClick(View view) { } }); + CourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + Button saveFormbtn=inflated_view.findViewById(R.id.saveFormBtn); saveFormbtn.setOnClickListener(new View.OnClickListener() { @Override @@ -158,10 +176,10 @@ public void AddUser(View view ){ String selected_item = StudentSpinner.getItemAtPosition(spinner_position).toString(); Log.i(FRAGMENT_NAME, selected_item); - user.add(selected_item); addstudentadapter.notifyItemInserted(user.size()); + } } @@ -194,8 +212,7 @@ private boolean ValidateForm(){ if (CourseSpinner.getSelectedItemPosition() != 0 ) if (!(GroupNameInput.getText().toString().compareTo("")==0) ) if (!(GroupDescInput.getText().toString().compareTo("") == 0)) - if (user.size()>0) - return true; + return user.size() > 0; return false; } @@ -221,6 +238,9 @@ public static void DeleteEntry(View view) private void WriteToDatabase() { Log.i(FRAGMENT_NAME, "Writing to database "); + user.add(getusername(UserId)); + Log.i(FRAGMENT_NAME, " " + first_name); + Map group = new HashMap<>(); group.put("course", CourseSpinner.getSelectedItemPosition()); group.put("description", GroupDescInput.getText().toString()); @@ -246,10 +266,36 @@ public void onFailure(@NonNull Exception e) { Log.w(FRAGMENT_NAME, "Error adding document", e); } }); -// this.getActivity().finish(); -// startActivity(new Intent(this.getActivity().getApplicationContext(),this.getActivity().getClass())); - getActivity().onBackPressed(); Log.i(FRAGMENT_NAME, "Writing to database completed "); + getFragmentManager().popBackStack(); + + } + + public String getusername(String UserId) { + + Log.i(FRAGMENT_NAME, " " + UserId); + DocumentReference docRef = db.collection("user").document(UserId); + + docRef.get().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) { + DocumentSnapshot document = task.getResult(); + if (document.exists()) { + first_name = (String) document.get("first_name"); + Log.i(FRAGMENT_NAME, "This is first name: "+ first_name); + + } else { + Log.d(FRAGMENT_NAME, "No such document"); + } + } else { + Log.d(FRAGMENT_NAME, "get failed with ", task.getException()); + } + } + }); + Log.i(FRAGMENT_NAME, "This is the first name pt2: " + first_name); + return first_name; + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/android/GroupFragment.java b/app/src/main/java/com/example/android/GroupFragment.java index b75e4df..8cc6ed2 100644 --- a/app/src/main/java/com/example/android/GroupFragment.java +++ b/app/src/main/java/com/example/android/GroupFragment.java @@ -27,8 +27,11 @@ import android.widget.Toast; import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.Task; import com.google.android.material.chip.Chip; +import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.QueryDocumentSnapshot; import com.google.firebase.firestore.QuerySnapshot; @@ -71,6 +74,7 @@ private static class GroupsInformation public ArrayList members; private GroupsInformation(String id , String NameofGroup, String GroupDescription, ArrayList members) { + this.id = id; this.NameofGroup = NameofGroup ; this.GroupDescription =GroupDescription; this.members = members; @@ -298,6 +302,9 @@ public void onClick(DialogInterface dialog, int id) { group.GroupDescription = NewGroupDesc.getText().toString(); adapter.notifyDataSetChanged(); + + updateDatabase(group.getid(), group.NameofGroup, group.GroupDescription); + } }); @@ -350,6 +357,11 @@ public void onCreate(Bundle savedInstanceState) { } } + @Override + public void onStop() { + super.onStop(); + groups.clear(); + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -368,7 +380,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onClick(View view) { getActivity().getSupportFragmentManager().beginTransaction() - .replace(R.id.fragmentContainerView,CreateGroupFragment.class,null) + .replace(R.id.fragmentContainerView,CreateGroupFragment.class,getArguments()) .setReorderingAllowed(true) .addToBackStack("tempBackStack") .commit(); @@ -376,4 +388,44 @@ public void onClick(View view) { }); return test; } + + public boolean updateDatabase(String id, String groupname, String groupdescription) + { + Log.i(FRAGMENT_NAME, "Message id: " + id); + DocumentReference groupRef = db.collection("groups").document(id); + + groupRef + .update("name", groupname) + + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + Log.d(FRAGMENT_NAME, "Group name successfully updated!"); + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + Log.w(FRAGMENT_NAME, "Error updating document id:" + id, e); + + } + }); + + groupRef + .update("description", groupdescription) + + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + Log.d(FRAGMENT_NAME, "Group Desc successfully updated!"); + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + Log.w(FRAGMENT_NAME, "Error updating document", e); + } + }); + return true; + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/android/MainActivity.java b/app/src/main/java/com/example/android/MainActivity.java index 2beca53..427c3d4 100644 --- a/app/src/main/java/com/example/android/MainActivity.java +++ b/app/src/main/java/com/example/android/MainActivity.java @@ -28,8 +28,8 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Bundle extras=getIntent().getExtras(); + // termPref=extras.getString("term"); // yearPref=extras.getString("year"); // levelPref=(ArrayList) getIntent().getSerializableExtra("level"); @@ -57,7 +57,7 @@ public void onClick(View view) { @Override public void onClick(View view) { fragmentManager.beginTransaction() - .replace(R.id.fragmentContainerView,GroupFragment.class,null) + .replace(R.id.fragmentContainerView,GroupFragment.class,extras) .setReorderingAllowed(true) .addToBackStack("tempBackStack") .commit(); diff --git a/build.gradle b/build.gradle index 2d4f571..39471a1 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,6 @@ buildscript { } }// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.3.1' apply false - id 'com.android.library' version '7.3.1' apply false + id 'com.android.application' version '7.2.2' apply false + id 'com.android.library' version '7.2.2' apply false } \ No newline at end of file From e1feff8b59ee9bd35bf63548f9b7a2e00809889e Mon Sep 17 00:00:00 2001 From: Salzeem Date: Tue, 22 Nov 2022 03:02:17 -0500 Subject: [PATCH 02/14] Second Push: Group Feature completed. - Need to refactor code - Need the course before final submission instructor table created - Need username to be passed by MainActivity.java --- .idea/misc.xml | 11 +++ .../example/android/CreateGroupFragment.java | 99 +++++++++++++++---- .../com/example/android/GroupFragment.java | 73 +++++++++++--- .../com/example/android/MainActivity.java | 2 + .../com/example/android/RegisterActivity.java | 1 + app/src/main/res/layout/fragment_group.xml | 15 ++- .../res/layout/groups_custom_dialog_box.xml | 2 +- 7 files changed, 172 insertions(+), 31 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index bdd9278..bf92341 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,16 @@ + + + diff --git a/app/src/main/java/com/example/android/CreateGroupFragment.java b/app/src/main/java/com/example/android/CreateGroupFragment.java index c23532d..4f14d30 100644 --- a/app/src/main/java/com/example/android/CreateGroupFragment.java +++ b/app/src/main/java/com/example/android/CreateGroupFragment.java @@ -15,6 +15,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Adapter; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; @@ -36,7 +37,10 @@ import com.google.firebase.firestore.QuerySnapshot; import com.google.firebase.firestore.auth.User; +import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -48,7 +52,7 @@ public class CreateGroupFragment extends Fragment { protected static final String FRAGMENT_NAME="CreateGroupFragment"; - String first_name; + //String first_name; protected FirebaseFirestore db = FirebaseFirestore.getInstance(); protected static final int MAXIMUM = 3; protected Spinner StudentSpinner; @@ -63,6 +67,8 @@ public class CreateGroupFragment extends Fragment { protected ArrayAdapter adapter2; protected RecyclerView StudentList; public static ArrayList user = new ArrayList(); + public ArrayList courses = new ArrayList<>(); + public ArrayList students = new ArrayList<>(); // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER @@ -124,18 +130,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, - adapter = ArrayAdapter.createFromResource(this.getContext(), R.array.sudent_list, android.R.layout.simple_spinner_item ); - adapter2 = ArrayAdapter.createFromResource(this.getContext(), R.array.courses_list, android.R.layout.simple_spinner_item ); + adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, students); adapter.setDropDownViewResource(android.R.layout.simple_selectable_list_item); - adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ProgressIndicator.setIndeterminate(false); StudentList.setAdapter(addstudentadapter); StudentList.setLayoutManager(new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false)); - StudentSpinner.setAdapter(adapter); - CourseSpinner.setAdapter(adapter2); + PopulateFormDb(UserId); AddButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -146,6 +149,44 @@ public void onClick(View view) { CourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + students.clear(); + students.add("None"); + //Have to reset existing chipview data once user selects a diff item + boolean changed = false; + for (int j = 1; j() { + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) { + for (QueryDocumentSnapshot document : task.getResult()) { + String first_name = (String) document.get("first_name"); + if (first_name.compareTo(user.get(0)) != 0 ) { + students.add((String) document.get("first_name")); + } + adapter.notifyDataSetChanged(); + + + } + } else { + Log.d(FRAGMENT_NAME, "Error getting documents: ", task.getException()); + } + } + }); + + + } @@ -177,7 +218,7 @@ public void AddUser(View view ){ String selected_item = StudentSpinner.getItemAtPosition(spinner_position).toString(); Log.i(FRAGMENT_NAME, selected_item); user.add(selected_item); - addstudentadapter.notifyItemInserted(user.size()); + addstudentadapter.notifyDataSetChanged(); } @@ -225,7 +266,7 @@ public static void DeleteEntry(View view) Log.i(FRAGMENT_NAME, element); while(!removed && i< user.size()) { - if (user.get(i).compareTo(elementDelete.getText().toString()) == 0) { + if (user.get(i).compareTo(elementDelete.getText().toString()) == 0 && i!=0) { user.remove(i); removed = true; addstudentadapter.notifyItemRemoved(i); @@ -235,11 +276,10 @@ public static void DeleteEntry(View view) i++; } } - private void WriteToDatabase() + public void WriteToDatabase() { Log.i(FRAGMENT_NAME, "Writing to database "); - user.add(getusername(UserId)); - Log.i(FRAGMENT_NAME, " " + first_name); + Map group = new HashMap<>(); group.put("course", CourseSpinner.getSelectedItemPosition()); @@ -267,13 +307,18 @@ public void onFailure(@NonNull Exception e) { } }); Log.i(FRAGMENT_NAME, "Writing to database completed "); - getFragmentManager().popBackStack(); } - public String getusername(String UserId) { + /*** + * Gets the userId that is passed on and finds the name of the user to add to the list of members + * Populates the Course Spinner with the data the user enters + * + * @param UserId + */ + public void PopulateFormDb(String UserId) { Log.i(FRAGMENT_NAME, " " + UserId); DocumentReference docRef = db.collection("user").document(UserId); @@ -283,8 +328,23 @@ public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); if (document.exists()) { - first_name = (String) document.get("first_name"); - Log.i(FRAGMENT_NAME, "This is first name: "+ first_name); + user.add ( (String) document.get("first_name") ) ; + addstudentadapter.notifyItemInserted(user.size()); + Log.i(FRAGMENT_NAME, "Courses : " + document.get("courses")); + + courses.add("None"); + ArrayList dbCourses = (ArrayList ) document.get("courses"); + + for (int i =0; i< dbCourses.size(); i++) { + courses.add(dbCourses.get(i)); + } + + adapter2 = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, courses ); + adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + CourseSpinner.setAdapter(adapter2); + + + } else { Log.d(FRAGMENT_NAME, "No such document"); @@ -294,8 +354,13 @@ public void onComplete(@NonNull Task task) { } } }); - Log.i(FRAGMENT_NAME, "This is the first name pt2: " + first_name); - return first_name; } + + @Override + public void onStop() { + super.onStop(); + user.clear(); + students.clear(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/android/GroupFragment.java b/app/src/main/java/com/example/android/GroupFragment.java index 8cc6ed2..785c055 100644 --- a/app/src/main/java/com/example/android/GroupFragment.java +++ b/app/src/main/java/com/example/android/GroupFragment.java @@ -4,27 +4,25 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import com.google.firebase.firestore.EventListener; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnFailureListener; @@ -32,10 +30,15 @@ import com.google.android.gms.tasks.Task; import com.google.android.material.chip.Chip; import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.FieldValue; import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; import com.google.firebase.firestore.QueryDocumentSnapshot; import com.google.firebase.firestore.QuerySnapshot; +import org.w3c.dom.Text; + import java.util.ArrayList; /** @@ -43,6 +46,11 @@ * Use the {@link GroupFragment#newInstance} factory method to * create an instance of this fragment. */ + + +/** + * Todo: Create a temp group and check for duplicates + */ public class GroupFragment extends Fragment { protected static final String FRAGMENT_NAME="GroupFragment"; protected static int colorIcon[] = {Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW}; @@ -55,13 +63,14 @@ public class GroupFragment extends Fragment { private ListView GroupLists; private View result; - + //DocumentReference docRef; private TextView message; private ImageView GroupIcon; private TextView GroupDescription; private GroupsInformation info; private CardView CardGroup; private LayoutInflater inflater; + private TextView nogroupinfo; private FirebaseFirestore db = FirebaseFirestore.getInstance(); @@ -165,6 +174,7 @@ public void onClick(View view) { public void DeleteGroupEntry(View view){ int positionitemToDelete = (int) view.getTag(); + GroupsInformation groupdel = groups.get(positionitemToDelete); String GroupName = groups.get(positionitemToDelete).NameofGroup; @@ -176,6 +186,12 @@ public void DeleteGroupEntry(View view){ public void onClick(DialogInterface dialog, int id) { groups.remove(positionitemToDelete); adapter.notifyDataSetChanged(); + if (groups.size() == 0 ) + { + nogroupinfo.setVisibility(View.VISIBLE); + GroupLists.setVisibility(View.INVISIBLE); + } + deletefromdatabase(groupdel.id, "saleem" ); //TODO: change mparam2 to username } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @@ -194,8 +210,10 @@ public void onClick(DialogInterface dialog, int id) { public void DisplayGroupInfo() { - db.collection("groups") + + db.collection("groups").whereArrayContains("members", "saleem") //TODO: change value to username .get() + .addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { @@ -207,6 +225,13 @@ public void onComplete(@NonNull Task task) { groups.add(new GroupsInformation(document.getId(), groupName, groupDesc, (ArrayList) document.get("members"))); adapter.notifyDataSetChanged(); + if (groups.size()>0 ) + { + GroupLists.setVisibility(View.VISIBLE); + nogroupinfo.setVisibility(View.INVISIBLE); + + + } } } else { Log.w(FRAGMENT_NAME, "Error getting documents.", task.getException()); @@ -319,7 +344,7 @@ public void onClick(DialogInterface dialog, int id) { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; + private static final String UserID = "userID"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters @@ -342,7 +367,7 @@ public GroupFragment() { public static GroupFragment newInstance(String param1, String param2) { GroupFragment fragment = new GroupFragment(); Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); + args.putString(UserID, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; @@ -352,7 +377,7 @@ public static GroupFragment newInstance(String param1, String param2) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); + mParam1 = getArguments().getString(UserID); mParam2 = getArguments().getString(ARG_PARAM2); } } @@ -371,9 +396,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, // FragmentManager fragmentManager =getSupportFragmentManager(); GroupLists = test.findViewById(R.id.GroupinformationList); + nogroupinfo = test.findViewById(R.id.NoGroupinfo); + adapter = new ViewGroupsAdapter(this.getContext(), 0 ); GroupLists.setAdapter(adapter); - DisplayGroupInfo(); + nogroupinfo.setText("No groups available! "); + nogroupinfo.setVisibility(View.VISIBLE); + GroupLists.setVisibility(View.INVISIBLE); + + + + CardView btn=test.findViewById(R.id.Banner); btn.setOnClickListener(new View.OnClickListener() { @@ -386,6 +419,7 @@ public void onClick(View view) { .commit(); } }); + DisplayGroupInfo(); return test; } @@ -393,10 +427,8 @@ public boolean updateDatabase(String id, String groupname, String groupdescripti { Log.i(FRAGMENT_NAME, "Message id: " + id); DocumentReference groupRef = db.collection("groups").document(id); - groupRef .update("name", groupname) - .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { @@ -428,4 +460,21 @@ public void onFailure(@NonNull Exception e) { }); return true; } + public void deletefromdatabase(String groupid, String username) + { + DocumentReference groupsRef = db.collection("groups").document(groupid); + Log.i(FRAGMENT_NAME, "Group id " + groupid + " username " + username); + groupsRef.update("members", FieldValue.arrayRemove(username)); + + + + + + /*** + * TODO before submission: Check if the group has only one member, delete the document if so + */ + } + + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/android/MainActivity.java b/app/src/main/java/com/example/android/MainActivity.java index 427c3d4..792b05a 100644 --- a/app/src/main/java/com/example/android/MainActivity.java +++ b/app/src/main/java/com/example/android/MainActivity.java @@ -1,6 +1,7 @@ package com.example.android; import android.content.Intent; +import android.graphics.Color; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; @@ -56,6 +57,7 @@ public void onClick(View view) { groupButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + fragmentManager.beginTransaction() .replace(R.id.fragmentContainerView,GroupFragment.class,extras) .setReorderingAllowed(true) diff --git a/app/src/main/java/com/example/android/RegisterActivity.java b/app/src/main/java/com/example/android/RegisterActivity.java index 5d85ca3..722a849 100644 --- a/app/src/main/java/com/example/android/RegisterActivity.java +++ b/app/src/main/java/com/example/android/RegisterActivity.java @@ -71,6 +71,7 @@ public void onComplete(@NonNull Task task) { Map currUser = new HashMap<>(); currUser.put("first_name", firstName); currUser.put("last_name", lastName); + currUser.put("email", email); users.document(userID).set(currUser); updateUI(user, userID); diff --git a/app/src/main/res/layout/fragment_group.xml b/app/src/main/res/layout/fragment_group.xml index 66ab3e2..e4fb4ab 100644 --- a/app/src/main/res/layout/fragment_group.xml +++ b/app/src/main/res/layout/fragment_group.xml @@ -37,6 +37,16 @@ + + + android:focusable="true" > + + + diff --git a/app/src/main/res/layout/groups_custom_dialog_box.xml b/app/src/main/res/layout/groups_custom_dialog_box.xml index bccb7a6..9f72e01 100644 --- a/app/src/main/res/layout/groups_custom_dialog_box.xml +++ b/app/src/main/res/layout/groups_custom_dialog_box.xml @@ -158,7 +158,7 @@ android:layout_height="wrap_content" android:backgroundTint="#808080" - android:text="Email Group" + android:text="Email Instructor" android:textColor="#FFFFFF" /> From 19a5e465c62f1ee66699e4b3ce6d307c00bd4bb3 Mon Sep 17 00:00:00 2001 From: Salzeem Date: Tue, 22 Nov 2022 15:08:09 -0500 Subject: [PATCH 03/14] Third Push: Group Feature completed. Some Layout changes. Need instructor table to have data in order to query for instructor email information. --- .idea/misc.xml | 4 ++ .../example/android/CreateGroupFragment.java | 7 ++- .../com/example/android/GroupFragment.java | 56 ++++++++++++++----- .../res/layout/groups_custom_dialog_box.xml | 6 +- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index bf92341..26e520d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,6 +3,10 @@ - > + + > + + + + + + - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127..5ecab20 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,5 @@ #FF018786 #FF000000 #FFFFFFFF + #F0EAD6 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc863c6..2e3c130 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,13 +4,14 @@ LoginActivity - Username + Email Password - login name + login email Sign In Create a new account + Registration Page Please enter your password! Please enter a valid email address! The password must be at least 8 characters and must include one digit, one lowercase character, one uppercase character, one special character, and one special character(!@#$%&*()-+=^). No white spaces are allowed. @@ -62,7 +63,7 @@ - Groups registration page + Groups Registration Page Err: Form is invalid, please make sure all fields are completed From bf366ce116e2947eabcae7ad3b4bb838dbd2b132 Mon Sep 17 00:00:00 2001 From: Salzeem Date: Mon, 28 Nov 2022 22:01:15 -0500 Subject: [PATCH 14/14] Latest code push --- .idea/.gitignore | 3 - .idea/gradle.xml | 1 - .idea/misc.xml | 34 +-- app/build.gradle | 7 + app/src/main/AndroidManifest.xml | 7 +- .../example/android/CreateGroupFragment.java | 48 +++- .../com/example/android/GroupFragment.java | 113 +++++--- .../java/com/example/android/Groupchat.java | 261 ++++++++++++++++++ .../com/example/android/LoginActivity.java | 12 + .../com/example/android/MainActivity.java | 6 +- .../main/res/layout/activity_groupchat.xml | 34 +++ .../res/layout/fragment_book_appointment.xml | 1 - .../res/layout/groups_custom_dialog_box.xml | 26 +- .../main/res/layout/message_from_person.xml | 38 +++ app/src/main/res/layout/message_from_user.xml | 34 +++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 11 +- 17 files changed, 548 insertions(+), 89 deletions(-) delete mode 100644 .idea/.gitignore create mode 100644 app/src/main/java/com/example/android/Groupchat.java create mode 100644 app/src/main/res/layout/activity_groupchat.xml create mode 100644 app/src/main/res/layout/message_from_person.xml create mode 100644 app/src/main/res/layout/message_from_user.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0bed1c8..a2d7c21 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,7 +7,6 @@