diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java b/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java index c34339c..334a2b1 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java @@ -1,19 +1,17 @@ package fr.gaulupeau.apps.Poche; -import android.util.Log; - import java.net.URL; public class Article { - public String url; - public String id; - public String title; - public String content; - public String archive; + public String url; + public String id; + public String title; + public String content; + public String archive; private URL m_url = null; - - public Article(String url, String id, String title, String content, String archive) { + + public Article(String url, String id, String title, String content, String archive) { super(); this.url = url; this.id = id; @@ -26,7 +24,7 @@ public class Article { } catch (Exception e) { e.printStackTrace(); } - } + } public String getHostOfUrl() { if (this.m_url != null) { diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java index 9703dff..7a9a261 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; + import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME; import static fr.gaulupeau.apps.Poche.Helpers.zeroUpdate; @@ -11,68 +12,68 @@ import static fr.gaulupeau.apps.Poche.Helpers.zeroUpdate; public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper { - public static final int VERSION = 1; - public static final String DB_NAME = "article_db.sqlite"; - public static String MY_ID = "my_id"; - public static String ARTICLE_TABLE = "article"; - public static String ARTICLE_DATE = "update_date"; - public static String ARTICLE_ID = "article_id"; - public static String ARTICLE_AUTHOR = "author"; - public static String ARTICLE_CONTENT = "content"; - public static String ARTICLE_TITLE = "title"; - 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) { - super(context, DB_NAME, null, VERSION); - c = context; - } + public static final int VERSION = 1; + public static final String DB_NAME = "article_db.sqlite"; + public static String MY_ID = "my_id"; + public static String ARTICLE_TABLE = "article"; + public static String ARTICLE_DATE = "update_date"; + public static String ARTICLE_ID = "article_id"; + public static String ARTICLE_AUTHOR = "author"; + public static String ARTICLE_CONTENT = "content"; + public static String ARTICLE_TITLE = "title"; + 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; - @Override - public void onCreate(SQLiteDatabase db) { - createTables(db); - } + public ArticlesSQLiteOpenHelper(Context context) { + super(context, DB_NAME, null, VERSION); + c = context; + } - - @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); - SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0); - SharedPreferences.Editor editor = preferences.edit(); - editor.putString("previous_update", zeroUpdate); - editor.commit(); - } + @Override + public void onCreate(SQLiteDatabase db) { + createTables(db); + } - protected void createTables(SQLiteDatabase db) { - db.execSQL( - "create table " + ARTICLE_TABLE + " (" + - MY_ID + " integer primary key autoincrement not null, " + - ARTICLE_AUTHOR + " text, " + - ARTICLE_DATE + " datetime, " + - ARTICLE_CONTENT + " text, " + - ARTICLE_TITLE + " text, " + - ARTICLE_URL + " text, " + - ARTICLE_ID + " integer, " + - ARCHIVE + " integer," + - ARTICLE_SYNC + " integer," + - ARTICLE_READAT + " integer," + - "UNIQUE (" + ARTICLE_URL + ")" + - ");" - ); - } - public void truncateTables(SQLiteDatabase db) { - db.execSQL("DELETE FROM " + ARTICLE_TABLE + ";"); - } + @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); + SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0); + SharedPreferences.Editor editor = preferences.edit(); + editor.putString("previous_update", zeroUpdate); + editor.commit(); + } + + protected void createTables(SQLiteDatabase db) { + db.execSQL( + "create table " + ARTICLE_TABLE + " (" + + MY_ID + " integer primary key autoincrement not null, " + + ARTICLE_AUTHOR + " text, " + + ARTICLE_DATE + " datetime, " + + ARTICLE_CONTENT + " text, " + + ARTICLE_TITLE + " text, " + + ARTICLE_URL + " text, " + + ARTICLE_ID + " integer, " + + ARCHIVE + " integer," + + ARTICLE_SYNC + " integer," + + ARTICLE_READAT + " integer," + + "UNIQUE (" + ARTICLE_URL + ")" + + ");" + ); + } + + public void truncateTables(SQLiteDatabase db) { + db.execSQL("DELETE FROM " + ARTICLE_TABLE + ";"); + } } diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/BaseActionBarActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/BaseActionBarActivity.java index b8a98f0..c230a78 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/BaseActionBarActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/BaseActionBarActivity.java @@ -2,7 +2,6 @@ package fr.gaulupeau.apps.Poche; import android.annotation.TargetApi; -import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/Helpers.java b/app/src/main/java/fr/gaulupeau/apps/Poche/Helpers.java index c799f3a..5a89160 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/Helpers.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/Helpers.java @@ -1,36 +1,32 @@ package fr.gaulupeau.apps.Poche; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; -public class Helpers { - - public static final String PREFS_NAME = "InThePoche"; - public final static String zeroUpdate = "2011-01-01 00:00:00"; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; - public static String InputStreamtoString(InputStream is) - { - String s = "",line=""; +public class Helpers { + + public static final String PREFS_NAME = "InThePoche"; + public final static String zeroUpdate = "2011-01-01 00:00:00"; + + public static String InputStreamtoString(InputStream is) { + String s = "", line = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); - try{ - for(; ; rd.readLine()) - { - if((line = rd.readLine())!=null) - { - s +=line; - }else - { + try { + for (; ; rd.readLine()) { + if ((line = rd.readLine()) != null) { + s += line; + } else { break; } } - }catch (IOException e) { + } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } @@ -38,7 +34,7 @@ public class Helpers { } public static String getInputStreamFromUrl(String url) { - InputStream content = null; + InputStream content; String res = ""; try { HttpGet httpGet = new HttpGet(url); diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ListArticles.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ListArticles.java index 18832fe..055b93a 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ListArticles.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ListArticles.java @@ -1,13 +1,8 @@ package fr.gaulupeau.apps.Poche; -import java.util.ArrayList; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.*; -import fr.gaulupeau.apps.InThePoche.R; -import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; @@ -16,12 +11,23 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ListView; +import java.util.ArrayList; + +import fr.gaulupeau.apps.InThePoche.R; + +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARCHIVE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_CONTENT; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TABLE; +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.MY_ID; + public class ListArticles extends BaseActionBarActivity { - private ArrayList
readArticlesInfo; - private ListView readList; + private ArrayList
readArticlesInfo; private SQLiteDatabase database; - + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); @@ -29,77 +35,77 @@ public class ListArticles extends BaseActionBarActivity { setupList(false); } - public void onDestroy() { - super.onDestroy(); - database.close(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.option_list, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menuShowAll: - setupList(true); - return true; - case R.id.menuWipeDb: - ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this); - helper.truncateTables(database); - setupList(false); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - + public void onDestroy() { + super.onDestroy(); + database.close(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.option_list, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menuShowAll: + setupList(true); + return true; + case R.id.menuWipeDb: + ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this); + helper.truncateTables(database); + setupList(false); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + public void setupDB() { ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this); database = helper.getWritableDatabase(); } - + public void setupList(Boolean showAll) { - readList = (ListView) findViewById(R.id.liste_articles); - readArticlesInfo = new ArrayList
(); - String filter = null; - if (showAll == false) { + ListView readList = (ListView) findViewById(R.id.liste_articles); + readArticlesInfo = new ArrayList
(); + String filter = null; + if (!showAll) { filter = ARCHIVE + "=0"; } - ReadingListAdapter ad = getAdapterQuery(filter, readArticlesInfo); - readList.setAdapter(ad); - - readList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + ReadingListAdapter ad = getAdapterQuery(filter, readArticlesInfo); + readList.setAdapter(ad); + + readList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { Intent i = new Intent(getBaseContext(), ReadArticle.class); - i.putExtra("id", (String) readArticlesInfo.get(position).id); + i.putExtra("id", readArticlesInfo.get(position).id); startActivity(i); } - - }); + + }); } - + public ReadingListAdapter getAdapterQuery(String filter, ArrayList
articleInfo) { //Log.e("getAdapterQuery", "running query"); //String url, String domain, String id, String title, String content - String[] getStrColumns = new String[] {ARTICLE_URL, MY_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE}; + String[] getStrColumns = new String[]{ARTICLE_URL, MY_ID, ARTICLE_TITLE, ARTICLE_CONTENT, ARCHIVE}; Cursor ac = database.query( ARTICLE_TABLE, getStrColumns, filter, null, null, null, ARTICLE_DATE + " DESC"); ac.moveToFirst(); - if(!ac.isAfterLast()) { + if (!ac.isAfterLast()) { do { - Article tempArticle = new Article(ac.getString(0),ac.getString(1),ac.getString(2),ac.getString(3),ac.getString(4)); + Article tempArticle = new Article(ac.getString(0), ac.getString(1), ac.getString(2), ac.getString(3), ac.getString(4)); articleInfo.add(tempArticle); } while (ac.moveToNext()); } ac.close(); return new ReadingListAdapter(getBaseContext(), articleInfo); } - + } diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java b/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java index af8b13b..39d0fbf 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java @@ -8,38 +8,6 @@ package fr.gaulupeau.apps.Poche; -import fr.gaulupeau.apps.InThePoche.R; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.SecureRandom; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.text.DateFormat; -import java.util.Date; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.X509TrustManager; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -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.InputSource; -import org.xml.sax.SAXException; - import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; @@ -55,143 +23,159 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.preference.PreferenceManager; 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; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; -import android.widget.EditText; import android.widget.Toast; -import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TABLE; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_URL; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TITLE; -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; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; +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 java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.X509TrustManager; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import fr.gaulupeau.apps.InThePoche.R; + +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARCHIVE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_CONTENT; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_SYNC; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TABLE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TITLE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_URL; +import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME; /** * Main activity class */ -@TargetApi(Build.VERSION_CODES.FROYO) public class Poche extends Activity { +@TargetApi(Build.VERSION_CODES.FROYO) +public class Poche extends Activity { private static SQLiteDatabase database; - Button btnDone; Button btnGetPost; Button btnSync; Button btnSettings; - EditText editPocheUrl; SharedPreferences settings; static String apiUsername; static String apiToken; static String pocheUrl; String action; - - - - /** Called when the activity is first created. - * Will act differently depending on whether sharing or - * displaying information page. */ - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Intent intent = getIntent(); - Bundle extras = intent.getExtras(); - action = intent.getAction(); + /** + * Called when the activity is first created. + * Will act differently depending on whether sharing or + * displaying information page. + */ + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - getSettings(); - // Find out if Sharing or if app has been launched from icon - if (action.equals(Intent.ACTION_SEND) && pocheUrl != "http://") { - 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()) { - // 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) { - // 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 { - // Afficher alerte connectivité - showToast(getString(R.string.txtNetOffline)); - } - } - else { - setContentView(R.layout.main); + Intent intent = getIntent(); + Bundle extras = intent.getExtras(); + action = intent.getAction(); + + getSettings(); + // Find out if Sharing or if app has been launched from icon + if (action.equals(Intent.ACTION_SEND) && !pocheUrl.equals("http://")) { + 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()) { + // 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) { + // 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 { + // Afficher alerte connectivité + showToast(getString(R.string.txtNetOffline)); + } + } else { + setContentView(R.layout.main); checkAndHandleAfterUpdate(); - btnSync = (Button)findViewById(R.id.btnSync); - btnSync.setOnClickListener(new OnClickListener() { + btnSync = (Button) findViewById(R.id.btnSync); + btnSync.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - // Vérification de la connectivité Internet - final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo(); - if (pocheUrl == "http://") { - showToast(getString(R.string.txtConfigNotSet)); - } else if (activeNetwork != null && activeNetwork.isConnected()) { - // Exécution de la synchro en arrière-plan - findViewById(R.id.progressBar1).setVisibility(View.VISIBLE); - new Thread(new Runnable() { - @Override - public void run() { - //pushRead(); - parseRSS(); - runOnUiThread(new Runnable() { - @Override - public void run() { - findViewById(R.id.progressBar1).setVisibility(View.GONE); - } - }); - } - }).start(); - } else { - // Afficher alerte connectivité - showToast(getString(R.string.txtNetOffline)); - } - + // Vérification de la connectivité Internet + final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo(); + if (pocheUrl.equals("http://")) { + showToast(getString(R.string.txtConfigNotSet)); + } else if (activeNetwork != null && activeNetwork.isConnected()) { + // Exécution de la synchro en arrière-plan + findViewById(R.id.progressBar1).setVisibility(View.VISIBLE); + new Thread(new Runnable() { + @Override + public void run() { + //pushRead(); + parseRSS(); + runOnUiThread(new Runnable() { + @Override + public void run() { + findViewById(R.id.progressBar1).setVisibility(View.GONE); + } + }); + } + }).start(); + } else { + // Afficher alerte connectivité + showToast(getString(R.string.txtNetOffline)); + } + } }); - - btnGetPost = (Button)findViewById(R.id.btnGetPost); - //updateUnread(); - + + btnGetPost = (Button) findViewById(R.id.btnGetPost); + //updateUnread(); + btnGetPost.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -199,20 +183,20 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; } }); - btnSettings = (Button)findViewById(R.id.btnSettings); + btnSettings = (Button) findViewById(R.id.btnSettings); btnSettings.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(getBaseContext(), Settings.class)); } }); - } - } + } + } private void checkAndHandleAfterUpdate() { SharedPreferences pref = getSharedPreferences(PREFS_NAME, 0); - if (pref.getInt("update_checker",0) < 9) { + if (pref.getInt("update_checker", 0) < 9) { // Wipe Database, because we now save HTML content instead of plain text ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this); database = helper.getReadableDatabase(); @@ -230,54 +214,50 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; pref.edit().putInt("update_checker", versionCode).commit(); } - private void getSettings(){ - settings = getSharedPreferences(PREFS_NAME, 0); - pocheUrl = settings.getString("pocheUrl", "http://"); - apiUsername = settings.getString("APIUsername", ""); - apiToken = settings.getString("APIToken", ""); - } - - @Override - protected void onResume() { - super.onResume(); - getSettings(); - if (! action.equals(Intent.ACTION_SEND)){ - updateUnread(); - } - } + private void getSettings() { + settings = getSharedPreferences(PREFS_NAME, 0); + pocheUrl = settings.getString("pocheUrl", "http://"); + apiUsername = settings.getString("APIUsername", ""); + apiToken = settings.getString("APIToken", ""); + } - @Override - protected void onDestroy() { - super.onDestroy(); - if (database != null) { - database.close(); + @Override + protected void onResume() { + super.onResume(); + getSettings(); + if (!action.equals(Intent.ACTION_SEND)) { + updateUnread(); } - } - - private void updateUnread(){ - runOnUiThread(new Runnable() { - public void run() - { - ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext()); - database = helper.getReadableDatabase(); - int news = database.query(ARTICLE_TABLE, null, ARCHIVE + "=0", null, null, null, null).getCount(); - btnGetPost.setText(String.format(getString(R.string.btnGetPost), news)); - } - }); - } - - public void showToast(final String toast) - { - runOnUiThread(new Runnable() { - public void run() - { - Toast.makeText(Poche.this, toast, Toast.LENGTH_SHORT).show(); - } - }); - } + } - private void showErrorMessage(final String message) - { + @Override + protected void onDestroy() { + super.onDestroy(); + if (database != null) { + database.close(); + } + } + + private void updateUnread() { + runOnUiThread(new Runnable() { + public void run() { + ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext()); + database = helper.getReadableDatabase(); + int news = database.query(ARTICLE_TABLE, null, ARCHIVE + "=0", null, null, null, null).getCount(); + btnGetPost.setText(String.format(getString(R.string.btnGetPost), news)); + } + }); + } + + public void showToast(final String toast) { + runOnUiThread(new Runnable() { + public void run() { + Toast.makeText(Poche.this, toast, Toast.LENGTH_SHORT).show(); + } + }); + } + + private void showErrorMessage(final String message) { runOnUiThread(new Runnable() { @Override public void run() { @@ -285,7 +265,7 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; messageBox.setMessage(message); messageBox.setTitle(getString(R.string.error)); // messageBox.setIconAttribute(android.R.attr.alertDialogIcon); - messageBox.setPositiveButton("OK",null); + messageBox.setPositiveButton("OK", null); messageBox.setCancelable(false); messageBox.create().show(); } @@ -308,8 +288,8 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; // } // finish(); // } - - + + // public void pushRead(){ // JSONRPC2Request reqOut = null; // String filter = ARCHIVE + "=1 AND " + ARTICLE_SYNC + "=0"; @@ -341,75 +321,80 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; // // } - - public String cleanString(String s){ - - s = s.replace("é", "é"); - s = s.replace("è", "è"); - s = s.replace("ê", "ê"); - s = s.replace("ë", "ë"); - s = s.replace("à", "à"); - s = s.replace("ä", "ä"); - s = s.replace("â", "â"); - s = s.replace("ù", "ù"); - s = s.replace("û", "û"); - s = s.replace("ü", "ü"); - s = s.replace("ô", "ô"); - s = s.replace("ö", "ö"); - s = s.replace("î", "î"); - s = s.replace("ï", "ï"); - s = s.replace("ç", "ç"); - s = s.replace("&", "&"); - return s; - } - - - private void trustEveryone() { - try { - HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){ - public boolean verify(String hostname, SSLSession session) { - return true; - }}); - SSLContext context = SSLContext.getInstance("TLS"); - context.init(null, new X509TrustManager[]{new X509TrustManager(){ - public void checkClientTrusted(X509Certificate[] chain, - String authType) throws CertificateException {} - public void checkServerTrusted(X509Certificate[] chain, - String authType) throws CertificateException {} - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - }}}, new SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory( - context.getSocketFactory()); - } catch (Exception e) { // should never happen - e.printStackTrace(); - } - } - - - public void parseRSS(){ - URL url; - try - { - // Set the url (you will need to change this to your RSS URL - url = new URL(pocheUrl + "/?feed&type=home&user_id=" + apiUsername + "&token=" + apiToken); + public String cleanString(String s) { + + s = s.replace("é", "é"); + s = s.replace("è", "è"); + s = s.replace("ê", "ê"); + s = s.replace("ë", "ë"); + s = s.replace("à", "à"); + s = s.replace("ä", "ä"); + s = s.replace("â", "â"); + s = s.replace("ù", "ù"); + s = s.replace("û", "û"); + s = s.replace("ü", "ü"); + s = s.replace("ô", "ô"); + s = s.replace("ö", "ö"); + s = s.replace("î", "î"); + s = s.replace("ï", "ï"); + s = s.replace("ç", "ç"); + s = s.replace("&", "&"); + return s; + } + + + private void trustEveryone() { + try { + HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }); + SSLContext context = SSLContext.getInstance("TLS"); + context.init(null, new X509TrustManager[]{new X509TrustManager() { + public void checkClientTrusted(X509Certificate[] chain, + String authType) throws CertificateException { + } + + public void checkServerTrusted(X509Certificate[] chain, + String authType) throws CertificateException { + } + + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + }}, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory( + context.getSocketFactory()); + } catch (Exception e) { // should never happen + e.printStackTrace(); + } + } + + + public void parseRSS() { + + URL url; + try { + // Set the url (you will need to change this to your RSS URL + url = new URL(pocheUrl + "/?feed&type=home&user_id=" + apiUsername + "&token=" + apiToken); if (pocheUrl.startsWith("https")) { trustEveryone(); } // Setup the connection - HttpURLConnection urlConnection = null; + HttpURLConnection urlConnection; urlConnection = (HttpURLConnection) url.openConnection(); - if ((urlConnection != null) && (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK)) { + if ((urlConnection != null) && (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK)) { - // Retreive the XML from the URL - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = null; + // Retreive the XML from the URL + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = null; - InputSource is = null; + InputSource is; try { is = new InputSource( @@ -429,107 +414,99 @@ import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_DATE; showErrorMessage("Got invalid response:\n\"" + stringBuffer.toString() + "\""); } - // This is the root node of each section you want to parse - NodeList itemLst = doc.getElementsByTagName("item"); + // This is the root node of each section you want to parse + NodeList itemLst = doc.getElementsByTagName("item"); - // 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()]; - arrays.PodcastDate = new String[itemLst.getLength()]; + // 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()]; + arrays.PodcastDate = new String[itemLst.getLength()]; - // Loop through the XML passing the data to the arrays - for (int i = 0; i < itemLst.getLength(); i++) - { + // 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; + 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 date = ielem.getElementsByTagName("pubDate"); - NodeList content = ielem - .getElementsByTagName("description"); - //NodeList media = ielem - // .getElementsByTagName("media:content"); + // 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 date = ielem.getElementsByTagName("pubDate"); + 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 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] = cleanString(title.item(0).getChildNodes().item(0).getNodeValue()); - } catch (NullPointerException e) - { - e.printStackTrace(); - arrays.PodcastTitle[i] = "Echec"; - } - try { + // 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] = cleanString(title.item(0).getChildNodes().item(0).getNodeValue()); + } catch (NullPointerException e) { + e.printStackTrace(); + arrays.PodcastTitle[i] = "Echec"; + } + try { arrays.PodcastDate[i] = date.item(0).getChildNodes().item(0).getNodeValue(); } catch (NullPointerException e) { e.printStackTrace(); - arrays.PodcastDate[i] = null; + arrays.PodcastDate[i] = null; } - try - { - arrays.PodcastURL[i] = link.item(0).getChildNodes() - .item(0).getNodeValue(); - } catch (NullPointerException e) - { - e.printStackTrace(); - arrays.PodcastURL[i] = "Echec"; - } - try - { - arrays.PodcastContent[i] = content.item(0) - .getChildNodes().item(0).getNodeValue(); - } catch (NullPointerException e) - { - e.printStackTrace(); - arrays.PodcastContent[i] = "Echec"; - } - - ContentValues values = new ContentValues(); - values.put(ARTICLE_TITLE, arrays.PodcastTitle[i]); - values.put(ARTICLE_CONTENT, arrays.PodcastContent[i]); - //values.put(ARTICLE_ID, Html.fromHtml(article.getString("id")).toString()); - values.put(ARTICLE_URL, arrays.PodcastURL[i]); - values.put(ARTICLE_DATE, arrays.PodcastDate[i]); - values.put(ARCHIVE, 0); - values.put(ARTICLE_SYNC, 0); - try { - database.insertOrThrow(ARTICLE_TABLE, null, values); - } catch (SQLiteConstraintException e) { - continue; - } catch (SQLiteException e) { - database.execSQL("ALTER TABLE " + ARTICLE_TABLE + " ADD COLUMN " + ARTICLE_DATE + " datetime;"); - database.insertOrThrow(ARTICLE_TABLE, null, values); - } - } - } - - } + try { + arrays.PodcastURL[i] = link.item(0).getChildNodes() + .item(0).getNodeValue(); + } catch (NullPointerException e) { + e.printStackTrace(); + arrays.PodcastURL[i] = "Echec"; + } + try { + arrays.PodcastContent[i] = content.item(0) + .getChildNodes().item(0).getNodeValue(); + } catch (NullPointerException e) { + e.printStackTrace(); + arrays.PodcastContent[i] = "Echec"; + } + + ContentValues values = new ContentValues(); + values.put(ARTICLE_TITLE, arrays.PodcastTitle[i]); + values.put(ARTICLE_CONTENT, arrays.PodcastContent[i]); + //values.put(ARTICLE_ID, Html.fromHtml(article.getString("id")).toString()); + values.put(ARTICLE_URL, arrays.PodcastURL[i]); + values.put(ARTICLE_DATE, arrays.PodcastDate[i]); + values.put(ARCHIVE, 0); + values.put(ARTICLE_SYNC, 0); + try { + database.insertOrThrow(ARTICLE_TABLE, null, values); + } catch (SQLiteConstraintException e) { + continue; + } catch (SQLiteException e) { + database.execSQL("ALTER TABLE " + ARTICLE_TABLE + " ADD COLUMN " + ARTICLE_DATE + " datetime;"); + database.insertOrThrow(ARTICLE_TABLE, null, values); + } + } + } + + } showToast(getString(R.string.txtSyncDone)); - updateUnread(); - } catch (Exception e) { + updateUnread(); + } catch (Exception e) { e.printStackTrace(); } - - } - + + } + // public void fetchUnread(){ // String id = "req-001"; // JSONRPC2Request reqOut = null; diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ReadArticle.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ReadArticle.java index 6c42159..594ff2b 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ReadArticle.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ReadArticle.java @@ -1,58 +1,45 @@ package fr.gaulupeau.apps.Poche; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARCHIVE; -import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_CONTENT; -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_URL; -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.MY_ID; - -import android.annotation.TargetApi; -import android.app.Activity; import android.content.ContentValues; -import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.os.Build; import android.os.Bundle; -import android.view.MenuItem; -import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; -import android.view.View.OnTouchListener; -import android.view.Window; -import android.webkit.WebChromeClient; import android.webkit.WebView; -import android.webkit.WebViewClient; import android.widget.Button; import android.widget.ScrollView; -import android.widget.TextView; import java.net.URL; import fr.gaulupeau.apps.InThePoche.R; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARCHIVE; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_AUTHOR; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_CONTENT; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_ID; +import static fr.gaulupeau.apps.Poche.ArticlesSQLiteOpenHelper.ARTICLE_TABLE; +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.MY_ID; + public class ReadArticle extends BaseActionBarActivity { WebView webViewContent; Button btnMarkRead; - SQLiteDatabase database; - String id = ""; - ScrollView view; - + SQLiteDatabase database; + String id = ""; + ScrollView view; + public void onCreate(Bundle savedInstanceState) { - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - requestWindowFeature(Window.FEATURE_PROGRESS); 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, MY_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(); - if(data != null) { + if (data != null) { id = data.getString("id"); } Cursor ac = database.query(ARTICLE_TABLE, getStrColumns, MY_ID + "=" + id, null, null, null, null); @@ -66,8 +53,7 @@ public class ReadArticle extends BaseActionBarActivity { try { URL originalUrl = new URL(originalUrlText); originalUrlDesc = originalUrl.getHost(); - } - catch (Exception e) { + } catch (Exception e) { // } @@ -83,8 +69,8 @@ public class ReadArticle extends BaseActionBarActivity { "\t\t\t\t
\n" + "\t\t\t\t\t
\n" + "\t\t\t\t\t\t
\n" + - "\t\t\t\t\t\t\t

"+ titleText +"

\n" + - "\t\t\t\t\t\t\t

Open Original: "+ originalUrlDesc +"

\n" + + "\t\t\t\t\t\t\t

" + titleText + "

\n" + + "\t\t\t\t\t\t\t

Open Original: " + originalUrlDesc + "

\n" + "\t\t\t\t\t\t
\n" + "\t\t\t\t\t\t
"; String htmlFooter = "
\n" + @@ -95,24 +81,12 @@ public class ReadArticle extends BaseActionBarActivity { ""; - setProgressBarIndeterminateVisibility(true); - setProgressBarVisibility(true); - - webViewContent = (WebView)findViewById(R.id.webViewContent); - webViewContent.setWebChromeClient(new WebChromeClient() { - public void onProgressChanged(WebView view, int progress) { - setProgress(progress * 100); - if(progress == 100) { - setProgressBarIndeterminateVisibility(false); - setProgressBarVisibility(false); - } - } - }); + webViewContent = (WebView) findViewById(R.id.webViewContent); webViewContent.loadDataWithBaseURL("file:///android_asset/", htmlHeader + htmlContent + htmlFooter, "text/html", "utf-8", null); - btnMarkRead = (Button)findViewById(R.id.btnMarkRead); + btnMarkRead = (Button) findViewById(R.id.btnMarkRead); btnMarkRead.setOnClickListener(new OnClickListener() { - + @Override public void onClick(View v) { ContentValues values = new ContentValues(); @@ -121,21 +95,21 @@ public class ReadArticle extends BaseActionBarActivity { finish(); } }); - - + + } @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 protected void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java index 57f01d9..039ffb5 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java @@ -1,56 +1,51 @@ package fr.gaulupeau.apps.Poche; -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; import android.widget.BaseAdapter; import android.widget.TextView; +import java.util.List; + +import fr.gaulupeau.apps.InThePoche.R; + public class ReadingListAdapter extends BaseAdapter { - private Context context; - private List
listArticles; + private Context context; + private List
listArticles; - public ReadingListAdapter(Context context, List
listArticles) { - this.context = context; - this.listArticles = listArticles; - } + public ReadingListAdapter(Context context, List
listArticles) { + this.context = context; + this.listArticles = listArticles; + } - public int getCount() { - return listArticles.size(); - } + public int getCount() { + return listArticles.size(); + } - public Object getItem(int position) { - return listArticles.get(position); - } + public Object getItem(int position) { + return listArticles.get(position); + } - public long getItemId(int position) { - return position; - } - - public View getView(int position, View convertView, ViewGroup parent) { - Article entry = listArticles.get(position); - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.article_list, parent, false); - } - TextView tvTitle = (TextView) convertView.findViewById(R.id.listitem_titre); - TextView tvHost = (TextView) convertView.findViewById(R.id.listitem_textview_url); - - tvTitle.setText(entry.title); - tvHost.setText(entry.getHostOfUrl()); - - return convertView; - } + public long getItemId(int position) { + return position; + } + public View getView(int position, View convertView, ViewGroup parent) { + Article entry = listArticles.get(position); + if (convertView == null) { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.article_list, parent, false); + } + TextView tvTitle = (TextView) convertView.findViewById(R.id.listitem_titre); + TextView tvHost = (TextView) convertView.findViewById(R.id.listitem_textview_url); + tvTitle.setText(entry.title); + tvHost.setText(entry.getHostOfUrl()); + return convertView; + } } diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/Settings.java b/app/src/main/java/fr/gaulupeau/apps/Poche/Settings.java index 38f1afc..2edd500 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/Settings.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/Settings.java @@ -1,24 +1,22 @@ package fr.gaulupeau.apps.Poche; -import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME; -import fr.gaulupeau.apps.InThePoche.R; -import android.app.Activity; import android.content.SharedPreferences; -import android.os.Build; import android.os.Bundle; -import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; +import fr.gaulupeau.apps.InThePoche.R; + +import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME; + public class Settings extends BaseActionBarActivity { Button btnDone; EditText editPocheUrl; EditText editAPIUsername; EditText editAPIToken; - EditText editGlobalToken; TextView textViewVersion; @Override @@ -26,28 +24,28 @@ public class Settings extends BaseActionBarActivity { super.onCreate(savedInstanceState); setContentView(R.layout.settings); - SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); - String pocheUrl = settings.getString("pocheUrl", "http://"); - String apiUsername = settings.getString("APIUsername", ""); - String apiToken = settings.getString("APIToken", ""); - editPocheUrl = (EditText)findViewById(R.id.pocheUrl); - editPocheUrl.setText(pocheUrl); - editAPIUsername = (EditText)findViewById(R.id.APIUsername); - editAPIUsername.setText(apiUsername); - editAPIToken = (EditText)findViewById(R.id.APIToken); - editAPIToken.setText(apiToken); - btnDone = (Button)findViewById(R.id.btnDone); - btnDone.setOnClickListener(new OnClickListener() { + SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); + String pocheUrl = settings.getString("pocheUrl", "http://"); + String apiUsername = settings.getString("APIUsername", ""); + String apiToken = settings.getString("APIToken", ""); + editPocheUrl = (EditText) findViewById(R.id.pocheUrl); + editPocheUrl.setText(pocheUrl); + editAPIUsername = (EditText) findViewById(R.id.APIUsername); + editAPIUsername.setText(apiUsername); + editAPIToken = (EditText) findViewById(R.id.APIToken); + editAPIToken.setText(apiToken); + btnDone = (Button) findViewById(R.id.btnDone); + btnDone.setOnClickListener(new OnClickListener() { public void onClick(View v) { SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); - SharedPreferences.Editor editor = settings.edit(); - editor.putString("pocheUrl", editPocheUrl.getText().toString()); - editor.putString("APIUsername", editAPIUsername.getText().toString()); - editor.putString("APIToken", editAPIToken.getText().toString()); + SharedPreferences.Editor editor = settings.edit(); + editor.putString("pocheUrl", editPocheUrl.getText().toString()); + editor.putString("APIUsername", editAPIUsername.getText().toString()); + editor.putString("APIToken", editAPIToken.getText().toString()); editor.commit(); finish(); } - }); + }); try { textViewVersion = (TextView) findViewById(R.id.version); textViewVersion.setText(getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0).versionName); diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/arrays.java b/app/src/main/java/fr/gaulupeau/apps/Poche/arrays.java index 288c7f4..a993a45 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/arrays.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/arrays.java @@ -1,9 +1,9 @@ package fr.gaulupeau.apps.Poche; public class arrays { - public static String[] PodcastTitle; - public static String[] PodcastURL; - public static String[] PodcastContent; - public static String[] PodcastMedia; - public static String[] PodcastDate; + public static String[] PodcastTitle; + public static String[] PodcastURL; + public static String[] PodcastContent; + public static String[] PodcastMedia; + public static String[] PodcastDate; }