Skip to content

Commit

Permalink
Fix #865 - Don't show success dialog when OBA API issue report fails
Browse files Browse the repository at this point in the history
* The communication failure case wasn't being handled properly in ReportProblemFragmentBase.  This may have partially been due to a somewhat misnamed callback ("onSendReport()" instead of "onReportSent()".  That callback should only happen if communication with the server is successful, and instead for non-Open311 issue reports (i.e., sending to OBA REST API) it was called when the loader was started (i.e., before the API request happens).  This patch moves the callback to onLoadFinished when success is confirmed and also renames the callback to be clearer in intent.
* Additionally, the success case of OBA REST API issue reporting in ReportProblemFragmentBase wasn't handled correctly.  Old logic from pre-Open311 support was being used that simply popped the fragment off the backstack with the mGoBackHandler (the old issue report UI was a single fragment).  This behavior was hidden by the above bug that triggered the success dialog (and then activity finishing) upon success or failure of API request.  This patch removes that old logic and replaces it with the correct callback to the listener.
  • Loading branch information
barbeau committed May 22, 2018
1 parent f06f71f commit cac5325
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public void onFocusChanged(BikeRentalStation bikeRentalStation) {
}

@Override
public void onSendReport() {
public void onReportSent() {
(new ReportSuccessDialog()).show(getSupportFragmentManager(), ReportSuccessDialog.TAG);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void onServiceRequestTaskCompleted(ServiceRequestResponse response) {
showProgressDialog(false);

if (response.isSuccess()) {
mCallback.onSendReport();
mCallback.onReportSent();
} else {
String message = response.getErrorMessage();
if (TextUtils.isEmpty(message)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
Expand Down Expand Up @@ -155,12 +154,7 @@ protected void sendReport() {

ObaAnalytics.reportEventWithCategory(ObaAnalytics.ObaEventCategory.SUBMIT.toString(),
getString(R.string.analytics_action_problem), getString(R.string.analytics_label_report_problem));

//If the activity implements the callback, then notify
if (mCallback != null) {
mCallback.onSendReport();
}
}
}

@Override
public Loader<ObaResponse> onCreateLoader(int id, Bundle args) {
Expand All @@ -172,8 +166,10 @@ public void onLoadFinished(Loader<ObaResponse> loader, ObaResponse response) {
UIUtils.showProgress(this, false);

if ((response != null) && (response.getCode() == ObaApi.OBA_OK)) {
// Manage the fragment back stack
mGoBackHandler.postDelayed(mGoBack, 100);
// If the activity implements the callback, then notify of successful report
if (mCallback != null) {
mCallback.onReportSent();
}
} else {
Toast.makeText(getActivity(), R.string.report_problem_error, Toast.LENGTH_LONG).show();
}
Expand All @@ -184,14 +180,6 @@ public void onLoaderReset(Loader<ObaResponse> loader) {
UIUtils.showProgress(this, false);
}

final Handler mGoBackHandler = new Handler();

final Runnable mGoBack = new Runnable() {
public void run() {
getActivity().getSupportFragmentManager().popBackStack();
}
};

//
// Report loader
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
public interface ReportProblemFragmentCallback {

/**
* Called when the problem submitted
* Called when the problem report was successfully submitted.
* Callback mechanism implemented as described in Android best-practices documentation:
* http://developer.android.com/training/basics/fragments/communicating.html
*/
void onSendReport();
void onReportSent();
}

0 comments on commit cac5325

Please sign in to comment.