Commit 5ee9eb0b authored by Willard's avatar Willard

Apply formatting to all files, minor refactoring

parent 96d4c693
...@@ -24,6 +24,20 @@ public class AppUtils { ...@@ -24,6 +24,20 @@ public class AppUtils {
private static Context c; private static Context c;
private static String username = ""; private static String username = "";
private static String password = ""; private static String password = "";
private static final Interceptor TOKEN_AUTH_INTERCEPTOR = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
String credentials = username + ":" + password;
final String basic = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder()
.header("Authorization", basic)
.header("Accept", "application/json")
.method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
};
private static int userId = -1; private static int userId = -1;
public static void login(String _username, String _password, int _userId) { public static void login(String _username, String _password, int _userId) {
...@@ -55,7 +69,7 @@ public class AppUtils { ...@@ -55,7 +69,7 @@ public class AppUtils {
} }
public static boolean isNetworkAvailable(Context c) { public static boolean isNetworkAvailable(Context c) {
ConnectivityManager connectivity =(ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager connectivity = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) { if (connectivity == null) {
return false; return false;
...@@ -72,6 +86,26 @@ public class AppUtils { ...@@ -72,6 +86,26 @@ public class AppUtils {
return false; return false;
} }
/*
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Response origResponse = chain.proceed(chain.request());
if (AppUtils.isNetworkAvailable(c)) {
int maxAge = 60; // read from cache for 1 minute
return origResponse.newBuilder()
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
} else {
int maxStale = 60 * 60 * 24 * 28; // tolerate 4-weeks stale
return origResponse.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
.build();
}
}
};
*/
public static void initREST(String serverIP, Context c) { public static void initREST(String serverIP, Context c) {
AppUtils.c = c; AppUtils.c = c;
File httpCacheDirectory = new File(c.getCacheDir(), "responses"); File httpCacheDirectory = new File(c.getCacheDir(), "responses");
...@@ -95,43 +129,7 @@ public class AppUtils { ...@@ -95,43 +129,7 @@ public class AppUtils {
.build(); .build();
service = retrofit.create(CanteeneoApiInterface.class); service = retrofit.create(CanteeneoApiInterface.class);
} }
/*
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Response origResponse = chain.proceed(chain.request());
if (AppUtils.isNetworkAvailable(c)) {
int maxAge = 60; // read from cache for 1 minute
return origResponse.newBuilder()
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
} else {
int maxStale = 60 * 60 * 24 * 28; // tolerate 4-weeks stale
return origResponse.newBuilder()
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
.build();
}
}
};
*/
private static final Interceptor TOKEN_AUTH_INTERCEPTOR = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
String credentials = username + ":" + password;
final String basic = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder()
.header("Authorization", basic)
.header("Accept", "application/json")
.method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
};
} }
...@@ -4,10 +4,10 @@ import com.canteeneo.entities.Cuisine; ...@@ -4,10 +4,10 @@ import com.canteeneo.entities.Cuisine;
import com.canteeneo.entities.Dish; import com.canteeneo.entities.Dish;
import com.canteeneo.entities.DishReview; import com.canteeneo.entities.DishReview;
import com.canteeneo.entities.DishType; import com.canteeneo.entities.DishType;
import com.canteeneo.entities.FavoriteInfo;
import com.canteeneo.entities.Location; import com.canteeneo.entities.Location;
import com.canteeneo.entities.NewUserResult; import com.canteeneo.entities.NewUserResult;
import com.canteeneo.entities.Stall; import com.canteeneo.entities.Stall;
import com.canteeneo.entities.FavoriteInfo;
import com.canteeneo.entities.StallReview; import com.canteeneo.entities.StallReview;
import com.canteeneo.entities.Token; import com.canteeneo.entities.Token;
...@@ -15,7 +15,6 @@ import java.util.List; ...@@ -15,7 +15,6 @@ import java.util.List;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.DELETE; import retrofit2.http.DELETE;
import retrofit2.http.Field; import retrofit2.http.Field;
......
...@@ -2,7 +2,7 @@ package com.canteeneo; ...@@ -2,7 +2,7 @@ package com.canteeneo;
import android.app.Application; import android.app.Application;
public class CustomApplication extends Application{ public class CustomApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
......
...@@ -7,15 +7,15 @@ import android.widget.BaseAdapter; ...@@ -7,15 +7,15 @@ import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.canteeneo.entities.Dish; import com.canteeneo.entities.Dish;
import com.squareup.picasso.Picasso;
import java.util.ArrayList; import java.util.ArrayList;
public class DishAdapter extends BaseAdapter { public class DishAdapter extends BaseAdapter {
private Activity context;
ArrayList<Dish> dishes; ArrayList<Dish> dishes;
ArrayList<Dish> filteredDishes; ArrayList<Dish> filteredDishes;
private Activity context;
public DishAdapter(Activity context, ArrayList<Dish> dishes) { public DishAdapter(Activity context, ArrayList<Dish> dishes) {
this.context = context; this.context = context;
...@@ -41,43 +41,43 @@ public class DishAdapter extends BaseAdapter { ...@@ -41,43 +41,43 @@ public class DishAdapter extends BaseAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
DishViewHolder holder; DishViewHolder holder;
if(convertView == null) { if (convertView == null) {
convertView = context.getLayoutInflater().inflate(R.layout.dish_row, null); convertView = context.getLayoutInflater().inflate(R.layout.dish_row, null);
holder = new DishViewHolder(); holder = new DishViewHolder();
holder.name = (TextView)convertView.findViewById(R.id.tvName); holder.name = (TextView) convertView.findViewById(R.id.tvName);
holder.price = (TextView)convertView.findViewById(R.id.tvPrice); holder.price = (TextView) convertView.findViewById(R.id.tvPrice);
holder.image = (ImageView)convertView.findViewById(R.id.iv); holder.image = (ImageView) convertView.findViewById(R.id.iv);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (DishViewHolder)convertView.getTag(); holder = (DishViewHolder) convertView.getTag();
} }
Dish d = filteredDishes.get(position); Dish d = filteredDishes.get(position);
holder.name.setText(d.getName()); holder.name.setText(d.getName());
holder.price.setText(d.getPrice()+""); holder.price.setText(d.getPrice() + "");
Picasso.with(context).load("http://" + parent.getResources().getString(R.string.server_ip) + ":5000/static/uploads/"+ d.getImagePath()).fit().centerCrop().tag(context).into(holder.image); Picasso.with(context).load("http://" + parent.getResources().getString(R.string.server_ip) + ":5000/static/uploads/" + d.getImagePath()).fit().centerCrop().tag(context).into(holder.image);
return convertView; return convertView;
} }
public void filter(String nameFilter, ArrayList<Integer> typeFilter, ArrayList<Integer> cuisineFilter, ArrayList<Integer> locationFilter, double minPrice, double maxPrice) { public void filter(String nameFilter, ArrayList<Integer> typeFilter, ArrayList<Integer> cuisineFilter, ArrayList<Integer> locationFilter, double minPrice, double maxPrice) {
filteredDishes.clear(); filteredDishes.clear();
for(Dish dish: dishes) { for (Dish dish : dishes) {
boolean skip = false; boolean skip = false;
String[] keywords = nameFilter.toLowerCase().split(" "); String[] keywords = nameFilter.toLowerCase().split(" ");
for(String keyword: keywords) { for (String keyword : keywords) {
if(dish.getName().toLowerCase().indexOf(keyword) == -1) { if (dish.getName().toLowerCase().indexOf(keyword) == -1) {
skip = true; skip = true;
break; break;
} }
} }
if(skip) continue; if (skip) continue;
if(typeFilter.indexOf(dish.getTypeId()) == -1) continue; if (typeFilter.indexOf(dish.getTypeId()) == -1) continue;
if(cuisineFilter.indexOf(dish.getCuisineId()) == -1) continue; if (cuisineFilter.indexOf(dish.getCuisineId()) == -1) continue;
if(locationFilter.indexOf(dish.getLocationId()) == -1) continue; if (locationFilter.indexOf(dish.getLocationId()) == -1) continue;
if(dish.getPrice() < minPrice || dish.getPrice() > maxPrice) continue; if (dish.getPrice() < minPrice || dish.getPrice() > maxPrice) continue;
filteredDishes.add(dish); filteredDishes.add(dish);
} }
......
...@@ -39,7 +39,7 @@ public class DishReviewActivity extends AppCompatActivity { ...@@ -39,7 +39,7 @@ public class DishReviewActivity extends AppCompatActivity {
body = (EditText) findViewById(R.id.rv_body); body = (EditText) findViewById(R.id.rv_body);
rating = (RatingBar) findViewById(R.id.rv_rating); rating = (RatingBar) findViewById(R.id.rv_rating);
if(editing) { if (editing) {
setTitle("Edit Dish Review"); setTitle("Edit Dish Review");
reviewId = getIntent().getIntExtra("REVIEW_ID", 0); reviewId = getIntent().getIntExtra("REVIEW_ID", 0);
title.setText(getIntent().getStringExtra("EDIT_TITLE")); title.setText(getIntent().getStringExtra("EDIT_TITLE"));
...@@ -61,7 +61,7 @@ public class DishReviewActivity extends AppCompatActivity { ...@@ -61,7 +61,7 @@ public class DishReviewActivity extends AppCompatActivity {
rv.setDishId(id); rv.setDishId(id);
rv.setUserId(AppUtils.getUserId()); rv.setUserId(AppUtils.getUserId());
if(editing) { if (editing) {
editReview(reviewId, rv); editReview(reviewId, rv);
} else { } else {
newReview(rv); newReview(rv);
......
...@@ -22,8 +22,8 @@ import retrofit2.Callback; ...@@ -22,8 +22,8 @@ import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
public class DishReviewAdapter extends BaseAdapter { public class DishReviewAdapter extends BaseAdapter {
private Activity context;
ArrayList<DishReview> dishReviews; ArrayList<DishReview> dishReviews;
private Activity context;
public DishReviewAdapter(Activity context, ArrayList<DishReview> dishReviews) { public DishReviewAdapter(Activity context, ArrayList<DishReview> dishReviews) {
this.context = context; this.context = context;
...@@ -59,9 +59,9 @@ public class DishReviewAdapter extends BaseAdapter { ...@@ -59,9 +59,9 @@ public class DishReviewAdapter extends BaseAdapter {
body.setText(dr.getBody()); body.setText(dr.getBody());
username.setText(dr.getUser()); username.setText(dr.getUser());
Button editButton = (Button)v.findViewById(R.id.edit_button); Button editButton = (Button) v.findViewById(R.id.edit_button);
Button deleteButton = (Button)v.findViewById(R.id.delete_button); Button deleteButton = (Button) v.findViewById(R.id.delete_button);
if(dr.getUserId() == AppUtils.getUserId()) { if (dr.getUserId() == AppUtils.getUserId()) {
editButton.setVisibility(View.VISIBLE); editButton.setVisibility(View.VISIBLE);
editButton.setOnClickListener(new View.OnClickListener() { editButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -81,7 +81,7 @@ public class DishReviewAdapter extends BaseAdapter { ...@@ -81,7 +81,7 @@ public class DishReviewAdapter extends BaseAdapter {
deleteButton.setOnClickListener(new View.OnClickListener() { deleteButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final DishViewActivity context = (DishViewActivity)DishReviewAdapter.this.context; final DishViewActivity context = (DishViewActivity) DishReviewAdapter.this.context;
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle("Confirm Delete") .setTitle("Confirm Delete")
.setMessage("Are you sure you want to delete your review? This cannot be undone.") .setMessage("Are you sure you want to delete your review? This cannot be undone.")
......
...@@ -13,9 +13,9 @@ import android.widget.ListView; ...@@ -13,9 +13,9 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.squareup.picasso.Picasso;
import com.canteeneo.entities.DishReview; import com.canteeneo.entities.DishReview;
import com.canteeneo.entities.FavoriteInfo; import com.canteeneo.entities.FavoriteInfo;
import com.squareup.picasso.Picasso;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -54,7 +54,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -54,7 +54,7 @@ public class DishViewActivity extends AppCompatActivity {
TextView dishDesc = (TextView) findViewById(R.id.dish_desc); TextView dishDesc = (TextView) findViewById(R.id.dish_desc);
dishDesc.setText(i.getStringExtra("DESCRIPTION")); dishDesc.setText(i.getStringExtra("DESCRIPTION"));
ImageView image = (ImageView) findViewById(R.id.dish_pic); ImageView image = (ImageView) findViewById(R.id.dish_pic);
Picasso.with(this).load("http://" + getResources().getString(R.string.server_ip) + ":5000/static/uploads/"+ i.getStringExtra("IMAGE")).fit().centerCrop().into(image); Picasso.with(this).load("http://" + getResources().getString(R.string.server_ip) + ":5000/static/uploads/" + i.getStringExtra("IMAGE")).fit().centerCrop().into(image);
dishStall = (TextView) findViewById(R.id.dish_stall); dishStall = (TextView) findViewById(R.id.dish_stall);
dishStall.setText(i.getStringExtra("STALLNAME")); dishStall.setText(i.getStringExtra("STALLNAME"));
...@@ -67,7 +67,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -67,7 +67,7 @@ public class DishViewActivity extends AppCompatActivity {
}); });
} }
favoriteCheckbox = (CheckBox)findViewById(R.id.favorite_checkbox); favoriteCheckbox = (CheckBox) findViewById(R.id.favorite_checkbox);
favoriteCheckbox.setEnabled(AppUtils.isLoggedIn()); favoriteCheckbox.setEnabled(AppUtils.isLoggedIn());
favoriteCheckbox.setOnClickListener(new View.OnClickListener() { favoriteCheckbox.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -141,18 +141,18 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -141,18 +141,18 @@ public class DishViewActivity extends AppCompatActivity {
public void onResponse(Call<List<DishReview>> call, Response<List<DishReview>> response) { public void onResponse(Call<List<DishReview>> call, Response<List<DishReview>> response) {
List<DishReview> newReviews = response.body(); List<DishReview> newReviews = response.body();
DishReview ownedReview = null; DishReview ownedReview = null;
for(DishReview review: newReviews) { for (DishReview review : newReviews) {
if(review.getUserId() == AppUtils.getUserId()) { if (review.getUserId() == AppUtils.getUserId()) {
ownedReview = review; ownedReview = review;
break; break;
} }
} }
reviews.clear(); reviews.clear();
if(ownedReview != null) { if (ownedReview != null) {
newReviews.remove(ownedReview); newReviews.remove(ownedReview);
reviews.add(ownedReview); reviews.add(ownedReview);
} }
findViewById(R.id.add_review_button).setVisibility(ownedReview != null || !AppUtils.isLoggedIn()? View.INVISIBLE: View.VISIBLE); findViewById(R.id.add_review_button).setVisibility(ownedReview != null || !AppUtils.isLoggedIn() ? View.INVISIBLE : View.VISIBLE);
reviews.addAll(newReviews); reviews.addAll(newReviews);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
......
...@@ -6,9 +6,7 @@ import android.content.Context; ...@@ -6,9 +6,7 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
...@@ -44,10 +42,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -44,10 +42,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
private DishAdapter adapter; private DishAdapter adapter;
private ArrayList<Dish> dishes = new ArrayList<>(); private ArrayList<Dish> dishes = new ArrayList<>();
private String query = "";
public static String EXTRA_MESSAGE = "com.testapp.MESSAGE";
String query = "";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -58,8 +53,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -58,8 +53,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle); drawer.addDrawerListener(toggle);
toggle.syncState(); toggle.syncState();
...@@ -89,19 +83,19 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -89,19 +83,19 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
} }
}); });
Button applyFilterButton = (Button)findViewById(R.id.apply_filter_button); Button applyFilterButton = (Button) findViewById(R.id.apply_filter_button);
applyFilterButton.setOnClickListener(new View.OnClickListener() { applyFilterButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
refreshDishes(); refreshDishes();
((DrawerLayout)NavDrawerActivity.this.findViewById(R.id.drawer_layout)).closeDrawer(Gravity.LEFT); ((DrawerLayout) NavDrawerActivity.this.findViewById(R.id.drawer_layout)).closeDrawer(Gravity.LEFT);
} }
}); });
RelativeLayout loggedInHeader = (RelativeLayout)findViewById(R.id.logged_in_header); RelativeLayout loggedInHeader = (RelativeLayout) findViewById(R.id.logged_in_header);
if(AppUtils.isLoggedIn()) { if (AppUtils.isLoggedIn()) {
loggedInHeader.setVisibility(View.VISIBLE); loggedInHeader.setVisibility(View.VISIBLE);
((TextView)findViewById(R.id.greeting)).setText("Hello, " + AppUtils.getUsername()); ((TextView) findViewById(R.id.greeting)).setText("Hello, " + AppUtils.getUsername());
findViewById(R.id.logout_button).setOnClickListener(new View.OnClickListener() { findViewById(R.id.logout_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -144,16 +138,16 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -144,16 +138,16 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
} }
public <T extends Filter> void populateFilter(Call<List<T>> call, int layout_id) { public <T extends Filter> void populateFilter(Call<List<T>> call, int layout_id) {
final LinearLayout checkboxes = (LinearLayout)findViewById(layout_id); final LinearLayout checkboxes = (LinearLayout) findViewById(layout_id);
checkboxes.removeAllViewsInLayout(); checkboxes.removeAllViewsInLayout();
call.enqueue(new Callback<List<T>>() { call.enqueue(new Callback<List<T>>() {
@Override @Override
public void onResponse(Call<List<T>> call, Response<List<T>> response) { public void onResponse(Call<List<T>> call, Response<List<T>> response) {
List<T> filters = response.body(); List<T> filters = response.body();
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(T filter: filters) { for (T filter : filters) {
CheckBox checkbox = (CheckBox)inflater.inflate(R.layout.search_checkbox, null); CheckBox checkbox = (CheckBox) inflater.inflate(R.layout.search_checkbox, null);
checkbox.setId(filter.getId()); checkbox.setId(filter.getId());
checkbox.setText(filter.getName()); checkbox.setText(filter.getName());
checkbox.setChecked(true); checkbox.setChecked(true);
...@@ -175,7 +169,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -175,7 +169,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
if (drawer.isDrawerOpen(GravityCompat.START)) { if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
} else { } else {
if(AppUtils.isLoggedIn()) { if (AppUtils.isLoggedIn()) {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setTitle("Logout") .setTitle("Logout")
.setMessage("Are you sure you want to log out?") .setMessage("Are you sure you want to log out?")
...@@ -234,13 +228,13 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -234,13 +228,13 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
} }
private ArrayList<Integer> getChecked(int layoutId) { private ArrayList<Integer> getChecked(int layoutId) {
LinearLayout checkboxes = (LinearLayout)findViewById(layoutId); LinearLayout checkboxes = (LinearLayout) findViewById(layoutId);
ArrayList<Integer> checked = new ArrayList<>(); ArrayList<Integer> checked = new ArrayList<>();
for(int i = 0; i < checkboxes.getChildCount(); i++) { for (int i = 0; i < checkboxes.getChildCount(); i++) {
View v = checkboxes.getChildAt(i); View v = checkboxes.getChildAt(i);
if(v instanceof CheckBox) { if (v instanceof CheckBox) {
CheckBox c = (CheckBox)v; CheckBox c = (CheckBox) v;
if(c.isChecked()) { if (c.isChecked()) {
checked.add(c.getId()); checked.add(c.getId());
} }
} }
...@@ -249,7 +243,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi ...@@ -249,7 +243,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
} }
public void refreshDishes() { public void refreshDishes() {
RangeSeekBar priceRangeBar = (RangeSeekBar)findViewById(R.id.price_range_bar); RangeSeekBar priceRangeBar = (RangeSeekBar) findViewById(R.id.price_range_bar);
adapter.filter(query, getChecked(R.id.type_checkboxes), getChecked(R.id.cuisine_checkboxes), getChecked(R.id.location_checkboxes), priceRangeBar.getSelectedMinValue().doubleValue(), priceRangeBar.getSelectedMaxValue().doubleValue()); adapter.filter(query, getChecked(R.id.type_checkboxes), getChecked(R.id.cuisine_checkboxes), getChecked(R.id.location_checkboxes), priceRangeBar.getSelectedMinValue().doubleValue(), priceRangeBar.getSelectedMaxValue().doubleValue());
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
System.out.println(adapter.filteredDishes.size()); System.out.println(adapter.filteredDishes.size());
......
...@@ -34,10 +34,10 @@ public class RegisterActivity extends AppCompatActivity { ...@@ -34,10 +34,10 @@ public class RegisterActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register); setContentView(R.layout.activity_register);
mEmailView = (EditText)findViewById(R.id.email); mEmailView = (EditText) findViewById(R.id.email);
mUsernameView = (EditText) findViewById(R.id.username); mUsernameView = (EditText) findViewById(R.id.username);
mPasswordView = (EditText) findViewById(R.id.password); mPasswordView = (EditText) findViewById(R.id.password);
mConfirmPasswordView = (EditText)findViewById(R.id.confirm_password); mConfirmPasswordView = (EditText) findViewById(R.id.confirm_password);
Button mRegisterButton = (Button) findViewById(R.id.register_button); Button mRegisterButton = (Button) findViewById(R.id.register_button);
mRegisterButton.setOnClickListener(new OnClickListener() { mRegisterButton.setOnClickListener(new OnClickListener() {
...@@ -64,19 +64,19 @@ public class RegisterActivity extends AppCompatActivity { ...@@ -64,19 +64,19 @@ public class RegisterActivity extends AppCompatActivity {
boolean cancel = false; boolean cancel = false;
View focusView = null; View focusView = null;
if(TextUtils.isEmpty(email)) { if (TextUtils.isEmpty(email)) {
mEmailView.setError(getString(R.string.error_field_required)); mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView; focusView = mEmailView;
cancel = true; cancel = true;
} }
if(TextUtils.isEmpty(password)) { if (TextUtils.isEmpty(password)) {
mPasswordView.setError(getString(R.string.error_field_required)); mPasswordView.setError(getString(R.string.error_field_required));
focusView = mPasswordView; focusView = mPasswordView;
cancel = true; cancel = true;
} }
if(!password.equals(confirm_password)) { if (!password.equals(confirm_password)) {
mPasswordView.setError(getString(R.string.error_password_match)); mPasswordView.setError(getString(R.string.error_password_match));
mConfirmPasswordView.setError(getString(R.string.error_password_match)); mConfirmPasswordView.setError(getString(R.string.error_password_match));
focusView = mPasswordView; focusView = mPasswordView;
...@@ -101,7 +101,7 @@ public class RegisterActivity extends AppCompatActivity { ...@@ -101,7 +101,7 @@ public class RegisterActivity extends AppCompatActivity {
showProgress(false); showProgress(false);
NewUserResult result = response.body(); NewUserResult result = response.body();
if(result.isSuccess()) { if (result.isSuccess()) {
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class); Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(intent); startActivity(intent);
} else { } else {
...@@ -119,11 +119,11 @@ public class RegisterActivity extends AppCompatActivity { ...@@ -119,11 +119,11 @@ public class RegisterActivity extends AppCompatActivity {
} }
public void registerError(String field) { public void registerError(String field) {
if(field.equals("username")) { if (field.equals("username")) {
mUsernameView.setError(getString(R.string.error_username_taken)); mUsernameView.setError(getString(R.string.error_username_taken));
mUsernameView.requestFocus(); mUsernameView.requestFocus();
} }
if(field.equals("email")) { if (field.equals("email")) {
mEmailView.setError(getString(R.string.error_email_taken)); mEmailView.setError(getString(R.string.error_email_taken));
mEmailView.requestFocus(); mEmailView.requestFocus();
} }
......
...@@ -39,7 +39,7 @@ public class StallReviewActivity extends AppCompatActivity { ...@@ -39,7 +39,7 @@ public class StallReviewActivity extends AppCompatActivity {
body = (EditText) findViewById(R.id.rv_body); body = (EditText) findViewById(R.id.rv_body);
rating = (RatingBar) findViewById(R.id.rv_rating); rating = (RatingBar) findViewById(R.id.rv_rating);
if(editing) { if (editing) {
setTitle("Edit Stall Review"); setTitle("Edit Stall Review");
reviewId = getIntent().getIntExtra("REVIEW_ID", 0); reviewId = getIntent().getIntExtra("REVIEW_ID", 0);
title.setText(getIntent().getStringExtra("EDIT_TITLE")); title.setText(getIntent().getStringExtra("EDIT_TITLE"));
...@@ -61,7 +61,7 @@ public class StallReviewActivity extends AppCompatActivity { ...@@ -61,7 +61,7 @@ public class StallReviewActivity extends AppCompatActivity {
rv.setStallId(id); rv.setStallId(id);
rv.setUserId(AppUtils.getUserId()); rv.setUserId(AppUtils.getUserId());
if(editing) { if (editing) {
editReview(reviewId, rv); editReview(reviewId, rv);
} else { } else {
newReview(rv); newReview(rv);
......
...@@ -22,8 +22,8 @@ import retrofit2.Callback; ...@@ -22,8 +22,8 @@ import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
public class StallReviewAdapter extends BaseAdapter { public class StallReviewAdapter extends BaseAdapter {
private Activity context;
ArrayList<StallReview> stallReviews; ArrayList<StallReview> stallReviews;
private Activity context;
public StallReviewAdapter(Activity context, ArrayList<StallReview> stallReviews) { public StallReviewAdapter(Activity context, ArrayList<StallReview> stallReviews) {
this.context = context; this.context = context;
...@@ -59,9 +59,9 @@ public class StallReviewAdapter extends BaseAdapter { ...@@ -59,9 +59,9 @@ public class StallReviewAdapter extends BaseAdapter {
body.setText(sr.getBody()); body.setText(sr.getBody());
username.setText(sr.getUser()); username.setText(sr.getUser());
Button editButton = (Button)v.findViewById(R.id.edit_button); Button editButton = (Button) v.findViewById(R.id.edit_button);
Button deleteButton = (Button)v.findViewById(R.id.delete_button); Button deleteButton = (Button) v.findViewById(R.id.delete_button);
if(sr.getUserId() == AppUtils.getUserId()) { if (sr.getUserId() == AppUtils.getUserId()) {
editButton.setVisibility(View.VISIBLE); editButton.setVisibility(View.VISIBLE);
editButton.setOnClickListener(new View.OnClickListener() { editButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -81,7 +81,7 @@ public class StallReviewAdapter extends BaseAdapter { ...@@ -81,7 +81,7 @@ public class StallReviewAdapter extends BaseAdapter {
deleteButton.setOnClickListener(new View.OnClickListener() { deleteButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final StallViewActivity context = (StallViewActivity)StallReviewAdapter.this.context; final StallViewActivity context = (StallViewActivity) StallReviewAdapter.this.context;
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle("Confirm Delete") .setTitle("Confirm Delete")
.setMessage("Are you sure you want to delete your review? This cannot be undone.") .setMessage("Are you sure you want to delete your review? This cannot be undone.")
......
...@@ -75,7 +75,7 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -75,7 +75,7 @@ public class StallViewActivity extends AppCompatActivity {
description.setText(s.getDescription()); description.setText(s.getDescription());
//ImageView image = (ImageView) findViewById(R.id.stall_logo); //ImageView image = (ImageView) findViewById(R.id.stall_logo);
//Picasso.with(getApplicationContext()).load("http://" + getResources().getString(R.string.server_ip) + ":5000/static/uploads/"+ s.getImagePath()).fit().centerCrop().into(image); //Picasso.with(getApplicationContext()).load("http://" + getResources().getString(R.string.server_ip) + ":5000/static/uploads/"+ s.getImagePath()).fit().centerCrop().into(image);
favoriteCheckbox = (CheckBox)findViewById(R.id.favorite_checkbox); favoriteCheckbox = (CheckBox) findViewById(R.id.favorite_checkbox);
favoriteCheckbox.setOnClickListener(new View.OnClickListener() { favoriteCheckbox.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -175,18 +175,18 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -175,18 +175,18 @@ public class StallViewActivity extends AppCompatActivity {
public void onResponse(Call<List<StallReview>> call, Response<List<StallReview>> response) { public void onResponse(Call<List<StallReview>> call, Response<List<StallReview>> response) {
List<StallReview> newReviews = response.body(); List<StallReview> newReviews = response.body();
StallReview ownedReview = null; StallReview ownedReview = null;
for(StallReview review: newReviews) { for (StallReview review : newReviews) {
if(review.getUserId() == AppUtils.getUserId()) { if (review.getUserId() == AppUtils.getUserId()) {
ownedReview = review; ownedReview = review;
break; break;
} }
} }
reviews.clear(); reviews.clear();
if(ownedReview != null) { if (ownedReview != null) {
newReviews.remove(ownedReview); newReviews.remove(ownedReview);
reviews.add(ownedReview); reviews.add(ownedReview);
} }
findViewById(R.id.add_review_button).setVisibility(ownedReview != null || !AppUtils.isLoggedIn()? View.INVISIBLE: View.VISIBLE); findViewById(R.id.add_review_button).setVisibility(ownedReview != null || !AppUtils.isLoggedIn() ? View.INVISIBLE : View.VISIBLE);
reviews.addAll(newReviews); reviews.addAll(newReviews);
srAdapter.notifyDataSetChanged(); srAdapter.notifyDataSetChanged();
......
...@@ -23,21 +23,37 @@ public class DishReview { ...@@ -23,21 +23,37 @@ public class DishReview {
this.dish_id = dish_id; this.dish_id = dish_id;
} }
public int getId() { return id; } public int getId() {
return id;
}
public void setId(int id) { this.id = id; } public void setId(int id) {
this.id = id;
}
public String getTitle() { return title; } public String getTitle() {
return title;
}
public void setTitle(String title) { this.title = title; } public void setTitle(String title) {
this.title = title;
}
public String getBody() { return body; } public String getBody() {
return body;
}
public void setBody(String body) { this.body = body; } public void setBody(String body) {
this.body = body;
}
public float getRating() { return rating; } public float getRating() {
return rating;
}
public void setRating(float rating) { this.rating = rating; } public void setRating(float rating) {
this.rating = rating;
}
public String getUser() { public String getUser() {
return user; return user;
...@@ -47,12 +63,20 @@ public class DishReview { ...@@ -47,12 +63,20 @@ public class DishReview {
this.user = user; this.user = user;
} }
public int getUserId() { return user_id; } public int getUserId() {
return user_id;
}
public void setUserId(int user_id) { this.user_id = user_id; } public void setUserId(int user_id) {
this.user_id = user_id;
}
public int getDishId() { return dish_id; } public int getDishId() {
return dish_id;
}
public void setDishId(int dish_id) { this.dish_id = dish_id; } public void setDishId(int dish_id) {
this.dish_id = dish_id;
}
} }
...@@ -2,7 +2,10 @@ package com.canteeneo.entities; ...@@ -2,7 +2,10 @@ package com.canteeneo.entities;
public interface Filter { public interface Filter {
int getId(); int getId();
void setId(int id); void setId(int id);
String getName(); String getName();
void setName(String name); void setName(String name);
} }
...@@ -24,21 +24,37 @@ public class StallReview { ...@@ -24,21 +24,37 @@ public class StallReview {
this.stall_id = stall_id; this.stall_id = stall_id;
} }
public int getId() { return id; } public int getId() {
return id;
}
public void setId(int id) { this.id = id; } public void setId(int id) {
this.id = id;
}
public String getTitle() { return title; } public String getTitle() {
return title;
}
public void setTitle(String title) { this.title = title; } public void setTitle(String title) {
this.title = title;
}
public String getBody() { return body; } public String getBody() {
return body;
}
public void setBody(String body) { this.body = body; } public void setBody(String body) {
this.body = body;
}
public float getRating() { return rating; } public float getRating() {
return rating;
}
public void setRating(float rating) { this.rating = rating; } public void setRating(float rating) {
this.rating = rating;
}
public String getUser() { public String getUser() {
return user; return user;
...@@ -48,12 +64,20 @@ public class StallReview { ...@@ -48,12 +64,20 @@ public class StallReview {
this.user = user; this.user = user;
} }
public int getUserId() { return user_id; } public int getUserId() {
return user_id;
}
public void setUserId(int user_id) { this.user_id = user_id; } public void setUserId(int user_id) {
this.user_id = user_id;
}
public int getStallId() { return stall_id; } public int getStallId() {
return stall_id;
}
public void setStallId(int stall_id) { this.stall_id = stall_id; } public void setStallId(int stall_id) {
this.stall_id = stall_id;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment