diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-11-03 21:35:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 21:35:18 +0100 |
commit | 9b06bf0dc595579193ce1893dfe7721f4b5adf0a (patch) | |
tree | c2af7147daac2b50a494dda345e9862917212f97 /app | |
parent | c171ab6823150d8cba1fe836269881ff5ec9cf2a (diff) | |
parent | 1e336ac0f8dd7ad74f576f2ce478222eaab26c1b (diff) | |
download | AntennaPod-9b06bf0dc595579193ce1893dfe7721f4b5adf0a.zip |
Merge pull request #6173 from ByteHamster/playbackservice-cleanup
PlaybackService cleanup
Diffstat (limited to 'app')
9 files changed, 39 insertions, 78 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java index 78cf59907..65e28c572 100644 --- a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java @@ -3,6 +3,7 @@ package de.test.antennapod.playback; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.view.KeyEvent; import androidx.preference.PreferenceManager; import android.view.View; @@ -10,6 +11,7 @@ import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; +import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.model.feed.FeedItemFilter; import de.danoeh.antennapod.playback.base.PlayerStatus; import org.awaitility.Awaitility; @@ -32,10 +34,8 @@ import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.test.antennapod.EspressoTestUtils; @@ -241,11 +241,11 @@ public class PlaybackTest { } private void skipEpisode() { - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SKIP_CURRENT_EPISODE); + context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_NEXT)); } protected void pauseEpisode() { - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE); + context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_PAUSE)); } protected void startLocalPlayback() { 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 450a99873..2b2d3de15 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.activity; -import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -23,7 +22,6 @@ import androidx.core.view.ViewCompat; import androidx.core.view.WindowCompat; import androidx.core.view.WindowInsetsCompat; import com.google.android.material.appbar.MaterialToolbar; -import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentContainerView; @@ -44,7 +42,6 @@ import org.greenrobot.eventbus.ThreadMode; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; -import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.util.download.AutoUpdateManager; import de.danoeh.antennapod.dialog.RatingDialog; import de.danoeh.antennapod.event.MessageEvent; @@ -448,7 +445,6 @@ public class MainActivity extends CastEnabledActivity { EventBus.getDefault().unregister(this); } - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onTrimMemory(int level) { super.onTrimMemory(level); @@ -662,9 +658,7 @@ public class MainActivity extends CastEnabledActivity { } if (customKeyCode != null) { - Intent intent = new Intent(this, PlaybackService.class); - intent.putExtra(MediaButtonReceiver.EXTRA_KEYCODE, customKeyCode); - ContextCompat.startForegroundService(this, intent); + sendBroadcast(MediaButtonReceiver.createIntent(this, customKeyCode)); return true; } return super.onKeyUp(keyCode, event); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index 65a5bf507..b96b18e85 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.activity; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.Intent; import android.graphics.PixelFormat; import android.graphics.drawable.ColorDrawable; @@ -174,7 +173,6 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar. super.onPause(); } - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onTrimMemory(int level) { super.onTrimMemory(level); @@ -190,18 +188,18 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar. private PlaybackController newPlaybackController() { return new PlaybackController(this) { @Override - public void onPositionObserverUpdate() { - VideoplayerActivity.this.onPositionObserverUpdate(); - } - - @Override - public void onReloadNotification(int code) { - VideoplayerActivity.this.onReloadNotification(code); - } - - @Override protected void updatePlayButtonShowsPlay(boolean showPlay) { viewBinding.playButton.setIsShowPlay(showPlay); + if (showPlay) { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } else { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setupVideoAspectRatio(); + if (videoSurfaceCreated && controller != null) { + Log.d(TAG, "Videosurface already created, setting videosurface now"); + controller.setVideoSurface(viewBinding.videoView.getHolder()); + } + } } @Override @@ -210,27 +208,9 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar. } @Override - public void onAwaitingVideoSurface() { - setupVideoAspectRatio(); - if (videoSurfaceCreated && controller != null) { - Log.d(TAG, "Videosurface already created, setting videosurface now"); - controller.setVideoSurface(viewBinding.videoView.getHolder()); - } - } - - @Override public void onPlaybackEnd() { finish(); } - - @Override - protected void setScreenOn(boolean enable) { - if (enable) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } else { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - } }; } @@ -259,6 +239,13 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar. if (controller == null || controller.getMedia() == null) { return; } + if (controller.getStatus() == PlayerStatus.PLAYING && !controller.isPlayingVideoLocally()) { + Log.d(TAG, "Closing, no longer video"); + destroyingDueToReload = true; + finish(); + new MainActivityStarter(this).withOpenPlayer().start(); + return; + } showTimeLeft = UserPreferences.shouldShowRemainingTime(); onPositionObserverUpdate(); checkFavorite(); @@ -485,22 +472,6 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar. } }; - protected void onReloadNotification(int notificationCode) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && PictureInPictureUtil.isInPictureInPictureMode(this)) { - if (notificationCode == PlaybackService.EXTRA_CODE_AUDIO - || notificationCode == PlaybackService.EXTRA_CODE_CAST) { - finish(); - } - return; - } - if (notificationCode == PlaybackService.EXTRA_CODE_CAST) { - Log.d(TAG, "ReloadNotification received, switching to Castplayer now"); - destroyingDueToReload = true; - finish(); - new MainActivityStarter(this).withOpenPlayer().start(); - } - } - private void showVideoControls() { viewBinding.bottomControlsContainer.setVisibility(View.VISIBLE); viewBinding.controlsContainer.setVisibility(View.VISIBLE); @@ -669,8 +640,8 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar. int remainingTime = converter.convert( controller.getDuration() - controller.getPosition()); Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition)); - if (currentPosition == PlaybackService.INVALID_TIME - || duration == PlaybackService.INVALID_TIME) { + if (currentPosition == Playable.INVALID_TIME + || duration == Playable.INVALID_TIME) { Log.w(TAG, "Could not react to position observer update because of invalid time"); return; } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java index de4dae6a0..5e9a2e9f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java @@ -1,15 +1,14 @@ package de.danoeh.antennapod.adapter.actionbutton; import android.content.Context; +import android.view.KeyEvent; import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.util.FeedItemUtil; -import de.danoeh.antennapod.core.util.IntentUtils; - -import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE; public class PauseActionButton extends ItemActionButton { @@ -37,7 +36,7 @@ public class PauseActionButton extends ItemActionButton { } if (FeedItemUtil.isCurrentlyPlaying(media)) { - IntentUtils.sendLocalBroadcast(context, ACTION_PAUSE_PLAY_CURRENT_EPISODE); + context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_PAUSE)); } } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java index 5a00e0e96..08c684a15 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment; import android.content.Intent; import android.os.Bundle; import android.util.Log; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -26,7 +27,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.elevation.SurfaceColors; import com.google.android.material.snackbar.Snackbar; -import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.event.playback.BufferUpdateEvent; import de.danoeh.antennapod.event.playback.PlaybackServiceEvent; @@ -54,7 +55,6 @@ import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.Converter; -import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.TimeSpeedConverter; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.dialog.PlaybackControlsDialog; @@ -215,8 +215,8 @@ public class AudioPlayerFragment extends Fragment implements SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, txtvFF); return false; }); - butSkip.setOnClickListener(v -> - IntentUtils.sendLocalBroadcast(getActivity(), PlaybackService.ACTION_SKIP_CURRENT_EPISODE)); + butSkip.setOnClickListener(v -> getActivity().sendBroadcast( + MediaButtonReceiver.createIntent(getContext(), KeyEvent.KEYCODE_MEDIA_NEXT))); } @Subscribe(threadMode = ThreadMode.MAIN) @@ -374,7 +374,7 @@ public class AudioPlayerFragment extends Fragment implements int remainingTime = converter.convert(Math.max(event.getDuration() - event.getPosition(), 0)); currentChapterIndex = ChapterUtils.getCurrentChapterIndex(controller.getMedia(), currentPosition); Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition)); - if (currentPosition == PlaybackService.INVALID_TIME || duration == PlaybackService.INVALID_TIME) { + if (currentPosition == Playable.INVALID_TIME || duration == Playable.INVALID_TIME) { Log.w(TAG, "Could not react to position observer update because of invalid time"); return; } 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 a155207aa..0443716b0 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java @@ -88,11 +88,6 @@ public class ChaptersFragment extends AppCompatDialogFragment { public void loadMediaInfo() { ChaptersFragment.this.loadMediaInfo(); } - - @Override - public void onPositionObserverUpdate() { - adapter.notifyDataSetChanged(); - } }; controller.init(); EventBus.getDefault().register(this); 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 1e24d62f7..2f39070ac 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -139,8 +139,8 @@ public class ExternalPlayerFragment extends Fragment { public void onPositionObserverUpdate(PlaybackPositionEvent event) { if (controller == null) { return; - } else if (controller.getPosition() == PlaybackService.INVALID_TIME - || controller.getDuration() == PlaybackService.INVALID_TIME) { + } else if (controller.getPosition() == Playable.INVALID_TIME + || controller.getDuration() == Playable.INVALID_TIME) { return; } progressBar.setProgress((int) diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 5bbda2980..c52db0500 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.menuhandler; import android.content.Context; import android.os.Handler; import android.util.Log; +import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -15,6 +16,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.sync.SynchronizationSettings; @@ -143,7 +145,7 @@ public class FeedItemMenuHandler { @NonNull Context context = fragment.requireContext(); if (menuItemId == R.id.skip_episode_item) { - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SKIP_CURRENT_EPISODE); + context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_NEXT)); } else if (menuItemId == R.id.remove_item) { DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId()); } else if (menuItemId == R.id.remove_inbox_item) { diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java index bb57e4bc0..22b46492f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java @@ -30,10 +30,10 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.ui.common.CircularProgressBar; import de.danoeh.antennapod.ui.common.ThemeUtils; @@ -230,7 +230,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { int timeDuration = event.getDuration(); int remainingTime = Math.max(timeDuration - currentPosition, 0); Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition)); - if (currentPosition == PlaybackService.INVALID_TIME || timeDuration == PlaybackService.INVALID_TIME) { + if (currentPosition == Playable.INVALID_TIME || timeDuration == Playable.INVALID_TIME) { Log.w(TAG, "Could not react to position observer update because of invalid time"); return; } |