Commit ca043d91 authored by lumisce's avatar lumisce

Add AddDishReview

parent 49041c35
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
<activity <activity
android:name=".StallViewActivity" android:name=".StallViewActivity"
android:label="@string/title_activity_stall_view" android:label="@string/title_activity_stall_view"
android:theme="@style/AppTheme" />
<activity
android:name=".AddDishReviewActivity"
android:label="@string/title_activity_add_dish_review"
android:theme="@style/AppTheme"></activity> android:theme="@style/AppTheme"></activity>
</application> </application>
......
package com.testapp;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Toast;
import com.testapp.entities.DishReview;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class AddDishReviewActivity extends AppCompatActivity {
private EditText title;
private EditText body;
private RatingBar rating;
private int id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_review);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("Add Dish Review");
title = (EditText) findViewById(R.id.rv_title);
body = (EditText) findViewById(R.id.rv_body);
rating = (RatingBar) findViewById(R.id.rv_rating);
id = getIntent().getIntExtra("ID", 0);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DishReview rv = new DishReview();
rv.setTitle(title.getText().toString());
rv.setBody(body.getText().toString());
rv.setRating((int) rating.getRating());
//todo add user_id
sendReview(id, rv);
}
});
}
private void sendReview(int id, DishReview rv) {
Call<ResponseBody> call = AppUtils.service.newDishReview(id, rv);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
finish();
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(getApplicationContext(), "Posting review failed", Toast.LENGTH_SHORT);
}
});
}
}
...@@ -13,7 +13,9 @@ import java.util.List; ...@@ -13,7 +13,9 @@ import java.util.List;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path; import retrofit2.http.Path;
import retrofit2.http.Query; import retrofit2.http.Query;
...@@ -47,4 +49,7 @@ public interface CanteeneoApiInterface { ...@@ -47,4 +49,7 @@ public interface CanteeneoApiInterface {
@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, DishReview review);
} }
...@@ -6,9 +6,11 @@ import android.support.v7.app.AppCompatActivity; ...@@ -6,9 +6,11 @@ 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.Button;
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.DishReview; import com.testapp.entities.DishReview;
...@@ -59,6 +61,17 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -59,6 +61,17 @@ public class DishViewActivity extends AppCompatActivity {
}); });
} }
Button addReviewBtn = (Button) findViewById(R.id.add_review_button);
addReviewBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(DishViewActivity.this, AddDishReviewActivity.class);
i.putExtra("ID", i.getIntExtra("ID", 0));
startActivityForResult(i, 0);
}
});
ListView lv = (ListView) findViewById(R.id.dish_reviews); ListView lv = (ListView) findViewById(R.id.dish_reviews);
adapter = new DishReviewAdapter(this, reviews); adapter = new DishReviewAdapter(this, reviews);
lv.setAdapter(adapter); lv.setAdapter(adapter);
...@@ -101,4 +114,12 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -101,4 +114,12 @@ public class DishViewActivity extends AppCompatActivity {
}); });
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Review Added", Toast.LENGTH_SHORT);
}
}
}
} }
...@@ -9,6 +9,9 @@ public class DishReview { ...@@ -9,6 +9,9 @@ public class DishReview {
int user_id; int user_id;
int dish_id; int dish_id;
public DishReview() {
}
public DishReview(int id, String title, String body, int rating, int user_id, int dish_id) { public DishReview(int id, String title, String body, int rating, int user_id, int dish_id) {
this.id = id; this.id = id;
this.title = title; this.title = title;
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.testapp.AddDishReviewActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_add_review" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.testapp.AddDishReviewActivity"
tools:showIn="@layout/activity_add_review">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rv_title"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Title" />
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rv_rating"
android:layout_below="@+id/rv_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:numStars="10"
android:stepSize="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="400dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/rv_body"
android:layout_below="@+id/rv_rating"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
...@@ -43,4 +43,5 @@ ...@@ -43,4 +43,5 @@
</string-array> </string-array>
<string name="title_activity_blahblah">blahblah</string> <string name="title_activity_blahblah">blahblah</string>
<string name="title_activity_stall_view">StallViewActivity</string> <string name="title_activity_stall_view">StallViewActivity</string>
<string name="title_activity_add_dish_review">AddDishReviewActivity</string>
</resources> </resources>
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