diff --git a/res/drawable-hdpi/ic_next_article.png b/res/drawable-hdpi/ic_next_article.png new file mode 100644 index 00000000..ef7e7be3 Binary files /dev/null and b/res/drawable-hdpi/ic_next_article.png differ diff --git a/res/drawable-hdpi/ic_next_article_disabled.png b/res/drawable-hdpi/ic_next_article_disabled.png new file mode 100644 index 00000000..7aeac8a4 Binary files /dev/null and b/res/drawable-hdpi/ic_next_article_disabled.png differ diff --git a/res/drawable-hdpi/ic_prev_article.png b/res/drawable-hdpi/ic_prev_article.png new file mode 100644 index 00000000..0d5744de Binary files /dev/null and b/res/drawable-hdpi/ic_prev_article.png differ diff --git a/res/drawable-hdpi/ic_prev_article_disabled.png b/res/drawable-hdpi/ic_prev_article_disabled.png new file mode 100644 index 00000000..848cf464 Binary files /dev/null and b/res/drawable-hdpi/ic_prev_article_disabled.png differ diff --git a/res/drawable/s_prev_article.svg b/res/drawable/s_prev_article.svg new file mode 100644 index 00000000..5c83a6b5 --- /dev/null +++ b/res/drawable/s_prev_article.svg @@ -0,0 +1,70 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/res/layout/article_fragment.xml b/res/layout/article_fragment.xml index 29334931..2a45daf3 100644 --- a/res/layout/article_fragment.xml +++ b/res/layout/article_fragment.xml @@ -1,38 +1,141 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 4a84aef2..b4075d7e 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -3,6 +3,9 @@ package org.fox.ttrss; import java.text.SimpleDateFormat; import java.util.Date; +import org.fox.ttrss.ArticleOps.RelativeArticle; +import org.jsoup.helper.StringUtil; + import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; @@ -10,22 +13,27 @@ import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.View.OnClickListener; import android.webkit.WebView; +import android.widget.ImageView; import android.widget.TextView; import com.google.ads.AdRequest; import com.google.ads.AdView; -public class ArticleFragment extends Fragment { +public class ArticleFragment extends Fragment implements OnClickListener { @SuppressWarnings("unused") private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; private Article m_article; private ArticleOps m_articleOps; + private Article m_nextArticle; + private Article m_prevArticle; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -35,6 +43,26 @@ public class ArticleFragment extends Fragment { } View view = inflater.inflate(R.layout.article_fragment, container, false); + + // TODO change to interface? + MainActivity activity = (MainActivity)getActivity(); + + if (activity != null) { + int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation(); + + if (!activity.isSmallScreen()) { + if (orientation % 2 == 0) { + view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); + } else { + view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE); + } + } else { + view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE); + view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); + } + } else { + view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); + } if (m_article != null) { @@ -56,6 +84,7 @@ public class ArticleFragment extends Fragment { String cssOverride = ""; if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { + web.setBackgroundColor(android.R.color.black); cssOverride = "body { background : black; color : #f0f0f0}\n"; } @@ -87,11 +116,21 @@ public class ArticleFragment extends Fragment { dv.setText(df.format(d)); } - TextView cv = (TextView)view.findViewById(R.id.comments); - - // comments are not currently returned by the API - if (cv != null) { - cv.setVisibility(View.GONE); + TextView tagv = (TextView)view.findViewById(R.id.tags); + + if (tagv != null) { + if (m_article.tags != null) { + String tagsStr = ""; + + for (String tag : m_article.tags) + tagsStr += tag + ", "; + + tagsStr = tagsStr.replaceAll(", $", ""); + + tagv.setText(tagsStr); + } else { + tagv.setVisibility(View.GONE); + } } AdView av = (AdView)view.findViewById(R.id.ad); @@ -106,6 +145,27 @@ public class ArticleFragment extends Fragment { av.setVisibility(View.GONE); } } + + ImageView next = (ImageView)view.findViewById(R.id.next_article); + + if (next != null) { + if (m_nextArticle != null) { + next.setOnClickListener(this); + } else { + next.setImageResource(R.drawable.ic_next_article_disabled); + } + } + + ImageView prev = (ImageView)view.findViewById(R.id.prev_article); + + if (prev != null) { + if (m_prevArticle != null) { + prev.setOnClickListener(this); + } else { + prev.setImageResource(R.drawable.ic_prev_article_disabled); + } + } + } return view; @@ -130,6 +190,17 @@ public class ArticleFragment extends Fragment { m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); m_articleOps = (ArticleOps)activity; m_article = m_articleOps.getSelectedArticle(); + + m_prevArticle = m_articleOps.getRelativeArticle(m_article, RelativeArticle.BEFORE); + m_nextArticle = m_articleOps.getRelativeArticle(m_article, RelativeArticle.AFTER); + } + @Override + public void onClick(View v) { + if (v.getId() == R.id.next_article) { + m_articleOps.openArticle(m_nextArticle, 0); + } else if (v.getId() == R.id.prev_article) { + m_articleOps.openArticle(m_prevArticle, R.anim.slide_right); + } } } diff --git a/src/org/fox/ttrss/ArticleOps.java b/src/org/fox/ttrss/ArticleOps.java index 16fa8e7e..070fbd29 100644 --- a/src/org/fox/ttrss/ArticleOps.java +++ b/src/org/fox/ttrss/ArticleOps.java @@ -1,11 +1,14 @@ package org.fox.ttrss; public interface ArticleOps { + public enum RelativeArticle { BEFORE, AFTER }; + public Article getSelectedArticle(); public void saveArticleUnread(final Article article); public void saveArticleMarked(final Article article); public void saveArticlePublished(final Article article); - public void onArticleOpened(Article article); public void updateHeadlines(); + public void openArticle(Article article, int compatAnimation); + public Article getRelativeArticle(Article article, RelativeArticle ra); } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index ba53b3a4..8e0d9756 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -93,13 +93,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { if (list != null) { Article article = (Article)list.getItemAtPosition(position); - m_articleOps.onArticleOpened(article); + m_articleOps.openArticle(article, 0); - if (article.unread) { - article.unread = false; - m_articleOps.saveArticleUnread(article); - } - m_activeArticleId = article.id; m_adapter.notifyDataSetChanged(); } @@ -380,4 +375,20 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { m_adapter.notifyDataSetChanged(); } + public ArticleList getAllArticles() { + return m_articles; + } + + public void setActiveArticleId(int id) { + m_activeArticleId = id; + m_adapter.notifyDataSetChanged(); + + ListView list = (ListView)getView().findViewById(R.id.headlines); + + if (list != null) { + int position = m_adapter.getPosition(m_articleOps.getSelectedArticle()); + list.setSelection(position); + } + } + } diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 08971d59..10beb477 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -148,6 +148,10 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe /** Called when the activity is first created. */ + public boolean isSmallScreen() { + return m_smallScreenMode; + } + @Override public void onCreate(Bundle savedInstanceState) { m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); @@ -627,10 +631,21 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe } } - public void openArticle(Article article) { + public void openArticle(Article article, int compatAnimation) { m_selectedArticle = article; + if (article.unread) { + article.unread = false; + saveArticleUnread(article); + } + initMainMenu(); + + HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + if (hf != null) { + hf.setActiveArticleId(article.id); + } ArticleFragment frag = new ArticleFragment(); @@ -639,7 +654,10 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe ft.commit(); if (m_compatMode) { - findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left)); + if (compatAnimation == 0) + findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left)); + else + findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, compatAnimation)); } if (m_smallScreenMode) { @@ -652,11 +670,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe } - @Override - public void onArticleOpened(Article article) { - openArticle(article); - } - public Feed getActiveFeed() { return m_activeFeed; } @@ -714,4 +727,32 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe setLoadingStatus(R.string.login_in_progress, true); } } + + @Override + public Article getRelativeArticle(Article article, RelativeArticle ra) { + HeadlinesFragment frag = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + if (frag != null) { + ArticleList articles = frag.getAllArticles(); + for (int i = 0; i < articles.size(); i++) { + Article a = articles.get(i); + + if (a.id == article.id) { + if (ra == RelativeArticle.AFTER) { + try { + return articles.get(i+1); + } catch (IndexOutOfBoundsException e) { + return null; + } + } else { + try { + return articles.get(i-1); + } catch (IndexOutOfBoundsException e) { + return null; + } + } + } + } + } + return null; + } } \ No newline at end of file