various progressbar usage fixes

remove unnecessary runOnUiThread from asynctask methods
This commit is contained in:
Andrew Dolgov 2011-11-27 12:57:34 +03:00
parent 2b25a9caec
commit 936935c019
2 changed files with 66 additions and 62 deletions

View File

@ -140,6 +140,13 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
if (sessionId != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setLoadingStatus(R.string.blank, true);
}
});
HashMap<String,String> map = new HashMap<String,String>() {
{
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 (getView() != null) {
TextView tv = (TextView)getView().findViewById(R.id.loading_message);
if (tv != null) {
tv.setText(status);
}
if (tv != null) {
tv.setText(status);
}
View pb = getView().findViewById(R.id.loading_progress);
View pb = getView().findViewById(R.id.loading_progress);
if (pb != null) {
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE);
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<List<Feed>>() {}.getType();
final List<Feed> 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);
for (Feed f : feeds)
m_feeds.add(f);
sortFeeds();
sortFeeds();
if (m_feeds.size() == 0)
setLoadingStatus(R.string.error_no_feeds, false);
else
setLoadingStatus(R.string.blank, false);
if (m_feeds.size() == 0)
setLoadingStatus(R.string.error_no_feeds, false);
else
setLoadingStatus(R.string.blank, false);
}
});
}
} else {
MainActivity activity = (MainActivity)getActivity();

View File

@ -144,6 +144,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
req.setOffset(skip);
setLoadingStatus(R.string.blank, true);
HashMap<String,String> map = new HashMap<String,String>() {
{
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 (getView() != null) {
TextView tv = (TextView)getView().findViewById(R.id.loading_message);
if (tv != null) {
tv.setText(status);
}
if (tv != null) {
tv.setText(status);
}
View pb = getView().findViewById(R.id.loading_progress);
View pb = getView().findViewById(R.id.loading_progress);
if (pb != null) {
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE);
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<List<Article>>() {}.getType();
final List<Article> articles = gson.fromJson(content, listType);
getActivity().runOnUiThread(new Runnable() {
public void run() {
if (m_offset == 0)
m_articles.clear();
if (m_offset == 0)
m_articles.clear();
int last_position = m_articles.size();
int last_position = m_articles.size();
for (Article f : articles)
m_articles.add(f);
for (Article f : articles)
m_articles.add(f);
m_adapter.notifyDataSetChanged();
m_adapter.notifyDataSetChanged();
ListView list = (ListView)getView().findViewById(R.id.headlines);
ListView list = (ListView)getView().findViewById(R.id.headlines);
if (list != null && m_offset != 0) {
list.setSelection(last_position+1);
}
if (list != null && m_offset != 0) {
list.setSelection(last_position+1);
}
MainActivity activity = (MainActivity)getActivity();
activity.setCanLoadMore(articles.size() >= 30);
activity.initMainMenu();
MainActivity activity = (MainActivity)getActivity();
activity.setCanLoadMore(articles.size() >= 30);
activity.initMainMenu();
setLoadingStatus(R.string.blank, false);
}
});
setLoadingStatus(R.string.blank, false);
}
} else {
MainActivity activity = (MainActivity)getActivity();