mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Add rating Recycler View
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.capstone.foodify.Activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@@ -14,6 +16,8 @@ import android.widget.Toast;
|
||||
import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.Model.Food.ImageFood;
|
||||
import com.capstone.foodify.Model.Review.Review;
|
||||
import com.capstone.foodify.Model.Review.ReviewAdapter;
|
||||
import com.capstone.foodify.R;
|
||||
import com.denzcoskun.imageslider.ImageSlider;
|
||||
import com.denzcoskun.imageslider.constants.ScaleTypes;
|
||||
@@ -47,6 +51,8 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
private LinearLayout linearLayout, linearLayout2, linearLayout3;
|
||||
private View line;
|
||||
private float totalPrice, price;
|
||||
private RecyclerView recyclerView_review;
|
||||
private ReviewAdapter reviewAdapter;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -73,6 +79,17 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
total_txt = findViewById(R.id.total_text_view);
|
||||
countRating_txt = findViewById(R.id.count_rating_text_view);
|
||||
description_content_txt = findViewById(R.id.content_description_text_view);
|
||||
recyclerView_review = findViewById(R.id.recycler_view_review);
|
||||
|
||||
reviewAdapter = new ReviewAdapter(this);
|
||||
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
|
||||
recyclerView_review.setLayoutManager(linearLayoutManager);
|
||||
|
||||
reviewAdapter.setData(getListReview());
|
||||
recyclerView_review.setAdapter(reviewAdapter);
|
||||
|
||||
|
||||
hideUI();
|
||||
|
||||
//Customize UI Horizontal Quantitizer
|
||||
@@ -114,6 +131,18 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private List<Review> getListReview(){
|
||||
ArrayList<Review> listReview = new ArrayList<>();
|
||||
|
||||
listReview.add(new Review("User A", 5, "Very Good!"));
|
||||
listReview.add(new Review("User B", 1, "Bad!"));
|
||||
listReview.add(new Review("User C", 4, "Delicious!"));
|
||||
listReview.add(new Review("User D", 3, "OK!"));
|
||||
listReview.add(new Review("User E", 5, "Awesome!"));
|
||||
|
||||
return listReview;
|
||||
}
|
||||
|
||||
private void hideUI() {
|
||||
horizontalQuantitizer.setVisibility(View.GONE);
|
||||
imageSlider.setVisibility(View.GONE);
|
||||
@@ -162,7 +191,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
price_txt.setText(fmt.format(Float.parseFloat(food.getPrice())));
|
||||
discount_txt.setText("-" + food.getDiscount() + "%");
|
||||
description_content_txt.setText(food.getDescription());
|
||||
countRating_txt.setText(food.getReviewCount());
|
||||
countRating_txt.setText(food.getReviewCount() + " rating");
|
||||
|
||||
add_to_basket_button.setText("ADD TO BASKET - " + fmt.format(0));
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.capstone.foodify.Model.Review;
|
||||
|
||||
public class Review {
|
||||
private String name;
|
||||
private int ratingScore;
|
||||
private String content;
|
||||
|
||||
public Review() {
|
||||
}
|
||||
|
||||
public Review(String name, int ratingScore, String content) {
|
||||
this.name = name;
|
||||
this.ratingScore = ratingScore;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getRatingScore() {
|
||||
return ratingScore;
|
||||
}
|
||||
|
||||
public void setRatingScore(int ratingScore) {
|
||||
this.ratingScore = ratingScore;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.capstone.foodify.Model.Review;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Model.Menu.MenuAdapter;
|
||||
import com.capstone.foodify.R;
|
||||
import com.willy.ratingbar.ScaleRatingBar;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReviewAdapter extends RecyclerView.Adapter<ReviewAdapter.ReviewViewHolder> {
|
||||
|
||||
private List<Review> listReview;
|
||||
private Context context;
|
||||
|
||||
public ReviewAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setData(List<Review> listReview){
|
||||
this.listReview = listReview;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReviewViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_review, parent, false);
|
||||
return new ReviewViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReviewViewHolder holder, int position) {
|
||||
Review review = listReview.get(position);
|
||||
|
||||
holder.name.setText(review.getName());
|
||||
holder.ratingScore.setRating(review.getRatingScore());
|
||||
holder.content.setText(review.getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if(listReview != null)
|
||||
return listReview.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public class ReviewViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private TextView name, content;
|
||||
private ScaleRatingBar ratingScore;
|
||||
|
||||
public ReviewViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
name = itemView.findViewById(R.id.user_name_text_view);
|
||||
ratingScore = itemView.findViewById(R.id.rating_bar);
|
||||
content = itemView.findViewById(R.id.comment_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,8 +270,9 @@
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_review"
|
||||
tools:listitem="@layout/item_review"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/linear_layout_2"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -38,11 +38,10 @@
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="26dp"
|
||||
app:srb_starPadding="5dp"
|
||||
android:clickable="false"
|
||||
app:srb_clickable="false"
|
||||
app:srb_starWidth="12dp"
|
||||
app:srb_starHeight="12dp"
|
||||
app:srb_numStars="5"
|
||||
app:srb_rating="5"
|
||||
app:layout_constraintTop_toBottomOf="@id/user_name_text_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="-5dp"
|
||||
|
||||
Reference in New Issue
Block a user