From decb167ba9d7b0ecfb6ddadee775051a543a469b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 10 Jul 2018 16:26:42 +0200 Subject: [PATCH] make the new extractor refactorings work with SoundCloud --- app/build.gradle | 2 +- .../java/org/schabi/newpipe/MainActivity.java | 12 +- .../newpipe/fragments/MainFragment.java | 6 +- .../fragments/detail/VideoDetailFragment.java | 4 +- .../fragments/list/BaseListFragment.java | 13 +- .../fragments/list/BaseListInfoFragment.java | 6 +- .../list/channel/ChannelFragment.java | 16 +- .../fragments/list/kiosk/KioskFragment.java | 8 +- .../list/playlist/PlaylistFragment.java | 20 +-- .../fragments/list/search/SearchFragment.java | 166 ++++++++++-------- .../local/bookmark/BookmarkFragment.java | 4 +- .../subscription/SubscriptionFragment.java | 4 +- .../schabi/newpipe/util/ExtractorHelper.java | 27 ++- .../schabi/newpipe/util/NavigationHelper.java | 24 ++- .../schabi/newpipe/util/ServiceHelper.java | 1 - 15 files changed, 163 insertions(+), 150 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 396b79459..10aaf91a0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:4746a1c48a8682' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:a1aaca1be' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.8.9' diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 38ee4a1f8..f43d413e9 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -410,17 +410,13 @@ public class MainActivity extends AppCompatActivity { case CHANNEL: NavigationHelper.openChannelFragment(getSupportFragmentManager(), serviceId, - NewPipe.getService(serviceId) - .getChannelUIHFactory() - .fromUrl(url), + url, title); break; case PLAYLIST: NavigationHelper.openPlaylistFragment(getSupportFragmentManager(), serviceId, - NewPipe.getService(serviceId) - .getChannelUIHFactory() - .fromUrl(url), + url, title); break; } @@ -431,9 +427,7 @@ public class MainActivity extends AppCompatActivity { NavigationHelper.openSearchFragment( getSupportFragmentManager(), serviceId, - NewPipe.getService(serviceId) - .getSearchQIHFactory() - .fromQuery(searchString)); + searchString); } else { NavigationHelper.gotoMainFragment(getSupportFragmentManager()); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index cd4fc1baf..0e3312403 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -132,9 +132,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte NavigationHelper.openSearchFragment( getFragmentManager(), ServiceHelper.getSelectedServiceId(activity), - NewPipe.getService(currentServiceId) - .getSearchQIHFactory() - .fromQuery("")); + ""); } catch (Exception e) { ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); } @@ -237,7 +235,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte String name = preferences.getString(getString(R.string.main_page_selected_channel_name), FALLBACK_CHANNEL_NAME); ChannelFragment fragment = ChannelFragment.getInstance(serviceId, - NewPipe.getService(currentServiceId).getPlaylistUIHFactory().fromUrl(url), + url, name); fragment.useAsFrontPage(true); return fragment; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index fac6435dd..d91502cdd 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -371,9 +371,7 @@ public class VideoDetailFragment NavigationHelper.openChannelFragment( getFragmentManager(), currentInfo.getServiceId(), - NewPipe.getService(currentInfo.getServiceId()) - .getChannelUIHFactory() - .fromUrl(currentInfo.getUploaderUrl()), + currentInfo.getUploaderUrl(), currentInfo.getUploaderName()); } catch (Exception e) { ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index adf419795..c4702046d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -162,10 +162,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem getParentFragment().getFragmentManager() : getFragmentManager(), selectedItem.getServiceId(), - NewPipe.getService(selectedItem - .getServiceId()) - .getChannelUIHFactory() - .fromUrl(selectedItem.getUrl()), + selectedItem.getUrl(), selectedItem.getName()); } catch (Exception e) { ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); @@ -183,9 +180,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem ? getParentFragment().getFragmentManager() : getFragmentManager(), selectedItem.getServiceId(), - NewPipe.getService(selectedItem.getServiceId()) - .getPlaylistUIHFactory() - .fromUrl(selectedItem.getUrl()), + selectedItem.getUrl(), selectedItem.getName()); } catch (Exception e) { ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); @@ -204,7 +199,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem private void onStreamSelected(StreamInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openVideoDetailFragment(useAsFrontPage ? getParentFragment().getFragmentManager() : getFragmentManager(), + NavigationHelper.openVideoDetailFragment(useAsFrontPage + ? getParentFragment().getFragmentManager() + : getFragmentManager(), selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); } 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 270ba5550..9c3afb7f6 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 @@ -30,7 +30,7 @@ public abstract class BaseListInfoFragment @State protected String name; @State - protected ListUIHandler uiHandler; + protected String url; protected I currentInfo; protected String currentNextPageUrl; @@ -187,9 +187,9 @@ public abstract class BaseListInfoFragment // Utils //////////////////////////////////////////////////////////////////////////*/ - protected void setInitialData(int serviceId, ListUIHandler uiHandler, String name) { + protected void setInitialData(int serviceId, String url, String name) { this.serviceId = serviceId; - this.uiHandler = uiHandler; + this.url = url; this.name = !TextUtils.isEmpty(name) ? name : ""; } } 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 758b6506c..041b550ed 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 @@ -91,9 +91,9 @@ public class ChannelFragment extends BaseListInfoFragment { private MenuItem menuRssButton; - public static ChannelFragment getInstance(int serviceId, ListUIHandler uiHandler, String name) { + public static ChannelFragment getInstance(int serviceId, String url, String name) { ChannelFragment instance = new ChannelFragment(); - instance.setInitialData(serviceId, uiHandler, name); + instance.setInitialData(serviceId, url, name); return instance; } @@ -237,10 +237,10 @@ public class ChannelFragment extends BaseListInfoFragment { openRssFeed(); break; case R.id.menu_item_openInBrowser: - openUrlInBrowser(uiHandler.getUrl()); + openUrlInBrowser(url); break; case R.id.menu_item_share: - shareUrl(name, uiHandler.getUrl()); + shareUrl(name, url); break; default: return super.onOptionsItemSelected(item); @@ -406,12 +406,12 @@ public class ChannelFragment extends BaseListInfoFragment { @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreChannelItems(serviceId, uiHandler.getUrl(), currentNextPageUrl); + return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl); } @Override protected Single loadResult(boolean forceLoad) { - return ExtractorHelper.getChannelInfo(serviceId, uiHandler.getUrl(), forceLoad); + return ExtractorHelper.getChannelInfo(serviceId, url, forceLoad); } /*////////////////////////////////////////////////////////////////////////// @@ -489,7 +489,7 @@ public class ChannelFragment extends BaseListInfoFragment { if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_CHANNEL, NewPipe.getNameOfService(serviceId), - "Get next page of: " + uiHandler.getUrl(), R.string.general_error); + "Get next page of: " + url, R.string.general_error); } } @@ -505,7 +505,7 @@ public class ChannelFragment extends BaseListInfoFragment { onUnrecoverableError(exception, UserAction.REQUESTED_CHANNEL, NewPipe.getNameOfService(serviceId), - uiHandler.getUrl(), + url, errorId); return true; } 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 97e35f4c2..66ccfe6c3 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 @@ -75,7 +75,7 @@ public class KioskFragment extends BaseListInfoFragment { ListUIHFactory kioskUIHFactory = service.getKioskList() .getUIHFactoryByType(kioskId); instance.setInitialData(serviceId, - kioskUIHFactory.fromId(kioskId), kioskId); + kioskUIHFactory.fromId(kioskId).getUrl(), kioskId); instance.kioskId = kioskId; return instance; } @@ -135,7 +135,7 @@ public class KioskFragment extends BaseListInfoFragment { .getString(getString(R.string.content_country_key), getString(R.string.default_country_value)); return ExtractorHelper.getKioskInfo(serviceId, - uiHandler.getUrl(), + url, contentCountry, forceReload); } @@ -147,7 +147,7 @@ public class KioskFragment extends BaseListInfoFragment { .getString(getString(R.string.content_country_key), getString(R.string.default_country_value)); return ExtractorHelper.getMoreKioskItems(serviceId, - uiHandler.getUrl(), + url, currentNextPageUrl, contentCountry); } @@ -183,7 +183,7 @@ public class KioskFragment extends BaseListInfoFragment { if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId) - , "Get next page of: " + uiHandler.getUrl(), 0); + , "Get next page of: " + url, 0); } } } 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 b7df1e0c3..2f60276d7 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 @@ -83,9 +83,9 @@ public class PlaylistFragment extends BaseListInfoFragment { private MenuItem playlistBookmarkButton; - public static PlaylistFragment getInstance(int serviceId, ListUIHandler uiHandler, String name) { + public static PlaylistFragment getInstance(int serviceId, String url, String name) { PlaylistFragment instance = new PlaylistFragment(); - instance.setInitialData(serviceId, uiHandler, name); + instance.setInitialData(serviceId, url, name); return instance; } @@ -220,22 +220,22 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMorePlaylistItems(serviceId, uiHandler.getUrl(), currentNextPageUrl); + return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl); } @Override protected Single loadResult(boolean forceLoad) { - return ExtractorHelper.getPlaylistInfo(serviceId, uiHandler.getUrl(), forceLoad); + return ExtractorHelper.getPlaylistInfo(serviceId, url, forceLoad); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_openInBrowser: - openUrlInBrowser(uiHandler.getUrl()); + openUrlInBrowser(url); break; case R.id.menu_item_share: - shareUrl(name, uiHandler.getUrl()); + shareUrl(name, url); break; case R.id.menu_item_bookmark: onBookmarkClicked(); @@ -275,9 +275,7 @@ public class PlaylistFragment extends BaseListInfoFragment { try { NavigationHelper.openChannelFragment(getFragmentManager(), result.getServiceId(), - NewPipe.getService(serviceId) - .getChannelUIHFactory() - .fromUrl(result.getUploaderUrl()), + result.getUploaderUrl(), result.getUploaderName()); } catch (Exception e) { ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); @@ -337,7 +335,7 @@ public class PlaylistFragment extends BaseListInfoFragment { if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId) - , "Get next page of: " + uiHandler.getUrl(), 0); + , "Get next page of: " + url, 0); } } @@ -353,7 +351,7 @@ public class PlaylistFragment extends BaseListInfoFragment { onUnrecoverableError(exception, UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId), - uiHandler.getUrl(), + url, errorId); return true; } 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 ee76966ff..503bc86ee 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 @@ -29,12 +29,15 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; +import com.facebook.stetho.common.ListUtil; + import org.schabi.newpipe.R; import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.database.history.model.SearchHistoryEntry; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.search.SearchExtractor; @@ -55,6 +58,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.net.SocketException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Queue; @@ -69,6 +73,8 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import static java.util.Arrays.asList; + import static org.schabi.newpipe.util.AnimationUtils.animateView; public class SearchFragment @@ -95,10 +101,19 @@ public class SearchFragment @State protected int serviceId = Constants.NO_SERVICE_ID; + + // this three represet the current search query @State - protected SearchQIHandler searchQuery; + protected String searchString; @State - protected SearchQIHandler lastSearchedQuery; + protected String[] contentFilter; + @State + protected String sortFilter; + + // these represtent the last search + @State + protected String lastSearchedString; + @State protected boolean wasSearchFocused = false; @@ -130,11 +145,11 @@ public class SearchFragment /*////////////////////////////////////////////////////////////////////////*/ - public static SearchFragment getInstance(int serviceId, SearchQIHandler query) { + public static SearchFragment getInstance(int serviceId, String searchString) { SearchFragment searchFragment = new SearchFragment(); - searchFragment.setQuery(serviceId, query); + searchFragment.setQuery(serviceId, searchString, new String[0], ""); - if (!TextUtils.isEmpty(query.getSearchString())) { + if (!TextUtils.isEmpty(searchString)) { searchFragment.setSearchOnResume(); } @@ -212,12 +227,12 @@ public class SearchFragment "", R.string.general_error)); } - if (!TextUtils.isEmpty(searchQuery.getSearchString())) { + if (!TextUtils.isEmpty(searchString)) { if (wasLoading.getAndSet(false)) { - search(searchQuery); + search(searchString, contentFilter, sortFilter); } else if (infoListAdapter.getItemsList().size() == 0) { if (savedState == null) { - search(searchQuery); + search(searchString, contentFilter, sortFilter); } else if (!isLoading.get() && !wasSearchFocused) { infoListAdapter.clearStreamItemList(); showEmptyState(); @@ -227,7 +242,7 @@ public class SearchFragment if (suggestionDisposable == null || suggestionDisposable.isDisposed()) initSuggestionObserver(); - if (TextUtils.isEmpty(searchQuery.getSearchString()) || wasSearchFocused) { + if (TextUtils.isEmpty(searchString) || wasSearchFocused) { showKeyboardSearch(); showSuggestionsPanel(); } else { @@ -257,8 +272,8 @@ public class SearchFragment switch (requestCode) { case ReCaptchaActivity.RECAPTCHA_REQUEST: if (resultCode == Activity.RESULT_OK - && !TextUtils.isEmpty(searchQuery.getSearchString())) { - search(searchQuery); + && !TextUtils.isEmpty(searchString)) { + search(searchString, contentFilter, sortFilter); } else Log.e(TAG, "ReCaptcha failed"); break; @@ -305,18 +320,9 @@ public class SearchFragment @Override public void onSaveInstanceState(Bundle bundle) { - try { - searchQuery = searchEditText != null - ? NewPipe.getService(serviceId).getSearchQIHFactory().fromQuery( - searchEditText.getText().toString()) - : searchQuery; - } catch (Exception e) { - ErrorActivity.reportError(getActivity(), e, getActivity().getClass(), - getActivity().findViewById(android.R.id.content), - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, - "", - "", R.string.general_error)); - } + searchString = searchEditText != null + ? searchEditText.getText().toString() + : searchString; super.onSaveInstanceState(bundle); } @@ -326,12 +332,11 @@ public class SearchFragment @Override public void reloadContent() { - if (!TextUtils.isEmpty(searchQuery.getSearchString()) + if (!TextUtils.isEmpty(searchString) || (searchEditText != null && !TextUtils.isEmpty(searchEditText.getText()))) { - search(!TextUtils.isEmpty(searchQuery.getSearchString()) - ? searchQuery - : getSearchQuery(searchEditText.getText().toString(), - new ArrayList<>(0), "")); + search(!TextUtils.isEmpty(searchString) + ? searchString + : searchEditText.getText().toString(), new String[0], ""); } else { if (searchEditText != null) { searchEditText.setText(""); @@ -387,14 +392,21 @@ public class SearchFragment private TextWatcher textWatcher; private void showSearchOnStart() { - if (DEBUG) Log.d(TAG, "showSearchOnStart() called, searchQuery → " + searchQuery+", lastSearchedQuery → " + lastSearchedQuery); - searchEditText.setText(searchQuery.getSearchString()); + if (DEBUG) Log.d(TAG, "showSearchOnStart() called, searchQuery → " + + searchString + + ", lastSearchedQuery → " + + lastSearchedString); + searchEditText.setText(searchString); - if (TextUtils.isEmpty(searchQuery.getSearchString()) || TextUtils.isEmpty(searchEditText.getText())) { + if (TextUtils.isEmpty(searchString) || TextUtils.isEmpty(searchEditText.getText())) { searchToolbarContainer.setTranslationX(100); searchToolbarContainer.setAlpha(0f); searchToolbarContainer.setVisibility(View.VISIBLE); - searchToolbarContainer.animate().translationX(0).alpha(1f).setDuration(200).setInterpolator(new DecelerateInterpolator()).start(); + searchToolbarContainer.animate() + .translationX(0) + .alpha(1f) + .setDuration(200) + .setInterpolator(new DecelerateInterpolator()).start(); } else { searchToolbarContainer.setTranslationX(0); searchToolbarContainer.setAlpha(1f); @@ -435,7 +447,7 @@ public class SearchFragment suggestionListAdapter.setListener(new SuggestionListAdapter.OnSuggestionItemSelected() { @Override public void onSuggestionItemSelected(SuggestionItem item) { - search(getSearchQuery(item.query, new ArrayList<>(), "")); + search(item.query, new String[0], ""); searchEditText.setText(item.query); } @@ -476,7 +488,7 @@ public class SearchFragment if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER || event.getAction() == EditorInfo.IME_ACTION_SEARCH)) { - search(getSearchQuery(searchEditText.getText().toString(), new ArrayList<>(), "")); + search(searchEditText.getText().toString(), new String[0], ""); return true; } return false; @@ -557,10 +569,12 @@ public class SearchFragment @Override public boolean onBackPressed() { - if (suggestionsPanel.getVisibility() == View.VISIBLE && infoListAdapter.getItemsList().size() > 0 && !isLoading.get()) { + if (suggestionsPanel.getVisibility() == View.VISIBLE + && infoListAdapter.getItemsList().size() > 0 + && !isLoading.get()) { hideSuggestionsPanel(); hideKeyboardSearch(); - searchEditText.setText(lastSearchedQuery.getSearchString()); + searchEditText.setText(lastSearchedString); return true; } return false; @@ -576,8 +590,8 @@ public class SearchFragment final Observable observable = suggestionPublisher .debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS) - .startWith(searchQuery != null - ? searchQuery.getSearchString() + .startWith(searchString != null + ? searchString : "") .filter(searchString -> isSuggestionsEnabled); @@ -650,17 +664,17 @@ public class SearchFragment // no-op } - private void search(final SearchQIHandler query) { - if (DEBUG) Log.d(TAG, "search() called with: query = [" + query + "]"); - if (query.getSearchString().isEmpty()) return; + private void search(final String searchString, String[] contentFilter, String sortFilter) { + if (DEBUG) Log.d(TAG, "search() called with: query = [" + searchString + "]"); + if (searchString.isEmpty()) return; try { - final StreamingService service = NewPipe.getServiceByUrl(query.getUrl()); + final StreamingService service = NewPipe.getServiceByUrl(searchString); if (service != null) { showLoading(); disposables.add(Observable .fromCallable(() -> - NavigationHelper.getIntentByLink(activity, service, query.getUrl())) + NavigationHelper.getIntentByLink(activity, service, searchString)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(intent -> { @@ -674,21 +688,20 @@ public class SearchFragment // Exception occurred, it's not a url } - lastSearchedQuery = query; - searchQuery = query; - currentPageUrl = ""; + lastSearchedString = this.searchString; + this.searchString = searchString; infoListAdapter.clearStreamItemList(); hideSuggestionsPanel(); hideKeyboardSearch(); - historyRecordManager.onSearched(serviceId, query.getSearchString()) + historyRecordManager.onSearched(serviceId, searchString) .observeOn(AndroidSchedulers.mainThread()) .subscribe( ignored -> {}, error -> showSnackBarError(error, UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), query.getSearchString(), 0) + NewPipe.getNameOfService(serviceId), searchString, 0) ); - suggestionPublisher.onNext(query.getSearchString()); + suggestionPublisher.onNext(searchString); startLoading(false); } @@ -697,11 +710,16 @@ public class SearchFragment super.startLoading(forceLoad); if (disposables != null) disposables.clear(); if (searchDisposable != null) searchDisposable.dispose(); - searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, contentCountry) + searchDisposable = ExtractorHelper.searchFor(serviceId, + searchString, + Arrays.asList(contentFilter), + sortFilter, + contentCountry) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((searchResult, throwable) -> isLoading.set(false)) .subscribe(this::handleResult, this::onError); + } @Override @@ -709,8 +727,13 @@ public class SearchFragment isLoading.set(true); showListFooter(true); if (searchDisposable != null) searchDisposable.dispose(); - searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, - searchQuery, nextPageUrl, contentCountry) + searchDisposable = ExtractorHelper.getMoreSearchItems( + serviceId, + searchString, + asList(contentFilter), + sortFilter, + nextPageUrl, + contentCountry) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((nextItemsResult, throwable) -> isLoading.set(false)) @@ -737,31 +760,18 @@ public class SearchFragment this.filterItemCheckedId = item.getItemId(); item.setChecked(true); - searchQuery = getSearchQuery(searchQuery.getSearchString(), contentFilter, ""); + this.contentFilter = new String[] {contentFilter.get(0)}; - if (!TextUtils.isEmpty(searchQuery.getSearchString())) { - search(searchQuery); + if (!TextUtils.isEmpty(searchString)) { + search(searchString, this.contentFilter, sortFilter); } } - private void setQuery(int serviceId, SearchQIHandler searchQuery) { + private void setQuery(int serviceId, String searchString, String[] contentfilter, String sortFilter) { this.serviceId = serviceId; - this.searchQuery = searchQuery; - } - - private SearchQIHandler getSearchQuery(String searchString, - List contentFilter, - String sortFilter) { - try { - return service.getSearchQIHFactory() - .fromQuery(searchString, contentFilter, sortFilter); - } catch (Exception e) { - onUnrecoverableError(e, UserAction.SEARCHED, - service.getServiceInfo().getName(), - searchQuery.getSearchString(), - R.string.general_error); - } - return searchQuery; + this.searchString = searchString; + this.contentFilter = contentfilter; + this.sortFilter = sortFilter; } /*////////////////////////////////////////////////////////////////////////// @@ -786,7 +796,7 @@ public class SearchFragment ? R.string.parsing_error : R.string.general_error; onUnrecoverableError(exception, UserAction.GET_SUGGESTIONS, - NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), errorId); + NewPipe.getNameOfService(serviceId), searchString, errorId); } /*////////////////////////////////////////////////////////////////////////// @@ -814,10 +824,12 @@ public class SearchFragment public void handleResult(@NonNull SearchInfo result) { if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), 0); + NewPipe.getNameOfService(serviceId), searchString, 0); } - lastSearchedQuery = searchQuery; + lastSearchedString = searchString; + nextPageUrl = result.getNextPageUrl(); + currentPageUrl = result.getUrl(); if (infoListAdapter.getItemsList().size() == 0) { if (!result.getRelatedItems().isEmpty()) { @@ -841,7 +853,7 @@ public class SearchFragment if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.SEARCHED, NewPipe.getNameOfService(serviceId) - , "\"" + searchQuery + "\" → page: " + nextPageUrl, 0); + , "\"" + searchString + "\" → page: " + nextPageUrl, 0); } super.handleNextItems(result); } @@ -858,7 +870,7 @@ public class SearchFragment ? R.string.parsing_error : R.string.general_error; onUnrecoverableError(exception, UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), errorId); + NewPipe.getNameOfService(serviceId), searchString, errorId); } return true; diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index a7e16a5f1..02eabd9ef 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -117,9 +117,7 @@ public final class BookmarkFragment NavigationHelper.openPlaylistFragment( fragmentManager, entry.getServiceId(), - NewPipe.getService(entry.getServiceId()) - .getPlaylistUIHFactory() - .fromUrl(entry.getUrl()), + entry.getUrl(), entry.getName()); } } catch (Exception e) { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java index 9bbb5f517..c194069fb 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java @@ -324,9 +324,7 @@ public class SubscriptionFragment extends BaseStateFragment searchFor(final int serviceId, - final SearchQIHandler query, + final String searchString, + final List contentFilter, + final String sortFilter, final String contentCountry) { checkServiceId(serviceId); return Single.fromCallable(() -> - SearchInfo.getInfo(NewPipe.getService(serviceId).getSearchExtractor(query, contentCountry))); + SearchInfo.getInfo(NewPipe.getService(serviceId), + NewPipe.getService(serviceId) + .getSearchQIHFactory() + .fromQuery(searchString, contentFilter, sortFilter), + contentCountry)); } public static Single getMoreSearchItems(final int serviceId, - final SearchQIHandler query, - final String pageUrl, - final String contentCountry) { + final String searchString, + final List contentFilter, + final String sortFilter, + final String pageUrl, + final String contentCountry) { checkServiceId(serviceId); return Single.fromCallable(() -> - SearchInfo.getMoreItems(NewPipe.getService(serviceId), query, contentCountry, pageUrl)); + SearchInfo.getMoreItems(NewPipe.getService(serviceId), + NewPipe.getService(serviceId) + .getSearchQIHFactory() + .fromQuery(searchString, contentFilter, sortFilter), + contentCountry, + pageUrl)); } @@ -225,7 +237,6 @@ public final class ExtractorHelper { serviceId == -1 ? "none" : NewPipe.getNameOfService(serviceId), url + (optionalErrorMessage == null ? "" : optionalErrorMessage), errorId)); } }); - } /** diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 0344e5e79..2271d79e1 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -286,9 +286,11 @@ public class NavigationHelper { return fragmentManager.popBackStackImmediate(SEARCH_FRAGMENT_TAG, 0); } - public static void openSearchFragment(FragmentManager fragmentManager, int serviceId, SearchQIHandler query) { + public static void openSearchFragment(FragmentManager fragmentManager, + int serviceId, + String searchString) { defaultTransaction(fragmentManager) - .replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, query)) + .replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, searchString)) .addToBackStack(SEARCH_FRAGMENT_TAG) .commit(); } @@ -317,18 +319,25 @@ public class NavigationHelper { .commit(); } - public static void openChannelFragment(FragmentManager fragmentManager, int serviceId, ListUIHandler uiHandler, String name) { + public static void openChannelFragment( + FragmentManager fragmentManager, + int serviceId, + String url, + String name) { if (name == null) name = ""; defaultTransaction(fragmentManager) - .replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, uiHandler, name)) + .replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, url, name)) .addToBackStack(null) .commit(); } - public static void openPlaylistFragment(FragmentManager fragmentManager, int serviceId, ListUIHandler uiHandler, String name) { + public static void openPlaylistFragment(FragmentManager fragmentManager, + int serviceId, + String url, + String name) { if (name == null) name = ""; defaultTransaction(fragmentManager) - .replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, uiHandler, name)) + .replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, url, name)) .addToBackStack(null) .commit(); } @@ -470,7 +479,8 @@ public class NavigationHelper { switch (linkType) { case STREAM: - rIntent.putExtra(VideoDetailFragment.AUTO_PLAY, PreferenceManager.getDefaultSharedPreferences(context) + rIntent.putExtra(VideoDetailFragment.AUTO_PLAY, + PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(context.getString(R.string.autoplay_through_intent_key), false)); break; } diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index d86f27f2f..e7e52f393 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -5,7 +5,6 @@ import android.preference.PreferenceManager; import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; -import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList;