better handle http errors
This commit is contained in:
parent
0bf4c51052
commit
0e25b7519c
@ -38,4 +38,8 @@
|
|||||||
<string name="show_all_articles">Show all articles</string>
|
<string name="show_all_articles">Show all articles</string>
|
||||||
<string name="show_unread_articles">Show unread articles</string>
|
<string name="show_unread_articles">Show unread articles</string>
|
||||||
<string name="ssl_trust_any">Accept any SSL certificate</string>
|
<string name="ssl_trust_any">Accept any SSL certificate</string>
|
||||||
|
<string name="error_no_data">Error: no data received.</string>
|
||||||
|
<string name="error_no_feeds">No feeds to display.</string>
|
||||||
|
<string name="error_invalid_object">Error: invalid object received.</string>
|
||||||
|
<string name="blank"></string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -62,7 +62,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLoading(boolean show) {
|
/* public void showLoading(boolean show) {
|
||||||
View v = getView();
|
View v = getView();
|
||||||
|
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
@ -71,7 +71,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
if (v != null)
|
if (v != null)
|
||||||
v.setVisibility(show ? View.VISIBLE : View.GONE);
|
v.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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)
|
if (m_feeds == null || m_feeds.size() == 0)
|
||||||
refresh();
|
refresh();
|
||||||
else
|
else
|
||||||
view.findViewById(R.id.loading_container).setVisibility(View.GONE);
|
view.findViewById(R.id.loading_progress).setVisibility(View.GONE);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@ -130,10 +130,10 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
FeedsRequest fr = new FeedsRequest();
|
FeedsRequest req = new FeedsRequest();
|
||||||
|
|
||||||
fr.setApi(m_prefs.getString("ttrss_url", null));
|
req.setApi(m_prefs.getString("ttrss_url", null));
|
||||||
fr.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
||||||
final boolean unreadOnly = ((MainActivity)getActivity()).getUnreadOnly();
|
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();
|
sortFeeds();
|
||||||
|
|
||||||
showLoading(false);
|
if (m_feeds.size() == 0)
|
||||||
|
setLoadingStatus(R.string.error_no_feeds, false);
|
||||||
|
else
|
||||||
|
setLoadingStatus(R.string.blank, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MainActivity activity = (MainActivity)getActivity();
|
MainActivity activity = (MainActivity)getActivity();
|
||||||
activity.login();
|
activity.login();
|
||||||
showLoading(false);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
setLoadingStatus(R.string.error_invalid_object, false);
|
||||||
// report invalid object received
|
// report invalid object received
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// report null object received
|
// report null object received
|
||||||
|
setLoadingStatus(R.string.error_no_data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
showLoading(false);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,12 +81,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
if (m_feed != null && (m_articles == null || m_articles.size() == 0))
|
if (m_feed != null && (m_articles == null || m_articles.size() == 0))
|
||||||
refresh(false);
|
refresh(false);
|
||||||
else
|
else
|
||||||
view.findViewById(R.id.loading_container).setVisibility(View.GONE);
|
view.findViewById(R.id.loading_progress).setVisibility(View.GONE);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLoading(boolean show) {
|
/* public void showLoading(boolean show) {
|
||||||
View v = getView();
|
View v = getView();
|
||||||
|
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
@ -95,7 +95,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
if (v != null)
|
if (v != null)
|
||||||
v.setVisibility(show ? View.VISIBLE : View.GONE);
|
v.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
@ -169,6 +169,20 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
out.putParcelable("selectedArticles", m_selectedArticles);
|
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 {
|
private class HeadlinesRequest extends ApiRequest {
|
||||||
int m_offset = 0;
|
int m_offset = 0;
|
||||||
|
|
||||||
@ -210,25 +224,22 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
activity.setCanLoadMore(articles.size() >= 30);
|
activity.setCanLoadMore(articles.size() >= 30);
|
||||||
activity.initMainMenu();
|
activity.initMainMenu();
|
||||||
|
|
||||||
showLoading(false);
|
setLoadingStatus(R.string.blank, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MainActivity activity = (MainActivity)getActivity();
|
MainActivity activity = (MainActivity)getActivity();
|
||||||
activity.login();
|
activity.login();
|
||||||
showLoading(false);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
// report invalid object
|
setLoadingStatus(R.string.error_invalid_object, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// report null object
|
setLoadingStatus(R.string.error_no_data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
showLoading(false);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -239,8 +250,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void catchupArticle(final Article article) {
|
public void catchupArticle(final Article article) {
|
||||||
ApiRequest ar = new ApiRequest();
|
ApiRequest req = new ApiRequest();
|
||||||
ar.setApi(m_prefs.getString("ttrss_url", null));
|
req.setApi(m_prefs.getString("ttrss_url", null));
|
||||||
|
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
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) {
|
public void setArticleMarked(final Article article) {
|
||||||
ApiRequest ar = new ApiRequest();
|
ApiRequest req = new ApiRequest();
|
||||||
ar.setApi(m_prefs.getString("ttrss_url", null));
|
req.setApi(m_prefs.getString("ttrss_url", null));
|
||||||
|
req.setTrustAny(m_prefs.getBoolean("ssl_trust_any", false));
|
||||||
|
|
||||||
final String sessionId = ((MainActivity)getActivity()).getSessionId();
|
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<Article> {
|
private class ArticleListAdapter extends ArrayAdapter<Article> {
|
||||||
private ArrayList<Article> items;
|
private ArrayList<Article> items;
|
||||||
|
Loading…
Reference in New Issue
Block a user