mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-30 18:34:50 +01:00
Merge pull request #3969 from ByteHamster/hide-miniplayer-when-nothing-playing
Hide the miniplayer if there is no media playing
This commit is contained in:
commit
144d85a15d
@ -11,6 +11,8 @@ import android.os.Handler;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -178,6 +180,15 @@ public class MainActivity extends CastEnabledActivity {
|
|||||||
return sheetBehavior;
|
return sheetBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPlayerVisible(boolean visible) {
|
||||||
|
getBottomSheet().setLocked(!visible);
|
||||||
|
FrameLayout mainView = findViewById(R.id.main_view);
|
||||||
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mainView.getLayoutParams();
|
||||||
|
params.setMargins(0, 0, 0, visible ? (int) getResources().getDimension(R.dimen.external_player_height) : 0);
|
||||||
|
mainView.setLayoutParams(params);
|
||||||
|
findViewById(R.id.audioplayerFragment).setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
public void loadFragment(String tag, Bundle args) {
|
public void loadFragment(String tag, Bundle args) {
|
||||||
Log.d(TAG, "loadFragment(tag: " + tag + ", args: " + args + ")");
|
Log.d(TAG, "loadFragment(tag: " + tag + ", args: " + args + ")");
|
||||||
Fragment fragment;
|
Fragment fragment;
|
||||||
|
@ -2,7 +2,6 @@ package de.danoeh.antennapod.fragment;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -11,18 +10,17 @@ import android.widget.ImageButton;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
import de.danoeh.antennapod.activity.MainActivity;
|
||||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import de.danoeh.antennapod.core.feed.MediaType;
|
import de.danoeh.antennapod.core.feed.MediaType;
|
||||||
|
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
|
||||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
|
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||||
import io.reactivex.Maybe;
|
import io.reactivex.Maybe;
|
||||||
@ -34,8 +32,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment which is supposed to be displayed outside of the MediaplayerActivity
|
* Fragment which is supposed to be displayed outside of the MediaplayerActivity.
|
||||||
* if the PlaybackService is running
|
|
||||||
*/
|
*/
|
||||||
public class ExternalPlayerFragment extends Fragment {
|
public class ExternalPlayerFragment extends Fragment {
|
||||||
public static final String TAG = "ExternalPlayerFragment";
|
public static final String TAG = "ExternalPlayerFragment";
|
||||||
@ -43,8 +40,8 @@ public class ExternalPlayerFragment extends Fragment {
|
|||||||
private ImageView imgvCover;
|
private ImageView imgvCover;
|
||||||
private TextView txtvTitle;
|
private TextView txtvTitle;
|
||||||
private ImageButton butPlay;
|
private ImageButton butPlay;
|
||||||
private TextView mFeedName;
|
private TextView feedName;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar progressBar;
|
||||||
private PlaybackController controller;
|
private PlaybackController controller;
|
||||||
private Disposable disposable;
|
private Disposable disposable;
|
||||||
|
|
||||||
@ -59,8 +56,8 @@ public class ExternalPlayerFragment extends Fragment {
|
|||||||
imgvCover = root.findViewById(R.id.imgvCover);
|
imgvCover = root.findViewById(R.id.imgvCover);
|
||||||
txtvTitle = root.findViewById(R.id.txtvTitle);
|
txtvTitle = root.findViewById(R.id.txtvTitle);
|
||||||
butPlay = root.findViewById(R.id.butPlay);
|
butPlay = root.findViewById(R.id.butPlay);
|
||||||
mFeedName = root.findViewById(R.id.txtvAuthor);
|
feedName = root.findViewById(R.id.txtvAuthor);
|
||||||
mProgressBar = root.findViewById(R.id.episodeProgress);
|
progressBar = root.findViewById(R.id.episodeProgress);
|
||||||
|
|
||||||
root.findViewById(R.id.fragmentLayout).setOnClickListener(v -> {
|
root.findViewById(R.id.fragmentLayout).setOnClickListener(v -> {
|
||||||
Log.d(TAG, "layoutInfo was clicked");
|
Log.d(TAG, "layoutInfo was clicked");
|
||||||
@ -114,12 +111,12 @@ public class ExternalPlayerFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShutdownNotification() {
|
public void onShutdownNotification() {
|
||||||
playbackDone();
|
((MainActivity) getActivity()).setPlayerVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackEnd() {
|
public void onPlaybackEnd() {
|
||||||
playbackDone();
|
((MainActivity) getActivity()).setPlayerVisible(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -171,22 +168,6 @@ public class ExternalPlayerFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playbackDone() {
|
|
||||||
clearUi();
|
|
||||||
if (controller != null) {
|
|
||||||
controller.release();
|
|
||||||
}
|
|
||||||
controller = setupPlaybackController();
|
|
||||||
if (butPlay != null) {
|
|
||||||
butPlay.setOnClickListener(v -> {
|
|
||||||
if (controller != null) {
|
|
||||||
controller.playPause();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
controller.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean loadMediaInfo() {
|
private boolean loadMediaInfo() {
|
||||||
Log.d(TAG, "Loading media info");
|
Log.d(TAG, "Loading media info");
|
||||||
if (controller == null) {
|
if (controller == null) {
|
||||||
@ -209,47 +190,36 @@ public class ExternalPlayerFragment extends Fragment {
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(media -> updateUi((Playable) media),
|
.subscribe(media -> updateUi((Playable) media),
|
||||||
error -> Log.e(TAG, Log.getStackTraceString(error)),
|
error -> Log.e(TAG, Log.getStackTraceString(error)),
|
||||||
this::clearUi);
|
() -> ((MainActivity) getActivity()).setPlayerVisible(false));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearUi() {
|
private void updateUi(Playable media) {
|
||||||
if (txtvTitle == null || mFeedName == null || mProgressBar == null || butPlay == null) {
|
if (media == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
txtvTitle.setText(R.string.no_media_playing_label);
|
((MainActivity) getActivity()).setPlayerVisible(true);
|
||||||
mFeedName.setText("");
|
txtvTitle.setText(media.getEpisodeTitle());
|
||||||
butPlay.setVisibility(View.GONE);
|
feedName.setText(media.getFeedTitle());
|
||||||
mProgressBar.setProgress(0);
|
onPositionObserverUpdate();
|
||||||
Glide.with(getActivity()).clear(imgvCover);
|
|
||||||
((MainActivity) getActivity()).getBottomSheet().setLocked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUi(Playable media) {
|
Glide.with(getActivity())
|
||||||
if (media != null) {
|
.load(ImageResourceUtils.getImageLocation(media))
|
||||||
txtvTitle.setText(media.getEpisodeTitle());
|
.apply(new RequestOptions()
|
||||||
mFeedName.setText(media.getFeedTitle());
|
.placeholder(R.color.light_gray)
|
||||||
onPositionObserverUpdate();
|
.error(R.color.light_gray)
|
||||||
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
|
.fitCenter()
|
||||||
|
.dontAnimate())
|
||||||
|
.into(imgvCover);
|
||||||
|
|
||||||
Glide.with(getActivity())
|
if (controller != null && controller.isPlayingVideoLocally()) {
|
||||||
.load(ImageResourceUtils.getImageLocation(media))
|
butPlay.setVisibility(View.GONE);
|
||||||
.apply(new RequestOptions()
|
((MainActivity) getActivity()).getBottomSheet().setLocked(true);
|
||||||
.placeholder(R.color.light_gray)
|
((MainActivity) getActivity()).getBottomSheet().setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||||
.error(R.color.light_gray)
|
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
|
||||||
.fitCenter()
|
|
||||||
.dontAnimate())
|
|
||||||
.into(imgvCover);
|
|
||||||
if (controller != null && controller.isPlayingVideoLocally()) {
|
|
||||||
butPlay.setVisibility(View.GONE);
|
|
||||||
((MainActivity) getActivity()).getBottomSheet().setLocked(true);
|
|
||||||
((MainActivity) getActivity()).getBottomSheet().setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
||||||
} else {
|
|
||||||
butPlay.setVisibility(View.VISIBLE);
|
|
||||||
((MainActivity) getActivity()).getBottomSheet().setLocked(false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!");
|
butPlay.setVisibility(View.VISIBLE);
|
||||||
|
((MainActivity) getActivity()).getBottomSheet().setLocked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +234,7 @@ public class ExternalPlayerFragment extends Fragment {
|
|||||||
|| controller.getDuration() == PlaybackService.INVALID_TIME) {
|
|| controller.getDuration() == PlaybackService.INVALID_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mProgressBar.setProgress((int)
|
progressBar.setProgress((int)
|
||||||
((double) controller.getPosition() / controller.getDuration() * 100));
|
((double) controller.getPosition() / controller.getDuration() * 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user