diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-06-01 18:29:04 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-06-01 18:29:04 +0200 |
commit | 71a47c0a5bf99a734081d217eb3e14d75f017a7a (patch) | |
tree | 902cbb139b58e4a0f331ed2ab6e3664c6b4d76c0 /src/de/danoeh/antennapod/activity | |
parent | b83656049d0453012d29eb67f74a6352ce246689 (diff) | |
download | AntennaPod-71a47c0a5bf99a734081d217eb3e14d75f017a7a.zip |
Ported several classes from FeedManager to DB*-classes
Diffstat (limited to 'src/de/danoeh/antennapod/activity')
7 files changed, 294 insertions, 146 deletions
diff --git a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java index 232a7ba1d..af2cdb65a 100644 --- a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java +++ b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java @@ -1,15 +1,20 @@ package de.danoeh.antennapod.activity; +import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; import com.actionbarsherlock.app.SherlockListActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.adapter.DownloadLogAdapter; import de.danoeh.antennapod.feed.EventDistributor; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.service.download.DownloadStatus; +import de.danoeh.antennapod.storage.DBReader; + +import java.util.List; /** * Displays completed and failed downloads in a list. The data comes from the @@ -18,18 +23,18 @@ import de.danoeh.antennapod.preferences.UserPreferences; public class DownloadLogActivity extends SherlockListActivity { private static final String TAG = "DownloadLogActivity"; - DownloadLogAdapter dla; - FeedManager manager; + private List<DownloadStatus> downloadLog; + private DownloadLogAdapter dla; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - manager = FeedManager.getInstance(); - dla = new DownloadLogAdapter(this); + dla = new DownloadLogAdapter(this, itemAccess); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setListAdapter(dla); + loadData(); } @Override @@ -62,12 +67,48 @@ public class DownloadLogActivity extends SherlockListActivity { return true; } + private void loadData() { + AsyncTask<Void, Void, List<DownloadStatus>> loadTask = new AsyncTask<Void, Void, List<DownloadStatus>>() { + @Override + protected List<DownloadStatus> doInBackground(Void... voids) { + return DBReader.getDownloadLog(DownloadLogActivity.this); + } + + @Override + protected void onPostExecute(List<DownloadStatus> downloadStatuses) { + super.onPostExecute(downloadStatuses); + if (downloadStatuses != null) { + downloadLog = downloadStatuses; + if (dla != null) { + dla.notifyDataSetChanged(); + } + } else { + Log.e(TAG, "Could not load download log"); + } + } + }; + loadTask.execute(); + } + + 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) { - dla.notifyDataSetChanged(); + loadData(); } } }; diff --git a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java index c57a5794b..58fa78546 100644 --- a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java +++ b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.activity; +import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; @@ -15,8 +16,8 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.ImageLoader; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.feed.Feed; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.util.LangUtils; import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; @@ -42,47 +43,66 @@ public class FeedInfoActivity extends SherlockActivity { setContentView(R.layout.feedinfo); getSupportActionBar().setDisplayHomeAsUpEnabled(true); long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1); - FeedManager manager = FeedManager.getInstance(); - feed = manager.getFeed(feedId); - if (feed != null) { - if (AppConfig.DEBUG) - Log.d(TAG, "Language is " + feed.getLanguage()); - if (AppConfig.DEBUG) - Log.d(TAG, "Author is " + feed.getAuthor()); - imgvCover = (ImageView) findViewById(R.id.imgvCover); - txtvTitle = (TextView) findViewById(R.id.txtvTitle); - txtvDescription = (TextView) findViewById(R.id.txtvDescription); - txtvLanguage = (TextView) findViewById(R.id.txtvLanguage); - txtvAuthor = (TextView) findViewById(R.id.txtvAuthor); - imgvCover.post(new Runnable() { - - @Override - public void run() { - ImageLoader.getInstance().loadThumbnailBitmap( - feed.getImage(), imgvCover); - } - }); + + AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() { - txtvTitle.setText(feed.getTitle()); - txtvDescription.setText(feed.getDescription()); - if (feed.getAuthor() != null) { - txtvAuthor.setText(feed.getAuthor()); - } - if (feed.getLanguage() != null) { - txtvLanguage.setText(LangUtils.getLanguageString(feed - .getLanguage())); + @Override + protected Feed doInBackground(Long... params) { + return DBReader.getFeed(FeedInfoActivity.this, params[0]); } - } else { - Log.e(TAG, "Activity was started with invalid arguments"); - } + @Override + protected void onPostExecute(Feed result) { + super.onPostExecute(result); + if (result != null) { + feed = result; + if (feed != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Language is " + feed.getLanguage()); + if (AppConfig.DEBUG) + Log.d(TAG, "Author is " + feed.getAuthor()); + imgvCover = (ImageView) findViewById(R.id.imgvCover); + txtvTitle = (TextView) findViewById(R.id.txtvTitle); + txtvDescription = (TextView) findViewById(R.id.txtvDescription); + txtvLanguage = (TextView) findViewById(R.id.txtvLanguage); + txtvAuthor = (TextView) findViewById(R.id.txtvAuthor); + imgvCover.post(new Runnable() { + + @Override + public void run() { + ImageLoader.getInstance().loadThumbnailBitmap( + feed.getImage(), imgvCover); + } + }); + + txtvTitle.setText(feed.getTitle()); + txtvDescription.setText(feed.getDescription()); + if (feed.getAuthor() != null) { + txtvAuthor.setText(feed.getAuthor()); + } + if (feed.getLanguage() != null) { + txtvLanguage.setText(LangUtils + .getLanguageString(feed.getLanguage())); + } + supportInvalidateOptionsMenu(); + } + } else { + Log.e(TAG, "Activity was started with invalid arguments"); + } + } + }; + loadTask.execute(feedId); } @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = new MenuInflater(this); - inflater.inflate(R.menu.feedinfo, menu); - return true; + if (feed != null) { + MenuInflater inflater = new MenuInflater(this); + inflater.inflate(R.menu.feedinfo, menu); + return true; + } else { + return false; + } } @Override @@ -105,7 +125,8 @@ public class FeedInfoActivity extends SherlockActivity { return FeedMenuHandler.onOptionsItemClicked(this, item, feed); } catch (DownloadRequestException e) { e.printStackTrace(); - DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, e.getMessage()); + DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, + e.getMessage()); } return super.onOptionsItemSelected(item); } diff --git a/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java b/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java index fdca48e8a..f784628d3 100644 --- a/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java +++ b/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.content.DialogInterface; import android.content.Intent; import android.content.res.TypedArray; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; @@ -15,16 +16,17 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; +import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.FeedRemover; import de.danoeh.antennapod.dialog.ConfirmationDialog; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.feed.Feed; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.fragment.ExternalPlayerFragment; import de.danoeh.antennapod.fragment.FeedlistFragment; import de.danoeh.antennapod.fragment.ItemlistFragment; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.util.StorageUtils; import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; @@ -33,8 +35,6 @@ import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; public class FeedItemlistActivity extends SherlockFragmentActivity { private static final String TAG = "FeedItemlistActivity"; - private FeedManager manager; - /** The feed which the activity displays */ private Feed feed; private ItemlistFragment filf; @@ -50,27 +50,52 @@ public class FeedItemlistActivity extends SherlockFragmentActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.feeditemlist_activity); - manager = FeedManager.getInstance(); long feedId = getIntent().getLongExtra( FeedlistFragment.EXTRA_SELECTED_FEED, -1); - if (feedId == -1) + if (feedId == -1) { Log.e(TAG, "Received invalid feed selection."); - - feed = manager.getFeed(feedId); - setTitle(feed.getTitle()); - - FragmentManager fragmentManager = getSupportFragmentManager(); - FragmentTransaction fT = fragmentManager.beginTransaction(); - - filf = ItemlistFragment.newInstance(feed.getId()); - fT.replace(R.id.feeditemlistFragment, filf); - - externalPlayerFragment = new ExternalPlayerFragment(); - fT.replace(R.id.playerFragment, externalPlayerFragment); - fT.commit(); + } else { + loadData(feedId); + } } + private void loadData(long id) { + AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() { + + @Override + protected Feed doInBackground(Long... longs) { + if (AppConfig.DEBUG) + Log.d(TAG, "Loading feed data in background"); + return DBReader.getFeed(FeedItemlistActivity.this, longs[0]); + } + + @Override + protected void onPostExecute(Feed result) { + super.onPostExecute(result); + if (result != null) { + if (AppConfig.DEBUG) Log.d(TAG, "Finished loading feed data"); + feed = result; + setTitle(feed.getTitle()); + + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fT = fragmentManager.beginTransaction(); + + filf = ItemlistFragment.newInstance(feed.getId()); + fT.replace(R.id.feeditemlistFragment, filf); + + externalPlayerFragment = new ExternalPlayerFragment(); + fT.replace(R.id.playerFragment, externalPlayerFragment); + fT.commit(); + supportInvalidateOptionsMenu(); + } else { + Log.e(TAG, "Error: Feed was null"); + } + } + }; + loadTask.execute(id); + } + @Override protected void onResume() { super.onResume(); @@ -79,13 +104,17 @@ public class FeedItemlistActivity extends SherlockFragmentActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.action_search }); - menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) - .setIcon(drawables.getDrawable(0)) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - return FeedMenuHandler - .onCreateOptionsMenu(new MenuInflater(this), menu); - } + if (feed != null) { + TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.action_search }); + menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) + .setIcon(drawables.getDrawable(0)) + .setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); + return FeedMenuHandler + .onCreateOptionsMenu(new MenuInflater(this), menu); + } else { + return false; + } + } @Override public boolean onPrepareOptionsMenu(Menu menu) { @@ -142,10 +171,14 @@ public class FeedItemlistActivity extends SherlockFragmentActivity { @Override public boolean onSearchRequested() { - Bundle bundle = new Bundle(); - bundle.putLong(SearchActivity.EXTRA_FEED_ID, feed.getId()); - startSearch(null, false, bundle, false); - return true; + if (feed != null) { + Bundle bundle = new Bundle(); + bundle.putLong(SearchActivity.EXTRA_FEED_ID, feed.getId()); + startSearch(null, false, bundle, false); + return true; + } else { + return false; + } } } diff --git a/src/de/danoeh/antennapod/activity/ItemviewActivity.java b/src/de/danoeh/antennapod/activity/ItemviewActivity.java index 5ead667dc..4568c535a 100644 --- a/src/de/danoeh/antennapod/activity/ItemviewActivity.java +++ b/src/de/danoeh/antennapod/activity/ItemviewActivity.java @@ -1,55 +1,56 @@ package de.danoeh.antennapod.activity; -import java.text.DateFormat; - +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.text.format.DateUtils; import android.util.Log; import android.widget.TextView; - import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; - import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; -import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.FeedManager; -import de.danoeh.antennapod.fragment.FeedlistFragment; import de.danoeh.antennapod.fragment.ItemDescriptionFragment; import de.danoeh.antennapod.fragment.ItemlistFragment; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.util.StorageUtils; import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler; +import java.text.DateFormat; + /** Displays a single FeedItem and provides various actions */ public class ItemviewActivity extends SherlockFragmentActivity { private static final String TAG = "ItemviewActivity"; - private FeedManager manager; - private FeedItem item; + private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOAD_QUEUED; - // Widgets - private TextView txtvTitle; - private TextView txtvPublished; + private FeedItem item; @Override public void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); StorageUtils.checkStorageAvailability(this); - manager = FeedManager.getInstance(); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); getSupportActionBar().setDisplayShowTitleEnabled(false); - extractFeeditem(); - populateUI(); + EventDistributor.getInstance().register(contentUpdate); + + long itemId = getIntent().getLongExtra( + ItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1); + if (itemId == -1) { + Log.e(TAG, "Received invalid selection of either feeditem or feed."); + } else { + loadData(itemId); + } } @Override @@ -66,28 +67,38 @@ public class ItemviewActivity extends SherlockFragmentActivity { Log.d(TAG, "Stopping Activity"); } - /** Extracts FeedItem object the activity is supposed to display */ - private void extractFeeditem() { - long itemId = getIntent().getLongExtra( - ItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1); - long feedId = getIntent().getLongExtra( - FeedlistFragment.EXTRA_SELECTED_FEED, -1); - if (itemId == -1 || feedId == -1) { - Log.e(TAG, "Received invalid selection of either feeditem or feed."); - } - Feed feed = manager.getFeed(feedId); - item = manager.getFeedItem(itemId, feed); - if (AppConfig.DEBUG) - Log.d(TAG, "Title of item is " + item.getTitle()); - if (AppConfig.DEBUG) - Log.d(TAG, "Title of feed is " + item.getFeed().getTitle()); - } + private void loadData(long itemId) { + AsyncTask<Long, Void, FeedItem> loadTask = new AsyncTask<Long, Void, FeedItem>() { + + @Override + protected FeedItem doInBackground(Long... longs) { + return DBReader.getFeedItem(ItemviewActivity.this, longs[0]); + } + + @Override + protected void onPostExecute(FeedItem feedItem) { + super.onPostExecute(feedItem); + if (feedItem != null && feedItem.getFeed() != null) { + item = feedItem; + populateUI(); + supportInvalidateOptionsMenu(); + } else { + if (feedItem == null) { + Log.e(TAG, "Error: FeedItem was null"); + } else if (feedItem.getFeed() == null) { + Log.e(TAG, "Error: Feed was null"); + } + } + } + }; + loadTask.execute(itemId); + } private void populateUI() { getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.feeditemview); - txtvTitle = (TextView) findViewById(R.id.txtvItemname); - txtvPublished = (TextView) findViewById(R.id.txtvPublished); + TextView txtvTitle = (TextView) findViewById(R.id.txtvItemname); + TextView txtvPublished = (TextView) findViewById(R.id.txtvPublished); setTitle(item.getFeed().getTitle()); txtvPublished.setText(DateUtils.formatSameDayTime(item.getPubDate() @@ -106,9 +117,13 @@ public class ItemviewActivity extends SherlockFragmentActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.feeditem, menu); - return true; + if (item != null) { + MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.feeditem, menu); + return true; + } else { + return false; + } } @Override @@ -143,4 +158,19 @@ public class ItemviewActivity extends SherlockFragmentActivity { }, item, true); } + private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + + @Override + public void update(EventDistributor eventDistributor, Integer arg) { + if ((EVENTS & arg) != 0) { + if (AppConfig.DEBUG) + Log.d(TAG, "Received contentUpdate Intent."); + if (item != null) { + loadData(item.getId()); + } + } + } + }; + + } diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java index 16b03809a..59e65bd48 100644 --- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -21,7 +21,6 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.dialog.TimeDialog; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.service.PlaybackService; import de.danoeh.antennapod.util.Converter; @@ -39,8 +38,6 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity implements OnSeekBarChangeListener { private static final String TAG = "MediaplayerActivity"; - protected FeedManager manager; - protected PlaybackController controller; protected TextView txtvPosition; @@ -149,7 +146,6 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity StorageUtils.checkStorageAvailability(this); orientation = getResources().getConfiguration().orientation; - manager = FeedManager.getInstance(); getWindow().setFormat(PixelFormat.TRANSPARENT); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } diff --git a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java index 7269f7549..f7e55d06f 100644 --- a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java +++ b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java @@ -1,36 +1,41 @@ package de.danoeh.antennapod.activity; import android.content.Context; -import android.content.res.TypedArray; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; - import com.actionbarsherlock.app.SherlockListActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import com.mobeta.android.dslv.DragSortListView; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.ImageLoader; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.storage.DBTasks; +import de.danoeh.antennapod.storage.DBWriter; import de.danoeh.antennapod.util.UndoBarController; +import java.util.List; + public class OrganizeQueueActivity extends SherlockListActivity implements UndoBarController.UndoListener { private static final String TAG = "OrganizeQueueActivity"; private static final int MENU_ID_ACCEPT = 2; + private List<FeedItem> queue; + private OrganizeAdapter adapter; private UndoBarController undoBarController; @@ -45,13 +50,37 @@ public class OrganizeQueueActivity extends SherlockListActivity implements listView.setDropListener(dropListener); listView.setRemoveListener(removeListener); - adapter = new OrganizeAdapter(this); - setListAdapter(adapter); - + loadData(); undoBarController = new UndoBarController(findViewById(R.id.undobar), this); } + private void loadData() { + AsyncTask<Void, Void, List<FeedItem>> loadTask = new AsyncTask<Void, Void, List<FeedItem>>() { + + @Override + protected List<FeedItem> doInBackground(Void... voids) { + return DBReader.getQueue(OrganizeQueueActivity.this); + } + + @Override + protected void onPostExecute(List<FeedItem> feedItems) { + super.onPostExecute(feedItems); + if (feedItems != null) { + queue = feedItems; + if (adapter == null) { + adapter = new OrganizeAdapter(OrganizeQueueActivity.this); + setListAdapter(adapter); + } + adapter.notifyDataSetChanged(); + } else { + Log.e(TAG, "Queue was null"); + } + } + }; + loadTask.execute(); + } + @Override protected void onPause() { super.onPause(); @@ -61,8 +90,7 @@ public class OrganizeQueueActivity extends SherlockListActivity implements @Override protected void onStop() { super.onStop(); - FeedManager.getInstance().autodownloadUndownloadedItems( - getApplicationContext()); + DBTasks.autodownloadUndownloadedItems(getApplicationContext()); } @Override @@ -76,9 +104,7 @@ public class OrganizeQueueActivity extends SherlockListActivity implements @Override public void update(EventDistributor eventDistributor, Integer arg) { if (((EventDistributor.QUEUE_UPDATE | EventDistributor.FEED_LIST_UPDATE) & arg) != 0) { - if (adapter != null) { - adapter.notifyDataSetChanged(); - } + loadData(); } } }; @@ -87,9 +113,9 @@ public class OrganizeQueueActivity extends SherlockListActivity implements @Override public void drop(int from, int to) { - FeedManager manager = FeedManager.getInstance(); - manager.moveQueueItem(OrganizeQueueActivity.this, from, to, false); - adapter.notifyDataSetChanged(); + + DBWriter.moveQueueItem(OrganizeQueueActivity.this, from, to, true); + //adapter.notifyDataSetChanged(); } }; @@ -97,9 +123,8 @@ public class OrganizeQueueActivity extends SherlockListActivity implements @Override public void remove(int which) { - FeedManager manager = FeedManager.getInstance(); FeedItem item = (FeedItem) getListAdapter().getItem(which); - manager.removeQueueItem(OrganizeQueueActivity.this, item, false); + DBWriter.removeQueueItem(OrganizeQueueActivity.this, item.getId(), true); undoBarController.showUndoBar(false, getString(R.string.removed_from_queue), new UndoToken(item, which)); @@ -127,22 +152,18 @@ public class OrganizeQueueActivity extends SherlockListActivity implements public void onUndo(Parcelable token) { // Perform the undo UndoToken undoToken = (UndoToken) token; - FeedItem feedItem = undoToken.getFeedItem(); + long itemId = undoToken.getFeedItemId(); int position = undoToken.getPosition(); - - FeedManager manager = FeedManager.getInstance(); - manager.addQueueItemAt(OrganizeQueueActivity.this, feedItem, position, - false); + DBWriter.addQueueItemAt(OrganizeQueueActivity.this, itemId, position, false); } private static class OrganizeAdapter extends BaseAdapter { - private Context context; - private FeedManager manager = FeedManager.getInstance(); + private OrganizeQueueActivity organizeQueueActivity; - public OrganizeAdapter(Context context) { + public OrganizeAdapter(OrganizeQueueActivity organizeQueueActivity) { super(); - this.context = context; + this.organizeQueueActivity = organizeQueueActivity; } @Override @@ -152,7 +173,7 @@ public class OrganizeQueueActivity extends SherlockListActivity implements if (convertView == null) { holder = new Holder(); - LayoutInflater inflater = (LayoutInflater) context + LayoutInflater inflater = (LayoutInflater) organizeQueueActivity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate( R.layout.organize_queue_listitem, null); @@ -189,13 +210,20 @@ public class OrganizeQueueActivity extends SherlockListActivity implements @Override public int getCount() { - int queueSize = manager.getQueueSize(true); - return queueSize; + if (organizeQueueActivity.queue != null) { + return organizeQueueActivity.queue.size(); + } else { + return 0; + } } @Override public FeedItem getItem(int position) { - return manager.getQueueItemAtIndex(position, true); + if (organizeQueueActivity.queue != null) { + return organizeQueueActivity.queue.get(position); + } else { + return null; + } } @Override @@ -211,7 +239,6 @@ public class OrganizeQueueActivity extends SherlockListActivity implements private int position; public UndoToken(FeedItem item, int position) { - FeedManager manager = FeedManager.getInstance(); this.itemId = item.getId(); this.feedId = item.getFeed().getId(); this.position = position; @@ -243,9 +270,8 @@ public class OrganizeQueueActivity extends SherlockListActivity implements out.writeInt(position); } - public FeedItem getFeedItem() { - FeedManager manager = FeedManager.getInstance(); - return manager.getFeedItem(itemId, feedId); + public long getFeedItemId() { + return itemId; } public int getPosition() { diff --git a/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java b/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java index 1a5a2cac9..9730c805c 100644 --- a/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java +++ b/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java @@ -14,6 +14,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBWriter; public class PlaybackHistoryActivity extends SherlockFragmentActivity { private static final String TAG = "PlaybackHistoryActivity"; @@ -36,7 +37,7 @@ public class PlaybackHistoryActivity extends SherlockFragmentActivity { startActivity(intent); return true; case R.id.clear_history_item: - FeedManager.getInstance().clearPlaybackHistory(this); + DBWriter.clearPlaybackHistory(this); return true; } return super.onOptionsItemSelected(item); |