Commit ad5aa333 authored by Willard's avatar Willard

Fix adding dish review

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