add menus to toggle marked/published on active article
This commit is contained in:
parent
16fd6cebd7
commit
973138935d
BIN
res/drawable-hdpi/rss.png
Normal file
BIN
res/drawable-hdpi/rss.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
res/drawable-hdpi/rss_bw.png
Normal file
BIN
res/drawable-hdpi/rss_bw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
@ -42,7 +42,15 @@
|
||||
android:icon="@android:drawable/ic_menu_share"
|
||||
android:title="@string/share_article"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
|
||||
<item android:id="@+id/toggle_marked"
|
||||
android:title="@string/toggle_marked"
|
||||
android:showAsAction=""/>
|
||||
|
||||
<item android:id="@+id/toggle_published"
|
||||
android:title="@string/toggle_published"
|
||||
android:showAsAction=""/>
|
||||
|
||||
<item android:id="@+id/logout"
|
||||
android:title="@string/logout"
|
||||
android:showAsAction=""/>
|
||||
|
@ -45,4 +45,6 @@
|
||||
<string name="error_invalid_object">Error: invalid object received.</string>
|
||||
<string name="blank"></string>
|
||||
<string name="transport_debugging">Log sent and received data</string>
|
||||
<string name="toggle_marked">Toggle starred</string>
|
||||
<string name="toggle_published">Toggle published</string>
|
||||
</resources>
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
10
src/org/fox/ttrss/ArticleOps.java
Normal file
10
src/org/fox/ttrss/ArticleOps.java
Normal file
@ -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();
|
||||
}
|
||||
|
@ -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<Article>)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<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
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<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
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<Article> {
|
||||
private ArrayList<Article> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
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<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
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<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user