Merge branch 'develop' of https://github.com/danieloeh/AntennaPod into move-to-top

This commit is contained in:
Tom Hennen 2013-08-16 11:14:01 -04:00
commit 82bdfe05ac
18 changed files with 93 additions and 103 deletions

View File

@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.5'
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
apply plugin: 'android'

View File

@ -52,10 +52,12 @@
public static <fields>;
}
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-dontwarn android.support.v4.**
-dontwarn android.support.v7.**
-keepattributes *Annotation*

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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

View File

@ -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);
@ -159,10 +164,15 @@ public class FeedlistFragment extends Fragment implements
EventDistributor.getInstance().register(contentUpdate);
}
@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();
}

View File

@ -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;

View File

@ -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();
}
});

View File

@ -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())});

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

@ -1 +1 @@
Subproject commit c56bf97269d5dc90df1c428fd18df0e7619eff0e
Subproject commit 643cc2a1afd4f849d5a33f014f877f7d7c10b2db