From 936935c01975f26bbf8cf7dd15f52872aacc8d4c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 27 Nov 2011 12:57:34 +0300 Subject: [PATCH] various progressbar usage fixes remove unnecessary runOnUiThread from asynctask methods --- src/org/fox/ttrss/FeedsFragment.java | 57 ++++++++++--------- src/org/fox/ttrss/HeadlinesFragment.java | 71 ++++++++++++------------ 2 files changed, 66 insertions(+), 62 deletions(-) diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 8e84aec1..2e0a7665 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -139,7 +139,14 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { final boolean unreadOnly = ((MainActivity)getActivity()).getUnreadOnly(); if (sessionId != null) { - + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + setLoadingStatus(R.string.blank, true); + } + }); + HashMap map = new HashMap() { { put("op", "getFeeds"); @@ -157,16 +164,18 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { } 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); + if (getView() != null) { + 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); + } } } @@ -187,22 +196,18 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { Type listType = new TypeToken>() {}.getType(); final List feeds = gson.fromJson(content, listType); - getActivity().runOnUiThread(new Runnable() { - public void run() { - m_feeds.clear(); + m_feeds.clear(); + + for (Feed f : feeds) + m_feeds.add(f); + + sortFeeds(); + + if (m_feeds.size() == 0) + setLoadingStatus(R.string.error_no_feeds, false); + else + setLoadingStatus(R.string.blank, false); - for (Feed f : feeds) - m_feeds.add(f); - - sortFeeds(); - - if (m_feeds.size() == 0) - setLoadingStatus(R.string.error_no_feeds, false); - else - setLoadingStatus(R.string.blank, false); - - } - }); } } else { MainActivity activity = (MainActivity)getActivity(); diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 1185e350..d6c7ae1c 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -144,6 +144,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { req.setOffset(skip); + setLoadingStatus(R.string.blank, true); + HashMap map = new HashMap() { { put("op", "getHeadlines"); @@ -171,16 +173,18 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { } 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); + if (getView() != null) { + 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); + } } } @@ -202,32 +206,27 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { Type listType = new TypeToken>() {}.getType(); final List
articles = gson.fromJson(content, listType); - getActivity().runOnUiThread(new Runnable() { - public void run() { - - if (m_offset == 0) - m_articles.clear(); - - int last_position = m_articles.size(); - - for (Article f : articles) - m_articles.add(f); - - m_adapter.notifyDataSetChanged(); - - ListView list = (ListView)getView().findViewById(R.id.headlines); - - if (list != null && m_offset != 0) { - list.setSelection(last_position+1); - } - - MainActivity activity = (MainActivity)getActivity(); - activity.setCanLoadMore(articles.size() >= 30); - activity.initMainMenu(); - - setLoadingStatus(R.string.blank, false); - } - }); + if (m_offset == 0) + m_articles.clear(); + + int last_position = m_articles.size(); + + for (Article f : articles) + m_articles.add(f); + + m_adapter.notifyDataSetChanged(); + + ListView list = (ListView)getView().findViewById(R.id.headlines); + + if (list != null && m_offset != 0) { + list.setSelection(last_position+1); + } + + MainActivity activity = (MainActivity)getActivity(); + activity.setCanLoadMore(articles.size() >= 30); + activity.initMainMenu(); + + setLoadingStatus(R.string.blank, false); } } else { MainActivity activity = (MainActivity)getActivity();