summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
diff options
context:
space:
mode:
authorH. Lehmann <ByteHamster@users.noreply.github.com>2020-03-25 22:49:34 +0100
committerGitHub <noreply@github.com>2020-03-25 22:49:34 +0100
commitb5836650d18aa611b2fe2ca73d41ed58342c1e94 (patch)
tree8e427bd10df1ee6422df210910a879acff11dcdb /app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
parentae906de06d1720331be1c64607cdb6011fc66ef5 (diff)
parentd87cc27c9bdfd7fa68df6e09bf184bd75393212b (diff)
downloadAntennaPod-b5836650d18aa611b2fe2ca73d41ed58342c1e94.zip
Merge pull request #3954 from ByteHamster/audioplayer-fragment
Convert AudioPlayer to fragment
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java127
1 files changed, 12 insertions, 115 deletions
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 698d7e295..55aadc60b 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
@@ -2,7 +2,6 @@ package de.danoeh.antennapod.activity;
import android.Manifest;
import android.annotation.TargetApi;
-import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@@ -52,6 +51,7 @@ import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
import de.danoeh.antennapod.dialog.PlaybackControlsDialog;
+import de.danoeh.antennapod.dialog.SkipPreferenceDialog;
import de.danoeh.antennapod.dialog.SleepTimerDialog;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -141,16 +141,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
}
@Override
- public void postStatusMsg(int msg, boolean showToast) {
- MediaplayerActivity.this.postStatusMsg(msg, showToast);
- }
-
- @Override
- public void clearStatusMsg() {
- MediaplayerActivity.this.clearStatusMsg();
- }
-
- @Override
public boolean loadMediaInfo() {
return MediaplayerActivity.this.loadMediaInfo();
}
@@ -198,13 +188,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
onPositionObserverUpdate();
}
- private static TextView getTxtvFFFromActivity(MediaplayerActivity activity) {
- return activity.txtvFF;
- }
- private static TextView getTxtvRevFromActivity(MediaplayerActivity activity) {
- return activity.txtvRev;
- }
-
private void onSetSpeedAbilityChanged() {
Log.d(TAG, "onSetSpeedAbilityChanged()");
updatePlaybackSpeedButton();
@@ -258,12 +241,16 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
* Should be used to inform the user that the PlaybackService is currently
* buffering.
*/
- protected abstract void onBufferStart();
+ protected void onBufferStart() {
+
+ }
/**
* Should be used to hide the view that was showing the 'buffering'-message.
*/
- protected abstract void onBufferEnd();
+ protected void onBufferEnd() {
+
+ }
private void onBufferUpdate(float progress) {
if (sbPosition != null) {
@@ -311,9 +298,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
- if (Flavors.FLAVOR == Flavors.PLAY) {
- requestCastButton(MenuItem.SHOW_AS_ACTION_ALWAYS);
- }
+ requestCastButton(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mediaplayer, menu);
return true;
@@ -478,10 +463,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
*/
protected abstract void onAwaitingVideoSurface();
- protected abstract void postStatusMsg(int resId, boolean showToast);
-
- protected abstract void clearStatusMsg();
-
void onPositionObserverUpdate() {
if (controller == null || txtvPosition == null || txtvLength == null) {
return;
@@ -543,92 +524,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
// Only meaningful on AudioplayerActivity, where it is overridden.
}
- /**
- * Abstract directions to skip forward or back (rewind) and encapsulates behavior to get or set preference (including update of UI on the skip buttons).
- */
- public enum SkipDirection {
- SKIP_FORWARD(
- UserPreferences::getFastForwardSecs,
- MediaplayerActivity::getTxtvFFFromActivity,
- UserPreferences::setFastForwardSecs,
- R.string.pref_fast_forward),
- SKIP_REWIND(UserPreferences::getRewindSecs,
- MediaplayerActivity::getTxtvRevFromActivity,
- UserPreferences::setRewindSecs,
- R.string.pref_rewind);
-
- private final Supplier<Integer> getPrefSecsFn;
- private final Function<MediaplayerActivity, TextView> getTextViewFn;
- private final Consumer<Integer> setPrefSecsFn;
- private final int titleResourceID;
-
- /**
- * Constructor for skip direction enum. Stores references to utility functions and resource
- * id's that vary dependending on the direction.
- *
- * @param getPrefSecsFn Handle to function that retrieves current seconds of the skip delta
- * @param getTextViewFn Handle to function that gets the TextView which displays the current skip delta value
- * @param setPrefSecsFn Handle to function that sets the preference (setting) for the skip delta value (and optionally updates the button label with the current values)
- * @param titleResourceID ID of the resource string with the title for a view
- */
- SkipDirection(Supplier<Integer> getPrefSecsFn, Function<MediaplayerActivity, TextView> getTextViewFn, Consumer<Integer> setPrefSecsFn, int titleResourceID) {
- this.getPrefSecsFn = getPrefSecsFn;
- this.getTextViewFn = getTextViewFn;
- this.setPrefSecsFn = setPrefSecsFn;
- this.titleResourceID = titleResourceID;
- }
-
-
- public int getPrefSkipSeconds() {
- return(getPrefSecsFn.get());
- }
-
- /**
- * Updates preferences for a forward or backward skip depending on the direction of the instance, optionally updating the UI.
- *
- * @param seconds Number of seconds to set the preference associated with the direction of the instance.
- * @param activity MediaplyerActivity that contains textview to update the display of the skip delta setting (or null if nothing to update)
- */
- public void setPrefSkipSeconds(int seconds, @Nullable Activity activity) {
- setPrefSecsFn.accept(seconds);
-
- if (activity != null && activity instanceof MediaplayerActivity) {
- TextView tv = getTextViewFn.apply((MediaplayerActivity)activity);
- if (tv != null) tv.setText(String.valueOf(seconds));
- }
- }
- public int getTitleResourceID() {
- return titleResourceID;
- }
- }
-
- public static void showSkipPreference(Activity activity, SkipDirection direction) {
- int checked = 0;
- int skipSecs = direction.getPrefSkipSeconds();
- final int[] values = activity.getResources().getIntArray(R.array.seek_delta_values);
- final String[] choices = new String[values.length];
- for (int i = 0; i < values.length; i++) {
- if (skipSecs == values[i]) {
- checked = i;
- }
- choices[i] = String.valueOf(values[i]) + " " + activity.getString(R.string.time_seconds);
- }
-
- AlertDialog.Builder builder = new AlertDialog.Builder(activity);
- builder.setTitle(direction.getTitleResourceID());
- builder.setSingleChoiceItems(choices, checked, null);
- builder.setNegativeButton(R.string.cancel_label, null);
- builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
- int choice = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
- if (choice < 0 || choice >= values.length) {
- System.err.printf("Choice in showSkipPreference is out of bounds %d", choice);
- } else {
- direction.setPrefSkipSeconds(values[choice], activity);
- }
- });
- builder.create().show();
- }
-
void setupGUI() {
setContentView(getContentViewResourceId());
sbPosition = findViewById(R.id.sbPosition);
@@ -688,7 +583,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
if (butRev != null) {
butRev.setOnClickListener(v -> onRewind());
butRev.setOnLongClickListener(v -> {
- showSkipPreference(MediaplayerActivity.this, SkipDirection.SKIP_REWIND);
+ SkipPreferenceDialog.showSkipPreference(MediaplayerActivity.this,
+ SkipPreferenceDialog.SkipDirection.SKIP_REWIND, txtvRev);
return true;
});
}
@@ -698,7 +594,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
if (butFF != null) {
butFF.setOnClickListener(v -> onFastForward());
butFF.setOnLongClickListener(v -> {
- showSkipPreference(MediaplayerActivity.this, SkipDirection.SKIP_FORWARD);
+ SkipPreferenceDialog.showSkipPreference(MediaplayerActivity.this,
+ SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, txtvFF);
return false;
});
}