Modifications cosmetiques. Ajout champs ARTICLE_ID unique

This commit is contained in:
GAULUPEAU Jonathan 2013-11-13 14:56:49 +01:00
parent b50a7c1286
commit c5406fc96b
10 changed files with 81 additions and 47 deletions

View File

@ -2,14 +2,14 @@
<manifest package="fr.gaulupeau.apps.InThePoche" <manifest package="fr.gaulupeau.apps.InThePoche"
android:versionCode="3" android:versionCode="3"
android:versionName="1.0.2" xmlns:android="http://schemas.android.com/apk/res/android"> android:versionName="1.0.2" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="4" <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"/>
<application android:icon="@drawable/icon" android:label="@string/app_name"> <application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="fr.gaulupeau.apps.Poche.Poche" <activity android:name="fr.gaulupeau.apps.Poche.Poche"
android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"> android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />

View File

@ -15,11 +15,31 @@
android:text="Titre" android:text="Titre"
android:textSize="25sp" /> android:textSize="25sp" />
<TextView
android:id="@+id/txtAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Author"
android:textSize="12sp" />
<View
android:id="@+id/viewLine"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#000000" />
<TextView <TextView
android:id="@+id/txtContent" android:id="@+id/txtContent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Contenu" /> android:text="Contenu"
android:textSize="18sp" />
<Button
android:id="@+id/btnMarkRead"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnMarkRead" />
</LinearLayout> </LinearLayout>

View File

@ -8,7 +8,10 @@
<ListView <ListView
android:id="@+id/liste_articles" android:id="@+id/liste_articles"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content"
android:divider="#000000"
android:dividerHeight="1dp" >
</ListView> </ListView>
</LinearLayout> </LinearLayout>

View File

@ -9,7 +9,8 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="30sp" android:paddingLeft="30sp"
android:paddingRight="30sp" > android:paddingRight="30sp"
android:paddingTop="15dp" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -78,22 +79,20 @@
<Button <Button
android:id="@+id/btnDone" android:id="@+id/btnDone"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btnDone" /> android:text="@string/btnDone" />
<Button <Button
android:id="@+id/btnGetPost" android:id="@+id/btnGetPost"
style="?android:attr/buttonStyleSmall" android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/btnGetPost" /> android:text="@string/btnGetPost" />
<Button <Button
android:id="@+id/btnSync" android:id="@+id/btnSync"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/btnSync" /> android:text="@string/btnSync" />

View File

@ -10,6 +10,7 @@
<string name="authorSite">http://cv.gaulupeau.fr</string> <string name="authorSite">http://cv.gaulupeau.fr</string>
<string name="url_label"><b><u>Your poche URL :</u></b></string> <string name="url_label"><b><u>Your poche URL :</u></b></string>
<string name="url_help">Examples:\n<i>http://poche.example.fr</i>\n<i>http://www.example.fr/poche</i></string> <string name="url_help">Examples:\n<i>http://poche.example.fr</i>\n<i>http://www.example.fr/poche</i></string>
<string name="btnGetPost">Save the post</string> <string name="btnGetPost">List articles</string>
<string name="btnSync">Syncroniser</string> <string name="btnSync">Syncronise</string>
<string name="btnMarkRead">Mark as Read</string>
</resources> </resources>

View File

@ -52,7 +52,8 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
ARTICLE_TITLE + " text, " + ARTICLE_TITLE + " text, " +
ARTICLE_URL + " text, " + ARTICLE_URL + " text, " +
ARTICLE_ID + " integer, " + ARTICLE_ID + " integer, " +
ARCHIVE + " integer" + ARCHIVE + " integer," +
"UNIQUE (" + ARTICLE_ID + ")" +
");" ");"
); );
db.execSQL( db.execSQL(

View File

@ -59,7 +59,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, ARTICLE_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE};
Cursor ac = database.query( Cursor ac = database.query(

View File

@ -11,6 +11,7 @@ package fr.gaulupeau.apps.Poche;
import fr.gaulupeau.apps.InThePoche.R; import fr.gaulupeau.apps.InThePoche.R;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -19,6 +20,7 @@ import android.app.Activity;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -80,8 +82,6 @@ import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl;
} }
String base64 = Base64.encodeToString(data, Base64.DEFAULT); String base64 = Base64.encodeToString(data, Base64.DEFAULT);
pocheSaveUrl.appendQueryParameter("url", base64); pocheSaveUrl.appendQueryParameter("url", base64);
System.out.println("base64 : " + base64);
System.out.println("pageurl : " + pageUrl);
// Load the constructed URL in the browser // Load the constructed URL in the browser
@ -119,17 +119,25 @@ import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl;
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String ret = getInputStreamFromUrl("http://poche.gaulupeau.fr/toto.php"); String ret = getInputStreamFromUrl("http://poche.gaulupeau.fr/toto.php");
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
database = helper.getWritableDatabase();
try { try {
JSONObject rootobj = new JSONObject(ret); JSONArray rootobj = new JSONArray(ret);
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext()); for (int i=0; i<rootobj.length(); i++) {
database = helper.getWritableDatabase(); JSONObject article = rootobj.getJSONObject(i);
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(ARTICLE_TITLE, Html.fromHtml(rootobj.getString("titre")).toString()); values.put(ARTICLE_TITLE, Html.fromHtml(article.getString("titre")).toString());
values.put(ARTICLE_CONTENT, Html.fromHtml(rootobj.getString("content")).toString()); values.put(ARTICLE_CONTENT, Html.fromHtml(article.getString("content")).toString());
values.put(ARTICLE_ID, Html.fromHtml(rootobj.getString("id")).toString()); values.put(ARTICLE_ID, Html.fromHtml(article.getString("id")).toString());
values.put(ARTICLE_URL, Html.fromHtml(rootobj.getString("url")).toString()); values.put(ARTICLE_URL, Html.fromHtml(article.getString("url")).toString());
values.put(ARCHIVE, 0); values.put(ARCHIVE, 0);
database.insert(ARTICLE_TABLE, null, values); try {
database.insertOrThrow(ARTICLE_TABLE, null, values);
} catch (SQLiteConstraintException e) {
continue;
}
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -6,22 +6,24 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_ID;
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TITLE; 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.Helpers.getInputStreamFromUrl; import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_AUTHOR;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import fr.gaulupeau.apps.InThePoche.R; import fr.gaulupeau.apps.InThePoche.R;
public class ReadArticle extends Activity { public class ReadArticle extends Activity {
TextView txtTitre; TextView txtTitre;
TextView txtContent; TextView txtContent;
TextView txtAuthor;
Button btnMarkRead;
SQLiteDatabase database; SQLiteDatabase database;
String id = ""; String id = "";
@ -30,7 +32,7 @@ public class ReadArticle extends Activity {
setContentView(R.layout.article); setContentView(R.layout.article);
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}; String[] getStrColumns = new String[] {ARTICLE_URL, ARTICLE_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");
@ -41,19 +43,19 @@ public class ReadArticle extends Activity {
txtTitre.setText(ac.getString(2)); txtTitre.setText(ac.getString(2));
txtContent = (TextView)findViewById(R.id.txtContent); txtContent = (TextView)findViewById(R.id.txtContent);
txtContent.setText(ac.getString(3)); txtContent.setText(ac.getString(3));
// String ret = getInputStreamFromUrl("http://poche.gaulupeau.fr/toto.php"); txtAuthor = (TextView)findViewById(R.id.txtAuthor);
// try { txtAuthor.setText(ac.getString(5));
// JSONObject rootobj = new JSONObject(ret); btnMarkRead = (Button)findViewById(R.id.btnMarkRead);
// System.out.println(rootobj); btnMarkRead.setOnClickListener(new OnClickListener() {
// txtTitre = (TextView)findViewById(R.id.txtTitre);
// txtContent = (TextView)findViewById(R.id.txtContent); @Override
// txtTitre.setText(Html.fromHtml(rootobj.getString("titre"))); public void onClick(View v) {
// txtContent.setText(Html.fromHtml(rootobj.getString("content"))); ContentValues values = new ContentValues();
// } catch (JSONException e) { values.put(ARCHIVE, 1);
// // TODO Auto-generated catch block database.update(ARTICLE_TABLE, values, ARTICLE_ID + "=" + id, null);
// e.printStackTrace(); }
// } });
} }
} }

View File

@ -42,7 +42,7 @@ public class ReadingListAdapter extends BaseAdapter {
convertView = inflater.inflate(R.layout.article_list, null); convertView = inflater.inflate(R.layout.article_list, null);
} }
TextView tvTitle = (TextView) convertView.findViewById(R.id.listitem_titre); TextView tvTitle = (TextView) convertView.findViewById(R.id.listitem_titre);
Log.e("title", entry.title); //Log.e("title", entry.title);
tvTitle.setText(entry.title); tvTitle.setText(entry.title);
return convertView; return convertView;