Commit 49041c35 authored by lumisce's avatar lumisce

Add StallView

parent 8efb1d9a
...@@ -5,6 +5,7 @@ import com.testapp.entities.Dish; ...@@ -5,6 +5,7 @@ import com.testapp.entities.Dish;
import com.testapp.entities.DishReview; 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.Stall;
import com.testapp.entities.StallReview; import com.testapp.entities.StallReview;
import java.util.List; import java.util.List;
...@@ -40,4 +41,10 @@ public interface CanteeneoApiInterface { ...@@ -40,4 +41,10 @@ public interface CanteeneoApiInterface {
@GET("api/stalls/{id}/reviews") @GET("api/stalls/{id}/reviews")
Call<List<StallReview>> getStallReviews(@Path("id") int id); Call<List<StallReview>> getStallReviews(@Path("id") int id);
@GET("api/stalls/")
Call<Stall> getStallByName(@Query("name") String name);
@GET("api/stalls/{id}/dishes")
Call<List<Dish>> getDishesByStall(@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.TextView;
import com.testapp.entities.StallReview;
import java.util.ArrayList;
public class StallReviewAdapter extends BaseAdapter {
private Activity context;
ArrayList<StallReview> stallReviews;
public StallReviewAdapter(Activity context, ArrayList<StallReview> stallReviews) {
this.context = context;
this.stallReviews = stallReviews;
}
@Override
public int getCount() {
return stallReviews.size();
}
@Override
public StallReview getItem(int position) {
return stallReviews.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.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);
StallReview dr = stallReviews.get(position);
title.setText(dr.getTitle());
rating.setText(dr.getRating());
body.setText(dr.getBody());
// TODO set username
return v;
}
}
package com.testapp; package com.testapp;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; 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.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.testapp.entities.Dish;
import com.testapp.entities.Stall;
import com.testapp.entities.StallReview;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class StallViewActivity extends AppCompatActivity { public class StallViewActivity extends AppCompatActivity {
private int id;
private ArrayList<Dish> dishes = new ArrayList<>();
private ArrayList<StallReview> reviews = new ArrayList<>();
private StallReviewAdapter srAdapter;
private DishAdapter dAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -16,6 +40,36 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -16,6 +40,36 @@ public class StallViewActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
Intent i = getIntent();
String name = i.getStringExtra("NAME");
setTitle(name);
getStall(name);
ListView lvDishes = (ListView) findViewById(R.id.stall_dishes);
dAdapter = new DishAdapter(this, dishes);
getStallDishes(id);
lvDishes.setAdapter(dAdapter);
lvDishes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(StallViewActivity.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());
i.putExtra("STALLNAME", d.getStallName());
startActivity(i);
}
});
ListView lvReviews = (ListView) findViewById(R.id.stall_reviews);
srAdapter = new StallReviewAdapter(this, reviews);
lvReviews.setAdapter(srAdapter);
getStallReviews(id);
} }
@Override @Override
...@@ -28,4 +82,62 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -28,4 +82,62 @@ public class StallViewActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
private void getStall(String name) {
Call<Stall> call = AppUtils.service.getStallByName(name);
call.enqueue(new Callback<Stall>() {
@Override
public void onResponse(Call<Stall> call, Response<Stall> response) {
Stall s = response.body();
id = s.getId();
TextView location = (TextView) findViewById(R.id.stall_location);
location.setText(s.getLocation());
TextView description = (TextView) findViewById(R.id.stall_description);
description.setText(s.getDescription());
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);
}
@Override
public void onFailure(Call<Stall> call, Throwable t) {
}
});
}
private void getStallDishes(int id) {
Call<List<Dish>> call = AppUtils.service.getDishesByStall(id);
call.enqueue(new Callback<List<Dish>>() {
@Override
public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
List<Dish> newDishes = response.body();
dishes.clear();
dishes.addAll(newDishes);
dAdapter.notifyDataSetChanged();
}
@Override
public void onFailure(Call<List<Dish>> call, Throwable t) {
}
});
}
private void getStallReviews(int id) {
Call<List<StallReview>> call = AppUtils.service.getStallReviews(id);
call.enqueue(new Callback<List<StallReview>>() {
@Override
public void onResponse(Call<List<StallReview>> call, Response<List<StallReview>> response) {
List<StallReview> newReviews = response.body();
reviews.clear();
reviews.addAll(newReviews);
srAdapter.notifyDataSetChanged();
}
@Override
public void onFailure(Call<List<StallReview>> call, Throwable t) {
}
});
}
} }
...@@ -6,14 +6,16 @@ public class Stall { ...@@ -6,14 +6,16 @@ public class Stall {
String name; String name;
String description; String description;
int owner_id; int owner_id;
int location_id; String location;
String imagePath;
public Stall(int id, String name, String description, int owner_id, int location_id) { public Stall(int id, String name, String description, int owner_id, String location, String imagePath) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.owner_id = owner_id; this.owner_id = owner_id;
this.location_id = location_id; this.location = location;
this.imagePath = imagePath;
} }
public int getId() { public int getId() {
...@@ -48,11 +50,19 @@ public class Stall { ...@@ -48,11 +50,19 @@ public class Stall {
this.owner_id = owner_id; this.owner_id = owner_id;
} }
public int getLocation_id() { public String getLocation() {
return location_id; return location;
} }
public void setLocation_id(int location_id) { public void setLocation(String location) {
this.location_id = location_id; this.location = location;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
} }
} }
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