From a42da09d6c8348ce88881da6129704e23e67eb0b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 24 Feb 2018 22:57:25 +0100 Subject: [PATCH] make NewPipe compatible with latest Extractor refactorings --- app/build.gradle | 2 +- .../fragments/list/BaseListInfoFragment.java | 25 ++++++++++--------- .../list/channel/ChannelFragment.java | 8 +++--- .../fragments/list/kiosk/KioskFragment.java | 6 ++--- .../list/playlist/PlaylistFragment.java | 8 +++--- .../fragments/list/search/SearchFragment.java | 10 ++++---- .../playlist/AbstractInfoPlayQueue.java | 12 ++++----- .../newpipe/playlist/ChannelPlayQueue.java | 4 +-- .../newpipe/playlist/PlaylistPlayQueue.java | 4 +-- .../schabi/newpipe/util/ExtractorHelper.java | 12 ++++----- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ea4d5384d..c5887faed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java index 8a26d81aa..34f190032 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java @@ -19,7 +19,8 @@ import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; -public abstract class BaseListInfoFragment extends BaseListFragment { +public abstract class BaseListInfoFragment + extends BaseListFragment { @State protected int serviceId = Constants.NO_SERVICE_ID; @@ -29,7 +30,7 @@ public abstract class BaseListInfoFragment 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 extends BaseListF public void writeTo(Queue objectsToSave) { super.writeTo(objectsToSave); objectsToSave.add(currentInfo); - objectsToSave.add(currentNextItemsUrl); + objectsToSave.add(currentNextPageUrl); } @Override @@ -81,7 +82,7 @@ public abstract class BaseListInfoFragment extends BaseListF public void readFrom(@NonNull Queue 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 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 extends BaseListF * Implement the logic to load more items
* You can use the default implementations from {@link org.schabi.newpipe.util.ExtractorHelper} */ - protected abstract Single loadMoreItemsLogic(); + protected abstract Single loadMoreItemsLogic(); protected void loadMoreItems() { isLoading.set(true); @@ -134,9 +135,9 @@ public abstract class BaseListInfoFragment 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 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); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index a7f513de9..19b0be8f8 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -388,8 +388,8 @@ public class ChannelFragment extends BaseListInfoFragment { //////////////////////////////////////////////////////////////////////////*/ @Override - protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextItemsUrl); + protected Single loadMoreItemsLogic() { + return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl); } @Override @@ -464,14 +464,14 @@ public class ChannelFragment extends BaseListInfoFragment { 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()) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 830471b73..976bcced2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -141,12 +141,12 @@ public class KioskFragment extends BaseListInfoFragment { } @Override - public Single loadMoreItemsLogic() { + public Single 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 { } @Override - public void handleNextItems(ListExtractor.NextItemsResult result) { + public void handleNextItems(ListExtractor.InfoItemPage result) { super.handleNextItems(result); if (!result.getErrors().isEmpty()) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index db382ef5d..324d3d7ef 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -206,8 +206,8 @@ public class PlaylistFragment extends BaseListInfoFragment { //////////////////////////////////////////////////////////////////////////*/ @Override - protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextItemsUrl); + protected Single loadMoreItemsLogic() { + return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl); } @Override @@ -300,14 +300,14 @@ public class PlaylistFragment extends BaseListInfoFragment { 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()) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 0638c06e7..9c9aeb080 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -71,7 +71,7 @@ import io.reactivex.subjects.PublishSubject; import static org.schabi.newpipe.util.AnimationUtils.animateView; -public class SearchFragment extends BaseListFragment implements BackPressable { +public class SearchFragment extends BaseListFragment implements BackPressable { /*////////////////////////////////////////////////////////////////////////// // Search @@ -725,9 +725,9 @@ public class SearchFragment extends BaseListFragment() { + .subscribe(new Consumer() { @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 ext }; } - SingleObserver getNextItemsObserver() { - return new SingleObserver() { + SingleObserver getNextPageObserver() { + return new SingleObserver() { @Override public void onSubscribe(@NonNull Disposable d) { if (isComplete || isInitial || (fetchReactor != null && !fetchReactor.isDisposed())) { @@ -95,11 +95,11 @@ abstract class AbstractInfoPlayQueue 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; diff --git a/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java index d3e31982a..a5ecad027 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java @@ -16,7 +16,7 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue getMoreSearchItems(final int serviceId, + public static Single 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 getMoreChannelItems(final int serviceId, + public static Single 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 getMorePlaylistItems(final int serviceId, + public static Single 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 getMoreKioskItems(final int serviceId, + public static Single getMoreKioskItems(final int serviceId, final String url, final String nextStreamsUrl, final String contentCountry) {