Commit 8bd0b903 authored by lumisce's avatar lumisce

Add dish review, remove dish location

parent 1dadb1d9
...@@ -2,13 +2,18 @@ package com.testapp; ...@@ -2,13 +2,18 @@ package com.testapp;
import com.testapp.entities.Cuisine; import com.testapp.entities.Cuisine;
import com.testapp.entities.Dish; import com.testapp.entities.Dish;
import com.testapp.entities.DishReview;
import com.testapp.entities.DishType; import com.testapp.entities.DishType;
import com.testapp.entities.Location; import com.testapp.entities.Location;
import com.testapp.entities.StallReview;
import java.util.List; import java.util.List;
import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query; import retrofit2.http.Query;
public interface CanteeneoApiInterface { public interface CanteeneoApiInterface {
...@@ -29,4 +34,10 @@ public interface CanteeneoApiInterface { ...@@ -29,4 +34,10 @@ public interface CanteeneoApiInterface {
@GET("api/cuisines") @GET("api/cuisines")
Call<List<Cuisine>> getCuisines(); Call<List<Cuisine>> getCuisines();
@GET("api/dishes/{id}/reviews")
Call<List<DishReview>> getDishReviews(@Path("id") int id);
@GET("api/stalls/{id}/reviews")
Call<List<StallReview>> getStallReviews(@Path("id") int id);
} }
package com.testapp;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.testapp.entities.Dish;
import com.testapp.entities.DishReview;
import java.util.ArrayList;
public class DishReviewAdapter extends BaseAdapter {
private Activity context;
ArrayList<DishReview> dishReviews;
public DishReviewAdapter(Activity context, ArrayList<DishReview> dishReviews) {
this.context = context;
this.dishReviews = dishReviews;
}
@Override
public int getCount() {
return dishReviews.size();
}
@Override
public DishReview getItem(int position) {
return dishReviews.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = context.getLayoutInflater().inflate(R.layout.dish_review_row, null);
TextView title = (TextView) v.findViewById(R.id.drv_title);
TextView rating = (TextView) v.findViewById(R.id.drv_rating);
TextView body = (TextView) v.findViewById(R.id.drv_body);
TextView username = (TextView) v.findViewById(R.id.drv_username);
DishReview dr = dishReviews.get(position);
title.setText(dr.getTitle());
rating.setText(dr.getRating());
body.setText(dr.getBody());
// TODO set username
return v;
}
}
...@@ -6,11 +6,23 @@ import android.support.v7.app.AppCompatActivity; ...@@ -6,11 +6,23 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.testapp.entities.DishReview;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DishViewActivity extends AppCompatActivity { public class DishViewActivity extends AppCompatActivity {
private TextView dishStall; private TextView dishStall;
private ArrayList<DishReview> reviews = new ArrayList<>();
private DishReviewAdapter adapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -31,8 +43,6 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -31,8 +43,6 @@ public class DishViewActivity extends AppCompatActivity {
dishPrice.setText(i.getStringExtra("PRICE")); dishPrice.setText(i.getStringExtra("PRICE"));
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"));
TextView dishLocation = (TextView) findViewById(R.id.dish_location);
// TODO setDishLocation
dishStall = (TextView) findViewById(R.id.dish_stall); dishStall = (TextView) findViewById(R.id.dish_stall);
dishStall.setText(i.getStringExtra("STALLNAME")); dishStall.setText(i.getStringExtra("STALLNAME"));
...@@ -44,6 +54,10 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -44,6 +54,10 @@ public class DishViewActivity extends AppCompatActivity {
} }
}); });
} }
ListView lv = (ListView) findViewById(R.id.dish_reviews);
adapter = new DishReviewAdapter(this, reviews);
lv.setAdapter(adapter);
} }
public void visitStall() { public void visitStall() {
...@@ -64,4 +78,22 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -64,4 +78,22 @@ public class DishViewActivity extends AppCompatActivity {
} }
} }
private void getDishReviews(int id) {
Call<List<DishReview>> call = AppUtils.service.getDishReviews(id);
call.enqueue(new Callback<List<DishReview>>() {
@Override
public void onResponse(Call<List<DishReview>> call, Response<List<DishReview>> response) {
List<DishReview> newDishes = response.body();
reviews.clear();
reviews.addAll(newDishes);
adapter.notifyDataSetChanged();
}
@Override
public void onFailure(Call<List<DishReview>> call, Throwable t) {
}
});
}
} }
...@@ -69,14 +69,6 @@ ...@@ -69,14 +69,6 @@
android:clickable="true" android:clickable="true"
android:onClick="visitStall"/> android:onClick="visitStall"/>
<TextView
android:text="Location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dish_location"
android:paddingTop="5dp"
android:layout_weight="1" />
<Button <Button
android:text="Favorite" android:text="Favorite"
android:layout_width="match_parent" android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title"
android:id="@+id/drv_title"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Rating"
android:id="@+id/drv_rating"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/drv_body"
android:layout_below="@+id/drv_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:inputType="textMultiLine" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="username"
android:id="@+id/drv_username"
android:layout_below="@+id/drv_body"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
\ No newline at end of file
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