Merge pull request #4039 from ByteHamster/allow-stop-preview
Allow to stop previewed episode
This commit is contained in:
commit
87f773de38
@ -5,6 +5,7 @@ import android.graphics.PorterDuff;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.graphics.drawable.DrawableCompat;
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -14,10 +15,11 @@ import de.danoeh.antennapod.R;
|
|||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the AntennaPod logo while waiting for the main activity to start
|
* Shows the AntennaPod logo while waiting for the main activity to start.
|
||||||
*/
|
*/
|
||||||
public class SplashActivity extends AppCompatActivity {
|
public class SplashActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
@ -40,13 +42,17 @@ public class SplashActivity extends AppCompatActivity {
|
|||||||
PodDBAdapter.getInstance().close();
|
PodDBAdapter.getInstance().close();
|
||||||
subscriber.onComplete();
|
subscriber.onComplete();
|
||||||
})
|
})
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(() -> {
|
.subscribe(() -> {
|
||||||
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
|
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
overridePendingTransition(0, 0);
|
overridePendingTransition(0, 0);
|
||||||
finish();
|
finish();
|
||||||
});
|
}, error -> {
|
||||||
|
error.printStackTrace();
|
||||||
|
Toast.makeText(this, error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
finish();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.core.feed.MediaType;
|
||||||
|
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||||
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
import de.danoeh.antennapod.core.util.playback.RemoteMedia;
|
import de.danoeh.antennapod.core.util.playback.RemoteMedia;
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
@ -67,16 +70,28 @@ public class FeedItemlistDescriptionAdapter extends ArrayAdapter<FeedItem> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Playable playable = new RemoteMedia(item);
|
Playable playable = new RemoteMedia(item);
|
||||||
|
if (PlaybackPreferences.getCurrentlyPlayingMediaType() == RemoteMedia.PLAYABLE_TYPE_REMOTE_MEDIA) {
|
||||||
|
PlaybackPreferences.writeNoMediaPlaying();
|
||||||
|
IntentUtils.sendLocalBroadcast(getContext(), PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||||
|
holder.preview.setText(R.string.preview_episode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!NetworkUtils.isStreamingAllowed()) {
|
if (!NetworkUtils.isStreamingAllowed()) {
|
||||||
new StreamingConfirmationDialog(getContext(), playable).show();
|
new StreamingConfirmationDialog(getContext(), playable).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new PlaybackServiceStarter(getContext(), playable)
|
new PlaybackServiceStarter(getContext(), playable)
|
||||||
.shouldStream(true)
|
.shouldStream(true)
|
||||||
.startWhenPrepared(true)
|
.startWhenPrepared(true)
|
||||||
.callEvenIfRunning(true)
|
.callEvenIfRunning(true)
|
||||||
.start();
|
.start();
|
||||||
getContext().startActivity(PlaybackService.getPlayerActivityIntent(getContext(), playable));
|
holder.preview.setText(R.string.stop_playback);
|
||||||
|
|
||||||
|
if (playable.getMediaType() == MediaType.VIDEO) {
|
||||||
|
getContext().startActivity(PlaybackService.getPlayerActivityIntent(getContext(), playable));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
convertView.setOnClickListener(v -> {
|
convertView.setOnClickListener(v -> {
|
||||||
if (holder.description.getTag() == Boolean.TRUE) {
|
if (holder.description.getTag() == Boolean.TRUE) {
|
||||||
@ -85,8 +100,14 @@ public class FeedItemlistDescriptionAdapter extends ArrayAdapter<FeedItem> {
|
|||||||
holder.description.setTag(Boolean.FALSE);
|
holder.description.setTag(Boolean.FALSE);
|
||||||
} else {
|
} else {
|
||||||
holder.description.setMaxLines(2000);
|
holder.description.setMaxLines(2000);
|
||||||
holder.preview.setVisibility(View.VISIBLE);
|
|
||||||
holder.description.setTag(Boolean.TRUE);
|
holder.description.setTag(Boolean.TRUE);
|
||||||
|
|
||||||
|
holder.preview.setVisibility(item.getMedia() != null ? View.VISIBLE : View.GONE);
|
||||||
|
if (PlaybackPreferences.getCurrentlyPlayingMediaType() == RemoteMedia.PLAYABLE_TYPE_REMOTE_MEDIA) {
|
||||||
|
holder.preview.setText(R.string.stop_playback);
|
||||||
|
} else {
|
||||||
|
holder.preview.setText(R.string.preview_episode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return convertView;
|
return convertView;
|
||||||
|
@ -209,7 +209,7 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||||||
* currently being played.
|
* currently being played.
|
||||||
*/
|
*/
|
||||||
public boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
return PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
|
return PlaybackPreferences.getCurrentlyPlayingMediaType() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
|
||||||
&& PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == id;
|
&& PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +33,16 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
|
|||||||
* Contains the id of the currently playing FeedMedia object or
|
* Contains the id of the currently playing FeedMedia object or
|
||||||
* NO_MEDIA_PLAYING if the currently playing media is no FeedMedia object.
|
* NO_MEDIA_PLAYING if the currently playing media is no FeedMedia object.
|
||||||
*/
|
*/
|
||||||
private static final String PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedMediaId";
|
private static final String PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID
|
||||||
|
= "de.danoeh.antennapod.preferences.lastPlayedFeedMediaId";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of the media object that is currently being played. This preference
|
* Type of the media object that is currently being played. This preference
|
||||||
* is set to NO_MEDIA_PLAYING after playback has been completed and is set
|
* is set to NO_MEDIA_PLAYING after playback has been completed and is set
|
||||||
* as soon as the 'play' button is pressed.
|
* as soon as the 'play' button is pressed.
|
||||||
*/
|
*/
|
||||||
private static final String PREF_CURRENTLY_PLAYING_MEDIA = "de.danoeh.antennapod.preferences.currentlyPlayingMedia";
|
private static final String PREF_CURRENTLY_PLAYING_MEDIA_TYPE
|
||||||
|
= "de.danoeh.antennapod.preferences.currentlyPlayingMedia";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if last played media was streamed.
|
* True if last played media was streamed.
|
||||||
@ -61,7 +63,8 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
|
|||||||
* A temporary playback speed which overrides the per-feed playback speed for the currently playing
|
* A temporary playback speed which overrides the per-feed playback speed for the currently playing
|
||||||
* media. Considered unset if set to SPEED_USE_GLOBAL;
|
* media. Considered unset if set to SPEED_USE_GLOBAL;
|
||||||
*/
|
*/
|
||||||
private static final String PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED = "de.danoeh.antennapod.preferences.temporaryPlaybackSpeed";
|
private static final String PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED
|
||||||
|
= "de.danoeh.antennapod.preferences.temporaryPlaybackSpeed";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,21 +105,21 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getCurrentlyPlayingMedia() {
|
public static long getCurrentlyPlayingMediaType() {
|
||||||
return prefs.getLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING);
|
return prefs.getLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getCurrentlyPlayingFeedMediaId() {
|
public static long getCurrentlyPlayingFeedMediaId() {
|
||||||
return prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
|
return prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getCurrentEpisodeIsStream() {
|
public static boolean getCurrentEpisodeIsStream() {
|
||||||
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
|
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getCurrentEpisodeIsVideo() {
|
public static boolean getCurrentEpisodeIsVideo() {
|
||||||
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
|
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCurrentPlayerStatus() {
|
public static int getCurrentPlayerStatus() {
|
||||||
return prefs.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
|
return prefs.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
|
||||||
@ -128,7 +131,7 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
|
|||||||
|
|
||||||
public static void writeNoMediaPlaying() {
|
public static void writeNoMediaPlaying() {
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING);
|
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING);
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING);
|
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING);
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
|
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
|
||||||
editor.putInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
|
editor.putInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
|
||||||
@ -142,13 +145,13 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
|
|||||||
if (playable == null) {
|
if (playable == null) {
|
||||||
writeNoMediaPlaying();
|
writeNoMediaPlaying();
|
||||||
} else {
|
} else {
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, playable.getPlayableType());
|
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, playable.getPlayableType());
|
||||||
editor.putBoolean(PREF_CURRENT_EPISODE_IS_STREAM, stream);
|
editor.putBoolean(PREF_CURRENT_EPISODE_IS_STREAM, stream);
|
||||||
editor.putBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, playable.getMediaType() == MediaType.VIDEO);
|
editor.putBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, playable.getMediaType() == MediaType.VIDEO);
|
||||||
if (playable instanceof FeedMedia) {
|
if (playable instanceof FeedMedia) {
|
||||||
FeedMedia fMedia = (FeedMedia) playable;
|
FeedMedia feedMedia = (FeedMedia) playable;
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, fMedia.getItem().getFeed().getId());
|
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, feedMedia.getItem().getFeed().getId());
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, fMedia.getId());
|
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, feedMedia.getId());
|
||||||
} else {
|
} else {
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING);
|
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING);
|
||||||
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
|
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
|
||||||
|
@ -188,7 +188,7 @@ public interface Playable extends Parcelable,
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Playable createInstanceFromPreferences(Context context) {
|
public static Playable createInstanceFromPreferences(Context context) {
|
||||||
long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
|
long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMediaType();
|
||||||
if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
|
if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
||||||
return PlayableUtils.createInstanceFromPreferences(context,
|
return PlayableUtils.createInstanceFromPreferences(context,
|
||||||
|
@ -282,7 +282,7 @@ public class RemoteMedia implements Playable {
|
|||||||
dest.writeString(imageUrl);
|
dest.writeString(imageUrl);
|
||||||
dest.writeString(feedLink);
|
dest.writeString(feedLink);
|
||||||
dest.writeString(mimeType);
|
dest.writeString(mimeType);
|
||||||
dest.writeLong(pubDate.getTime());
|
dest.writeLong((pubDate != null) ? pubDate.getTime() : 0);
|
||||||
dest.writeString(notes);
|
dest.writeString(notes);
|
||||||
dest.writeInt(duration);
|
dest.writeInt(duration);
|
||||||
dest.writeInt(position);
|
dest.writeInt(position);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user