Browse Source

API connection for profile view, Minor fixes

master
Apostolos Fanakis 6 years ago
parent
commit
feb3385b7a
  1. 179
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/ProfileActivity.java
  2. 21
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileDrinkRatingsFragment.java
  3. 22
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileFoodRatingsFragment.java
  4. 83
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java
  5. 22
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileRestaurantRatingsFragment.java
  6. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  7. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java
  8. 88
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Profile.java
  9. 10
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantRating.java
  10. 48
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantSummary.java
  11. 1
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java
  12. 11
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/RestaurantRatingsAdapter.java
  13. 3
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_profile_info.xml
  14. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_rating_row.xml
  15. 1
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

179
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<ItemRating> drinkRatings = new ArrayList<>();
private ArrayList<ItemRating> foodRatings = new ArrayList<>();
private ArrayList<RestaurantRating> 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<Void, Void, Integer> {
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<RestaurantSummary> 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<DietSummary> 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);
}
}
}

21
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<ItemRating> drinkRatings;
public static ProfileDrinkRatingsFragment newInstance(int profileId) {
public static ProfileDrinkRatingsFragment newInstance(ArrayList<ItemRating> 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<ItemRating> 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());

22
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<ItemRating> foodRatings;
public static ProfileFoodRatingsFragment newInstance(int profileId) {
public static ProfileFoodRatingsFragment newInstance(ArrayList<ItemRating> 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<ItemRating> 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());

83
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;
}
}

22
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<RestaurantRating> restaurantRatings;
public static ProfileRestaurantRatingsFragment newInstance(int profileId) {
public static ProfileRestaurantRatingsFragment newInstance(ArrayList<RestaurantRating> 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<RestaurantRating> 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());

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

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

88
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<RestaurantSummary> restaurantsOwned;
private ArrayList<DietSummary> dietsFollowed;
public Profile(int id, int age, int reviewsNumber, String username, String email,
ArrayList<RestaurantSummary> restaurantsOwned, ArrayList<DietSummary> 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<RestaurantSummary> getRestaurantsOwned() {
return restaurantsOwned;
}
public ArrayList<DietSummary> 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<Profile> CREATOR = new Parcelable.Creator<Profile>() {
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<RestaurantSummary>) in.readArrayList(DietRatingPair.class.getClassLoader());
dietsFollowed = (ArrayList<DietSummary>) in.readArrayList(DietRatingPair.class.getClassLoader());
}
}

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

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

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

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

@ -48,6 +48,14 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter<RestaurantRat
holder.accessibility.setVisibility(View.GONE);
}
if (!ratings.get(position).getDiet().equals("null")) {
holder.diet.setVisibility(View.VISIBLE);
holder.diet.setText(context.getString(R.string.restaurant_ratings_row_diet_placeholder,
ratings.get(position).getDiet()));
} else {
holder.diet.setVisibility(View.GONE);
}
if (!ratings.get(position).getText().equals("null")) {
holder.text.setVisibility(View.VISIBLE);
holder.text.setText(ratings.get(position).getText());
@ -63,7 +71,7 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter<RestaurantRat
}
static class RatingViewHolder extends RecyclerView.ViewHolder {
TextView username, date, grade, accessibility, text;
TextView username, date, grade, accessibility, diet, text;
RatingViewHolder(View v) {
super(v);
@ -71,6 +79,7 @@ public class RestaurantRatingsAdapter extends RecyclerView.Adapter<RestaurantRat
date = v.findViewById(R.id.restaurant_rating_date);
grade = v.findViewById(R.id.restaurant_rating_grade);
accessibility = v.findViewById(R.id.restaurant_rating_accessibility);
diet = v.findViewById(R.id.restaurant_rating_diet);
text = v.findViewById(R.id.restaurant_rating_text);
}
}

3
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_profile_info.xml

@ -26,8 +26,7 @@
android:id="@+id/profile_number_of_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profile_number_of_reviews"
android:visibility="gone" />
android:text="@string/profile_number_of_reviews" />
<TextView
android:id="@+id/profile_owns_restaurant"

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_rating_row.xml

@ -30,6 +30,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/restaurant_rating_diet"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/restaurant_rating_text"
android:layout_width="match_parent"

1
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

@ -59,6 +59,7 @@
<string name="restaurant_diet_average_rating">Restaurant average rating for diet %1$s: %2$.2f</string>
<string name="restaurant_ratings_row_grade_placeholder">Grade = %1$d/5</string>
<string name="restaurant_ratings_row_accessibility_placeholder">Accessibility = %1$s</string>
<string name="restaurant_ratings_row_diet_placeholder">Diet = %1$s</string>
<!-- Item -->
<string name="item_ratings_row_grade_placeholder">Grade = %1$d/5</string>

Loading…
Cancel
Save