From 973138935dbebbfe190b283196541b443840a8d1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 27 Nov 2011 15:22:03 +0300 Subject: [PATCH] add menus to toggle marked/published on active article --- res/drawable-hdpi/rss.png | Bin 0 -> 3015 bytes res/drawable-hdpi/rss_bw.png | Bin 0 -> 2506 bytes res/menu/main_menu.xml | 10 ++- res/values/strings.xml | 2 + src/org/fox/ttrss/ArticleFragment.java | 5 +- src/org/fox/ttrss/ArticleOps.java | 10 +++ src/org/fox/ttrss/HeadlinesFragment.java | 51 ++++----------- src/org/fox/ttrss/MainActivity.java | 75 ++++++++++++++++++++++- 8 files changed, 110 insertions(+), 43 deletions(-) create mode 100644 res/drawable-hdpi/rss.png create mode 100644 res/drawable-hdpi/rss_bw.png create mode 100644 src/org/fox/ttrss/ArticleOps.java diff --git a/res/drawable-hdpi/rss.png b/res/drawable-hdpi/rss.png new file mode 100644 index 0000000000000000000000000000000000000000..240e45e3cb6f4acb88781b423db7d0a26255453b GIT binary patch literal 3015 zcmV;&3pn(NP)}XT2LA-f5%;gWDk5EE#fwvZs!P9>;} zRIuL0skT!UEB2z!IPjr$rf8w+C|_Ec!4DnBG187=r&XpUai+HA;&ik^06PUC5zEFv z0&LR2F5&F%Ip^(%y=1dFmrV#L^qI+=%kFv4`Th5OpXdL+nIrIs{i~+e8K(J!fCa!( zukU|BVyA=yQsuS9EvFB-eNi}l@ZqW{3lx)I1516uAmOSAp-2Q@Fn})@9QP+4k4Wn} zX+24zua9`FkF>4>?6g$YI0<1Zz@7)Dt`}1NA{Z*Cs}X@n5@ z7K8wV$ZoTZ+MXLa&K!!N>kHe$?tIbxvh5XYK&VI&Kngz+l|-zMSTu^BIENHs!?jyZ zt#=h*|Eh@-O;dXn#GO@jwN%y4#!9ErPxX^J6GtdR50eMWK`2E)!@e_g?DkpVaiNgI z+Xa#PutfEcSoIVZx zR6qLZzD(nn5q#$3^C&{cBt%v1Y=Y(G^c?B9(=@~Y@KBCf&F$=YVCs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*2pAT!Ie^Y-cEhrRFb2Je&uayw2Y$2$0XZ}M!U_iuHC&zT%+ zz&#JB6Kg!@^G>0Zg*@S5L=JFwcqDqT4ta}U9BRe*tlbq}T40`W@5(txQw*Q#cFzF- z{+aXb;q7`rTGv6SCD~i+pPR7uzv6h~^ntDDfBB^+yxp%+9O@*SAt1pzch*w?=>RV! zs6j3FHc7?`r}ZR(Kmg?VlDxgq{t6s!L#e$1QQZgMh8=S7gn zAwjZRYcTFOvC%vCGGZ*qp^Y^dw}l6Zzp|XPp3JcAy?@G%$unmxojSJ;pFCO8#AZDH zMP2Fwrq{&AGuzvotNvyKv1pY3?&CWZ2?ye_K0rZ=vMU~b!t_cMO(h=dL&54$R6!`>TI)$|(EfSw~AtJ2A2=EX^^3}KuFYw)sypD?|Win`pG z&%HQFi>jvA6f)aR^6XxnMOt9!NF#|f(?d73iXK!JJ!qj2`3H6QZuWdG|4?uZGP{yv z2cJE!1~vSZzAhs<8pp|UQ^Xg*)s1K{{xVo#8fvPPU`>w002ov JPDHLkV1m)$@_zsT literal 0 HcmV?d00001 diff --git a/res/drawable-hdpi/rss_bw.png b/res/drawable-hdpi/rss_bw.png new file mode 100644 index 0000000000000000000000000000000000000000..1e698ec0894dbba3d0744da7952a9df51481e244 GIT binary patch literal 2506 zcmV;*2{rbKP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5&!@T5&_cPe*6Fc02y>eSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+lb?0x$oCxE<8$wcc9XSaQEofmH{+Ra#`c&o z%9t==!rx=Zj_nwleM8fXkjb-lj2}P#9}Qpdbv`Vhr%ah*7A{<9y1Kf|wr$(Y-o1PO zlapuT8F^Noxn``s(nO3KH?EZrx3;#LwQJW}use6|G#fW=G^X3ZKq`5bfIx^-s#`t^45a2qyk$R^*nY11aNdGqFMZrQTMFt={qYRQ(l zefxI9+_7VaeHM4_+O^9tckkY9_Uze{8He8o16aVMdc%;r|26dHZa%Ph@!||P0O!x2 z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Q2`) zz!SF@@IeB2SUHLs+NCYCIm%j$b#HO=*dSnr3L9G9*oHro5Zb3%+DS?~a{R&0y< z{rmSC`Pu7|(?jx>W`;IG+MaVrv4H{&fuA;QTATnmgzW3#l_B8Mr%%!DE!|*kV5NLB zg9uLXqzwpg-5$#Wo=KMQdO!?3!RN`7C))33uhTEkTG!f_QC<49JzlDf5csK6r`i-* zAV4B^tb3cpH~?o<4o5f+x>wK~)II zYkRyx8}v4O;5i^!@BnhOdn!XanStU94fMKZc@a69G$v4n3LA|8iYHm~VtK%~w6xe- z0L)oOh&QvwQwtm3$3`XPCu^NapOCIhDtJT=JHC*>l<(nB(i~HCy-(W{>GPA5B{J## zLqHxp1js27A;2D$73o^_fuu(I_9-Q8EYF855BSNGCtHQ;9+k}wOG83RRaeCpbxQYE ztLkE@&S!bRi?OrA(zR=G*`a~qIFnPhZ?Dz!F_9B;d%#bcG|8&ny5sWP8E`L52mw`| z$$@|}ef#0CJm6(Rr0&9mduc-Y<*2ZdP%>!O~0NyJzkRX?)Wbb^m zfhX_ - + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 9ffb5baf..d106c5f6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -45,4 +45,6 @@ Error: invalid object received. Log sent and received data + Toggle starred + Toggle published diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 60ac6090..205cfa5d 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -23,6 +23,7 @@ public class ArticleFragment extends Fragment { private SharedPreferences m_prefs; private Article m_article; + private ArticleOps m_articleOps; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -112,6 +113,8 @@ public class ArticleFragment extends Fragment { super.onAttach(activity); m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); - m_article = ((MainActivity)activity).getSelectedArticle(); + m_articleOps = (ArticleOps)activity; + m_article = m_articleOps.getSelectedArticle(); + } } diff --git a/src/org/fox/ttrss/ArticleOps.java b/src/org/fox/ttrss/ArticleOps.java new file mode 100644 index 00000000..32d76050 --- /dev/null +++ b/src/org/fox/ttrss/ArticleOps.java @@ -0,0 +1,10 @@ +package org.fox.ttrss; + +public interface ArticleOps { + public Article getSelectedArticle(); + public void saveArticleUnread(final Article article); + public void saveArticleMarked(final Article article); + public void saveArticlePublished(final Article article); + public void updateHeadlines(); +} + diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 0165a05c..1e7e9ef4 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -53,6 +53,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { private ArticleList m_selectedArticles = new ArticleList(); private OnArticleSelectedListener m_articleSelectedListener; + private ArticleOps m_articleOps; public interface OnArticleSelectedListener { public void onArticleSelected(Article article); @@ -76,7 +77,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { m_adapter = new ArticleListAdapter(getActivity(), R.layout.headlines_row, (ArrayList
)m_articles); list.setAdapter(m_adapter); list.setOnItemClickListener(this); - + Log.d(TAG, "onCreateView, feed=" + m_feed); if (m_feed != null && (m_articles == null || m_articles.size() == 0)) @@ -104,6 +105,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); m_feed = ((MainActivity)activity).getActiveFeed(); m_articleSelectedListener = (OnArticleSelectedListener) activity; + m_articleOps = (ArticleOps) activity; } @Override @@ -118,7 +120,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { m_selectedArticleId = article.id; m_adapter.notifyDataSetChanged(); - catchupArticle(article); + m_articleOps.saveArticleUnread(article); } } @@ -253,43 +255,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { } } - public void catchupArticle(final Article article) { - ApiRequest req = new ApiRequest(getActivity().getApplicationContext()); - //req.setApi(m_prefs.getString("ttrss_url", null)); - //req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false)); - - final String sessionId = ((MainActivity)getActivity()).getSessionId(); - - HashMap map = new HashMap() { - { - put("sid", sessionId); - put("op", "updateArticle"); - put("article_ids", String.valueOf(article.id)); - put("mode", "0"); - put("field", "2"); - } - }; - - req.execute(map); - } - - public void setArticleMarked(final Article article) { - ApiRequest req = new ApiRequest(getActivity().getApplicationContext()); - - final String sessionId = ((MainActivity)getActivity()).getSessionId(); - - HashMap map = new HashMap() { - { - put("sid", sessionId); - put("op", "updateArticle"); - put("article_ids", String.valueOf(article.id)); - put("mode", article.marked ? "1" : "0"); - put("field", "0"); - } - }; - - req.execute(map); - } private class ArticleListAdapter extends ArrayAdapter
{ private ArrayList
items; @@ -362,7 +327,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { article.marked = !article.marked; m_adapter.notifyDataSetChanged(); - setArticleMarked(article); + m_articleOps.saveArticleMarked(article); } }); } @@ -413,4 +378,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { } } + + + public void notifyUpdated() { + m_adapter.notifyDataSetChanged(); + } + } diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index b00ce875..99509cde 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -26,7 +26,7 @@ import android.widget.TextView; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -public class MainActivity extends FragmentActivity implements FeedsFragment.OnFeedSelectedListener, HeadlinesFragment.OnArticleSelectedListener { +public class MainActivity extends FragmentActivity implements FeedsFragment.OnFeedSelectedListener, HeadlinesFragment.OnArticleSelectedListener, ArticleOps { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; @@ -43,6 +43,61 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe private boolean m_canLoadMore = true; private boolean m_compatMode = false; + public void updateHeadlines() { + HeadlinesFragment frag = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + if (frag != null) { + frag.notifyUpdated(); + } + } + + public void saveArticleUnread(final Article article) { + ApiRequest req = new ApiRequest(getApplicationContext()); + + HashMap map = new HashMap() { + { + put("sid", m_sessionId); + put("op", "updateArticle"); + put("article_ids", String.valueOf(article.id)); + put("mode", "0"); + put("field", "2"); + } + }; + + req.execute(map); + } + + public void saveArticleMarked(final Article article) { + ApiRequest req = new ApiRequest(getApplicationContext()); + + HashMap map = new HashMap() { + { + put("sid", m_sessionId); + put("op", "updateArticle"); + put("article_ids", String.valueOf(article.id)); + put("mode", article.marked ? "1" : "0"); + put("field", "0"); + } + }; + + req.execute(map); + } + + public void saveArticlePublished(final Article article) { + ApiRequest req = new ApiRequest(getApplicationContext()); + + HashMap map = new HashMap() { + { + put("sid", m_sessionId); + put("op", "updateArticle"); + put("article_ids", String.valueOf(article.id)); + put("mode", article.published ? "1" : "0"); + put("field", "1"); + } + }; + + req.execute(map); + } + private class RefreshTask extends TimerTask { @Override @@ -318,6 +373,20 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe case R.id.share_article: shareArticle(m_selectedArticle); return true; + case R.id.toggle_marked: + if (m_selectedArticle != null) { + m_selectedArticle.marked = !m_selectedArticle.marked; + saveArticleMarked(m_selectedArticle); + updateHeadlines(); + } + return true; + case R.id.toggle_published: + if (m_selectedArticle != null) { + m_selectedArticle.published = !m_selectedArticle.published; + saveArticlePublished(m_selectedArticle); + updateHeadlines(); + } + return true; case R.id.show_feeds: setUnreadOnly(!getUnreadOnly()); @@ -389,12 +458,16 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe if (m_selectedArticle != null) { m_menu.findItem(R.id.close_article).setVisible(true); m_menu.findItem(R.id.share_article).setVisible(true); + m_menu.findItem(R.id.toggle_marked).setVisible(true); + m_menu.findItem(R.id.toggle_published).setVisible(true); m_menu.findItem(R.id.update_feeds).setVisible(false); m_menu.findItem(R.id.show_feeds).setVisible(false); } else { m_menu.findItem(R.id.close_article).setVisible(false); m_menu.findItem(R.id.share_article).setVisible(false); + m_menu.findItem(R.id.toggle_marked).setVisible(false); + m_menu.findItem(R.id.toggle_published).setVisible(false); if (!m_smallScreenMode || m_activeFeed == null) { m_menu.findItem(R.id.show_feeds).setVisible(true);