Commit a168d5e4 authored by Willard's avatar Willard

Make searching use filters

parent f9f1baee
......@@ -6,6 +6,7 @@ import com.testapp.entities.Dish;
import com.testapp.entities.DishType;
import com.testapp.entities.Location;
import java.util.ArrayList;
import java.util.List;
import okhttp3.ResponseBody;
......@@ -27,7 +28,12 @@ public interface CanteeneoApiInterface {
Call<CData> getAllBy(@Query("date") String date);
@GET("api/search/dish")
Call<List<Dish>> searchByName(@Query("name") String name);
Call<List<Dish>> searchByName(@Query("name") String name,
@Query("type_filters") String types,
@Query("cuisine_filters") String cuisines,
@Query("location_filters") String location,
@Query("min_price") int min_price,
@Query("max_price") int max_price);
@GET("api/locations")
Call<List<Location>> getLocations();
......
......@@ -283,8 +283,23 @@ public class NavDrawerActivity extends AppCompatActivity
return true;
}
private String getChecked(int layoutId) {
LinearLayout checkboxes = (LinearLayout)findViewById(layoutId);
String checked = "";
for(int i = 0; i < checkboxes.getChildCount(); i++) {
View v = checkboxes.getChildAt(i);
if(v instanceof CheckBox) {
CheckBox c = (CheckBox)v;
if(c.isChecked()) {
checked += c.getId();
}
}
}
return checked;
}
private void searchDish(String name) {
Call<List<Dish>> call = service.searchByName(name);
Call<List<Dish>> call = service.searchByName(name, getChecked(R.id.type_checkboxes), getChecked(R.id.cuisine_checkboxes), getChecked(R.id.location_checkboxes), 0, 1000);
call.enqueue(new Callback<List<Dish>>() {
@Override
public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
......
......@@ -8,6 +8,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListView;
import com.google.gson.Gson;
......@@ -97,8 +99,23 @@ public class SearchActivity extends AppCompatActivity {
});
}
private String getChecked(int layoutId) {
LinearLayout checkboxes = (LinearLayout)findViewById(layoutId);
String checked = "";
for(int i = 0; i < checkboxes.getChildCount(); i++) {
View v = checkboxes.getChildAt(i);
if(v instanceof CheckBox) {
CheckBox c = (CheckBox)v;
if(c.isChecked()) {
checked += c.getId();
}
}
}
return checked;
}
private void searchDish(String name) {
Call<List<Dish>> call = service.searchByName(name);
Call<List<Dish>> call = service.searchByName(name, getChecked(R.id.type_checkboxes), getChecked(R.id.cuisine_checkboxes), getChecked(R.id.location_checkboxes), 0, 1000);
call.enqueue(new Callback<List<Dish>>() {
@Override
public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
......
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