experimentally implement actionbar-pulltorefresh for feeds and cats

This commit is contained in:
Andrew Dolgov 2013-10-16 12:38:18 +04:00
parent 7484ec13e7
commit 29cb4f17d8
4 changed files with 46 additions and 10 deletions

View File

@ -11,4 +11,6 @@
target=android-17 target=android-17
android.library.reference.1=..\\Android-ViewPagerIndicator\\library android.library.reference.1=..\\Android-ViewPagerIndicator\\library
android.library.reference.2=..\\ActionBarSherlock\\actionbarsherlock 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

View File

@ -11,6 +11,8 @@ import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedCategory;
import org.fox.ttrss.types.FeedCategoryList; import org.fox.ttrss.types.FeedCategoryList;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -44,7 +46,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken; 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 final String TAG = this.getClass().getSimpleName();
private SharedPreferences m_prefs; private SharedPreferences m_prefs;
private FeedCategoryListAdapter m_adapter; private FeedCategoryListAdapter m_adapter;
@ -207,6 +209,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
list.setOnItemClickListener(this); list.setOnItemClickListener(this);
registerForContextMenu(list); registerForContextMenu(list);
m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this);
return view; return view;
} }
@ -258,8 +262,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
final boolean unreadOnly = m_activity.getUnreadOnly(); final boolean unreadOnly = m_activity.getUnreadOnly();
if (sessionId != null) { if (sessionId != null) {
m_activity.setLoadingStatus(R.string.blank, true); //m_activity.setLoadingStatus(R.string.blank, true);
m_activity.setProgressBarVisibility(true); //m_activity.setProgressBarVisibility(true);
@SuppressWarnings("serial") @SuppressWarnings("serial")
HashMap<String,String> map = new HashMap<String,String>() { HashMap<String,String> map = new HashMap<String,String>() {
@ -332,6 +336,10 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
//m_adapter.notifyDataSetChanged(); (done by sortCats) //m_adapter.notifyDataSetChanged(); (done by sortCats)
m_activity.setLoadingStatus(R.string.blank, false); m_activity.setLoadingStatus(R.string.blank, false);
if (isAdded()) {
m_activity.m_pullToRefreshAttacher.setRefreshComplete();
}
return; return;
} }
@ -502,5 +510,10 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
public FeedCategory getSelectedCategory() { public FeedCategory getSelectedCategory() {
return m_selectedCat; return m_selectedCat;
}
@Override
public void onRefreshStarted(View view) {
refresh(false);
} }
} }

View File

@ -1,5 +1,6 @@
package org.fox.ttrss; package org.fox.ttrss;
import java.util.Date; import java.util.Date;
import org.fox.ttrss.types.Article; import org.fox.ttrss.types.Article;
@ -10,6 +11,7 @@ import org.fox.ttrss.util.AppRater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshAttacher;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
@ -39,6 +41,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
private SlidingMenu m_slidingMenu; private SlidingMenu m_slidingMenu;
private boolean m_feedIsSelected = false; private boolean m_feedIsSelected = false;
protected PullToRefreshAttacher m_pullToRefreshAttacher;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -55,6 +59,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
GlobalState.getInstance().load(savedInstanceState); GlobalState.getInstance().load(savedInstanceState);
m_pullToRefreshAttacher = PullToRefreshAttacher.get(this);
if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) { if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) {
m_slidingMenu = new SlidingMenu(this); m_slidingMenu = new SlidingMenu(this);

View File

@ -17,6 +17,8 @@ import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedCategory;
import org.fox.ttrss.types.FeedList; import org.fox.ttrss.types.FeedList;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -57,7 +59,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken; 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 final String TAG = this.getClass().getSimpleName();
private SharedPreferences m_prefs; private SharedPreferences m_prefs;
private FeedListAdapter m_adapter; 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); 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; return view;
} }
@ -260,6 +266,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
m_prefs.registerOnSharedPreferenceChangeListener(this); m_prefs.registerOnSharedPreferenceChangeListener(this);
m_activity = (FeedsActivity)activity; m_activity = (FeedsActivity)activity;
} }
@Override @Override
@ -315,7 +322,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
@SuppressWarnings({ "unchecked", "serial" }) @SuppressWarnings({ "unchecked", "serial" })
public void refresh(boolean background) { public void refresh(boolean background) {
//FeedCategory cat = m_onlineServices.getActiveCategory(); //FeedCategory cat = m_onlineServices.getActiveCategory();
m_activity.setProgressBarVisibility(true);
final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4; 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); FeedsRequest req = new FeedsRequest(getActivity().getApplicationContext(), catId);
if (sessionId != null) { if (sessionId != null) {
m_activity.setLoadingStatus(R.string.blank, true); //m_activity.setLoadingStatus(R.string.blank, true);
//m_activity.setProgressBarVisibility(true);
HashMap<String,String> map = new HashMap<String,String>() { HashMap<String,String> map = new HashMap<String,String>() {
{ {
@ -459,10 +466,13 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
m_activity.setLoadingStatus(R.string.blank, false); m_activity.setLoadingStatus(R.string.blank, false);
//m_adapter.notifyDataSetChanged(); (done by sortFeeds) //m_adapter.notifyDataSetChanged(); (done by sortFeeds)
if (m_enableFeedIcons && !m_feedIconsChecked && if (m_enableFeedIcons && !m_feedIconsChecked && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
getFeedIcons(); getFeedIcons();
if (isAdded()) {
m_activity.m_pullToRefreshAttacher.setRefreshComplete();
}
return; return;
} }
@ -730,4 +740,9 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
} }
@Override
public void onRefreshStarted(View view) {
refresh(false);
}
} }