From 658559699f5cd482bb19ade298db43a65d750664 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 11 Oct 2014 17:43:07 +0200 Subject: Moved core classes into subproject --- .../config/ApplicationCallbacksImpl.java | 23 +++++ .../antennapod/config/ClientConfigurator.java | 19 ++++ .../config/DownloadServiceCallbacksImpl.java | 49 ++++++++++ .../antennapod/config/FlattrCallbacksImpl.java | 53 ++++++++++ .../antennapod/config/GpodnetCallbacksImpl.java | 22 +++++ .../config/PlaybackServiceCallbacksImpl.java | 21 ++++ .../antennapod/config/StorageCallbacksImpl.java | 107 +++++++++++++++++++++ 7 files changed, 294 insertions(+) create mode 100644 app/src/main/java/de/danoeh/antennapod/config/ApplicationCallbacksImpl.java create mode 100644 app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java create mode 100644 app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java create mode 100644 app/src/main/java/de/danoeh/antennapod/config/FlattrCallbacksImpl.java create mode 100644 app/src/main/java/de/danoeh/antennapod/config/GpodnetCallbacksImpl.java create mode 100644 app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java create mode 100644 app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java (limited to 'app/src/main/java/de/danoeh/antennapod/config') diff --git a/app/src/main/java/de/danoeh/antennapod/config/ApplicationCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/ApplicationCallbacksImpl.java new file mode 100644 index 000000000..fdbb2139d --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/ApplicationCallbacksImpl.java @@ -0,0 +1,23 @@ +package de.danoeh.antennapod.config; + + +import android.app.Application; +import android.content.Context; +import android.content.Intent; + +import de.danoeh.antennapod.PodcastApp; +import de.danoeh.antennapod.activity.StorageErrorActivity; +import de.danoeh.antennapod.core.ApplicationCallbacks; + +public class ApplicationCallbacksImpl implements ApplicationCallbacks { + + @Override + public Application getApplicationInstance() { + return PodcastApp.getInstance(); + } + + @Override + public Intent getStorageErrorActivity(Context context) { + return new Intent(context, StorageErrorActivity.class); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java new file mode 100644 index 000000000..5dc3416c6 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java @@ -0,0 +1,19 @@ +package de.danoeh.antennapod.config; + +import de.danoeh.antennapod.core.ClientConfig; + +/** + * Configures the ClientConfig class of the core package. + */ +public class ClientConfigurator { + + static { + ClientConfig.USER_AGENT = "AntennaPod/0.9.9.3"; + ClientConfig.applicationCallbacks = new ApplicationCallbacksImpl(); + ClientConfig.downloadServiceCallbacks = new DownloadServiceCallbacksImpl(); + ClientConfig.gpodnetCallbacks = new GpodnetCallbacksImpl(); + ClientConfig.playbackServiceCallbacks = new PlaybackServiceCallbacksImpl(); + ClientConfig.storageCallbacks = new StorageCallbacksImpl(); + ClientConfig.flattrCallbacks = new FlattrCallbacksImpl(); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java new file mode 100644 index 000000000..0f180e9c5 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java @@ -0,0 +1,49 @@ +package de.danoeh.antennapod.config; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +import de.danoeh.antennapod.activity.DownloadAuthenticationActivity; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.adapter.NavListAdapter; +import de.danoeh.antennapod.core.DownloadServiceCallbacks; +import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.fragment.DownloadsFragment; + + +public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks { + + @Override + public PendingIntent getNotificationContentIntent(Context context) { + Intent intent = new Intent(context, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, NavListAdapter.VIEW_TYPE_NAV); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, MainActivity.POS_DOWNLOADS); + Bundle args = new Bundle(); + args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_RUNNING); + intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args); + + return PendingIntent.getActivity(context, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT); + } + + @Override + public PendingIntent getAuthentificationNotificationContentIntent(Context context, DownloadRequest request) { + final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class); + activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request); + activityIntent.putExtra(DownloadAuthenticationActivity.ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, true); + return PendingIntent.getActivity(context.getApplicationContext(), 0, activityIntent, PendingIntent.FLAG_ONE_SHOT); + } + + @Override + public PendingIntent getReportNotificationContentIntent(Context context) { + Intent intent = new Intent(context, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, NavListAdapter.VIEW_TYPE_NAV); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, MainActivity.POS_DOWNLOADS); + Bundle args = new Bundle(); + args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_LOG); + intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args); + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/FlattrCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/FlattrCallbacksImpl.java new file mode 100644 index 000000000..3817db6de --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/FlattrCallbacksImpl.java @@ -0,0 +1,53 @@ +package de.danoeh.antennapod.config; + + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import org.shredzone.flattr4j.oauth.AccessToken; + +import de.danoeh.antennapod.BuildConfig; +import de.danoeh.antennapod.activity.FlattrAuthActivity; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.core.FlattrCallbacks; + +public class FlattrCallbacksImpl implements FlattrCallbacks { + private static final String TAG = "FlattrCallbacksImpl"; + + @Override + public boolean flattrEnabled() { + return true; + } + + @Override + public Intent getFlattrAuthenticationActivityIntent(Context context) { + return new Intent(context, FlattrAuthActivity.class); + } + + @Override + public PendingIntent getFlattrFailedNotificationContentIntent(Context context) { + return PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); + } + + @Override + public String getFlattrAppKey() { + return BuildConfig.FLATTR_APP_KEY; + } + + @Override + public String getFlattrAppSecret() { + return BuildConfig.FLATTR_APP_SECRET; + } + + @Override + public void handleFlattrAuthenticationSuccess(AccessToken token) { + FlattrAuthActivity instance = FlattrAuthActivity.getInstance(); + if (instance != null) { + instance.handleAuthenticationSuccess(); + } else { + Log.e(TAG, "FlattrAuthActivity instance was null"); + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/GpodnetCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/GpodnetCallbacksImpl.java new file mode 100644 index 000000000..5f8da6894 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/GpodnetCallbacksImpl.java @@ -0,0 +1,22 @@ +package de.danoeh.antennapod.config; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; + +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.core.GpodnetCallbacks; + + +public class GpodnetCallbacksImpl implements GpodnetCallbacks { + @Override + public boolean gpodnetEnabled() { + return true; + } + + @Override + public PendingIntent getGpodnetSyncServiceErrorNotificationPendingIntent(Context context) { + return PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), + PendingIntent.FLAG_UPDATE_CURRENT); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java new file mode 100644 index 000000000..d1e3a8379 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java @@ -0,0 +1,21 @@ +package de.danoeh.antennapod.config; + +import android.content.Context; +import android.content.Intent; + +import de.danoeh.antennapod.activity.AudioplayerActivity; +import de.danoeh.antennapod.activity.VideoplayerActivity; +import de.danoeh.antennapod.core.PlaybackServiceCallbacks; +import de.danoeh.antennapod.core.feed.MediaType; + + +public class PlaybackServiceCallbacksImpl implements PlaybackServiceCallbacks { + @Override + public Intent getPlayerActivityIntent(Context context, MediaType mediaType) { + if (mediaType == MediaType.VIDEO) { + return new Intent(context, VideoplayerActivity.class); + } else { + return new Intent(context, AudioplayerActivity.class); + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java new file mode 100644 index 000000000..ec133aed1 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java @@ -0,0 +1,107 @@ +package de.danoeh.antennapod.config; + + +import android.content.ContentValues; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +import de.danoeh.antennapod.core.StorageCallbacks; +import de.danoeh.antennapod.core.storage.PodDBAdapter; + +public class StorageCallbacksImpl implements StorageCallbacks { + + @Override + public int getDatabaseVersion() { + return 12; + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w("DBAdapter", "Upgrading from version " + oldVersion + " to " + + newVersion + "."); + if (oldVersion <= 1) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + " ADD COLUMN " + + PodDBAdapter.KEY_TYPE + " TEXT"); + } + if (oldVersion <= 2) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_SIMPLECHAPTERS + + " ADD COLUMN " + PodDBAdapter.KEY_LINK + " TEXT"); + } + if (oldVersion <= 3) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + + " ADD COLUMN " + PodDBAdapter.KEY_ITEM_IDENTIFIER + " TEXT"); + } + if (oldVersion <= 4) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + " ADD COLUMN " + + PodDBAdapter.KEY_FEED_IDENTIFIER + " TEXT"); + } + if (oldVersion <= 5) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_DOWNLOAD_LOG + + " ADD COLUMN " + PodDBAdapter.KEY_REASON_DETAILED + " TEXT"); + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_DOWNLOAD_LOG + + " ADD COLUMN " + PodDBAdapter.KEY_DOWNLOADSTATUS_TITLE + " TEXT"); + } + if (oldVersion <= 6) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_SIMPLECHAPTERS + + " ADD COLUMN " + PodDBAdapter.KEY_CHAPTER_TYPE + " INTEGER"); + } + if (oldVersion <= 7) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA + + " ADD COLUMN " + PodDBAdapter.KEY_PLAYBACK_COMPLETION_DATE + + " INTEGER"); + } + if (oldVersion <= 8) { + final int KEY_ID_POSITION = 0; + final int KEY_MEDIA_POSITION = 1; + + // Add feeditem column to feedmedia table + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA + + " ADD COLUMN " + PodDBAdapter.KEY_FEEDITEM + + " INTEGER"); + Cursor feeditemCursor = db.query(PodDBAdapter.TABLE_NAME_FEED_ITEMS, + new String[]{PodDBAdapter.KEY_ID, PodDBAdapter.KEY_MEDIA}, "? > 0", + new String[]{PodDBAdapter.KEY_MEDIA}, null, null, null); + if (feeditemCursor.moveToFirst()) { + db.beginTransaction(); + ContentValues contentValues = new ContentValues(); + do { + long mediaId = feeditemCursor.getLong(KEY_MEDIA_POSITION); + contentValues.put(PodDBAdapter.KEY_FEEDITEM, feeditemCursor.getLong(KEY_ID_POSITION)); + db.update(PodDBAdapter.TABLE_NAME_FEED_MEDIA, contentValues, PodDBAdapter.KEY_ID + "=?", new String[]{String.valueOf(mediaId)}); + contentValues.clear(); + } while (feeditemCursor.moveToNext()); + db.setTransactionSuccessful(); + db.endTransaction(); + } + feeditemCursor.close(); + } + if (oldVersion <= 9) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_AUTO_DOWNLOAD + + " INTEGER DEFAULT 1"); + } + if (oldVersion <= 10) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_FLATTR_STATUS + + " INTEGER"); + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + + " ADD COLUMN " + PodDBAdapter.KEY_FLATTR_STATUS + + " INTEGER"); + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA + + " ADD COLUMN " + PodDBAdapter.KEY_PLAYED_DURATION + + " INTEGER"); + } + if (oldVersion <= 11) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_USERNAME + + " TEXT"); + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_PASSWORD + + " TEXT"); + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + + " ADD COLUMN " + PodDBAdapter.KEY_IMAGE + + " INTEGER"); + } + } +} -- cgit v1.2.3