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) { if (sessionId != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setLoadingStatus(R.string.blank, true);
}
});
HashMap<String,String> map = new HashMap<String,String>() { HashMap<String,String> map = new HashMap<String,String>() {
{ {
put("op", "getFeeds"); put("op", "getFeeds");
@ -157,6 +164,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
} }
public void setLoadingStatus(int status, boolean showProgress) { public void setLoadingStatus(int status, boolean showProgress) {
if (getView() != null) {
TextView tv = (TextView)getView().findViewById(R.id.loading_message); TextView tv = (TextView)getView().findViewById(R.id.loading_message);
if (tv != null) { if (tv != null) {
@ -169,6 +177,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE); pb.setVisibility(showProgress ? View.VISIBLE : View.GONE);
} }
} }
}
private class FeedsRequest extends ApiRequest { private class FeedsRequest extends ApiRequest {
@ -187,8 +196,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
Type listType = new TypeToken<List<Feed>>() {}.getType(); Type listType = new TypeToken<List<Feed>>() {}.getType();
final List<Feed> feeds = gson.fromJson(content, listType); 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) for (Feed f : feeds)
@ -202,8 +209,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
setLoadingStatus(R.string.blank, false); setLoadingStatus(R.string.blank, false);
} }
});
}
} else { } else {
MainActivity activity = (MainActivity)getActivity(); MainActivity activity = (MainActivity)getActivity();
activity.login(); activity.login();

View File

@ -144,6 +144,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
req.setOffset(skip); req.setOffset(skip);
setLoadingStatus(R.string.blank, true);
HashMap<String,String> map = new HashMap<String,String>() { HashMap<String,String> map = new HashMap<String,String>() {
{ {
put("op", "getHeadlines"); put("op", "getHeadlines");
@ -171,6 +173,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
} }
public void setLoadingStatus(int status, boolean showProgress) { public void setLoadingStatus(int status, boolean showProgress) {
if (getView() != null) {
TextView tv = (TextView)getView().findViewById(R.id.loading_message); TextView tv = (TextView)getView().findViewById(R.id.loading_message);
if (tv != null) { if (tv != null) {
@ -183,6 +186,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE); 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;
@ -202,9 +206,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
Type listType = new TypeToken<List<Article>>() {}.getType(); Type listType = new TypeToken<List<Article>>() {}.getType();
final List<Article> articles = gson.fromJson(content, listType); final List<Article> articles = gson.fromJson(content, listType);
getActivity().runOnUiThread(new Runnable() {
public void run() {
if (m_offset == 0) if (m_offset == 0)
m_articles.clear(); m_articles.clear();
@ -227,8 +228,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
setLoadingStatus(R.string.blank, false); setLoadingStatus(R.string.blank, false);
} }
});
}
} else { } else {
MainActivity activity = (MainActivity)getActivity(); MainActivity activity = (MainActivity)getActivity();
activity.login(); activity.login();