mirror of
https://github.com/moparisthebest/android-app
synced 2024-12-24 07:28:51 -05:00
Récupération des articles par flux RSS
This commit is contained in:
parent
303cd9b6d0
commit
6f077b2346
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest package="fr.gaulupeau.apps.InThePoche"
|
<manifest package="fr.gaulupeau.apps.InThePoche"
|
||||||
android:versionCode="3"
|
android:versionCode="4"
|
||||||
android:versionName="1.0.2" xmlns:android="http://schemas.android.com/apk/res/android">
|
android:versionName="1.5" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<uses-sdk android:minSdkVersion="8"
|
<uses-sdk android:minSdkVersion="8"
|
||||||
android:targetSdkVersion="8" />
|
android:targetSdkVersion="8" />
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
@ -41,22 +41,6 @@
|
|||||||
<requestFocus />
|
<requestFocus />
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/txtGlobalToken"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/txtGlobalToken"
|
|
||||||
android:textSize="18sp" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/globalToken"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:ems="10"
|
|
||||||
android:inputType="text" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/txtAPIUsername"
|
android:id="@+id/txtAPIUsername"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
<string name="txtSyncDone">Synchronize done !</string>
|
<string name="txtSyncDone">Synchronize done !</string>
|
||||||
<string name="txtSyncFailed">Synchronize failed !</string>
|
<string name="txtSyncFailed">Synchronize failed !</string>
|
||||||
<string name="txtNetOffline">Check Internet Connectivity !</string>
|
<string name="txtNetOffline">Check Internet Connectivity !</string>
|
||||||
|
<string name="txtConfigNotSet">Please configure the app before Syncing !</string>
|
||||||
<string name="txtGlobalToken"><b><u>API global token :</u></b></string>
|
<string name="txtGlobalToken"><b><u>API global token :</u></b></string>
|
||||||
<string name="txtAPIUsername"><b><u>Your API username :</u></b></string>
|
<string name="txtAPIUsername"><b><u>Your username ID (user_id in Feed URL):</u></b></string>
|
||||||
<string name="txtAPIToken"><b><u>Your API token :</u></b></string>
|
<string name="txtAPIToken"><b><u>Your token (token in Feed URL):</u></b></string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -64,7 +64,7 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
|
|||||||
ARCHIVE + " integer," +
|
ARCHIVE + " integer," +
|
||||||
ARTICLE_SYNC + " integer," +
|
ARTICLE_SYNC + " integer," +
|
||||||
ARTICLE_READAT + " integer," +
|
ARTICLE_READAT + " integer," +
|
||||||
"UNIQUE (" + ARTICLE_ID + ")" +
|
"UNIQUE (" + ARTICLE_URL + ")" +
|
||||||
");"
|
");"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class ListArticles extends Activity {
|
|||||||
public ReadingListAdapter getAdapterQuery(String filter, ArrayList<Article> articleInfo) {
|
public ReadingListAdapter getAdapterQuery(String filter, ArrayList<Article> articleInfo) {
|
||||||
//Log.e("getAdapterQuery", "running query");
|
//Log.e("getAdapterQuery", "running query");
|
||||||
//String url, String domain, String id, String title, String content
|
//String url, String domain, String id, String title, String content
|
||||||
String[] getStrColumns = new String[] {ARTICLE_URL, ARTICLE_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE};
|
String[] getStrColumns = new String[] {ARTICLE_URL, MY_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE};
|
||||||
Cursor ac = database.query(
|
Cursor ac = database.query(
|
||||||
ARTICLE_TABLE,
|
ARTICLE_TABLE,
|
||||||
getStrColumns,
|
getStrColumns,
|
||||||
|
@ -9,14 +9,28 @@
|
|||||||
package fr.gaulupeau.apps.Poche;
|
package fr.gaulupeau.apps.Poche;
|
||||||
|
|
||||||
import fr.gaulupeau.apps.InThePoche.R;
|
import fr.gaulupeau.apps.InThePoche.R;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.PasswordAuthentication;
|
import java.net.PasswordAuthentication;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.w3c.dom.DOMException;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException;
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException;
|
||||||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
|
||||||
@ -35,9 +49,12 @@ import android.database.sqlite.SQLiteConstraintException;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.Browser;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.util.Base64;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -59,16 +76,15 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
|
|||||||
* Main activity class
|
* Main activity class
|
||||||
*/
|
*/
|
||||||
@TargetApi(Build.VERSION_CODES.FROYO) public class Poche extends Activity {
|
@TargetApi(Build.VERSION_CODES.FROYO) public class Poche extends Activity {
|
||||||
private SQLiteDatabase database;
|
private static SQLiteDatabase database;
|
||||||
Button btnDone;
|
Button btnDone;
|
||||||
Button btnGetPost;
|
Button btnGetPost;
|
||||||
Button btnSync;
|
Button btnSync;
|
||||||
EditText editPocheUrl;
|
EditText editPocheUrl;
|
||||||
SharedPreferences settings;
|
SharedPreferences settings;
|
||||||
String globalToken;
|
static String apiUsername;
|
||||||
String apiUsername;
|
static String apiToken;
|
||||||
String apiToken;
|
static String pocheUrl;
|
||||||
String pocheUrl;
|
|
||||||
String action;
|
String action;
|
||||||
|
|
||||||
/** Called when the activity is first created.
|
/** Called when the activity is first created.
|
||||||
@ -93,12 +109,32 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
|
|||||||
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
|
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
|
||||||
if (activeNetwork != null && activeNetwork.isConnected()) {
|
if (activeNetwork != null && activeNetwork.isConnected()) {
|
||||||
// Exécution de la synchro en arrière-plan
|
// Start to build the poche URL
|
||||||
new Thread(new Runnable() {
|
Uri.Builder pocheSaveUrl = Uri.parse(pocheUrl).buildUpon();
|
||||||
public void run() {
|
// Add the parameters from the call
|
||||||
pocheIt(pageUrl);
|
pocheSaveUrl.appendQueryParameter("action", "add");
|
||||||
}
|
byte[] data = null;
|
||||||
}).start();
|
try {
|
||||||
|
data = pageUrl.getBytes("UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
|
||||||
|
pocheSaveUrl.appendQueryParameter("url", base64);
|
||||||
|
System.out.println("base64 : " + base64);
|
||||||
|
System.out.println("pageurl : " + pageUrl);
|
||||||
|
|
||||||
|
// Load the constructed URL in the browser
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
|
i.setData(pocheSaveUrl.build());
|
||||||
|
i.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
|
||||||
|
// If user has more then one browser installed give them a chance to
|
||||||
|
// select which one they want to use
|
||||||
|
|
||||||
|
startActivity(i);
|
||||||
|
// That is all this app needs to do, so call finish()
|
||||||
|
this.finish();
|
||||||
} else {
|
} else {
|
||||||
// Afficher alerte connectivité
|
// Afficher alerte connectivité
|
||||||
showToast(getString(R.string.txtNetOffline));
|
showToast(getString(R.string.txtNetOffline));
|
||||||
@ -114,12 +150,14 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
|
|||||||
// Vérification de la connectivité Internet
|
// Vérification de la connectivité Internet
|
||||||
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
|
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
|
||||||
if (activeNetwork != null && activeNetwork.isConnected()) {
|
if (pocheUrl != "http://") {
|
||||||
|
showToast(getString(R.string.txtConfigNotSet));
|
||||||
|
} else if (activeNetwork != null && activeNetwork.isConnected()) {
|
||||||
// Exécution de la synchro en arrière-plan
|
// Exécution de la synchro en arrière-plan
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
pushRead();
|
//pushRead();
|
||||||
fetchUnread();
|
parseRSS();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
} else {
|
} else {
|
||||||
@ -131,7 +169,7 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
|
|||||||
});
|
});
|
||||||
|
|
||||||
btnGetPost = (Button)findViewById(R.id.btnGetPost);
|
btnGetPost = (Button)findViewById(R.id.btnGetPost);
|
||||||
updateUnread();
|
//updateUnread();
|
||||||
|
|
||||||
btnGetPost.setOnClickListener(new OnClickListener() {
|
btnGetPost.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -146,7 +184,6 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
|
|||||||
private void getSettings(){
|
private void getSettings(){
|
||||||
settings = getSharedPreferences(PREFS_NAME, 0);
|
settings = getSharedPreferences(PREFS_NAME, 0);
|
||||||
pocheUrl = settings.getString("pocheUrl", "http://");
|
pocheUrl = settings.getString("pocheUrl", "http://");
|
||||||
globalToken = settings.getString("globalToken", "");
|
|
||||||
apiUsername = settings.getString("APIUsername", "");
|
apiUsername = settings.getString("APIUsername", "");
|
||||||
apiToken = settings.getString("APIToken", "");
|
apiToken = settings.getString("APIToken", "");
|
||||||
}
|
}
|
||||||
@ -208,155 +245,284 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void pocheIt(String url){
|
// public void pocheIt(String url){
|
||||||
String id ="req-001";
|
// String id ="req-001";
|
||||||
JSONRPC2Request reqOut = null;
|
// JSONRPC2Request reqOut = null;
|
||||||
try{
|
// try{
|
||||||
reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.add\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, \"" + url + "\", true]}");
|
// reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.add\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, \"" + url + "\", true]}");
|
||||||
System.err.println(reqOut.toString());
|
// System.err.println(reqOut.toString());
|
||||||
JSONRPC2Response response = sendRequest(reqOut);
|
// JSONRPC2Response response = sendRequest(reqOut);
|
||||||
if (response.indicatesSuccess()) {
|
// if (response.indicatesSuccess()) {
|
||||||
showToast(getString(R.string.txtSyncDone));
|
// showToast(getString(R.string.txtSyncDone));
|
||||||
}
|
// }
|
||||||
} catch (JSONRPC2ParseException e2) {
|
// } catch (JSONRPC2ParseException e2) {
|
||||||
e2.printStackTrace();
|
// e2.printStackTrace();
|
||||||
showToast(getString(R.string.txtSyncFailed));
|
// showToast(getString(R.string.txtSyncFailed));
|
||||||
}
|
// }
|
||||||
finish();
|
// finish();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public void pushRead(){
|
// public void pushRead(){
|
||||||
JSONRPC2Request reqOut = null;
|
// JSONRPC2Request reqOut = null;
|
||||||
String filter = ARCHIVE + "=1 AND " + ARTICLE_SYNC + "=0";
|
// String filter = ARCHIVE + "=1 AND " + ARTICLE_SYNC + "=0";
|
||||||
String[] getStrColumns = new String[] {ARTICLE_ID};
|
// String[] getStrColumns = new String[] {ARTICLE_ID};
|
||||||
Cursor ac = database.query(
|
// Cursor ac = database.query(
|
||||||
ARTICLE_TABLE,
|
// ARTICLE_TABLE,
|
||||||
getStrColumns,
|
// getStrColumns,
|
||||||
filter, null, null, null, null);
|
// filter, null, null, null, null);
|
||||||
ac.moveToFirst();
|
// ac.moveToFirst();
|
||||||
if(!ac.isAfterLast()) {
|
// if(!ac.isAfterLast()) {
|
||||||
do {
|
// do {
|
||||||
String article_id = ac.getString(0);
|
// String article_id = ac.getString(0);
|
||||||
String id ="req-001";
|
// String id ="req-001";
|
||||||
try{
|
// try{
|
||||||
reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.mark_as_read\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, " + article_id + "]}");
|
// reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.mark_as_read\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, " + article_id + "]}");
|
||||||
System.err.println(reqOut.toString());
|
// System.err.println(reqOut.toString());
|
||||||
JSONRPC2Response response = sendRequest(reqOut);
|
// JSONRPC2Response response = sendRequest(reqOut);
|
||||||
if (response.indicatesSuccess()) {
|
// if (response.indicatesSuccess()) {
|
||||||
ContentValues values = new ContentValues();
|
// ContentValues values = new ContentValues();
|
||||||
values.put(ARTICLE_SYNC, 1);
|
// values.put(ARTICLE_SYNC, 1);
|
||||||
database.update(ARTICLE_TABLE, values, ARTICLE_ID + "=" + article_id, null);
|
// database.update(ARTICLE_TABLE, values, ARTICLE_ID + "=" + article_id, null);
|
||||||
}
|
// }
|
||||||
} catch (JSONRPC2ParseException e2) {
|
// } catch (JSONRPC2ParseException e2) {
|
||||||
e2.printStackTrace();
|
// e2.printStackTrace();
|
||||||
}
|
// }
|
||||||
} while (ac.moveToNext());
|
// } while (ac.moveToNext());
|
||||||
}
|
// }
|
||||||
ac.close();
|
// ac.close();
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public void updateReads(){
|
|
||||||
String lastUpdate = settings.getString("lastUpdate", "");
|
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
|
||||||
editor.putString("lastUpdate", "");
|
|
||||||
//TODO Continuer la fonction en se basant sur le timestamp "update" de Poche
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void fetchUnread(){
|
public void parseRSS(){
|
||||||
String id = "req-001";
|
|
||||||
JSONRPC2Request reqOut = null;
|
|
||||||
try {
|
|
||||||
// POCHE A LINK
|
|
||||||
//reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.add\",\"id\":\"req-001\",\"params\":[{\"username\":\"poche\",\"api_token\":\"cPG2urVgA+ToMXY\"},\"http://cdetc.fr\",true]}");
|
|
||||||
// GET A LINK
|
|
||||||
//reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.info\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, 1]}");
|
|
||||||
// GET ALL UNREAD
|
|
||||||
reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.list_unread\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, null, null]}");
|
|
||||||
System.err.println(reqOut.toString());
|
|
||||||
} catch (JSONRPC2ParseException e2) {
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println(reqOut.toString());
|
|
||||||
URL url = null;
|
|
||||||
try {
|
|
||||||
final String rpcuser ="api_user";
|
|
||||||
final String rpcpassword = globalToken;
|
|
||||||
|
|
||||||
Authenticator.setDefault(new Authenticator() {
|
URL url;
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
try
|
||||||
return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
|
{
|
||||||
}});
|
// Set the url (you will need to change this to your RSS URL
|
||||||
url = new URL(pocheUrl + "/jsonrpc.php");
|
url = new URL(pocheUrl + "/?feed&type=home&user_id=" + apiUsername + "&token=" + apiToken );
|
||||||
} catch (MalformedURLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
JSONRPC2Session session = new JSONRPC2Session(url);
|
|
||||||
JSONRPC2Response response = null;
|
|
||||||
try{
|
|
||||||
response = session.send(reqOut);
|
|
||||||
} catch (JSONRPC2SessionException e) {
|
|
||||||
|
|
||||||
System.err.println(e.getMessage());
|
// Setup the connection
|
||||||
}
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
if (response.indicatesSuccess()){
|
|
||||||
JSONObject article = null;
|
// Connect
|
||||||
ContentValues values = new ContentValues();
|
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK)
|
||||||
try {
|
{
|
||||||
JSONArray ret = new JSONArray(response.getResult().toString());
|
|
||||||
for (int i = 0; i < ret.length(); i++) {
|
// Retreive the XML from the URL
|
||||||
article = ret.getJSONObject(i);
|
DocumentBuilderFactory dbf = DocumentBuilderFactory
|
||||||
values.put(ARTICLE_TITLE, Html.fromHtml(article.getString("title")).toString());
|
.newInstance();
|
||||||
values.put(ARTICLE_CONTENT, Html.fromHtml(article.getString("content")).toString());
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
values.put(ARTICLE_ID, Html.fromHtml(article.getString("id")).toString());
|
Document doc;
|
||||||
values.put(ARTICLE_URL, Html.fromHtml(article.getString("url")).toString());
|
doc = db.parse(url.openStream());
|
||||||
values.put(ARCHIVE, 0);
|
doc.getDocumentElement().normalize();
|
||||||
values.put(ARTICLE_SYNC, 0);
|
|
||||||
try {
|
// This is the root node of each section you want to parse
|
||||||
database.insertOrThrow(ARTICLE_TABLE, null, values);
|
NodeList itemLst = doc.getElementsByTagName("item");
|
||||||
} catch (SQLiteConstraintException e) {
|
|
||||||
continue;
|
// This sets up some arrays to hold the data parsed
|
||||||
|
arrays.PodcastTitle = new String[itemLst.getLength()];
|
||||||
|
arrays.PodcastURL = new String[itemLst.getLength()];
|
||||||
|
arrays.PodcastContent = new String[itemLst.getLength()];
|
||||||
|
arrays.PodcastMedia = new String[itemLst.getLength()];
|
||||||
|
|
||||||
|
// Loop through the XML passing the data to the arrays
|
||||||
|
for (int i = 0; i < itemLst.getLength(); i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
Node item = itemLst.item(i);
|
||||||
|
if (item.getNodeType() == Node.ELEMENT_NODE)
|
||||||
|
{
|
||||||
|
Element ielem = (Element) item;
|
||||||
|
|
||||||
|
// This section gets the elements from the XML
|
||||||
|
// that we want to use you will need to add
|
||||||
|
// and remove elements that you want / don't want
|
||||||
|
NodeList title = ielem.getElementsByTagName("title");
|
||||||
|
NodeList link = ielem.getElementsByTagName("link");
|
||||||
|
NodeList content = ielem
|
||||||
|
.getElementsByTagName("description");
|
||||||
|
//NodeList media = ielem
|
||||||
|
// .getElementsByTagName("media:content");
|
||||||
|
|
||||||
|
// This is an attribute of an element so I create
|
||||||
|
// a string to make it easier to use
|
||||||
|
//String mediaurl = media.item(0).getAttributes()
|
||||||
|
// .getNamedItem("url").getNodeValue();
|
||||||
|
|
||||||
|
// This section adds an entry to the arrays with the
|
||||||
|
// data retrieved from above. I have surrounded each
|
||||||
|
// with try/catch just incase the element does not
|
||||||
|
// exist
|
||||||
|
try
|
||||||
|
{
|
||||||
|
arrays.PodcastTitle[i] = title.item(0)
|
||||||
|
.getChildNodes().item(0).getNodeValue();
|
||||||
|
} catch (NullPointerException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
arrays.PodcastURL[i] = link.item(0).getChildNodes()
|
||||||
|
.item(0).getNodeValue();
|
||||||
|
} catch (NullPointerException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
arrays.PodcastContent[i] = content.item(0)
|
||||||
|
.getChildNodes().item(0).getNodeValue();
|
||||||
|
} catch (NullPointerException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// arrays.PodcastMedia[i] = mediaurl;
|
||||||
|
} catch (NullPointerException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(ARTICLE_TITLE, Html.fromHtml(arrays.PodcastTitle[i]).toString());
|
||||||
|
values.put(ARTICLE_CONTENT, Html.fromHtml(arrays.PodcastContent[i]).toString());
|
||||||
|
//values.put(ARTICLE_ID, Html.fromHtml(article.getString("id")).toString());
|
||||||
|
values.put(ARTICLE_URL, Html.fromHtml(arrays.PodcastURL[i]).toString());
|
||||||
|
values.put(ARCHIVE, 0);
|
||||||
|
values.put(ARTICLE_SYNC, 0);
|
||||||
|
try {
|
||||||
|
database.insertOrThrow(ARTICLE_TABLE, null, values);
|
||||||
|
} catch (SQLiteConstraintException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
showToast(getString(R.string.txtSyncFailed));
|
|
||||||
}
|
}
|
||||||
|
showToast(getString(R.string.txtSyncDone));
|
||||||
showToast(getString(R.string.txtSyncDone));
|
|
||||||
updateUnread();
|
updateUnread();
|
||||||
}else{
|
} catch (MalformedURLException e)
|
||||||
System.out.println(response.getError().getMessage( ));
|
{
|
||||||
showToast(getString(R.string.txtSyncFailed));
|
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) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONRPC2Response sendRequest(JSONRPC2Request reqOut){
|
// public void fetchUnread(){
|
||||||
URL url = null;
|
// String id = "req-001";
|
||||||
try {
|
// JSONRPC2Request reqOut = null;
|
||||||
final String rpcuser ="api_user";
|
// try {
|
||||||
final String rpcpassword = globalToken;
|
// // POCHE A LINK
|
||||||
|
// //reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.add\",\"id\":\"req-001\",\"params\":[{\"username\":\"poche\",\"api_token\":\"cPG2urVgA+ToMXY\"},\"http://cdetc.fr\",true]}");
|
||||||
Authenticator.setDefault(new Authenticator() {
|
// // GET A LINK
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
// //reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.info\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, 1]}");
|
||||||
return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
|
// // GET ALL UNREAD
|
||||||
}});
|
// reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.list_unread\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, null, null]}");
|
||||||
url = new URL(pocheUrl + "/jsonrpc.php");
|
// System.err.println(reqOut.toString());
|
||||||
} catch (MalformedURLException e1) {
|
// } catch (JSONRPC2ParseException e2) {
|
||||||
e1.printStackTrace();
|
// e2.printStackTrace();
|
||||||
}
|
// }
|
||||||
JSONRPC2Session session = new JSONRPC2Session(url);
|
// System.out.println(reqOut.toString());
|
||||||
JSONRPC2Response response = null;
|
// URL url = null;
|
||||||
try{
|
// try {
|
||||||
response = session.send(reqOut);
|
// final String rpcuser ="api_user";
|
||||||
} catch (JSONRPC2SessionException e) {
|
// final String rpcpassword = globalToken;
|
||||||
|
//
|
||||||
System.err.println(e.getMessage());
|
// Authenticator.setDefault(new Authenticator() {
|
||||||
}
|
// protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
return response;
|
// return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
|
||||||
}
|
// }});
|
||||||
|
// url = new URL(pocheUrl + "/jsonrpc.php");
|
||||||
|
// } catch (MalformedURLException e1) {
|
||||||
|
// e1.printStackTrace();
|
||||||
|
// }
|
||||||
|
// JSONRPC2Session session = new JSONRPC2Session(url);
|
||||||
|
// JSONRPC2Response response = null;
|
||||||
|
// try{
|
||||||
|
// response = session.send(reqOut);
|
||||||
|
// } catch (JSONRPC2SessionException e) {
|
||||||
|
//
|
||||||
|
// System.err.println(e.getMessage());
|
||||||
|
// }
|
||||||
|
// if (response.indicatesSuccess()){
|
||||||
|
// JSONObject article = null;
|
||||||
|
// ContentValues values = new ContentValues();
|
||||||
|
// try {
|
||||||
|
// JSONArray ret = new JSONArray(response.getResult().toString());
|
||||||
|
// for (int i = 0; i < ret.length(); i++) {
|
||||||
|
// article = ret.getJSONObject(i);
|
||||||
|
// values.put(ARTICLE_TITLE, Html.fromHtml(article.getString("title")).toString());
|
||||||
|
// values.put(ARTICLE_CONTENT, Html.fromHtml(article.getString("content")).toString());
|
||||||
|
// values.put(ARTICLE_ID, Html.fromHtml(article.getString("id")).toString());
|
||||||
|
// values.put(ARTICLE_URL, Html.fromHtml(article.getString("url")).toString());
|
||||||
|
// values.put(ARCHIVE, 0);
|
||||||
|
// values.put(ARTICLE_SYNC, 0);
|
||||||
|
// try {
|
||||||
|
// database.insertOrThrow(ARTICLE_TABLE, null, values);
|
||||||
|
// } catch (SQLiteConstraintException e) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (JSONException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// showToast(getString(R.string.txtSyncFailed));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// showToast(getString(R.string.txtSyncDone));
|
||||||
|
// updateUnread();
|
||||||
|
// }else{
|
||||||
|
// System.out.println(response.getError().getMessage( ));
|
||||||
|
// showToast(getString(R.string.txtSyncFailed));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public JSONRPC2Response sendRequest(JSONRPC2Request reqOut){
|
||||||
|
// URL url = null;
|
||||||
|
// try {
|
||||||
|
// final String rpcuser ="api_user";
|
||||||
|
// final String rpcpassword = globalToken;
|
||||||
|
//
|
||||||
|
// Authenticator.setDefault(new Authenticator() {
|
||||||
|
// protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
// return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
|
||||||
|
// }});
|
||||||
|
// url = new URL(pocheUrl + "/jsonrpc.php");
|
||||||
|
// } catch (MalformedURLException e1) {
|
||||||
|
// e1.printStackTrace();
|
||||||
|
// }
|
||||||
|
// JSONRPC2Session session = new JSONRPC2Session(url);
|
||||||
|
// JSONRPC2Response response = null;
|
||||||
|
// try{
|
||||||
|
// response = session.send(reqOut);
|
||||||
|
// } catch (JSONRPC2SessionException e) {
|
||||||
|
//
|
||||||
|
// System.err.println(e.getMessage());
|
||||||
|
// }
|
||||||
|
// return response;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TITLE;
|
|||||||
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_URL;
|
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_URL;
|
||||||
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TABLE;
|
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TABLE;
|
||||||
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_AUTHOR;
|
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_AUTHOR;
|
||||||
|
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.MY_ID;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@ -38,12 +39,12 @@ public class ReadArticle extends Activity {
|
|||||||
view = (ScrollView) findViewById(R.id.scroll);
|
view = (ScrollView) findViewById(R.id.scroll);
|
||||||
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
|
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
|
||||||
database = helper.getWritableDatabase();
|
database = helper.getWritableDatabase();
|
||||||
String[] getStrColumns = new String[] {ARTICLE_URL, ARTICLE_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE, ARTICLE_AUTHOR};
|
String[] getStrColumns = new String[] {ARTICLE_URL, MY_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE, ARTICLE_AUTHOR};
|
||||||
Bundle data = getIntent().getExtras();
|
Bundle data = getIntent().getExtras();
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
id = data.getString("id");
|
id = data.getString("id");
|
||||||
}
|
}
|
||||||
Cursor ac = database.query(ARTICLE_TABLE, getStrColumns, ARTICLE_ID + "=" + id, null, null, null, null);
|
Cursor ac = database.query(ARTICLE_TABLE, getStrColumns, MY_ID + "=" + id, null, null, null, null);
|
||||||
ac.moveToFirst();
|
ac.moveToFirst();
|
||||||
txtTitre = (TextView)findViewById(R.id.txtTitre);
|
txtTitre = (TextView)findViewById(R.id.txtTitre);
|
||||||
txtTitre.setText(ac.getString(2));
|
txtTitre.setText(ac.getString(2));
|
||||||
@ -58,7 +59,7 @@ public class ReadArticle extends Activity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(ARCHIVE, 1);
|
values.put(ARCHIVE, 1);
|
||||||
database.update(ARTICLE_TABLE, values, ARTICLE_ID + "=" + id, null);
|
database.update(ARTICLE_TABLE, values, MY_ID + "=" + id, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,15 +25,12 @@ public class Settings extends Activity {
|
|||||||
String pocheUrl = settings.getString("pocheUrl", "http://");
|
String pocheUrl = settings.getString("pocheUrl", "http://");
|
||||||
String apiUsername = settings.getString("APIUsername", "");
|
String apiUsername = settings.getString("APIUsername", "");
|
||||||
String apiToken = settings.getString("APIToken", "");
|
String apiToken = settings.getString("APIToken", "");
|
||||||
String globalToken = settings.getString("globalToken", "");
|
|
||||||
editPocheUrl = (EditText)findViewById(R.id.pocheUrl);
|
editPocheUrl = (EditText)findViewById(R.id.pocheUrl);
|
||||||
editPocheUrl.setText(pocheUrl);
|
editPocheUrl.setText(pocheUrl);
|
||||||
editAPIUsername = (EditText)findViewById(R.id.APIUsername);
|
editAPIUsername = (EditText)findViewById(R.id.APIUsername);
|
||||||
editAPIUsername.setText(apiUsername);
|
editAPIUsername.setText(apiUsername);
|
||||||
editAPIToken = (EditText)findViewById(R.id.APIToken);
|
editAPIToken = (EditText)findViewById(R.id.APIToken);
|
||||||
editAPIToken.setText(apiToken);
|
editAPIToken.setText(apiToken);
|
||||||
editGlobalToken = (EditText)findViewById(R.id.globalToken);
|
|
||||||
editGlobalToken.setText(globalToken);
|
|
||||||
btnDone = (Button)findViewById(R.id.btnDone);
|
btnDone = (Button)findViewById(R.id.btnDone);
|
||||||
btnDone.setOnClickListener(new OnClickListener() {
|
btnDone.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -42,7 +39,6 @@ public class Settings extends Activity {
|
|||||||
editor.putString("pocheUrl", editPocheUrl.getText().toString());
|
editor.putString("pocheUrl", editPocheUrl.getText().toString());
|
||||||
editor.putString("APIUsername", editAPIUsername.getText().toString());
|
editor.putString("APIUsername", editAPIUsername.getText().toString());
|
||||||
editor.putString("APIToken", editAPIToken.getText().toString());
|
editor.putString("APIToken", editAPIToken.getText().toString());
|
||||||
editor.putString("globalToken", editGlobalToken.getText().toString());
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
8
src/fr/gaulupeau/apps/Poche/arrays.java
Normal file
8
src/fr/gaulupeau/apps/Poche/arrays.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package fr.gaulupeau.apps.Poche;
|
||||||
|
|
||||||
|
public class arrays {
|
||||||
|
public static String[] PodcastTitle;
|
||||||
|
public static String[] PodcastURL;
|
||||||
|
public static String[] PodcastContent;
|
||||||
|
public static String[] PodcastMedia;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user