Browse Source

Add API connection for diet following, ingredient prohibition and item ratings

master
Apostolos Fanakis 6 years ago
parent
commit
c8e76cce5c
  1. 82
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java
  2. 54
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddIngredientActivity.java
  3. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java
  4. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java
  5. 6
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/LoginActivity.java
  6. 89
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java
  7. 7
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java
  8. 4
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java
  9. 35
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java
  10. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java
  11. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java
  12. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java
  13. 12
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java
  14. 1
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  15. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java
  16. 45
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/FollowDietStateTask.java
  17. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

82
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java

@ -1,5 +1,6 @@
package gr.auth.databases.flavours.activities; package gr.auth.databases.flavours.activities;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MenuItem; import android.view.MenuItem;
@ -8,6 +9,7 @@ import android.view.inputmethod.EditorInfo;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
@ -17,10 +19,15 @@ import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.IngredientSummary; import gr.auth.databases.flavours.model.Ingredient;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import static gr.auth.databases.flavours.session.SessionManager.addDietUrl;
public class AddDietActivity extends BaseActivity { public class AddDietActivity extends BaseActivity {
private ArrayList<IngredientSummary> ingredients = new ArrayList<>(); private ArrayList<Ingredient> ingredients = new ArrayList<>();
private EditText dietNameInput, dietDescriptionInput; private EditText dietNameInput, dietDescriptionInput;
@Override @Override
@ -37,7 +44,8 @@ public class AddDietActivity extends BaseActivity {
} }
dietNameInput = findViewById(R.id.add_diet_name); dietNameInput = findViewById(R.id.add_diet_name);
AppCompatButton addItemButton = findViewById(R.id.add_diet_add_btn); dietDescriptionInput = findViewById(R.id.add_diet_description);
AppCompatButton addDietButton = findViewById(R.id.add_diet_add_btn);
final TextView ingredientsTitle = findViewById(R.id.add_diet_add_ingredient_title); final TextView ingredientsTitle = findViewById(R.id.add_diet_add_ingredient_title);
final EditText addIngredientInput = findViewById(R.id.add_diet_add_ingredient); final EditText addIngredientInput = findViewById(R.id.add_diet_add_ingredient);
final LinearLayout ingredientsList = findViewById(R.id.add_diet_ingredients_list); final LinearLayout ingredientsList = findViewById(R.id.add_diet_ingredients_list);
@ -46,13 +54,21 @@ public class AddDietActivity extends BaseActivity {
@Override @Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE) { if (actionId == EditorInfo.IME_ACTION_DONE) {
ingredients.add(new IngredientSummary( final Ingredient newIngredient = new Ingredient(addIngredientInput.getText().toString(), false);
addIngredientInput.getText().toString())); ingredients.add(newIngredient);
View ingredientRow = getLayoutInflater().inflate(R.layout.add_item_ingredient_row, ingredientsList, false); View ingredientRow = getLayoutInflater().inflate(R.layout.add_item_ingredient_row, ingredientsList, false);
TextView ingredientName = ingredientRow.findViewById(R.id.add_item_ingredient_name); TextView ingredientName = ingredientRow.findViewById(R.id.add_item_ingredient_name);
ingredientName.setText(ingredients.get(ingredients.size() - 1).getName()); ingredientName.setText(ingredients.get(ingredients.size() - 1).getName());
ingredientRow.findViewById(R.id.add_item_ingredient_has_alcohol).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ingredients.get(ingredients.indexOf(newIngredient)).
setHasAlcohol(!ingredients.get(ingredients.indexOf(newIngredient)).hasAlcohol());
}
});
AppCompatImageButton removeIngredientBtn = ingredientRow.findViewById(R.id.add_item_remove_ingredient); AppCompatImageButton removeIngredientBtn = ingredientRow.findViewById(R.id.add_item_remove_ingredient);
removeIngredientBtn.setOnClickListener(new View.OnClickListener() { removeIngredientBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -74,10 +90,11 @@ public class AddDietActivity extends BaseActivity {
} }
}); });
addItemButton.setOnClickListener(new View.OnClickListener() { addDietButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//TODO AddDietTask addDietTask = new AddDietTask();
addDietTask.execute();
} }
}); });
@ -105,4 +122,55 @@ public class AddDietActivity extends BaseActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private class AddDietTask extends AsyncTask<Void, Void, Integer> {
private static final String REQ_DIET_NAME = "diet_name";
private static final String REQ_DIET_DESCRIPTION = "diet_description";
private static final String REQ_DIET_PROHIBITS_INGREDIENTS_LIST = "ingredients";
@Override
protected void onPreExecute() {
}
@Override
protected Integer doInBackground(Void... params) {
StringBuilder ingredientsJson = new StringBuilder("[");
for (int ingredientIndex = 0; ingredientIndex < ingredients.size(); ++ingredientIndex) {
Ingredient ingredient = ingredients.get(ingredientIndex);
ingredientsJson.append("{\"ingredient_name\": \"").append(ingredient.getName())
.append("\", \"ingredient_has_alcohol\": \"").append(ingredient.hasAlcohol())
.append("\"}");
if (ingredientIndex < ingredients.size() - 1) {
ingredientsJson.append(",");
}
}
ingredientsJson.append("]");
//Builds the request
RequestBody formBody = new FormBody.Builder()
.add(REQ_DIET_NAME, dietNameInput.getText().toString())
.add(REQ_DIET_DESCRIPTION, dietDescriptionInput.getText().toString())
.add(REQ_DIET_PROHIBITS_INGREDIENTS_LIST, ingredientsJson.toString())
.build();
Request request = new Request.Builder()
.url(addDietUrl)
.post(formBody)
.build();
try {
client.newCall(request).execute();
return 0;
} catch (Exception e) {
return 2;
}
}
@Override
protected void onPostExecute(Integer result) {
Toast.makeText(AddDietActivity.this,
"Diet was added and awaits approval!", Toast.LENGTH_SHORT).show();
AddDietActivity.this.finish();
}
}
} }

54
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddIngredientActivity.java

@ -2,6 +2,7 @@ package gr.auth.databases.flavours.activities;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -15,6 +16,11 @@ import androidx.appcompat.widget.Toolbar;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.Ingredient; import gr.auth.databases.flavours.model.Ingredient;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import static gr.auth.databases.flavours.session.SessionManager.addIngredientUrl;
public class AddIngredientActivity extends BaseActivity { public class AddIngredientActivity extends BaseActivity {
public static final String INGREDIENT_ADD_RESULT = "INGREDIENT_ADD_RESULT"; public static final String INGREDIENT_ADD_RESULT = "INGREDIENT_ADD_RESULT";
@ -57,6 +63,9 @@ public class AddIngredientActivity extends BaseActivity {
return; return;
} }
AddIngredientTask addIngredientTask = new AddIngredientTask();
addIngredientTask.execute();
Intent returnIntent = new Intent(); Intent returnIntent = new Intent();
returnIntent.putExtra(INGREDIENT_ADD_RESULT, new Ingredient(ingredientNameInput.getText().toString(), returnIntent.putExtra(INGREDIENT_ADD_RESULT, new Ingredient(ingredientNameInput.getText().toString(),
hasAlcoholResult == 1)); hasAlcoholResult == 1));
@ -89,4 +98,49 @@ public class AddIngredientActivity extends BaseActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private class AddIngredientTask extends AsyncTask<Void, Void, Integer> {
private static final String REQ_INGREDIENT_NAME = "ingredient_name";
private static final String REQ_INGREDIENT_HAS_ALCOHOL = "ingredient_has_alcohol";
@Override
protected void onPreExecute() {
}
@Override
protected Integer doInBackground(Void... params) {
int hasAlcoholResult = -1;
switch (ingredientHasAlcoholInput.getCheckedRadioButtonId()) {
case R.id.add_ingredient_has_alcohol_yes:
hasAlcoholResult = 1;
break;
case R.id.add_ingredient_has_alcohol_no:
hasAlcoholResult = 0;
break;
}
//Builds the request
RequestBody formBody = new FormBody.Builder()
.add(REQ_INGREDIENT_NAME, ingredientNameInput.getText().toString())
.add(REQ_INGREDIENT_HAS_ALCOHOL, hasAlcoholResult == 1 ? "True" : "False")
.build();
Request request = new Request.Builder()
.url(addIngredientUrl)
.post(formBody)
.build();
try {
client.newCall(request).execute();
return 0;
} catch (Exception e) {
return 2;
}
}
@Override
protected void onPostExecute(Integer result) {
Toast.makeText(AddIngredientActivity.this,
"Ingredient was added!", Toast.LENGTH_SHORT).show();
}
}
} }

2
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java

@ -51,7 +51,6 @@ public class AddItemActivity extends BaseActivity {
itemType = (ItemSummary.ItemType) extras.getSerializable(BUNDLE_ADD_ITEM_ITEM_TYPE); itemType = (ItemSummary.ItemType) extras.getSerializable(BUNDLE_ADD_ITEM_ITEM_TYPE);
restaurantId = extras.getInt(BUNDLE_ADD_ITEM_ITEM_RESTAURANT_ID); restaurantId = extras.getInt(BUNDLE_ADD_ITEM_ITEM_RESTAURANT_ID);
Toolbar toolbar = findViewById(R.id.add_item_toolbar); Toolbar toolbar = findViewById(R.id.add_item_toolbar);
if (itemType == ItemSummary.ItemType.FOOD) { if (itemType == ItemSummary.ItemType.FOOD) {
toolbar.setTitle(getString(R.string.add_item_toolbar_title_food)); toolbar.setTitle(getString(R.string.add_item_toolbar_title_food));
@ -214,7 +213,6 @@ public class AddItemActivity extends BaseActivity {
//Makes request & handles response //Makes request & handles response
client.newCall(request).execute(); client.newCall(request).execute();
return 0; return 0;
} catch (Exception e) { } catch (Exception e) {

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java

@ -260,7 +260,7 @@ public class AddRestaurantActivity extends BaseActivity implements AdapterView.O
private static final String REQ_RESTAURANT_CLOSING = "restaurant_closing"; private static final String REQ_RESTAURANT_CLOSING = "restaurant_closing";
@Override @Override
protected void onPreExecute() { //Show a progress dialog until done protected void onPreExecute() {
} }
@Override @Override
@ -280,7 +280,6 @@ public class AddRestaurantActivity extends BaseActivity implements AdapterView.O
.build(); .build();
try { try {
//Makes request & handles response
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
if (response.code() == 201) { if (response.code() == 201) {
@ -295,7 +294,7 @@ public class AddRestaurantActivity extends BaseActivity implements AdapterView.O
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
} }
} }
} }

6
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/LoginActivity.java

@ -53,7 +53,7 @@ public class LoginActivity extends BaseActivity {
private class LoginTask extends AsyncTask<String, Void, Integer> { private class LoginTask extends AsyncTask<String, Void, Integer> {
@Override @Override
protected void onPreExecute() { //Show a progress dialog until done protected void onPreExecute() {
loginButton.setEnabled(false); loginButton.setEnabled(false);
View view = getCurrentFocus(); View view = getCurrentFocus();
@ -69,7 +69,7 @@ public class LoginActivity extends BaseActivity {
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
"Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG)
.show(); .show();
@ -82,7 +82,7 @@ public class LoginActivity extends BaseActivity {
@Override @Override
protected void onCancelled() { protected void onCancelled() {
super.onCancelled(); super.onCancelled();
loginButton.setEnabled(true); //Re-enable login button loginButton.setEnabled(true); //Re-enables login button
} }
} }

89
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateItemActivity.java

@ -1,5 +1,6 @@
package gr.auth.databases.flavours.activities; package gr.auth.databases.flavours.activities;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -7,6 +8,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatButton;
@ -15,11 +17,17 @@ import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.ItemRating; import gr.auth.databases.flavours.model.ItemRating;
import gr.auth.databases.flavours.model.ItemSummary; import gr.auth.databases.flavours.model.ItemSummary;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import static gr.auth.databases.flavours.session.SessionManager.rateDrinkUrl;
import static gr.auth.databases.flavours.session.SessionManager.rateFoodUrl;
public class RateItemActivity extends BaseActivity implements AdapterView.OnItemSelectedListener { public class RateItemActivity extends BaseActivity implements AdapterView.OnItemSelectedListener {
public static final String BUNDLE_RATE_ITEM_TYPE = "BUNDLE_RATE_ITEM_TYPE"; public static final String BUNDLE_RATE_ITEM = "BUNDLE_RATE_ITEM_TYPE";
private ItemSummary.ItemType itemType; private ItemSummary item;
private EditText ratingText; private EditText ratingText;
private int ratingGrade; private int ratingGrade;
private ItemRating.PortionSize ratingPortionSize; private ItemRating.PortionSize ratingPortionSize;
@ -30,12 +38,17 @@ public class RateItemActivity extends BaseActivity implements AdapterView.OnItem
setContentView(R.layout.activity_rate_item); setContentView(R.layout.activity_rate_item);
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { assert extras != null;
itemType = (ItemSummary.ItemType) extras.getSerializable(BUNDLE_RATE_ITEM_TYPE); item = extras.getParcelable(BUNDLE_RATE_ITEM);
}
Toolbar toolbar = findViewById(R.id.rate_item_toolbar); Toolbar toolbar = findViewById(R.id.rate_item_toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
if (item.getType() == ItemSummary.ItemType.FOOD) {
toolbar.setTitle(getString(R.string.rate_item_toolbar_title_food));
} else if (item.getType() == ItemSummary.ItemType.DRINK) {
toolbar.setTitle(getString(R.string.rate_item_toolbar_title_drink));
}
ActionBar actionbar = getSupportActionBar(); ActionBar actionbar = getSupportActionBar();
if (actionbar != null) { if (actionbar != null) {
actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setDisplayHomeAsUpEnabled(true);
@ -62,7 +75,8 @@ public class RateItemActivity extends BaseActivity implements AdapterView.OnItem
rateButton.setOnClickListener(new View.OnClickListener() { rateButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//TODO RateItemTask rateItemTask = new RateItemTask();
rateItemTask.execute();
} }
}); });
@ -102,4 +116,67 @@ public class RateItemActivity extends BaseActivity implements AdapterView.OnItem
@Override @Override
public void onNothingSelected(AdapterView<?> adapterView) { public void onNothingSelected(AdapterView<?> adapterView) {
} }
private class RateItemTask extends AsyncTask<Void, Void, Integer> {
private static final String REQ_RATE_FOOD_ID = "food";
private static final String REQ_RATE_DRINK_ID = "drink";
private static final String REQ_RATE_ITEM_GRADE = "rating_grade";
private static final String REQ_RATE_ITEM_DESCRIPTION = "rating_text";
private static final String REQ_RATE_ITEM_PORTION_SIZE = "rating_pοrtion_size";
@Override
protected void onPreExecute() {
}
@Override
protected Integer doInBackground(Void... params) {
Request request;
FormBody.Builder builder = new FormBody.Builder();
if (ratingPortionSize != null) {
builder.add(REQ_RATE_ITEM_PORTION_SIZE,
"" + ItemRating.PortionSize.getWorkingTypeFromId(ratingPortionSize.getId()));
}
if (item.getType() == ItemSummary.ItemType.FOOD) {
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")
.build();
RequestBody formBody = builder.build();
request = new Request.Builder()
.url(rateFoodUrl)
.post(formBody)
.build();
} else {
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")
.build();
RequestBody formBody = builder.build();
request = new Request.Builder()
.url(rateDrinkUrl)
.post(formBody)
.build();
}
try {
client.newCall(request).execute();
return 0;
} catch (Exception e) {
return 2;
}
}
@Override
protected void onPostExecute(Integer result) {
Toast.makeText(RateItemActivity.this, "Rating added!", Toast.LENGTH_SHORT).show();
RateItemActivity.this.finish();
}
}
} }

7
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/RateRestaurantActivity.java

@ -149,7 +149,6 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
.build(); .build();
try { try {
//Makes request & handles response
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
ResponseBody responseBody = response.body(); ResponseBody responseBody = response.body();
@ -172,7 +171,7 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
Spinner dietSpinner = findViewById(R.id.rate_restaurant_diet); Spinner dietSpinner = findViewById(R.id.rate_restaurant_diet);
ArrayAdapter<String> dietAdapter = new ArrayAdapter<>(RateRestaurantActivity.this, ArrayAdapter<String> dietAdapter = new ArrayAdapter<>(RateRestaurantActivity.this,
android.R.layout.simple_spinner_item, spinnerArray); android.R.layout.simple_spinner_item, spinnerArray);
@ -196,7 +195,6 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
@Override @Override
protected Integer doInBackground(Void... params) { protected Integer doInBackground(Void... params) {
//Builds the signup request
FormBody.Builder builder = new FormBody.Builder() FormBody.Builder builder = new FormBody.Builder()
.add(REQ_RATE_RESTAURANT_ID, "" + restaurant.getId()) .add(REQ_RATE_RESTAURANT_ID, "" + restaurant.getId())
.add(REQ_RATE_RESTAURANT_GRADE, "" + ratingGrade) .add(REQ_RATE_RESTAURANT_GRADE, "" + ratingGrade)
@ -218,7 +216,6 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
.build(); .build();
try { try {
//Makes request & handles response
client.newCall(request).execute(); client.newCall(request).execute();
return 0; return 0;
@ -228,7 +225,7 @@ public class RateRestaurantActivity extends BaseActivity implements AdapterView.
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
Toast.makeText(RateRestaurantActivity.this, "Rating added!", Toast.LENGTH_SHORT).show(); Toast.makeText(RateRestaurantActivity.this, "Rating added!", Toast.LENGTH_SHORT).show();
RateRestaurantActivity.this.finish(); RateRestaurantActivity.this.finish();
} }

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

@ -94,7 +94,7 @@ public class SignUpActivity extends BaseActivity {
private class SignupTask extends AsyncTask<String, Void, Integer> { private class SignupTask extends AsyncTask<String, Void, Integer> {
@Override @Override
protected void onPreExecute() { //Show a progress dialog until done protected void onPreExecute() {
signupButton.setEnabled(false); signupButton.setEnabled(false);
View view = getCurrentFocus(); View view = getCurrentFocus();
@ -110,7 +110,7 @@ public class SignUpActivity extends BaseActivity {
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
"Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG)
.show(); .show();

35
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java

@ -21,13 +21,12 @@ import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.activities.AddDietActivity; import gr.auth.databases.flavours.activities.AddDietActivity;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.Diet; import gr.auth.databases.flavours.model.Diet;
import gr.auth.databases.flavours.utils.FollowDietStateTask;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import static gr.auth.databases.flavours.session.SessionManager.dietsUserViewUrl; import static gr.auth.databases.flavours.session.SessionManager.dietsUserViewUrl;
import static gr.auth.databases.flavours.session.SessionManager.followDietUrl;
public class DietsActivity extends BaseActivity implements DietsAdapter.SubscribeDietsAdapterInteractionListener { public class DietsActivity extends BaseActivity implements DietsAdapter.SubscribeDietsAdapterInteractionListener {
private RecyclerView recyclerView; private RecyclerView recyclerView;
@ -91,7 +90,7 @@ public class DietsActivity extends BaseActivity implements DietsAdapter.Subscrib
@Override @Override
public void onSubscribeDietsAdapterInteraction(Diet diet) { public void onSubscribeDietsAdapterInteraction(Diet diet) {
FollowDietStateTask followDietStateTask = new FollowDietStateTask(); FollowDietStateTask followDietStateTask = new FollowDietStateTask(client);
followDietStateTask.execute(diet.getId()); followDietStateTask.execute(diet.getId());
} }
@ -153,34 +152,4 @@ public class DietsActivity extends BaseActivity implements DietsAdapter.Subscrib
recyclerView.setAdapter(dietsAdapter); recyclerView.setAdapter(dietsAdapter);
} }
} }
private class FollowDietStateTask 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(followDietUrl + params[0] + "/")
.build();
try {
//Makes request & handles response
client.newCall(request).execute();
return 0;
} catch (Exception e) {
e.printStackTrace();
return 2;
}
}
@Override
protected void onPostExecute(Integer result) {
}
}
} }

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java

@ -39,7 +39,7 @@ import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import static gr.auth.databases.flavours.activities.RateItemActivity.BUNDLE_RATE_ITEM_TYPE; import static gr.auth.databases.flavours.activities.RateItemActivity.BUNDLE_RATE_ITEM;
import static gr.auth.databases.flavours.activities.ingredients.IngredientsActivity.INGREDIENT_PICK_RESULT; import static gr.auth.databases.flavours.activities.ingredients.IngredientsActivity.INGREDIENT_PICK_RESULT;
import static gr.auth.databases.flavours.session.SessionManager.drinksUserViewUrl; import static gr.auth.databases.flavours.session.SessionManager.drinksUserViewUrl;
@ -103,7 +103,7 @@ public class DrinkActivity extends BaseActivity {
startActivityForResult(intent, ADD_INGREDIENT_REQUEST); startActivityForResult(intent, ADD_INGREDIENT_REQUEST);
} else if (viewPager.getCurrentItem() == 2) { } else if (viewPager.getCurrentItem() == 2) {
Intent intent = new Intent(view.getContext(), RateItemActivity.class); Intent intent = new Intent(view.getContext(), RateItemActivity.class);
intent.putExtra(BUNDLE_RATE_ITEM_TYPE, ItemSummary.ItemType.DRINK); intent.putExtra(BUNDLE_RATE_ITEM, mDrink);
startActivity(intent); startActivity(intent);
} }
} }
@ -207,7 +207,6 @@ public class DrinkActivity extends BaseActivity {
private static final String JSON_TAG_DRINK_RATING_DATE = "rating_date"; 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_DRINK_RATING_PORTION_SIZE = "rating_pοrtion_size";
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
} }

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java

@ -39,7 +39,7 @@ import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import static gr.auth.databases.flavours.activities.RateItemActivity.BUNDLE_RATE_ITEM_TYPE; import static gr.auth.databases.flavours.activities.RateItemActivity.BUNDLE_RATE_ITEM;
import static gr.auth.databases.flavours.activities.ingredients.IngredientsActivity.INGREDIENT_PICK_RESULT; import static gr.auth.databases.flavours.activities.ingredients.IngredientsActivity.INGREDIENT_PICK_RESULT;
import static gr.auth.databases.flavours.session.SessionManager.foodsUserViewUrl; import static gr.auth.databases.flavours.session.SessionManager.foodsUserViewUrl;
@ -103,7 +103,7 @@ public class FoodActivity extends BaseActivity {
startActivityForResult(intent, ADD_INGREDIENT_REQUEST); startActivityForResult(intent, ADD_INGREDIENT_REQUEST);
} else if (viewPager.getCurrentItem() == 2) { } else if (viewPager.getCurrentItem() == 2) {
Intent intent = new Intent(view.getContext(), RateItemActivity.class); Intent intent = new Intent(view.getContext(), RateItemActivity.class);
intent.putExtra(BUNDLE_RATE_ITEM_TYPE, ItemSummary.ItemType.FOOD); intent.putExtra(BUNDLE_RATE_ITEM, mFood);
startActivity(intent); startActivity(intent);
} }
} }
@ -207,7 +207,6 @@ public class FoodActivity extends BaseActivity {
private static final String JSON_TAG_FOOD_RATING_DATE = "rating_date"; 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_FOOD_RATING_PORTION_SIZE = "rating_pοrtion_size";
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
} }

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

@ -301,7 +301,7 @@ public class MainActivity extends BaseActivity {
private static final String JSON_TAG_RESTAURANT_CLOSING = "restaurant_closing"; private static final String JSON_TAG_RESTAURANT_CLOSING = "restaurant_closing";
@Override @Override
protected void onPreExecute() { //Show a progress dialog until done protected void onPreExecute() {
restaurants.clear(); restaurants.clear();
} }
@ -354,7 +354,6 @@ public class MainActivity extends BaseActivity {
.build(); .build();
try { try {
//Makes request & handles response
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
ResponseBody responseBody = response.body(); ResponseBody responseBody = response.body();
@ -380,7 +379,7 @@ public class MainActivity extends BaseActivity {
} }
@Override @Override
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) {
viewPager.setAdapter(null); viewPager.setAdapter(null);
PagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager()); PagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter); viewPager.setAdapter(pagerAdapter);

12
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/profile/fragments/ProfileInfoFragment.java

@ -11,8 +11,10 @@ import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageButton; import androidx.appcompat.widget.AppCompatImageButton;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseApplication;
import gr.auth.databases.flavours.model.DietSummary; import gr.auth.databases.flavours.model.DietSummary;
import gr.auth.databases.flavours.model.Profile; import gr.auth.databases.flavours.model.Profile;
import gr.auth.databases.flavours.utils.FollowDietStateTask;
public class ProfileInfoFragment extends Fragment { public class ProfileInfoFragment extends Fragment {
@ -76,11 +78,11 @@ public class ProfileInfoFragment extends Fragment {
if (!profileUserView.getDietsFollowed().isEmpty()) { if (!profileUserView.getDietsFollowed().isEmpty()) {
(rootView.findViewById(R.id.profile_diets_list_title)).setVisibility(View.VISIBLE); (rootView.findViewById(R.id.profile_diets_list_title)).setVisibility(View.VISIBLE);
LinearLayout dietsList = rootView.findViewById(R.id.profile_diets_list); final LinearLayout dietsList = rootView.findViewById(R.id.profile_diets_list);
dietsList.setVisibility(View.VISIBLE); dietsList.setVisibility(View.VISIBLE);
for (DietSummary dietFollowed : profileUserView.getDietsFollowed()) { for (final DietSummary dietFollowed : profileUserView.getDietsFollowed()) {
View userDietRow = getLayoutInflater().inflate(R.layout.profile_diet_row, dietsList, false); final View userDietRow = getLayoutInflater().inflate(R.layout.profile_diet_row, dietsList, false);
TextView dietName = userDietRow.findViewById(R.id.profile_diet_name); TextView dietName = userDietRow.findViewById(R.id.profile_diet_name);
dietName.setText(dietFollowed.getName()); dietName.setText(dietFollowed.getName());
@ -90,7 +92,9 @@ public class ProfileInfoFragment extends Fragment {
removeDiet.setOnClickListener(new View.OnClickListener() { removeDiet.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//TODO FollowDietStateTask followDietStateTask = new FollowDietStateTask(BaseApplication.getInstance().getClient());
followDietStateTask.execute(dietFollowed.getId());
dietsList.removeView(userDietRow);
} }
}); });

1
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java

@ -63,7 +63,6 @@ public class RestaurantActivity extends BaseActivity
private TabLayout tabLayout; private TabLayout tabLayout;
private FloatingActionButton FAB; private FloatingActionButton FAB;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/session/SessionManager.java

@ -56,6 +56,8 @@ public class SessionManager {
public static final String restaurantsUrl = baseServerUrl + "api/restaurant/"; public static final String restaurantsUrl = baseServerUrl + "api/restaurant/";
public static final String restaurantsUserViewUrl = baseServerUrl + "api/restaurantUserView/"; public static final String restaurantsUserViewUrl = baseServerUrl + "api/restaurantUserView/";
public static final String getUserDietsUrl = baseServerUrl + "api/userDiets/"; public static final String getUserDietsUrl = baseServerUrl + "api/userDiets/";
public static final String rateDrinkUrl = baseServerUrl + "api/userratesdrink/";
public static final String rateFoodUrl = baseServerUrl + "api/userratesfood/";
public static final String rateRestaurantUrl = baseServerUrl + "api/userratesrestaurant/"; public static final String rateRestaurantUrl = baseServerUrl + "api/userratesrestaurant/";
public static final String foodsUserViewUrl = baseServerUrl + "api/foodUserView/"; public static final String foodsUserViewUrl = baseServerUrl + "api/foodUserView/";
public static final String drinksUserViewUrl = baseServerUrl + "api/drinkUserView/"; public static final String drinksUserViewUrl = baseServerUrl + "api/drinkUserView/";
@ -66,6 +68,8 @@ public class SessionManager {
public static final String ingredientsUserViewUrl = baseServerUrl + "api/ingredientUserView/"; public static final String ingredientsUserViewUrl = baseServerUrl + "api/ingredientUserView/";
public static final String prohibitIngredientUrl = baseServerUrl + "api/prohibitIngredient/"; public static final String prohibitIngredientUrl = baseServerUrl + "api/prohibitIngredient/";
public static final String followDietUrl = baseServerUrl + "api/followDiet/"; public static final String followDietUrl = baseServerUrl + "api/followDiet/";
public static final String addIngredientUrl = baseServerUrl + "api/ingredient/";
public static final String addDietUrl = baseServerUrl + "api/addDiet/";
// Client & Cookies // Client & Cookies
private final OkHttpClient client; private final OkHttpClient client;
@ -104,7 +108,6 @@ public class SessionManager {
.post(formBody) .post(formBody)
.build(); .build();
try { try {
//Makes request & handles response //Makes request & handles response
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();

45
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/FollowDietStateTask.java

@ -0,0 +1,45 @@
package gr.auth.databases.flavours.utils;
import android.os.AsyncTask;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import static gr.auth.databases.flavours.session.SessionManager.followDietUrl;
public class FollowDietStateTask extends AsyncTask<Integer, Void, Integer> {
private OkHttpClient client;
public FollowDietStateTask(OkHttpClient client) {
this.client = client;
}
@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(followDietUrl + params[0] + "/")
.build();
try {
//Makes request & handles response
client.newCall(request).execute();
return 0;
} catch (Exception e) {
e.printStackTrace();
return 2;
}
}
@Override
protected void onPostExecute(Integer result) {
}
}

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

@ -160,6 +160,8 @@
<!-- Rate Item --> <!-- Rate Item -->
<string name="rate_item_toolbar_title">Rate Item</string> <string name="rate_item_toolbar_title">Rate Item</string>
<string name="rate_item_toolbar_title_food">Rate Food</string>
<string name="rate_item_toolbar_title_drink">Rate Drink</string>
<string name="rate_item_grade_title">Grade:</string> <string name="rate_item_grade_title">Grade:</string>
<string name="rate_item_portion_size_title">Portion size:</string> <string name="rate_item_portion_size_title">Portion size:</string>
<string name="rate_item_text">Add some text to your rating</string> <string name="rate_item_text">Add some text to your rating</string>

Loading…
Cancel
Save