support loading more headlines from main menu
This commit is contained in:
parent
10672b110f
commit
131dec0c1c
@ -20,7 +20,12 @@
|
||||
android:title="@string/close_article"
|
||||
android:showAsAction="ifRoom|withText"/>
|
||||
|
||||
|
||||
<item android:id="@+id/load_more_articles"
|
||||
android:visible="false"
|
||||
android:icon="@android:drawable/ic_menu_more"
|
||||
android:title="@string/load_more_articles"
|
||||
android:showAsAction="ifRoom|withText"/>
|
||||
|
||||
<item android:id="@+id/update_feeds"
|
||||
android:enabled="false"
|
||||
android:icon="@android:drawable/ic_menu_rotate"
|
||||
|
@ -33,4 +33,5 @@
|
||||
<string name="share_article">Share article</string>
|
||||
<string name="could_not_decode_content">Could not decode content (UnsupportedEncodingException)</string>
|
||||
<string name="sort_feeds_by_unread">Sort feeds by unread count</string>
|
||||
<string name="load_more_articles">More headlines...</string>
|
||||
</resources>
|
||||
|
@ -79,7 +79,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
||||
Log.d(TAG, "onCreateView, feed=" + m_feed);
|
||||
|
||||
if (m_feed != null && (m_articles == null || m_articles.size() == 0))
|
||||
refresh();
|
||||
refresh(false);
|
||||
else
|
||||
view.findViewById(R.id.loading_container).setVisibility(View.GONE);
|
||||
|
||||
@ -121,13 +121,26 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
public void refresh(boolean append) {
|
||||
HeadlinesRequest req = new HeadlinesRequest();
|
||||
|
||||
req.setApi(m_prefs.getString("ttrss_url", null));
|
||||
|
||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||
|
||||
int skip = 0;
|
||||
|
||||
if (append) {
|
||||
for (Article a : m_articles) {
|
||||
if (a.unread) ++skip;
|
||||
}
|
||||
|
||||
if (skip == 0) skip = m_articles.size();
|
||||
}
|
||||
|
||||
final int fskip = skip;
|
||||
|
||||
req.setOffset(skip);
|
||||
|
||||
HashMap<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
put("op", "getHeadlines");
|
||||
@ -137,6 +150,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
||||
put("limit", String.valueOf(30));
|
||||
put("offset", String.valueOf(0));
|
||||
put("view_mode", "adaptive");
|
||||
put("skip", String.valueOf(fskip));
|
||||
}
|
||||
};
|
||||
|
||||
@ -154,6 +168,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
||||
}
|
||||
|
||||
private class HeadlinesRequest extends ApiRequest {
|
||||
int m_offset = 0;
|
||||
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
if (result != null) {
|
||||
@ -172,12 +187,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
||||
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
m_articles.clear();
|
||||
|
||||
if (m_offset == 0)
|
||||
m_articles.clear();
|
||||
|
||||
for (Article f : articles)
|
||||
m_articles.add(f);
|
||||
|
||||
m_adapter.notifyDataSetInvalidated();
|
||||
m_adapter.notifyDataSetChanged();
|
||||
|
||||
showLoading(false);
|
||||
}
|
||||
@ -199,6 +216,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public void setOffset(int skip) {
|
||||
m_offset = skip;
|
||||
}
|
||||
}
|
||||
|
||||
public void catchupArticle(final Article article) {
|
||||
|
@ -225,6 +225,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
||||
case R.id.close_article:
|
||||
closeArticle();
|
||||
return true;
|
||||
case R.id.load_more_articles:
|
||||
viewFeed(m_activeFeed, true);
|
||||
return true;
|
||||
case R.id.share_article:
|
||||
shareArticle(m_selectedArticle);
|
||||
return true;
|
||||
@ -285,14 +288,17 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
||||
m_menu.findItem(R.id.update_feeds).setEnabled(true);
|
||||
m_menu.findItem(R.id.show_feeds).setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
m_menu.findItem(R.id.load_more_articles).setVisible(m_activeFeed != null);
|
||||
|
||||
} else {
|
||||
m_menu.findItem(R.id.login).setVisible(true);
|
||||
|
||||
m_menu.findItem(R.id.logout).setVisible(false);
|
||||
m_menu.findItem(R.id.close_article).setVisible(false);
|
||||
m_menu.findItem(R.id.share_article).setVisible(false);
|
||||
|
||||
m_menu.findItem(R.id.load_more_articles).setVisible(false);
|
||||
|
||||
m_menu.findItem(R.id.update_feeds).setEnabled(false);
|
||||
m_menu.findItem(R.id.show_feeds).setEnabled(false);
|
||||
}
|
||||
@ -377,21 +383,30 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
||||
@Override
|
||||
public void onFeedSelected(Feed feed) {
|
||||
Log.d(TAG, "Selected feed: " + feed.toString());
|
||||
viewFeed(feed);
|
||||
viewFeed(feed, false);
|
||||
}
|
||||
|
||||
public Article getSelectedArticle() {
|
||||
return m_selectedArticle;
|
||||
}
|
||||
|
||||
public void viewFeed(Feed feed) {
|
||||
public void viewFeed(Feed feed, boolean append) {
|
||||
m_activeFeed = feed;
|
||||
|
||||
initMainMenu();
|
||||
|
||||
HeadlinesFragment hf = new HeadlinesFragment();
|
||||
if (!append) {
|
||||
HeadlinesFragment hf = new HeadlinesFragment();
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.headlines_fragment, hf);
|
||||
ft.commit();
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.headlines_fragment, hf);
|
||||
ft.commit();
|
||||
} else {
|
||||
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||
if (hf != null) {
|
||||
hf.refresh(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void openArticle(Article article) {
|
||||
|
Loading…
Reference in New Issue
Block a user