Browse Source

Add options for moderators, Various fixes

master
Apostolos Fanakis 6 years ago
parent
commit
c21b34f5c5
  1. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java
  2. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java
  3. 4
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java
  4. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java
  5. 4
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java
  6. 51
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java
  7. 54
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java
  8. 4
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java
  9. 32
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java
  10. 47
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/fragments/MainListFragment.java
  11. 10
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  12. 48
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java
  13. 48
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java
  14. 35
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java
  15. 13
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Diet.java
  16. 14
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java
  17. 20
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Restaurant.java
  18. 4
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/RestaurantUserView.java
  19. 14
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java
  20. 37
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main_list_row.xml
  21. 16
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml
  22. 19
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml
  23. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml
  24. 2
      UI/AndroidApp/flavoursWithoutBorders/build.gradle
  25. 3
      UI/AndroidApp/flavoursWithoutBorders/gradle/wrapper/gradle-wrapper.properties

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

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

4
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()

2
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,

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

51
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<Diet> 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<Integer, Void, Integer> {
@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) {
}
}
}

54
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<DietsAdapter.DietViewHolder> {
private ArrayList<Diet> diets;
private AcceptDietAdapterInteractionListener acceptDietAdapterInteractionListener;
private SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener;
DietsAdapter(ArrayList<Diet> diets, SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener) {
DietsAdapter(ArrayList<Diet> diets,
AcceptDietAdapterInteractionListener acceptDietAdapterInteractionListener,
SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener) {
this.diets = diets;
this.acceptDietAdapterInteractionListener = acceptDietAdapterInteractionListener;
this.subscribeDietsAdapterInteractionListener = subscribeDietsAdapterInteractionListener;
}
@ -41,6 +48,43 @@ public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHold
holder.addDietButton.setImageResource(R.drawable.ic_add_black_18dp);
}
if (!diets.get(position).isAccepted() &&
(getSessionManager().getUserType() == SessionManager.UserType.MODERATOR)) {
holder.acceptDietBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (acceptDietAdapterInteractionListener != null) {
acceptDietAdapterInteractionListener.
onAcceptDietAdapterInteraction(diets.get(holder.getAdapterPosition()));
diets.get(holder.getAdapterPosition()).setAccepted(true);
holder.acceptDietBtn.setVisibility(View.GONE);
holder.addDietButton.setVisibility(View.VISIBLE);
holder.addDietButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
subscribeDietsAdapterInteractionListener.onSubscribeDietsAdapterInteraction(
diets.get(holder.getAdapterPosition()));
if ((diets.get(position).isFollowedByUser())) {
holder.addDietButton.setImageResource(R.drawable.ic_add_black_18dp);
diets.get(position).setFollowedByUser(!diets.get(position).isFollowedByUser());
} else {
holder.addDietButton.setImageResource(R.drawable.ic_delete_black_18dp);
diets.get(position).setFollowedByUser(!diets.get(position).isFollowedByUser());
}
}
});
}
}
});
holder.acceptDietBtn.setVisibility(View.VISIBLE);
holder.addDietButton.setVisibility(View.GONE);
} else {
holder.acceptDietBtn.setVisibility(View.GONE);
holder.addDietButton.setVisibility(View.VISIBLE);
holder.addDietButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -57,6 +101,7 @@ public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHold
}
});
}
}
@Override
public int getItemCount() {
@ -65,16 +110,21 @@ public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHold
static class DietViewHolder extends RecyclerView.ViewHolder {
TextView name, description;
AppCompatImageButton addDietButton;
AppCompatImageButton acceptDietBtn, addDietButton;
DietViewHolder(View v) {
super(v);
name = v.findViewById(R.id.diets_diet_name);
description = v.findViewById(R.id.diets_diet_description);
acceptDietBtn = v.findViewById(R.id.restaurant_item_row_accept_btn);
addDietButton = v.findViewById(R.id.diets_diet_subscribe);
}
}
public interface AcceptDietAdapterInteractionListener {
void onAcceptDietAdapterInteraction(Diet diet);
}
public interface SubscribeDietsAdapterInteractionListener {
void onSubscribeDietsAdapterInteraction(Diet diet);
}

4
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java

@ -299,6 +299,7 @@ public class MainActivity 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";
@Override
protected void onPreExecute() {
@ -378,7 +379,8 @@ public class MainActivity extends BaseActivity {
jsonRestaurant.getDouble(JSON_TAG_RESTAURANT_LONGITUDE),
jsonRestaurant.getDouble(JSON_TAG_RESTAURANT_LATITUDE),
jsonRestaurant.getString(JSON_TAG_RESTAURANT_OPENING),
jsonRestaurant.getString(JSON_TAG_RESTAURANT_CLOSING)));
jsonRestaurant.getString(JSON_TAG_RESTAURANT_CLOSING),
jsonRestaurant.getBoolean(JSON_TAG_RESTAURANT_IS_ACCEPTED)));
}
return 1;
} catch (Exception e) {

32
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainAdapter.java

@ -11,21 +11,27 @@ 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.activities.restaurant.RestaurantActivity;
import gr.auth.databases.flavours.model.Restaurant;
import gr.auth.databases.flavours.session.SessionManager;
import static gr.auth.databases.flavours.activities.restaurant.RestaurantActivity.BUNDLE_ARG_RESTAURANT;
import static gr.auth.databases.flavours.base.BaseActivity.getSessionManager;
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.RestaurantViewHolder> {
private Context context;
private ArrayList<Restaurant> restaurants;
private AcceptRestaurantAdapterInteractionListener acceptRestaurantAdapterInteractionListener;
public MainAdapter(Context context, ArrayList<Restaurant> restaurants) {
public MainAdapter(Context context, ArrayList<Restaurant> restaurants,
AcceptRestaurantAdapterInteractionListener acceptRestaurantAdapterInteractionListener) {
this.context = context;
this.restaurants = restaurants;
this.acceptRestaurantAdapterInteractionListener = acceptRestaurantAdapterInteractionListener;
}
@NonNull
@ -84,6 +90,24 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.RestaurantView
holder.typeText.setText(context.getResources().getString(R.string.main_ethnic_type));
break;
}
if (!restaurants.get(position).isAccepted() &&
(getSessionManager().getUserType() == SessionManager.UserType.MODERATOR)) {
holder.acceptRestaurantBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (acceptRestaurantAdapterInteractionListener != null) {
acceptRestaurantAdapterInteractionListener.
onAcceptRestaurantAdapterInteraction(restaurants.get(holder.getAdapterPosition()));
restaurants.get(holder.getAdapterPosition()).setAccepted(true);
holder.acceptRestaurantBtn.setVisibility(View.GONE);
}
}
});
holder.acceptRestaurantBtn.setVisibility(View.VISIBLE);
} else {
holder.acceptRestaurantBtn.setVisibility(View.GONE);
}
}
@Override
@ -95,6 +119,7 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.RestaurantView
CardView card;
TextView name, typeText, workingHours;
ImageView typeImage;
AppCompatImageButton acceptRestaurantBtn;
RestaurantViewHolder(View v) {
super(v);
@ -103,6 +128,11 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.RestaurantView
typeText = v.findViewById(R.id.main_row_type_txt);
workingHours = v.findViewById(R.id.main_row_working_hours);
typeImage = v.findViewById(R.id.main_row_type_img);
acceptRestaurantBtn = v.findViewById(R.id.main_row_accept_restaurant_btn);
}
}
public interface AcceptRestaurantAdapterInteractionListener {
void onAcceptRestaurantAdapterInteraction(Restaurant restaurant);
}
}

47
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/fragments/MainListFragment.java

@ -1,5 +1,6 @@
package gr.auth.databases.flavours.activities.main.fragments;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -13,9 +14,14 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.activities.main.MainAdapter;
import gr.auth.databases.flavours.base.BaseApplication;
import gr.auth.databases.flavours.model.Restaurant;
import okhttp3.Request;
import okhttp3.RequestBody;
public class MainListFragment extends Fragment {
import static gr.auth.databases.flavours.session.SessionManager.acceptRestaurantUrl;
public class MainListFragment extends Fragment implements MainAdapter.AcceptRestaurantAdapterInteractionListener {
private static final String RESTAURANTS_TAG = "RESTAURANTS_TAG";
private ArrayList<Restaurant> 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<Integer, Void, Integer> {
@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) {
}
}
}

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

48
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<Integer, Void, Integer> {
@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) {
}
}
}

48
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<Integer, Void, Integer> {
@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) {
}
}
}

35
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<RecyclerView.ViewHolder> {
private RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener foodInteractionListener;
private RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener drinkInteractionListener;
private final ArrayList<ItemSummary> items;
private AcceptItemAdapterInteractionListener acceptItemAdapterInteractionListener;
RestaurantItemAdapter(BaseFragment.FragmentInteractionListener interactionListener,
ItemSummary.ItemType itemType, ArrayList<ItemSummary> items) {
ItemSummary.ItemType itemType, ArrayList<ItemSummary> 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<RecyclerView.Vie
}
this.items = items;
this.acceptItemAdapterInteractionListener = acceptRestaurantAdapterInteractionListener;
}
@NonNull
@ -41,7 +48,7 @@ public class RestaurantItemAdapter extends RecyclerView.Adapter<RecyclerView.Vie
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
ItemSummary item = items.get(position);
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
final ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
itemViewHolder.card.setOnClickListener(new View.OnClickListener() {
@Override
@ -61,6 +68,24 @@ public class RestaurantItemAdapter extends RecyclerView.Adapter<RecyclerView.Vie
});
itemViewHolder.item.setText(item.getItemName());
if (!items.get(position).isAccepted() &&
(getSessionManager().getUserType() == SessionManager.UserType.MODERATOR)) {
itemViewHolder.acceptItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (acceptItemAdapterInteractionListener != null) {
acceptItemAdapterInteractionListener.
onAcceptItemAdapterInteraction(items.get(holder.getAdapterPosition()));
items.get(holder.getAdapterPosition()).setAccepted(true);
itemViewHolder.acceptItem.setVisibility(View.GONE);
}
}
});
itemViewHolder.acceptItem.setVisibility(View.VISIBLE);
} else {
itemViewHolder.acceptItem.setVisibility(View.GONE);
}
}
@Override
@ -71,11 +96,17 @@ public class RestaurantItemAdapter extends RecyclerView.Adapter<RecyclerView.Vie
private static class ItemViewHolder extends RecyclerView.ViewHolder {
CardView card;
TextView item;
AppCompatImageButton acceptItem;
ItemViewHolder(View itemView) {
super(itemView);
card = itemView.findViewById(R.id.restaurant_item_row_card);
item = itemView.findViewById(R.id.restaurant_item_row_item);
acceptItem = itemView.findViewById(R.id.restaurant_item_row_accept_btn);
}
}
public interface AcceptItemAdapterInteractionListener {
void onAcceptItemAdapterInteraction(ItemSummary item);
}
}

13
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Diet.java

@ -3,13 +3,14 @@ package gr.auth.databases.flavours.model;
public class Diet {
private int id;
private String name, description;
private boolean isFollowedByUser;
private boolean isFollowedByUser, isAccepted;
public Diet(int id, String name, String description, boolean isFollowedByUser) {
public Diet(int id, String name, String description, boolean isFollowedByUser, boolean isAccepted) {
this.id = id;
this.name = name;
this.description = description;
this.isFollowedByUser = isFollowedByUser;
this.isAccepted = isAccepted;
}
public int getId() {
@ -31,4 +32,12 @@ public class Diet {
public void setFollowedByUser(boolean followedByUser) {
isFollowedByUser = followedByUser;
}
public boolean isAccepted() {
return isAccepted;
}
public void setAccepted(boolean accepted) {
isAccepted = accepted;
}
}

14
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java

@ -46,11 +46,13 @@ public class ItemSummary implements Parcelable {
private String itemName;
private int id;
private ItemType type;
private boolean isAccepted;
public ItemSummary(String item, int id, ItemType type) {
public ItemSummary(String item, int id, ItemType type, boolean isAccepted) {
this.itemName = item;
this.id = id;
this.type = type;
this.isAccepted = isAccepted;
}
public String getItemName() {
@ -65,6 +67,14 @@ public class ItemSummary implements Parcelable {
return type;
}
public boolean isAccepted() {
return isAccepted;
}
public void setAccepted(boolean accepted) {
isAccepted = accepted;
}
@Override
public int describeContents() {
return 0;
@ -75,6 +85,7 @@ public class ItemSummary implements Parcelable {
out.writeInt(id);
out.writeString(itemName);
out.writeInt(type.getId());
out.writeByte((byte) (isAccepted ? 1 : 0));
}
public static final Parcelable.Creator<ItemSummary> CREATOR = new Parcelable.Creator<ItemSummary>() {
@ -91,5 +102,6 @@ public class ItemSummary implements Parcelable {
id = in.readInt();
itemName = in.readString();
type = ItemType.getEnumTypeFromId(in.readInt());
isAccepted = in.readByte() != 0;
}
}

20
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<Restaurant> CREATOR = new Parcelable.Creator<Restaurant>() {
@ -136,5 +147,6 @@ public class Restaurant implements Parcelable {
latitude = in.readDouble();
openingTime = in.readString();
closingTime = in.readString();
isAccepted = in.readByte() != 0;
}
}

4
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<DietRatingPair> 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<DietRatingPair> averageRatingPerDiet) {
super(id, name, type, longitude, latitude, openingTime, closingTime);
super(id, name, type, longitude, latitude, openingTime, closingTime, isAccepted);
this.averageRating = averageRating;
this.averageRatingPerDiet = averageRatingPerDiet;
}

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

37
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">
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="2dp"
android:paddingTop="6dp"
android:paddingEnd="4dp"
@ -26,35 +25,45 @@
android:id="@+id/main_row_type_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/main_row_type" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="0.5"
android:orientation="vertical">
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/main_row_type"
android:src="@drawable/restaurant_marker" />
<TextView
android:id="@+id/main_row_name"
android:layout_width="match_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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" />
<TextView
android:id="@+id/main_row_working_hours"
android:layout_width="match_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main_row_name"
android:layout_toEndOf="@+id/main_row_type_img"
android:text="@string/main_row_working_hours" />
</LinearLayout>
<TextView
android:id="@+id/main_row_type_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:contentDescription="@string/main_row_type"
android:textColor="@color/colorAccent" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/main_row_accept_restaurant_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/main_row_type_img"
android:layout_alignParentEnd="true"
android:layout_gravity="end"
android:src="@drawable/ic_check_black_18dp"
android:visibility="gone" />
</RelativeLayout>
</androidx.cardview.widget.CardView>

16
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml

@ -39,11 +39,25 @@
android:ellipsize="end"
android:text="@string/diet_description" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="end"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/restaurant_item_row_accept_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_check_black_18dp"
android:visibility="gone" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/diets_diet_subscribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:src="@drawable/ic_add_black_18dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>

19
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml

@ -13,11 +13,28 @@
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="4dp"
android:paddingTop="6dp"
android:paddingEnd="4dp"
android:paddingBottom="6dp">
<TextView
android:id="@+id/restaurant_item_row_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:textColor="@color/colorAccent"
android:textSize="16sp" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/restaurant_item_row_accept_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:src="@drawable/ic_check_black_18dp"
android:visibility="gone" />
</LinearLayout>
</androidx.cardview.widget.CardView>

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

@ -16,7 +16,7 @@
<string name="sign_up_hint_birthday">Birthday</string>
<string name="sign_up_btn_sign_up">SIGN UP</string>
<string name="sign_up_btn_go_to_login">or login</string>
<string name="sign_up_birthday_placeholder">%1$d-%2$d-%3$d</string>
<string name="sign_up_birthday_placeholder">%1$d-%2$s-%3$s</string>
<!-- Drawer -->
<string name="drawer_home">Home</string>

2
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

3
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

Loading…
Cancel
Save