Commit ad5aa333 authored by Willard's avatar Willard

Fix adding dish review

parent 08af01f0
...@@ -43,8 +43,6 @@ ...@@ -43,8 +43,6 @@
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
...@@ -38,7 +38,7 @@ public class AddDishReviewActivity extends AppCompatActivity { ...@@ -38,7 +38,7 @@ public class AddDishReviewActivity extends AppCompatActivity {
rating = (RatingBar) findViewById(R.id.rv_rating); rating = (RatingBar) findViewById(R.id.rv_rating);
id = getIntent().getIntExtra("ID", 0); id = getIntent().getIntExtra("ID", 0);
Toast.makeText(getApplicationContext(), id + "", Toast.LENGTH_SHORT).show();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -47,8 +47,8 @@ public class AddDishReviewActivity extends AppCompatActivity { ...@@ -47,8 +47,8 @@ public class AddDishReviewActivity extends AppCompatActivity {
rv.setTitle(title.getText().toString()); rv.setTitle(title.getText().toString());
rv.setBody(body.getText().toString()); rv.setBody(body.getText().toString());
rv.setRating((int) rating.getRating()); rv.setRating((int) rating.getRating());
rv.setDishId(id);
//todo add user_id rv.setUserId(AppUtils.userId);
sendReview(id, rv); sendReview(id, rv);
} }
...@@ -60,8 +60,9 @@ public class AddDishReviewActivity extends AppCompatActivity { ...@@ -60,8 +60,9 @@ public class AddDishReviewActivity extends AppCompatActivity {
call.enqueue(new Callback<ResponseBody>() { call.enqueue(new Callback<ResponseBody>() {
@Override @Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(getApplicationContext(), "Review posted!", Toast.LENGTH_SHORT); setResult(RESULT_OK);
//finish(); finish();
} }
@Override @Override
......
...@@ -25,6 +25,7 @@ public class AppUtils { ...@@ -25,6 +25,7 @@ public class AppUtils {
private static Context c; private static Context c;
public static String username = ""; public static String username = "";
public static String password = ""; public static String password = "";
public static int userId = -1;
public static boolean isNetworkAvailable(Context c) { public static boolean isNetworkAvailable(Context c) {
ConnectivityManager connectivity =(ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager connectivity =(ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
......
...@@ -31,6 +31,8 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -31,6 +31,8 @@ public class DishViewActivity extends AppCompatActivity {
private DishReviewAdapter adapter; private DishReviewAdapter adapter;
private CheckBox favoriteCheckbox; private CheckBox favoriteCheckbox;
private int id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -44,7 +46,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -44,7 +46,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); 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);
...@@ -103,7 +105,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -103,7 +105,7 @@ public class DishViewActivity extends AppCompatActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent i = new Intent(DishViewActivity.this, AddDishReviewActivity.class); Intent i = new Intent(DishViewActivity.this, AddDishReviewActivity.class);
i.putExtra("ID", i.getIntExtra("ID", 0)); i.putExtra("ID", id);
startActivityForResult(i, 0); startActivityForResult(i, 0);
} }
}); });
...@@ -154,7 +156,8 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -154,7 +156,8 @@ public class DishViewActivity extends AppCompatActivity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) { if (requestCode == 0) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
Toast.makeText(this, "Review Added", Toast.LENGTH_SHORT); Toast.makeText(this, "Review Added", Toast.LENGTH_SHORT).show();
getDishReviews(id);
} }
} }
} }
......
...@@ -129,6 +129,7 @@ public class LoginActivity extends AppCompatActivity { ...@@ -129,6 +129,7 @@ public class LoginActivity extends AppCompatActivity {
Toast.makeText(LoginActivity.this, "Invalid credentials!", Toast.LENGTH_LONG).show(); Toast.makeText(LoginActivity.this, "Invalid credentials!", Toast.LENGTH_LONG).show();
} else { } else {
Toast.makeText(LoginActivity.this, "Logged in as " + AppUtils.username + " successfully.", Toast.LENGTH_LONG).show(); Toast.makeText(LoginActivity.this, "Logged in as " + AppUtils.username + " successfully.", Toast.LENGTH_LONG).show();
AppUtils.userId = response.body().getId();
Intent intent = new Intent(LoginActivity.this, NavDrawerActivity.class); Intent intent = new Intent(LoginActivity.this, NavDrawerActivity.class);
startActivity(intent); startActivity(intent);
} }
......
package com.testapp.entities; package com.testapp.entities;
public class Token { public class Token {
String token; int duration; int id;
public Token(String token, int duration) { String token;
int duration;
public Token(int id, String token, int duration) {
this.id = id;
this.token = token; this.token = token;
this.duration = duration; this.duration = duration;
} }
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public String getToken() { public String getToken() {
return token; return token;
} }
...@@ -14,4 +26,12 @@ public class Token { ...@@ -14,4 +26,12 @@ public class Token {
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
} }
\ No newline at end of file
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
android:hint="Title" /> android:hint="Title" />
<RatingBar <RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/rv_rating" android:id="@+id/rv_rating"
android:layout_below="@+id/rv_title" android:layout_below="@+id/rv_title"
android:layout_alignParentLeft="true" android:layout_centerHorizontal="true"
android:layout_alignParentStart="true"
android:numStars="5" android:numStars="5"
android:stepSize=".5" /> android:stepSize=".5"
android:layout_width="wrap_content"/>
<EditText <EditText
android:layout_width="match_parent" android:layout_width="match_parent"
......
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