Commit 70855ed8 authored by Willard's avatar Willard

Hide "Add Review" button and disable favorite button when on guest mode

parent 6d8f41a2
...@@ -68,6 +68,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -68,6 +68,7 @@ public class DishViewActivity extends AppCompatActivity {
} }
favoriteCheckbox = (CheckBox)findViewById(R.id.favorite_checkbox); favoriteCheckbox = (CheckBox)findViewById(R.id.favorite_checkbox);
favoriteCheckbox.setEnabled(AppUtils.isLoggedIn());
favoriteCheckbox.setOnClickListener(new View.OnClickListener() { favoriteCheckbox.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -75,7 +76,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -75,7 +76,7 @@ public class DishViewActivity extends AppCompatActivity {
favoriteCall.enqueue(new Callback<FavoriteInfo>() { favoriteCall.enqueue(new Callback<FavoriteInfo>() {
@Override @Override
public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) { public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) {
favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")"); favoriteCheckbox.setText(response.body().getCount() + " users favorited this");
} }
@Override @Override
...@@ -91,12 +92,12 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -91,12 +92,12 @@ public class DishViewActivity extends AppCompatActivity {
@Override @Override
public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> 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(response.body().getCount() + " users favorited this");
} }
@Override @Override
public void onFailure(Call<FavoriteInfo> call, Throwable t) { public void onFailure(Call<FavoriteInfo> call, Throwable t) {
favoriteCheckbox.setText("Favorite (-1)"); favoriteCheckbox.setText("-");
} }
}); });
...@@ -151,7 +152,7 @@ public class DishViewActivity extends AppCompatActivity { ...@@ -151,7 +152,7 @@ public class DishViewActivity extends AppCompatActivity {
newReviews.remove(ownedReview); newReviews.remove(ownedReview);
reviews.add(ownedReview); reviews.add(ownedReview);
} }
findViewById(R.id.add_review_button).setVisibility(ownedReview != null? View.INVISIBLE: View.VISIBLE); findViewById(R.id.add_review_button).setVisibility(ownedReview != null || !AppUtils.isLoggedIn()? View.INVISIBLE: View.VISIBLE);
reviews.addAll(newReviews); reviews.addAll(newReviews);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
......
...@@ -9,15 +9,13 @@ import android.view.View; ...@@ -9,15 +9,13 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
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 android.widget.Toast;
import com.squareup.picasso.Picasso;
import com.testapp.entities.Dish; import com.testapp.entities.Dish;
import com.testapp.entities.Stall;
import com.testapp.entities.FavoriteInfo; import com.testapp.entities.FavoriteInfo;
import com.testapp.entities.Stall;
import com.testapp.entities.StallReview; import com.testapp.entities.StallReview;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -85,7 +83,7 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -85,7 +83,7 @@ public class StallViewActivity extends AppCompatActivity {
favoriteCall.enqueue(new Callback<FavoriteInfo>() { favoriteCall.enqueue(new Callback<FavoriteInfo>() {
@Override @Override
public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) { public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> response) {
favoriteCheckbox.setText("Favorite (" + response.body().getCount() + ")"); favoriteCheckbox.setText(response.body().getCount() + " users favorited this");
} }
@Override @Override
...@@ -101,12 +99,12 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -101,12 +99,12 @@ public class StallViewActivity extends AppCompatActivity {
@Override @Override
public void onResponse(Call<FavoriteInfo> call, Response<FavoriteInfo> 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(response.body().getCount() + " users favorited this");
} }
@Override @Override
public void onFailure(Call<FavoriteInfo> call, Throwable t) { public void onFailure(Call<FavoriteInfo> call, Throwable t) {
favoriteCheckbox.setText("Favorite (-1)"); favoriteCheckbox.setText("-");
} }
}); });
...@@ -188,7 +186,7 @@ public class StallViewActivity extends AppCompatActivity { ...@@ -188,7 +186,7 @@ public class StallViewActivity extends AppCompatActivity {
newReviews.remove(ownedReview); newReviews.remove(ownedReview);
reviews.add(ownedReview); reviews.add(ownedReview);
} }
findViewById(R.id.add_review_button).setVisibility(ownedReview != null? View.INVISIBLE: View.VISIBLE); findViewById(R.id.add_review_button).setVisibility(ownedReview != null || !AppUtils.isLoggedIn()? View.INVISIBLE: View.VISIBLE);
reviews.addAll(newReviews); reviews.addAll(newReviews);
srAdapter.notifyDataSetChanged(); srAdapter.notifyDataSetChanged();
......
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