-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-correzzione errore autenticazione #60
- Loading branch information
Showing
3 changed files
with
36 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
|
||
import org.json.JSONObject; | ||
|
||
import it.gaiacri.mobile.Accesso; | ||
import it.gaiacri.mobile.R; | ||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
|
||
public class ErrorJson { | ||
|
||
|
@@ -21,14 +23,23 @@ public static int Controllo(String ris,Activity context,JSONObject json){ | |
return 2; | ||
}else{ | ||
if(ris.startsWith("Errore ")){ | ||
ProblemaApi(ris.substring(7),context,json); | ||
return 3; | ||
Log.d("Errore",json.optJSONObject("errore").optString("codice")); | ||
Log.d("Errore", ""+ ("1010".equals(json.optJSONObject("errore").optString("codice")))); | ||
if("1010".equals(json.optJSONObject("errore").optString("codice"))){ | ||
Log.d("si", "YEP"); | ||
Intent myIntent = new Intent(context, Accesso.class); | ||
context.startActivity(myIntent); | ||
context.finish(); | ||
}else{ | ||
ProblemaApi(ris.substring(7),context,json); | ||
return 3; | ||
} | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* | ||
* @param context Utilizzato per generare il Dialog | ||
|
@@ -39,44 +50,44 @@ public static AlertDialog.Builder AssenzaInternet(final Activity context){ | |
miaAlert.setMessage(R.string.error_internet); | ||
miaAlert.setCancelable(false); | ||
miaAlert.setNegativeButton(R.string.error_internet_no, new DialogInterface.OnClickListener() { | ||
public void onClick(DialogInterface dialog, int id) { | ||
context.setResult(100); | ||
context.finish(); | ||
} | ||
}); | ||
public void onClick(DialogInterface dialog, int id) { | ||
context.setResult(100); | ||
context.finish(); | ||
} | ||
}); | ||
return miaAlert; | ||
} | ||
|
||
/** | ||
* | ||
* @param errore Stringa che indica il tipo di errore che poi verra mostrato all'utente | ||
* @param context Utilizzato per creare il Dialog | ||
* @param json Contiene la risposta ritornata all'utente e viene eventualmente usata per segnalare tramite email il problema allo sviluppatore | ||
*/ | ||
|
||
public static void ProblemaApi(String errore,final Activity context,final JSONObject json){ | ||
AlertDialog.Builder miaAlert = new AlertDialog.Builder(context); | ||
miaAlert.setTitle(R.string.api_error); | ||
miaAlert.setMessage(errore); | ||
|
||
miaAlert.setCancelable(false); | ||
miaAlert.setPositiveButton(R.string.api_email, new DialogInterface.OnClickListener() { | ||
public void onClick(DialogInterface dialog, int id) { | ||
//da aggiungere il codice per la mail | ||
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( | ||
"mailto","[email protected]", null)); | ||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Errore Android Api"); | ||
emailIntent.putExtra(Intent.EXTRA_TEXT, "Errore Generato \n"+json); | ||
context.startActivity(Intent.createChooser(emailIntent, "Send email...")); | ||
context.setResult(100); | ||
context.finish(); | ||
} | ||
}); | ||
public void onClick(DialogInterface dialog, int id) { | ||
//da aggiungere il codice per la mail | ||
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( | ||
"mailto","[email protected]", null)); | ||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Errore Android Api"); | ||
emailIntent.putExtra(Intent.EXTRA_TEXT, "Errore Generato \n"+json); | ||
context.startActivity(Intent.createChooser(emailIntent, "Send email...")); | ||
context.setResult(100); | ||
context.finish(); | ||
} | ||
}); | ||
miaAlert.setNegativeButton(R.string.api_close, new DialogInterface.OnClickListener() { | ||
public void onClick(DialogInterface dialog, int id) { | ||
context.setResult(100); | ||
context.finish(); | ||
} | ||
public void onClick(DialogInterface dialog, int id) { | ||
context.setResult(100); | ||
context.finish(); | ||
} | ||
}); | ||
AlertDialog alert = miaAlert.create(); | ||
alert.show(); | ||
|