diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2013-08-16 11:14:01 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2013-08-16 11:14:01 -0400 |
commit | 82bdfe05ac9ced9ffff2469e8ec1dacf88a3f166 (patch) | |
tree | 1943278704d17b88cf4d2c61fca618c743ce55af /src | |
parent | 07277b2fef6dcb1470ef18c55947b50ed710a7d5 (diff) | |
parent | 3994d02ddfb52a4418951a22bb72f55f85a76fbb (diff) | |
download | AntennaPod-82bdfe05ac9ced9ffff2469e8ec1dacf88a3f166.zip |
Merge branch 'develop' of https://github.com/danieloeh/AntennaPod into move-to-top
Diffstat (limited to 'src')
15 files changed, 85 insertions, 97 deletions
diff --git a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java index 949834596..5e48371b8 100644 --- a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java +++ b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java @@ -37,7 +37,7 @@ public class DownloadLogActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); - listview = (ListView) findViewById(R.layout.listview_activity); + listview = (ListView) findViewById(R.id.listview); dla = new DownloadLogAdapter(this, itemAccess); listview.setAdapter(dla); diff --git a/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java b/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java index c53a4cc7b..ee4e39b9d 100644 --- a/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java +++ b/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java @@ -7,6 +7,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.TypedArray; +import android.media.AudioManager; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentManager; @@ -57,6 +58,7 @@ public class FeedItemlistActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.feeditemlist_activity); + setVolumeControlStream(AudioManager.STREAM_MUSIC); long feedId = getIntent().getLongExtra( FeedlistFragment.EXTRA_SELECTED_FEED, -1); diff --git a/src/de/danoeh/antennapod/activity/ItemviewActivity.java b/src/de/danoeh/antennapod/activity/ItemviewActivity.java index 4c0fdfdba..c2833760d 100644 --- a/src/de/danoeh/antennapod/activity/ItemviewActivity.java +++ b/src/de/danoeh/antennapod/activity/ItemviewActivity.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.activity; +import android.media.AudioManager; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentManager; @@ -45,6 +46,7 @@ public class ItemviewActivity extends ActionBarActivity { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); getSupportActionBar().setDisplayShowTitleEnabled(false); EventDistributor.getInstance().register(contentUpdate); + setVolumeControlStream(AudioManager.STREAM_MUSIC); long itemId = getIntent().getLongExtra( ItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1); diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index 20c53553b..447a436cf 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -6,6 +6,7 @@ import android.app.SearchManager; import android.app.SearchableInfo; import android.content.Context; import android.content.Intent; +import android.media.AudioManager; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; @@ -55,8 +56,9 @@ public class MainActivity extends ActionBarActivity { StorageUtils.checkStorageAvailability(this); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.main); + setVolumeControlStream(AudioManager.STREAM_MUSIC); - getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); viewpager = (ViewPager) findViewById(R.id.viewpager); pagerAdapter = new TabsAdapter(this, viewpager); diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java index b5b694995..24c92fbbb 100644 --- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -4,6 +4,7 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.PixelFormat; +import android.media.AudioManager; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; @@ -143,8 +144,9 @@ public abstract class MediaplayerActivity extends ActionBarActivity if (AppConfig.DEBUG) Log.d(TAG, "Creating Activity"); StorageUtils.checkStorageAvailability(this); + setVolumeControlStream(AudioManager.STREAM_MUSIC); - orientation = getResources().getConfiguration().orientation; + orientation = getResources().getConfiguration().orientation; 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 77dae303e..e376b08b8 100644 --- a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java +++ b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java @@ -51,6 +51,7 @@ public class OrganizeQueueActivity extends ActionBarActivity implements listView = (DragSortListView) findViewById(android.R.id.list); listView.setDropListener(dropListener); listView.setRemoveListener(removeListener); + listView.setEmptyView(findViewById(android.R.id.empty)); loadData(); undoBarController = new UndoBarController(findViewById(R.id.undobar), @@ -155,9 +156,11 @@ public class OrganizeQueueActivity extends ActionBarActivity implements public void onUndo(Parcelable token) { // Perform the undo UndoToken undoToken = (UndoToken) token; - long itemId = undoToken.getFeedItemId(); - int position = undoToken.getPosition(); - DBWriter.addQueueItemAt(OrganizeQueueActivity.this, itemId, position, false); + if (token != null) { + long itemId = undoToken.getFeedItemId(); + int position = undoToken.getPosition(); + DBWriter.addQueueItemAt(OrganizeQueueActivity.this, itemId, position, false); + } } private static class OrganizeAdapter extends BaseAdapter { diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 9cee1a86a..34505dda9 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -314,13 +314,6 @@ public class Feed extends FeedFile { this.items = list; } - /** - * Returns an array that contains all the feeditems of this feed. - */ - public FeedItem[] getItemsArray() { - return items.toArray(new FeedItem[items.size()]); - } - public Date getLastUpdate() { return lastUpdate; } diff --git a/src/de/danoeh/antennapod/feed/FeedMedia.java b/src/de/danoeh/antennapod/feed/FeedMedia.java index 2e0eac7a4..f140a37e6 100644 --- a/src/de/danoeh/antennapod/feed/FeedMedia.java +++ b/src/de/danoeh/antennapod/feed/FeedMedia.java @@ -304,7 +304,7 @@ public class FeedMedia extends FeedFile implements Playable { @Override public void saveCurrentPosition(SharedPreferences pref, int newPosition) { position = newPosition; - DBWriter.setFeedMediaPosition(PodcastApp.getInstance(), this); + DBWriter.setFeedMediaPlaybackInformation(PodcastApp.getInstance(), this); } @Override diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index 3e8679bca..0e06e546e 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment; import java.util.List; import android.annotation.SuppressLint; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; @@ -29,9 +30,9 @@ import de.danoeh.antennapod.storage.FeedItemStatistics; import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; public class FeedlistFragment extends Fragment implements - ActionMode.Callback, AdapterView.OnItemClickListener, - AdapterView.OnItemLongClickListener { - private static final String TAG = "FeedlistFragment"; + ActionMode.Callback, AdapterView.OnItemClickListener, + AdapterView.OnItemLongClickListener { + private static final String TAG = "FeedlistFragment"; private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOAD_QUEUED @@ -94,12 +95,16 @@ public class FeedlistFragment extends Fragment implements AsyncTask<Void, Void, List[]> loadTask = new AsyncTask<Void, Void, List[]>() { @Override protected List[] doInBackground(Void... params) { - return new List[]{DBReader.getFeedList(getActivity()), - DBReader.getFeedStatisticsList(getActivity())}; + Context context = getActivity(); + if (context != null) { + return new List[]{DBReader.getFeedList(context), + DBReader.getFeedStatisticsList(context)}; + } else { + return null; + } } - @Override protected void onPostExecute(List[] result) { super.onPostExecute(result); @@ -160,9 +165,14 @@ public class FeedlistFragment extends Fragment implements } @Override + public void onDestroy() { + super.onDestroy(); + EventDistributor.getInstance().unregister(contentUpdate); + } + + @Override public void onPause() { super.onPause(); - EventDistributor.getInstance().unregister(contentUpdate); if (mActionMode != null) { mActionMode.finish(); } diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index 2056efab2..c84a6f913 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -561,7 +561,7 @@ public class DownloadService extends Service { Log.d(TAG, numberOfDownloads.get() + " downloads left"); } - if (numberOfDownloads.get() <= 0) { + if (numberOfDownloads.get() <= 0 && DownloadRequester.getInstance().hasNoDownloads()) { if (AppConfig.DEBUG) Log.d(TAG, "Number of downloads is " + numberOfDownloads.get() + ", attempting shutdown"); stopSelf(); @@ -647,28 +647,21 @@ public class DownloadService extends Service { Log.d(TAG, "Feed has image; Downloading...."); savedFeed.getImage().setFeed(savedFeed); final Feed savedFeedRef = savedFeed; - handler.post(new Runnable() { - - @Override - public void run() { - try { - requester.downloadImage(DownloadService.this, - savedFeedRef.getImage()); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DBWriter.addDownloadStatus( - DownloadService.this, - new DownloadStatus( - savedFeedRef.getImage(), - savedFeedRef - .getImage() - .getHumanReadableIdentifier(), - DownloadError.ERROR_REQUEST_ERROR, - false, e.getMessage())); - } - } - }); - + try { + requester.downloadImage(DownloadService.this, + savedFeedRef.getImage()); + } catch (DownloadRequestException e) { + e.printStackTrace(); + DBWriter.addDownloadStatus( + DownloadService.this, + new DownloadStatus( + savedFeedRef.getImage(), + savedFeedRef + .getImage() + .getHumanReadableIdentifier(), + DownloadError.ERROR_REQUEST_ERROR, + false, e.getMessage())); + } } } catch (SAXException e) { @@ -730,7 +723,7 @@ public class DownloadService extends Service { } private boolean hasValidFeedItems(Feed feed) { - for (FeedItem item : feed.getItemsArray()) { + for (FeedItem item : feed.getItems()) { if (item.getTitle() == null) { Log.e(TAG, "Item has no title"); return false; diff --git a/src/de/danoeh/antennapod/storage/DBWriter.java b/src/de/danoeh/antennapod/storage/DBWriter.java index 4b0dd9c2d..9946783e9 100644 --- a/src/de/danoeh/antennapod/storage/DBWriter.java +++ b/src/de/danoeh/antennapod/storage/DBWriter.java @@ -73,7 +73,10 @@ public class DBWriter { } media.setDownloaded(false); media.setFile_url(null); - setFeedMedia(context, media); + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + adapter.setMedia(media); + adapter.close(); // If media is currently being played, change playback // type to 'stream' and shutdown playback service @@ -688,18 +691,18 @@ public class DBWriter { } /** - * Saves only value of the 'position'-attribute of a FeedMedia object. + * Saves the 'position' and 'duration' attributes of a FeedMedia object * * @param context A context that is used for opening a database connection. * @param media The FeedMedia object. */ - public static Future<?> setFeedMediaPosition(final Context context, final FeedMedia media) { + public static Future<?> setFeedMediaPlaybackInformation(final Context context, final FeedMedia media) { return dbExec.submit(new Runnable() { @Override public void run() { PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); - adapter.setFeedMediaPosition(media); + adapter.setFeedMediaPlaybackInformation(media); adapter.close(); } }); diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java index edcbe1cf4..78b4c6daa 100644 --- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java +++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java @@ -361,6 +361,7 @@ public class PodDBAdapter { values.put(KEY_DOWNLOAD_URL, media.getDownload_url()); values.put(KEY_DOWNLOADED, media.isDownloaded()); values.put(KEY_FILE_URL, media.getFile_url()); + if (media.getPlaybackCompletionDate() != null) { values.put(KEY_PLAYBACK_COMPLETION_DATE, media .getPlaybackCompletionDate().getTime()); @@ -379,14 +380,15 @@ public class PodDBAdapter { return media.getId(); } - public void setFeedMediaPosition(FeedMedia media) { + public void setFeedMediaPlaybackInformation(FeedMedia media) { if (media.getId() != 0) { ContentValues values = new ContentValues(); values.put(KEY_POSITION, media.getPosition()); + values.put(KEY_DURATION, media.getDuration()); db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?", new String[]{String.valueOf(media.getId())}); } else { - Log.e(TAG, "setFeedMediaPosition: ID of media was 0"); + Log.e(TAG, "setFeedMediaPlaybackInformation: ID of media was 0"); } } @@ -397,8 +399,10 @@ public class PodDBAdapter { public void setCompleteFeed(Feed feed) { db.beginTransaction(); setFeed(feed); - for (FeedItem item : feed.getItemsArray()) { - setFeedItem(item); + if (feed.getItems() != null) { + for (FeedItem item : feed.getItems()) { + setFeedItem(item, false); + } } db.setTransactionSuccessful(); db.endTransaction(); @@ -407,7 +411,7 @@ public class PodDBAdapter { public void setFeedItemlist(List<FeedItem> items) { db.beginTransaction(); for (FeedItem item : items) { - setFeedItem(item); + setFeedItem(item, true); } db.setTransactionSuccessful(); db.endTransaction(); @@ -415,7 +419,7 @@ public class PodDBAdapter { public long setSingleFeedItem(FeedItem item) { db.beginTransaction(); - long result = setFeedItem(item); + long result = setFeedItem(item, true); db.setTransactionSuccessful(); db.endTransaction(); return result; @@ -423,10 +427,12 @@ public class PodDBAdapter { /** * Inserts or updates a feeditem entry - * + * @param item The FeedItem + * @param saveFeed true if the Feed of the item should also be saved. This should be set to + * false if the method is executed on a list of FeedItems of the same Feed. * @return the id of the entry */ - private long setFeedItem(FeedItem item) { + private long setFeedItem(FeedItem item, boolean saveFeed) { ContentValues values = new ContentValues(); values.put(KEY_TITLE, item.getTitle()); values.put(KEY_LINK, item.getLink()); @@ -438,7 +444,7 @@ public class PodDBAdapter { } values.put(KEY_PUBDATE, item.getPubDate().getTime()); values.put(KEY_PAYMENT_LINK, item.getPaymentLink()); - if (item.getFeed() != null) { + if (saveFeed && item.getFeed() != null) { setFeed(item.getFeed()); } values.put(KEY_FEED, item.getFeed().getId()); @@ -603,8 +609,10 @@ public class PodDBAdapter { if (feed.getImage() != null) { removeFeedImage(feed.getImage()); } - for (FeedItem item : feed.getItemsArray()) { - removeFeedItem(item); + if (feed.getItems() != null) { + for (FeedItem item : feed.getItems()) { + removeFeedItem(item); + } } db.delete(TABLE_NAME_FEEDS, KEY_ID + "=?", new String[]{String.valueOf(feed.getId())}); diff --git a/src/de/danoeh/antennapod/util/QueueAccess.java b/src/de/danoeh/antennapod/util/QueueAccess.java index ce9d11429..7a1c7fef2 100644 --- a/src/de/danoeh/antennapod/util/QueueAccess.java +++ b/src/de/danoeh/antennapod/util/QueueAccess.java @@ -51,9 +51,8 @@ public abstract class QueueAccess { if (items == null) { return false; } - Iterator<FeedItem> it = items.iterator(); - for (FeedItem i = it.next(); it.hasNext(); i = it.next()) { - if (i.getId() == id) { + for (FeedItem item : items) { + if (item.getId() == id) { return true; } } @@ -63,8 +62,10 @@ public abstract class QueueAccess { @Override public boolean remove(long id) { Iterator<FeedItem> it = items.iterator(); - for (FeedItem i = it.next(); it.hasNext(); i = it.next()) { - if (i.getId() == id) { + FeedItem item; + while (it.hasNext()) { + item = it.next(); + if (item.getId() == id) { it.remove(); return true; } diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBWriterTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBWriterTest.java index dbec84370..1c20d5342 100644 --- a/src/instrumentationTest/de/test/antennapod/storage/DBWriterTest.java +++ b/src/instrumentationTest/de/test/antennapod/storage/DBWriterTest.java @@ -84,37 +84,6 @@ public class DBWriterTest extends InstrumentationTestCase { assertNull(media.getFile_url()); } - public void testDeleteFeedMediaOfItemFileDoesNotExists() throws IOException, ExecutionException, InterruptedException { - File dest = new File(getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER), "testFile"); - - Feed feed = new Feed("url", new Date(), "title"); - List<FeedItem> items = new ArrayList<FeedItem>(); - feed.setItems(items); - FeedItem item = new FeedItem(); - item.setTitle("title"); - item.setPubDate(new Date()); - item.setFeed(feed); - - FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", dest.getAbsolutePath(), "download_url", false, null); - item.setMedia(media); - - items.add(item); - - PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext()); - adapter.open(); - adapter.setCompleteFeed(feed); - adapter.close(); - assertTrue(media.getId() != 0); - assertTrue(item.getId() != 0); - - DBWriter.deleteFeedMediaOfItem(getInstrumentation().getTargetContext(), media.getId()).get(); - media = DBReader.getFeedMedia(getInstrumentation().getTargetContext(), media.getId()); - assertNotNull(media); - assertFalse(dest.exists()); - assertFalse(media.isDownloaded()); - assertNull(media.getFile_url()); - } - public void testDeleteFeed() throws IOException, ExecutionException, InterruptedException, TimeoutException { File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER); assertNotNull(destFolder); diff --git a/src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java b/src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java index 030df0fcb..95c3a3dba 100644 --- a/src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java +++ b/src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java @@ -124,7 +124,7 @@ public class FeedHandlerTest extends AndroidTestCase { } private boolean hasValidFeedItems(Feed feed) { - for (FeedItem item : feed.getItemsArray()) { + for (FeedItem item : feed.getItems()) { if (item.getTitle() == null) { Log.e(TAG, "Item has no title"); return false; |