1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

make NewPipe compatible with latest Extractor refactorings

This commit is contained in:
Christian Schabesberger 2018-02-24 22:57:25 +01:00
parent 72a9940863
commit a42da09d6c
10 changed files with 46 additions and 45 deletions

View File

@ -55,7 +55,7 @@ dependencies {
exclude module: 'support-annotations'
}
implementation 'com.github.TeamNewPipe:NewPipeExtractor:7716b1437815'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:86db415b181'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'

View File

@ -19,7 +19,8 @@ import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListFragment<I, ListExtractor.NextItemsResult> {
public abstract class BaseListInfoFragment<I extends ListInfo>
extends BaseListFragment<I, ListExtractor.InfoItemPage> {
@State
protected int serviceId = Constants.NO_SERVICE_ID;
@ -29,7 +30,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
protected String url;
protected I currentInfo;
protected String currentNextItemsUrl;
protected String currentNextPageUrl;
protected Disposable currentWorker;
@Override
@ -73,7 +74,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
public void writeTo(Queue<Object> objectsToSave) {
super.writeTo(objectsToSave);
objectsToSave.add(currentInfo);
objectsToSave.add(currentNextItemsUrl);
objectsToSave.add(currentNextPageUrl);
}
@Override
@ -81,7 +82,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
public void readFrom(@NonNull Queue<Object> savedObjects) throws Exception {
super.readFrom(savedObjects);
currentInfo = (I) savedObjects.poll();
currentNextItemsUrl = (String) savedObjects.poll();
currentNextPageUrl = (String) savedObjects.poll();
}
/*//////////////////////////////////////////////////////////////////////////
@ -116,7 +117,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
.subscribe((@NonNull I result) -> {
isLoading.set(false);
currentInfo = result;
currentNextItemsUrl = result.next_streams_url;
currentNextPageUrl = result.next_streams_url;
handleResult(result);
}, (@NonNull Throwable throwable) -> onError(throwable));
}
@ -125,7 +126,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
* Implement the logic to load more items<br/>
* You can use the default implementations from {@link org.schabi.newpipe.util.ExtractorHelper}
*/
protected abstract Single<ListExtractor.NextItemsResult> loadMoreItemsLogic();
protected abstract Single<ListExtractor.InfoItemPage> loadMoreItemsLogic();
protected void loadMoreItems() {
isLoading.set(true);
@ -134,9 +135,9 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
currentWorker = loadMoreItemsLogic()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@io.reactivex.annotations.NonNull ListExtractor.NextItemsResult nextItemsResult) -> {
.subscribe((@io.reactivex.annotations.NonNull ListExtractor.InfoItemPage InfoItemPage) -> {
isLoading.set(false);
handleNextItems(nextItemsResult);
handleNextItems(InfoItemPage);
}, (@io.reactivex.annotations.NonNull Throwable throwable) -> {
isLoading.set(false);
onError(throwable);
@ -144,17 +145,17 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
}
@Override
public void handleNextItems(ListExtractor.NextItemsResult result) {
public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result);
currentNextItemsUrl = result.nextItemsUrl;
infoListAdapter.addInfoItemList(result.nextItemsList);
currentNextPageUrl = result.nextPageUrl;
infoListAdapter.addInfoItemList(result.infoItemList);
showListFooter(hasMoreItems());
}
@Override
protected boolean hasMoreItems() {
return !TextUtils.isEmpty(currentNextItemsUrl);
return !TextUtils.isEmpty(currentNextPageUrl);
}
/*//////////////////////////////////////////////////////////////////////////

View File

@ -388,8 +388,8 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
//////////////////////////////////////////////////////////////////////////*/
@Override
protected Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextItemsUrl);
protected Single<ListExtractor.InfoItemPage> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl);
}
@Override
@ -464,14 +464,14 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
return new ChannelPlayQueue(
currentInfo.getServiceId(),
currentInfo.getUrl(),
currentInfo.getNextStreamsUrl(),
currentInfo.getNextPageUrl(),
infoListAdapter.getItemsList(),
index
);
}
@Override
public void handleNextItems(ListExtractor.NextItemsResult result) {
public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result);
if (!result.getErrors().isEmpty()) {

View File

@ -141,12 +141,12 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
}
@Override
public Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() {
public Single<ListExtractor.InfoItemPage> loadMoreItemsLogic() {
String contentCountry = PreferenceManager
.getDefaultSharedPreferences(activity)
.getString(getString(R.string.content_country_key),
getString(R.string.default_country_value));
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextItemsUrl, contentCountry);
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPageUrl, contentCountry);
}
/*//////////////////////////////////////////////////////////////////////////
@ -174,7 +174,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
}
@Override
public void handleNextItems(ListExtractor.NextItemsResult result) {
public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result);
if (!result.getErrors().isEmpty()) {

View File

@ -206,8 +206,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
//////////////////////////////////////////////////////////////////////////*/
@Override
protected Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextItemsUrl);
protected Single<ListExtractor.InfoItemPage> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl);
}
@Override
@ -300,14 +300,14 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
return new PlaylistPlayQueue(
currentInfo.getServiceId(),
currentInfo.getUrl(),
currentInfo.getNextStreamsUrl(),
currentInfo.getNextPageUrl(),
infoListAdapter.getItemsList(),
index
);
}
@Override
public void handleNextItems(ListExtractor.NextItemsResult result) {
public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result);
if (!result.getErrors().isEmpty()) {

View File

@ -71,7 +71,7 @@ import io.reactivex.subjects.PublishSubject;
import static org.schabi.newpipe.util.AnimationUtils.animateView;
public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor.NextItemsResult> implements BackPressable {
public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor.InfoItemPage> implements BackPressable {
/*//////////////////////////////////////////////////////////////////////////
// Search
@ -725,9 +725,9 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchQuery, currentNextPage, contentCountry, filter)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ListExtractor.NextItemsResult>() {
.subscribe(new Consumer<ListExtractor.InfoItemPage>() {
@Override
public void accept(@NonNull ListExtractor.NextItemsResult result) throws Exception {
public void accept(@NonNull ListExtractor.InfoItemPage result) throws Exception {
isLoading.set(false);
handleNextItems(result);
}
@ -841,9 +841,9 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
}
@Override
public void handleNextItems(ListExtractor.NextItemsResult result) {
public void handleNextItems(ListExtractor.InfoItemPage result) {
showListFooter(false);
currentPage = Integer.parseInt(result.getNextItemsUrl());
currentPage = Integer.parseInt(result.getNextPageUrl());
infoListAdapter.addInfoItemList(result.getNextItemsList());
if (!result.getErrors().isEmpty()) {

View File

@ -83,8 +83,8 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
};
}
SingleObserver<ListExtractor.NextItemsResult> getNextItemsObserver() {
return new SingleObserver<ListExtractor.NextItemsResult>() {
SingleObserver<ListExtractor.InfoItemPage> getNextPageObserver() {
return new SingleObserver<ListExtractor.InfoItemPage>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
if (isComplete || isInitial || (fetchReactor != null && !fetchReactor.isDisposed())) {
@ -95,11 +95,11 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
}
@Override
public void onSuccess(@NonNull ListExtractor.NextItemsResult result) {
if (!result.hasMoreStreams()) isComplete = true;
nextUrl = result.nextItemsUrl;
public void onSuccess(@NonNull ListExtractor.InfoItemPage result) {
if (!result.hasNextPage()) isComplete = true;
nextUrl = result.nextPageUrl;
append(extractListItems(result.nextItemsList));
append(extractListItems(result.infoItemList));
fetchReactor.dispose();
fetchReactor = null;

View File

@ -16,7 +16,7 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue<ChannelInfo, C
}
public ChannelPlayQueue(final ChannelInfo info) {
this(info.getServiceId(), info.getUrl(), info.getNextStreamsUrl(), info.getRelatedStreams(), 0);
this(info.getServiceId(), info.getUrl(), info.getNextPageUrl(), info.getRelatedStreams(), 0);
}
public ChannelPlayQueue(final int serviceId,
@ -43,7 +43,7 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue<ChannelInfo, C
ExtractorHelper.getMoreChannelItems(this.serviceId, this.baseUrl, this.nextUrl)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getNextItemsObserver());
.subscribe(getNextPageObserver());
}
}
}

View File

@ -16,7 +16,7 @@ public final class PlaylistPlayQueue extends AbstractInfoPlayQueue<PlaylistInfo,
}
public PlaylistPlayQueue(final PlaylistInfo info) {
this(info.getServiceId(), info.getUrl(), info.getNextStreamsUrl(), info.getRelatedStreams(), 0);
this(info.getServiceId(), info.getUrl(), info.getNextPageUrl(), info.getRelatedStreams(), 0);
}
public PlaylistPlayQueue(final int serviceId,
@ -43,7 +43,7 @@ public final class PlaylistPlayQueue extends AbstractInfoPlayQueue<PlaylistInfo,
ExtractorHelper.getMorePlaylistItems(this.serviceId, this.baseUrl, this.nextUrl)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getNextItemsObserver());
.subscribe(getNextPageObserver());
}
}
}

View File

@ -29,7 +29,7 @@ import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemPage;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
@ -78,7 +78,7 @@ public final class ExtractorHelper {
);
}
public static Single<NextItemsResult> getMoreSearchItems(final int serviceId,
public static Single<InfoItemPage> getMoreSearchItems(final int serviceId,
final String query,
final int nextPageNumber,
final String searchLanguage,
@ -86,7 +86,7 @@ public final class ExtractorHelper {
checkServiceId(serviceId);
return searchFor(serviceId, query, nextPageNumber, searchLanguage, filter)
.map((@NonNull SearchResult searchResult) ->
new NextItemsResult(searchResult.resultList,
new InfoItemPage(searchResult.resultList,
nextPageNumber + "",
searchResult.errors));
}
@ -117,7 +117,7 @@ public final class ExtractorHelper {
ChannelInfo.getInfo(NewPipe.getService(serviceId), url)));
}
public static Single<NextItemsResult> getMoreChannelItems(final int serviceId,
public static Single<InfoItemPage> getMoreChannelItems(final int serviceId,
final String url,
final String nextStreamsUrl) {
checkServiceId(serviceId);
@ -133,7 +133,7 @@ public final class ExtractorHelper {
PlaylistInfo.getInfo(NewPipe.getService(serviceId), url)));
}
public static Single<NextItemsResult> getMorePlaylistItems(final int serviceId,
public static Single<InfoItemPage> getMorePlaylistItems(final int serviceId,
final String url,
final String nextStreamsUrl) {
checkServiceId(serviceId);
@ -149,7 +149,7 @@ public final class ExtractorHelper {
KioskInfo.getInfo(NewPipe.getService(serviceId), url, contentCountry)));
}
public static Single<NextItemsResult> getMoreKioskItems(final int serviceId,
public static Single<InfoItemPage> getMoreKioskItems(final int serviceId,
final String url,
final String nextStreamsUrl,
final String contentCountry) {