diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java index 9b03253..c1f45bb 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java @@ -265,7 +265,7 @@ public class AddRestaurantActivity extends BaseActivity implements AdapterView.O @Override protected Integer doInBackground(String... params) { - //Builds the signup request + //Builds the request RequestBody formBody = new FormBody.Builder() .add(REQ_RESTAURANT_NAME, params[0]) .add(REQ_RESTAURANT_CATEGORY, params[1]) diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java index 3cca457..523cbf7 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java @@ -348,7 +348,7 @@ public class MainActivity extends BaseActivity { requestUrl.append("filter_restaurant_calories=").append(maxCalories); } - //Builds the signup request + //Builds the request Request request = new Request.Builder() .url(requestUrl.toString()) .build(); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java index bf52e6b..8a6dd63 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java @@ -17,6 +17,8 @@ import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.activities.restaurant.RestaurantActivity; import gr.auth.databases.flavours.model.Restaurant; +import static gr.auth.databases.flavours.activities.restaurant.RestaurantActivity.BUNDLE_ARG_RESTAURANT; + public class MainAdapter extends RecyclerView.Adapter { private Context context; private ArrayList restaurants; @@ -36,11 +38,12 @@ public class MainAdapter extends RecyclerView.Adapter foods = new ArrayList<>(); + private ArrayList drinks = new ArrayList<>(); + ArrayList ratings = new ArrayList<>(); + private ViewPager viewPager; + private TabLayout tabLayout; private FloatingActionButton FAB; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_restaurant); + Bundle extras = getIntent().getExtras(); + assert extras != null; + mRestaurant = (Restaurant) extras.getParcelable(BUNDLE_ARG_RESTAURANT); + Toolbar toolbar = findViewById(R.id.restaurant_toolbar); - toolbar.setTitle("Αιθερόπλοο"); setSupportActionBar(toolbar); + toolbar.setTitle(mRestaurant.getName()); ActionBar actionbar = getSupportActionBar(); if (actionbar != null) { actionbar.setDisplayHomeAsUpEnabled(true); @@ -92,9 +119,10 @@ public class RestaurantActivity extends BaseActivity } }); - setupViewPager(viewPager); - TabLayout tabLayout = findViewById(R.id.restaurant_tabs); - tabLayout.setupWithViewPager(viewPager); + tabLayout = findViewById(R.id.restaurant_tabs); + + RestaurantTask restaurantTask = new RestaurantTask(); + restaurantTask.execute(); } @Override @@ -132,10 +160,10 @@ public class RestaurantActivity extends BaseActivity private void setupViewPager(ViewPager viewPager) { RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager()); - adapter.addFrag(RestaurantInfoFragment.newInstance(64), "INFO"); - adapter.addFrag(RestaurantFoodsFragment.newInstance(64), "FOOD"); - adapter.addFrag(RestaurantDrinksFragment.newInstance(64), "DRINKS"); - adapter.addFrag(RestaurantRatingsFragment.newInstance(64), "RATINGS"); + adapter.addFrag(RestaurantInfoFragment.newInstance(restaurant), "INFO"); + adapter.addFrag(RestaurantFoodsFragment.newInstance(foods), "FOOD"); + adapter.addFrag(RestaurantDrinksFragment.newInstance(drinks), "DRINKS"); + adapter.addFrag(RestaurantRatingsFragment.newInstance(ratings), "RATINGS"); viewPager.setAdapter(adapter); } @@ -168,4 +196,128 @@ public class RestaurantActivity extends BaseActivity return mFragmentTitleList.get(position); } } + + private class RestaurantTask extends AsyncTask { + private static final String JSON_TAG_RESTAURANT_INFO = "restaurantInfo"; + private static final String JSON_TAG_RESTAURANT_ID = "restaurant_id"; + private static final String JSON_TAG_RESTAURANT_NAME = "restaurant_name"; + private static final String JSON_TAG_RESTAURANT_CATEGORY = "restaurant_category"; + private static final String JSON_TAG_RESTAURANT_LONGITUDE = "restaurant_longitude"; + private static final String JSON_TAG_RESTAURANT_LATITUDE = "restaurant_latitude"; + private static final String JSON_TAG_RESTAURANT_OPENING = "restaurant_opening"; + private static final String JSON_TAG_RESTAURANT_CLOSING = "restaurant_closing"; + private static final String JSON_TAG_RESTAURANT_AVG_RATING_OBJ = "averageRating"; + + private static final String JSON_TAG_RESTAURANT_AVG_RATING = "rating_grade__avg"; + + private static final String JSON_TAG_RESTAURANT_RATINGS_PER_DIET = "avgRatingPerDiet"; + private static final String JSON_TAG_RESTAURANT_RATINGS_PER_DIET_NAME = "diet_name"; + private static final String JSON_TAG_RESTAURANT_RATINGS_PER_DIET_RATING = "average_rating"; + + private static final String JSON_TAG_RESTAURANT_FOODS = "foods"; + private static final String JSON_TAG_RESTAURANT_FOOD_ID = "food_id"; + private static final String JSON_TAG_RESTAURANT_FOOD_NAME = "food_name"; + + private static final String JSON_TAG_RESTAURANT_DRINKS = "drinks"; + private static final String JSON_TAG_RESTAURANT_DRINK_ID = "drink_id"; + private static final String JSON_TAG_RESTAURANT_DRINK_NAME = "drink_name"; + + private static final String JSON_TAG_RESTAURANT_RATINGS = "ratings"; + private static final String JSON_TAG_RESTAURANT_RATING_GRADE = "rating_grade"; + private static final String JSON_TAG_RESTAURANT_RATING_USERNAME = "username"; + private static final String JSON_TAG_RESTAURANT_RATING_TEXT = "rating_text"; + private static final String JSON_TAG_RESTAURANT_RATING_DATE = "rating_date"; + private static final String JSON_TAG_RESTAURANT_RATING_ACCESSIBILITY = "rating_accessibility"; + + + @Override + protected void onPreExecute() { + foods.clear(); + drinks.clear(); + ratings.clear(); + } + + @Override + protected Integer doInBackground(Void... params) { + String requestUrl = restaurantsUserViewUrl + mRestaurant.getId() + "/"; + + //Builds the request + Request request = new Request.Builder() + .url(requestUrl) + .build(); + + try { + //Makes request & handles response + Response response = client.newCall(request).execute(); + + ResponseBody responseBody = response.body(); + assert responseBody != null; + String result = responseBody.string(); + JSONObject jsonResponce = new JSONObject(result); + + JSONObject jsonRestaurantInfo = jsonResponce.getJSONObject(JSON_TAG_RESTAURANT_INFO); + JSONArray jsonRatingsPerDiet = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_RATINGS_PER_DIET); + ArrayList> ratingsPerDiet = new ArrayList<>(); + + for (int dietIndex = 0; dietIndex < jsonRatingsPerDiet.length(); ++dietIndex) { + JSONObject dietAvgRating = (JSONObject) jsonRatingsPerDiet.get(dietIndex); + ratingsPerDiet.add(new Pair<>(dietAvgRating.getString(JSON_TAG_RESTAURANT_RATINGS_PER_DIET_NAME), + dietAvgRating.getDouble(JSON_TAG_RESTAURANT_RATINGS_PER_DIET_RATING))); + } + + restaurant = new RestaurantUserView(jsonRestaurantInfo.getInt(JSON_TAG_RESTAURANT_ID), + jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_NAME), + jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CATEGORY), + jsonRestaurantInfo.getDouble(JSON_TAG_RESTAURANT_LONGITUDE), + jsonRestaurantInfo.getDouble(JSON_TAG_RESTAURANT_LATITUDE), + jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_OPENING), + jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CLOSING), + jsonResponce.getJSONObject(JSON_TAG_RESTAURANT_AVG_RATING_OBJ).getDouble(JSON_TAG_RESTAURANT_AVG_RATING), + ratingsPerDiet); + + JSONArray jsonFoods = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_FOODS); + Log.d("THISSS", "jsonFoods size = " + jsonFoods.length()); + for (int foodIndex = 0; foodIndex < jsonFoods.length(); ++foodIndex) { + JSONObject food = jsonFoods.getJSONObject(foodIndex); + foods.add(new ItemSummary(food.getString(JSON_TAG_RESTAURANT_FOOD_NAME), + food.getInt(JSON_TAG_RESTAURANT_FOOD_ID), + ItemSummary.ItemType.FOOD)); + } + Log.d("THISSS", "foods size = " + foods.size()); + + + JSONArray jsonDrinks = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_DRINKS); + Log.d("THISSS", "jsonDrinks size = " + jsonDrinks.length()); + for (int drinkIndex = 0; drinkIndex < jsonDrinks.length(); ++drinkIndex) { + JSONObject drink = jsonDrinks.getJSONObject(drinkIndex); + drinks.add(new ItemSummary(drink.getString(JSON_TAG_RESTAURANT_DRINK_NAME), + drink.getInt(JSON_TAG_RESTAURANT_DRINK_ID), + ItemSummary.ItemType.DRINK)); + } + Log.d("THISSS", "drinks size = " + drinks.size()); + + JSONArray jsonRatings = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_RATINGS); + for (int ratingIndex = 0; ratingIndex < jsonRatings.length(); ++ratingIndex) { + JSONObject rating = jsonRatings.getJSONObject(ratingIndex); + ratings.add(new RestaurantRating(rating.getInt(JSON_TAG_RESTAURANT_RATING_GRADE), + rating.getString(JSON_TAG_RESTAURANT_RATING_USERNAME), + rating.getString(JSON_TAG_RESTAURANT_RATING_TEXT), + rating.getString(JSON_TAG_RESTAURANT_RATING_DATE), + RestaurantRating.Accessibility.getEnumTypeFromString( + rating.getString(JSON_TAG_RESTAURANT_RATING_ACCESSIBILITY)))); + } + + return 1; + } catch (Exception e) { + e.printStackTrace(); + return 2; + } + } + + @Override + protected void onPostExecute(Integer result) { //Handle attempt result + setupViewPager(viewPager); + tabLayout.setupWithViewPager(viewPager); + } + } } 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 968a0de..1bca874 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 @@ -20,14 +20,14 @@ public class RestaurantDrinksFragment extends BaseFragment { // Required empty public constructor } - private static final String RESTAURANT_ID = "RESTAURANT_ID"; + private static final String RESTAURANT_DRINKS = "RESTAURANT_DRINKS"; - private int restaurantId; + private ArrayList drinks; - public static RestaurantDrinksFragment newInstance(int restaurantId) { + public static RestaurantDrinksFragment newInstance(ArrayList drinks) { RestaurantDrinksFragment fragment = new RestaurantDrinksFragment(); Bundle args = new Bundle(); - args.putInt(RESTAURANT_ID, restaurantId); + args.putParcelableArrayList(RESTAURANT_DRINKS, drinks); fragment.setArguments(args); return fragment; } @@ -36,17 +36,12 @@ public class RestaurantDrinksFragment extends BaseFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - restaurantId = getArguments().getInt(RESTAURANT_ID); + drinks = getArguments().getParcelableArrayList(RESTAURANT_DRINKS); } @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false); - - ArrayList drinks = new ArrayList<>(); - drinks.add(new ItemSummary("White russian", 5, ItemSummary.ItemType.DRINK)); - drinks.add(new ItemSummary("Τσίπουρο Τσάπουρας", 5, ItemSummary.ItemType.DRINK)); - RestaurantItemAdapter itemAdapter = new RestaurantItemAdapter(fragmentInteractionListener, ItemSummary.ItemType.DRINK, drinks); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); 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 07df4bc..0a2807a 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 @@ -20,14 +20,14 @@ public class RestaurantFoodsFragment extends BaseFragment { // Required empty public constructor } - private static final String RESTAURANT_ID = "RESTAURANT_ID"; + private static final String RESTAURANT_FOODS = "RESTAURANT_FOODS"; - private int restaurantId; + private ArrayList foods; - public static RestaurantFoodsFragment newInstance(int restaurantId) { + public static RestaurantFoodsFragment newInstance(ArrayList foods) { RestaurantFoodsFragment fragment = new RestaurantFoodsFragment(); Bundle args = new Bundle(); - args.putInt(RESTAURANT_ID, restaurantId); + args.putParcelableArrayList(RESTAURANT_FOODS, foods); fragment.setArguments(args); return fragment; } @@ -36,17 +36,12 @@ public class RestaurantFoodsFragment extends BaseFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - restaurantId = getArguments().getInt(RESTAURANT_ID); + foods = getArguments().getParcelableArrayList(RESTAURANT_FOODS); } @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false); - - ArrayList foods = new ArrayList<>(); - foods.add(new ItemSummary("Γιουβαρλάκια", 5, ItemSummary.ItemType.FOOD)); - foods.add(new ItemSummary("Γεμιστά", 5, ItemSummary.ItemType.FOOD)); - RestaurantItemAdapter itemAdapter = new RestaurantItemAdapter(fragmentInteractionListener, ItemSummary.ItemType.FOOD, foods); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); 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 82957e9..1b13c60 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 @@ -1,6 +1,7 @@ package gr.auth.databases.flavours.activities.restaurant.fragments; import android.os.Bundle; +import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,6 +19,7 @@ import com.google.android.gms.maps.model.MarkerOptions; import androidx.annotation.NonNull; import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.base.BaseFragment; +import gr.auth.databases.flavours.model.RestaurantUserView; public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCallback { private MapView gMapView = null; @@ -26,14 +28,14 @@ public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCa // Required empty public constructor } - private static final String RESTAURANT_ID = "RESTAURANT_ID"; + private static final String RESTAURANT_INFO = "RESTAURANT_INFO"; - private int restaurantId; + private RestaurantUserView restaurant; - public static RestaurantInfoFragment newInstance(int restaurantId) { + public static RestaurantInfoFragment newInstance(RestaurantUserView restaurant) { RestaurantInfoFragment fragment = new RestaurantInfoFragment(); Bundle args = new Bundle(); - args.putInt(RESTAURANT_ID, restaurantId); + args.putParcelable(RESTAURANT_INFO, restaurant); fragment.setArguments(args); return fragment; } @@ -42,7 +44,7 @@ public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCa public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - restaurantId = getArguments().getInt(RESTAURANT_ID); + restaurant = getArguments().getParcelable(RESTAURANT_INFO); } @Override @@ -50,21 +52,28 @@ public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCa final View rootView = inflater.inflate(R.layout.fragment_restaurant_info, container, false); TextView workingHours = rootView.findViewById(R.id.restaurant_working_hours); - workingHours.setText(getString(R.string.restaurant_working_hours, - "12:00", "01:30")); + if (restaurant.getOpeningTime() != null && restaurant.getClosingTime() != null) { + workingHours.setText(getString(R.string.restaurant_working_hours, + restaurant.getOpeningTime(), restaurant.getClosingTime())); + } else { + workingHours.setText(getString(R.string.restaurant_working_hours, "-", "-")); + } TextView type = rootView.findViewById(R.id.restaurant_type); - type.setText(getString(R.string.restaurant_type, "Bar")); + type.setText(getString(R.string.restaurant_type, restaurant.getType())); TextView averageRatings = rootView.findViewById(R.id.restaurant_average_rating); - 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); - dietRatingView = new TextView(getContext()); - dietRatingView.setText(getString(R.string.restaurant_diet_average_rating, "vegan", 2.23)); - averageRatingPerDiet.addView(dietRatingView); + averageRatings.setText(getString(R.string.restaurant_average_rating, restaurant.getAverageRating())); + + if (!restaurant.getAverageRatingPerDiet().isEmpty()) { + LinearLayout averageRatingPerDiet = rootView.findViewById(R.id.restaurant_average_rating_per_diet); + averageRatingPerDiet.setVisibility(View.VISIBLE); + + for (Pair rating : restaurant.getAverageRatingPerDiet()) { + TextView dietRatingView = new TextView(getContext()); + dietRatingView.setText(getString(R.string.restaurant_diet_average_rating, + rating.first, rating.second)); + averageRatingPerDiet.addView(dietRatingView); + } + } gMapView = rootView.findViewById(R.id.restaurant_map); gMapView.getMapAsync(this); @@ -129,11 +138,11 @@ public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCa */ @Override public void onMapReady(GoogleMap googleMap) { - LatLng aitheroploo = new LatLng(40.6144, 22.9598); + LatLng restaurantLocation = new LatLng(restaurant.getLatitude(), restaurant.getLongitude()); googleMap.addMarker(new MarkerOptions() - .position(aitheroploo) - .title("Αιθερόπλοο") + .position(restaurantLocation) + .title(restaurant.getName()) .icon(BitmapDescriptorFactory.fromResource(R.drawable.pub_marker))); - googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(aitheroploo, 12.0f)); + googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(restaurantLocation, 12.0f)); } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java index b95aaca..bf10af5 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java @@ -23,14 +23,14 @@ public class RestaurantRatingsFragment extends Fragment { // Required empty public constructor } - private static final String RESTAURANT_ID = "RESTAURANT_ID"; + private static final String RESTAURANT_RATINGS = "RESTAURANT_RATINGS"; - private int restaurantId; + private ArrayList ratings; - public static RestaurantRatingsFragment newInstance(int restaurantId) { + public static RestaurantRatingsFragment newInstance(ArrayList ratings) { RestaurantRatingsFragment fragment = new RestaurantRatingsFragment(); Bundle args = new Bundle(); - args.putInt(RESTAURANT_ID, restaurantId); + args.putParcelableArrayList(RESTAURANT_RATINGS, ratings); fragment.setArguments(args); return fragment; } @@ -39,22 +39,12 @@ public class RestaurantRatingsFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - restaurantId = getArguments().getInt(RESTAURANT_ID); + ratings = getArguments().getParcelableArrayList(RESTAURANT_RATINGS); } @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 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)); - Context context = getContext(); assert context != null; RestaurantRatingsAdapter itemAdapter = new RestaurantRatingsAdapter(context, ratings); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java index 1c8363f..4e3c925 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java @@ -1,22 +1,60 @@ package gr.auth.databases.flavours.model; -public class ItemSummary { +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.Nullable; + +public class ItemSummary implements Parcelable { public enum ItemType { - FOOD, DRINK + FOOD(0), DRINK(1), UNSUPPORTED(-1); + + private int id; + + ItemType(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + @Nullable + public static String getWorkingTypeFromId(int id) { + switch (id) { + case 0: + return "Food"; + case 1: + return "Drink"; + default: + return null; + } + } + + public static ItemType getEnumTypeFromId(int id) { + switch (id) { + case 0: + return FOOD; + case 1: + return DRINK; + default: + return UNSUPPORTED; + } + } } - private String item; + private String itemName; private int id; private ItemType type; public ItemSummary(String item, int id, ItemType type) { - this.item = item; + this.itemName = item; this.id = id; this.type = type; } public String getItem() { - return item; + return itemName; } public int getId() { @@ -26,4 +64,32 @@ public class ItemSummary { public ItemType getType() { return type; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(id); + out.writeString(itemName); + out.writeInt(type.getId()); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public ItemSummary createFromParcel(Parcel in) { + return new ItemSummary(in); + } + + public ItemSummary[] newArray(int size) { + return new ItemSummary[size]; + } + }; + + private ItemSummary(Parcel in) { + id = in.readInt(); + itemName = in.readString(); + type = ItemType.getEnumTypeFromId(in.readInt()); + } } 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 bc065ad..49f917a 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,6 +1,9 @@ package gr.auth.databases.flavours.model; -public class Rating { +import android.os.Parcel; +import android.os.Parcelable; + +public class Rating implements Parcelable { private int grade; private String username, text, date; @@ -26,4 +29,34 @@ public class Rating { public String getDate() { return date; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(getGrade()); + out.writeString(getUsername()); + out.writeString(getText()); + out.writeString(getDate()); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public Rating createFromParcel(Parcel in) { + return new Rating(in); + } + + public Rating[] newArray(int size) { + return new Rating[size]; + } + }; + + Rating(Parcel in) { + grade = in.readInt(); + username = in.readString(); + text = in.readString(); + date = in.readString(); + } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java index 0f7fe39..add4501 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java @@ -128,7 +128,7 @@ public class Restaurant implements Parcelable { } }; - private Restaurant(Parcel in) { + Restaurant(Parcel in) { id = in.readInt(); name = in.readString(); type = in.readString(); 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 index b8b3d11..bd04ede 100644 --- 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 @@ -1,5 +1,7 @@ package gr.auth.databases.flavours.model; +import android.os.Parcel; + import androidx.annotation.Nullable; public class RestaurantRating extends Rating { @@ -42,6 +44,19 @@ public class RestaurantRating extends Rating { return UNSUPPORTED; } } + + public static Accessibility getEnumTypeFromString(String possible) { + switch (possible.toLowerCase()) { + case "easy": + return EASY; + case "moderate": + return MODERATE; + case "hard": + return HARD; + default: + return UNSUPPORTED; + } + } } private Accessibility accessibility; @@ -54,4 +69,31 @@ public class RestaurantRating extends Rating { public Accessibility getAccessibility() { return accessibility; } + + private RestaurantRating(Parcel in) { + super(in); + accessibility = Accessibility.getEnumTypeFromId(in.readInt()); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RestaurantRating createFromParcel(Parcel in) { + return new RestaurantRating(in); + } + + @Override + public RestaurantRating[] newArray(int size) { + return new RestaurantRating[size]; + } + }; + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(accessibility.getId()); + } + + public int describeContents() { + return 0; + } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java new file mode 100644 index 0000000..4142e86 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java @@ -0,0 +1,56 @@ +package gr.auth.databases.flavours.model; + +import android.os.Parcel; +import android.util.Pair; + +import java.util.ArrayList; + +public class RestaurantUserView extends Restaurant { + private double averageRating; + private ArrayList> averageRatingPerDiet; + + public RestaurantUserView(int id, String name, String type, double longitude, double latitude, + String openingTime, String closingTime, double averageRating, + ArrayList> averageRatingPerDiet) { + super(id, name, type, longitude, latitude, openingTime, closingTime); + this.averageRating = averageRating; + this.averageRatingPerDiet = averageRatingPerDiet; + } + + public double getAverageRating() { + return averageRating; + } + + public ArrayList> getAverageRatingPerDiet() { + return averageRatingPerDiet; + } + + private RestaurantUserView(Parcel in) { + super(in); + averageRating = in.readDouble(); + averageRatingPerDiet = (ArrayList>) in.readArrayList(Pair.class.getClassLoader()); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RestaurantUserView createFromParcel(Parcel in) { + return new RestaurantUserView(in); + } + + @Override + public RestaurantUserView[] newArray(int size) { + return new RestaurantUserView[size]; + } + }; + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeDouble(averageRating); + dest.writeList(averageRatingPerDiet); + } + + public int describeContents() { + return 0; + } +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java index 8107424..fdaa89e 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java @@ -54,6 +54,7 @@ public class SessionManager { public static final String logoutUrl = baseServerUrl + "api/rest-auth/logout/"; public static final String setUserBirthday = baseServerUrl + "api/setUserBirthday/"; public static final String restaurantsUrl = baseServerUrl + "api/restaurant/"; + public static final String restaurantsUserViewUrl = baseServerUrl + "api/restaurantUserView/"; // Client & Cookies private final OkHttpClient client; diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java index ade0a4a..ea3f1d9 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java @@ -39,7 +39,8 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter