|
@ -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); |
|
|
} |
|
|
} |
|
|