From ebb1253ddd886f6330ff85332763bb652c5101b9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 28 Nov 2011 12:45:19 +0300 Subject: [PATCH] implement moving between articles --- res/drawable-hdpi/ic_next_article.png | Bin 0 -> 473 bytes .../ic_next_article_disabled.png | Bin 0 -> 482 bytes res/drawable-hdpi/ic_prev_article.png | Bin 0 -> 466 bytes .../ic_prev_article_disabled.png | Bin 0 -> 486 bytes res/drawable/s_prev_article.svg | 70 +++++++ res/layout/article_fragment.xml | 179 ++++++++++++++---- src/org/fox/ttrss/ArticleFragment.java | 83 +++++++- src/org/fox/ttrss/ArticleOps.java | 5 +- src/org/fox/ttrss/HeadlinesFragment.java | 23 ++- src/org/fox/ttrss/MainActivity.java | 55 +++++- 10 files changed, 357 insertions(+), 58 deletions(-) create mode 100644 res/drawable-hdpi/ic_next_article.png create mode 100644 res/drawable-hdpi/ic_next_article_disabled.png create mode 100644 res/drawable-hdpi/ic_prev_article.png create mode 100644 res/drawable-hdpi/ic_prev_article_disabled.png create mode 100644 res/drawable/s_prev_article.svg diff --git a/res/drawable-hdpi/ic_next_article.png b/res/drawable-hdpi/ic_next_article.png new file mode 100644 index 0000000000000000000000000000000000000000..ef7e7be3e9a6a10fb3e198c9ac4727bb127cb8ab GIT binary patch literal 473 zcmV;~0Ve*5P)k?<>$0~oNq{|gb?@-*-9C5&OM9B$+!z4tgN+{ zS|BE6sA-xz;1}45kBD42=MFat(zfkdM6Rd3h&(M8i`|WZ0CZjV2E0$|17pm?MnM3K zF;~F%q(0YBGz+ArqFEqNPtj};sG}$gq=up_5YShY4FbA~ia^@7U55~ErhSg0A`k#; z?JEk3ia|g}kqU^0A{7uQSEL3~8Z{8-+!=5@slUAUw<+(7##OQJ`+e{IC$Kl}LkLIK z+K-fPsBFZ0|2TyJUQ!`cKuVRw6sgfr5>vDh4JE}O%jNPE1tl?AYBZI^WNk!KNj8YK zl9*X)YAA`BwUHW1W`opH5|gB+rjnSX-x9+x+>6LI@H2u~X+eO}>8p`HbvxTN@$8er P00000NkvXXu0mjf*g3!$ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..7aeac8a4a32692b150378160f088b661c3b29e2d GIT binary patch literal 482 zcmV<80UiE{P)6tGZmMgXfR|LA-+tkpa&VXb9v0frN&f zMHs||mk@-(bI7Qh?sAh3VHmJ~s>6JcO?6fA=(h=t%nYZHvyi5)>zv_#Nx2x;= zSqemjG!fC8bIvjIx&ILHuJ8NnMM1RIdu#2>k)zEp3>S-m001;i^MQ!FgYuQN_F+*F z002bXGV}Mm=A65gP!t7HQc)BLKsiOxAOK|)C4rPslmr4GuP7M=Kvq!}h}L>fL?Vi^ zKt>o5McE(#GKxe%Bov8&j4)Y>#6WT*24al4VdnKg`HP5N7XvZItgN+Mn0FU-6_#LIb2DfOLbPowq9hB%7_%ZG5hXrJ zY9y6R^RWZcN|HcIDDjC>Q$oqKC$zDYk|>apN_>LUSZnWLAdbu2#ix@R)JMwCfoQdwav0k|rBeFc~k|B*dMYv*p5}at+5z6%B80 zNL1*sl$EE+|5G^2U-t9F_WuE)5A9Qq7aIvyIvsg@)-Uw_%%4fw3QC)tj(lDrH+$Jm zUrB#Cf!h1;6(1$vQGOJ9d)xhJX2nI-3>F=)`q#a_H|hBXr;Za`4CfYAsVq7@r_x73 z&MU^jX37l5JyT{l*h~dsk>(0*O{SF#mvAg;o0Kyl%4?Iuv?(iIZ4LDlJ26Qpt?p}s z2ir}zNe)gN<_sT1uevK0y<%-z>3?*8`}y>cewUIL8~r9-HTW#W5VxqxzU4zg>j@^t zh%ghL!=0ikk!R;bb!{s5)pd2fy}fNwj%o28QBnDfdtE;2tCufI0&+!WzL(N>)tf%A zU1{?y%P`lx^9*Tmt6v#2{K=`=ec9yh(w_3)%Gdrdh0i!}jyYk~Ghp~Lc)I$ztaD0e F0stzLypaF^ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..848cf4642df4e5644c792451a6ee96bc7cdda5b0 GIT binary patch literal 486 zcmeAS@N?(olHy`uVBq!ia0vp^N+8U^1|+TAxeoy;mSQK*5Dp-y;YjHK@;M7UB8wRq z_~w8xBm0!#yFfw764!{5;QX|b^2DN4hVt@qz0ADq;^f4FRK5J7^x5xhq!<_&lRaG= zLn2zw&hYkPF%)Q9t(6yIbKF3oqr5;-sbX5&gf=?|=k^10TqhiCEf;W z{I1AQfPo?T%)Ab}Wu`8B5}qygjS*!@hzq>`{b(1^5E0F#U81VdWVK1==K% z8lQ2gt1B + + + + + + + + + + + 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