Several changes.

This commit is contained in:
GAULUPEAU Jonathan 2014-01-04 15:33:29 +01:00
parent 95d51667bb
commit 303cd9b6d0
5 changed files with 92 additions and 35 deletions

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent"
android:id="@+id/scroll" >
<LinearLayout
android:layout_width="match_parent"

View File

@ -52,7 +52,14 @@
android:layout_weight="1"
android:text="@string/btnSync" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0"
android:visibility="invisible" />
</LinearLayout>

View File

@ -22,6 +22,7 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
public static String ARTICLE_URL = "url";
public static String ARCHIVE = "archive";
public static String ARTICLE_SYNC = "sync";
public static String ARTICLE_READAT = "read_at";
Context c;
public ArticlesSQLiteOpenHelper(Context context) {
@ -34,7 +35,14 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
createTables(db);
}
@Override
public void onOpen(SQLiteDatabase db) {
// TODO Auto-generated method stub
super.onOpen(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.delete(ARTICLE_TABLE, null, null);
@ -55,6 +63,7 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
ARTICLE_ID + " integer, " +
ARCHIVE + " integer," +
ARTICLE_SYNC + " integer," +
ARTICLE_READAT + " integer," +
"UNIQUE (" + ARTICLE_ID + ")" +
");"
);

View File

@ -9,7 +9,6 @@
package fr.gaulupeau.apps.Poche;
import fr.gaulupeau.apps.InThePoche.R;
import java.io.UnsupportedEncodingException;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
@ -36,12 +35,9 @@ import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Browser;
import android.text.Html;
import android.util.Base64;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -73,6 +69,7 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
String apiUsername;
String apiToken;
String pocheUrl;
String action;
/** Called when the activity is first created.
* Will act differently depending on whether sharing or
@ -82,36 +79,30 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String action = intent.getAction();
action = intent.getAction();
getSettings();
// Find out if Sharing or if app has been launched from icon
if (action.equals(Intent.ACTION_SEND) && pocheUrl != "http://") {
// ACTION_SEND is called when sharing, get the title and URL from
// the call
String pageUrl = extras.getString("android.intent.extra.TEXT");
// Start to build the poche URL
Uri.Builder pocheSaveUrl = Uri.parse(pocheUrl).buildUpon();
// Add the parameters from the call
pocheSaveUrl.appendQueryParameter("action", "add");
byte[] data = null;
try {
data = pageUrl.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
pocheSaveUrl.appendQueryParameter("url", base64);
// 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);
this.finish();
setContentView(R.layout.main);
findViewById(R.id.btnSync).setVisibility(View.GONE);
findViewById(R.id.btnGetPost).setVisibility(View.GONE);
findViewById(R.id.progressBar1).setVisibility(View.VISIBLE);
final String pageUrl = extras.getString("android.intent.extra.TEXT");
// 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() {
pocheIt(pageUrl);
}
}).start();
} else {
// Afficher alerte connectivité
showToast(getString(R.string.txtNetOffline));
}
}
else {
setContentView(R.layout.main);
@ -164,7 +155,9 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
protected void onResume() {
super.onResume();
getSettings();
updateUnread();
if (! action.equals(Intent.ACTION_SEND)){
updateUnread();
}
}
@Override
@ -187,7 +180,9 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
@Override
protected void onDestroy() {
super.onDestroy();
database.close();
if (database != null) {
database.close();
}
}
private void updateUnread(){
@ -212,6 +207,25 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
});
}
public void pocheIt(String url){
String id ="req-001";
JSONRPC2Request reqOut = null;
try{
reqOut = JSONRPC2Request.parse("{\"jsonrpc\":\"2.0\",\"method\":\"item.add\",\"id\":\"" + id + "\",\"params\":[{\"username\":\""+ apiUsername + "\",\"api_token\":\""+ apiToken +"\"}, \"" + url + "\", true]}");
System.err.println(reqOut.toString());
JSONRPC2Response response = sendRequest(reqOut);
if (response.indicatesSuccess()) {
showToast(getString(R.string.txtSyncDone));
}
} catch (JSONRPC2ParseException e2) {
e2.printStackTrace();
showToast(getString(R.string.txtSyncFailed));
}
finish();
}
public void pushRead(){
JSONRPC2Request reqOut = null;
String filter = ARCHIVE + "=1 AND " + ARTICLE_SYNC + "=0";
@ -242,6 +256,14 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
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(){

View File

@ -10,12 +10,16 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_AUTHOR;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import fr.gaulupeau.apps.InThePoche.R;
@ -26,10 +30,12 @@ public class ReadArticle extends Activity {
Button btnMarkRead;
SQLiteDatabase database;
String id = "";
ScrollView view;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.article);
view = (ScrollView) findViewById(R.id.scroll);
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
database = helper.getWritableDatabase();
String[] getStrColumns = new String[] {ARTICLE_URL, ARTICLE_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE, ARTICLE_AUTHOR};
@ -56,6 +62,18 @@ public class ReadArticle extends Activity {
}
});
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
ContentValues values = new ContentValues();
values.put("read_at", view.getScrollY());
database.update(ARTICLE_TABLE, values, ARTICLE_ID + "=" + id, null);
System.out.println(view.getScrollY());
super.onStop();
}
@Override