diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/ProfileActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/ProfileActivity.java index b1c70dc..d4a285a 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/ProfileActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/ProfileActivity.java @@ -1,12 +1,17 @@ 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; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.List; @@ -23,19 +28,42 @@ import gr.auth.databases.flavours.activities.profile.fragments.ProfileFoodRating import gr.auth.databases.flavours.activities.profile.fragments.ProfileInfoFragment; 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.ItemRating; +import gr.auth.databases.flavours.model.Profile; +import gr.auth.databases.flavours.model.RestaurantRating; +import gr.auth.databases.flavours.model.RestaurantSummary; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + +import static gr.auth.databases.flavours.session.SessionManager.profileUserViewUrl; 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; + private ArrayList drinkRatings = new ArrayList<>(); + private ArrayList foodRatings = new ArrayList<>(); + private ArrayList restaurantRatings = new ArrayList<>(); + private TabLayout tabLayout; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); + Bundle extras = getIntent().getExtras(); + assert extras != null; + profileID = extras.getInt(BUNDLE_USER_ID); + String username = extras.getString(BUNDLE_USER_NAME); + Toolbar toolbar = findViewById(R.id.profile_toolbar); - toolbar.setTitle("Username"); + toolbar.setTitle(username); setSupportActionBar(toolbar); ActionBar actionbar = getSupportActionBar(); if (actionbar != null) { @@ -69,9 +97,10 @@ public class ProfileActivity extends BaseActivity { } }); - setupViewPager(viewPager); - TabLayout tabLayout = findViewById(R.id.profile_tabs); - tabLayout.setupWithViewPager(viewPager); + tabLayout = findViewById(R.id.profile_tabs); + + ProfileTask profileTask = new ProfileTask(); + profileTask.execute(); } @Override @@ -97,10 +126,10 @@ public class ProfileActivity extends BaseActivity { private void setupViewPager(ViewPager viewPager) { RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager()); - adapter.addFrag(ProfileInfoFragment.newInstance(64), "INFO"); - adapter.addFrag(ProfileFoodRatingsFragment.newInstance(64), "FOODS"); - adapter.addFrag(ProfileDrinkRatingsFragment.newInstance(64), "DRINKS"); - adapter.addFrag(ProfileRestaurantRatingsFragment.newInstance(64), "PLACES"); + adapter.addFrag(ProfileInfoFragment.newInstance(profileUserView), "INFO"); + adapter.addFrag(ProfileFoodRatingsFragment.newInstance(foodRatings), "FOODS"); + adapter.addFrag(ProfileDrinkRatingsFragment.newInstance(drinkRatings), "DRINKS"); + adapter.addFrag(ProfileRestaurantRatingsFragment.newInstance(restaurantRatings), "PLACES"); viewPager.setAdapter(adapter); } @@ -133,4 +162,138 @@ public class ProfileActivity extends BaseActivity { return mFragmentTitleList.get(position); } } + + private class ProfileTask extends AsyncTask { + private static final String JSON_TAG_PROFILE_INFO = "userInfo"; + private static final String JSON_TAG_PROFILE_USERNAME = "username"; + private static final String JSON_TAG_PROFILE_EMAIL = "email"; + private static final String JSON_TAG_PROFILE_AGE = "age"; + private static final String JSON_TAG_PROFILE_REVIEWS_NUMBER = "reviewsNumber"; + + 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_FOOD_RATINGS = "foodRatings"; + private static final String JSON_TAG_FOOD_RATING_GRADE = "rating_grade"; + 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"; + private static final String JSON_TAG_FOOD_RATING_PORTION_SIZE = "rating_pοrtion_size"; + + 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_USERNAME = "username"; + private static final String JSON_TAG_DRINK_RATING_TEXT = "rating_text"; + private static final String JSON_TAG_DRINK_RATING_DATE = "rating_date"; + private static final String JSON_TAG_DRINK_RATING_PORTION_SIZE = "rating_pοrtion_size"; + + 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_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"; + private static final String JSON_TAG_RESTAURANT_RATING_DIET = "diet_name"; + + @Override + protected void onPreExecute() { + } + + @Override + protected Integer doInBackground(Void... params) { + String requestUrl = profileUserViewUrl + profileID + "/"; + + //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 jsonResponse = new JSONObject(result); + + JSONObject jsonProfileInfo = jsonResponse.getJSONObject(JSON_TAG_PROFILE_INFO); + + ArrayList restaurantsOwned = new ArrayList<>(); + + JSONArray jsonRestaurantsOwned = jsonProfileInfo.getJSONArray(JSON_TAG_PROFILE_RESTAURANTS_OWNED); + for (int restaurantIndex = 0; restaurantIndex < jsonRestaurantsOwned.length(); ++restaurantIndex) { + JSONObject restaurantOwned = jsonRestaurantsOwned.getJSONObject(restaurantIndex); + restaurantsOwned.add(new RestaurantSummary(restaurantOwned.getInt(JSON_TAG_PROFILE_RESTAURANT_OWNED_ID), + restaurantOwned.getString(JSON_TAG_PROFILE_RESTAURANT_OWNED_NAME))); + } + + ArrayList dietsFollowed = new ArrayList<>(); + + 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))); + } + + profileUserView = new Profile(profileID, + jsonProfileInfo.getInt(JSON_TAG_PROFILE_AGE), + jsonProfileInfo.getInt(JSON_TAG_PROFILE_REVIEWS_NUMBER), + jsonProfileInfo.getString(JSON_TAG_PROFILE_USERNAME), + jsonProfileInfo.getString(JSON_TAG_PROFILE_EMAIL), + restaurantsOwned, + dietsFollowed); + + 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.getString(JSON_TAG_FOOD_RATING_USERNAME), + rating.getString(JSON_TAG_FOOD_RATING_TEXT), + rating.getString(JSON_TAG_FOOD_RATING_DATE), + ItemRating.PortionSize.getEnumTypeFromString( + rating.getString(JSON_TAG_FOOD_RATING_PORTION_SIZE)))); + } + + JSONArray jsonDrinkRatings = jsonResponse.getJSONArray(JSON_TAG_DRINK_RATINGS); + 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.getString(JSON_TAG_DRINK_RATING_USERNAME), + rating.getString(JSON_TAG_DRINK_RATING_TEXT), + rating.getString(JSON_TAG_DRINK_RATING_DATE), + ItemRating.PortionSize.getEnumTypeFromString( + rating.getString(JSON_TAG_DRINK_RATING_PORTION_SIZE)))); + } + + JSONArray jsonRestaurantRatings = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_RATINGS); + 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.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)), + rating.getString(JSON_TAG_RESTAURANT_RATING_DIET))); + } + + return 1; + } catch (Exception e) { + e.printStackTrace(); + return 2; + } + } + + @Override + protected void onPostExecute(Integer result) { + setupViewPager(viewPager); + tabLayout.setupWithViewPager(viewPager); + } + } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileDrinkRatingsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileDrinkRatingsFragment.java index ee4ae94..81cb020 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileDrinkRatingsFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileDrinkRatingsFragment.java @@ -23,14 +23,14 @@ public class ProfileDrinkRatingsFragment extends Fragment { // Required empty public constructor } - private static final String PROFILE_ID = "PROFILE_ID"; + private static final String PROFILE_DRINK_RATINGS = "PROFILE_DRINK_RATINGS"; - private int profileId; + private ArrayList drinkRatings; - public static ProfileDrinkRatingsFragment newInstance(int profileId) { + public static ProfileDrinkRatingsFragment newInstance(ArrayList drinkRatings) { ProfileDrinkRatingsFragment fragment = new ProfileDrinkRatingsFragment(); Bundle args = new Bundle(); - args.putInt(PROFILE_ID, profileId); + args.putParcelableArrayList(PROFILE_DRINK_RATINGS, drinkRatings); fragment.setArguments(args); return fragment; } @@ -39,25 +39,16 @@ public class ProfileDrinkRatingsFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - profileId = getArguments().getInt(PROFILE_ID); + drinkRatings = getArguments().getParcelableArrayList(PROFILE_DRINK_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 ItemRating(5, "Apostolof", "Πάρα πολύ καλό!", "2018-01-04", ItemRating.PortionSize.MEDIUM)); - ratings.add(new ItemRating(5, "Apostolof", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", ItemRating.PortionSize.BIG)); - ratings.add(new ItemRating(4, "Apostolof", "-", "2018-06-08", ItemRating.PortionSize.BIG)); - ratings.add(new ItemRating(4, "Apostolof", "Μου άρεσε.", "2018-06-08", ItemRating.PortionSize.MEDIUM)); - ratings.add(new ItemRating(5, "Apostolof", "Τέλειο.", "2018-06-08", ItemRating.PortionSize.BIG)); - ratings.add(new ItemRating(2, "Apostolof", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); - ratings.add(new ItemRating(4, "Apostolof", "-", "2018-06-08", ItemRating.PortionSize.MEDIUM)); - Context context = getContext(); assert context != null; - ItemRatingsAdapter itemAdapter = new ItemRatingsAdapter(context, ratings); + ItemRatingsAdapter itemAdapter = new ItemRatingsAdapter(context, drinkRatings); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileFoodRatingsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileFoodRatingsFragment.java index fe200e6..1bb2cdc 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileFoodRatingsFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileFoodRatingsFragment.java @@ -23,14 +23,14 @@ public class ProfileFoodRatingsFragment extends Fragment { // Required empty public constructor } - private static final String PROFILE_ID = "PROFILE_ID"; + private static final String PROFILE_FOOD_RATINGS = "PROFILE_FOOD_RATINGS"; - private int profileId; + private ArrayList foodRatings; - public static ProfileFoodRatingsFragment newInstance(int profileId) { + public static ProfileFoodRatingsFragment newInstance(ArrayList foodRatings) { ProfileFoodRatingsFragment fragment = new ProfileFoodRatingsFragment(); Bundle args = new Bundle(); - args.putInt(PROFILE_ID, profileId); + args.putParcelableArrayList(PROFILE_FOOD_RATINGS, foodRatings); fragment.setArguments(args); return fragment; } @@ -39,25 +39,15 @@ public class ProfileFoodRatingsFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - profileId = getArguments().getInt(PROFILE_ID); + foodRatings = getArguments().getParcelableArrayList(PROFILE_FOOD_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 ItemRating(5, "Apostolof", "Πάρα πολύ καλό!", "2018-01-04", ItemRating.PortionSize.MEDIUM)); - ratings.add(new ItemRating(5, "Apostolof", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", ItemRating.PortionSize.BIG)); - ratings.add(new ItemRating(4, "Apostolof", "-", "2018-06-08", ItemRating.PortionSize.BIG)); - ratings.add(new ItemRating(4, "Apostolof", "Μου άρεσε.", "2018-06-08", ItemRating.PortionSize.MEDIUM)); - ratings.add(new ItemRating(5, "Apostolof", "Τέλειο.", "2018-06-08", ItemRating.PortionSize.BIG)); - ratings.add(new ItemRating(2, "Apostolof", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); - ratings.add(new ItemRating(4, "Apostolof", "-", "2018-06-08", ItemRating.PortionSize.MEDIUM)); - Context context = getContext(); assert context != null; - ItemRatingsAdapter itemAdapter = new ItemRatingsAdapter(context, ratings); + ItemRatingsAdapter itemAdapter = new ItemRatingsAdapter(context, foodRatings); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java index a3a8c1c..abd123f 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java @@ -11,6 +11,8 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageButton; import androidx.fragment.app.Fragment; import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.model.DietSummary; +import gr.auth.databases.flavours.model.Profile; public class ProfileInfoFragment extends Fragment { @@ -18,14 +20,14 @@ public class ProfileInfoFragment extends Fragment { // Required empty public constructor } - private static final String PROFILE_ID = "PROFILE_ID"; + private static final String PROFILE_INFO = "PROFILE_INFO"; - private int profileId; + private Profile profileUserView; - public static ProfileInfoFragment newInstance(int profileId) { + public static ProfileInfoFragment newInstance(Profile profileUserView) { ProfileInfoFragment fragment = new ProfileInfoFragment(); Bundle args = new Bundle(); - args.putInt(PROFILE_ID, profileId); + args.putParcelable(PROFILE_INFO, profileUserView); fragment.setArguments(args); return fragment; } @@ -34,7 +36,7 @@ public class ProfileInfoFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - profileId = getArguments().getInt(PROFILE_ID); + profileUserView = getArguments().getParcelable(PROFILE_INFO); } @Override @@ -42,35 +44,60 @@ public class ProfileInfoFragment extends Fragment { final View rootView = inflater.inflate(R.layout.fragment_profile_info, container, false); TextView email = rootView.findViewById(R.id.profile_email); - email.setText(getString(R.string.profile_email_placeholder, "apotwohd@gmail.com")); + if (!profileUserView.getEmail().equals("null")) { + email.setText(getString(R.string.profile_email_placeholder, profileUserView.getEmail())); + } else { + email.setVisibility(View.GONE); + } + TextView age = rootView.findViewById(R.id.profile_age); - age.setText(getString(R.string.profile_age_placeholder, 23)); + if (profileUserView.getAge() != -1) { + age.setText(getString(R.string.profile_age_placeholder, profileUserView.getAge())); + } else { + age.setVisibility(View.GONE); + } TextView numberOfRatings = rootView.findViewById(R.id.profile_number_of_reviews); - numberOfRatings.setText(getString(R.string.profile_number_of_reviews_placeholder, 52)); - numberOfRatings.setVisibility(View.VISIBLE); + numberOfRatings.setText(getString(R.string.profile_number_of_reviews_placeholder, profileUserView.getReviewsNumber())); + TextView ownsRestaurant = rootView.findViewById(R.id.profile_owns_restaurant); - ownsRestaurant.setText(getString(R.string.profile_owns_restaurant_placeholder, "Κανένα :(")); - ownsRestaurant.setVisibility(View.VISIBLE); - - (rootView.findViewById(R.id.profile_diets_list_title)).setVisibility(View.VISIBLE); - - LinearLayout dietsList = rootView.findViewById(R.id.profile_diets_list); - dietsList.setVisibility(View.VISIBLE); - View userDietRow = getLayoutInflater().inflate(R.layout.profile_diet_row, dietsList, false); - - TextView dietName = userDietRow.findViewById(R.id.profile_diet_name); - dietName.setText("Όγκος φυσικά"); - AppCompatImageButton removeDiet = userDietRow.findViewById(R.id.profile_diet_remove); - removeDiet.setVisibility(View.VISIBLE); - removeDiet.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - //TODO + if (!profileUserView.getRestaurantsOwned().isEmpty()) { + StringBuilder restaurantsOwned = new StringBuilder(); + for (int restaurantIndex = 0; restaurantIndex < profileUserView.getRestaurantsOwned().size(); ++restaurantIndex) { + restaurantsOwned.append(profileUserView.getRestaurantsOwned().get(restaurantIndex).getName()); + if (restaurantIndex != profileUserView.getRestaurantsOwned().size() - 1) { + restaurantsOwned.append(", "); + } + } + ownsRestaurant.setText(getString(R.string.profile_owns_restaurant_placeholder, restaurantsOwned.toString())); + ownsRestaurant.setVisibility(View.VISIBLE); + } + + if (!profileUserView.getDietsFollowed().isEmpty()) { + (rootView.findViewById(R.id.profile_diets_list_title)).setVisibility(View.VISIBLE); + + LinearLayout dietsList = rootView.findViewById(R.id.profile_diets_list); + dietsList.setVisibility(View.VISIBLE); + + for (DietSummary dietFollowed : profileUserView.getDietsFollowed()) { + View userDietRow = getLayoutInflater().inflate(R.layout.profile_diet_row, dietsList, false); + + TextView dietName = userDietRow.findViewById(R.id.profile_diet_name); + dietName.setText(dietFollowed.getName()); + + AppCompatImageButton removeDiet = userDietRow.findViewById(R.id.profile_diet_remove); + removeDiet.setVisibility(View.VISIBLE); + removeDiet.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //TODO + } + }); + + dietsList.addView(userDietRow); } - }); + } - dietsList.addView(userDietRow); return rootView; } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileRestaurantRatingsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileRestaurantRatingsFragment.java index 798ea8d..9870b03 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileRestaurantRatingsFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileRestaurantRatingsFragment.java @@ -23,14 +23,14 @@ public class ProfileRestaurantRatingsFragment extends Fragment { // Required empty public constructor } - private static final String PROFILE_ID = "PROFILE_ID"; + private static final String PROFILE_RESTAURANT_RATINGS = "PROFILE_RESTAURANT_RATINGS"; - private int profileId; + private ArrayList restaurantRatings; - public static ProfileRestaurantRatingsFragment newInstance(int profileId) { + public static ProfileRestaurantRatingsFragment newInstance(ArrayList restaurantRatings) { ProfileRestaurantRatingsFragment fragment = new ProfileRestaurantRatingsFragment(); Bundle args = new Bundle(); - args.putInt(PROFILE_ID, profileId); + args.putParcelableArrayList(PROFILE_RESTAURANT_RATINGS, restaurantRatings); fragment.setArguments(args); return fragment; } @@ -39,25 +39,15 @@ public class ProfileRestaurantRatingsFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); assert getArguments() != null; - profileId = getArguments().getInt(PROFILE_ID); + restaurantRatings = getArguments().getParcelableArrayList(PROFILE_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, "Apostolof", "Πάρα πολύ καλό!", "2018-01-04", RestaurantRating.Accessibility.MODERATE)); - ratings.add(new RestaurantRating(5, "Apostolof", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", RestaurantRating.Accessibility.EASY)); - ratings.add(new RestaurantRating(4, "Apostolof", "-", "2018-06-08", RestaurantRating.Accessibility.EASY)); - ratings.add(new RestaurantRating(4, "Apostolof", "Μου άρεσε.", "2018-06-08", RestaurantRating.Accessibility.MODERATE)); - ratings.add(new RestaurantRating(5, "Apostolof", "Τέλειο.", "2018-06-08", RestaurantRating.Accessibility.EASY)); - ratings.add(new RestaurantRating(2, "Apostolof", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null)); - ratings.add(new RestaurantRating(4, "Apostolof", "-", "2018-06-08", RestaurantRating.Accessibility.MODERATE)); - Context context = getContext(); assert context != null; - RestaurantRatingsAdapter itemAdapter = new RestaurantRatingsAdapter(context, ratings); + RestaurantRatingsAdapter itemAdapter = new RestaurantRatingsAdapter(context, restaurantRatings); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java index e39aad4..bb2d335 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java @@ -232,7 +232,7 @@ public class RestaurantActivity extends BaseActivity 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"; - + private static final String JSON_TAG_RESTAURANT_RATING_DIET = "diet_name"; @Override protected void onPreExecute() { @@ -308,7 +308,8 @@ public class RestaurantActivity extends BaseActivity rating.getString(JSON_TAG_RESTAURANT_RATING_TEXT), rating.getString(JSON_TAG_RESTAURANT_RATING_DATE), RestaurantRating.Accessibility.getEnumTypeFromString( - rating.getString(JSON_TAG_RESTAURANT_RATING_ACCESSIBILITY)))); + rating.getString(JSON_TAG_RESTAURANT_RATING_ACCESSIBILITY)), + rating.getString(JSON_TAG_RESTAURANT_RATING_DIET))); } return 1; diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java index 31632cd..ac7158f 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java @@ -37,6 +37,7 @@ import okhttp3.OkHttpClient; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static gr.auth.databases.flavours.activities.profile.ProfileActivity.BUNDLE_USER_ID; +import static gr.auth.databases.flavours.activities.profile.ProfileActivity.BUNDLE_USER_NAME; public abstract class BaseActivity extends AppCompatActivity { // Client & Cookies @@ -208,6 +209,7 @@ public abstract class BaseActivity extends AppCompatActivity { Intent intent = new Intent(BaseActivity.this, ProfileActivity.class); Bundle extras = new Bundle(); extras.putInt(BUNDLE_USER_ID, sessionManager.getUserId()); + extras.putString(BUNDLE_USER_NAME, sessionManager.getUsername()); intent.putExtras(extras); intent.setFlags(FLAG_ACTIVITY_NEW_TASK); startActivity(intent); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Profile.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Profile.java new file mode 100644 index 0000000..e10be28 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Profile.java @@ -0,0 +1,88 @@ +package gr.auth.databases.flavours.model; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; + +public class Profile implements Parcelable { + private int id, age, reviewsNumber; + private String username, email; + private ArrayList restaurantsOwned; + private ArrayList dietsFollowed; + + public Profile(int id, int age, int reviewsNumber, String username, String email, + ArrayList restaurantsOwned, ArrayList dietsFollowed) { + this.id = id; + this.age = age; + this.reviewsNumber = reviewsNumber; + this.username = username; + this.email = email; + this.restaurantsOwned = restaurantsOwned; + this.dietsFollowed = dietsFollowed; + } + + public int getId() { + return id; + } + + public int getAge() { + return age; + } + + public int getReviewsNumber() { + return reviewsNumber; + } + + public String getUsername() { + return username; + } + + public String getEmail() { + return email; + } + + public ArrayList getRestaurantsOwned() { + return restaurantsOwned; + } + + public ArrayList getDietsFollowed() { + return dietsFollowed; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(id); + out.writeInt(age); + out.writeInt(reviewsNumber); + out.writeString(username); + out.writeString(email); + out.writeList(restaurantsOwned); + out.writeList(dietsFollowed); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public Profile createFromParcel(Parcel in) { + return new Profile(in); + } + + public Profile[] newArray(int size) { + return new Profile[size]; + } + }; + + private Profile(Parcel in) { + id = in.readInt(); + age = in.readInt(); + reviewsNumber = in.readInt(); + username = in.readString(); + email = in.readString(); + restaurantsOwned = (ArrayList) in.readArrayList(DietRatingPair.class.getClassLoader()); + dietsFollowed = (ArrayList) in.readArrayList(DietRatingPair.class.getClassLoader()); + } +} 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 bd04ede..c9c25eb 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 @@ -60,19 +60,26 @@ public class RestaurantRating extends Rating { } private Accessibility accessibility; + private String diet; - public RestaurantRating(int grade, String username, String text, String date, Accessibility accessibility) { + public RestaurantRating(int grade, String username, String text, String date, Accessibility accessibility, String diet) { super(grade, username, text, date); this.accessibility = accessibility; + this.diet = diet; } public Accessibility getAccessibility() { return accessibility; } + public String getDiet() { + return diet; + } + private RestaurantRating(Parcel in) { super(in); accessibility = Accessibility.getEnumTypeFromId(in.readInt()); + diet = in.readString(); } public static final Creator CREATOR = new Creator() { @@ -91,6 +98,7 @@ public class RestaurantRating extends Rating { public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); dest.writeInt(accessibility.getId()); + dest.writeString(diet); } public int describeContents() { diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantSummary.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantSummary.java new file mode 100644 index 0000000..bc0acae --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantSummary.java @@ -0,0 +1,48 @@ +package gr.auth.databases.flavours.model; + +import android.os.Parcel; +import android.os.Parcelable; + +public class RestaurantSummary implements Parcelable { + private int id; + private String name; + + public RestaurantSummary(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(id); + out.writeString(name); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public RestaurantSummary createFromParcel(Parcel in) { + return new RestaurantSummary(in); + } + + public RestaurantSummary[] newArray(int size) { + return new RestaurantSummary[size]; + } + }; + + private RestaurantSummary(Parcel in) { + id = in.readInt(); + name = in.readString(); + } +} 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 ce9bfd9..7ac4d3f 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 @@ -59,6 +59,7 @@ public class SessionManager { public static final String rateRestaurantUrl = baseServerUrl + "api/userratesrestaurant/"; public static final String foodsUserViewUrl = baseServerUrl + "api/foodUserView/"; public static final String drinksUserViewUrl = baseServerUrl + "api/drinkUserView/"; + public static final String profileUserViewUrl = baseServerUrl + "api/profileUserView/"; // 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 ea3f1d9..2bccfb7 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 @@ -48,6 +48,14 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter + android:text="@string/profile_number_of_reviews" /> + + Restaurant average rating for diet %1$s: %2$.2f Grade = %1$d/5 Accessibility = %1$s + Diet = %1$s Grade = %1$d/5