Skip to content

Commit

Permalink
Move heavy operations off the ui thread
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedol committed Aug 3, 2013
1 parent 5ea7d21 commit e7a3797
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockListFragment;
Expand Down Expand Up @@ -88,6 +89,7 @@ public abstract class BaseListFragment<V extends View, M extends Model, L extend
*/
protected V view;


/**
* BaseListActivity
*
Expand Down Expand Up @@ -125,8 +127,6 @@ public void onActivityCreated(Bundle savedInstanceState) {

listView.setFocusable(true);
listView.setFocusableInTouchMode(true);

new LoadingTask(getActivity()).execute((String)null);
}
}

Expand Down Expand Up @@ -154,14 +154,6 @@ public void onResume() {
super.onResume();
}

/**
* Called after ListAdapter has been loaded
*
* @param success
* true is successfully loaded
*/
protected abstract void onLoaded(boolean success);

@SuppressWarnings("unchecked")
protected M getSelectedItem() {
return (M) listView.getSelectedItem();
Expand All @@ -174,38 +166,6 @@ public void onItemSelected(AdapterView<?> adapterView,
public void onNothingSelected(AdapterView<?> adapterView) {
}

/**
* ProgressTask sub-class for showing Loading... dialog while the
* BaseListAdapter loads the data
*/
protected class LoadingTask extends ProgressTask {
public LoadingTask(Activity activity) {
super(activity);
}

@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.cancel();
}

@Override
protected Boolean doInBackground(String... args) {

adapter.refresh();

return true;
}

@Override
protected void onPostExecute(Boolean success) {
super.onPostExecute(success);

onLoaded(success);
listView.setAdapter(adapter);
}
}

protected void log(String message) {
Logger.log(getClass().getName(), message);
}
Expand Down
Loading

0 comments on commit e7a3797

Please sign in to comment.