From 1b6459c8ee2dfcb40a4909aa87ff2ea100b8221e Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 19 Mar 2016 00:31:41 -0400 Subject: Include chromecast dependencies --- app/src/main/AndroidManifest.xml | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 005ba604f..55b70ed90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,6 +41,10 @@ android:name="com.google.android.backup.api_key" android:value="AEdPqrEAAAAI3a05VToCTlqBymJrbFGaKQMvF-bBAuLsOdavBA"/> + + Date: Sat, 19 Mar 2016 01:32:55 -0400 Subject: add chromecast support initialization logic and introduce chromecast preference --- .../danoeh/antennapod/config/CastCallbacksImpl.java | 20 ++++++++++++++++++++ .../danoeh/antennapod/config/ClientConfigurator.java | 1 + app/src/main/res/xml/preferences.xml | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 app/src/main/java/de/danoeh/antennapod/config/CastCallbacksImpl.java (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/config/CastCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/CastCallbacksImpl.java new file mode 100644 index 000000000..b92544201 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/config/CastCallbacksImpl.java @@ -0,0 +1,20 @@ +package de.danoeh.antennapod.config; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; + +import de.danoeh.antennapod.activity.AudioplayerActivity; +import de.danoeh.antennapod.core.CastCallbacks; + +public class CastCallbacksImpl implements CastCallbacks { + @Override + public Class getCastActivity() { + return AudioplayerActivity.class; + } + + @Override + public Intent getCastActivityIntent(Context context) { + return new Intent(context, getCastActivity()); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java index 932b9d22f..154b10cb3 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java +++ b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java @@ -16,5 +16,6 @@ public class ClientConfigurator { ClientConfig.playbackServiceCallbacks = new PlaybackServiceCallbacksImpl(); ClientConfig.flattrCallbacks = new FlattrCallbacksImpl(); ClientConfig.dbTasksCallbacks = new DBTasksCallbacksImpl(); + ClientConfig.castCallbacks = new CastCallbacksImpl(); } } diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index ecdcd3517..57829e3e1 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -293,5 +293,14 @@ android:key="prefAbout" android:title="@string/about_pref"/> + + + + -- cgit v1.2.3 From afbae2a7ef8b0466e8e89e82708c2fcb9f77ff35 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 19 Mar 2016 11:37:37 -0400 Subject: Create interface for PlaybackServiceMediaPlayer --- .../playback/PlaybackServiceMediaPlayerTest.java | 85 +++++++++++----------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'app') diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java index 7dac89e9b..7255d921f 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java @@ -20,14 +20,15 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.FeedPreferences; -import de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer; +import de.danoeh.antennapod.core.service.playback.IPlaybackServiceMediaPlayer; +import de.danoeh.antennapod.core.service.playback.LocalPSMP; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.playback.Playable; import de.test.antennapod.util.service.download.HTTPBin; /** - * Test class for PlaybackServiceMediaPlayer + * Test class for LocalPSMP */ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { private static final String TAG = "PlaybackServiceMediaPlayerTest"; @@ -85,7 +86,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { assertEquals(0, httpServer.serveFile(dest)); } - private void checkPSMPInfo(PlaybackServiceMediaPlayer.PSMPInfo info) { + private void checkPSMPInfo(LocalPSMP.PSMPInfo info) { try { switch (info.playerStatus) { case PLAYING: @@ -111,7 +112,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testInit() { final Context c = getInstrumentation().getTargetContext(); - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, defaultCallback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, defaultCallback); psmp.shutdown(); } @@ -137,9 +138,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamNoStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -200,7 +201,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, false, false); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -216,9 +217,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -278,7 +279,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, true, false); @@ -295,9 +296,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamNoStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(4); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -360,7 +361,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, false, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -375,9 +376,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(5); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -444,7 +445,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, true, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -458,9 +459,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalNoStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -521,7 +522,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, false, false); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -536,9 +537,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -598,7 +599,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, true, false); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -613,9 +614,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalNoStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(4); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -678,7 +679,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, false, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -692,9 +693,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(5); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) @@ -761,7 +762,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, true, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -773,9 +774,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } - private final PlaybackServiceMediaPlayer.PSMPCallback defaultCallback = new PlaybackServiceMediaPlayer.PSMPCallback() { + private final IPlaybackServiceMediaPlayer.PSMPCallback defaultCallback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); } @@ -823,9 +824,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { final int latchCount = (stream && reinit) ? 2 : 1; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) { if (assertionError == null) @@ -899,7 +900,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); if (initialState == PlayerStatus.PLAYING) { psmp.playMediaObject(p, stream, true, true); @@ -954,9 +955,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { (initialState == PlayerStatus.PREPARED) ? 1 : 0; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) { if (assertionError == null) @@ -1015,7 +1016,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); if (initialState == PlayerStatus.PREPARED || initialState == PlayerStatus.PLAYING || initialState == PlayerStatus.PAUSED) { boolean startWhenPrepared = (initialState != PlayerStatus.PREPARED); psmp.playMediaObject(writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL), false, startWhenPrepared, true); @@ -1047,9 +1048,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { final Context c = getInstrumentation().getTargetContext(); final int latchCount = 1; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) { if (assertionError == null) @@ -1106,7 +1107,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); if (initialState == PlayerStatus.INITIALIZED || initialState == PlayerStatus.PLAYING @@ -1152,9 +1153,9 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { final Context c = getInstrumentation().getTargetContext(); final int latchCount = 2; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { + IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { @Override - public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { + public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); if (newInfo.playerStatus == PlayerStatus.ERROR) { if (assertionError == null) @@ -1210,7 +1211,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - PlaybackServiceMediaPlayer psmp = new PlaybackServiceMediaPlayer(c, callback); + IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); boolean prepareImmediately = initialState != PlayerStatus.INITIALIZED; boolean startImmediately = initialState != PlayerStatus.PREPARED; -- cgit v1.2.3 From 6224f80c898e5cf78719e266fb719d424295ec83 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 19 Mar 2016 12:42:26 -0400 Subject: add cast button to important activities --- .../antennapod/activity/CastEnabledActivity.java | 97 ++++++++++++++++++++++ .../danoeh/antennapod/activity/MainActivity.java | 3 +- .../antennapod/activity/MediaplayerActivity.java | 3 +- app/src/main/res/menu/cast_enabled.xml | 11 +++ 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java create mode 100644 app/src/main/res/menu/cast_enabled.xml (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java new file mode 100644 index 000000000..497247ad4 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java @@ -0,0 +1,97 @@ +package de.danoeh.antennapod.activity; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; + +import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.preferences.UserPreferences; + +/** + * Activity that allows for showing the MediaRouter button whenever there's a cast device in the + * network. + */ +public abstract class CastEnabledActivity extends AppCompatActivity + implements SharedPreferences.OnSharedPreferenceChangeListener { + + protected VideoCastManager mCastManager; + private int castUICounter; + protected MenuItem mMediaRouteMenuItem; + protected boolean isCastEnabled; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + PreferenceManager.getDefaultSharedPreferences(this). + registerOnSharedPreferenceChangeListener(this); + + castUICounter = 0; + mCastManager = VideoCastManager.getInstance(); + isCastEnabled = UserPreferences.isCastEnabled(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + getMenuInflater().inflate(R.menu.cast_enabled, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + mMediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); + mMediaRouteMenuItem.setEnabled(isCastEnabled); + mMediaRouteMenuItem = mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item); + return true; + } + + @Override + protected void onResume() { + super.onResume(); + castUICounter++; + if (isCastEnabled) { + mCastManager.incrementUiCounter(); + castUICounter++; + } + } + + @Override + protected void onPause() { + super.onPause(); + castUICounter--; + if (isCastEnabled) { + mCastManager.decrementUiCounter(); + castUICounter--; + } + } + + //This whole method might just be useless because it's assumed that the cast button + //won't show where the user actually has the power to change the preference. + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(UserPreferences.PREF_CAST_ENABLED)) { + isCastEnabled = UserPreferences.isCastEnabled(); + mMediaRouteMenuItem.setEnabled(isCastEnabled); + if (isCastEnabled) { + //Test if activity is resumed but without UI counter incremented + if (castUICounter==1) { + mCastManager.incrementUiCounter(); + castUICounter++; + } + } else { + if (castUICounter > 1) { + mCastManager.decrementUiCounter(); + castUICounter--; + } + //TODO disable any current casting (or possibly do it within the PlaybackService) + } + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 8599eb4f4..beaea0fb9 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -17,7 +17,6 @@ import android.support.v4.app.FragmentTransaction; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.util.TypedValue; @@ -70,7 +69,7 @@ import rx.schedulers.Schedulers; /** * The activity that is shown when the user launches the app. */ -public class MainActivity extends AppCompatActivity implements NavDrawerActivity { +public class MainActivity extends CastEnabledActivity implements NavDrawerActivity { private static final String TAG = "MainActivity"; diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 4911f61bc..3f8cfc557 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -12,7 +12,6 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.view.ViewCompat; import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -58,7 +57,7 @@ import rx.schedulers.Schedulers; * Provides general features which are both needed for playing audio and video * files. */ -public abstract class MediaplayerActivity extends AppCompatActivity implements OnSeekBarChangeListener { +public abstract class MediaplayerActivity extends CastEnabledActivity implements OnSeekBarChangeListener { private static final String TAG = "MediaplayerActivity"; private static final String PREFS = "MediaPlayerActivityPreferences"; private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft"; diff --git a/app/src/main/res/menu/cast_enabled.xml b/app/src/main/res/menu/cast_enabled.xml new file mode 100644 index 000000000..f8135db2a --- /dev/null +++ b/app/src/main/res/menu/cast_enabled.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file -- cgit v1.2.3 From 88d47c178c033ab8e111e59ddeeda4e674f5b474 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sun, 20 Mar 2016 00:42:21 -0400 Subject: Make PlaybackServiceMediaPlayer an abstract class and move implementation independent methods inside it --- .../playback/PlaybackServiceMediaPlayerTest.java | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'app') diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java index 7255d921f..5b816ce0a 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java @@ -20,7 +20,7 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.FeedPreferences; -import de.danoeh.antennapod.core.service.playback.IPlaybackServiceMediaPlayer; +import de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer; import de.danoeh.antennapod.core.service.playback.LocalPSMP; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.PodDBAdapter; @@ -112,7 +112,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testInit() { final Context c = getInstrumentation().getTargetContext(); - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, defaultCallback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, defaultCallback); psmp.shutdown(); } @@ -138,7 +138,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamNoStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -201,7 +201,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, false, false); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -217,7 +217,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -279,7 +279,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, true, false); @@ -296,7 +296,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamNoStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(4); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -361,7 +361,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, false, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -376,7 +376,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectStreamStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(5); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -445,7 +445,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null); psmp.playMediaObject(p, true, true, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -459,7 +459,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalNoStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -522,7 +522,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, false, false); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -537,7 +537,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalStartNoPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(2); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -599,7 +599,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, true, false); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -614,7 +614,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalNoStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(4); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -679,7 +679,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, false, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -693,7 +693,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { public void testPlayMediaObjectLocalStartPrepare() throws InterruptedException { final Context c = getInstrumentation().getTargetContext(); final CountDownLatch countDownLatch = new CountDownLatch(5); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { try { @@ -762,7 +762,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); psmp.playMediaObject(p, false, true, true); boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -774,7 +774,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } - private final IPlaybackServiceMediaPlayer.PSMPCallback defaultCallback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + private final PlaybackServiceMediaPlayer.PSMPCallback defaultCallback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); @@ -824,7 +824,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { final int latchCount = (stream && reinit) ? 2 : 1; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); @@ -900,7 +900,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); if (initialState == PlayerStatus.PLAYING) { psmp.playMediaObject(p, stream, true, true); @@ -955,7 +955,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { (initialState == PlayerStatus.PREPARED) ? 1 : 0; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); @@ -1016,7 +1016,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); if (initialState == PlayerStatus.PREPARED || initialState == PlayerStatus.PLAYING || initialState == PlayerStatus.PAUSED) { boolean startWhenPrepared = (initialState != PlayerStatus.PREPARED); psmp.playMediaObject(writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL), false, startWhenPrepared, true); @@ -1048,7 +1048,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { final Context c = getInstrumentation().getTargetContext(); final int latchCount = 1; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); @@ -1107,7 +1107,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); if (initialState == PlayerStatus.INITIALIZED || initialState == PlayerStatus.PLAYING @@ -1153,7 +1153,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { final Context c = getInstrumentation().getTargetContext(); final int latchCount = 2; final CountDownLatch countDownLatch = new CountDownLatch(latchCount); - IPlaybackServiceMediaPlayer.PSMPCallback callback = new IPlaybackServiceMediaPlayer.PSMPCallback() { + PlaybackServiceMediaPlayer.PSMPCallback callback = new PlaybackServiceMediaPlayer.PSMPCallback() { @Override public void statusChanged(LocalPSMP.PSMPInfo newInfo) { checkPSMPInfo(newInfo); @@ -1211,7 +1211,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { return false; } }; - IPlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); + PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback); Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL); boolean prepareImmediately = initialState != PlayerStatus.INITIALIZED; boolean startImmediately = initialState != PlayerStatus.PREPARED; -- cgit v1.2.3 From 2057a92a19e76cdbf903f238f8faaa12001138b7 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Mon, 21 Mar 2016 22:08:58 -0400 Subject: Add the casting feature to PlaybackService --- app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java | 1 + 1 file changed, 1 insertion(+) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 3f8cfc557..dba4db334 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -207,6 +207,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements Log.d(TAG, "onCreate()"); StorageUtils.checkStorageAvailability(this); + //TODO we should most likely change this if casting setVolumeControlStream(AudioManager.STREAM_MUSIC); orientation = getResources().getConfiguration().orientation; -- cgit v1.2.3 From af7526a4099d739f2d668151ffa46d606493aea7 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Thu, 24 Mar 2016 01:59:37 -0400 Subject: add a CastManager, and other changes --- .../java/de/danoeh/antennapod/activity/CastEnabledActivity.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java index 497247ad4..0ce90eae3 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java @@ -7,9 +7,8 @@ import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; -import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; - import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.cast.CastManager; import de.danoeh.antennapod.core.preferences.UserPreferences; /** @@ -19,7 +18,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; public abstract class CastEnabledActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - protected VideoCastManager mCastManager; + protected CastManager mCastManager; private int castUICounter; protected MenuItem mMediaRouteMenuItem; protected boolean isCastEnabled; @@ -32,7 +31,7 @@ public abstract class CastEnabledActivity extends AppCompatActivity registerOnSharedPreferenceChangeListener(this); castUICounter = 0; - mCastManager = VideoCastManager.getInstance(); + mCastManager = CastManager.getInstance(); isCastEnabled = UserPreferences.isCastEnabled(); } -- cgit v1.2.3 From 037b705075a2af95042308c810b41b6dbff55b13 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 26 Mar 2016 00:45:50 -0400 Subject: * add GooglePlayServices check * implement wifi-reconnect feature for casting * move wifiLock logic to abstract PSMP --- .../antennapod/preferences/PreferenceController.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 23534e4f8..b8d721e26 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -34,6 +34,8 @@ import android.widget.Toast; import android.widget.ListView; import com.afollestad.materialdialogs.MaterialDialog; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.GoogleApiAvailability; import org.apache.commons.lang3.ArrayUtils; @@ -410,6 +412,22 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc ui.getActivity().startActivity(Intent.createChooser(emailIntent, intentTitle)); return true; }); + //checks whether Google Play Services is installed on the device (condition necessary for Cast support) + ui.findPreference(UserPreferences.PREF_CAST_ENABLED).setOnPreferenceChangeListener((preference, o) -> { + if (o instanceof Boolean && ((Boolean) o)) { + final int googlePlayServicesCheck = GoogleApiAvailability.getInstance() + .isGooglePlayServicesAvailable(ui.getActivity()); + if (googlePlayServicesCheck == ConnectionResult.SUCCESS) { + return true; + } else { + GoogleApiAvailability.getInstance() + .getErrorDialog(ui.getActivity(), googlePlayServicesCheck, 0) + .show(); + return false; + } + } + return true; + }); buildEpisodeCleanupPreference(); buildSmartMarkAsPlayedPreference(); buildAutodownloadSelectedNetworsPreference(); -- cgit v1.2.3 From 1088fae74506bbd9620fc0d3659976afbae6fcb2 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 26 Mar 2016 12:26:35 -0400 Subject: remove data channel from CastManager add cast failure strings --- app/src/main/res/menu/cast_enabled.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/res/menu/cast_enabled.xml b/app/src/main/res/menu/cast_enabled.xml index f8135db2a..25c10c88d 100644 --- a/app/src/main/res/menu/cast_enabled.xml +++ b/app/src/main/res/menu/cast_enabled.xml @@ -4,7 +4,7 @@ -- cgit v1.2.3 From e70f4d5389fc21fc00e3ecdda0e86f07873883ba Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Mon, 28 Mar 2016 03:34:07 -0400 Subject: fix media router button still showing when disabled --- .../antennapod/activity/CastEnabledActivity.java | 30 ++++++++++++++-------- app/src/main/res/menu/cast_enabled.xml | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java index 0ce90eae3..82cf0eed1 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java @@ -4,11 +4,12 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.Menu; -import android.view.MenuItem; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.cast.CastManager; +import de.danoeh.antennapod.core.cast.SwitchableMediaRouteActionProvider; import de.danoeh.antennapod.core.preferences.UserPreferences; /** @@ -17,17 +18,18 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; */ public abstract class CastEnabledActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { + public static final String TAG = "CastEnabledActivity"; protected CastManager mCastManager; - private int castUICounter; - protected MenuItem mMediaRouteMenuItem; - protected boolean isCastEnabled; + private volatile int castUICounter; + protected SwitchableMediaRouteActionProvider mMediaRouteActionProvider; + protected volatile boolean isCastEnabled; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - PreferenceManager.getDefaultSharedPreferences(this). + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()). registerOnSharedPreferenceChangeListener(this); castUICounter = 0; @@ -35,6 +37,13 @@ public abstract class CastEnabledActivity extends AppCompatActivity isCastEnabled = UserPreferences.isCastEnabled(); } + @Override + protected void onDestroy() { + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) + .unregisterOnSharedPreferenceChangeListener(this); + super.onDestroy(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); @@ -45,9 +54,9 @@ public abstract class CastEnabledActivity extends AppCompatActivity @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - mMediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); - mMediaRouteMenuItem.setEnabled(isCastEnabled); - mMediaRouteMenuItem = mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item); + mMediaRouteActionProvider = mCastManager + .addMediaRouterButton(menu.findItem(R.id.media_route_menu_item)); + mMediaRouteActionProvider.setEnabled(isCastEnabled); return true; } @@ -71,13 +80,12 @@ public abstract class CastEnabledActivity extends AppCompatActivity } } - //This whole method might just be useless because it's assumed that the cast button - //won't show where the user actually has the power to change the preference. @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(UserPreferences.PREF_CAST_ENABLED)) { isCastEnabled = UserPreferences.isCastEnabled(); - mMediaRouteMenuItem.setEnabled(isCastEnabled); + Log.d(TAG, "onSharedPreferenceChanged(), isCastEnabled set to " + isCastEnabled); + mMediaRouteActionProvider.setEnabled(isCastEnabled); if (isCastEnabled) { //Test if activity is resumed but without UI counter incremented if (castUICounter==1) { diff --git a/app/src/main/res/menu/cast_enabled.xml b/app/src/main/res/menu/cast_enabled.xml index 25c10c88d..676f3ea1e 100644 --- a/app/src/main/res/menu/cast_enabled.xml +++ b/app/src/main/res/menu/cast_enabled.xml @@ -6,6 +6,6 @@ android:id="@+id/media_route_menu_item" android:title="@string/cast_media_route_menu_title" android:enabled="false" - custom:actionProviderClass="android.support.v7.app.MediaRouteActionProvider" + custom:actionProviderClass="de.danoeh.antennapod.core.cast.SwitchableMediaRouteActionProvider" custom:showAsAction="always"/> \ No newline at end of file -- cgit v1.2.3 From b41eba90bdddfc23f9bf4c7204285ad975442f76 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Mon, 28 Mar 2016 22:43:22 -0400 Subject: implement basic cast session join --- .../main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java index 82cf0eed1..9177a1f1c 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java @@ -82,7 +82,7 @@ public abstract class CastEnabledActivity extends AppCompatActivity @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.equals(UserPreferences.PREF_CAST_ENABLED)) { + if (UserPreferences.PREF_CAST_ENABLED.equals(key)) { isCastEnabled = UserPreferences.isCastEnabled(); Log.d(TAG, "onSharedPreferenceChanged(), isCastEnabled set to " + isCastEnabled); mMediaRouteActionProvider.setEnabled(isCastEnabled); -- cgit v1.2.3 From 8a18adf50c85de94d6fab036f2066c1c4dd56e74 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 16 Apr 2016 10:23:40 -0400 Subject: disconnect cast session if user disables it in preferences and PlaybackService isn't running --- .../main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java index 9177a1f1c..dd7cef428 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastEnabledActivity.java @@ -11,6 +11,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.cast.CastManager; import de.danoeh.antennapod.core.cast.SwitchableMediaRouteActionProvider; import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.service.playback.PlaybackService; /** * Activity that allows for showing the MediaRouter button whenever there's a cast device in the @@ -97,7 +98,9 @@ public abstract class CastEnabledActivity extends AppCompatActivity mCastManager.decrementUiCounter(); castUICounter--; } - //TODO disable any current casting (or possibly do it within the PlaybackService) + if (!PlaybackService.isRunning) { + CastManager.getInstance().disconnect(); + } } } } -- cgit v1.2.3 From b3a78d47f945006070120c8dd12d3b5fdc2ad3be Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 16 Apr 2016 11:29:17 -0400 Subject: update PlaybackServiceCallbacks to be able to handle a cast player activity --- .../de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java index 997befe99..007799df7 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java +++ b/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java @@ -12,7 +12,11 @@ import de.danoeh.antennapod.core.feed.MediaType; public class PlaybackServiceCallbacksImpl implements PlaybackServiceCallbacks { @Override - public Intent getPlayerActivityIntent(Context context, MediaType mediaType) { + public Intent getPlayerActivityIntent(Context context, MediaType mediaType, boolean remotePlayback) { + if (remotePlayback) { + // TODO possibly switch to a proper cast activity + return new Intent(context, AudioplayerActivity.class); + } if (mediaType == MediaType.VIDEO) { return new Intent(context, VideoplayerActivity.class); } else { -- cgit v1.2.3 From 281db69d780daa1c7bb5aad2a87d92b7055d667a Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sun, 17 Apr 2016 02:06:32 -0400 Subject: separate audioplayeractivity into audio and cast activities --- .../antennapod/activity/AudioplayerActivity.java | 601 +------------------- .../antennapod/activity/CastplayerActivity.java | 10 + .../activity/MediaplayerInfoActivity.java | 614 +++++++++++++++++++++ .../antennapod/fragment/ChaptersFragment.java | 4 +- .../danoeh/antennapod/fragment/CoverFragment.java | 4 +- .../fragment/ExternalPlayerFragment.java | 1 + .../fragment/ItemDescriptionFragment.java | 10 +- 7 files changed, 636 insertions(+), 608 deletions(-) create mode 100644 app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java create mode 100644 app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index 292f3d9b6..bd8e43c4e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -1,165 +1,18 @@ package de.danoeh.antennapod.activity; -import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; -import android.support.annotation.Nullable; -import android.support.design.widget.AppBarLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.Log; -import android.util.TypedValue; -import android.view.ContextMenu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; -import com.viewpagerindicator.CirclePageIndicator; - -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.adapter.ChaptersListAdapter; -import de.danoeh.antennapod.adapter.NavListAdapter; -import de.danoeh.antennapod.core.asynctask.FeedRemover; -import de.danoeh.antennapod.core.dialog.ConfirmationDialog; -import de.danoeh.antennapod.core.feed.EventDistributor; -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; -import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.service.playback.PlayerStatus; -import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.playback.ExternalMedia; -import de.danoeh.antennapod.core.util.playback.Playable; -import de.danoeh.antennapod.core.util.playback.PlaybackController; -import de.danoeh.antennapod.fragment.AddFeedFragment; -import de.danoeh.antennapod.fragment.ChaptersFragment; -import de.danoeh.antennapod.fragment.CoverFragment; -import de.danoeh.antennapod.fragment.DownloadsFragment; -import de.danoeh.antennapod.fragment.EpisodesFragment; -import de.danoeh.antennapod.fragment.ItemDescriptionFragment; -import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; -import de.danoeh.antennapod.fragment.QueueFragment; -import de.danoeh.antennapod.fragment.SubscriptionFragment; -import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; -import rx.Observable; -import rx.Subscription; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; /** * Activity for playing audio files. */ -public class AudioplayerActivity extends MediaplayerActivity implements NavDrawerActivity { - - private static final int POS_COVER = 0; - private static final int POS_DESCR = 1; - private static final int POS_CHAPTERS = 2; - private static final int NUM_CONTENT_FRAGMENTS = 3; - - final String TAG = "AudioplayerActivity"; - private static final String PREFS = "AudioPlayerActivityPreferences"; - private static final String PREF_KEY_SELECTED_FRAGMENT_POSITION = "selectedFragmentPosition"; - - public static final String[] NAV_DRAWER_TAGS = { - QueueFragment.TAG, - EpisodesFragment.TAG, - SubscriptionFragment.TAG, - DownloadsFragment.TAG, - PlaybackHistoryFragment.TAG, - AddFeedFragment.TAG, - NavListAdapter.SUBSCRIPTION_LIST_TAG - }; - - private AtomicBoolean isSetup = new AtomicBoolean(false); - - private DrawerLayout drawerLayout; - private NavListAdapter navAdapter; - private ListView navList; - private View navDrawer; - private ActionBarDrawerToggle drawerToggle; - private int mPosition = -1; - - private Playable media; - private ViewPager pager; - private AudioplayerPagerAdapter pagerAdapter; - - private Subscription subscription; - - @Override - protected void onStop() { - super.onStop(); - Log.d(TAG, "onStop()"); - if(pagerAdapter != null) { - pagerAdapter.setController(null); - } - if(subscription != null) { - subscription.unsubscribe(); - } - EventDistributor.getInstance().unregister(contentUpdate); - saveCurrentFragment(); - } - - @Override - public void onDestroy() { - Log.d(TAG, "onDestroy()"); - super.onDestroy(); - // don't risk creating memory leaks - drawerLayout = null; - navAdapter = null; - navList = null; - navDrawer = null; - drawerToggle = null; - pager = null; - pagerAdapter = null; - } - - @Override - protected void chooseTheme() { - setTheme(UserPreferences.getNoTitleTheme()); - } - - private void saveCurrentFragment() { - if(pager == null) { - return; - } - Log.d(TAG, "Saving preferences"); - SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); - prefs.edit() - .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, pager.getCurrentItem()) - .commit(); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - if(drawerToggle != null) { - drawerToggle.onConfigurationChanged(newConfig); - } - } - - private void loadLastFragment() { - Log.d(TAG, "Restoring instance state"); - SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); - int lastPosition = prefs.getInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, -1); - pager.setCurrentItem(lastPosition); - } +public class AudioplayerActivity extends MediaplayerInfoActivity { + public static final String TAG = "AudioPlayerActivity"; @Override protected void onResume() { @@ -178,455 +31,5 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe true); startService(launchIntent); } - if(pagerAdapter != null && controller != null && controller.getMedia() != media) { - media = controller.getMedia(); - pagerAdapter.onMediaChanged(media); - pagerAdapter.setController(controller); - } - - EventDistributor.getInstance().register(contentUpdate); - loadData(); - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - setIntent(intent); - } - - @Override - protected void onAwaitingVideoSurface() { - Log.d(TAG, "onAwaitingVideoSurface was called in audio player -> switching to video player"); - startActivity(new Intent(this, VideoplayerActivity.class)); - } - - @Override - protected void postStatusMsg(int resId) { - if (resId == R.string.player_preparing_msg - || resId == R.string.player_seeking_msg - || resId == R.string.player_buffering_msg) { - // TODO Show progress bar here - } - } - - @Override - protected void clearStatusMsg() { - // TODO Hide progress bar here - } - - - @Override - protected void setupGUI() { - if(isSetup.getAndSet(true)) { - return; - } - super.setupGUI(); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setTitle(""); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - findViewById(R.id.shadow).setVisibility(View.GONE); - AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appBar); - float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); - appBarLayout.setElevation(px); - } - drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - navList = (ListView) findViewById(R.id.nav_list); - navDrawer = findViewById(R.id.nav_layout); - - drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); - drawerToggle.setDrawerIndicatorEnabled(false); - drawerLayout.setDrawerListener(drawerToggle); - - navAdapter = new NavListAdapter(itemAccess, this); - navList.setAdapter(navAdapter); - navList.setOnItemClickListener((parent, view, position, id) -> { - int viewType = parent.getAdapter().getItemViewType(position); - if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER) { - Intent intent = new Intent(AudioplayerActivity.this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_NAV_TYPE, viewType); - intent.putExtra(MainActivity.EXTRA_NAV_INDEX, position); - startActivity(intent); - } - drawerLayout.closeDrawer(navDrawer); - }); - navList.setOnItemLongClickListener((parent, view, position, id) -> { - if (position < navAdapter.getTags().size()) { - showDrawerPreferencesDialog(); - return true; - } else { - mPosition = position; - return false; - } - }); - registerForContextMenu(navList); - drawerToggle.syncState(); - - findViewById(R.id.nav_settings).setOnClickListener(v -> { - drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(AudioplayerActivity.this, PreferenceController.getPreferenceActivity())); - }); - - pager = (ViewPager) findViewById(R.id.pager); - pagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager(), media); - pagerAdapter.setController(controller); - pager.setAdapter(pagerAdapter); - CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator); - pageIndicator.setViewPager(pager); - loadLastFragment(); - pager.onSaveInstanceState(); - } - - @Override - protected void onPositionObserverUpdate() { - super.onPositionObserverUpdate(); - notifyMediaPositionChanged(); - } - - @Override - protected boolean loadMediaInfo() { - if (!super.loadMediaInfo()) { - return false; - } - if(controller.getMedia() != media) { - media = controller.getMedia(); - pagerAdapter.onMediaChanged(media); - } - return true; - } - - public void notifyMediaPositionChanged() { - if(pagerAdapter == null) { - return; - } - ChaptersFragment chaptersFragment = pagerAdapter.getChaptersFragment(); - if(chaptersFragment != null) { - ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter(); - if (adapter != null) { - adapter.notifyDataSetChanged(); - } - } - } - - @Override - protected void onReloadNotification(int notificationCode) { - if (notificationCode == PlaybackService.EXTRA_CODE_VIDEO) { - Log.d(TAG, "ReloadNotification received, switching to Videoplayer now"); - finish(); - startActivity(new Intent(this, VideoplayerActivity.class)); - - } - } - - @Override - protected void onBufferStart() { - postStatusMsg(R.string.player_buffering_msg); - } - - @Override - protected void onBufferEnd() { - clearStatusMsg(); - } - - public PlaybackController getPlaybackController() { - return controller; - } - - @Override - public boolean isDrawerOpen() { - return drawerLayout != null && navDrawer != null && drawerLayout.isDrawerOpen(navDrawer); - } - - @Override - protected int getContentViewResourceId() { - return R.layout.audioplayer_activity; - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - return drawerToggle != null && drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); - if(v.getId() != R.id.nav_list) { - return; - } - AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; - int position = adapterInfo.position; - if(position < navAdapter.getSubscriptionOffset()) { - return; - } - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.nav_feed_context, menu); - Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset()); - menu.setHeaderTitle(feed.getTitle()); - // episodes are not loaded, so we cannot check if the podcast has new or unplayed ones! - } - - @Override - public boolean onContextItemSelected(MenuItem item) { - final int position = mPosition; - mPosition = -1; // reset - if(position < 0) { - return false; - } - Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset()); - switch(item.getItemId()) { - case R.id.mark_all_seen_item: - DBWriter.markFeedSeen(feed.getId()); - return true; - case R.id.mark_all_read_item: - DBWriter.markFeedRead(feed.getId()); - return true; - case R.id.remove_item: - final FeedRemover remover = new FeedRemover(this, feed) { - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - } - }; - ConfirmationDialog conDialog = new ConfirmationDialog(this, - R.string.remove_feed_label, - R.string.feed_delete_confirmation_msg) { - @Override - public void onConfirmButtonPressed( - DialogInterface dialog) { - dialog.dismiss(); - if (controller != null) { - Playable playable = controller.getMedia(); - if (playable != null && playable instanceof FeedMedia) { - FeedMedia media = (FeedMedia) playable; - if (media.getItem().getFeed().getId() == feed.getId()) { - Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); - remover.skipOnCompletion = true; - if(controller.getStatus() == PlayerStatus.PLAYING) { - sendBroadcast(new Intent( - PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)); - } - } - } - } - remover.executeAsync(); - } - }; - conDialog.createNewDialog().show(); - return true; - default: - return super.onContextItemSelected(item); - } - } - - @Override - public void onBackPressed() { - if(isDrawerOpen()) { - drawerLayout.closeDrawer(navDrawer); - } else if (pager == null || pager.getCurrentItem() == 0) { - // If the user is currently looking at the first step, allow the system to handle the - // Back button. This calls finish() on this activity and pops the back stack. - super.onBackPressed(); - } else { - // Otherwise, select the previous step. - pager.setCurrentItem(pager.getCurrentItem() - 1); - } - } - - public void showDrawerPreferencesDialog() { - final List hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); - String[] navLabels = new String[NAV_DRAWER_TAGS.length]; - final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; - for (int i = 0; i < NAV_DRAWER_TAGS.length; i++) { - String tag = NAV_DRAWER_TAGS[i]; - navLabels[i] = navAdapter.getLabel(tag); - if (!hiddenDrawerItems.contains(tag)) { - checked[i] = true; - } - } - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.drawer_preferences); - builder.setMultiChoiceItems(navLabels, checked, (dialog, which, isChecked) -> { - if (isChecked) { - hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]); - } else { - hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]); - } - }); - builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { - UserPreferences.setHiddenDrawerItems(hiddenDrawerItems); - }); - builder.setNegativeButton(R.string.cancel_label, null); - builder.create().show(); - } - - private DBReader.NavDrawerData navDrawerData; - - private void loadData() { - subscription = Observable.fromCallable(DBReader::getNavDrawerData) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(result -> { - navDrawerData = result; - if (navAdapter != null) { - navAdapter.notifyDataSetChanged(); - } - }, error -> { - Log.e(TAG, Log.getStackTraceString(error)); - }); - } - - - - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EventDistributor.FEED_LIST_UPDATE & arg) != 0) { - Log.d(TAG, "Received contentUpdate Intent."); - loadData(); - } - } - }; - - private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { - @Override - public int getCount() { - if (navDrawerData != null) { - return navDrawerData.feeds.size(); - } else { - return 0; - } - } - - @Override - public Feed getItem(int position) { - if (navDrawerData != null && 0 <= position && position < navDrawerData.feeds.size()) { - return navDrawerData.feeds.get(position); - } else { - return null; - } - } - - @Override - public int getSelectedItemIndex() { - return -1; - } - - @Override - public int getQueueSize() { - return (navDrawerData != null) ? navDrawerData.queueSize : 0; - } - - @Override - public int getNumberOfNewItems() { - return (navDrawerData != null) ? navDrawerData.numNewItems : 0; - } - - @Override - public int getNumberOfDownloadedItems() { - return (navDrawerData != null) ? navDrawerData.numDownloadedItems : 0; - } - - @Override - public int getReclaimableItems() { - return (navDrawerData != null) ? navDrawerData.reclaimableSpace : 0; - } - - @Override - public int getFeedCounter(long feedId) { - return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; - } - - @Override - public int getFeedCounterSum() { - if(navDrawerData == null) { - return 0; - } - int sum = 0; - for(int counter : navDrawerData.feedCounters.values()) { - sum += counter; - } - return sum; - } - }; - - public interface AudioplayerContentFragment { - void onMediaChanged(Playable media); } - - private static class AudioplayerPagerAdapter extends FragmentStatePagerAdapter { - - private static final String TAG = "AudioplayerPagerAdapter"; - - private Playable media; - private PlaybackController controller; - - public AudioplayerPagerAdapter(FragmentManager fm, Playable media) { - super(fm); - this.media = media; - } - - private CoverFragment coverFragment; - private ItemDescriptionFragment itemDescriptionFragment; - private ChaptersFragment chaptersFragment; - - public void onMediaChanged(Playable media) { - this.media = media; - if(coverFragment != null) { - coverFragment.onMediaChanged(media); - } - if(itemDescriptionFragment != null) { - itemDescriptionFragment.onMediaChanged(media); - } - if(chaptersFragment != null) { - chaptersFragment.onMediaChanged(media); - } - } - - public void setController(PlaybackController controller) { - this.controller = controller; - if(chaptersFragment != null) { - chaptersFragment.setController(controller); - } - } - - @Nullable - public ChaptersFragment getChaptersFragment() { - return chaptersFragment; - } - - @Override - public Fragment getItem(int position) { - Log.d(TAG, "getItem(" + position + ")"); - switch (position) { - case POS_COVER: - if(coverFragment == null) { - coverFragment = CoverFragment.newInstance(media); - } - return coverFragment; - case POS_DESCR: - if(itemDescriptionFragment == null) { - itemDescriptionFragment = ItemDescriptionFragment.newInstance(media, true, true); - } - return itemDescriptionFragment; - case POS_CHAPTERS: - if(chaptersFragment == null) { - chaptersFragment = ChaptersFragment.newInstance(media); - chaptersFragment.setController(controller); - } - return chaptersFragment; - default: - return null; - } - } - - @Override - public int getCount() { - return NUM_CONTENT_FRAGMENTS; - } - } - } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java new file mode 100644 index 000000000..f15c96467 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java @@ -0,0 +1,10 @@ +package de.danoeh.antennapod.activity; + +/** + * Created by domingos on 4/16/16. + */ +public class CastplayerActivity extends MediaplayerInfoActivity { + public static final String TAG = "CastPlayerActivity"; + + +} diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java new file mode 100644 index 000000000..8b1643143 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -0,0 +1,614 @@ +package de.danoeh.antennapod.activity; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Build; +import android.support.annotation.Nullable; +import android.support.design.widget.AppBarLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.util.TypedValue; +import android.view.ContextMenu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; + +import com.viewpagerindicator.CirclePageIndicator; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.adapter.ChaptersListAdapter; +import de.danoeh.antennapod.adapter.NavListAdapter; +import de.danoeh.antennapod.core.asynctask.FeedRemover; +import de.danoeh.antennapod.core.dialog.ConfirmationDialog; +import de.danoeh.antennapod.core.feed.EventDistributor; +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.service.playback.PlayerStatus; +import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.core.util.playback.Playable; +import de.danoeh.antennapod.core.util.playback.PlaybackController; +import de.danoeh.antennapod.fragment.AddFeedFragment; +import de.danoeh.antennapod.fragment.ChaptersFragment; +import de.danoeh.antennapod.fragment.CoverFragment; +import de.danoeh.antennapod.fragment.DownloadsFragment; +import de.danoeh.antennapod.fragment.EpisodesFragment; +import de.danoeh.antennapod.fragment.ItemDescriptionFragment; +import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; +import de.danoeh.antennapod.fragment.QueueFragment; +import de.danoeh.antennapod.fragment.SubscriptionFragment; +import de.danoeh.antennapod.menuhandler.NavDrawerActivity; +import de.danoeh.antennapod.preferences.PreferenceController; +import rx.Observable; +import rx.Subscription; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + +/** + * Activity for playing files that do not require a video surface. + */ +public abstract class MediaplayerInfoActivity extends MediaplayerActivity implements NavDrawerActivity { + + private static final int POS_COVER = 0; + private static final int POS_DESCR = 1; + private static final int POS_CHAPTERS = 2; + private static final int NUM_CONTENT_FRAGMENTS = 3; + + final String TAG = "MediaplayerInfoActivity"; + private static final String PREFS = "AudioPlayerActivityPreferences"; + private static final String PREF_KEY_SELECTED_FRAGMENT_POSITION = "selectedFragmentPosition"; + + public static final String[] NAV_DRAWER_TAGS = { + QueueFragment.TAG, + EpisodesFragment.TAG, + SubscriptionFragment.TAG, + DownloadsFragment.TAG, + PlaybackHistoryFragment.TAG, + AddFeedFragment.TAG, + NavListAdapter.SUBSCRIPTION_LIST_TAG + }; + + private AtomicBoolean isSetup = new AtomicBoolean(false); + + private DrawerLayout drawerLayout; + private NavListAdapter navAdapter; + private ListView navList; + private View navDrawer; + private ActionBarDrawerToggle drawerToggle; + private int mPosition = -1; + + private Playable media; + private ViewPager pager; + private MediaplayerInfoPagerAdapter pagerAdapter; + + private Subscription subscription; + + @Override + protected void onStop() { + super.onStop(); + Log.d(TAG, "onStop()"); + if(pagerAdapter != null) { + pagerAdapter.setController(null); + } + if(subscription != null) { + subscription.unsubscribe(); + } + EventDistributor.getInstance().unregister(contentUpdate); + saveCurrentFragment(); + } + + @Override + public void onDestroy() { + Log.d(TAG, "onDestroy()"); + super.onDestroy(); + // don't risk creating memory leaks + drawerLayout = null; + navAdapter = null; + navList = null; + navDrawer = null; + drawerToggle = null; + pager = null; + pagerAdapter = null; + } + + @Override + protected void chooseTheme() { + setTheme(UserPreferences.getNoTitleTheme()); + } + + private void saveCurrentFragment() { + if(pager == null) { + return; + } + Log.d(TAG, "Saving preferences"); + SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); + prefs.edit() + .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, pager.getCurrentItem()) + .commit(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if(drawerToggle != null) { + drawerToggle.onConfigurationChanged(newConfig); + } + } + + private void loadLastFragment() { + Log.d(TAG, "Restoring instance state"); + SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); + int lastPosition = prefs.getInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, -1); + pager.setCurrentItem(lastPosition); + } + + @Override + protected void onResume() { + super.onResume(); + if(pagerAdapter != null && controller != null && controller.getMedia() != media) { + media = controller.getMedia(); + pagerAdapter.onMediaChanged(media); + pagerAdapter.setController(controller); + } + + EventDistributor.getInstance().register(contentUpdate); + loadData(); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); + } + + @Override + protected void onAwaitingVideoSurface() { + Log.d(TAG, "onAwaitingVideoSurface was called in audio player -> switching to video player"); + startActivity(new Intent(this, VideoplayerActivity.class)); + } + + @Override + protected void postStatusMsg(int resId) { + if (resId == R.string.player_preparing_msg + || resId == R.string.player_seeking_msg + || resId == R.string.player_buffering_msg) { + // TODO Show progress bar here + } + } + + @Override + protected void clearStatusMsg() { + // TODO Hide progress bar here + } + + + @Override + protected void setupGUI() { + if(isSetup.getAndSet(true)) { + return; + } + super.setupGUI(); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setTitle(""); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + findViewById(R.id.shadow).setVisibility(View.GONE); + AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appBar); + float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); + appBarLayout.setElevation(px); + } + drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + navList = (ListView) findViewById(R.id.nav_list); + navDrawer = findViewById(R.id.nav_layout); + + drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); + drawerToggle.setDrawerIndicatorEnabled(false); + drawerLayout.setDrawerListener(drawerToggle); + + navAdapter = new NavListAdapter(itemAccess, this); + navList.setAdapter(navAdapter); + navList.setOnItemClickListener((parent, view, position, id) -> { + int viewType = parent.getAdapter().getItemViewType(position); + if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER) { + Intent intent = new Intent(MediaplayerInfoActivity.this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, viewType); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, position); + startActivity(intent); + } + drawerLayout.closeDrawer(navDrawer); + }); + navList.setOnItemLongClickListener((parent, view, position, id) -> { + if (position < navAdapter.getTags().size()) { + showDrawerPreferencesDialog(); + return true; + } else { + mPosition = position; + return false; + } + }); + registerForContextMenu(navList); + drawerToggle.syncState(); + + findViewById(R.id.nav_settings).setOnClickListener(v -> { + drawerLayout.closeDrawer(navDrawer); + startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceController.getPreferenceActivity())); + }); + + pager = (ViewPager) findViewById(R.id.pager); + pagerAdapter = new MediaplayerInfoPagerAdapter(getSupportFragmentManager(), media); + pagerAdapter.setController(controller); + pager.setAdapter(pagerAdapter); + CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator); + pageIndicator.setViewPager(pager); + loadLastFragment(); + pager.onSaveInstanceState(); + } + + @Override + protected void onPositionObserverUpdate() { + super.onPositionObserverUpdate(); + notifyMediaPositionChanged(); + } + + @Override + protected boolean loadMediaInfo() { + if (!super.loadMediaInfo()) { + return false; + } + if(controller.getMedia() != media) { + media = controller.getMedia(); + pagerAdapter.onMediaChanged(media); + } + return true; + } + + public void notifyMediaPositionChanged() { + if(pagerAdapter == null) { + return; + } + ChaptersFragment chaptersFragment = pagerAdapter.getChaptersFragment(); + if(chaptersFragment != null) { + ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter(); + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } + } + + @Override + protected void onReloadNotification(int notificationCode) { + if (notificationCode == PlaybackService.EXTRA_CODE_VIDEO) { + Log.d(TAG, "ReloadNotification received, switching to Videoplayer now"); + finish(); + startActivity(new Intent(this, VideoplayerActivity.class)); + + } + } + + @Override + protected void onBufferStart() { + postStatusMsg(R.string.player_buffering_msg); + } + + @Override + protected void onBufferEnd() { + clearStatusMsg(); + } + + public PlaybackController getPlaybackController() { + return controller; + } + + @Override + public boolean isDrawerOpen() { + return drawerLayout != null && navDrawer != null && drawerLayout.isDrawerOpen(navDrawer); + } + + @Override + protected int getContentViewResourceId() { + return R.layout.mediaplayerinfo_activity; + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + return drawerToggle != null && drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + if(v.getId() != R.id.nav_list) { + return; + } + AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; + int position = adapterInfo.position; + if(position < navAdapter.getSubscriptionOffset()) { + return; + } + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.nav_feed_context, menu); + Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset()); + menu.setHeaderTitle(feed.getTitle()); + // episodes are not loaded, so we cannot check if the podcast has new or unplayed ones! + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + final int position = mPosition; + mPosition = -1; // reset + if(position < 0) { + return false; + } + Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset()); + switch(item.getItemId()) { + case R.id.mark_all_seen_item: + DBWriter.markFeedSeen(feed.getId()); + return true; + case R.id.mark_all_read_item: + DBWriter.markFeedRead(feed.getId()); + return true; + case R.id.remove_item: + final FeedRemover remover = new FeedRemover(this, feed) { + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + } + }; + ConfirmationDialog conDialog = new ConfirmationDialog(this, + R.string.remove_feed_label, + R.string.feed_delete_confirmation_msg) { + @Override + public void onConfirmButtonPressed( + DialogInterface dialog) { + dialog.dismiss(); + if (controller != null) { + Playable playable = controller.getMedia(); + if (playable != null && playable instanceof FeedMedia) { + FeedMedia media = (FeedMedia) playable; + if (media.getItem().getFeed().getId() == feed.getId()) { + Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); + remover.skipOnCompletion = true; + if(controller.getStatus() == PlayerStatus.PLAYING) { + sendBroadcast(new Intent( + PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)); + } + } + } + } + remover.executeAsync(); + } + }; + conDialog.createNewDialog().show(); + return true; + default: + return super.onContextItemSelected(item); + } + } + + @Override + public void onBackPressed() { + if(isDrawerOpen()) { + drawerLayout.closeDrawer(navDrawer); + } else if (pager == null || pager.getCurrentItem() == 0) { + // If the user is currently looking at the first step, allow the system to handle the + // Back button. This calls finish() on this activity and pops the back stack. + super.onBackPressed(); + } else { + // Otherwise, select the previous step. + pager.setCurrentItem(pager.getCurrentItem() - 1); + } + } + + public void showDrawerPreferencesDialog() { + final List hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); + String[] navLabels = new String[NAV_DRAWER_TAGS.length]; + final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; + for (int i = 0; i < NAV_DRAWER_TAGS.length; i++) { + String tag = NAV_DRAWER_TAGS[i]; + navLabels[i] = navAdapter.getLabel(tag); + if (!hiddenDrawerItems.contains(tag)) { + checked[i] = true; + } + } + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.drawer_preferences); + builder.setMultiChoiceItems(navLabels, checked, (dialog, which, isChecked) -> { + if (isChecked) { + hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]); + } else { + hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]); + } + }); + builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { + UserPreferences.setHiddenDrawerItems(hiddenDrawerItems); + }); + builder.setNegativeButton(R.string.cancel_label, null); + builder.create().show(); + } + + private DBReader.NavDrawerData navDrawerData; + + private void loadData() { + subscription = Observable.fromCallable(DBReader::getNavDrawerData) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + navDrawerData = result; + if (navAdapter != null) { + navAdapter.notifyDataSetChanged(); + } + }, error -> { + Log.e(TAG, Log.getStackTraceString(error)); + }); + } + + + + private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + + @Override + public void update(EventDistributor eventDistributor, Integer arg) { + if ((EventDistributor.FEED_LIST_UPDATE & arg) != 0) { + Log.d(TAG, "Received contentUpdate Intent."); + loadData(); + } + } + }; + + private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { + @Override + public int getCount() { + if (navDrawerData != null) { + return navDrawerData.feeds.size(); + } else { + return 0; + } + } + + @Override + public Feed getItem(int position) { + if (navDrawerData != null && 0 <= position && position < navDrawerData.feeds.size()) { + return navDrawerData.feeds.get(position); + } else { + return null; + } + } + + @Override + public int getSelectedItemIndex() { + return -1; + } + + @Override + public int getQueueSize() { + return (navDrawerData != null) ? navDrawerData.queueSize : 0; + } + + @Override + public int getNumberOfNewItems() { + return (navDrawerData != null) ? navDrawerData.numNewItems : 0; + } + + @Override + public int getNumberOfDownloadedItems() { + return (navDrawerData != null) ? navDrawerData.numDownloadedItems : 0; + } + + @Override + public int getReclaimableItems() { + return (navDrawerData != null) ? navDrawerData.reclaimableSpace : 0; + } + + @Override + public int getFeedCounter(long feedId) { + return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; + } + + @Override + public int getFeedCounterSum() { + if(navDrawerData == null) { + return 0; + } + int sum = 0; + for(int counter : navDrawerData.feedCounters.values()) { + sum += counter; + } + return sum; + } + }; + + public interface MediaplayerInfoContentFragment { + void onMediaChanged(Playable media); + } + + private static class MediaplayerInfoPagerAdapter extends FragmentStatePagerAdapter { + + private static final String TAG = "MPInfoPagerAdapter"; + + private Playable media; + private PlaybackController controller; + + public MediaplayerInfoPagerAdapter(FragmentManager fm, Playable media) { + super(fm); + this.media = media; + } + + private CoverFragment coverFragment; + private ItemDescriptionFragment itemDescriptionFragment; + private ChaptersFragment chaptersFragment; + + public void onMediaChanged(Playable media) { + this.media = media; + if(coverFragment != null) { + coverFragment.onMediaChanged(media); + } + if(itemDescriptionFragment != null) { + itemDescriptionFragment.onMediaChanged(media); + } + if(chaptersFragment != null) { + chaptersFragment.onMediaChanged(media); + } + } + + public void setController(PlaybackController controller) { + this.controller = controller; + if(chaptersFragment != null) { + chaptersFragment.setController(controller); + } + } + + @Nullable + public ChaptersFragment getChaptersFragment() { + return chaptersFragment; + } + + @Override + public Fragment getItem(int position) { + Log.d(TAG, "getItem(" + position + ")"); + switch (position) { + case POS_COVER: + if(coverFragment == null) { + coverFragment = CoverFragment.newInstance(media); + } + return coverFragment; + case POS_DESCR: + if(itemDescriptionFragment == null) { + itemDescriptionFragment = ItemDescriptionFragment.newInstance(media, true, true); + } + return itemDescriptionFragment; + case POS_CHAPTERS: + if(chaptersFragment == null) { + chaptersFragment = ChaptersFragment.newInstance(media); + chaptersFragment.setController(controller); + } + return chaptersFragment; + default: + return null; + } + } + + @Override + public int getCount() { + return NUM_CONTENT_FRAGMENTS; + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java index aea911f79..77e66f3b0 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java @@ -7,14 +7,14 @@ import android.view.View; import android.widget.ListView; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.AudioplayerActivity.AudioplayerContentFragment; +import de.danoeh.antennapod.activity.MediaplayerInfoActivity.MediaplayerInfoContentFragment; import de.danoeh.antennapod.adapter.ChaptersListAdapter; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -public class ChaptersFragment extends ListFragment implements AudioplayerContentFragment { +public class ChaptersFragment extends ListFragment implements MediaplayerInfoContentFragment { private static final String TAG = "ChaptersFragment"; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index d3b97f9df..943ddeec7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -12,14 +12,14 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.AudioplayerActivity.AudioplayerContentFragment; +import de.danoeh.antennapod.activity.MediaplayerInfoActivity.MediaplayerInfoContentFragment; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.playback.Playable; /** * Displays the cover and the title of a FeedItem. */ -public class CoverFragment extends Fragment implements AudioplayerContentFragment { +public class CoverFragment extends Fragment implements MediaplayerInfoContentFragment { private static final String TAG = "CoverFragment"; private static final String ARG_PLAYABLE = "arg.playable"; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index ca60e7bf2..49959ac26 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -172,6 +172,7 @@ public class ExternalPlayerFragment extends Fragment { .into(imgvCover); fragmentLayout.setVisibility(View.VISIBLE); + // TODO change this to show play button if connected to chromecast if (controller.isPlayingVideo()) { butPlay.setVisibility(View.GONE); } else { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 5b301333e..55d28cadb 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -27,8 +27,8 @@ import android.webkit.WebViewClient; import android.widget.Toast; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.AudioplayerActivity; -import de.danoeh.antennapod.activity.AudioplayerActivity.AudioplayerContentFragment; +import de.danoeh.antennapod.activity.MediaplayerInfoActivity; +import de.danoeh.antennapod.activity.MediaplayerInfoActivity.MediaplayerInfoContentFragment; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; @@ -47,7 +47,7 @@ import rx.schedulers.Schedulers; /** * Displays the description of a Playable object in a Webview. */ -public class ItemDescriptionFragment extends Fragment implements AudioplayerContentFragment { +public class ItemDescriptionFragment extends Fragment implements MediaplayerInfoContentFragment { private static final String TAG = "ItemDescriptionFragment"; @@ -371,8 +371,8 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont private void onTimecodeLinkSelected(String link) { int time = Timeline.getTimecodeLinkTime(link); - if (getActivity() != null && getActivity() instanceof AudioplayerActivity) { - PlaybackController pc = ((AudioplayerActivity) getActivity()).getPlaybackController(); + if (getActivity() != null && getActivity() instanceof MediaplayerInfoActivity) { + PlaybackController pc = ((MediaplayerInfoActivity) getActivity()).getPlaybackController(); if (pc != null) { pc.seekTo(time); } -- cgit v1.2.3 From dedd454685f29985f36330b59eb7d17e7748458d Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sun, 17 Apr 2016 02:08:16 -0400 Subject: change name of audioplayer_activity layout --- app/src/main/res/layout/audioplayer_activity.xml | 220 --------------------- .../main/res/layout/mediaplayerinfo_activity.xml | 220 +++++++++++++++++++++ 2 files changed, 220 insertions(+), 220 deletions(-) delete mode 100644 app/src/main/res/layout/audioplayer_activity.xml create mode 100644 app/src/main/res/layout/mediaplayerinfo_activity.xml (limited to 'app') diff --git a/app/src/main/res/layout/audioplayer_activity.xml b/app/src/main/res/layout/audioplayer_activity.xml deleted file mode 100644 index fb4f995a2..000000000 --- a/app/src/main/res/layout/audioplayer_activity.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -