164 lines
5.2 KiB
Java
164 lines
5.2 KiB
Java
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;
|
|
|
|
public class ReadArticle extends Activity {
|
|
WebView webViewContent;
|
|
Button btnMarkRead;
|
|
SQLiteDatabase database;
|
|
String id = "";
|
|
ScrollView view;
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
|
requestWindowFeature(Window.FEATURE_PROGRESS);
|
|
setContentView(R.layout.article);
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
try {
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
} catch (Exception e) {
|
|
//
|
|
}
|
|
}
|
|
|
|
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};
|
|
Bundle data = getIntent().getExtras();
|
|
if(data != null) {
|
|
id = data.getString("id");
|
|
}
|
|
Cursor ac = database.query(ARTICLE_TABLE, getStrColumns, MY_ID + "=" + id, null, null, null, null);
|
|
ac.moveToFirst();
|
|
|
|
String titleText = ac.getString(2);
|
|
String originalUrlText = ac.getString(0);
|
|
String originalUrlDesc = originalUrlText;
|
|
String htmlContent = ac.getString(3);
|
|
|
|
try {
|
|
URL originalUrl = new URL(originalUrlText);
|
|
originalUrlDesc = originalUrl.getHost();
|
|
}
|
|
catch (Exception e) {
|
|
//
|
|
}
|
|
|
|
String htmlHeader = "<html>\n" +
|
|
"\t<head>\n" +
|
|
"\t\t<meta name=\"viewport\" content=\"initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />\n" +
|
|
"\t\t<meta charset=\"utf-8\">\n" +
|
|
"\t\t<link rel=\"stylesheet\" href=\"main.css\" media=\"all\" id=\"main-theme\">\n" +
|
|
"\t\t<link rel=\"stylesheet\" href=\"ratatouille.css\" media=\"all\" id=\"extra-theme\">\n" +
|
|
"\t</head>\n" +
|
|
"\t\t<div id=\"main\">\n" +
|
|
"\t\t\t<body>\n" +
|
|
"\t\t\t\t<div id=\"content\" class=\"w600p center\">\n" +
|
|
"\t\t\t\t\t<div id=\"article\">\n" +
|
|
"\t\t\t\t\t\t<header class=\"mbm\">\n" +
|
|
"\t\t\t\t\t\t\t<h1>"+ titleText +"</h1>\n" +
|
|
"\t\t\t\t\t\t\t<p>Open Original: <a href=\""+ originalUrlText +"\">"+ originalUrlDesc +"</a></p>\n" +
|
|
"\t\t\t\t\t\t</header>\n" +
|
|
"\t\t\t\t\t\t<article>";
|
|
String htmlFooter = "</article>\n" +
|
|
"\t\t\t\t\t</div>\n" +
|
|
"\t\t\t\t</div>\n" +
|
|
"\t\t\t</body>\n" +
|
|
"\t\t</div>\n" +
|
|
"</html>";
|
|
|
|
|
|
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.loadDataWithBaseURL("file:///android_asset/", htmlHeader + htmlContent + htmlFooter, "text/html", "utf-8", null);
|
|
|
|
btnMarkRead = (Button)findViewById(R.id.btnMarkRead);
|
|
btnMarkRead.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
ContentValues values = new ContentValues();
|
|
values.put(ARCHIVE, 1);
|
|
database.update(ARTICLE_TABLE, values, MY_ID + "=" + id, null);
|
|
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();
|
|
database.close();
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
switch (item.getItemId()) {
|
|
case android.R.id.home:
|
|
this.finish();
|
|
return super.onOptionsItemSelected(item);
|
|
default:
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
}
|
|
}
|