Don't handle play image resource in PlaybackController
This commit is contained in:
parent
5fa558e483
commit
8768144c91
|
@ -17,6 +17,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import de.danoeh.antennapod.view.PlayButton;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
@ -72,7 +73,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
SeekBar sbPosition;
|
||||
private ImageButton butRev;
|
||||
private TextView txtvRev;
|
||||
private ImageButton butPlay;
|
||||
private PlayButton butPlay;
|
||||
private ImageButton butFF;
|
||||
private TextView txtvFF;
|
||||
private ImageButton butSkip;
|
||||
|
@ -123,8 +124,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImageButton getPlayButton() {
|
||||
return butPlay;
|
||||
protected void updatePlayButtonShowsPlay(boolean showPlay) {
|
||||
butPlay.setIsShowPlay(showPlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -513,6 +514,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
txtvRev.setText(NumberFormat.getInstance().format(UserPreferences.getRewindSecs()));
|
||||
}
|
||||
butPlay = findViewById(R.id.butPlay);
|
||||
butPlay.setIsVideoScreen(true);
|
||||
butFF = findViewById(R.id.butFF);
|
||||
txtvFF = findViewById(R.id.txtvFF);
|
||||
if (txtvFF != null) {
|
||||
|
|
|
@ -50,6 +50,7 @@ import de.danoeh.antennapod.dialog.VariableSpeedDialog;
|
|||
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
||||
import de.danoeh.antennapod.view.ChapterSeekBar;
|
||||
import de.danoeh.antennapod.ui.common.PlaybackSpeedIndicatorView;
|
||||
import de.danoeh.antennapod.view.PlayButton;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
@ -82,7 +83,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
private ChapterSeekBar sbPosition;
|
||||
private ImageButton butRev;
|
||||
private TextView txtvRev;
|
||||
private ImageButton butPlay;
|
||||
private PlayButton butPlay;
|
||||
private ImageButton butFF;
|
||||
private TextView txtvFF;
|
||||
private ImageButton butSkip;
|
||||
|
@ -379,8 +380,8 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImageButton getPlayButton() {
|
||||
return butPlay;
|
||||
protected void updatePlayButtonShowsPlay(boolean showPlay) {
|
||||
butPlay.setIsShowPlay(showPlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,7 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
|||
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
import de.danoeh.antennapod.view.PlayButton;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
@ -40,7 +41,7 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
|
||||
private ImageView imgvCover;
|
||||
private TextView txtvTitle;
|
||||
private ImageButton butPlay;
|
||||
private PlayButton butPlay;
|
||||
private TextView feedName;
|
||||
private ProgressBar progressBar;
|
||||
private PlaybackController controller;
|
||||
|
@ -103,8 +104,8 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImageButton getPlayButton() {
|
||||
return butPlay;
|
||||
protected void updatePlayButtonShowsPlay(boolean showPlay) {
|
||||
butPlay.setIsShowPlay(showPlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package de.danoeh.antennapod.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||
|
||||
public class PlayButton extends AppCompatImageButton {
|
||||
private boolean isVideoScreen;
|
||||
|
||||
public PlayButton(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public PlayButton(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public PlayButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setIsVideoScreen(boolean isVideoScreen) {
|
||||
this.isVideoScreen = isVideoScreen;
|
||||
}
|
||||
|
||||
public void setIsShowPlay(boolean showPlay) {
|
||||
setContentDescription(getContext().getString(showPlay ? R.string.play_label : R.string.pause_label));
|
||||
if (isVideoScreen) {
|
||||
setImageResource(showPlay ? R.drawable.ic_av_play_white_80dp : R.drawable.ic_av_pause_white_80dp);
|
||||
} else {
|
||||
setImageResource(ThemeUtils.getDrawableFromAttr(getContext(), showPlay ? R.attr.av_play : R.attr.av_pause));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -138,7 +138,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp">
|
||||
|
||||
<ImageButton
|
||||
<de.danoeh.antennapod.view.PlayButton
|
||||
android:id="@+id/butPlay"
|
||||
android:layout_width="@dimen/audioplayer_playercontrols_length_big"
|
||||
android:layout_height="@dimen/audioplayer_playercontrols_length_big"
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
|
||||
<ImageButton
|
||||
<de.danoeh.antennapod.view.PlayButton
|
||||
android:id="@+id/butPlay"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
android:contentDescription="@string/rewind_label"
|
||||
app:srcCompat="@drawable/ic_av_fast_rewind_white_80dp" />
|
||||
|
||||
<ImageButton
|
||||
<de.danoeh.antennapod.view.PlayButton
|
||||
android:id="@+id/butPlay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.res.TypedArray;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
@ -15,7 +14,6 @@ import android.text.TextUtils;
|
|||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.widget.ImageButton;
|
||||
import androidx.annotation.NonNull;
|
||||
import de.danoeh.antennapod.core.R;
|
||||
import de.danoeh.antennapod.core.event.MessageEvent;
|
||||
|
@ -28,12 +26,6 @@ import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer;
|
||||
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.MaybeOnSubscribe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
@ -60,8 +52,6 @@ public abstract class PlaybackController {
|
|||
private boolean initialized = false;
|
||||
private boolean eventsRegistered = false;
|
||||
|
||||
private Disposable mediaLoader;
|
||||
|
||||
public PlaybackController(@NonNull Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
@ -77,7 +67,7 @@ public abstract class PlaybackController {
|
|||
if (PlaybackService.isRunning) {
|
||||
initServiceRunning();
|
||||
} else {
|
||||
initServiceNotRunning();
|
||||
updatePlayButtonShowsPlay(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,21 +302,6 @@ public abstract class PlaybackController {
|
|||
* should be used to update the GUI or start/cancel background threads.
|
||||
*/
|
||||
private void handleStatus() {
|
||||
final int playResource;
|
||||
final int pauseResource;
|
||||
final CharSequence playText = activity.getString(R.string.play_label);
|
||||
final CharSequence pauseText = activity.getString(R.string.pause_label);
|
||||
|
||||
if (PlaybackService.getCurrentMediaType() == MediaType.AUDIO || PlaybackService.isCasting()) {
|
||||
TypedArray res = activity.obtainStyledAttributes(new int[]{ R.attr.av_play, R.attr.av_pause});
|
||||
playResource = res.getResourceId(0, R.drawable.ic_av_play_black_48dp);
|
||||
pauseResource = res.getResourceId(1, R.drawable.ic_av_pause_black_48dp);
|
||||
res.recycle();
|
||||
} else {
|
||||
playResource = R.drawable.ic_av_play_white_80dp;
|
||||
pauseResource = R.drawable.ic_av_pause_white_80dp;
|
||||
}
|
||||
|
||||
Log.d(TAG, "status: " + status.toString());
|
||||
switch (status) {
|
||||
case ERROR:
|
||||
|
@ -336,37 +311,31 @@ public abstract class PlaybackController {
|
|||
case PAUSED:
|
||||
checkMediaInfoLoaded();
|
||||
onPositionObserverUpdate();
|
||||
updatePlayButtonAppearance(playResource, playText);
|
||||
if (!PlaybackService.isCasting() &&
|
||||
PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
updatePlayButtonShowsPlay(true);
|
||||
if (!PlaybackService.isCasting() && PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
setScreenOn(false);
|
||||
}
|
||||
break;
|
||||
case PLAYING:
|
||||
checkMediaInfoLoaded();
|
||||
if (!PlaybackService.isCasting() &&
|
||||
PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
if (!PlaybackService.isCasting() && PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
onAwaitingVideoSurface();
|
||||
setScreenOn(true);
|
||||
}
|
||||
updatePlayButtonAppearance(pauseResource, pauseText);
|
||||
updatePlayButtonShowsPlay(false);
|
||||
break;
|
||||
case PREPARING:
|
||||
checkMediaInfoLoaded();
|
||||
if (playbackService != null) {
|
||||
if (playbackService.isStartWhenPrepared()) {
|
||||
updatePlayButtonAppearance(pauseResource, pauseText);
|
||||
} else {
|
||||
updatePlayButtonAppearance(playResource, playText);
|
||||
}
|
||||
updatePlayButtonShowsPlay(!playbackService.isStartWhenPrepared());
|
||||
}
|
||||
break;
|
||||
case STOPPED:
|
||||
updatePlayButtonAppearance(playResource, playText);
|
||||
updatePlayButtonShowsPlay(true);
|
||||
break;
|
||||
case PREPARED:
|
||||
checkMediaInfoLoaded();
|
||||
updatePlayButtonAppearance(playResource, playText);
|
||||
updatePlayButtonShowsPlay(true);
|
||||
onPositionObserverUpdate();
|
||||
break;
|
||||
case SEEKING:
|
||||
|
@ -374,7 +343,7 @@ public abstract class PlaybackController {
|
|||
break;
|
||||
case INITIALIZED:
|
||||
checkMediaInfoLoaded();
|
||||
updatePlayButtonAppearance(playResource, playText);
|
||||
updatePlayButtonShowsPlay(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -386,16 +355,8 @@ public abstract class PlaybackController {
|
|||
mediaInfoLoaded = true;
|
||||
}
|
||||
|
||||
private void updatePlayButtonAppearance(int resource, CharSequence contentDescription) {
|
||||
ImageButton butPlay = getPlayButton();
|
||||
if(butPlay != null) {
|
||||
butPlay.setImageResource(resource);
|
||||
butPlay.setContentDescription(contentDescription);
|
||||
}
|
||||
}
|
||||
protected void updatePlayButtonShowsPlay(boolean showPlay) {
|
||||
|
||||
public ImageButton getPlayButton() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void loadMediaInfo();
|
||||
|
@ -662,29 +623,4 @@ public abstract class PlaybackController {
|
|||
public boolean isStreaming() {
|
||||
return playbackService != null && playbackService.isStreaming();
|
||||
}
|
||||
|
||||
private void initServiceNotRunning() {
|
||||
if (getPlayButton() == null) {
|
||||
return;
|
||||
}
|
||||
Log.v(TAG, "initServiceNotRunning()");
|
||||
mediaLoader = Maybe.create((MaybeOnSubscribe<Playable>) emitter -> {
|
||||
Playable media = getMedia();
|
||||
if (media != null) {
|
||||
emitter.onSuccess(media);
|
||||
} else {
|
||||
emitter.onComplete();
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> {
|
||||
if (media.getMediaType() == MediaType.AUDIO) {
|
||||
getPlayButton().setImageResource(
|
||||
ThemeUtils.getDrawableFromAttr(activity, de.danoeh.antennapod.core.R.attr.av_play));
|
||||
} else {
|
||||
getPlayButton().setImageResource(R.drawable.ic_av_play_white_80dp);
|
||||
}
|
||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue