Apostolos Fanakis
6 years ago
16 changed files with 318 additions and 43 deletions
@ -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<ItemRating> 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; |
||||
|
} |
||||
|
} |
@ -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<ItemRating> 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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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<ItemRatingsAdapter.RatingViewHolder> { |
||||
|
private Context context; |
||||
|
private ArrayList<ItemRating> ratings; |
||||
|
|
||||
|
public ItemRatingsAdapter(@NonNull Context context, ArrayList<ItemRating> 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); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginStart="8dp" |
||||
|
android:layout_marginEnd="8dp" |
||||
|
android:layout_marginBottom="6dp" |
||||
|
android:orientation="vertical"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_rating_username" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginBottom="4dp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_rating_date" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginBottom="4dp" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_rating_grade" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_rating_accessibility" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_rating_text" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
</LinearLayout> |
Loading…
Reference in new issue