Skip to content

Commit

Permalink
rating works, just need to make popup that will take user input.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond123 committed Nov 30, 2022
1 parent 6bb07a5 commit 87d399f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/mealer/app/CookUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public String getRating() {
return rating + "%";
}

@Exclude
public int getIntRating() {return Integer.parseInt(rating); }

@Exclude
public void setRating(int rating) {
this.rating = Integer.toString(rating);
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/mealer/ui/ClientHomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ protected void onCreate(Bundle savedInstanceState) {

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

}else {
navController.navigate(id, args);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.mealer.ui.ui.account;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

import android.util.Log;
Expand All @@ -27,14 +30,20 @@
import com.mealer.app.CookUser;
import com.mealer.app.User;
import com.mealer.ui.LoginPage;
import com.mealer.ui.OnFragmentInteractionListener;
import com.mealer.ui.R;
import com.mealer.ui.databinding.FragmentAccountPageBinding;

import java.util.HashMap;
import java.util.Objects;

public class AccountPageFragment extends Fragment {

private static final String TAG = "AccountPageFragment";

private static final int reload = R.id.action_navigation_account_self;
private OnFragmentInteractionListener mListener;

// initializing activity elements
private TextView userType;
private TextView userName;
Expand Down Expand Up @@ -73,14 +82,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
FirebaseUser currentFirebaseUser = mAuth.getCurrentUser();
dbRef = FirebaseDatabase.getInstance().getReference("users");
// display user type on home page

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

if(this.signedIn.getClass() != Admin.class && currentFirebaseUser != null){
if(getArguments() != null) {
Bundle args = requireArguments();
CookUser user = args.getParcelable("COOK");
String cookId = args.getString("ID");
userName.setText(user.getFirstName() + " " + user.getLastName());
userType.setText("Cook Rating: " + user.getRating());
userDescription.setText("Cook Description: \n" + user.getDescription());
Log.d(TAG, "userType: " + this.signedIn.getUserType());

signOut.setText("Rate Cook");
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);
});
}
}else {
dbRef.child(currentFirebaseUser.getUid()).get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Expand Down Expand Up @@ -126,12 +154,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Log.d(TAG, "userType: " + this.signedIn.getUserType());
}

// userType.setText("User Type: " + this.signedIn.getUserType());
// Log.d("firebase", "userType: " + this.signedIn.getUserType());

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

return root;
}

Expand All @@ -141,6 +163,27 @@ public void onDestroy() {
binding = null;
}

/**
* 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
* @param context fragment context
*/
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
mListener = (OnFragmentInteractionListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}

private void updateUI(Bundle args, int id) {
mListener.changeFragment(args, id);
}


/**
* signs current user that is signed in to firebase authentication out and sends to login page
* @param currentFirebaseUser current user that is signed in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
if(task.isSuccessful()){
DataSnapshot data = task.getResult();
args.putParcelable("COOK", data.getValue(CookUser.class));
args.putString("ID", cookId);
updateUI(args, navToAcc);
}
});
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,9 @@
android:id="@+id/navigation_account"
android:name="com.mealer.ui.ui.account.AccountPageFragment"
android:label="@string/accountPage"
tools:layout="@layout/fragment_account_page" />
tools:layout="@layout/fragment_account_page" >
<action
android:id="@+id/action_navigation_account_self"
app:destination="@id/navigation_account" />
</fragment>
</navigation>

0 comments on commit 87d399f

Please sign in to comment.