Commit 08af01f0 authored by Willard's avatar Willard

Add dish favorites

parent cd1ca47a
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
android:theme="@style/AppTheme"/> android:theme="@style/AppTheme"/>
<activity android:name=".RegisterActivity"> <activity android:name=".RegisterActivity">
</activity> </activity>
<activity android:name=".AddStallReviewActivity">
</activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -7,7 +7,7 @@ import com.testapp.entities.DishType; ...@@ -7,7 +7,7 @@ import com.testapp.entities.DishType;
import com.testapp.entities.Location; import com.testapp.entities.Location;
import com.testapp.entities.NewUserResult; import com.testapp.entities.NewUserResult;
import com.testapp.entities.Stall; import com.testapp.entities.Stall;
import com.testapp.entities.StallFavoriteInfo; import com.testapp.entities.FavoriteInfo;
import com.testapp.entities.StallReview; import com.testapp.entities.StallReview;
import com.testapp.entities.Token; import com.testapp.entities.Token;
...@@ -34,6 +34,10 @@ public interface CanteeneoApiInterface { ...@@ -34,6 +34,10 @@ public interface CanteeneoApiInterface {
@Query("min_price") int min_price, @Query("min_price") int min_price,
@Query("max_price") int max_price); @Query("max_price") int max_price);
@FormUrlEncoded
@POST("api/users/new")
Call<NewUserResult> newUser(@Field("email") String email, @Field("username") String username, @Field("password") String password);
@GET("api/locations") @GET("api/locations")
Call<List<Location>> getLocations(); Call<List<Location>> getLocations();
...@@ -43,6 +47,16 @@ public interface CanteeneoApiInterface { ...@@ -43,6 +47,16 @@ public interface CanteeneoApiInterface {
@GET("api/cuisines") @GET("api/cuisines")
Call<List<Cuisine>> getCuisines(); Call<List<Cuisine>> getCuisines();
@FormUrlEncoded
@POST("api/dishes/{id}/favorites")
Call<FavoriteInfo> setDishFavorite(@Path("id") int id, @Field("favorited") boolean favorited);
@GET("api/dishes/{id}/favorites")
Call<FavoriteInfo> getDishFavorite(@Path("id") int id);
@POST("api/dishes/{id}/reviews")
Call<ResponseBody> newDishReview(@Path("id") int id, @Body DishReview review);
@GET("api/dishes/{id}/reviews") @GET("api/dishes/{id}/reviews")
Call<List<DishReview>> getDishReviews(@Path("id") int id); Call<List<DishReview>> getDishReviews(@Path("id") int id);
...@@ -54,21 +68,17 @@ public interface CanteeneoApiInterface { ...@@ -54,21 +68,17 @@ public interface CanteeneoApiInterface {
@FormUrlEncoded @FormUrlEncoded
@POST("api/stalls/{id}/favorites") @POST("api/stalls/{id}/favorites")
Call<StallFavoriteInfo> setStallFavorite(@Path("id") int id, @Field("favorited") boolean favorited); Call<FavoriteInfo> setStallFavorite(@Path("id") int id, @Field("favorited") boolean favorited);
@GET("api/stalls/{id}/favorites") @GET("api/stalls/{id}/favorites")
Call<StallFavoriteInfo> getStallFavorite(@Path("id") int id); Call<FavoriteInfo> getStallFavorite(@Path("id") int id);
@POST("api/stalls/{id}/reviews")
Call<ResponseBody> newStallReview(@Path("id") int id, @Body StallReview review);
@GET("api/stalls/{id}/dishes") @GET("api/stalls/{id}/dishes")
Call<List<Dish>> getDishesByStall(@Path("id") int id); Call<List<Dish>> getDishesByStall(@Path("id") int id);
@POST("api/dishes/{id}/reviews")
Call<ResponseBody> newDishReview(@Path("id") int id, @Body DishReview review);
@FormUrlEncoded
@POST("api/users/new")
Call<NewUserResult> newUser(@Field("email") String email, @Field("username") String username, @Field("password") String password);
@GET("api/token") @GET("api/token")
Call<Token> getToken(); Call<Token> getToken();
} }
...@@ -7,6 +7,7 @@ import android.support.v7.widget.Toolbar; ...@@ -7,6 +7,7 @@ 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.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
...@@ -14,6 +15,7 @@ import android.widget.Toast; ...@@ -14,6 +15,7 @@ import android.widget.Toast;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.testapp.entities.DishReview; import com.testapp.entities.DishReview;
import com.testapp.entities.FavoriteInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -27,6 +29,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -27,6 +29,7 @@ public class DishViewActivity extends AppCompatActivity {
private TextView dishStall; private TextView dishStall;
private ArrayList<DishReview> reviews = new ArrayList<>(); private ArrayList<DishReview> reviews = new ArrayList<>();
private DishReviewAdapter adapter; private DishReviewAdapter adapter;
private CheckBox favoriteCheckbox;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -41,6 +44,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -41,6 +44,7 @@ public class DishViewActivity extends AppCompatActivity {
setTitle("Dish Pls"); setTitle("Dish Pls");
Intent i = getIntent(); Intent i = getIntent();
final int id = i.getIntExtra("ID", 0);
TextView dishName = (TextView) findViewById(R.id.dish_name); TextView dishName = (TextView) findViewById(R.id.dish_name);
dishName.setText(i.getStringExtra("NAME")); dishName.setText(i.getStringExtra("NAME"));
TextView dishPrice = (TextView) findViewById(R.id.dish_price); TextView dishPrice = (TextView) findViewById(R.id.dish_price);
...@@ -61,6 +65,39 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -61,6 +65,39 @@ public class DishViewActivity extends AppCompatActivity {
}); });
} }
favoriteCheckbox = (CheckBox)findViewById(R.id.favorite_checkbox);
favoriteCheckbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Call<FavoriteInfo> favoriteCall = AppUtils.service.setDishFavorite(id, favoriteCheckbox.isChecked());
favoriteCall.enqueue(new Callback<FavoriteInfo>() {
@Override
public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) {
favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")");
}
@Override
public void onFailure(Call<FavoriteInfo> call, Throwable t) {
}
});
}
});
Call<FavoriteInfo> countCall = AppUtils.service.getDishFavorite(id);
countCall.enqueue(new Callback<FavoriteInfo>() {
@Override
public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) {
favoriteCheckbox.setChecked(response.body().isFavorited());
favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")");
}
@Override
public void onFailure(Call<FavoriteInfo> call, Throwable t) {
favoriteCheckbox.setText("Favorite (-1)");
}
});
Button addReviewBtn = (Button) findViewById(R.id.add_review_button); Button addReviewBtn = (Button) findViewById(R.id.add_review_button);
addReviewBtn.setOnClickListener(new View.OnClickListener() { addReviewBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -4,7 +4,6 @@ import android.content.Intent; ...@@ -4,7 +4,6 @@ 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.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
...@@ -12,12 +11,11 @@ import android.widget.CheckBox; ...@@ -12,12 +11,11 @@ import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.testapp.entities.Dish; import com.testapp.entities.Dish;
import com.testapp.entities.Stall; import com.testapp.entities.Stall;
import com.testapp.entities.StallFavoriteInfo; import com.testapp.entities.FavoriteInfo;
import com.testapp.entities.StallReview; import com.testapp.entities.StallReview;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -81,31 +79,31 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -81,31 +79,31 @@ public class StallViewActivity extends AppCompatActivity {
favoriteCheckbox.setOnClickListener(new View.OnClickListener() { favoriteCheckbox.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Call<StallFavoriteInfo> favoriteCall = AppUtils.service.setStallFavorite(id, favoriteCheckbox.isChecked()); Call<FavoriteInfo> favoriteCall = AppUtils.service.setStallFavorite(id, favoriteCheckbox.isChecked());
favoriteCall.enqueue(new Callback<StallFavoriteInfo>() { favoriteCall.enqueue(new Callback<FavoriteInfo>() {
@Override @Override
public void onResponse(Call<StallFavoriteInfo> call, Response<StallFavoriteInfo> response) { public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) {
favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")"); favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")");
} }
@Override @Override
public void onFailure(Call<StallFavoriteInfo> call, Throwable t) { public void onFailure(Call<FavoriteInfo> call, Throwable t) {
} }
}); });
} }
}); });
Call<StallFavoriteInfo> countCall = AppUtils.service.getStallFavorite(id); Call<FavoriteInfo> countCall = AppUtils.service.getStallFavorite(id);
countCall.enqueue(new Callback<StallFavoriteInfo>() { countCall.enqueue(new Callback<FavoriteInfo>() {
@Override @Override
public void onResponse(Call<StallFavoriteInfo> call, Response<StallFavoriteInfo> response) { public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) {
favoriteCheckbox.setChecked(response.body().isFavorited()); favoriteCheckbox.setChecked(response.body().isFavorited());
favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")"); favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")");
} }
@Override @Override
public void onFailure(Call<StallFavoriteInfo> call, Throwable t) { public void onFailure(Call<FavoriteInfo> call, Throwable t) {
favoriteCheckbox.setText("Favorite (-1)"); favoriteCheckbox.setText("Favorite (-1)");
} }
}); });
......
package com.testapp.entities; package com.testapp.entities;
public class StallFavoriteInfo { public class FavoriteInfo {
int count; int count;
boolean favorited; boolean favorited;
public StallFavoriteInfo(int count, boolean favorited) { public FavoriteInfo(int count, boolean favorited) {
this.count = count; this.count = count;
this.favorited = favorited; this.favorited = favorited;
} }
......
...@@ -72,11 +72,11 @@ ...@@ -72,11 +72,11 @@
android:textSize="18sp" android:textSize="18sp"
android:textColor="?android:attr/textColorLink" /> android:textColor="?android:attr/textColorLink" />
<Button <CheckBox
android:text="Favorite" android:text="Favorite"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/dish_favorite" android:id="@+id/favorite_checkbox"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="1" /> 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