mirror of
https://github.com/moparisthebest/android-app
synced 2024-11-15 05:15:04 -05:00
added error handling for wrong user ids or wrong tokens
This commit is contained in:
parent
288e7cba77
commit
0a05cf82c4
@ -11,6 +11,7 @@ package fr.gaulupeau.apps.Poche;
|
|||||||
import fr.gaulupeau.apps.InThePoche.R;
|
import fr.gaulupeau.apps.InThePoche.R;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@ -41,6 +42,7 @@ import org.xml.sax.SAXException;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -57,6 +59,7 @@ import android.preference.PreferenceManager;
|
|||||||
import android.provider.Browser;
|
import android.provider.Browser;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -272,8 +275,23 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showErrorMessage(final String message)
|
||||||
|
{
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
AlertDialog.Builder messageBox = new AlertDialog.Builder(Poche.this);
|
||||||
|
messageBox.setMessage(message);
|
||||||
|
messageBox.setTitle(getString(R.string.error));
|
||||||
|
// messageBox.setIconAttribute(android.R.attr.alertDialogIcon);
|
||||||
|
messageBox.setPositiveButton("OK",null);
|
||||||
|
messageBox.setCancelable(false);
|
||||||
|
messageBox.create().show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// public void pocheIt(String url){
|
// public void pocheIt(String url){
|
||||||
// String id ="req-001";
|
// String id ="req-001";
|
||||||
// JSONRPC2Request reqOut = null;
|
// JSONRPC2Request reqOut = null;
|
||||||
@ -375,40 +393,42 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE;
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set the url (you will need to change this to your RSS URL
|
// Set the url (you will need to change this to your RSS URL
|
||||||
url = new URL(pocheUrl + "/?feed&type=home&user_id=" + apiUsername + "&token=" + apiToken );
|
url = new URL(pocheUrl + "/?feed&type=home&user_id=" + apiUsername + "&token=" + apiToken);
|
||||||
// Setup the connection
|
if (pocheUrl.startsWith("https")) {
|
||||||
HttpsURLConnection conn_s = null;
|
trustEveryone();
|
||||||
HttpURLConnection conn = null;
|
}
|
||||||
if (pocheUrl.startsWith("https") ) {
|
|
||||||
trustEveryone();
|
// Setup the connection
|
||||||
conn_s = (HttpsURLConnection) url.openConnection();
|
HttpURLConnection urlConnection = null;
|
||||||
}else{
|
urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
|
||||||
}
|
if ((urlConnection != null) && (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK)) {
|
||||||
|
|
||||||
if (
|
|
||||||
((conn != null) && (conn.getResponseCode() == HttpURLConnection.HTTP_OK))
|
|
||||||
|| ((conn_s != null) && (conn_s.getResponseCode() == HttpURLConnection.HTTP_OK))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Retreive the XML from the URL
|
// Retreive the XML from the URL
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
.newInstance();
|
|
||||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
Document doc;
|
Document doc = null;
|
||||||
// doc = db.parse(url.openStream());
|
|
||||||
InputSource is = new InputSource(
|
InputSource is = null;
|
||||||
new InputStreamReader(
|
|
||||||
url.openStream()));
|
try {
|
||||||
doc = db.parse(is);
|
is = new InputSource(
|
||||||
// doc = db.parse(
|
new InputStreamReader(
|
||||||
// new InputSource(
|
urlConnection.getInputStream()));
|
||||||
// new InputStreamReader(
|
doc = db.parse(is);
|
||||||
// url.openStream(),
|
doc.getDocumentElement().normalize();
|
||||||
// "latin-1")));
|
} catch (SAXException e) {
|
||||||
doc.getDocumentElement().normalize();
|
e.printStackTrace();
|
||||||
|
|
||||||
|
InputStream inputStream = url.openStream();
|
||||||
|
int ch;
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((ch = inputStream.read()) != -1) {
|
||||||
|
stringBuffer.append((char) ch);
|
||||||
|
}
|
||||||
|
showErrorMessage("Got invalid response:\n\"" + stringBuffer.toString() + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
// This is the root node of each section you want to parse
|
// This is the root node of each section you want to parse
|
||||||
NodeList itemLst = doc.getElementsByTagName("item");
|
NodeList itemLst = doc.getElementsByTagName("item");
|
||||||
|
|
||||||
@ -503,21 +523,6 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE;
|
|||||||
}
|
}
|
||||||
showToast(getString(R.string.txtSyncDone));
|
showToast(getString(R.string.txtSyncDone));
|
||||||
updateUnread();
|
updateUnread();
|
||||||
} catch (MalformedURLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (DOMException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ParserConfigurationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SAXException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,5 @@
|
|||||||
<string name="txtConfigNotSet">Bitte konfiguriere die App zunächst!</string>
|
<string name="txtConfigNotSet">Bitte konfiguriere die App zunächst!</string>
|
||||||
<string name="txtAPIUsername"><b><u>Deine User ID:</u></b></string>
|
<string name="txtAPIUsername"><b><u>Deine User ID:</u></b></string>
|
||||||
<string name="txtAPIToken"><b><u>Dein Token:</u></b></string>
|
<string name="txtAPIToken"><b><u>Dein Token:</u></b></string>
|
||||||
|
<string name="error">Fehler</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -19,4 +19,5 @@
|
|||||||
<string name="txtConfigNotSet">Please configure the app before Syncing !</string>
|
<string name="txtConfigNotSet">Please configure the app before Syncing !</string>
|
||||||
<string name="txtAPIUsername"><b><u>Your User ID:</u></b></string>
|
<string name="txtAPIUsername"><b><u>Your User ID:</u></b></string>
|
||||||
<string name="txtAPIToken"><b><u>Your Token:</u></b></string>
|
<string name="txtAPIToken"><b><u>Your Token:</u></b></string>
|
||||||
|
<string name="error">Error</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user