From 29cb4f17d80b22b6d222588a153949ec6e9125e6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 16 Oct 2013 12:38:18 +0400 Subject: [PATCH] experimentally implement actionbar-pulltorefresh for feeds and cats --- project.properties | 4 ++- src/org/fox/ttrss/FeedCategoriesFragment.java | 19 ++++++++++--- src/org/fox/ttrss/FeedsActivity.java | 6 +++++ src/org/fox/ttrss/FeedsFragment.java | 27 ++++++++++++++----- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/project.properties b/project.properties index fd20fc51..bb236c79 100644 --- a/project.properties +++ b/project.properties @@ -11,4 +11,6 @@ target=android-17 android.library.reference.1=..\\Android-ViewPagerIndicator\\library android.library.reference.2=..\\ActionBarSherlock\\actionbarsherlock -android.library.reference.3=../SlidingMenu/library +android.library.reference.3=..\\SlidingMenu\\library +android.library.reference.4=../ActionBar-PullToRefresh/library +android.library.reference.5=../ActionBar-PullToRefresh/extras/pulltorefresh-actionbarsherlock diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index addfc8e2..03dc4873 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -11,6 +11,8 @@ import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedCategoryList; +import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener; + import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -44,7 +46,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; -public class FeedCategoriesFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener { +public class FeedCategoriesFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener, OnRefreshListener { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; private FeedCategoryListAdapter m_adapter; @@ -207,6 +209,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe list.setOnItemClickListener(this); registerForContextMenu(list); + m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); + return view; } @@ -258,8 +262,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe final boolean unreadOnly = m_activity.getUnreadOnly(); if (sessionId != null) { - m_activity.setLoadingStatus(R.string.blank, true); - m_activity.setProgressBarVisibility(true); + //m_activity.setLoadingStatus(R.string.blank, true); + //m_activity.setProgressBarVisibility(true); @SuppressWarnings("serial") HashMap map = new HashMap() { @@ -332,6 +336,10 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe //m_adapter.notifyDataSetChanged(); (done by sortCats) m_activity.setLoadingStatus(R.string.blank, false); + if (isAdded()) { + m_activity.m_pullToRefreshAttacher.setRefreshComplete(); + } + return; } @@ -502,5 +510,10 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe public FeedCategory getSelectedCategory() { return m_selectedCat; + } + + @Override + public void onRefreshStarted(View view) { + refresh(false); } } diff --git a/src/org/fox/ttrss/FeedsActivity.java b/src/org/fox/ttrss/FeedsActivity.java index f1ddcd0e..0b4ca761 100644 --- a/src/org/fox/ttrss/FeedsActivity.java +++ b/src/org/fox/ttrss/FeedsActivity.java @@ -1,5 +1,6 @@ package org.fox.ttrss; + import java.util.Date; import org.fox.ttrss.types.Article; @@ -10,6 +11,7 @@ import org.fox.ttrss.util.AppRater; import com.actionbarsherlock.view.MenuItem; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; +import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshAttacher; import android.view.ViewGroup; import android.animation.LayoutTransition; @@ -39,6 +41,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe private SlidingMenu m_slidingMenu; private boolean m_feedIsSelected = false; + protected PullToRefreshAttacher m_pullToRefreshAttacher; + @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { @@ -55,6 +59,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe GlobalState.getInstance().load(savedInstanceState); + m_pullToRefreshAttacher = PullToRefreshAttacher.get(this); + if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) { m_slidingMenu = new SlidingMenu(this); diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 19aac645..31c03ed7 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -17,6 +17,8 @@ import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedList; +import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener; + import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -57,7 +59,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; -public class FeedsFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener { +public class FeedsFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener, OnRefreshListener { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; private FeedListAdapter m_adapter; @@ -244,6 +246,10 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh m_enableFeedIcons = m_prefs.getBoolean("download_feed_icons", false); + Log.d(TAG, "mpTRA=" + m_activity.m_pullToRefreshAttacher); + + m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); + return view; } @@ -260,6 +266,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh m_prefs.registerOnSharedPreferenceChangeListener(this); m_activity = (FeedsActivity)activity; + } @Override @@ -315,7 +322,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh @SuppressWarnings({ "unchecked", "serial" }) public void refresh(boolean background) { //FeedCategory cat = m_onlineServices.getActiveCategory(); - m_activity.setProgressBarVisibility(true); final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4; @@ -325,7 +331,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh FeedsRequest req = new FeedsRequest(getActivity().getApplicationContext(), catId); if (sessionId != null) { - m_activity.setLoadingStatus(R.string.blank, true); + //m_activity.setLoadingStatus(R.string.blank, true); + //m_activity.setProgressBarVisibility(true); HashMap map = new HashMap() { { @@ -459,10 +466,13 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh m_activity.setLoadingStatus(R.string.blank, false); //m_adapter.notifyDataSetChanged(); (done by sortFeeds) - if (m_enableFeedIcons && !m_feedIconsChecked && - Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) + if (m_enableFeedIcons && !m_feedIconsChecked && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) getFeedIcons(); - + + if (isAdded()) { + m_activity.m_pullToRefreshAttacher.setRefreshComplete(); + } + return; } @@ -730,4 +740,9 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh m_adapter.notifyDataSetChanged(); } + @Override + public void onRefreshStarted(View view) { + refresh(false); + } + }