Browse Source

API connection for restaurant rating, Fixes

master
Apostolos Fanakis 6 years ago
parent
commit
0e8daf3c14
  1. 154
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java
  2. 43
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  3. 12
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java
  4. 48
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/DietRatingPair.java
  5. 19
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/DietSummary.java
  6. 10
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java
  7. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java

154
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java

@ -1,13 +1,17 @@
package gr.auth.databases.flavours.activities; package gr.auth.databases.flavours.activities;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -17,14 +21,29 @@ import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.DietSummary;
import gr.auth.databases.flavours.model.Restaurant;
import gr.auth.databases.flavours.model.RestaurantRating; import gr.auth.databases.flavours.model.RestaurantRating;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import static gr.auth.databases.flavours.session.SessionManager.getUserDietsUrl;
import static gr.auth.databases.flavours.session.SessionManager.rateRestaurantUrl;
public class RateRestaurantActivity extends BaseActivity implements AdapterView.OnItemSelectedListener { public class RateRestaurantActivity extends BaseActivity implements AdapterView.OnItemSelectedListener {
public static final String BUNDLE_RATE_RESTAURANT_NAME = "BUNDLE_RATE_RESTAURANT_NAME"; public static final String BUNDLE_RATE_RESTAURANT = "BUNDLE_RATE_RESTAURANT";
List<String> spinnerArray = new ArrayList<>();
List<DietSummary> userDiets = new ArrayList<>();
private Restaurant restaurant;
private EditText ratingText; private EditText ratingText;
private int ratingGrade; private int ratingGrade = -1;
private RestaurantRating.Accessibility ratingAccessibility; private RestaurantRating.Accessibility ratingAccessibility;
private int ratingDiet = -1;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -32,9 +51,8 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
setContentView(R.layout.activity_rate_restaurant); setContentView(R.layout.activity_rate_restaurant);
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { assert extras != null;
//itemType = (ItemSummary.ItemType) extras.getSerializable(BUNDLE_ADD_ITEM_ITEM_TYPE); restaurant = extras.getParcelable(BUNDLE_RATE_RESTAURANT);
}
Toolbar toolbar = findViewById(R.id.rate_restaurant_toolbar); Toolbar toolbar = findViewById(R.id.rate_restaurant_toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -58,30 +76,22 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
accessibilitySpinner.setAdapter(accessibilityAdapter); accessibilitySpinner.setAdapter(accessibilityAdapter);
accessibilitySpinner.setOnItemSelectedListener(this); accessibilitySpinner.setOnItemSelectedListener(this);
List<String> spinnerArray = new ArrayList<String>();
spinnerArray.add("Όγκος");
spinnerArray.add("Πολύ όγκος");
Spinner dietSpinner = findViewById(R.id.rate_restaurant_diet);
ArrayAdapter<String> dietAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, spinnerArray);
dietAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dietSpinner.setAdapter(dietAdapter);
dietSpinner.setOnItemSelectedListener(this);
dietSpinner.setVisibility(View.VISIBLE);
ratingText = findViewById(R.id.rate_restaurant_text); ratingText = findViewById(R.id.rate_restaurant_text);
AppCompatButton rateButton = findViewById(R.id.rate_restaurant_rate_btn); AppCompatButton rateButton = findViewById(R.id.rate_restaurant_rate_btn);
rateButton.setOnClickListener(new View.OnClickListener() { rateButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//TODO RateRestaurantTask rateRestaurantTask = new RateRestaurantTask();
rateRestaurantTask.execute();
} }
}); });
createDrawer(); createDrawer();
drawer.setSelection(-1); drawer.setSelection(-1);
GetUserDietsTask getUserDietsTask = new GetUserDietsTask();
getUserDietsTask.execute();
} }
@Override @Override
@ -111,10 +121,116 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
} else if (parent.getId() == R.id.rate_restaurant_accessibility) { } else if (parent.getId() == R.id.rate_restaurant_accessibility) {
ratingAccessibility = RestaurantRating.Accessibility.getEnumTypeFromId(pos); ratingAccessibility = RestaurantRating.Accessibility.getEnumTypeFromId(pos);
} else if (parent.getId() == R.id.rate_restaurant_diet) { } else if (parent.getId() == R.id.rate_restaurant_diet) {
if (pos == 0) {
ratingDiet = -1;
} else {
ratingDiet = userDiets.get(pos - 1).getId();
}
} }
} }
@Override @Override
public void onNothingSelected(AdapterView<?> adapterView) { public void onNothingSelected(AdapterView<?> adapterView) {
} }
private class GetUserDietsTask extends AsyncTask<Void, Void, Integer> {
private static final String JSON_TAG_DIET_ID = "diet_id";
private static final String JSON_TAG_DIET_NAME = "diet_name";
@Override
protected void onPreExecute() {
}
@Override
protected Integer doInBackground(Void... params) {
//Builds the request
Request request = new Request.Builder()
.url(getUserDietsUrl)
.build();
try {
//Makes request & handles response
Response response = client.newCall(request).execute();
ResponseBody responseBody = response.body();
assert responseBody != null;
String result = responseBody.string();
JSONArray jsonResponse = new JSONArray(result);
spinnerArray.add("None");
for (int dietIndex = 0; dietIndex < jsonResponse.length(); ++dietIndex) {
JSONObject diet = (JSONObject) jsonResponse.get(dietIndex);
spinnerArray.add(diet.getString(JSON_TAG_DIET_NAME));
userDiets.add(new DietSummary(diet.getInt(JSON_TAG_DIET_ID),
diet.getString(JSON_TAG_DIET_NAME)));
}
return 1;
} catch (Exception e) {
e.printStackTrace();
return 2;
}
}
@Override
protected void onPostExecute(Integer result) { //Handle attempt result
Spinner dietSpinner = findViewById(R.id.rate_restaurant_diet);
ArrayAdapter<String> dietAdapter = new ArrayAdapter<>(RateRestaurantActivity.this,
android.R.layout.simple_spinner_item, spinnerArray);
dietAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dietSpinner.setAdapter(dietAdapter);
dietSpinner.setOnItemSelectedListener(RateRestaurantActivity.this);
dietSpinner.setVisibility(View.VISIBLE);
}
}
private class RateRestaurantTask extends AsyncTask<Void, Void, Integer> {
private static final String REQ_RATE_RESTAURANT_ID = "restaurant";
private static final String REQ_RATE_RESTAURANT_GRADE = "rating_grade";
private static final String REQ_RATE_RESTAURANT_ACCESSIBILITY = "rating_accessibility";
private static final String REQ_RATE_RESTAURANT_DIET = "diet";
private static final String REQ_RATE_RESTAURANT_TEXT = "rating_text";
@Override
protected void onPreExecute() {
}
@Override
protected Integer doInBackground(Void... params) {
//Builds the signup request
FormBody.Builder builder = new FormBody.Builder()
.add(REQ_RATE_RESTAURANT_ID, "" + restaurant.getId())
.add(REQ_RATE_RESTAURANT_GRADE, "" + ratingGrade)
.add(REQ_RATE_RESTAURANT_TEXT, ratingText.getText().toString())
.add("user", "1");
if (ratingAccessibility != null) {
builder.add(REQ_RATE_RESTAURANT_ACCESSIBILITY,
"" + RestaurantRating.Accessibility.getWorkingTypeFromId(ratingAccessibility.getId()));
}
if (ratingDiet != -1) {
builder.add(REQ_RATE_RESTAURANT_DIET, "" + ratingDiet);
}
RequestBody formBody = builder.build();
Request request = new Request.Builder()
.url(rateRestaurantUrl)
.post(formBody)
.build();
try {
//Makes request & handles response
client.newCall(request).execute();
return 0;
} catch (Exception e) {
return 2;
}
}
@Override
protected void onPostExecute(Integer result) { //Handle attempt result
Toast.makeText(RateRestaurantActivity.this, "Rating added!", Toast.LENGTH_SHORT).show();
RateRestaurantActivity.this.finish();
}
}
} }

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

@ -3,8 +3,6 @@ package gr.auth.databases.flavours.activities.restaurant;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -34,6 +32,7 @@ import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantFood
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantInfoFragment; import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantInfoFragment;
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantRatingsFragment; import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantRatingsFragment;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.DietRatingPair;
import gr.auth.databases.flavours.model.ItemSummary; import gr.auth.databases.flavours.model.ItemSummary;
import gr.auth.databases.flavours.model.Restaurant; import gr.auth.databases.flavours.model.Restaurant;
import gr.auth.databases.flavours.model.RestaurantRating; import gr.auth.databases.flavours.model.RestaurantRating;
@ -43,6 +42,7 @@ import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import static gr.auth.databases.flavours.activities.AddItemActivity.BUNDLE_ADD_ITEM_ITEM_TYPE; import static gr.auth.databases.flavours.activities.AddItemActivity.BUNDLE_ADD_ITEM_ITEM_TYPE;
import static gr.auth.databases.flavours.activities.RateRestaurantActivity.BUNDLE_RATE_RESTAURANT;
import static gr.auth.databases.flavours.session.SessionManager.restaurantsUserViewUrl; import static gr.auth.databases.flavours.session.SessionManager.restaurantsUserViewUrl;
public class RestaurantActivity extends BaseActivity public class RestaurantActivity extends BaseActivity
@ -50,11 +50,11 @@ public class RestaurantActivity extends BaseActivity
RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener { RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener {
public static final String BUNDLE_ARG_RESTAURANT = "BUNDLE_ARG_RESTAURANT"; public static final String BUNDLE_ARG_RESTAURANT = "BUNDLE_ARG_RESTAURANT";
private static Restaurant mRestaurant; private Restaurant mRestaurant;
private static RestaurantUserView restaurant; private RestaurantUserView restaurant;
private ArrayList<ItemSummary> foods = new ArrayList<>(); private ArrayList<ItemSummary> foods = new ArrayList<>();
private ArrayList<ItemSummary> drinks = new ArrayList<>(); private ArrayList<ItemSummary> drinks = new ArrayList<>();
ArrayList<RestaurantRating> ratings = new ArrayList<>(); private ArrayList<RestaurantRating> ratings = new ArrayList<>();
private ViewPager viewPager; private ViewPager viewPager;
private TabLayout tabLayout; private TabLayout tabLayout;
@ -68,7 +68,7 @@ public class RestaurantActivity extends BaseActivity
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
assert extras != null; assert extras != null;
mRestaurant = (Restaurant) extras.getParcelable(BUNDLE_ARG_RESTAURANT); mRestaurant = extras.getParcelable(BUNDLE_ARG_RESTAURANT);
Toolbar toolbar = findViewById(R.id.restaurant_toolbar); Toolbar toolbar = findViewById(R.id.restaurant_toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -97,6 +97,7 @@ public class RestaurantActivity extends BaseActivity
startActivity(intent); startActivity(intent);
} else if (viewPager.getCurrentItem() == 3) { } else if (viewPager.getCurrentItem() == 3) {
Intent intent = new Intent(view.getContext(), RateRestaurantActivity.class); Intent intent = new Intent(view.getContext(), RateRestaurantActivity.class);
intent.putExtra(BUNDLE_RATE_RESTAURANT, mRestaurant);
startActivity(intent); startActivity(intent);
} }
} }
@ -253,18 +254,23 @@ public class RestaurantActivity extends BaseActivity
ResponseBody responseBody = response.body(); ResponseBody responseBody = response.body();
assert responseBody != null; assert responseBody != null;
String result = responseBody.string(); String result = responseBody.string();
JSONObject jsonResponce = new JSONObject(result); JSONObject jsonResponse = new JSONObject(result);
JSONObject jsonRestaurantInfo = jsonResponce.getJSONObject(JSON_TAG_RESTAURANT_INFO); JSONObject jsonRestaurantInfo = jsonResponse.getJSONObject(JSON_TAG_RESTAURANT_INFO);
JSONArray jsonRatingsPerDiet = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_RATINGS_PER_DIET); JSONArray jsonRatingsPerDiet = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_RATINGS_PER_DIET);
ArrayList<Pair<String, Double>> ratingsPerDiet = new ArrayList<>(); ArrayList<DietRatingPair> ratingsPerDiet = new ArrayList<>();
for (int dietIndex = 0; dietIndex < jsonRatingsPerDiet.length(); ++dietIndex) { for (int dietIndex = 0; dietIndex < jsonRatingsPerDiet.length(); ++dietIndex) {
JSONObject dietAvgRating = (JSONObject) jsonRatingsPerDiet.get(dietIndex); JSONObject dietAvgRating = (JSONObject) jsonRatingsPerDiet.get(dietIndex);
ratingsPerDiet.add(new Pair<>(dietAvgRating.getString(JSON_TAG_RESTAURANT_RATINGS_PER_DIET_NAME), ratingsPerDiet.add(new DietRatingPair(dietAvgRating.getString(JSON_TAG_RESTAURANT_RATINGS_PER_DIET_NAME),
dietAvgRating.getDouble(JSON_TAG_RESTAURANT_RATINGS_PER_DIET_RATING))); dietAvgRating.getDouble(JSON_TAG_RESTAURANT_RATINGS_PER_DIET_RATING)));
} }
double avgRestaurantRating = -1;
if (!jsonResponse.getJSONObject(JSON_TAG_RESTAURANT_AVG_RATING_OBJ).isNull(JSON_TAG_RESTAURANT_AVG_RATING)) {
avgRestaurantRating = jsonResponse.getJSONObject(JSON_TAG_RESTAURANT_AVG_RATING_OBJ).getDouble(JSON_TAG_RESTAURANT_AVG_RATING);
}
restaurant = new RestaurantUserView(jsonRestaurantInfo.getInt(JSON_TAG_RESTAURANT_ID), restaurant = new RestaurantUserView(jsonRestaurantInfo.getInt(JSON_TAG_RESTAURANT_ID),
jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_NAME), jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_NAME),
jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CATEGORY), jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CATEGORY),
@ -272,31 +278,26 @@ public class RestaurantActivity extends BaseActivity
jsonRestaurantInfo.getDouble(JSON_TAG_RESTAURANT_LATITUDE), jsonRestaurantInfo.getDouble(JSON_TAG_RESTAURANT_LATITUDE),
jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_OPENING), jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_OPENING),
jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CLOSING), jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CLOSING),
jsonResponce.getJSONObject(JSON_TAG_RESTAURANT_AVG_RATING_OBJ).getDouble(JSON_TAG_RESTAURANT_AVG_RATING), avgRestaurantRating,
ratingsPerDiet); ratingsPerDiet);
JSONArray jsonFoods = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_FOODS); JSONArray jsonFoods = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_FOODS);
Log.d("THISSS", "jsonFoods size = " + jsonFoods.length());
for (int foodIndex = 0; foodIndex < jsonFoods.length(); ++foodIndex) { for (int foodIndex = 0; foodIndex < jsonFoods.length(); ++foodIndex) {
JSONObject food = jsonFoods.getJSONObject(foodIndex); JSONObject food = jsonFoods.getJSONObject(foodIndex);
foods.add(new ItemSummary(food.getString(JSON_TAG_RESTAURANT_FOOD_NAME), foods.add(new ItemSummary(food.getString(JSON_TAG_RESTAURANT_FOOD_NAME),
food.getInt(JSON_TAG_RESTAURANT_FOOD_ID), food.getInt(JSON_TAG_RESTAURANT_FOOD_ID),
ItemSummary.ItemType.FOOD)); ItemSummary.ItemType.FOOD));
} }
Log.d("THISSS", "foods size = " + foods.size());
JSONArray jsonDrinks = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_DRINKS); JSONArray jsonDrinks = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_DRINKS);
Log.d("THISSS", "jsonDrinks size = " + jsonDrinks.length());
for (int drinkIndex = 0; drinkIndex < jsonDrinks.length(); ++drinkIndex) { for (int drinkIndex = 0; drinkIndex < jsonDrinks.length(); ++drinkIndex) {
JSONObject drink = jsonDrinks.getJSONObject(drinkIndex); JSONObject drink = jsonDrinks.getJSONObject(drinkIndex);
drinks.add(new ItemSummary(drink.getString(JSON_TAG_RESTAURANT_DRINK_NAME), drinks.add(new ItemSummary(drink.getString(JSON_TAG_RESTAURANT_DRINK_NAME),
drink.getInt(JSON_TAG_RESTAURANT_DRINK_ID), drink.getInt(JSON_TAG_RESTAURANT_DRINK_ID),
ItemSummary.ItemType.DRINK)); ItemSummary.ItemType.DRINK));
} }
Log.d("THISSS", "drinks size = " + drinks.size());
JSONArray jsonRatings = jsonResponce.getJSONArray(JSON_TAG_RESTAURANT_RATINGS); JSONArray jsonRatings = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_RATINGS);
for (int ratingIndex = 0; ratingIndex < jsonRatings.length(); ++ratingIndex) { for (int ratingIndex = 0; ratingIndex < jsonRatings.length(); ++ratingIndex) {
JSONObject rating = jsonRatings.getJSONObject(ratingIndex); JSONObject rating = jsonRatings.getJSONObject(ratingIndex);
ratings.add(new RestaurantRating(rating.getInt(JSON_TAG_RESTAURANT_RATING_GRADE), ratings.add(new RestaurantRating(rating.getInt(JSON_TAG_RESTAURANT_RATING_GRADE),
@ -315,7 +316,7 @@ public class RestaurantActivity extends BaseActivity
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
setupViewPager(viewPager); setupViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
} }

12
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java

@ -1,7 +1,6 @@
package gr.auth.databases.flavours.activities.restaurant.fragments; package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.os.Bundle; import android.os.Bundle;
import android.util.Pair;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -19,6 +18,7 @@ import com.google.android.gms.maps.model.MarkerOptions;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseFragment; import gr.auth.databases.flavours.base.BaseFragment;
import gr.auth.databases.flavours.model.DietRatingPair;
import gr.auth.databases.flavours.model.RestaurantUserView; import gr.auth.databases.flavours.model.RestaurantUserView;
public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCallback { public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCallback {
@ -61,16 +61,20 @@ public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCa
TextView type = rootView.findViewById(R.id.restaurant_type); TextView type = rootView.findViewById(R.id.restaurant_type);
type.setText(getString(R.string.restaurant_type, restaurant.getType())); type.setText(getString(R.string.restaurant_type, restaurant.getType()));
TextView averageRatings = rootView.findViewById(R.id.restaurant_average_rating); TextView averageRatings = rootView.findViewById(R.id.restaurant_average_rating);
averageRatings.setText(getString(R.string.restaurant_average_rating, restaurant.getAverageRating())); if (restaurant.getAverageRating() != -1) {
averageRatings.setText(getString(R.string.restaurant_average_rating, restaurant.getAverageRating()));
} else {
averageRatings.setVisibility(View.GONE);
}
if (!restaurant.getAverageRatingPerDiet().isEmpty()) { if (!restaurant.getAverageRatingPerDiet().isEmpty()) {
LinearLayout averageRatingPerDiet = rootView.findViewById(R.id.restaurant_average_rating_per_diet); LinearLayout averageRatingPerDiet = rootView.findViewById(R.id.restaurant_average_rating_per_diet);
averageRatingPerDiet.setVisibility(View.VISIBLE); averageRatingPerDiet.setVisibility(View.VISIBLE);
for (Pair<String, Double> rating : restaurant.getAverageRatingPerDiet()) { for (DietRatingPair rating : restaurant.getAverageRatingPerDiet()) {
TextView dietRatingView = new TextView(getContext()); TextView dietRatingView = new TextView(getContext());
dietRatingView.setText(getString(R.string.restaurant_diet_average_rating, dietRatingView.setText(getString(R.string.restaurant_diet_average_rating,
rating.first, rating.second)); rating.getDietName(), rating.getRating()));
averageRatingPerDiet.addView(dietRatingView); averageRatingPerDiet.addView(dietRatingView);
} }
} }

48
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/DietRatingPair.java

@ -0,0 +1,48 @@
package gr.auth.databases.flavours.model;
import android.os.Parcel;
import android.os.Parcelable;
public class DietRatingPair implements Parcelable {
private String dietName;
private double rating;
public DietRatingPair(String dietName, double rating) {
this.dietName = dietName;
this.rating = rating;
}
public String getDietName() {
return dietName;
}
public double getRating() {
return rating;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(dietName);
out.writeDouble(rating);
}
public static final Parcelable.Creator<DietRatingPair> CREATOR = new Parcelable.Creator<DietRatingPair>() {
public DietRatingPair createFromParcel(Parcel in) {
return new DietRatingPair(in);
}
public DietRatingPair[] newArray(int size) {
return new DietRatingPair[size];
}
};
private DietRatingPair(Parcel in) {
dietName = in.readString();
rating = in.readDouble();
}
}

19
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/DietSummary.java

@ -0,0 +1,19 @@
package gr.auth.databases.flavours.model;
public class DietSummary {
private int id;
private String name;
public DietSummary(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}

10
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java

@ -1,17 +1,16 @@
package gr.auth.databases.flavours.model; package gr.auth.databases.flavours.model;
import android.os.Parcel; import android.os.Parcel;
import android.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
public class RestaurantUserView extends Restaurant { public class RestaurantUserView extends Restaurant {
private double averageRating; private double averageRating;
private ArrayList<Pair<String, Double>> averageRatingPerDiet; private ArrayList<DietRatingPair> averageRatingPerDiet;
public RestaurantUserView(int id, String name, String type, double longitude, double latitude, public RestaurantUserView(int id, String name, String type, double longitude, double latitude,
String openingTime, String closingTime, double averageRating, String openingTime, String closingTime, double averageRating,
ArrayList<Pair<String, Double>> averageRatingPerDiet) { ArrayList<DietRatingPair> averageRatingPerDiet) {
super(id, name, type, longitude, latitude, openingTime, closingTime); super(id, name, type, longitude, latitude, openingTime, closingTime);
this.averageRating = averageRating; this.averageRating = averageRating;
this.averageRatingPerDiet = averageRatingPerDiet; this.averageRatingPerDiet = averageRatingPerDiet;
@ -21,14 +20,14 @@ public class RestaurantUserView extends Restaurant {
return averageRating; return averageRating;
} }
public ArrayList<Pair<String, Double>> getAverageRatingPerDiet() { public ArrayList<DietRatingPair> getAverageRatingPerDiet() {
return averageRatingPerDiet; return averageRatingPerDiet;
} }
private RestaurantUserView(Parcel in) { private RestaurantUserView(Parcel in) {
super(in); super(in);
averageRating = in.readDouble(); averageRating = in.readDouble();
averageRatingPerDiet = (ArrayList<Pair<String, Double>>) in.readArrayList(Pair.class.getClassLoader()); averageRatingPerDiet = (ArrayList<DietRatingPair>) in.readArrayList(DietRatingPair.class.getClassLoader());
} }
public static final Creator<RestaurantUserView> CREATOR = new Creator<RestaurantUserView>() { public static final Creator<RestaurantUserView> CREATOR = new Creator<RestaurantUserView>() {
@ -47,6 +46,7 @@ public class RestaurantUserView extends Restaurant {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);
dest.writeDouble(averageRating); dest.writeDouble(averageRating);
//dest.writeList(averageRatingPerDiet);
dest.writeList(averageRatingPerDiet); dest.writeList(averageRatingPerDiet);
} }

2
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java

@ -55,6 +55,8 @@ public class SessionManager {
public static final String setUserBirthday = baseServerUrl + "api/setUserBirthday/"; public static final String setUserBirthday = baseServerUrl + "api/setUserBirthday/";
public static final String restaurantsUrl = baseServerUrl + "api/restaurant/"; public static final String restaurantsUrl = baseServerUrl + "api/restaurant/";
public static final String restaurantsUserViewUrl = baseServerUrl + "api/restaurantUserView/"; public static final String restaurantsUserViewUrl = baseServerUrl + "api/restaurantUserView/";
public static final String getUserDietsUrl = baseServerUrl + "api/userDiets/";
public static final String rateRestaurantUrl = baseServerUrl + "api/userratesrestaurant/";
// Client & Cookies // Client & Cookies
private final OkHttpClient client; private final OkHttpClient client;

Loading…
Cancel
Save