After user selecting area, there is a function called checkCoverageGuest()
. This function checks whether selected area by the user is under coverage for that restaurantor not. If the restaurant is under coverage, then checkCoverageGuest()
will return true value. When there is no coverage for that restaurant, checkCoverageGuest()
will return false.
If the value is true then, it proceed to the next level which is checkout. If the value is false, the screen will display toast error message that the selected restaurant is not under coverage.
Right now, every this coming out from this function checkCoverageGuest()
as false.
Here is my code.
private boolean checkCoverageGuest() {
try {
String url;
if (appPrefs.getLanguage().equalsIgnoreCase("ar"))
url = LinksConstants.TEST_SERVER_URL
+ LinksConstants.SEARCH_COVERAGE_AREA;
else
url = LinksConstants.TEST_SERVER_URL
+ LinksConstants.SEARCH_COVERAGE_AREA;
Intent startingIntent = getIntent();
city_id = getIntent().getStringExtra("id");
RequestParams params = new RequestParams();
params.put("area", city_id);
NetworkRestClient.post(url, params, new JsonHttpResponseHandler() {
@Override
public void onStart() {
super.onStart();
progressActivity.showLoading();
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
progressActivity.showContent();
JSONObject[] restaurants_arr = null;
hasCoverageGuest = true;
try {
if (response != null) {
JSONArray restaurants = response.getJSONArray("restaurants");
// if restaurants deliver to that area
if (!restaurants.getString(0).equals("null")) {
restaurants_arr = new JSONObject[restaurants.length()];
int has_coverage = 1; // assume coverage is there..
for (int j = 0; j < Utils.cart_restaurants.size(); j++) {
RestaurantModel restaurant = Utils.cart_restaurants.get(j);
String restaurantCartID = restaurant.getId();
boolean found = false;
for (int i = 0; i < restaurants.length(); i++) {
restaurants_arr[i] = restaurants.getJSONObject(i);
String restaurantID = restaurants_arr[i].get("restaurant_id").toString();
if (restaurantCartID.equals(restaurantID)) {
found = true;
break;
}
} //end of inner for
if (found == false) {
Toast.makeText(CheckoutActivity.this, "There is no coverage for the Selected Area ", Toast.LENGTH_SHORT).show();
hasCoverageGuest = false;
break;
}
}
//end of outer for
} //end of if
else //if restaurants don't deliver to that area
{
hasCoverageGuest = false;
}
} // end of if response != null
} // end of try
catch (Exception ex) {
GSLogger.e(ex);
showError();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, String errorResponse, Throwable throwable) {
super.onFailure(statusCode, headers, errorResponse, throwable);
showError();
if (AppConstants.DEBUG_MODE)
showToast(errorResponse);
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
showError();
}
});
} catch (Exception ex) {
GSLogger.e(ex);
showError();
}
return hasCoverageGuest;
}
Your private boolean checkCoverageGuest()
method returns before public void onSuccess()
is executed, this is the reason for checkCoverageGuest()
always returning false.
If you need to execute something after you get the hasCoverageGuest
good value then excute it inside onSucess()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments