Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

Commit

Permalink
OAQ
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Jan 2, 2016
1 parent 0d85d43 commit b010953
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions app/src/main/java/rikka/searchbyimage/ui/UploadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,25 @@ public class UploadActivity extends AppCompatActivity {
public final static int SITE_TINEYE = 3;
public final static int SITE_SAUCENAO = 4;

private class Error {
public String title;
public String message;

Error(String title, String message) {
this.title = title;
this.message = message;
}
}

private class HttpUpload {
public String url;
public String html;
public String uploadUrl;
public int siteId;
public Error error;

HttpUpload() {

HttpUpload(Error error) {
this.error = error;
}

HttpUpload(String uploadUrl, String url, String html, int siteId) {
Expand Down Expand Up @@ -149,13 +160,13 @@ protected HttpUpload doInBackground(Uri... imageUrl) {
}
} catch (UnknownHostException e) {
e.printStackTrace();
responseUri = getString(R.string.unknown_host_exception) + "\n" + getExceptionText(e);
return new HttpUpload(new Error(getString(R.string.unknown_host_exception), getExceptionText(e)));
} catch (SocketTimeoutException e) {
e.printStackTrace();
responseUri = getString(R.string.timeout_exception) + "\n" + getExceptionText(e);
return new HttpUpload(new Error(getString(R.string.timeout_exception), getExceptionText(e)));
} catch (IOException e) {
e.printStackTrace();
responseUri = getString(R.string.socket_exception) + "\n" + getExceptionText(e);
return new HttpUpload(new Error(getString(R.string.socket_exception), getExceptionText(e)));
}

return new HttpUpload(uploadUri, responseUri, httpRequest.getHtml(), siteId);
Expand All @@ -175,6 +186,19 @@ private String getExceptionText(Exception e) {

protected void onPostExecute(HttpUpload result) {
if (result.url == null) {

AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setMessage(result.error.message);
builder.setTitle(result.error.title);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
});

builder.show();

mProgressDialog.dismiss();
return;
}
Expand Down Expand Up @@ -226,18 +250,6 @@ protected void onPostExecute(HttpUpload result) {
mProgressDialog.dismiss();
finish();

} else {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setMessage(result.url);
builder.setTitle(R.string.something_wrong);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
});

builder.show();
}
}
}
Expand Down

0 comments on commit b010953

Please sign in to comment.