Commit afd1dddb authored by lumisce's avatar lumisce

Add data to DishView

parent fff5654f
......@@ -25,7 +25,7 @@ public class DishAdapter extends BaseAdapter {
}
@Override
public Object getItem(int position) {
public Dish getItem(int position) {
return dishes.get(position);
}
......
......@@ -5,10 +5,13 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class DishViewActivity extends AppCompatActivity {
private TextView dishStall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -20,14 +23,32 @@ public class DishViewActivity extends AppCompatActivity {
getSupportActionBar().setDisplayShowHomeEnabled(true);
setTitle("Dish Pls");
Intent i = getIntent();
TextView dishStall = (TextView) findViewById(R.id.dish_stall);
TextView dishName = (TextView) findViewById(R.id.dish_name);
dishName.setText(i.getStringExtra("NAME"));
TextView dishPrice = (TextView) findViewById(R.id.dish_price);
dishPrice.setText(i.getStringExtra("PRICE"));
TextView dishDesc = (TextView) findViewById(R.id.dish_desc);
dishDesc.setText(i.getStringExtra("DESCRIPTION"));
TextView dishLocation = (TextView) findViewById(R.id.dish_location);
// TODO setDishLocation
dishStall = (TextView) findViewById(R.id.dish_stall);
dishStall.setText(i.getStringExtra("STALLNAME"));
if (dishStall != null) {
dishStall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
visitStall();
}
});
}
}
public void visitStall() {
Intent intent = new Intent(this, StallViewActivity.class);
intent.putExtra("NAME", dishStall.getText());
startActivity(intent);
}
......
......@@ -16,6 +16,7 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListView;
......@@ -106,6 +107,25 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
populateFilter(service.getDishTypes(), R.id.type_checkboxes);
populateFilter(service.getCuisines(), R.id.cuisine_checkboxes);
populateFilter(service.getLocations(), R.id.location_checkboxes);
ListView lv = (ListView) findViewById(R.id.listView);
adapter = new DishAdapter(this, dishes);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(NavDrawerActivity.this, DishViewActivity.class);
Dish d = dishes.get(position);
i.putExtra("ID", d.getId());
i.putExtra("NAME", d.getName());
i.putExtra("PRICE", d.getPrice());
i.putExtra("IMAGE", d.getImagePath());
i.putExtra("DESCRIPTION", d.getDescription());
// TODO i.putExtra("LOCATION", getStall(stallname).getLocation)?????????????
i.putExtra("STALLNAME", d.getStallName());
startActivity(i);
}
});
}
public <T extends Filter> void populateFilter(Call<List<T>> call, int layout_id) {
......@@ -134,18 +154,6 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
}
public void goToSearchPage(String query) {
String dishName = query;
ListView lv = (ListView) findViewById(R.id.listView);
adapter = new DishAdapter(this, dishes);
lv.setAdapter(adapter);
searchDish(dishName);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
......@@ -168,9 +176,7 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
@Override
public boolean onQueryTextSubmit(String query) {
goToSearchPage(query);
searchDish(query);
return false;
}
......
......@@ -7,6 +7,7 @@ public class Dish {
int id;
String name;
double price;
String description;
@SerializedName("image_path")
String imagePath;
......@@ -14,11 +15,12 @@ public class Dish {
@SerializedName("stall_name")
String stallName;
public Dish(int id, String name, double price, String stallName) {
public Dish(int id, String name, double price, String stallName, String description) {
this.id = id;
this.name = name;
this.price = price;
this.stallName = stallName;
this.description = description;
}
public int getId() {
......@@ -60,4 +62,12 @@ public class Dish {
public void setStallName(String stallName) {
this.stallName = stallName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
......@@ -47,7 +47,7 @@
android:text="Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:id="@+id/dish_name"
android:layout_weight="2"
android:textSize="18sp" />
......@@ -55,7 +55,7 @@
android:text="Price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView6"
android:id="@+id/dish_price"
android:layout_weight="1"
android:paddingTop="5dp" />
......@@ -73,7 +73,7 @@
android:text="Location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView8"
android:id="@+id/dish_location"
android:paddingTop="5dp"
android:layout_weight="1" />
......
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