Browse Source

API connection for restaurant view

master
Apostolos Fanakis 6 years ago
parent
commit
69ca39bbb5
  1. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java
  2. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java
  3. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java
  4. 168
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  5. 15
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java
  6. 15
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java
  7. 53
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java
  8. 20
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java
  9. 76
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java
  10. 35
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Rating.java
  11. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java
  12. 42
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantRating.java
  13. 56
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java
  14. 1
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java
  15. 11
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java

2
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])

2
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();

5
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<MainAdapter.RestaurantViewHolder> {
private Context context;
private ArrayList<Restaurant> restaurants;
@ -36,11 +38,12 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.RestaurantView
}
@Override
public void onBindViewHolder(@NonNull RestaurantViewHolder holder, int position) {
public void onBindViewHolder(@NonNull final RestaurantViewHolder holder, int position) {
holder.card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, RestaurantActivity.class);
intent.putExtra(BUNDLE_ARG_RESTAURANT, restaurants.get(holder.getAdapterPosition()));
context.startActivity(intent);
}
});

168
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java

@ -1,13 +1,19 @@
package gr.auth.databases.flavours.activities.restaurant;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
@ -29,23 +35,44 @@ import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantInfo
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantRatingsFragment;
import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.ItemSummary;
import gr.auth.databases.flavours.model.Restaurant;
import gr.auth.databases.flavours.model.RestaurantRating;
import gr.auth.databases.flavours.model.RestaurantUserView;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import static gr.auth.databases.flavours.activities.AddItemActivity.BUNDLE_ADD_ITEM_ITEM_TYPE;
import static gr.auth.databases.flavours.session.SessionManager.restaurantsUserViewUrl;
public class RestaurantActivity extends BaseActivity
implements RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener,
RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener {
public static final String BUNDLE_ARG_RESTAURANT = "BUNDLE_ARG_RESTAURANT";
private static Restaurant mRestaurant;
private static RestaurantUserView restaurant;
private ArrayList<ItemSummary> foods = new ArrayList<>();
private ArrayList<ItemSummary> drinks = new ArrayList<>();
ArrayList<RestaurantRating> 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<Void, Void, Integer> {
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<Pair<String, Double>> 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);
}
}
}

15
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<ItemSummary> drinks;
public static RestaurantDrinksFragment newInstance(int restaurantId) {
public static RestaurantDrinksFragment newInstance(ArrayList<ItemSummary> 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<ItemSummary> 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);

15
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<ItemSummary> foods;
public static RestaurantFoodsFragment newInstance(int restaurantId) {
public static RestaurantFoodsFragment newInstance(ArrayList<ItemSummary> 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<ItemSummary> 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);

53
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<String, Double> 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));
}
}

20
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<RestaurantRating> ratings;
public static RestaurantRatingsFragment newInstance(int restaurantId) {
public static RestaurantRatingsFragment newInstance(ArrayList<RestaurantRating> 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<RestaurantRating> 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);

76
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<ItemSummary> CREATOR = new Parcelable.Creator<ItemSummary>() {
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());
}
}

35
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<Rating> CREATOR = new Parcelable.Creator<Rating>() {
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();
}
}

2
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();

42
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<RestaurantRating> CREATOR = new Creator<RestaurantRating>() {
@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;
}
}

56
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<Pair<String, Double>> averageRatingPerDiet;
public RestaurantUserView(int id, String name, String type, double longitude, double latitude,
String openingTime, String closingTime, double averageRating,
ArrayList<Pair<String, Double>> averageRatingPerDiet) {
super(id, name, type, longitude, latitude, openingTime, closingTime);
this.averageRating = averageRating;
this.averageRatingPerDiet = averageRatingPerDiet;
}
public double getAverageRating() {
return averageRating;
}
public ArrayList<Pair<String, Double>> getAverageRatingPerDiet() {
return averageRatingPerDiet;
}
private RestaurantUserView(Parcel in) {
super(in);
averageRating = in.readDouble();
averageRatingPerDiet = (ArrayList<Pair<String, Double>>) in.readArrayList(Pair.class.getClassLoader());
}
public static final Creator<RestaurantUserView> CREATOR = new Creator<RestaurantUserView>() {
@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;
}
}

1
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;

11
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java

@ -39,7 +39,8 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter<RestaurantRat
holder.grade.setText(context.getString(R.string.restaurant_ratings_row_grade_placeholder,
ratings.get(position).getGrade()));
if (ratings.get(position).getAccessibility() != null) {
if (ratings.get(position).getAccessibility() != null &&
ratings.get(position).getAccessibility() != RestaurantRating.Accessibility.UNSUPPORTED) {
holder.accessibility.setVisibility(View.VISIBLE);
holder.accessibility.setText(context.getString(R.string.restaurant_ratings_row_accessibility_placeholder,
ratings.get(position).getAccessibility().toString()));
@ -47,7 +48,13 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter<RestaurantRat
holder.accessibility.setVisibility(View.GONE);
}
holder.text.setText(ratings.get(position).getText());
if (!ratings.get(position).getText().equals("null")) {
holder.text.setVisibility(View.VISIBLE);
holder.text.setText(ratings.get(position).getText());
} else {
holder.text.setVisibility(View.GONE);
}
}
@Override

Loading…
Cancel
Save