From 09dd7b00868534f85d9019275bf9f34195169b50 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 2 Jan 2019 12:55:57 +0200 Subject: [PATCH] Complete FoodActivity, DrinkActivity, Minor fixes --- .../activities/drink/DrinkActivity.java | 3 +- .../drink/fragments/DrinkRatingsFragment.java | 71 +++++++++++++++++++ .../activities/food/FoodActivity.java | 3 +- .../food/fragments/FoodRatingsFragment.java | 71 +++++++++++++++++++ .../fragments/RestaurantDrinksFragment.java | 3 - .../fragments/RestaurantFoodsFragment.java | 3 - .../fragments/RestaurantInfoFragment.java | 1 + .../fragments/RestaurantRatingsAdapter.java | 18 ++--- .../fragments/RestaurantRatingsFragment.java | 18 ++--- .../databases/flavours/model/ItemRating.java | 18 +++++ .../auth/databases/flavours/model/Rating.java | 12 +--- .../flavours/model/RestaurantRating.java | 18 +++++ .../flavours/utils/ItemRatingsAdapter.java | 70 ++++++++++++++++++ ...urant_list_row.xml => item_rating_row.xml} | 10 +-- .../main/res/layout/restaurant_item_row.xml | 5 +- .../main/res/layout/restaurant_rating_row.xml | 37 ++++++++++ 16 files changed, 318 insertions(+), 43 deletions(-) create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkRatingsFragment.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodRatingsFragment.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemRating.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantRating.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ItemRatingsAdapter.java rename UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/{activity_restaurant_list_row.xml => item_rating_row.xml} (79%) create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_rating_row.xml diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java index 2fad6f9..96404f6 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java @@ -10,6 +10,7 @@ import androidx.viewpager.widget.ViewPager; import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.activities.drink.fragments.DrinkInfoFragment; import gr.auth.databases.flavours.activities.drink.fragments.DrinkIngredientsFragment; +import gr.auth.databases.flavours.activities.drink.fragments.DrinkRatingsFragment; import gr.auth.databases.flavours.base.BaseActivity; import android.os.Bundle; @@ -101,7 +102,7 @@ public class DrinkActivity extends BaseActivity { RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager()); adapter.addFrag(DrinkInfoFragment.newInstance(64), "INFO"); adapter.addFrag(DrinkIngredientsFragment.newInstance(64), "INGREDIENTS"); - /*adapter.addFrag(DrinkRatingsFragment.newInstance(64), "RATINGS");*/ + adapter.addFrag(DrinkRatingsFragment.newInstance(64), "RATINGS"); viewPager.setAdapter(adapter); } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkRatingsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkRatingsFragment.java new file mode 100644 index 0000000..9c864fa --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkRatingsFragment.java @@ -0,0 +1,71 @@ +package gr.auth.databases.flavours.activities.drink.fragments; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.model.ItemRating; +import gr.auth.databases.flavours.utils.ItemRatingsAdapter; + +public class DrinkRatingsFragment extends Fragment { + + public DrinkRatingsFragment() { + // Required empty public constructor + } + + private static final String DRINK_ID = "DRINK_ID"; + + private int drinkId; + + public static DrinkRatingsFragment newInstance(int drinkId) { + DrinkRatingsFragment fragment = new DrinkRatingsFragment(); + Bundle args = new Bundle(); + args.putInt(DRINK_ID, drinkId); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + assert getArguments() != null; + drinkId = getArguments().getInt(DRINK_ID); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false); + + ArrayList ratings = new ArrayList<>(); + ratings.add(new ItemRating(5, "Ανώνυμος", "Πάρα πολύ καλό!", "2018-01-04", ItemRating.PortionSize.MEDIUM)); + ratings.add(new ItemRating(5, "Ανύπαρκτος", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", ItemRating.PortionSize.BIG)); + ratings.add(new ItemRating(4, "Γαρδένιος ο Stoner", "-", "2018-06-08", ItemRating.PortionSize.BIG)); + ratings.add(new ItemRating(4, "Μαγκούστα", "Μου άρεσε.", "2018-06-08", ItemRating.PortionSize.MEDIUM)); + ratings.add(new ItemRating(5, "Νταλίκας", "Τέλειο.", "2018-06-08", ItemRating.PortionSize.BIG)); + ratings.add(new ItemRating(2, "Ms Godzila", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); + ratings.add(new ItemRating(4, "eddie lives inside you", "-", "2018-06-08", ItemRating.PortionSize.MEDIUM)); + + Context context = getContext(); + assert context != null; + ItemRatingsAdapter itemAdapter = new ItemRatingsAdapter(context, ratings); + RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); + mainContent.setAdapter(itemAdapter); + LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); + mainContent.setLayoutManager(layoutManager); + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(), + layoutManager.getOrientation()); + mainContent.addItemDecoration(dividerItemDecoration); + + return rootView; + } +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java index c2cd567..03c3558 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java @@ -10,6 +10,7 @@ import androidx.viewpager.widget.ViewPager; import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.activities.food.fragments.FoodInfoFragment; import gr.auth.databases.flavours.activities.food.fragments.FoodIngredientsFragment; +import gr.auth.databases.flavours.activities.food.fragments.FoodRatingsFragment; import gr.auth.databases.flavours.base.BaseActivity; import android.os.Bundle; @@ -101,7 +102,7 @@ public class FoodActivity extends BaseActivity { RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager()); adapter.addFrag(FoodInfoFragment.newInstance(64), "INFO"); adapter.addFrag(FoodIngredientsFragment.newInstance(64), "INGREDIENTS"); - /*adapter.addFrag(FoodRatingsFragment.newInstance(64), "RATINGS");*/ + adapter.addFrag(FoodRatingsFragment.newInstance(64), "RATINGS"); viewPager.setAdapter(adapter); } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodRatingsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodRatingsFragment.java new file mode 100644 index 0000000..4280537 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodRatingsFragment.java @@ -0,0 +1,71 @@ +package gr.auth.databases.flavours.activities.food.fragments; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.model.ItemRating; +import gr.auth.databases.flavours.utils.ItemRatingsAdapter; + +public class FoodRatingsFragment extends Fragment { + + public FoodRatingsFragment() { + // Required empty public constructor + } + + private static final String FOOD_ID = "FOOD_ID"; + + private int foodId; + + public static FoodRatingsFragment newInstance(int foodId) { + FoodRatingsFragment fragment = new FoodRatingsFragment(); + Bundle args = new Bundle(); + args.putInt(FOOD_ID, foodId); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + assert getArguments() != null; + foodId = getArguments().getInt(FOOD_ID); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false); + + ArrayList ratings = new ArrayList<>(); + ratings.add(new ItemRating(5, "Ανώνυμος", "Πάρα πολύ καλό!", "2018-01-04", ItemRating.PortionSize.MEDIUM)); + ratings.add(new ItemRating(5, "Ανύπαρκτος", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", ItemRating.PortionSize.BIG)); + ratings.add(new ItemRating(4, "Γαρδένιος ο Stoner", "-", "2018-06-08", ItemRating.PortionSize.BIG)); + ratings.add(new ItemRating(4, "Μαγκούστα", "Μου άρεσε.", "2018-06-08", ItemRating.PortionSize.MEDIUM)); + ratings.add(new ItemRating(5, "Νταλίκας", "Τέλειο.", "2018-06-08", ItemRating.PortionSize.BIG)); + ratings.add(new ItemRating(2, "Ms Godzila", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); + ratings.add(new ItemRating(4, "eddie lives inside you", "-", "2018-06-08", ItemRating.PortionSize.MEDIUM)); + + Context context = getContext(); + assert context != null; + ItemRatingsAdapter itemAdapter = new ItemRatingsAdapter(context, ratings); + RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); + mainContent.setAdapter(itemAdapter); + LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); + mainContent.setLayoutManager(layoutManager); + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(), + layoutManager.getOrientation()); + mainContent.addItemDecoration(dividerItemDecoration); + + return rootView; + } +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java index 6d1c01b..9333519 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java @@ -56,9 +56,6 @@ public class RestaurantDrinksFragment extends BaseFragment { mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); mainContent.setLayoutManager(layoutManager); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(), - layoutManager.getOrientation()); - mainContent.addItemDecoration(dividerItemDecoration); return rootView; } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java index e13f208..e7a6112 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java @@ -54,9 +54,6 @@ public class RestaurantFoodsFragment extends BaseFragment { mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); mainContent.setLayoutManager(layoutManager); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(), - layoutManager.getOrientation()); - mainContent.addItemDecoration(dividerItemDecoration); return rootView; } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java index 6af4901..82957e9 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java @@ -58,6 +58,7 @@ public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCa averageRatings.setText(getString(R.string.restaurant_average_rating, 4.78)); LinearLayout averageRatingPerDiet = rootView.findViewById(R.id.restaurant_average_rating_per_diet); + averageRatingPerDiet.setVisibility(View.VISIBLE); TextView dietRatingView = new TextView(getContext()); dietRatingView.setText(getString(R.string.restaurant_diet_average_rating, "όγκος", 4.65)); averageRatingPerDiet.addView(dietRatingView); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsAdapter.java index e99e6f9..ef1ec60 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsAdapter.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsAdapter.java @@ -11,13 +11,13 @@ import java.util.ArrayList; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import gr.auth.databases.flavours.R; -import gr.auth.databases.flavours.model.Rating; +import gr.auth.databases.flavours.model.RestaurantRating; public class RestaurantRatingsAdapter extends RecyclerView.Adapter { private Context context; - private ArrayList ratings; + private ArrayList ratings; - RestaurantRatingsAdapter(Context context, ArrayList ratings) { + RestaurantRatingsAdapter(@NonNull Context context, ArrayList ratings) { this.context = context; this.ratings = ratings; } @@ -26,7 +26,7 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter ratings = new ArrayList<>(); - ratings.add(new Rating(5, "Ανώνυμος", "Πάρα πολύ καλό!", "2018-01-04", Rating.Accessibility.MODERATE)); - ratings.add(new Rating(5, "Ανύπαρκτος", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", Rating.Accessibility.EASY)); - ratings.add(new Rating(4, "Γαρδένιος ο Stoner", "-", "2018-06-08", Rating.Accessibility.EASY)); - ratings.add(new Rating(4, "Μαγκούστα", "Μου άρεσε.", "2018-06-08", Rating.Accessibility.MODERATE)); - ratings.add(new Rating(5, "Νταλίκας", "Τέλειο.", "2018-06-08", Rating.Accessibility.EASY)); - ratings.add(new Rating(2, "Ms Godzila", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); - ratings.add(new Rating(4, "eddie lives inside you", "-", "2018-06-08", Rating.Accessibility.MODERATE)); + ArrayList ratings = new ArrayList<>(); + ratings.add(new RestaurantRating(5, "Ανώνυμος", "Πάρα πολύ καλό!", "2018-01-04", RestaurantRating.Accessibility.MODERATE)); + ratings.add(new RestaurantRating(5, "Ανύπαρκτος", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", RestaurantRating.Accessibility.EASY)); + ratings.add(new RestaurantRating(4, "Γαρδένιος ο Stoner", "-", "2018-06-08", RestaurantRating.Accessibility.EASY)); + ratings.add(new RestaurantRating(4, "Μαγκούστα", "Μου άρεσε.", "2018-06-08", RestaurantRating.Accessibility.MODERATE)); + ratings.add(new RestaurantRating(5, "Νταλίκας", "Τέλειο.", "2018-06-08", RestaurantRating.Accessibility.EASY)); + ratings.add(new RestaurantRating(2, "Ms Godzila", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); + ratings.add(new RestaurantRating(4, "eddie lives inside you", "-", "2018-06-08", RestaurantRating.Accessibility.MODERATE)); RestaurantRatingsAdapter itemAdapter = new RestaurantRatingsAdapter(getContext(), ratings); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemRating.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemRating.java new file mode 100644 index 0000000..91f9dc7 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemRating.java @@ -0,0 +1,18 @@ +package gr.auth.databases.flavours.model; + +public class ItemRating extends Rating { + public enum PortionSize { + SMALL, MEDIUM, BIG + } + + private PortionSize portionSize; + + public ItemRating(int grade, String username, String text, String date, PortionSize portionSize) { + super(grade, username, text, date); + this.portionSize = portionSize; + } + + public PortionSize getPortionSize() { + return portionSize; + } +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Rating.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Rating.java index ba11aa3..bc065ad 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Rating.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Rating.java @@ -1,20 +1,14 @@ package gr.auth.databases.flavours.model; public class Rating { - public enum Accessibility { - EASY, MODERATE, HARD - } - private int grade; private String username, text, date; - private Accessibility accessibility; - public Rating(int grade, String username, String text, String date, Accessibility accessibility) { + Rating(int grade, String username, String text, String date) { this.grade = grade; this.username = username; this.text = text; this.date = date; - this.accessibility = accessibility; } public int getGrade() { @@ -32,8 +26,4 @@ public class Rating { public String getDate() { return date; } - - public Accessibility getAccessibility() { - return accessibility; - } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantRating.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantRating.java new file mode 100644 index 0000000..176b44b --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantRating.java @@ -0,0 +1,18 @@ +package gr.auth.databases.flavours.model; + +public class RestaurantRating extends Rating { + public enum Accessibility { + EASY, MODERATE, HARD + } + + private Accessibility accessibility; + + public RestaurantRating(int grade, String username, String text, String date, Accessibility accessibility) { + super(grade, username, text, date); + this.accessibility = accessibility; + } + + public Accessibility getAccessibility() { + return accessibility; + } +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ItemRatingsAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ItemRatingsAdapter.java new file mode 100644 index 0000000..e6e3930 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ItemRatingsAdapter.java @@ -0,0 +1,70 @@ +package gr.auth.databases.flavours.utils; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.ArrayList; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.model.ItemRating; + +public class ItemRatingsAdapter extends RecyclerView.Adapter { + private Context context; + private ArrayList ratings; + + public ItemRatingsAdapter(@NonNull Context context, ArrayList ratings) { + this.context = context; + this.ratings = ratings; + } + + @NonNull + @Override + public ItemRatingsAdapter.RatingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, + int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rating_row, + parent, false); + return new RatingViewHolder(v); + } + + @Override + public void onBindViewHolder(@NonNull RatingViewHolder holder, int position) { + holder.authorUsername.setText(ratings.get(position).getUsername()); + holder.date.setText(ratings.get(position).getDate()); + + holder.grade.setText(context.getString(R.string.restaurant_row_grade_placeholder, + ratings.get(position).getGrade())); + + if (ratings.get(position).getPortionSize() != null) { + holder.portionSize.setVisibility(View.VISIBLE); + holder.portionSize.setText(context.getString(R.string.restaurant_row_accessibility_placeholder, + ratings.get(position).getPortionSize().toString())); + } else { + holder.portionSize.setVisibility(View.GONE); + } + + holder.text.setText(ratings.get(position).getText()); + } + + @Override + public int getItemCount() { + return ratings == null ? 0 : ratings.size(); + } + + static class RatingViewHolder extends RecyclerView.ViewHolder { + TextView authorUsername, date, grade, portionSize, text; + + RatingViewHolder(View v) { + super(v); + authorUsername = v.findViewById(R.id.item__rating_author_username); + date = v.findViewById(R.id.item__rating_date); + grade = v.findViewById(R.id.item__rating_grade); + portionSize = v.findViewById(R.id.item__rating_portion_size); + text = v.findViewById(R.id.item__rating_text); + } + } +} \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant_list_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/item_rating_row.xml similarity index 79% rename from UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant_list_row.xml rename to UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/item_rating_row.xml index d8717d9..cba7e17 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant_list_row.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/item_rating_row.xml @@ -8,30 +8,30 @@ android:orientation="vertical"> \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml index afbbf92..bc1b424 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml @@ -16,5 +16,8 @@ + android:layout_height="wrap_content" + android:layout_margin="6dp" + android:textColor="@color/colorAccent" + android:textSize="16sp" /> \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_rating_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_rating_row.xml new file mode 100644 index 0000000..036d444 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_rating_row.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + \ No newline at end of file