summaryrefslogtreecommitdiff
path: root/src/org/fox/ttrss/OnlineActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/fox/ttrss/OnlineActivity.java')
-rw-r--r--src/org/fox/ttrss/OnlineActivity.java146
1 files changed, 126 insertions, 20 deletions
diff --git a/src/org/fox/ttrss/OnlineActivity.java b/src/org/fox/ttrss/OnlineActivity.java
index 7530ff1e..da1a6f17 100644
--- a/src/org/fox/ttrss/OnlineActivity.java
+++ b/src/org/fox/ttrss/OnlineActivity.java
@@ -39,15 +39,24 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
+import android.webkit.WebView;
+import android.webkit.WebView.HitTestResult;
import android.widget.EditText;
import android.widget.SearchView;
import android.widget.ShareActionProvider;
+import android.widget.TextView;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+
public class OnlineActivity extends CommonActivity {
private final String TAG = this.getClass().getSimpleName();
@@ -61,6 +70,8 @@ public class OnlineActivity extends CommonActivity {
private ActionMode m_headlinesActionMode;
private HeadlinesActionModeCallback m_headlinesActionModeCallback;
+ private String m_lastImageHitTestUrl;
+
private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context content, Intent intent) {
@@ -129,20 +140,13 @@ public class OnlineActivity extends CommonActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
+ ApiRequest.disableConnectionReuseIfNecessary();
+
+ // we use that before parent onCreate so let's init locally
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
- ApiRequest.disableConnectionReuseIfNecessary();
-
- if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
- setTheme(R.style.DarkTheme);
- } else if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_SEPIA")) {
- setTheme(R.style.SepiaTheme);
- } else if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK_GRAY")) {
- setTheme(R.style.DarkGrayTheme);
- } else {
- setTheme(R.style.LightTheme);
- }
+ setAppTheme(m_prefs);
super.onCreate(savedInstanceState);
@@ -536,6 +540,66 @@ public class OnlineActivity extends CommonActivity {
final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
switch (item.getItemId()) {
+ case R.id.article_img_open:
+ if (getLastContentImageHitTestUrl() != null) {
+ try {
+ Intent intent = new Intent(Intent.ACTION_VIEW,
+ Uri.parse(getLastContentImageHitTestUrl()));
+ startActivity(intent);
+ } catch (Exception e) {
+ e.printStackTrace();
+ toast(R.string.error_other_error);
+ }
+ }
+ return true;
+ case R.id.article_img_share:
+ if (getLastContentImageHitTestUrl() != null) {
+ Intent intent = new Intent(Intent.ACTION_SEND);
+
+ intent.setType("image/png");
+ intent.putExtra(Intent.EXTRA_SUBJECT, getLastContentImageHitTestUrl());
+ intent.putExtra(Intent.EXTRA_TEXT, getLastContentImageHitTestUrl());
+
+ startActivity(Intent.createChooser(intent, getLastContentImageHitTestUrl()));
+ }
+ return true;
+ case R.id.article_img_view_caption:
+ if (getLastContentImageHitTestUrl() != null) {
+
+ // Android doesn't give us an easy way to access title tags;
+ // we'll use Jsoup on the body text to grab the title text
+ // from the first image tag with this url. This will show
+ // the wrong text if an image is used multiple times.
+ Document doc = Jsoup.parse(ap.getSelectedArticle().content);
+ Elements es = doc.getElementsByAttributeValue("src", getLastContentImageHitTestUrl());
+ if (es.size() > 0){
+ if (es.get(0).hasAttr("title")){
+ Dialog dia = new Dialog(this);
+ if (es.get(0).hasAttr("alt")){
+ dia.setTitle(es.get(0).attr("alt"));
+ } else {
+ dia.setTitle(es.get(0).attr("title"));
+ }
+ TextView titleText = new TextView(this);
+
+ if (android.os.Build.VERSION.SDK_INT >= 16) {
+ titleText.setPaddingRelative(24, 24, 24, 24);
+ } else {
+ titleText.setPadding(24, 24, 24, 24);
+ }
+
+ titleText.setTextSize(16);
+ titleText.setText(es.get(0).attr("title"));
+ dia.setContentView(titleText);
+ dia.show();
+ } else {
+ toast(R.string.no_caption_to_display);
+ }
+ } else {
+ toast(R.string.no_caption_to_display);
+ }
+ }
+ return true;
case R.id.article_link_share:
if (ap != null && ap.getSelectedArticle() != null) {
shareArticle(ap.getSelectedArticle());
@@ -584,6 +648,7 @@ public class OnlineActivity extends CommonActivity {
Dialog dialog = new Dialog(OnlineActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this)
.setTitle(R.string.attachments_prompt)
+ .setCancelable(true)
.setSingleChoiceItems(items, 0, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@@ -807,11 +872,11 @@ public class OnlineActivity extends CommonActivity {
}
return true;
case R.id.share_article:
- if (android.os.Build.VERSION.SDK_INT < 14) {
+ //if (android.os.Build.VERSION.SDK_INT < 14) {
if (ap != null) {
shareArticle(ap.getSelectedArticle());
}
- }
+ //}
return true;
case R.id.toggle_marked:
if (ap != null & ap.getSelectedArticle() != null) {
@@ -841,6 +906,7 @@ public class OnlineActivity extends CommonActivity {
toggleArticlesUnread(selected);
hf.notifyUpdated();
+ initMenu();
}
}
return true;
@@ -854,6 +920,7 @@ public class OnlineActivity extends CommonActivity {
toggleArticlesMarked(selected);
hf.notifyUpdated();
+ initMenu();
}
}
return true;
@@ -867,6 +934,7 @@ public class OnlineActivity extends CommonActivity {
toggleArticlesPublished(selected);
hf.notifyUpdated();
+ initMenu();
}
}
return true;
@@ -894,6 +962,7 @@ public class OnlineActivity extends CommonActivity {
if (tmp.size() > 0) {
toggleArticlesUnread(tmp);
hf.notifyUpdated();
+ initMenu();
}
}
}
@@ -901,8 +970,12 @@ public class OnlineActivity extends CommonActivity {
case R.id.set_unread:
if (ap != null && ap.getSelectedArticle() != null) {
Article a = ap.getSelectedArticle();
- a.unread = true;
- saveArticleUnread(a);
+
+ if (a != null) {
+ a.unread = !a.unread;
+ saveArticleUnread(a);
+ }
+
if (hf != null) hf.notifyUpdated();
}
return true;
@@ -1126,7 +1199,12 @@ public class OnlineActivity extends CommonActivity {
@SuppressWarnings({ "unchecked", "serial" })
public void saveArticleUnread(final Article article) {
- ApiRequest req = new ApiRequest(getApplicationContext());
+ ApiRequest req = new ApiRequest(getApplicationContext()) {
+ protected void onPostExecute(JsonElement result) {
+ //toast(R.string.article_set_unread);
+ initMenu();
+ }
+ };
HashMap<String, String> map = new HashMap<String, String>() {
{
@@ -1145,7 +1223,8 @@ public class OnlineActivity extends CommonActivity {
public void saveArticleMarked(final Article article) {
ApiRequest req = new ApiRequest(getApplicationContext()) {
protected void onPostExecute(JsonElement result) {
- toast(article.marked ? R.string.notify_article_marked : R.string.notify_article_unmarked);
+ //toast(article.marked ? R.string.notify_article_marked : R.string.notify_article_unmarked);
+ initMenu();
}
};
@@ -1167,7 +1246,8 @@ public class OnlineActivity extends CommonActivity {
ApiRequest req = new ApiRequest(getApplicationContext()) {
protected void onPostExecute(JsonElement result) {
- toast(article.published ? R.string.notify_article_published : R.string.notify_article_unpublished);
+ //toast(article.published ? R.string.notify_article_published : R.string.notify_article_unpublished);
+ initMenu();
}
};
@@ -1382,7 +1462,24 @@ public class OnlineActivity extends CommonActivity {
MenuItem search = m_menu.findItem(R.id.search);
search.setEnabled(getApiLevel() >= 2);
- if (android.os.Build.VERSION.SDK_INT >= 14) {
+ ArticlePager ap = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
+
+ if (ap != null) {
+ Article article = ap.getSelectedArticle();
+
+ if (article != null) {
+ m_menu.findItem(R.id.toggle_marked).setIcon(article.marked ? R.drawable.ic_important_light :
+ R.drawable.ic_unimportant_light);
+
+ m_menu.findItem(R.id.toggle_published).setIcon(article.published ? R.drawable.ic_menu_published_light :
+ R.drawable.ic_menu_unpublished_light);
+
+ m_menu.findItem(R.id.set_unread).setIcon(article.unread ? R.drawable.ic_unread_light :
+ R.drawable.ic_read_light);
+ }
+ }
+
+ /* if (android.os.Build.VERSION.SDK_INT >= 14) {
ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider();
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
@@ -1394,7 +1491,7 @@ public class OnlineActivity extends CommonActivity {
m_menu.findItem(R.id.share_article).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
- }
+ } */
if (!isCompatMode()) {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
@@ -1570,4 +1667,13 @@ public class OnlineActivity extends CommonActivity {
public String getViewMode() {
return m_prefs.getString("view_mode", "adaptive");
}
+
+ public void setLastContentImageHitTestUrl(String url) {
+ m_lastImageHitTestUrl = url;
+ }
+
+ public String getLastContentImageHitTestUrl() {
+ return m_lastImageHitTestUrl;
+ }
+
}