diff options
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.java | 133 |
1 files changed, 15 insertions, 118 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 c0ba75ba6..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; @@ -22,9 +21,12 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.arch.core.util.Function; import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityOptionsCompat; import androidx.core.content.ContextCompat; +import androidx.core.util.Consumer; +import androidx.core.util.Supplier; import com.bumptech.glide.Glide; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.event.PlaybackPositionEvent; @@ -35,15 +37,12 @@ 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.Consumer; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.Flavors; -import de.danoeh.antennapod.core.util.Function; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.StorageUtils; -import de.danoeh.antennapod.core.util.Supplier; import de.danoeh.antennapod.core.util.TimeSpeedConverter; import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil; import de.danoeh.antennapod.core.util.playback.ExternalMedia; @@ -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; }); } |