From ddb85d210aede04602540ee6109c57984310afe3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 15 Oct 2014 16:41:33 +0400 Subject: [PATCH] remove pulltorefresh library, switch to swiperefreshlayout --- project.properties | 1 - res/layout/cats_fragment.xml | 18 ++++++--- res/layout/feeds_fragment.xml | 18 ++++++--- res/layout/headlines_fragment.xml | 24 +++++++----- src/org/fox/ttrss/ArticlePager.java | 4 +- src/org/fox/ttrss/CommonActivity.java | 2 + src/org/fox/ttrss/FeedCategoriesFragment.java | 33 ++++++++++++---- src/org/fox/ttrss/FeedsActivity.java | 8 ++-- src/org/fox/ttrss/FeedsFragment.java | 38 ++++++++++++++----- src/org/fox/ttrss/HeadlinesFragment.java | 34 +++++++++++++---- src/org/fox/ttrss/OnlineActivity.java | 8 ++-- 11 files changed, 130 insertions(+), 58 deletions(-) diff --git a/project.properties b/project.properties index 94614f9e..b27e5796 100644 --- a/project.properties +++ b/project.properties @@ -13,4 +13,3 @@ android.library.reference.1=..\\Android-ViewPagerIndicator\\library android.library.reference.2=..\\tasker-locale-api android.library.reference.3=..\\appcompat android.library.reference.4=..\\SlidingMenu\\library -android.library.reference.5=../pulltorefresh-actionbarcompat diff --git a/res/layout/cats_fragment.xml b/res/layout/cats_fragment.xml index a883bf9f..cc295e1c 100644 --- a/res/layout/cats_fragment.xml +++ b/res/layout/cats_fragment.xml @@ -18,13 +18,19 @@ - - + + + + + - - + + + + + - - + + + + + { @@ -212,13 +212,30 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe View view = inflater.inflate(R.layout.cats_fragment, container, false); + m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.feeds_swipe_container); + + m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refresh(false); + } + }); + + if (!m_activity.isCompatMode()) { + m_swipeLayout.setColorScheme(android.R.color.holo_green_dark, + android.R.color.holo_red_dark, + android.R.color.holo_blue_dark, + android.R.color.holo_orange_dark); + } + + ListView list = (ListView)view.findViewById(R.id.feeds); m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, (ArrayList)m_cats); list.setAdapter(m_adapter); list.setOnItemClickListener(this); registerForContextMenu(list); - m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); + //m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); return view; } @@ -265,6 +282,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe } */ public void refresh(boolean background) { + m_swipeLayout.setRefreshing(true); + CatsRequest req = new CatsRequest(getActivity().getApplicationContext()); final String sessionId = m_activity.getSessionId(); @@ -306,7 +325,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe if (isDetached()) return; m_activity.setProgressBarVisibility(false); - m_activity.m_pullToRefreshAttacher.setRefreshComplete(); + m_swipeLayout.setRefreshing(false); if (getView() != null) { ListView list = (ListView)getView().findViewById(R.id.feeds); @@ -521,8 +540,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe return m_selectedCat; } - @Override + /* @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 fd283369..68f7fc45 100644 --- a/src/org/fox/ttrss/FeedsActivity.java +++ b/src/org/fox/ttrss/FeedsActivity.java @@ -137,7 +137,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe lr.execute(map); } - m_pullToRefreshAttacher.setRefreshing(true); + //m_pullToRefreshAttacher.setRefreshing(true); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); @@ -226,7 +226,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe public void onFeedSelected(Feed feed) { GlobalState.getInstance().m_loadedArticles.clear(); - m_pullToRefreshAttacher.setRefreshing(true); + //m_pullToRefreshAttacher.setRefreshing(true); FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); @@ -288,7 +288,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe public void onCatSelected(FeedCategory cat, boolean openAsFeed) { FeedCategoriesFragment fc = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS); - m_pullToRefreshAttacher.setRefreshing(true); + //m_pullToRefreshAttacher.setRefreshing(true); if (!openAsFeed) { @@ -358,7 +358,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe refresh(); return true; case R.id.update_feeds: - m_pullToRefreshAttacher.setRefreshing(true); + //m_pullToRefreshAttacher.setRefreshing(true); refresh(); return true; default: diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 5391997d..7c974809 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -17,8 +17,6 @@ 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; @@ -36,6 +34,7 @@ import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; +import android.support.v4.widget.SwipeRefreshLayout; import android.util.Base64; import android.util.Log; import android.view.ContextMenu; @@ -59,7 +58,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, OnRefreshListener { +public class FeedsFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; private FeedListAdapter m_adapter; @@ -70,6 +69,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh private static final String ICON_PATH = "/icons/"; private boolean m_enableFeedIcons; private boolean m_feedIconsChecked = false; + private SwipeRefreshLayout m_swipeLayout; public void initialize(FeedCategory cat) { m_activeCategory = cat; @@ -277,6 +277,22 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh View view = inflater.inflate(R.layout.feeds_fragment, container, false); + m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.feeds_swipe_container); + + m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refresh(false); + } + }); + + if (!m_activity.isCompatMode()) { + m_swipeLayout.setColorScheme(android.R.color.holo_green_dark, + android.R.color.holo_red_dark, + android.R.color.holo_blue_dark, + android.R.color.holo_orange_dark); + } + ListView list = (ListView)view.findViewById(R.id.feeds); m_adapter = new FeedListAdapter(getActivity(), R.layout.feeds_row, (ArrayList)m_feeds); list.setAdapter(m_adapter); @@ -287,9 +303,8 @@ 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); + //Log.d(TAG, "mpTRA=" + m_activity.m_pullToRefreshAttacher); + //m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); return view; } @@ -365,6 +380,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh public void refresh(boolean background) { //FeedCategory cat = m_onlineServices.getActiveCategory(); + m_swipeLayout.setRefreshing(true); + final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4; final String sessionId = m_activity.getSessionId(); @@ -484,8 +501,9 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh } m_activity.setProgressBarVisibility(false); - m_activity.m_pullToRefreshAttacher.setRefreshComplete(); - + //m_activity.m_pullToRefreshAttacher.setRefreshComplete(); + m_swipeLayout.setRefreshing(false); + if (result != null) { try { JsonArray content = result.getAsJsonArray(); @@ -782,9 +800,9 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh } } - @Override + /* @Override public void onRefreshStarted(View view) { refresh(false); - } + } */ } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index c6380b94..b67012a6 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -14,8 +14,6 @@ import org.fox.ttrss.util.HeadlinesRequest; import org.fox.ttrss.util.TypefaceCache; import org.jsoup.Jsoup; -import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener; - import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -29,6 +27,7 @@ import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; +import android.support.v4.widget.SwipeRefreshLayout; import android.text.Html; import android.text.Html.ImageGetter; import android.util.Log; @@ -53,7 +52,7 @@ import android.widget.TextView; import com.google.gson.JsonElement; -public class HeadlinesFragment extends Fragment implements OnItemClickListener, OnScrollListener, OnRefreshListener { +public class HeadlinesFragment extends Fragment implements OnItemClickListener, OnScrollListener { public static enum ArticlesSelection { ALL, NONE, UNREAD }; public static final int HEADLINES_REQUEST_SIZE = 30; @@ -75,6 +74,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, private ArticleList m_readArticles = new ArticleList(); private HeadlinesEventListener m_listener; private OnlineActivity m_activity; + private SwipeRefreshLayout m_swipeLayout; private ImageGetter m_dummyGetter = new ImageGetter() { @@ -290,6 +290,23 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, View view = inflater.inflate(R.layout.headlines_fragment, container, false); + m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.headlines_swipe_container); + + m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refresh(false); + } + }); + + if (!m_activity.isCompatMode()) { + m_swipeLayout.setColorScheme(android.R.color.holo_green_dark, + android.R.color.holo_red_dark, + android.R.color.holo_blue_dark, + android.R.color.holo_orange_dark); + } + + ListView list = (ListView)view.findViewById(R.id.headlines); m_adapter = new ArticleListAdapter(getActivity(), R.layout.headlines_row, (ArrayList
)m_articles); @@ -318,7 +335,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, //list.setEmptyView(view.findViewById(R.id.no_headlines)); registerForContextMenu(list); - m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); + //m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); //if (m_activity.isSmallScreen()) //view.findViewById(R.id.headlines_fragment).setPadding(0, 0, 0, 0); @@ -387,6 +404,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, if (m_activity != null && m_feed != null) { m_refreshInProgress = true; + m_swipeLayout.setRefreshing(true); m_activity.setProgressBarVisibility(true); if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) { @@ -434,8 +452,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, super.onPostExecute(result); if (isAdded()) { - m_activity.m_pullToRefreshAttacher.setRefreshComplete(); - } + m_swipeLayout.setRefreshing(false); + } if (result != null) { m_refreshInProgress = false; @@ -986,10 +1004,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, return m_feed; } - @Override + /* @Override public void onRefreshStarted(View view) { refresh(false); - } + } */ } diff --git a/src/org/fox/ttrss/OnlineActivity.java b/src/org/fox/ttrss/OnlineActivity.java index 1a43d73f..e19bbd0c 100644 --- a/src/org/fox/ttrss/OnlineActivity.java +++ b/src/org/fox/ttrss/OnlineActivity.java @@ -17,7 +17,6 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; -import uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.*; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; @@ -53,7 +52,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; - public class OnlineActivity extends CommonActivity { private final String TAG = this.getClass().getSimpleName(); @@ -69,7 +67,7 @@ public class OnlineActivity extends CommonActivity { private String m_lastImageHitTestUrl; - protected PullToRefreshAttacher m_pullToRefreshAttacher; + //protected PullToRefreshAttacher m_pullToRefreshAttacher; protected abstract class OnLoginFinishedListener { public abstract void OnLoginSuccess(); @@ -173,7 +171,7 @@ public class OnlineActivity extends CommonActivity { setContentView(R.layout.login); - m_pullToRefreshAttacher = PullToRefreshAttacher.get(this); + //m_pullToRefreshAttacher = PullToRefreshAttacher.get(this); if (isOffline) { switchOfflineSuccess(); @@ -1036,7 +1034,7 @@ public class OnlineActivity extends CommonActivity { return true; case R.id.update_headlines: if (hf != null) { - m_pullToRefreshAttacher.setRefreshing(true); + //m_pullToRefreshAttacher.setRefreshing(true); hf.refresh(false); } return true;