mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 01:20:34 +00:00
Merge pull request #1497 from karyogamy/view-history-fix
View history fix
This commit is contained in:
commit
ccc27b48df
@ -71,6 +71,14 @@ public class PlaylistRemoteEntity implements PlaylistLocalItem {
|
|||||||
info.getUploaderName(), info.getStreamCount());
|
info.getUploaderName(), info.getStreamCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public boolean isIdenticalTo(final PlaylistInfo info) {
|
||||||
|
return getServiceId() == info.getServiceId() && getName().equals(info.getName()) &&
|
||||||
|
getStreamCount() == info.getStreamCount() && getUrl().equals(info.getUrl()) &&
|
||||||
|
getThumbnailUrl().equals(info.getThumbnailUrl()) &&
|
||||||
|
getUploader().equals(info.getUploaderName());
|
||||||
|
}
|
||||||
|
|
||||||
public long getUid() {
|
public long getUid() {
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,14 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
|
import org.schabi.newpipe.extractor.stream.Stream;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.fragments.BackPressable;
|
import org.schabi.newpipe.fragments.BackPressable;
|
||||||
import org.schabi.newpipe.fragments.BaseStateFragment;
|
import org.schabi.newpipe.fragments.BaseStateFragment;
|
||||||
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter;
|
import org.schabi.newpipe.util.StreamItemAdapter;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
||||||
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||||
@ -128,7 +130,7 @@ public class VideoDetailFragment
|
|||||||
|
|
||||||
private StreamInfo currentInfo;
|
private StreamInfo currentInfo;
|
||||||
private Disposable currentWorker;
|
private Disposable currentWorker;
|
||||||
private CompositeDisposable disposables = new CompositeDisposable();
|
@NonNull private CompositeDisposable disposables = new CompositeDisposable();
|
||||||
|
|
||||||
private List<VideoStream> sortedVideoStreams;
|
private List<VideoStream> sortedVideoStreams;
|
||||||
private int selectedVideoStreamIndex = -1;
|
private int selectedVideoStreamIndex = -1;
|
||||||
@ -872,10 +874,7 @@ public class VideoDetailFragment
|
|||||||
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
|
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
|
||||||
openNormalBackgroundPlayer(append);
|
openNormalBackgroundPlayer(append);
|
||||||
} else {
|
} else {
|
||||||
NavigationHelper.playOnExternalPlayer(activity,
|
startOnExternalPlayer(activity, currentInfo, audioStream);
|
||||||
currentInfo.getName(),
|
|
||||||
currentInfo.getUploaderName(),
|
|
||||||
audioStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,10 +901,7 @@ public class VideoDetailFragment
|
|||||||
|
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(activity)
|
if (PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
.getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
|
.getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
|
||||||
NavigationHelper.playOnExternalPlayer(activity,
|
startOnExternalPlayer(activity, currentInfo, selectedVideoStream);
|
||||||
currentInfo.getName(),
|
|
||||||
currentInfo.getUploaderName(),
|
|
||||||
selectedVideoStream);
|
|
||||||
} else {
|
} else {
|
||||||
openNormalPlayer(selectedVideoStream);
|
openNormalPlayer(selectedVideoStream);
|
||||||
}
|
}
|
||||||
@ -949,6 +945,20 @@ public class VideoDetailFragment
|
|||||||
this.autoPlayEnabled = autoplay;
|
this.autoPlayEnabled = autoplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startOnExternalPlayer(@NonNull final Context context,
|
||||||
|
@NonNull final StreamInfo info,
|
||||||
|
@NonNull final Stream selectedStream) {
|
||||||
|
NavigationHelper.playOnExternalPlayer(context, currentInfo.getName(),
|
||||||
|
currentInfo.getUploaderName(), selectedStream);
|
||||||
|
|
||||||
|
final HistoryRecordManager recordManager = new HistoryRecordManager(requireContext());
|
||||||
|
disposables.add(recordManager.onViewed(info).onErrorComplete()
|
||||||
|
.subscribe(
|
||||||
|
ignored -> {/* successful */},
|
||||||
|
error -> Log.e(TAG, "Register view failure: ", error)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private VideoStream getSelectedVideoStream() {
|
private VideoStream getSelectedVideoStream() {
|
||||||
return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null;
|
return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null;
|
||||||
|
@ -29,8 +29,8 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
||||||
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
|
||||||
import org.schabi.newpipe.info_list.InfoItemDialog;
|
import org.schabi.newpipe.info_list.InfoItemDialog;
|
||||||
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
@ -44,6 +44,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import io.reactivex.Flowable;
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
@ -93,7 +94,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
disposables = new CompositeDisposable();
|
disposables = new CompositeDisposable();
|
||||||
isBookmarkButtonReady = new AtomicBoolean(false);
|
isBookmarkButtonReady = new AtomicBoolean(false);
|
||||||
remotePlaylistManager = new RemotePlaylistManager(NewPipeDatabase.getInstance(getContext()));
|
remotePlaylistManager = new RemotePlaylistManager(NewPipeDatabase.getInstance(
|
||||||
|
requireContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -281,14 +283,11 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remotePlaylistManager.getPlaylist(result)
|
remotePlaylistManager.getPlaylist(result)
|
||||||
|
.flatMap(lists -> getUpdateProcessor(lists, result), (lists, id) -> lists)
|
||||||
.onBackpressureLatest()
|
.onBackpressureLatest()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(getPlaylistBookmarkSubscriber());
|
.subscribe(getPlaylistBookmarkSubscriber());
|
||||||
|
|
||||||
remotePlaylistManager.onUpdate(result)
|
|
||||||
.subscribeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(integer -> {/* Do nothing*/}, this::onError);
|
|
||||||
|
|
||||||
headerPlayAllButton.setOnClickListener(view ->
|
headerPlayAllButton.setOnClickListener(view ->
|
||||||
NavigationHelper.playOnMainPlayer(activity, getPlayQueue()));
|
NavigationHelper.playOnMainPlayer(activity, getPlayQueue()));
|
||||||
headerPopupButton.setOnClickListener(view ->
|
headerPopupButton.setOnClickListener(view ->
|
||||||
@ -344,6 +343,17 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
|||||||
// Utils
|
// Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
private Flowable<Integer> getUpdateProcessor(@NonNull List<PlaylistRemoteEntity> playlists,
|
||||||
|
@NonNull PlaylistInfo result) {
|
||||||
|
final Flowable<Integer> noItemToUpdate = Flowable.just(/*noItemToUpdate=*/-1);
|
||||||
|
if (playlists.isEmpty()) return noItemToUpdate;
|
||||||
|
|
||||||
|
final PlaylistRemoteEntity playlistEntity = playlists.get(0);
|
||||||
|
if (playlistEntity.isIdenticalTo(result)) return noItemToUpdate;
|
||||||
|
|
||||||
|
return remotePlaylistManager.onUpdate(playlists.get(0).getUid(), result).toFlowable();
|
||||||
|
}
|
||||||
|
|
||||||
private Subscriber<List<PlaylistRemoteEntity>> getPlaylistBookmarkSubscriber() {
|
private Subscriber<List<PlaylistRemoteEntity>> getPlaylistBookmarkSubscriber() {
|
||||||
return new Subscriber<List<PlaylistRemoteEntity>>() {
|
return new Subscriber<List<PlaylistRemoteEntity>>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,8 +40,11 @@ public class RemotePlaylistManager {
|
|||||||
}).subscribeOn(Schedulers.io());
|
}).subscribeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Single<Integer> onUpdate(final PlaylistInfo playlistInfo) {
|
public Single<Integer> onUpdate(final long playlistId, final PlaylistInfo playlistInfo) {
|
||||||
return Single.fromCallable(() -> playlistRemoteTable.update(new PlaylistRemoteEntity(playlistInfo)))
|
return Single.fromCallable(() -> {
|
||||||
.subscribeOn(Schedulers.io());
|
PlaylistRemoteEntity playlist = new PlaylistRemoteEntity(playlistInfo);
|
||||||
|
playlist.setUid(playlistId);
|
||||||
|
return playlistRemoteTable.update(playlist);
|
||||||
|
}).subscribeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user