Skip to content

Commit

Permalink
added function to make complaints when on cook account page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond123 committed Dec 4, 2022
1 parent bfc40ce commit 2a144f8
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 15 deletions.
6 changes: 1 addition & 5 deletions app/src/main/java/com/mealer/ui/ClientHomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void changeFragment(Bundle args, int id) {
if(id == 0){

}else {
navController.navigate(id, args);
}
navController.navigate(id, args);
}
}
120 changes: 110 additions & 10 deletions app/src/main/java/com/mealer/ui/ui/account/AccountPageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
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.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;
Expand All @@ -27,6 +32,7 @@
import com.google.firebase.database.FirebaseDatabase;
import com.mealer.app.Admin;
import com.mealer.app.ClientUser;
import com.mealer.app.Complaint;
import com.mealer.app.CookUser;
import com.mealer.app.User;
import com.mealer.ui.LoginPage;
Expand All @@ -48,12 +54,15 @@ public class AccountPageFragment extends Fragment {
private TextView userType;
private TextView userName;
private TextView userDescription;

private Button signOut;
private Button complain;

private Admin signedIn;

FragmentAccountPageBinding binding;
DatabaseReference dbRef;
DatabaseReference cRef;
FirebaseAuth mAuth;

@SuppressLint("SetTextI18n")
Expand Down Expand Up @@ -81,14 +90,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// get current firebase user from firebase authentication
FirebaseUser currentFirebaseUser = mAuth.getCurrentUser();
dbRef = FirebaseDatabase.getInstance().getReference("users");
cRef = FirebaseDatabase.getInstance().getReference("complaints");
// display user type on home page

signOut = binding.signOut;
signOut.setOnClickListener(c->signOut(currentFirebaseUser));

complain = binding.complain;
complain.setVisibility(View.GONE);

if(this.signedIn.getClass() != Admin.class && currentFirebaseUser != null){
if(getArguments() != null) {
Bundle args = requireArguments();
setArguments(null);
CookUser user = args.getParcelable("COOK");
String cookId = args.getString("ID");
userName.setText(user.getFirstName() + " " + user.getLastName());
Expand All @@ -97,18 +111,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Log.d(TAG, "userType: " + this.signedIn.getUserType());

signOut.setText("Rate Cook");
complain.setText("File Complaint");
complain.setVisibility(View.VISIBLE);
if(signOut.hasOnClickListeners()){
signOut.setOnClickListener(onClick -> {
// popup rating input
HashMap<String, Object> update = new HashMap<>();
int rating = (20 + user.getIntRating())/2; // 50 == rating input
user.setRating(rating);
update.put("rating", String.valueOf(user.getIntRating()));
dbRef.child(cookId).updateChildren(update);

updateUI(getArguments(), reload);
});
signOut.setOnClickListener(
onClick -> openPopup(this.getView(), user, cookId));
}
complain.setOnClickListener(
onClick -> fileComplain(this.getView(), user, cookId));
}else {
dbRef.child(currentFirebaseUser.getUid()).get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Expand Down Expand Up @@ -157,12 +167,102 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return root;
}

@SuppressLint({"MissingInflatedId", "ClickableViewAccessibility"})
private void fileComplain(View view, CookUser user, String cookId) {
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams")
View popup = inflater.inflate(R.layout.complaint_popup, null);
popup.setBackgroundColor(Color.BLACK);

// create the popup window
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true; // lets taps outside the popup also dismiss it

final PopupWindow popupWindow = new PopupWindow(popup, width, height, focusable);

Button submit = popup.findViewById(R.id.complaintSubmit);
EditText subject = popup.findViewById(R.id.complaintSubjectP);
EditText description = popup.findViewById(R.id.complaintDescriptionP);

// show the popup window
// which view you pass in doesn't matter, it is only used for the window token
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

// dismiss the popup window when touched
popup.setOnTouchListener((v, event) -> {
popupWindow.dismiss();
return true;
});

submit.setOnClickListener(c ->{
Complaint complaint = new Complaint(
subject.getText().toString(),
description.getText().toString(),
cookId);

cRef.child(complaint.getComplaintID()).setValue(complaint);
popupWindow.dismiss();
updateUI(getArguments(), reload);
});
}

@Override
public void onDestroy() {
super.onDestroy();
binding = null;
}

/**
* Opens a small popup window where the admin can input the length of the cooks suspension
* @param view androidStudio view to show popup
*/
@SuppressLint({"ClickableViewAccessibility", "MissingInflatedId", "SetTextI18n"})
public void openPopup(View view, CookUser user, String cookId){
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams")
View popup = inflater.inflate(R.layout.suspension_popup, null);
popup.setBackgroundColor(Color.GREEN);

// create the popup window
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true; // lets taps outside the popup also dismiss it

final PopupWindow popupWindow = new PopupWindow(popup, width, height, focusable);

Spinner monthDayChoice = popup.findViewById(R.id.spinner);
monthDayChoice.setVisibility(View.GONE);

Button rate = popup.findViewById(R.id.completeSuspension);
rate.setText("Rate");

EditText rating = popup.findViewById(R.id.suspensionLength);
rating.setHint("Rating / 100");
rating.setInputType(InputType.TYPE_CLASS_NUMBER);

// show the popup window
// which view you pass in doesn't matter, it is only used for the window token
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

// dismiss the popup window when touched
popup.setOnTouchListener((v, event) -> {
popupWindow.dismiss();
return true;
});

rate.setOnClickListener(onClick -> {
HashMap<String, Object> update = new HashMap<>();
int input = Integer.parseInt(rating.getText().toString());
int newRating = (input + user.getIntRating())/2; // 50 == rating input
user.setRating(newRating);
update.put("rating", String.valueOf(user.getIntRating()));
dbRef.child(cookId).updateChildren(update);
popupWindow.dismiss();
updateUI(getArguments(), reload);
});
}

/**
* gets the mListener object from the fragments context in order to be able to return to
* previous fragment and get the complaint info passed to this fragment
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/res/layout/complaint_popup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp">

<EditText
android:id="@+id/complaintSubjectP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/darkGreen"
android:textColor="@color/darkGreen"
android:ems="10"
android:inputType="textPersonName"
android:hint="@string/subject"
android:autofillHints=""
android:layout_marginBottom="10dp"/>

<EditText
android:id="@+id/complaintDescriptionP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/darkGreen"
android:textColor="@color/darkGreen"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine"
android:hint="@string/description"
android:autofillHints=""
android:layout_marginBottom="10dp"/>

<Button
android:id="@+id/complaintSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/lightBrown"
android:text="@string/submit" />
</LinearLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/layout/fragment_account_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@
android:text="@string/sign_out"
android:translationY="200dp" />

<Space
android:layout_width="match_parent"
android:layout_height="20dp" />

<Button
android:id="@+id/complain"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:backgroundTint="@color/lightBrown"
android:text="@string/sign_out"
android:translationY="200dp" />

</LinearLayout>

</FrameLayout>
Expand Down

0 comments on commit 2a144f8

Please sign in to comment.