|
|
@ -2,11 +2,8 @@ package gr.auth.databases.flavours.activities.profile; |
|
|
|
|
|
|
|
import android.os.AsyncTask; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.util.Log; |
|
|
|
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; |
|
|
@ -29,6 +26,7 @@ import gr.auth.databases.flavours.activities.profile.fragments.ProfileInfoFragme |
|
|
|
import gr.auth.databases.flavours.activities.profile.fragments.ProfileRestaurantRatingsFragment; |
|
|
|
import gr.auth.databases.flavours.base.BaseActivity; |
|
|
|
import gr.auth.databases.flavours.model.DietSummary; |
|
|
|
import gr.auth.databases.flavours.model.IngredientSummary; |
|
|
|
import gr.auth.databases.flavours.model.ItemRating; |
|
|
|
import gr.auth.databases.flavours.model.Profile; |
|
|
|
import gr.auth.databases.flavours.model.RestaurantRating; |
|
|
@ -43,7 +41,6 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
public static final String BUNDLE_USER_ID = "BUNDLE_USER_ID"; |
|
|
|
public static final String BUNDLE_USER_NAME = "BUNDLE_USER_NAME"; |
|
|
|
private ViewPager viewPager; |
|
|
|
private FloatingActionButton FAB; |
|
|
|
|
|
|
|
private int profileID; |
|
|
|
private Profile profileUserView; |
|
|
@ -73,30 +70,7 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
|
|
|
|
createDrawer(); |
|
|
|
|
|
|
|
FAB = findViewById(R.id.profile_fab); |
|
|
|
FAB.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View view) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
viewPager = findViewById(R.id.profile_pager); |
|
|
|
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { |
|
|
|
public void onPageScrollStateChanged(int state) { |
|
|
|
} |
|
|
|
|
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
|
|
|
} |
|
|
|
|
|
|
|
public void onPageSelected(int position) { |
|
|
|
if (position != 0) { |
|
|
|
FAB.hide(); |
|
|
|
} else { |
|
|
|
FAB.show(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
tabLayout = findViewById(R.id.profile_tabs); |
|
|
|
|
|
|
|
ProfileTask profileTask = new ProfileTask(); |
|
|
@ -126,7 +100,7 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
|
|
|
|
private void setupViewPager(ViewPager viewPager) { |
|
|
|
RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager()); |
|
|
|
adapter.addFrag(ProfileInfoFragment.newInstance(profileUserView), "INFO"); |
|
|
|
adapter.addFrag(ProfileInfoFragment.newInstance(profileUserView, profileID == sessionManager.getUserId()), "INFO"); |
|
|
|
adapter.addFrag(ProfileFoodRatingsFragment.newInstance(foodRatings), "FOODS"); |
|
|
|
adapter.addFrag(ProfileDrinkRatingsFragment.newInstance(drinkRatings), "DRINKS"); |
|
|
|
adapter.addFrag(ProfileRestaurantRatingsFragment.newInstance(restaurantRatings), "PLACES"); |
|
|
@ -173,12 +147,17 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
private static final String JSON_TAG_PROFILE_RESTAURANTS_OWNED = "owns"; |
|
|
|
private static final String JSON_TAG_PROFILE_RESTAURANT_OWNED_ID = "restaurant_id"; |
|
|
|
private static final String JSON_TAG_PROFILE_RESTAURANT_OWNED_NAME = "restaurant_name"; |
|
|
|
|
|
|
|
private static final String JSON_TAG_PROFILE_DIETS_FOLLOWED = "diets"; |
|
|
|
private static final String JSON_TAG_PROFILE_DIET_FOLLOWED_ID = "diet_id"; |
|
|
|
private static final String JSON_TAG_PROFILE_DIET_FOLLOWED_NAME = "diet_name"; |
|
|
|
|
|
|
|
private static final String JSON_TAG_PROFILE_INGREDIENTS_PROHIBITED = "ingredients"; |
|
|
|
private static final String JSON_TAG_PROFILE_INGREDIENTS_PROHIBITED_NAME = "ingredient_name"; |
|
|
|
|
|
|
|
private static final String JSON_TAG_FOOD_RATINGS = "foodRatings"; |
|
|
|
private static final String JSON_TAG_FOOD_RATING_GRADE = "rating_grade"; |
|
|
|
private static final String JSON_TAG_FOOD_RATING_USER_ID = "user_id"; |
|
|
|
private static final String JSON_TAG_FOOD_RATING_USERNAME = "username"; |
|
|
|
private static final String JSON_TAG_FOOD_RATING_TEXT = "rating_text"; |
|
|
|
private static final String JSON_TAG_FOOD_RATING_DATE = "rating_date"; |
|
|
@ -186,6 +165,7 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
|
|
|
|
private static final String JSON_TAG_DRINK_RATINGS = "drinkRatings"; |
|
|
|
private static final String JSON_TAG_DRINK_RATING_GRADE = "rating_grade"; |
|
|
|
private static final String JSON_TAG_DRINK_RATING_USER_ID = "user_id"; |
|
|
|
private static final String JSON_TAG_DRINK_RATING_USERNAME = "username"; |
|
|
|
private static final String JSON_TAG_DRINK_RATING_TEXT = "rating_text"; |
|
|
|
private static final String JSON_TAG_DRINK_RATING_DATE = "rating_date"; |
|
|
@ -193,6 +173,7 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
|
|
|
|
private static final String JSON_TAG_RESTAURANT_RATINGS = "restaurantRatings"; |
|
|
|
private static final String JSON_TAG_RESTAURANT_RATING_GRADE = "rating_grade"; |
|
|
|
private static final String JSON_TAG_RESTAURANT_RATING_USER_ID = "user_id"; |
|
|
|
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"; |
|
|
@ -236,9 +217,17 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
|
|
|
|
JSONArray jsonDietsFollowed = jsonProfileInfo.getJSONArray(JSON_TAG_PROFILE_DIETS_FOLLOWED); |
|
|
|
for (int dietIndex = 0; dietIndex < jsonDietsFollowed.length(); ++dietIndex) { |
|
|
|
JSONObject restaurantOwned = jsonDietsFollowed.getJSONObject(dietIndex); |
|
|
|
dietsFollowed.add(new DietSummary(restaurantOwned.getInt(JSON_TAG_PROFILE_DIET_FOLLOWED_ID), |
|
|
|
restaurantOwned.getString(JSON_TAG_PROFILE_DIET_FOLLOWED_NAME))); |
|
|
|
JSONObject jsonDiet = jsonDietsFollowed.getJSONObject(dietIndex); |
|
|
|
dietsFollowed.add(new DietSummary(jsonDiet.getInt(JSON_TAG_PROFILE_DIET_FOLLOWED_ID), |
|
|
|
jsonDiet.getString(JSON_TAG_PROFILE_DIET_FOLLOWED_NAME))); |
|
|
|
} |
|
|
|
|
|
|
|
ArrayList<IngredientSummary> ingredientsProhibited = new ArrayList<>(); |
|
|
|
|
|
|
|
JSONArray jsonIngredientsProhibited = jsonProfileInfo.getJSONArray(JSON_TAG_PROFILE_INGREDIENTS_PROHIBITED); |
|
|
|
for (int ingredientIndex = 0; ingredientIndex < jsonIngredientsProhibited.length(); ++ingredientIndex) { |
|
|
|
JSONObject jsonIngredient = jsonIngredientsProhibited.getJSONObject(ingredientIndex); |
|
|
|
ingredientsProhibited.add(new IngredientSummary(jsonIngredient.getString(JSON_TAG_PROFILE_INGREDIENTS_PROHIBITED_NAME))); |
|
|
|
} |
|
|
|
|
|
|
|
profileUserView = new Profile(profileID, |
|
|
@ -247,12 +236,14 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
jsonProfileInfo.getString(JSON_TAG_PROFILE_USERNAME), |
|
|
|
jsonProfileInfo.getString(JSON_TAG_PROFILE_EMAIL), |
|
|
|
restaurantsOwned, |
|
|
|
dietsFollowed); |
|
|
|
dietsFollowed, |
|
|
|
ingredientsProhibited); |
|
|
|
|
|
|
|
JSONArray jsonFoodRatings = jsonResponse.getJSONArray(JSON_TAG_FOOD_RATINGS); |
|
|
|
for (int ratingIndex = 0; ratingIndex < jsonFoodRatings.length(); ++ratingIndex) { |
|
|
|
JSONObject rating = jsonFoodRatings.getJSONObject(ratingIndex); |
|
|
|
foodRatings.add(new ItemRating(rating.getInt(JSON_TAG_FOOD_RATING_GRADE), |
|
|
|
rating.getInt(JSON_TAG_FOOD_RATING_USER_ID), |
|
|
|
rating.getString(JSON_TAG_FOOD_RATING_USERNAME), |
|
|
|
rating.getString(JSON_TAG_FOOD_RATING_TEXT), |
|
|
|
rating.getString(JSON_TAG_FOOD_RATING_DATE), |
|
|
@ -264,6 +255,7 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
for (int ratingIndex = 0; ratingIndex < jsonDrinkRatings.length(); ++ratingIndex) { |
|
|
|
JSONObject rating = jsonDrinkRatings.getJSONObject(ratingIndex); |
|
|
|
drinkRatings.add(new ItemRating(rating.getInt(JSON_TAG_DRINK_RATING_GRADE), |
|
|
|
rating.getInt(JSON_TAG_DRINK_RATING_USER_ID), |
|
|
|
rating.getString(JSON_TAG_DRINK_RATING_USERNAME), |
|
|
|
rating.getString(JSON_TAG_DRINK_RATING_TEXT), |
|
|
|
rating.getString(JSON_TAG_DRINK_RATING_DATE), |
|
|
@ -275,6 +267,7 @@ public class ProfileActivity extends BaseActivity { |
|
|
|
for (int ratingIndex = 0; ratingIndex < jsonRestaurantRatings.length(); ++ratingIndex) { |
|
|
|
JSONObject rating = jsonRestaurantRatings.getJSONObject(ratingIndex); |
|
|
|
restaurantRatings.add(new RestaurantRating(rating.getInt(JSON_TAG_RESTAURANT_RATING_GRADE), |
|
|
|
rating.getInt(JSON_TAG_RESTAURANT_RATING_USER_ID), |
|
|
|
rating.getString(JSON_TAG_RESTAURANT_RATING_USERNAME), |
|
|
|
rating.getString(JSON_TAG_RESTAURANT_RATING_TEXT), |
|
|
|
rating.getString(JSON_TAG_RESTAURANT_RATING_DATE), |
|
|
|