Correction problème encodage. Possibilité de vider la BD locale.

This commit is contained in:
GAULUPEAU Jonathan 2014-01-05 18:54:27 +01:00
parent d6f6aba6f4
commit c6150513a2
7 changed files with 46 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menuShowAll" android:title="@string/menuShowAll"></item>
<item android:id="@+id/menuWipeDb" android:title="@string/menuWipeDb"></item>
</menu>

View File

@ -15,6 +15,7 @@
<string name="btnMarkRead">Mark as Read</string>
<string name="menuSettings">Settings</string>
<string name="menuShowAll">Show All</string>
<string name="menuWipeDb">Wipe Database</string>
<string name="txtSyncDone">Synchronize done !</string>
<string name="txtSyncFailed">Synchronize failed !</string>
<string name="txtNetOffline">Check Internet Connectivity !</string>

View File

@ -69,6 +69,8 @@ public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
);
}
public void truncateTables(SQLiteDatabase db) {
db.execSQL("DELETE FROM " + ARTICLE_TABLE + ";");
}
}

View File

@ -50,6 +50,12 @@ public class ListArticles extends Activity {
switch (item.getItemId()) {
case R.id.menuShowAll:
setupList(true);
return super.onOptionsItemSelected(item);
case R.id.menuWipeDb:
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this);
helper.truncateTables(database);
setupList(false);
super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}

View File

@ -11,6 +11,7 @@ package fr.gaulupeau.apps.Poche;
import fr.gaulupeau.apps.InThePoche.R;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
@ -30,6 +31,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException;
@ -72,6 +74,8 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_CONTENT;
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARCHIVE;
import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
/**
* Main activity class
*/
@ -295,6 +299,26 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
// }
public String cleanString(String s){
s = s.replace("&Atilde;&copy;", "&eacute;");
s = s.replace("&Atilde;&uml;", "&egrave;");
s = s.replace("&Atilde;&ordf;", "&ecirc;");
s = s.replace("&Atilde;&laquo;", "&euml;");
s = s.replace("&Atilde;&nbsp;", "&agrave;");
s = s.replace("&Atilde;&curren;", "&auml;");
s = s.replace("&Atilde;&cent;", "&acirc;");
s = s.replace("&Atilde;&sup1;", "&ugrave;");
s = s.replace("&Atilde;&raquo;", "&ucirc;");
s = s.replace("&Atilde;&frac14;", "&uuml;");
s = s.replace("&Atilde;&acute;", "&ocirc;");
s = s.replace("&Atilde;&para;", "&ouml;");
s = s.replace("&Atilde;&reg;", "&icirc;");
s = s.replace("&Atilde;&macr;", "&iuml;");
s = s.replace("&Atilde;&sect;", "&ccedil;");
s = s.replace("&amp;", "&amp;");
return s;
}
public void parseRSS(){
@ -318,8 +342,13 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc;
doc = db.parse(url.openStream());
// doc = db.parse(
// new InputSource(
// new InputStreamReader(
// url.openStream(),
// "latin-1")));
doc.getDocumentElement().normalize();
// This is the root node of each section you want to parse
NodeList itemLst = doc.getElementsByTagName("item");
@ -359,8 +388,7 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC;
// exist
try
{
arrays.PodcastTitle[i] = title.item(0)
.getChildNodes().item(0).getNodeValue();
arrays.PodcastTitle[i] = cleanString(title.item(0).getChildNodes().item(0).getNodeValue());
} catch (NullPointerException e)
{
e.printStackTrace();

View File

@ -19,6 +19,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
@ -50,8 +51,9 @@ public class ReadArticle extends Activity {
txtTitre.setText(ac.getString(2));
txtContent = (TextView)findViewById(R.id.txtContent);
txtContent.setText(ac.getString(3));
txtAuthor = (TextView)findViewById(R.id.txtAuthor);
txtAuthor.setText(ac.getString(5));
txtAuthor.setText(ac.getString(0));
btnMarkRead = (Button)findViewById(R.id.btnMarkRead);
btnMarkRead.setOnClickListener(new OnClickListener() {

View File

@ -5,6 +5,7 @@ import java.util.List;
import fr.gaulupeau.apps.InThePoche.R;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;