Merge pull request #4039 from ByteHamster/allow-stop-preview

Allow to stop previewed episode
This commit is contained in:
H. Lehmann 2020-04-11 12:09:41 +02:00 committed by GitHub
commit 87f773de38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 34 deletions

View File

@ -5,6 +5,7 @@ import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.appcompat.app.AppCompatActivity;
@ -14,10 +15,11 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
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 {
@Override
@ -40,13 +42,17 @@ public class SplashActivity extends AppCompatActivity {
PodDBAdapter.getInstance().close();
subscriber.onComplete();
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
overridePendingTransition(0, 0);
finish();
});
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
overridePendingTransition(0, 0);
finish();
}, error -> {
error.printStackTrace();
Toast.makeText(this, error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
finish();
});
}
}

View File

@ -8,6 +8,9 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
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.playback.RemoteMedia;
import de.danoeh.antennapod.core.feed.FeedItem;
@ -67,16 +70,28 @@ public class FeedItemlistDescriptionAdapter extends ArrayAdapter<FeedItem> {
return;
}
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()) {
new StreamingConfirmationDialog(getContext(), playable).show();
return;
}
new PlaybackServiceStarter(getContext(), playable)
.shouldStream(true)
.startWhenPrepared(true)
.callEvenIfRunning(true)
.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 -> {
if (holder.description.getTag() == Boolean.TRUE) {
@ -85,8 +100,14 @@ public class FeedItemlistDescriptionAdapter extends ArrayAdapter<FeedItem> {
holder.description.setTag(Boolean.FALSE);
} else {
holder.description.setMaxLines(2000);
holder.preview.setVisibility(View.VISIBLE);
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;

View File

@ -209,7 +209,7 @@ public class FeedMedia extends FeedFile implements Playable {
* currently being played.
*/
public boolean isPlaying() {
return PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
return PlaybackPreferences.getCurrentlyPlayingMediaType() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
&& PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == id;
}

View File

@ -33,14 +33,16 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
* Contains the id of the currently playing FeedMedia object or
* 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
* is set to NO_MEDIA_PLAYING after playback has been completed and is set
* 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.
@ -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
* 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() {
return prefs.getLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING);
}
public static long getCurrentlyPlayingMediaType() {
return prefs.getLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING);
}
public static long getCurrentlyPlayingFeedMediaId() {
return prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
}
public static long getCurrentlyPlayingFeedMediaId() {
return prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
}
public static boolean getCurrentEpisodeIsStream() {
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
}
public static boolean getCurrentEpisodeIsStream() {
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
}
public static boolean getCurrentEpisodeIsVideo() {
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
}
public static boolean getCurrentEpisodeIsVideo() {
return prefs.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
}
public static int getCurrentPlayerStatus() {
return prefs.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
@ -128,7 +131,7 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
public static void writeNoMediaPlaying() {
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_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
editor.putInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER);
@ -142,13 +145,13 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
if (playable == null) {
writeNoMediaPlaying();
} 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_VIDEO, playable.getMediaType() == MediaType.VIDEO);
if (playable instanceof FeedMedia) {
FeedMedia fMedia = (FeedMedia) playable;
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, fMedia.getItem().getFeed().getId());
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, fMedia.getId());
FeedMedia feedMedia = (FeedMedia) playable;
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, feedMedia.getItem().getFeed().getId());
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, feedMedia.getId());
} else {
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING);
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);

View File

@ -188,7 +188,7 @@ public interface Playable extends Parcelable,
*/
@Nullable
public static Playable createInstanceFromPreferences(Context context) {
long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMediaType();
if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
return PlayableUtils.createInstanceFromPreferences(context,

View File

@ -282,7 +282,7 @@ public class RemoteMedia implements Playable {
dest.writeString(imageUrl);
dest.writeString(feedLink);
dest.writeString(mimeType);
dest.writeLong(pubDate.getTime());
dest.writeLong((pubDate != null) ? pubDate.getTime() : 0);
dest.writeString(notes);
dest.writeInt(duration);
dest.writeInt(position);