Fixed IllegalStateExceptions in some Fragments

This commit is contained in:
daniel oeh 2014-07-26 12:35:43 +02:00
parent aca79dc5b9
commit c1fbc59f1c
2 changed files with 26 additions and 10 deletions

View File

@ -68,6 +68,7 @@ public class CompletedDownloadsFragment extends ListFragment {
listAdapter = null;
viewCreated = false;
feedItemDialog = null;
stopItemLoader();
}
@Override
@ -103,6 +104,7 @@ public class CompletedDownloadsFragment extends ListFragment {
listAdapter = new DownloadedEpisodesListAdapter(getActivity(), itemAccess);
setListAdapter(listAdapter);
}
setListShown(true);
listAdapter.notifyDataSetChanged();
if (feedItemDialog != null) {
boolean res = feedItemDialog.updateContent(queue, items);
@ -171,7 +173,6 @@ public class CompletedDownloadsFragment extends ListFragment {
@Override
protected void onPostExecute(Object[] results) {
super.onPostExecute(results);
setListShown(true);
if (results != null) {
items = (List<FeedItem>) results[0];
queue = (QueueAccess) results[1];

View File

@ -11,18 +11,18 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.fragment.SearchFragment;
import de.danoeh.antennapod.gpoddernet.GpodnetService;
import de.danoeh.antennapod.gpoddernet.GpodnetServiceException;
import de.danoeh.antennapod.gpoddernet.model.GpodnetTag;
import de.danoeh.antennapod.util.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.util.menuhandler.NavDrawerActivity;
import java.util.ArrayList;
import java.util.List;
public class TagListFragment extends ListFragment {
private static final String TAG = "TagListFragment";
private static final int COUNT = 50;
@ -69,11 +69,26 @@ public class TagListFragment extends ListFragment {
}
});
loadData();
startLoadTask();
}
private void loadData() {
AsyncTask<Void, Void, List<GpodnetTag>> task = new AsyncTask<Void, Void, List<GpodnetTag>>() {
@Override
public void onDestroyView() {
super.onDestroyView();
cancelLoadTask();
}
private AsyncTask<Void, Void, List<GpodnetTag>> loadTask;
private void cancelLoadTask() {
if (loadTask != null && !loadTask.isCancelled()) {
loadTask.cancel(true);
}
}
private void startLoadTask() {
cancelLoadTask();
loadTask = new AsyncTask<Void, Void, List<GpodnetTag>>() {
private Exception exception;
@Override
@ -118,9 +133,9 @@ public class TagListFragment extends ListFragment {
}
};
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
task.execute();
loadTask.execute();
}
}
}