diff --git a/libs/json-smart-1.2.jar b/libs/json-smart-1.2.jar new file mode 100644 index 0000000..6e4ffd8 Binary files /dev/null and b/libs/json-smart-1.2.jar differ diff --git a/libs/jsonrpc2-base-1.35.jar b/libs/jsonrpc2-base-1.35.jar new file mode 100644 index 0000000..37fd3d2 Binary files /dev/null and b/libs/jsonrpc2-base-1.35.jar differ diff --git a/libs/jsonrpc2-client-1.14.4.jar b/libs/jsonrpc2-client-1.14.4.jar new file mode 100644 index 0000000..c601b3f Binary files /dev/null and b/libs/jsonrpc2-client-1.14.4.jar differ diff --git a/res/layout/settings.xml b/res/layout/settings.xml index 1aa9c67..6caf3bd 100644 --- a/res/layout/settings.xml +++ b/res/layout/settings.xml @@ -41,6 +41,51 @@ + + + + + + + + + + + + Synchronize done ! Synchronize failed ! Check Internet Connectivity ! + API global token : + Your API username : + Your API token : diff --git a/src/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java b/src/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java index f8adc47..e8ecd06 100644 --- a/src/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java +++ b/src/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java @@ -56,17 +56,6 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper { "UNIQUE (" + ARTICLE_ID + ")" + ");" ); - db.execSQL( - "INSERT INTO " + ARTICLE_TABLE + - " (" + - ARTICLE_TITLE + ", " + - ARTICLE_CONTENT + ", " + - ARTICLE_ID + ", " + - ARTICLE_URL + ", " + - ARCHIVE + - ") VALUES (" + - "'Ceci est un test', 'coucou', 1, 'toto', 0);" - ); } diff --git a/src/fr/gaulupeau/apps/Poche/Poche.java b/src/fr/gaulupeau/apps/Poche/Poche.java index 9629370..9992893 100644 --- a/src/fr/gaulupeau/apps/Poche/Poche.java +++ b/src/fr/gaulupeau/apps/Poche/Poche.java @@ -10,11 +10,19 @@ package fr.gaulupeau.apps.Poche; import fr.gaulupeau.apps.InThePoche.R; import java.io.UnsupportedEncodingException; - -import org.json.JSONArray; +import java.net.Authenticator; +import java.net.MalformedURLException; +import java.net.PasswordAuthentication; +import java.net.URL; import org.json.JSONException; import org.json.JSONObject; +import com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException; +import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; +import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; +import com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session; +import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException; + import android.annotation.TargetApi; import android.app.Activity; import android.content.ContentValues; @@ -31,6 +39,7 @@ import android.os.Bundle; import android.provider.Browser; import android.text.Html; import android.util.Base64; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -67,7 +76,10 @@ import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl; Bundle extras = intent.getExtras(); String action = intent.getAction(); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); - String pocheUrl = settings.getString("pocheUrl", "http://"); + final String pocheUrl = settings.getString("pocheUrl", "http://"); + final String globalToken = settings.getString("globalToken", ""); + final String apiUsername = settings.getString("APIUsername", ""); + final String apiToken = settings.getString("APIToken", ""); // Find out if Sharing or if app has been launched from icon if (action.equals(Intent.ACTION_SEND) && pocheUrl != "http://") { @@ -104,56 +116,78 @@ import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl; btnSync.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { -// JSONRPCClient client = JSONRPCClient.create("http://v2.inthepoche.com/jsonrpc.php", JSONRPCParams.Versions.VERSION_2); -// client.setConnectionTimeout(8000); -// client.setSoTimeout(8000); -// JSONObject params = new JSONObject(); -// try { -// params.put("admin", "PYBRAYc4ebUuRoa"); -// String ret = client.callString("authentication"); -// Log.e("API", ret); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } - // Vérification de la connectivité Internet - final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo(); - if (activeNetwork != null && activeNetwork.isConnected()) { - // Exécution de la synchro en arrière-plan - new Thread(new Runnable() { - public void run() { - String ret = getInputStreamFromUrl("http://poche.gaulupeau.fr/toto.php"); - ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext()); - database = helper.getWritableDatabase(); - try { - JSONArray rootobj = new JSONArray(ret); - for (int i=0; i