From b6997db6819f89568a4cec8fcffb8a8a5e2f37ee Mon Sep 17 00:00:00 2001 From: misaochan Date: Thu, 15 Dec 2016 15:22:41 +1300 Subject: [PATCH] Finish alertDialog code --- .../nrw/commons/upload/ExistingFileAsync.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/ExistingFileAsync.java b/app/src/main/java/fr/free/nrw/commons/upload/ExistingFileAsync.java index 29a23fc1c..257eb53d4 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/ExistingFileAsync.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/ExistingFileAsync.java @@ -3,6 +3,7 @@ package fr.free.nrw.commons.upload; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.os.AsyncTask; import android.util.Log; @@ -15,6 +16,7 @@ import java.util.ArrayList; import android.support.v7.app.AlertDialog; import fr.free.nrw.commons.CommonsApplication; +import fr.free.nrw.commons.contributions.ContributionsActivity; /** * Sends asynchronous queries to the Commons MediaWiki API to check that file doesn't already exist @@ -27,8 +29,6 @@ public class ExistingFileAsync extends AsyncTask { private String fileSHA1; private Context context; - private AlertDialog.Builder alertDialog; - public ExistingFileAsync(String fileSHA1, Context context) { super(); this.fileSHA1 = fileSHA1; @@ -38,7 +38,6 @@ public class ExistingFileAsync extends AsyncTask { @Override protected void onPreExecute() { super.onPreExecute(); - alertDialog = new AlertDialog.Builder(context); } @Override @@ -78,14 +77,25 @@ public class ExistingFileAsync extends AsyncTask { super.onPostExecute(fileExists); //TODO: Add Dialog here to tell user file exists, do you want to continue? Yes/No - alertDialog.setMessage("test"); - alertDialog.setCancelable(false); - alertDialog.setPositiveButton("ok", new DialogInterface.OnClickListener() { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + + builder.setMessage("This file already exists in Commons. Are you sure you want to proceed?") + .setTitle("Warning"); + builder.setPositiveButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); + //Go back to ContributionsActivity + Intent intent = new Intent(context, ContributionsActivity.class); + context.startActivity(intent); + } + + }); + builder.setNegativeButton("Yes", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + //No need to do anything, user remains on upload screen } }); - AlertDialog alertLogin = alertDialog.create(); - alertLogin.show(); + + AlertDialog dialog = builder.create(); + dialog.show(); } } \ No newline at end of file