diff options
Diffstat (limited to 'src/de/danoeh/antennapod/fragment/DownloadLogFragment.java')
-rw-r--r-- | src/de/danoeh/antennapod/fragment/DownloadLogFragment.java | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/src/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/src/de/danoeh/antennapod/fragment/DownloadLogFragment.java deleted file mode 100644 index d81ba4b86..000000000 --- a/src/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ /dev/null @@ -1,121 +0,0 @@ -package de.danoeh.antennapod.fragment; - -import android.content.Context; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.ListFragment; -import android.view.View; -import de.danoeh.antennapod.adapter.DownloadLogAdapter; -import de.danoeh.antennapod.feed.EventDistributor; -import de.danoeh.antennapod.service.download.DownloadStatus; -import de.danoeh.antennapod.storage.DBReader; - -import java.util.List; - -/** - * Shows the download log - */ -public class DownloadLogFragment extends ListFragment { - - private List<DownloadStatus> downloadLog; - private DownloadLogAdapter adapter; - - private boolean viewsCreated = false; - private boolean itemsLoaded = false; - - @Override - public void onStart() { - super.onStart(); - EventDistributor.getInstance().register(contentUpdate); - startItemLoader(); - } - - @Override - public void onStop() { - super.onStop(); - EventDistributor.getInstance().unregister(contentUpdate); - stopItemLoader(); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - viewsCreated = true; - if (itemsLoaded) { - onFragmentLoaded(); - } - } - - private void onFragmentLoaded() { - if (adapter == null) { - adapter = new DownloadLogAdapter(getActivity(), itemAccess); - setListAdapter(adapter); - } - setListShown(true); - adapter.notifyDataSetChanged(); - - } - - private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() { - - @Override - public int getCount() { - return (downloadLog != null) ? downloadLog.size() : 0; - } - - @Override - public DownloadStatus getItem(int position) { - return (downloadLog != null) ? downloadLog.get(position) : null; - } - }; - - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((arg & EventDistributor.DOWNLOADLOG_UPDATE) != 0) { - startItemLoader(); - } - } - }; - - private ItemLoader itemLoader; - - private void startItemLoader() { - if (itemLoader != null) { - itemLoader.cancel(true); - } - itemLoader = new ItemLoader(); - itemLoader.execute(); - } - - private void stopItemLoader() { - if (itemLoader != null) { - itemLoader.cancel(true); - } - } - - private class ItemLoader extends AsyncTask<Void, Void, List<DownloadStatus>> { - - @Override - protected void onPostExecute(List<DownloadStatus> downloadStatuses) { - super.onPostExecute(downloadStatuses); - if (downloadStatuses != null) { - downloadLog = downloadStatuses; - itemsLoaded = true; - if (viewsCreated) { - onFragmentLoaded(); - } - } - } - - @Override - protected List<DownloadStatus> doInBackground(Void... params) { - Context context = getActivity(); - if (context != null) { - return DBReader.getDownloadLog(context); - } - return null; - } - } -} |