From 0e25b7519cc9caaa22603b1586c3b5b1b75cdc9f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 27 Nov 2011 10:18:54 +0300 Subject: [PATCH] better handle http errors --- res/values/strings.xml | 4 +++ src/org/fox/ttrss/FeedsFragment.java | 25 ++++++++------ src/org/fox/ttrss/HeadlinesFragment.java | 43 +++++++++++++++--------- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 7c7408fb..8e32a61c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -38,4 +38,8 @@ Show all articles Show unread articles Accept any SSL certificate + Error: no data received. + No feeds to display. + Error: invalid object received. + diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index df7ef6be..43c30234 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -62,7 +62,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { } - public void showLoading(boolean show) { + /* public void showLoading(boolean show) { View v = getView(); if (v != null) { @@ -71,7 +71,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { if (v != null) v.setVisibility(show ? View.VISIBLE : View.GONE); } - } + } */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -91,7 +91,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { if (m_feeds == null || m_feeds.size() == 0) refresh(); else - view.findViewById(R.id.loading_container).setVisibility(View.GONE); + view.findViewById(R.id.loading_progress).setVisibility(View.GONE); return view; } @@ -130,10 +130,10 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { } public void refresh() { - FeedsRequest fr = new FeedsRequest(); + FeedsRequest req = new FeedsRequest(); - fr.setApi(m_prefs.getString("ttrss_url", null)); - fr.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false)); + req.setApi(m_prefs.getString("ttrss_url", null)); + req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false)); final String sessionId = ((MainActivity)getActivity()).getSessionId(); final boolean unreadOnly = ((MainActivity)getActivity()).getUnreadOnly(); @@ -151,7 +151,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { } }; - fr.execute(map); + req.execute(map); } } @@ -196,25 +196,28 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { sortFeeds(); - showLoading(false); + if (m_feeds.size() == 0) + setLoadingStatus(R.string.error_no_feeds, false); + else + setLoadingStatus(R.string.blank, false); + } }); } } else { MainActivity activity = (MainActivity)getActivity(); activity.login(); - showLoading(false); } } catch (Exception e) { e.printStackTrace(); + setLoadingStatus(R.string.error_invalid_object, false); // report invalid object received } } else { // report null object received + setLoadingStatus(R.string.error_no_data, false); } - showLoading(false); - return; } } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 734c21a4..1e49c876 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -81,12 +81,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { if (m_feed != null && (m_articles == null || m_articles.size() == 0)) refresh(false); else - view.findViewById(R.id.loading_container).setVisibility(View.GONE); + view.findViewById(R.id.loading_progress).setVisibility(View.GONE); return view; } - public void showLoading(boolean show) { + /* public void showLoading(boolean show) { View v = getView(); if (v != null) { @@ -95,7 +95,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { if (v != null) v.setVisibility(show ? View.VISIBLE : View.GONE); } - } + } */ @Override public void onAttach(Activity activity) { @@ -169,6 +169,20 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { out.putParcelable("selectedArticles", m_selectedArticles); } + public void setLoadingStatus(int status, boolean showProgress) { + TextView tv = (TextView)getView().findViewById(R.id.loading_message); + + if (tv != null) { + tv.setText(status); + } + + View pb = getView().findViewById(R.id.loading_progress); + + if (pb != null) { + pb.setVisibility(showProgress ? View.VISIBLE : View.GONE); + } + } + private class HeadlinesRequest extends ApiRequest { int m_offset = 0; @@ -210,25 +224,22 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { activity.setCanLoadMore(articles.size() >= 30); activity.initMainMenu(); - showLoading(false); + setLoadingStatus(R.string.blank, false); } }); } } else { MainActivity activity = (MainActivity)getActivity(); activity.login(); - showLoading(false); } } catch (Exception e) { e.printStackTrace(); - // report invalid object + setLoadingStatus(R.string.error_invalid_object, false); } } else { - // report null object + setLoadingStatus(R.string.error_no_data, false); } - showLoading(false); - return; } @@ -239,8 +250,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { } public void catchupArticle(final Article article) { - ApiRequest ar = new ApiRequest(); - ar.setApi(m_prefs.getString("ttrss_url", null)); + ApiRequest req = new ApiRequest(); + req.setApi(m_prefs.getString("ttrss_url", null)); + req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false)); final String sessionId = ((MainActivity)getActivity()).getSessionId(); @@ -254,12 +266,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { } }; - ar.execute(map); + req.execute(map); } public void setArticleMarked(final Article article) { - ApiRequest ar = new ApiRequest(); - ar.setApi(m_prefs.getString("ttrss_url", null)); + ApiRequest req = new ApiRequest(); + req.setApi(m_prefs.getString("ttrss_url", null)); + req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false)); final String sessionId = ((MainActivity)getActivity()).getSessionId(); @@ -273,7 +286,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { } }; - ar.execute(map); + req.execute(map); } private class ArticleListAdapter extends ArrayAdapter
{ private ArrayList
items;