diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java index 00f8437..99a59b7 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java @@ -169,7 +169,7 @@ public class AddDietActivity extends BaseActivity { @Override protected void onPostExecute(Integer result) { Toast.makeText(AddDietActivity.this, - "Diet was added and awaits approval!", Toast.LENGTH_SHORT).show(); + "Diet was added!", Toast.LENGTH_SHORT).show(); AddDietActivity.this.finish(); } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java index cb57982..14334fb 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java @@ -284,7 +284,7 @@ public class AddRestaurantActivity extends BaseActivity implements AdapterView.O if (response.code() == 201) { Toast.makeText(AddRestaurantActivity.this, - "Restaurant was added and awaits approval!", Toast.LENGTH_SHORT).show(); + "Restaurant was added!", Toast.LENGTH_SHORT).show(); return 0; } return 1; diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java index 7a9b24f..d97875e 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java @@ -144,7 +144,7 @@ public class RateItemActivity extends BaseActivity implements AdapterView.OnItem builder.add(REQ_RATE_FOOD_ID, "" + item.getId()) .add(REQ_RATE_ITEM_GRADE, "" + ratingGrade) .add(REQ_RATE_ITEM_DESCRIPTION, "" + ratingText.getText().toString()) - .add("user", "1") + .add("user", "" + sessionManager.getUserId()) .build(); RequestBody formBody = builder.build(); request = new Request.Builder() @@ -155,7 +155,7 @@ public class RateItemActivity extends BaseActivity implements AdapterView.OnItem builder.add(REQ_RATE_DRINK_ID, "" + item.getId()) .add(REQ_RATE_ITEM_GRADE, "" + ratingGrade) .add(REQ_RATE_ITEM_DESCRIPTION, "" + ratingText.getText().toString()) - .add("user", "1") + .add("user", "" + sessionManager.getUserId()) .build(); RequestBody formBody = builder.build(); request = new Request.Builder() diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java index 289e03c..6b6039b 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java @@ -199,7 +199,7 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView. .add(REQ_RATE_RESTAURANT_ID, "" + restaurant.getId()) .add(REQ_RATE_RESTAURANT_GRADE, "" + ratingGrade) .add(REQ_RATE_RESTAURANT_TEXT, ratingText.getText().toString()) - .add("user", "1"); + .add("user", "" + sessionManager.getUserId()); if (ratingAccessibility != null) { builder.add(REQ_RATE_RESTAURANT_ACCESSIBILITY, diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java index eb17128..6dbe11b 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java @@ -88,7 +88,9 @@ public class SignUpActivity extends BaseActivity { } public void onDateSet(DatePicker view, int year, int month, int day) { - birthdayInput.setText(getResources().getString(R.string.sign_up_birthday_placeholder, year, month + 1, day)); + birthdayInput.setText(getResources().getString(R.string.sign_up_birthday_placeholder, year, + ((month < 9) ? "0" : "") + (month + 1), + ((day < 10) ? "0" : "") + day)); } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java index 48e07fe..e0d9f5d 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java @@ -20,15 +20,19 @@ import androidx.recyclerview.widget.RecyclerView; import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.activities.AddDietActivity; import gr.auth.databases.flavours.base.BaseActivity; +import gr.auth.databases.flavours.base.BaseApplication; import gr.auth.databases.flavours.model.Diet; import gr.auth.databases.flavours.utils.FollowDietStateTask; import okhttp3.Request; +import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; +import static gr.auth.databases.flavours.session.SessionManager.acceptDietUrl; import static gr.auth.databases.flavours.session.SessionManager.dietsUserViewUrl; -public class DietsActivity extends BaseActivity implements DietsAdapter.SubscribeDietsAdapterInteractionListener { +public class DietsActivity extends BaseActivity implements + DietsAdapter.AcceptDietAdapterInteractionListener, DietsAdapter.SubscribeDietsAdapterInteractionListener { private RecyclerView recyclerView; private FloatingActionButton FAB; private ArrayList diets = new ArrayList<>(); @@ -88,6 +92,13 @@ public class DietsActivity extends BaseActivity implements DietsAdapter.Subscrib return super.onOptionsItemSelected(item); } + @Override + public void onAcceptDietAdapterInteraction(Diet diet) { + AcceptDietTask acceptDietTask = new AcceptDietTask(); + acceptDietTask.execute(diet.getId()); + diets.get(diets.indexOf(diet)).setAccepted(true); + } + @Override public void onSubscribeDietsAdapterInteraction(Diet diet) { FollowDietStateTask followDietStateTask = new FollowDietStateTask(client); @@ -99,7 +110,7 @@ public class DietsActivity extends BaseActivity implements DietsAdapter.Subscrib private static final String JSON_TAG_DIET_ID = "diet_id"; private static final String JSON_TAG_DIET_NAME = "diet_name"; private static final String JSON_TAG_DIET_DESCRIPTION = "diet_description"; - //private static final String JSON_TAG_DIET_IS_APPROVED = "food_calories"; + private static final String JSON_TAG_DIET_IS_ACCEPTED = "diet_is_approved"; private static final String JSON_TAG_USER_FOLLOWS_DIET_LIST = "followed"; private static final String JSON_TAG_USER_FOLLOWS_DIET_DIET = "diet"; @@ -137,7 +148,8 @@ public class DietsActivity extends BaseActivity implements DietsAdapter.Subscrib diets.add(new Diet(diet.getInt(JSON_TAG_DIET_ID), diet.getString(JSON_TAG_DIET_NAME), diet.getString(JSON_TAG_DIET_DESCRIPTION), - userDiets.contains(diet.getInt(JSON_TAG_DIET_ID)))); + userDiets.contains(diet.getInt(JSON_TAG_DIET_ID)), + diet.getBoolean(JSON_TAG_DIET_IS_ACCEPTED))); } return 1; } catch (Exception e) { @@ -148,8 +160,39 @@ public class DietsActivity extends BaseActivity implements DietsAdapter.Subscrib @Override protected void onPostExecute(Integer result) { - DietsAdapter dietsAdapter = new DietsAdapter(diets, DietsActivity.this); + DietsAdapter dietsAdapter = new DietsAdapter(diets, DietsActivity.this, + DietsActivity.this); recyclerView.setAdapter(dietsAdapter); } } + + private class AcceptDietTask extends AsyncTask { + @Override + protected void onPreExecute() { + } + + @Override + protected Integer doInBackground(Integer... params) { + RequestBody requestBody = RequestBody.create(null, new byte[]{}); + + //Builds the request + Request request = new Request.Builder() + .patch(requestBody) + .url(acceptDietUrl + params[0] + "/") + .build(); + + try { + //Makes request & handles response + BaseApplication.getInstance().getClient().newCall(request).execute(); + return 0; + } catch (Exception e) { + e.printStackTrace(); + return 2; + } + } + + @Override + protected void onPostExecute(Integer result) { + } + } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java index 18579ca..cf83af6 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java @@ -12,13 +12,20 @@ import androidx.appcompat.widget.AppCompatImageButton; import androidx.recyclerview.widget.RecyclerView; import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.model.Diet; +import gr.auth.databases.flavours.session.SessionManager; + +import static gr.auth.databases.flavours.base.BaseActivity.getSessionManager; public class DietsAdapter extends RecyclerView.Adapter { private ArrayList diets; + private AcceptDietAdapterInteractionListener acceptDietAdapterInteractionListener; private SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener; - DietsAdapter(ArrayList diets, SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener) { + DietsAdapter(ArrayList diets, + AcceptDietAdapterInteractionListener acceptDietAdapterInteractionListener, + SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener) { this.diets = diets; + this.acceptDietAdapterInteractionListener = acceptDietAdapterInteractionListener; this.subscribeDietsAdapterInteractionListener = subscribeDietsAdapterInteractionListener; } @@ -41,21 +48,59 @@ public class DietsAdapter extends RecyclerView.Adapter { private Context context; private ArrayList restaurants; + private AcceptRestaurantAdapterInteractionListener acceptRestaurantAdapterInteractionListener; - public MainAdapter(Context context, ArrayList restaurants) { + public MainAdapter(Context context, ArrayList restaurants, + AcceptRestaurantAdapterInteractionListener acceptRestaurantAdapterInteractionListener) { this.context = context; this.restaurants = restaurants; + this.acceptRestaurantAdapterInteractionListener = acceptRestaurantAdapterInteractionListener; } @NonNull @@ -84,6 +90,24 @@ public class MainAdapter extends RecyclerView.Adapter restaurants; @@ -44,9 +50,46 @@ public class MainListFragment extends Fragment { LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(layoutManager); - MainAdapter mainAdapter = new MainAdapter(getContext(), restaurants); + MainAdapter mainAdapter = new MainAdapter(getContext(), restaurants, this); recyclerView.setAdapter(mainAdapter); return rootView; } + + @Override + public void onAcceptRestaurantAdapterInteraction(Restaurant restaurant) { + AcceptRestaurantTask acceptRestaurantTask = new AcceptRestaurantTask(); + acceptRestaurantTask.execute(restaurant.getId()); + restaurants.get(restaurants.indexOf(restaurant)).setAccepted(true); + } + + private class AcceptRestaurantTask extends AsyncTask { + @Override + protected void onPreExecute() { + } + + @Override + protected Integer doInBackground(Integer... params) { + RequestBody requestBody = RequestBody.create(null, new byte[]{}); + + //Builds the request + Request request = new Request.Builder() + .patch(requestBody) + .url(acceptRestaurantUrl + params[0] + "/") + .build(); + + try { + //Makes request & handles response + BaseApplication.getInstance().getClient().newCall(request).execute(); + return 0; + } catch (Exception e) { + e.printStackTrace(); + return 2; + } + } + + @Override + protected void onPostExecute(Integer result) { + } + } } 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 f94c393..5ed2b2b 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 @@ -213,6 +213,7 @@ public class RestaurantActivity extends BaseActivity private static final String JSON_TAG_RESTAURANT_LATITUDE = "restaurant_latitude"; private static final String JSON_TAG_RESTAURANT_OPENING = "restaurant_opening"; private static final String JSON_TAG_RESTAURANT_CLOSING = "restaurant_closing"; + private static final String JSON_TAG_RESTAURANT_IS_ACCEPTED = "restaurant_is_approved"; private static final String JSON_TAG_RESTAURANT_AVG_RATING_OBJ = "averageRating"; private static final String JSON_TAG_RESTAURANT_AVG_RATING = "rating_grade__avg"; @@ -223,10 +224,12 @@ public class RestaurantActivity extends BaseActivity private static final String JSON_TAG_RESTAURANT_FOODS = "foods"; private static final String JSON_TAG_RESTAURANT_FOOD_ID = "food_id"; private static final String JSON_TAG_RESTAURANT_FOOD_NAME = "food_name"; + private static final String JSON_TAG_RESTAURANT_FOOD_IS_ACCEPTED = "food_is_approved"; private static final String JSON_TAG_RESTAURANT_DRINKS = "drinks"; private static final String JSON_TAG_RESTAURANT_DRINK_ID = "drink_id"; private static final String JSON_TAG_RESTAURANT_DRINK_NAME = "drink_name"; + private static final String JSON_TAG_RESTAURANT_DRINK_IS_ACCEPTED = "drink_is_approved"; private static final String JSON_TAG_RESTAURANT_RATINGS = "ratings"; private static final String JSON_TAG_RESTAURANT_RATING_GRADE = "rating_grade"; @@ -284,6 +287,7 @@ public class RestaurantActivity extends BaseActivity jsonRestaurantInfo.getDouble(JSON_TAG_RESTAURANT_LATITUDE), jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_OPENING), jsonRestaurantInfo.getString(JSON_TAG_RESTAURANT_CLOSING), + jsonRestaurantInfo.getBoolean(JSON_TAG_RESTAURANT_IS_ACCEPTED), avgRestaurantRating, ratingsPerDiet); @@ -292,7 +296,8 @@ public class RestaurantActivity extends BaseActivity JSONObject food = jsonFoods.getJSONObject(foodIndex); foods.add(new ItemSummary(food.getString(JSON_TAG_RESTAURANT_FOOD_NAME), food.getInt(JSON_TAG_RESTAURANT_FOOD_ID), - ItemSummary.ItemType.FOOD)); + ItemSummary.ItemType.FOOD, + food.getBoolean(JSON_TAG_RESTAURANT_FOOD_IS_ACCEPTED))); } JSONArray jsonDrinks = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_DRINKS); @@ -300,7 +305,8 @@ public class RestaurantActivity extends BaseActivity JSONObject drink = jsonDrinks.getJSONObject(drinkIndex); drinks.add(new ItemSummary(drink.getString(JSON_TAG_RESTAURANT_DRINK_NAME), drink.getInt(JSON_TAG_RESTAURANT_DRINK_ID), - ItemSummary.ItemType.DRINK)); + ItemSummary.ItemType.DRINK, + drink.getBoolean(JSON_TAG_RESTAURANT_DRINK_IS_ACCEPTED))); } JSONArray jsonRatings = jsonResponse.getJSONArray(JSON_TAG_RESTAURANT_RATINGS); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java index 1bca874..f5a1db2 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java @@ -1,5 +1,6 @@ package gr.auth.databases.flavours.activities.restaurant.fragments; +import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -11,10 +12,16 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.base.BaseApplication; import gr.auth.databases.flavours.base.BaseFragment; import gr.auth.databases.flavours.model.ItemSummary; +import okhttp3.Request; +import okhttp3.RequestBody; -public class RestaurantDrinksFragment extends BaseFragment { +import static gr.auth.databases.flavours.session.SessionManager.acceptDrinkUrl; + +public class RestaurantDrinksFragment extends BaseFragment implements + RestaurantItemAdapter.AcceptItemAdapterInteractionListener { public RestaurantDrinksFragment() { // Required empty public constructor @@ -43,7 +50,7 @@ public class RestaurantDrinksFragment extends BaseFragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false); RestaurantItemAdapter itemAdapter = new RestaurantItemAdapter(fragmentInteractionListener, - ItemSummary.ItemType.DRINK, drinks); + ItemSummary.ItemType.DRINK, drinks, this); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); @@ -52,7 +59,44 @@ public class RestaurantDrinksFragment extends BaseFragment { return rootView; } + @Override + public void onAcceptItemAdapterInteraction(ItemSummary item) { + AcceptItemTask acceptItemTask = new AcceptItemTask(); + acceptItemTask.execute(item.getId()); + drinks.get(drinks.indexOf(item)).setAccepted(true); + } + public interface RestaurantDrinksFragmentInteractionListener extends FragmentInteractionListener { void onRestaurantDrinksFragmentInteraction(ItemSummary foodSummary); } + + private class AcceptItemTask extends AsyncTask { + @Override + protected void onPreExecute() { + } + + @Override + protected Integer doInBackground(Integer... params) { + RequestBody requestBody = RequestBody.create(null, new byte[]{}); + + //Builds the request + Request request = new Request.Builder() + .patch(requestBody) + .url(acceptDrinkUrl + params[0] + "/") + .build(); + + try { + //Makes request & handles response + BaseApplication.getInstance().getClient().newCall(request).execute(); + return 0; + } catch (Exception e) { + e.printStackTrace(); + return 2; + } + } + + @Override + protected void onPostExecute(Integer result) { + } + } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java index 0a2807a..4c5bd18 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java @@ -1,5 +1,6 @@ package gr.auth.databases.flavours.activities.restaurant.fragments; +import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -11,10 +12,16 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.base.BaseApplication; import gr.auth.databases.flavours.base.BaseFragment; import gr.auth.databases.flavours.model.ItemSummary; +import okhttp3.Request; +import okhttp3.RequestBody; -public class RestaurantFoodsFragment extends BaseFragment { +import static gr.auth.databases.flavours.session.SessionManager.acceptFoodUrl; + +public class RestaurantFoodsFragment extends BaseFragment implements + RestaurantItemAdapter.AcceptItemAdapterInteractionListener { public RestaurantFoodsFragment() { // Required empty public constructor @@ -43,7 +50,7 @@ public class RestaurantFoodsFragment extends BaseFragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false); RestaurantItemAdapter itemAdapter = new RestaurantItemAdapter(fragmentInteractionListener, - ItemSummary.ItemType.FOOD, foods); + ItemSummary.ItemType.FOOD, foods, this); RecyclerView mainContent = rootView.findViewById(R.id.recycler_list); mainContent.setAdapter(itemAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); @@ -52,7 +59,44 @@ public class RestaurantFoodsFragment extends BaseFragment { return rootView; } + @Override + public void onAcceptItemAdapterInteraction(ItemSummary item) { + AcceptItemTask acceptItemTask = new AcceptItemTask(); + acceptItemTask.execute(item.getId()); + foods.get(foods.indexOf(item)).setAccepted(true); + } + public interface RestaurantFoodsFragmentInteractionListener extends FragmentInteractionListener { void onRestaurantFoodsFragmentInteraction(ItemSummary foodSummary); } + + private class AcceptItemTask extends AsyncTask { + @Override + protected void onPreExecute() { + } + + @Override + protected Integer doInBackground(Integer... params) { + RequestBody requestBody = RequestBody.create(null, new byte[]{}); + + //Builds the request + Request request = new Request.Builder() + .patch(requestBody) + .url(acceptFoodUrl + params[0] + "/") + .build(); + + try { + //Makes request & handles response + BaseApplication.getInstance().getClient().newCall(request).execute(); + return 0; + } catch (Exception e) { + e.printStackTrace(); + return 2; + } + } + + @Override + protected void onPostExecute(Integer result) { + } + } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java index de1bacd..17fb134 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java @@ -8,19 +8,25 @@ import android.widget.TextView; import java.util.ArrayList; import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageButton; import androidx.cardview.widget.CardView; import androidx.recyclerview.widget.RecyclerView; import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.base.BaseFragment; import gr.auth.databases.flavours.model.ItemSummary; +import gr.auth.databases.flavours.session.SessionManager; + +import static gr.auth.databases.flavours.base.BaseActivity.getSessionManager; public class RestaurantItemAdapter extends RecyclerView.Adapter { private RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener foodInteractionListener; private RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener drinkInteractionListener; private final ArrayList items; + private AcceptItemAdapterInteractionListener acceptItemAdapterInteractionListener; RestaurantItemAdapter(BaseFragment.FragmentInteractionListener interactionListener, - ItemSummary.ItemType itemType, ArrayList items) { + ItemSummary.ItemType itemType, ArrayList items, + AcceptItemAdapterInteractionListener acceptRestaurantAdapterInteractionListener) { if (itemType == ItemSummary.ItemType.FOOD) { this.foodInteractionListener = (RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener) interactionListener; } else if (itemType == ItemSummary.ItemType.DRINK) { @@ -28,6 +34,7 @@ public class RestaurantItemAdapter extends RecyclerView.Adapter CREATOR = new Parcelable.Creator() { @@ -91,5 +102,6 @@ public class ItemSummary implements Parcelable { id = in.readInt(); itemName = in.readString(); type = ItemType.getEnumTypeFromId(in.readInt()); + isAccepted = in.readByte() != 0; } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java index add4501..d046968 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java @@ -59,12 +59,13 @@ public class Restaurant implements Parcelable { } } - private final int id; - private final String name, type, openingTime, closingTime; - private final double longitude, latitude; + private int id; + private String name, type, openingTime, closingTime; + private double longitude, latitude; + private boolean isAccepted; public Restaurant(int id, String name, String type, double longitude, double latitude, - String openingTime, String closingTime) { + String openingTime, String closingTime, boolean isAccepted) { this.id = id; this.name = name; this.type = type; @@ -72,6 +73,7 @@ public class Restaurant implements Parcelable { this.latitude = latitude; this.openingTime = openingTime; this.closingTime = closingTime; + this.isAccepted = isAccepted; } public int getId() { @@ -102,6 +104,14 @@ public class Restaurant implements Parcelable { return closingTime; } + public boolean isAccepted() { + return isAccepted; + } + + public void setAccepted(boolean accepted) { + isAccepted = accepted; + } + @Override public int describeContents() { return 0; @@ -116,6 +126,7 @@ public class Restaurant implements Parcelable { out.writeDouble(latitude); out.writeString(openingTime); out.writeString(closingTime); + out.writeByte((byte) (isAccepted ? 1 : 0)); } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @@ -136,5 +147,6 @@ public class Restaurant implements Parcelable { latitude = in.readDouble(); openingTime = in.readString(); closingTime = in.readString(); + isAccepted = in.readByte() != 0; } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java index 5d86186..988d31e 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java @@ -9,9 +9,9 @@ public class RestaurantUserView extends Restaurant { private ArrayList averageRatingPerDiet; public RestaurantUserView(int id, String name, String type, double longitude, double latitude, - String openingTime, String closingTime, double averageRating, + String openingTime, String closingTime, boolean isAccepted, double averageRating, ArrayList averageRatingPerDiet) { - super(id, name, type, longitude, latitude, openingTime, closingTime); + super(id, name, type, longitude, latitude, openingTime, closingTime, isAccepted); this.averageRating = averageRating; this.averageRatingPerDiet = averageRatingPerDiet; } 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 a851e4d..e23b7e1 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 @@ -48,11 +48,11 @@ public class SessionManager { } //Generic constants - public static final String baseServerUrl = "http://83.212.109.171:8181/"; - public static final String loginUrl = baseServerUrl + "api/rest-auth/login/"; - public static final String signupUrl = baseServerUrl + "api/rest-auth/registration/"; - public static final String logoutUrl = baseServerUrl + "api/rest-auth/logout/"; - public static final String setUserBirthday = baseServerUrl + "api/setUserBirthday/"; + private static final String baseServerUrl = "http://83.212.109.171:8181/"; + private static final String loginUrl = baseServerUrl + "api/rest-auth/login/"; + private static final String signupUrl = baseServerUrl + "api/rest-auth/registration/"; + private static final String logoutUrl = baseServerUrl + "api/rest-auth/logout/"; + private static final String setUserBirthday = baseServerUrl + "api/setUserBirthday/"; public static final String restaurantsUrl = baseServerUrl + "api/restaurant/"; public static final String restaurantsUserViewUrl = baseServerUrl + "api/restaurantUserView/"; public static final String getUserDietsUrl = baseServerUrl + "api/userDiets/"; @@ -72,6 +72,10 @@ public class SessionManager { public static final String addDietUrl = baseServerUrl + "api/addDiet/"; public static final String addIngredientToFoodUrl = baseServerUrl + "api/foodhasingredient/"; public static final String addIngredientToDrinkUrl = baseServerUrl + "api/drinkhasingredient/"; + public static final String acceptRestaurantUrl = baseServerUrl + "api/acceptRestaurant/"; + public static final String acceptFoodUrl = baseServerUrl + "api/acceptFood/"; + public static final String acceptDrinkUrl = baseServerUrl + "api/acceptDrink/"; + public static final String acceptDietUrl = baseServerUrl + "api/acceptDiet/"; // Client & Cookies private final OkHttpClient client; diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main_list_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main_list_row.xml index 6cc4bd1..8638489 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main_list_row.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main_list_row.xml @@ -13,10 +13,9 @@ card_view:cardPreventCornerOverlap="false" card_view:cardUseCompatPadding="true"> - + android:layout_alignParentStart="true" + android:layout_alignParentTop="true" + android:contentDescription="@string/main_row_type" + android:src="@drawable/restaurant_marker" /> - + android:layout_toStartOf="@+id/main_row_type_txt" + android:layout_toEndOf="@+id/main_row_type_img" + android:ellipsize="end" + android:text="@string/main_row_name" + android:textStyle="bold" /> - - - - + - + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml index 07f8f82..fc4f124 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml @@ -39,11 +39,25 @@ android:ellipsize="end" android:text="@string/diet_description" /> - + android:gravity="end" + android:orientation="horizontal"> + + + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml index bc1b424..9452339 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml @@ -13,11 +13,28 @@ card_view:cardPreventCornerOverlap="false" card_view:cardUseCompatPadding="true"> - + android:orientation="vertical" + android:paddingStart="4dp" + android:paddingTop="6dp" + android:paddingEnd="4dp" + android:paddingBottom="6dp"> + + + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml index b8e05e2..af38613 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml @@ -16,7 +16,7 @@ Birthday SIGN UP or login - %1$d-%2$d-%3$d + %1$d-%2$s-%3$s Home diff --git a/UI/AndroidApp/flavoursWithoutBorders/build.gradle b/UI/AndroidApp/flavoursWithoutBorders/build.gradle index c935b4f..7bbf478 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/build.gradle +++ b/UI/AndroidApp/flavoursWithoutBorders/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.3.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/UI/AndroidApp/flavoursWithoutBorders/gradle/wrapper/gradle-wrapper.properties b/UI/AndroidApp/flavoursWithoutBorders/gradle/wrapper/gradle-wrapper.properties index 9a4163a..5e8a8ed 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/gradle/wrapper/gradle-wrapper.properties +++ b/UI/AndroidApp/flavoursWithoutBorders/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Jan 14 20:35:57 EET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip