Merge pull request #903 from mfietz/issue/898-store-has-embedded-picture
Store information if file has embedded picture in the database
This commit is contained in:
commit
7727caf9f4
@ -1,6 +1,7 @@
|
||||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -31,6 +32,7 @@ import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.adapter.NavListAdapter;
|
||||
import de.danoeh.antennapod.core.event.ProgressEvent;
|
||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.QueueEvent;
|
||||
@ -95,6 +97,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||
private CharSequence currentTitle;
|
||||
private String currentFragment;
|
||||
|
||||
private ProgressDialog pd;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(UserPreferences.getNoTitleTheme());
|
||||
@ -470,6 +474,9 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||
cancelLoadTask();
|
||||
EventDistributor.getInstance().unregister(contentUpdate);
|
||||
EventBus.getDefault().unregister(this);
|
||||
if(pd != null) {
|
||||
pd.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -573,6 +580,24 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||
loadData();
|
||||
}
|
||||
|
||||
public void onEventMainThread(ProgressEvent event) {
|
||||
Log.d(TAG, "onEvent(" + event + ")");
|
||||
switch(event.action) {
|
||||
case START:
|
||||
pd = new ProgressDialog(this);
|
||||
pd.setMessage(event.message);
|
||||
pd.setIndeterminate(true);
|
||||
pd.setCancelable(false);
|
||||
pd.show();
|
||||
break;
|
||||
case END:
|
||||
if(pd != null) {
|
||||
pd.dismiss();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ package de.danoeh.antennapod.config;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.util.Log;
|
||||
|
||||
import de.danoeh.antennapod.core.StorageCallbacks;
|
||||
@ -13,11 +14,11 @@ public class StorageCallbacksImpl implements StorageCallbacks {
|
||||
|
||||
@Override
|
||||
public int getDatabaseVersion() {
|
||||
return 15;
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onUpgrade(final SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.w("DBAdapter", "Upgrading from version " + oldVersion + " to "
|
||||
+ newVersion + ".");
|
||||
if (oldVersion <= 1) {
|
||||
@ -125,7 +126,6 @@ public class StorageCallbacksImpl implements StorageCallbacks {
|
||||
PodDBAdapter.KEY_CHAPTER_TYPE));
|
||||
}
|
||||
if(oldVersion <= 14) {
|
||||
|
||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_AUTO_DOWNLOAD + " INTEGER");
|
||||
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
|
||||
@ -137,7 +137,6 @@ public class StorageCallbacksImpl implements StorageCallbacks {
|
||||
|
||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_HIDE + " TEXT");
|
||||
|
||||
|
||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0");
|
||||
@ -149,5 +148,38 @@ public class StorageCallbacksImpl implements StorageCallbacks {
|
||||
db.execSQL(PodDBAdapter.CREATE_INDEX_QUEUE_FEEDITEM);
|
||||
db.execSQL(PodDBAdapter.CREATE_INDEX_SIMPLECHAPTERS_FEEDITEM);
|
||||
}
|
||||
if(oldVersion <= 15) {
|
||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_HAS_EMBEDDED_PICTURE + " INTEGER DEFAULT -1");
|
||||
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
|
||||
+ " SET " + PodDBAdapter.KEY_HAS_EMBEDDED_PICTURE + "=0"
|
||||
+ " WHERE " + PodDBAdapter.KEY_DOWNLOADED + "=0");
|
||||
Cursor c = db.rawQuery("SELECT " + PodDBAdapter.KEY_FILE_URL
|
||||
+ " FROM " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
|
||||
+ " WHERE " + PodDBAdapter.KEY_DOWNLOADED + "=1 "
|
||||
+ " AND " + PodDBAdapter.KEY_HAS_EMBEDDED_PICTURE + "=-1", null);
|
||||
if(c.moveToFirst()) {
|
||||
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
|
||||
do {
|
||||
String fileUrl = c.getString(0);
|
||||
try {
|
||||
mmr.setDataSource(fileUrl);
|
||||
byte[] image = mmr.getEmbeddedPicture();
|
||||
if (image != null) {
|
||||
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
|
||||
+ " SET " + PodDBAdapter.KEY_HAS_EMBEDDED_PICTURE + "=1"
|
||||
+ " WHERE " + PodDBAdapter.KEY_FILE_URL + "='"+ fileUrl + "'");
|
||||
} else {
|
||||
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
|
||||
+ " SET " + PodDBAdapter.KEY_HAS_EMBEDDED_PICTURE + "=0"
|
||||
+ " WHERE " + PodDBAdapter.KEY_FILE_URL + "='"+ fileUrl + "'");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while(c.moveToNext());
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package de.danoeh.antennapod.core.event;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
public class ProgressEvent {
|
||||
|
||||
public enum Action {
|
||||
START, END
|
||||
}
|
||||
|
||||
public final Action action;
|
||||
public final String message;
|
||||
|
||||
private ProgressEvent(Action action, String message) {
|
||||
this.action = action;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static ProgressEvent start(String message) {
|
||||
return new ProgressEvent(Action.START, message);
|
||||
}
|
||||
|
||||
public static ProgressEvent end() {
|
||||
return new ProgressEvent(Action.END, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
|
||||
.append("action", action)
|
||||
.append("message", message)
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
@ -35,6 +35,8 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||
private String mime_type;
|
||||
private volatile FeedItem item;
|
||||
private Date playbackCompletionDate;
|
||||
|
||||
// if null: unknown, will be checked
|
||||
private Boolean hasEmbeddedPicture;
|
||||
|
||||
/* Used for loading item when restoring from parcel. */
|
||||
@ -63,6 +65,15 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||
? null : (Date) playbackCompletionDate.clone();
|
||||
}
|
||||
|
||||
public FeedMedia(long id, FeedItem item, int duration, int position,
|
||||
long size, String mime_type, String file_url, String download_url,
|
||||
boolean downloaded, Date playbackCompletionDate, int played_duration,
|
||||
Boolean hasEmbeddedPicture) {
|
||||
this(id, item, duration, position, size, mime_type, file_url, download_url, downloaded,
|
||||
playbackCompletionDate, played_duration);
|
||||
this.hasEmbeddedPicture = hasEmbeddedPicture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableIdentifier() {
|
||||
if (item != null && item.getTitle() != null) {
|
||||
@ -429,6 +440,10 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setHasEmbeddedPicture(Boolean hasEmbeddedPicture) {
|
||||
this.hasEmbeddedPicture = hasEmbeddedPicture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDownloaded(boolean downloaded) {
|
||||
super.setDownloaded(downloaded);
|
||||
|
@ -1143,6 +1143,7 @@ public class DownloadService extends Service {
|
||||
boolean chaptersRead = false;
|
||||
media.setDownloaded(true);
|
||||
media.setFile_url(request.getDestination());
|
||||
media.setHasEmbeddedPicture(null);
|
||||
|
||||
// Get duration
|
||||
MediaMetadataRetriever mmr = null;
|
||||
|
@ -274,6 +274,18 @@ public final class DBReader {
|
||||
playbackCompletionDate = new Date(
|
||||
playbackCompletionTime);
|
||||
}
|
||||
Boolean hasEmbeddedPicture;
|
||||
switch(cursor.getInt(cursor.getColumnIndex(PodDBAdapter.KEY_HAS_EMBEDDED_PICTURE))) {
|
||||
case 1:
|
||||
hasEmbeddedPicture = Boolean.TRUE;
|
||||
break;
|
||||
case 0:
|
||||
hasEmbeddedPicture = Boolean.FALSE;
|
||||
break;
|
||||
default:
|
||||
hasEmbeddedPicture = null;
|
||||
break;
|
||||
}
|
||||
|
||||
return new FeedMedia(
|
||||
mediaId,
|
||||
@ -286,7 +298,8 @@ public final class DBReader {
|
||||
cursor.getString(PodDBAdapter.KEY_DOWNLOAD_URL_INDEX),
|
||||
cursor.getInt(PodDBAdapter.KEY_DOWNLOADED_INDEX) > 0,
|
||||
playbackCompletionDate,
|
||||
cursor.getInt(PodDBAdapter.KEY_PLAYED_DURATION_INDEX));
|
||||
cursor.getInt(PodDBAdapter.KEY_PLAYED_DURATION_INDEX),
|
||||
hasEmbeddedPicture);
|
||||
}
|
||||
|
||||
private static Feed extractFeedFromCursorRow(PodDBAdapter adapter,
|
||||
|
@ -100,6 +100,7 @@ public class DBWriter {
|
||||
}
|
||||
media.setDownloaded(false);
|
||||
media.setFile_url(null);
|
||||
media.setHasEmbeddedPicture(false);
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
adapter.setMedia(media);
|
||||
|
@ -19,6 +19,8 @@ import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.core.BuildConfig;
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.R;
|
||||
import de.danoeh.antennapod.core.event.ProgressEvent;
|
||||
import de.danoeh.antennapod.core.feed.Chapter;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedComponent;
|
||||
@ -29,6 +31,7 @@ import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.util.LongIntMap;
|
||||
import de.danoeh.antennapod.core.util.flattr.FlattrStatus;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
;
|
||||
|
||||
@ -155,6 +158,8 @@ public class PodDBAdapter {
|
||||
public static final String KEY_NEXT_PAGE_LINK = "next_page_link";
|
||||
public static final String KEY_HIDE = "hide";
|
||||
public static final String KEY_LAST_UPDATE_FAILED = "last_update_failed";
|
||||
public static final String KEY_HAS_EMBEDDED_PICTURE = "has_embedded_picture";
|
||||
|
||||
|
||||
// Table names
|
||||
public static final String TABLE_NAME_FEEDS = "Feeds";
|
||||
@ -209,7 +214,7 @@ public class PodDBAdapter {
|
||||
+ KEY_PLAYBACK_COMPLETION_DATE + " INTEGER,"
|
||||
+ KEY_FEEDITEM + " INTEGER,"
|
||||
+ KEY_PLAYED_DURATION + " INTEGER,"
|
||||
+ KEY_AUTO_DOWNLOAD + " INTEGER)";
|
||||
+ KEY_HAS_EMBEDDED_PICTURE + " INTEGER)";
|
||||
|
||||
public static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE "
|
||||
+ TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE
|
||||
@ -516,6 +521,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());
|
||||
values.put(KEY_HAS_EMBEDDED_PICTURE, media.hasEmbeddedPicture());
|
||||
|
||||
if (media.getPlaybackCompletionDate() != null) {
|
||||
values.put(KEY_PLAYBACK_COMPLETION_DATE, media
|
||||
@ -1463,6 +1469,9 @@ public class PodDBAdapter {
|
||||
* Helper class for opening the Antennapod database.
|
||||
*/
|
||||
private static class PodDBHelper extends SQLiteOpenHelper {
|
||||
|
||||
private Context context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -1474,6 +1483,7 @@ public class PodDBAdapter {
|
||||
public PodDBHelper(final Context context, final String name,
|
||||
final CursorFactory factory, final int version) {
|
||||
super(context, name, factory, version);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1497,7 +1507,9 @@ public class PodDBAdapter {
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion,
|
||||
final int newVersion) {
|
||||
EventBus.getDefault().post(ProgressEvent.start(context.getString(R.string.progress_upgrading_database)));
|
||||
ClientConfig.storageCallbacks.onUpgrade(db, oldVersion, newVersion);
|
||||
EventBus.getDefault().post(ProgressEvent.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -435,6 +435,10 @@
|
||||
<string name="authentication_label">Authentication</string>
|
||||
<string name="authentication_descr">Change your username and password for this podcast and its episodes.</string>
|
||||
|
||||
|
||||
<!-- Progress information -->
|
||||
<string name="progress_upgrading_database">Upgrading the database</string>
|
||||
|
||||
<!-- AntennaPodSP -->
|
||||
|
||||
<string name="sp_apps_importing_feeds_msg">Importing subscriptions from single-purpose apps…</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user