From d10f9a5f25e7acac7f089f2492c8e9b7d036579b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 14:27:12 +0200 Subject: [PATCH 1/6] add getMoreInfo to SearchInfo --- app/build.gradle | 2 +- .../fragments/list/search/SearchFragment.java | 295 ++++++++++-------- .../schabi/newpipe/util/ExtractorHelper.java | 30 +- 3 files changed, 175 insertions(+), 152 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c41535163..503a3e469 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:bf1c771' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:39332a283b1c911' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.8.9' 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 d07ff6448..e57cdbd31 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 @@ -38,10 +38,13 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchInfo; import org.schabi.newpipe.extractor.search.SearchResult; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.list.BaseListFragment; import org.schabi.newpipe.local.history.HistoryRecordManager; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.AnimationUtils; @@ -56,7 +59,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Queue; -import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import icepick.State; @@ -65,14 +68,13 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; import static org.schabi.newpipe.util.AnimationUtils.animateView; public class SearchFragment - extends BaseListFragment + extends BaseListFragment implements BackPressable { /*////////////////////////////////////////////////////////////////////////// @@ -92,19 +94,21 @@ public class SearchFragment @State protected int filterItemCheckedId = -1; - private SearchEngine.Filter filter = SearchEngine.Filter.ANY; @State protected int serviceId = Constants.NO_SERVICE_ID; @State - protected String searchQuery; + protected SearchQIHandler searchQuery; @State - protected String lastSearchedQuery; + protected SearchQIHandler lastSearchedQuery; @State protected boolean wasSearchFocused = false; + @State + List contentFilter; - private int currentPage = 0; - private int currentNextPage = 0; + private StreamingService service; + private String currentPageUrl; + private String nextPageUrl; private String contentCountry; private boolean isSuggestionsEnabled = true; private boolean isSearchHistoryEnabled = true; @@ -130,11 +134,11 @@ public class SearchFragment /*////////////////////////////////////////////////////////////////////////*/ - public static SearchFragment getInstance(int serviceId, String query) { + public static SearchFragment getInstance(int serviceId, SearchQIHandler query) { SearchFragment searchFragment = new SearchFragment(); searchFragment.setQuery(serviceId, query); - if (!TextUtils.isEmpty(query)) { + if (!TextUtils.isEmpty(query.getSearchString())) { searchFragment.setSearchOnResume(); } @@ -202,10 +206,19 @@ public class SearchFragment if (DEBUG) Log.d(TAG, "onResume() called"); super.onResume(); - if (!TextUtils.isEmpty(searchQuery)) { + try { + service = NewPipe.getService(serviceId); + } 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)); + } + + if (!TextUtils.isEmpty(searchQuery.getSearchString())) { if (wasLoading.getAndSet(false)) { - if (currentNextPage > currentPage) loadMoreItems(); - else search(searchQuery); + search(searchQuery); } else if (infoListAdapter.getItemsList().size() == 0) { if (savedState == null) { search(searchQuery); @@ -218,7 +231,7 @@ public class SearchFragment if (suggestionDisposable == null || suggestionDisposable.isDisposed()) initSuggestionObserver(); - if (TextUtils.isEmpty(searchQuery) || wasSearchFocused) { + if (TextUtils.isEmpty(searchQuery.getSearchString()) || wasSearchFocused) { showKeyboardSearch(); showSuggestionsPanel(); } else { @@ -247,7 +260,8 @@ public class SearchFragment public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case ReCaptchaActivity.RECAPTCHA_REQUEST: - if (resultCode == Activity.RESULT_OK && !TextUtils.isEmpty(searchQuery)) { + if (resultCode == Activity.RESULT_OK + && !TextUtils.isEmpty(searchQuery.getSearchString())) { search(searchQuery); } else Log.e(TAG, "ReCaptcha failed"); break; @@ -282,20 +296,31 @@ public class SearchFragment @Override public void writeTo(Queue objectsToSave) { super.writeTo(objectsToSave); - objectsToSave.add(currentPage); - objectsToSave.add(currentNextPage); + objectsToSave.add(currentPageUrl); + objectsToSave.add(nextPageUrl); } @Override public void readFrom(@NonNull Queue savedObjects) throws Exception { super.readFrom(savedObjects); - currentPage = (int) savedObjects.poll(); - currentNextPage = (int) savedObjects.poll(); + currentPageUrl = (String) savedObjects.poll(); + nextPageUrl = (String) savedObjects.poll(); } @Override public void onSaveInstanceState(Bundle bundle) { - searchQuery = searchEditText != null ? searchEditText.getText().toString() : searchQuery; + 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)); + } super.onSaveInstanceState(bundle); } @@ -305,8 +330,12 @@ public class SearchFragment @Override public void reloadContent() { - if (!TextUtils.isEmpty(searchQuery) || (searchEditText != null && !TextUtils.isEmpty(searchEditText.getText()))) { - search(!TextUtils.isEmpty(searchQuery) ? searchQuery : searchEditText.getText().toString()); + if (!TextUtils.isEmpty(searchQuery.getSearchString()) + || (searchEditText != null && !TextUtils.isEmpty(searchEditText.getText()))) { + search(!TextUtils.isEmpty(searchQuery.getSearchString()) + ? searchQuery + : getSearchQuery(searchEditText.getText().toString(), + new ArrayList<>(0), "")); } else { if (searchEditText != null) { searchEditText.setText(""); @@ -330,22 +359,20 @@ public class SearchFragment supportActionBar.setDisplayHomeAsUpEnabled(true); } - inflater.inflate(R.menu.menu_search, menu); + for(String filter : service.getSearchQIHFactory().getAvailableContentFilter()) { + menu.add(filter); + } restoreFilterChecked(menu, filterItemCheckedId); } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_filter_all: - case R.id.menu_filter_video: - case R.id.menu_filter_channel: - case R.id.menu_filter_playlist: - changeFilter(item, getFilterFromMenuId(item.getItemId())); - return true; - default: - return super.onOptionsItemSelected(item); - } + + List contentFilter = new ArrayList<>(1); + contentFilter.add(item.getTitle().toString()); + changeContentFilter(item, contentFilter); + + return true; } private void restoreFilterChecked(Menu menu, int itemId) { @@ -354,21 +381,8 @@ public class SearchFragment if (item == null) return; item.setChecked(true); - filter = getFilterFromMenuId(itemId); - } - } - - private SearchEngine.Filter getFilterFromMenuId(int itemId) { - switch (itemId) { - case R.id.menu_filter_video: - return SearchEngine.Filter.STREAM; - case R.id.menu_filter_channel: - return SearchEngine.Filter.CHANNEL; - case R.id.menu_filter_playlist: - return SearchEngine.Filter.PLAYLIST; - case R.id.menu_filter_all: - default: - return SearchEngine.Filter.ANY; + contentFilter.clear(); + contentFilter.add(menu.getItem(itemId).getTitle().toString()); } } @@ -380,9 +394,9 @@ public class SearchFragment private void showSearchOnStart() { if (DEBUG) Log.d(TAG, "showSearchOnStart() called, searchQuery → " + searchQuery+", lastSearchedQuery → " + lastSearchedQuery); - searchEditText.setText(searchQuery); + searchEditText.setText(searchQuery.getSearchString()); - if (TextUtils.isEmpty(searchQuery) || TextUtils.isEmpty(searchEditText.getText())) { + if (TextUtils.isEmpty(searchQuery.getSearchString()) || TextUtils.isEmpty(searchEditText.getText())) { searchToolbarContainer.setTranslationX(100); searchToolbarContainer.setAlpha(0f); searchToolbarContainer.setVisibility(View.VISIBLE); @@ -396,47 +410,38 @@ public class SearchFragment private void initSearchListeners() { if (DEBUG) Log.d(TAG, "initSearchListeners() called"); - searchClear.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]"); - if (TextUtils.isEmpty(searchEditText.getText())) { - NavigationHelper.gotoMainFragment(getFragmentManager()); - return; - } - - searchEditText.setText(""); - suggestionListAdapter.setItems(new ArrayList()); - showKeyboardSearch(); + searchClear.setOnClickListener(v -> { + if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]"); + if (TextUtils.isEmpty(searchEditText.getText())) { + NavigationHelper.gotoMainFragment(getFragmentManager()); + return; } + + searchEditText.setText(""); + suggestionListAdapter.setItems(new ArrayList<>()); + showKeyboardSearch(); }); TooltipCompat.setTooltipText(searchClear, getString(R.string.clear)); - searchEditText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]"); - if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) { - showSuggestionsPanel(); - } + searchEditText.setOnClickListener(v -> { + if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]"); + if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) { + showSuggestionsPanel(); } }); - searchEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (DEBUG) Log.d(TAG, "onFocusChange() called with: v = [" + v + "], hasFocus = [" + hasFocus + "]"); - if (isSuggestionsEnabled && hasFocus && errorPanelRoot.getVisibility() != View.VISIBLE) { - showSuggestionsPanel(); - } + searchEditText.setOnFocusChangeListener((View v, boolean hasFocus) -> { + if (DEBUG) Log.d(TAG, "onFocusChange() called with: v = [" + v + "], hasFocus = [" + hasFocus + "]"); + if (isSuggestionsEnabled && hasFocus && errorPanelRoot.getVisibility() != View.VISIBLE) { + showSuggestionsPanel(); } }); suggestionListAdapter.setListener(new SuggestionListAdapter.OnSuggestionItemSelected() { @Override public void onSuggestionItemSelected(SuggestionItem item) { - search(item.query); + search(getSearchQuery(item.query, new ArrayList<>(), "")); searchEditText.setText(item.query); } @@ -469,21 +474,22 @@ public class SearchFragment } }; searchEditText.addTextChangedListener(textWatcher); - searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (DEBUG) { - Log.d(TAG, "onEditorAction() called with: v = [" + v + "], actionId = [" + actionId + "], event = [" + event + "]"); - } - if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER || event.getAction() == EditorInfo.IME_ACTION_SEARCH)) { - search(searchEditText.getText().toString()); - return true; - } - return false; - } - }); + searchEditText.setOnEditorActionListener( + (TextView v, int actionId, KeyEvent event) -> { + if (DEBUG) { + Log.d(TAG, "onEditorAction() called with: v = [" + v + "], actionId = [" + actionId + "], event = [" + event + "]"); + } + if (event != null + && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER + || event.getAction() == EditorInfo.IME_ACTION_SEARCH)) { + search(getSearchQuery(searchEditText.getText().toString(), new ArrayList<>(), "")); + return true; + } + return false; + }); - if (suggestionDisposable == null || suggestionDisposable.isDisposed()) initSuggestionObserver(); + if (suggestionDisposable == null || suggestionDisposable.isDisposed()) + initSuggestionObserver(); } private void unsetSearchListeners() { @@ -513,7 +519,8 @@ public class SearchFragment if (searchEditText == null) return; if (searchEditText.requestFocus()) { - InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = (InputMethodManager) activity.getSystemService( + Context.INPUT_METHOD_SERVICE); imm.showSoftInput(searchEditText, InputMethodManager.SHOW_IMPLICIT); } } @@ -522,8 +529,10 @@ public class SearchFragment if (DEBUG) Log.d(TAG, "hideKeyboardSearch() called"); if (searchEditText == null) return; - InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(searchEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + InputMethodManager imm = (InputMethodManager) activity.getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(searchEditText.getWindowToken(), + InputMethodManager.HIDE_NOT_ALWAYS); searchEditText.clearFocus(); } @@ -557,7 +566,7 @@ public class SearchFragment if (suggestionsPanel.getVisibility() == View.VISIBLE && infoListAdapter.getItemsList().size() > 0 && !isLoading.get()) { hideSuggestionsPanel(); hideKeyboardSearch(); - searchEditText.setText(lastSearchedQuery); + searchEditText.setText(lastSearchedQuery.getSearchString()); return true; } return false; @@ -573,8 +582,10 @@ public class SearchFragment final Observable observable = suggestionPublisher .debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS) - .startWith(searchQuery != null ? searchQuery : "") - .filter(query -> isSuggestionsEnabled); + .startWith(searchQuery != null + ? searchQuery.getSearchString() + : "") + .filter(searchString -> isSuggestionsEnabled); suggestionDisposable = observable .switchMap(query -> { @@ -645,35 +656,24 @@ public class SearchFragment // no-op } - private void search(final String query) { + private void search(final SearchQIHandler query) { if (DEBUG) Log.d(TAG, "search() called with: query = [" + query + "]"); - if (query.isEmpty()) return; + if (query.getSearchString().isEmpty()) return; try { - final StreamingService service = NewPipe.getServiceByUrl(query); + final StreamingService service = NewPipe.getServiceByUrl(query.getUrl()); if (service != null) { showLoading(); disposables.add(Observable - .fromCallable(new Callable() { - @Override - public Intent call() throws Exception { - return NavigationHelper.getIntentByLink(activity, service, query); - } - }) + .fromCallable(() -> + NavigationHelper.getIntentByLink(activity, service, query.getUrl())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Consumer() { - @Override - public void accept(Intent intent) throws Exception { - getFragmentManager().popBackStackImmediate(); - activity.startActivity(intent); - } - }, new Consumer() { - @Override - public void accept(Throwable throwable) throws Exception { - showError(getString(R.string.url_not_supported_toast), false); - } - })); + .subscribe(intent -> { + getFragmentManager().popBackStackImmediate(); + activity.startActivity(intent); + }, throwable -> + showError(getString(R.string.url_not_supported_toast), false))); return; } } catch (Exception e) { @@ -682,19 +682,19 @@ public class SearchFragment lastSearchedQuery = query; searchQuery = query; - currentPage = 0; + currentPageUrl = ""; infoListAdapter.clearStreamItemList(); hideSuggestionsPanel(); hideKeyboardSearch(); - historyRecordManager.onSearched(serviceId, query) + historyRecordManager.onSearched(serviceId, query.getSearchString()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( ignored -> {}, error -> showSnackBarError(error, UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), query, 0) + NewPipe.getNameOfService(serviceId), query.getSearchString(), 0) ); - suggestionPublisher.onNext(query); + suggestionPublisher.onNext(query.getSearchString()); startLoading(false); } @@ -703,7 +703,8 @@ public class SearchFragment super.startLoading(forceLoad); if (disposables != null) disposables.clear(); if (searchDisposable != null) searchDisposable.dispose(); - searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, currentPage, contentCountry, filter) + searchDisposable = ExtractorHelper.searchFor(serviceId, + searchQuery, currentPageUrl, contentCountry, contentFilter, "") .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((searchResult, throwable) -> isLoading.set(false)) @@ -716,7 +717,8 @@ public class SearchFragment showListFooter(true); if (searchDisposable != null) searchDisposable.dispose(); currentNextPage = currentPage + 1; - searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchQuery, currentNextPage, contentCountry, filter) + searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, + searchQuery, currentNextPage, contentCountry, filter) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((nextItemsResult, throwable) -> isLoading.set(false)) @@ -739,21 +741,38 @@ public class SearchFragment // Utils //////////////////////////////////////////////////////////////////////////*/ - private void changeFilter(MenuItem item, SearchEngine.Filter filter) { - this.filter = filter; + private void changeContentFilter(MenuItem item, List contentFilter) { this.filterItemCheckedId = item.getItemId(); item.setChecked(true); - if (!TextUtils.isEmpty(searchQuery)) { + this.contentFilter = contentFilter; + searchQuery = getSearchQuery(searchQuery.getSearchString(), contentFilter, ""); + + if (!TextUtils.isEmpty(searchQuery.getSearchString())) { search(searchQuery); } } - private void setQuery(int serviceId, String searchQuery) { + private void setQuery(int serviceId, SearchQIHandler searchQuery) { 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) { + ErrorActivity.reportError(getActivity(), e, getActivity().getClass(), + getActivity().findViewById(android.R.id.content), + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "", + "", R.string.general_error)); + } + } + /*////////////////////////////////////////////////////////////////////////// // Suggestion Results //////////////////////////////////////////////////////////////////////////*/ @@ -772,8 +791,11 @@ public class SearchFragment if (DEBUG) Log.d(TAG, "onSuggestionError() called with: exception = [" + exception + "]"); if (super.onError(exception)) return; - int errorId = exception instanceof ParsingException ? R.string.parsing_error : R.string.general_error; - onUnrecoverableError(exception, UserAction.GET_SUGGESTIONS, NewPipe.getNameOfService(serviceId), searchQuery, errorId); + int errorId = exception instanceof ParsingException + ? R.string.parsing_error + : R.string.general_error; + onUnrecoverableError(exception, UserAction.GET_SUGGESTIONS, + NewPipe.getNameOfService(serviceId), searchQuery, errorId); } /*////////////////////////////////////////////////////////////////////////// @@ -800,7 +822,8 @@ public class SearchFragment @Override public void handleResult(@NonNull SearchResult result) { if (!result.errors.isEmpty()) { - showSnackBarError(result.errors, UserAction.SEARCHED, NewPipe.getNameOfService(serviceId), searchQuery, 0); + showSnackBarError(result.errors, UserAction.SEARCHED, + NewPipe.getNameOfService(serviceId), searchQuery, 0); } lastSearchedQuery = searchQuery; @@ -825,7 +848,8 @@ public class SearchFragment infoListAdapter.addInfoItemList(result.getItems()); if (!result.getErrors().isEmpty()) { - showSnackBarError(result.getErrors(), UserAction.SEARCHED, NewPipe.getNameOfService(serviceId) + showSnackBarError(result.getErrors(), UserAction.SEARCHED, + NewPipe.getNameOfService(serviceId) , "\"" + searchQuery + "\" → page " + currentPage, 0); } super.handleNextItems(result); @@ -839,8 +863,11 @@ public class SearchFragment infoListAdapter.clearStreamItemList(); showEmptyState(); } else { - int errorId = exception instanceof ParsingException ? R.string.parsing_error : R.string.general_error; - onUnrecoverableError(exception, UserAction.SEARCHED, NewPipe.getNameOfService(serviceId), searchQuery, errorId); + int errorId = exception instanceof ParsingException + ? R.string.parsing_error + : R.string.general_error; + onUnrecoverableError(exception, UserAction.SEARCHED, + NewPipe.getNameOfService(serviceId), searchQuery, errorId); } return true; diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 1897589c6..9cbedff23 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -38,9 +38,11 @@ import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.kiosk.KioskInfo; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchInfo; import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.StreamInfo; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; @@ -66,29 +68,23 @@ public final class ExtractorHelper { } } - public static Single searchFor(final int serviceId, - final String query, - final int pageNumber, - final String contentCountry, - final SearchEngine.Filter filter) { + public static Single searchFor(final int serviceId, + final SearchQIHandler query, + final String contentCountry) { checkServiceId(serviceId); return Single.fromCallable(() -> - SearchResult.getSearchResult(NewPipe.getService(serviceId).getSearchEngine(), - query, pageNumber, contentCountry, filter) - ); + SearchInfo.getInfo(NewPipe.getService(serviceId).getSearchExtractor(query, contentCountry))); } public static Single getMoreSearchItems(final int serviceId, - final String query, - final int nextPageNumber, - final String searchLanguage, - final SearchEngine.Filter filter) { + final SearchQIHandler query, + final String pageUrl, + final String contentCountry) { checkServiceId(serviceId); - return searchFor(serviceId, query, nextPageNumber, searchLanguage, filter) - .map((@NonNull SearchResult searchResult) -> - new InfoItemsPage(searchResult.resultList, - nextPageNumber + "", - searchResult.errors)); + return Single.fromCallable(() -> + SearchInfo.get + NewPipe.getService(serviceId).getSearchExtractor(query, contentCountry)) + } public static Single> suggestionsFor(final int serviceId, From d5a500c0372a36db37ff92fbce465ff166026cf0 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Jul 2018 17:46:21 +0200 Subject: [PATCH 2/6] bring everything to compile and run --- app/build.gradle | 2 +- .../java/org/schabi/newpipe/MainActivity.java | 69 ++++++++++++------- .../newpipe/fragments/MainFragment.java | 27 +++++--- .../fragments/detail/VideoDetailFragment.java | 20 ++++-- .../fragments/list/BaseListFragment.java | 38 ++++++++-- .../fragments/list/BaseListInfoFragment.java | 10 +-- .../list/channel/ChannelFragment.java | 21 +++--- .../fragments/list/kiosk/KioskFragment.java | 26 ++++--- .../list/playlist/PlaylistFragment.java | 39 +++++++---- .../fragments/list/search/SearchFragment.java | 47 +++++-------- .../local/bookmark/BookmarkFragment.java | 34 ++++++--- .../subscription/SubscriptionFragment.java | 16 ++++- .../org/schabi/newpipe/util/Constants.java | 2 +- .../schabi/newpipe/util/ExtractorHelper.java | 8 +-- .../schabi/newpipe/util/NavigationHelper.java | 17 +++-- 15 files changed, 238 insertions(+), 138 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 503a3e469..396b79459 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:39332a283b1c911' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:4746a1c48a8682' 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 61b430c27..38ee4a1f8 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -49,6 +49,7 @@ import android.widget.TextView; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; @@ -61,6 +62,8 @@ import org.schabi.newpipe.util.ServiceHelper; import org.schabi.newpipe.util.StateSaver; import org.schabi.newpipe.util.ThemeHelper; +import static org.schabi.newpipe.extractor.InfoItem.InfoType.PLAYLIST; + public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); @@ -392,31 +395,51 @@ public class MainActivity extends AppCompatActivity { } private void handleIntent(Intent intent) { - if (DEBUG) Log.d(TAG, "handleIntent() called with: intent = [" + intent + "]"); + try { + if (DEBUG) Log.d(TAG, "handleIntent() called with: intent = [" + intent + "]"); - if (intent.hasExtra(Constants.KEY_LINK_TYPE)) { - String url = intent.getStringExtra(Constants.KEY_URL); - int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0); - String title = intent.getStringExtra(Constants.KEY_TITLE); - switch (((StreamingService.LinkType) intent.getSerializableExtra(Constants.KEY_LINK_TYPE))) { - case STREAM: - boolean autoPlay = intent.getBooleanExtra(VideoDetailFragment.AUTO_PLAY, false); - NavigationHelper.openVideoDetailFragment(getSupportFragmentManager(), serviceId, url, title, autoPlay); - break; - case CHANNEL: - NavigationHelper.openChannelFragment(getSupportFragmentManager(), serviceId, url, title); - break; - case PLAYLIST: - NavigationHelper.openPlaylistFragment(getSupportFragmentManager(), serviceId, url, title); - break; + if (intent.hasExtra(Constants.KEY_LINK_TYPE)) { + String url = intent.getStringExtra(Constants.KEY_URL); + int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0); + String title = intent.getStringExtra(Constants.KEY_TITLE); + switch (((StreamingService.LinkType) intent.getSerializableExtra(Constants.KEY_LINK_TYPE))) { + case STREAM: + boolean autoPlay = intent.getBooleanExtra(VideoDetailFragment.AUTO_PLAY, false); + NavigationHelper.openVideoDetailFragment(getSupportFragmentManager(), serviceId, url, title, autoPlay); + break; + case CHANNEL: + NavigationHelper.openChannelFragment(getSupportFragmentManager(), + serviceId, + NewPipe.getService(serviceId) + .getChannelUIHFactory() + .fromUrl(url), + title); + break; + case PLAYLIST: + NavigationHelper.openPlaylistFragment(getSupportFragmentManager(), + serviceId, + NewPipe.getService(serviceId) + .getChannelUIHFactory() + .fromUrl(url), + title); + break; + } + } else if (intent.hasExtra(Constants.KEY_OPEN_SEARCH)) { + String searchString = intent.getStringExtra(Constants.KEY_SEARCH_STRING); + if (searchString == null) searchString = ""; + int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0); + NavigationHelper.openSearchFragment( + getSupportFragmentManager(), + serviceId, + NewPipe.getService(serviceId) + .getSearchQIHFactory() + .fromQuery(searchString)); + + } else { + NavigationHelper.gotoMainFragment(getSupportFragmentManager()); } - } else if (intent.hasExtra(Constants.KEY_OPEN_SEARCH)) { - String searchQuery = intent.getStringExtra(Constants.KEY_QUERY); - if (searchQuery == null) searchQuery = ""; - int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0); - NavigationHelper.openSearchFragment(getSupportFragmentManager(), serviceId, searchQuery); - } else { - NavigationHelper.gotoMainFragment(getSupportFragmentManager()); + } catch (Exception e) { + ErrorActivity.reportUiError(this, e); } } } 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 31092d3e6..cd4fc1baf 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -10,6 +10,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; @@ -127,7 +128,16 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: - NavigationHelper.openSearchFragment(getFragmentManager(), ServiceHelper.getSelectedServiceId(activity), ""); + try { + NavigationHelper.openSearchFragment( + getFragmentManager(), + ServiceHelper.getSelectedServiceId(activity), + NewPipe.getService(currentServiceId) + .getSearchQIHFactory() + .fromQuery("")); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } return true; } return super.onOptionsItemSelected(item); @@ -226,7 +236,9 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte FALLBACK_CHANNEL_URL); String name = preferences.getString(getString(R.string.main_page_selected_channel_name), FALLBACK_CHANNEL_NAME); - ChannelFragment fragment = ChannelFragment.getInstance(serviceId, url, name); + ChannelFragment fragment = ChannelFragment.getInstance(serviceId, + NewPipe.getService(currentServiceId).getPlaylistUIHFactory().fromUrl(url), + name); fragment.useAsFrontPage(true); return fragment; } else { @@ -255,20 +267,13 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte for (final String ks : kl.getAvailableKiosks()) { menu.add(0, KIOSK_MENU_OFFSET + i, Menu.NONE, KioskTranslator.getTranslatedKioskName(ks, getContext())) - .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { + .setOnMenuItemClickListener(menuItem -> { try { NavigationHelper.openKioskFragment(getFragmentManager(), currentServiceId, ks); } catch (Exception e) { - ErrorActivity.reportError(activity, e, - activity.getClass(), - null, - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, - "none", "", R.string.app_ui_crash)); + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); } return true; - } }); i++; } 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 5aef21f39..fac6435dd 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 @@ -17,6 +17,7 @@ import android.support.v4.content.ContextCompat; import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; import android.text.Html; import android.text.Spanned; import android.text.TextUtils; @@ -54,7 +55,7 @@ import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.StreamInfo; @@ -64,6 +65,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.local.history.HistoryRecordManager; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.StreamItemAdapter; import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; @@ -365,11 +367,17 @@ public class VideoDetailFragment if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) { Log.w(TAG, "Can't open channel because we got no channel URL"); } else { - NavigationHelper.openChannelFragment( - getFragmentManager(), - currentInfo.getServiceId(), - currentInfo.getUploaderUrl(), - currentInfo.getUploaderName()); + try { + NavigationHelper.openChannelFragment( + getFragmentManager(), + currentInfo.getServiceId(), + NewPipe.getService(currentInfo.getServiceId()) + .getChannelUIHFactory() + .fromUrl(currentInfo.getUploaderUrl()), + currentInfo.getUploaderName()); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } } break; case R.id.detail_thumbnail_root_layout: 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 c4b341aae..adf419795 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 @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -15,15 +16,18 @@ import android.view.View; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.info_list.InfoListAdapter; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.StateSaver; @@ -152,18 +156,40 @@ public abstract class BaseListFragment extends BaseStateFragment implem infoListAdapter.setOnChannelSelectedListener(new OnClickGesture() { @Override public void selected(ChannelInfoItem selectedItem) { - onItemSelected(selectedItem); - NavigationHelper.openChannelFragment(useAsFrontPage ? getParentFragment().getFragmentManager() : getFragmentManager(), - selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); + try { + onItemSelected(selectedItem); + NavigationHelper.openChannelFragment(useAsFrontPage ? + getParentFragment().getFragmentManager() + : getFragmentManager(), + selectedItem.getServiceId(), + NewPipe.getService(selectedItem + .getServiceId()) + .getChannelUIHFactory() + .fromUrl(selectedItem.getUrl()), + selectedItem.getName()); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } } }); infoListAdapter.setOnPlaylistSelectedListener(new OnClickGesture() { @Override public void selected(PlaylistInfoItem selectedItem) { - onItemSelected(selectedItem); - NavigationHelper.openPlaylistFragment(useAsFrontPage ? getParentFragment().getFragmentManager() : getFragmentManager(), - selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); + try { + onItemSelected(selectedItem); + NavigationHelper.openPlaylistFragment( + useAsFrontPage + ? getParentFragment().getFragmentManager() + : getFragmentManager(), + selectedItem.getServiceId(), + NewPipe.getService(selectedItem.getServiceId()) + .getPlaylistUIHFactory() + .fromUrl(selectedItem.getUrl()), + selectedItem.getName()); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } } }); 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 a132213bf..270ba5550 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 @@ -8,6 +8,9 @@ import android.view.View; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListInfo; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.uih.ListUIHandler; +import org.schabi.newpipe.extractor.uih.UIHandler; import org.schabi.newpipe.util.Constants; import java.util.Queue; @@ -27,7 +30,7 @@ public abstract class BaseListInfoFragment @State protected String name; @State - protected String url; + protected ListUIHandler uiHandler; protected I currentInfo; protected String currentNextPageUrl; @@ -166,7 +169,6 @@ public abstract class BaseListInfoFragment public void handleResult(@NonNull I result) { super.handleResult(result); - url = result.getUrl(); name = result.getName(); setTitle(name); @@ -185,9 +187,9 @@ public abstract class BaseListInfoFragment // Utils //////////////////////////////////////////////////////////////////////////*/ - protected void setInitialData(int serviceId, String url, String name) { + protected void setInitialData(int serviceId, ListUIHandler uiHandler, String name) { this.serviceId = serviceId; - this.url = url; + this.uiHandler = uiHandler; 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 b56692877..758b6506c 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 @@ -33,6 +33,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; @@ -90,9 +91,9 @@ public class ChannelFragment extends BaseListInfoFragment { private MenuItem menuRssButton; - public static ChannelFragment getInstance(int serviceId, String url, String name) { + public static ChannelFragment getInstance(int serviceId, ListUIHandler uiHandler, String name) { ChannelFragment instance = new ChannelFragment(); - instance.setInitialData(serviceId, url, name); + instance.setInitialData(serviceId, uiHandler, name); return instance; } @@ -236,10 +237,10 @@ public class ChannelFragment extends BaseListInfoFragment { openRssFeed(); break; case R.id.menu_item_openInBrowser: - openUrlInBrowser(url); + openUrlInBrowser(uiHandler.getUrl()); break; case R.id.menu_item_share: - shareUrl(name, url); + shareUrl(name, uiHandler.getUrl()); break; default: return super.onOptionsItemSelected(item); @@ -405,12 +406,12 @@ public class ChannelFragment extends BaseListInfoFragment { @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl); + return ExtractorHelper.getMoreChannelItems(serviceId, uiHandler.getUrl(), currentNextPageUrl); } @Override protected Single loadResult(boolean forceLoad) { - return ExtractorHelper.getChannelInfo(serviceId, url, forceLoad); + return ExtractorHelper.getChannelInfo(serviceId, uiHandler.getUrl(), forceLoad); } /*////////////////////////////////////////////////////////////////////////// @@ -488,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: " + url, R.string.general_error); + "Get next page of: " + uiHandler.getUrl(), R.string.general_error); } } @@ -501,7 +502,11 @@ public class ChannelFragment extends BaseListInfoFragment { if (super.onError(exception)) return true; int errorId = exception instanceof ExtractionException ? R.string.parsing_error : R.string.general_error; - onUnrecoverableError(exception, UserAction.REQUESTED_CHANNEL, NewPipe.getNameOfService(serviceId), url, errorId); + onUnrecoverableError(exception, + UserAction.REQUESTED_CHANNEL, + NewPipe.getNameOfService(serviceId), + uiHandler.getUrl(), + 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 5dfdcd655..97e35f4c2 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 @@ -11,22 +11,20 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskInfo; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHFactory; +import org.schabi.newpipe.extractor.uih.ListUIHandler; +import org.schabi.newpipe.extractor.uih.UIHFactory; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; -import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.KioskTranslator; -import org.schabi.newpipe.util.NavigationHelper; import icepick.State; import io.reactivex.Single; @@ -74,10 +72,10 @@ public class KioskFragment extends BaseListInfoFragment { throws ExtractionException { KioskFragment instance = new KioskFragment(); StreamingService service = NewPipe.getService(serviceId); - UrlIdHandler kioskTypeUrlIdHandler = service.getKioskList() - .getUrlIdHandlerByType(kioskId); + ListUIHFactory kioskUIHFactory = service.getKioskList() + .getUIHFactoryByType(kioskId); instance.setInitialData(serviceId, - kioskTypeUrlIdHandler.getUrl(kioskId), kioskId); + kioskUIHFactory.fromId(kioskId), kioskId); instance.kioskId = kioskId; return instance; } @@ -136,7 +134,10 @@ public class KioskFragment extends BaseListInfoFragment { .getDefaultSharedPreferences(activity) .getString(getString(R.string.content_country_key), getString(R.string.default_country_value)); - return ExtractorHelper.getKioskInfo(serviceId, url, contentCountry, forceReload); + return ExtractorHelper.getKioskInfo(serviceId, + uiHandler.getUrl(), + contentCountry, + forceReload); } @Override @@ -145,7 +146,10 @@ public class KioskFragment extends BaseListInfoFragment { .getDefaultSharedPreferences(activity) .getString(getString(R.string.content_country_key), getString(R.string.default_country_value)); - return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPageUrl, contentCountry); + return ExtractorHelper.getMoreKioskItems(serviceId, + uiHandler.getUrl(), + currentNextPageUrl, + contentCountry); } /*////////////////////////////////////////////////////////////////////////// @@ -179,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: " + url, 0); + , "Get next page of: " + uiHandler.getUrl(), 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 ca732aa2c..b7df1e0c3 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 @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -19,6 +20,7 @@ import android.widget.TextView; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; +import org.schabi.newpipe.App; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; @@ -28,12 +30,14 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; 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.PlaylistPlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ImageDisplayConstants; @@ -79,9 +83,9 @@ public class PlaylistFragment extends BaseListInfoFragment { private MenuItem playlistBookmarkButton; - public static PlaylistFragment getInstance(int serviceId, String url, String name) { + public static PlaylistFragment getInstance(int serviceId, ListUIHandler uiHandler, String name) { PlaylistFragment instance = new PlaylistFragment(); - instance.setInitialData(serviceId, url, name); + instance.setInitialData(serviceId, uiHandler, name); return instance; } @@ -216,22 +220,22 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl); + return ExtractorHelper.getMorePlaylistItems(serviceId, uiHandler.getUrl(), currentNextPageUrl); } @Override protected Single loadResult(boolean forceLoad) { - return ExtractorHelper.getPlaylistInfo(serviceId, url, forceLoad); + return ExtractorHelper.getPlaylistInfo(serviceId, uiHandler.getUrl(), forceLoad); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_openInBrowser: - openUrlInBrowser(url); + openUrlInBrowser(uiHandler.getUrl()); break; case R.id.menu_item_share: - shareUrl(name, url); + shareUrl(name, uiHandler.getUrl()); break; case R.id.menu_item_bookmark: onBookmarkClicked(); @@ -267,11 +271,18 @@ public class PlaylistFragment extends BaseListInfoFragment { if (!TextUtils.isEmpty(result.getUploaderName())) { headerUploaderName.setText(result.getUploaderName()); if (!TextUtils.isEmpty(result.getUploaderUrl())) { - headerUploaderLayout.setOnClickListener(v -> + headerUploaderLayout.setOnClickListener(v -> { + try { NavigationHelper.openChannelFragment(getFragmentManager(), - result.getServiceId(), result.getUploaderUrl(), - result.getUploaderName()) - ); + result.getServiceId(), + NewPipe.getService(serviceId) + .getChannelUIHFactory() + .fromUrl(result.getUploaderUrl()), + result.getUploaderName()); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } + }); } } @@ -326,7 +337,7 @@ public class PlaylistFragment extends BaseListInfoFragment { if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId) - , "Get next page of: " + url, 0); + , "Get next page of: " + uiHandler.getUrl(), 0); } } @@ -339,7 +350,11 @@ public class PlaylistFragment extends BaseListInfoFragment { if (super.onError(exception)) return true; int errorId = exception instanceof ExtractionException ? R.string.parsing_error : R.string.general_error; - onUnrecoverableError(exception, UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId), url, errorId); + onUnrecoverableError(exception, + UserAction.REQUESTED_PLAYLIST, + NewPipe.getNameOfService(serviceId), + uiHandler.getUrl(), + 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 e57cdbd31..ee76966ff 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 @@ -37,9 +37,8 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchInfo; -import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.list.BaseListFragment; @@ -59,7 +58,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Queue; -import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import icepick.State; @@ -103,8 +101,6 @@ public class SearchFragment protected SearchQIHandler lastSearchedQuery; @State protected boolean wasSearchFocused = false; - @State - List contentFilter; private StreamingService service; private String currentPageUrl; @@ -381,8 +377,6 @@ public class SearchFragment if (item == null) return; item.setChecked(true); - contentFilter.clear(); - contentFilter.add(menu.getItem(itemId).getTitle().toString()); } } @@ -703,8 +697,7 @@ public class SearchFragment super.startLoading(forceLoad); if (disposables != null) disposables.clear(); if (searchDisposable != null) searchDisposable.dispose(); - searchDisposable = ExtractorHelper.searchFor(serviceId, - searchQuery, currentPageUrl, contentCountry, contentFilter, "") + searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, contentCountry) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((searchResult, throwable) -> isLoading.set(false)) @@ -716,9 +709,8 @@ public class SearchFragment isLoading.set(true); showListFooter(true); if (searchDisposable != null) searchDisposable.dispose(); - currentNextPage = currentPage + 1; searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, - searchQuery, currentNextPage, contentCountry, filter) + searchQuery, nextPageUrl, contentCountry) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((nextItemsResult, throwable) -> isLoading.set(false)) @@ -745,7 +737,6 @@ public class SearchFragment this.filterItemCheckedId = item.getItemId(); item.setChecked(true); - this.contentFilter = contentFilter; searchQuery = getSearchQuery(searchQuery.getSearchString(), contentFilter, ""); if (!TextUtils.isEmpty(searchQuery.getSearchString())) { @@ -765,12 +756,12 @@ public class SearchFragment return service.getSearchQIHFactory() .fromQuery(searchString, contentFilter, sortFilter); } 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)); + onUnrecoverableError(e, UserAction.SEARCHED, + service.getServiceInfo().getName(), + searchQuery.getSearchString(), + R.string.general_error); } + return searchQuery; } /*////////////////////////////////////////////////////////////////////////// @@ -795,7 +786,7 @@ public class SearchFragment ? R.string.parsing_error : R.string.general_error; onUnrecoverableError(exception, UserAction.GET_SUGGESTIONS, - NewPipe.getNameOfService(serviceId), searchQuery, errorId); + NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), errorId); } /*////////////////////////////////////////////////////////////////////////// @@ -820,17 +811,17 @@ public class SearchFragment //////////////////////////////////////////////////////////////////////////*/ @Override - public void handleResult(@NonNull SearchResult result) { - if (!result.errors.isEmpty()) { - showSnackBarError(result.errors, UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), searchQuery, 0); + public void handleResult(@NonNull SearchInfo result) { + if (!result.getErrors().isEmpty()) { + showSnackBarError(result.getErrors(), UserAction.SEARCHED, + NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), 0); } lastSearchedQuery = searchQuery; if (infoListAdapter.getItemsList().size() == 0) { - if (!result.getResults().isEmpty()) { - infoListAdapter.addInfoItemList(result.getResults()); + if (!result.getRelatedItems().isEmpty()) { + infoListAdapter.addInfoItemList(result.getRelatedItems()); } else { infoListAdapter.clearStreamItemList(); showEmptyState(); @@ -844,13 +835,13 @@ public class SearchFragment @Override public void handleNextItems(ListExtractor.InfoItemsPage result) { showListFooter(false); - currentPage = Integer.parseInt(result.getNextPageUrl()); + currentPageUrl = result.getNextPageUrl(); infoListAdapter.addInfoItemList(result.getItems()); if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.SEARCHED, NewPipe.getNameOfService(serviceId) - , "\"" + searchQuery + "\" → page " + currentPage, 0); + , "\"" + searchQuery + "\" → page: " + nextPageUrl, 0); } super.handleNextItems(result); } @@ -859,7 +850,7 @@ public class SearchFragment protected boolean onError(Throwable exception) { if (super.onError(exception)) return true; - if (exception instanceof SearchEngine.NothingFoundException) { + if (exception instanceof SearchExtractor.NothingFoundException) { infoListAdapter.clearStreamItemList(); showEmptyState(); } else { @@ -867,7 +858,7 @@ public class SearchFragment ? R.string.parsing_error : R.string.general_error; onUnrecoverableError(exception, UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), searchQuery, errorId); + NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), 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 f3f390c4d..a7e16a5f1 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 @@ -6,6 +6,7 @@ import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; +import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,9 +20,11 @@ import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.PlaylistLocalItem; import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.local.playlist.LocalPlaylistManager; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; @@ -99,19 +102,28 @@ public final class BookmarkFragment itemListAdapter.setSelectedListener(new OnClickGesture() { @Override public void selected(LocalItem selectedItem) { - // Requires the parent fragment to find holder for fragment replacement - if (getParentFragment() == null) return; - final FragmentManager fragmentManager = getParentFragment().getFragmentManager(); + try { + // Requires the parent fragment to find holder for fragment replacement + if (getParentFragment() == null) return; + final FragmentManager fragmentManager = getParentFragment().getFragmentManager(); - if (selectedItem instanceof PlaylistMetadataEntry) { - final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); - NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid, - entry.name); + if (selectedItem instanceof PlaylistMetadataEntry) { + final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); + NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid, + entry.name); - } else if (selectedItem instanceof PlaylistRemoteEntity) { - final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem); - NavigationHelper.openPlaylistFragment(fragmentManager, entry.getServiceId(), - entry.getUrl(), entry.getName()); + } else if (selectedItem instanceof PlaylistRemoteEntity) { + final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem); + NavigationHelper.openPlaylistFragment( + fragmentManager, + entry.getServiceId(), + NewPipe.getService(entry.getServiceId()) + .getPlaylistUIHFactory() + .fromUrl(entry.getUrl()), + entry.getName()); + } + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), 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 5f6ea42ee..9bbb5f517 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 @@ -15,6 +15,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -38,6 +39,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.info_list.InfoListAdapter; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService; import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService; @@ -318,9 +320,17 @@ public class SubscriptionFragment extends BaseStateFragment() { @Override public void selected(ChannelInfoItem selectedItem) { - // Requires the parent fragment to find holder for fragment replacement - NavigationHelper.openChannelFragment(getParentFragment().getFragmentManager(), - selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); + try { + // Requires the parent fragment to find holder for fragment replacement + NavigationHelper.openChannelFragment(getParentFragment().getFragmentManager(), + selectedItem.getServiceId(), + NewPipe.getService(selectedItem.getServiceId()) + .getChannelUIHFactory() + .fromUrl(selectedItem.getUrl()), + selectedItem.getName()); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } } }); diff --git a/app/src/main/java/org/schabi/newpipe/util/Constants.java b/app/src/main/java/org/schabi/newpipe/util/Constants.java index a6aec96e2..b01b6df6a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Constants.java +++ b/app/src/main/java/org/schabi/newpipe/util/Constants.java @@ -6,7 +6,7 @@ public class Constants { public static final String KEY_TITLE = "key_title"; public static final String KEY_LINK_TYPE = "key_link_type"; public static final String KEY_OPEN_SEARCH = "key_open_search"; - public static final String KEY_QUERY = "key_query"; + public static final String KEY_SEARCH_STRING = "key_search_string"; public static final String KEY_THEME_CHANGE = "key_theme_change"; public static final String KEY_MAIN_PAGE_CHANGE = "key_main_page_change"; diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 9cbedff23..2e4ef84e1 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -37,10 +37,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.kiosk.KioskInfo; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; -import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchInfo; -import org.schabi.newpipe.extractor.search.SearchResult; -import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.report.ErrorActivity; @@ -52,7 +50,6 @@ import java.util.List; import io.reactivex.Maybe; import io.reactivex.Single; -import io.reactivex.annotations.NonNull; public final class ExtractorHelper { private static final String TAG = ExtractorHelper.class.getSimpleName(); @@ -82,8 +79,7 @@ public final class ExtractorHelper { final String contentCountry) { checkServiceId(serviceId); return Single.fromCallable(() -> - SearchInfo.get - NewPipe.getService(serviceId).getSearchExtractor(query, contentCountry)) + SearchInfo.getMoreItems(NewPipe.getService(serviceId), query, contentCountry, pageUrl)); } 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 12f6856de..0344e5e79 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -26,10 +26,13 @@ import org.schabi.newpipe.download.DownloadActivity; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SearchExtractor; 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.VideoStream; +import org.schabi.newpipe.extractor.uih.ListUIHandler; +import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.list.channel.ChannelFragment; @@ -283,7 +286,7 @@ public class NavigationHelper { return fragmentManager.popBackStackImmediate(SEARCH_FRAGMENT_TAG, 0); } - public static void openSearchFragment(FragmentManager fragmentManager, int serviceId, String query) { + public static void openSearchFragment(FragmentManager fragmentManager, int serviceId, SearchQIHandler query) { defaultTransaction(fragmentManager) .replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, query)) .addToBackStack(SEARCH_FRAGMENT_TAG) @@ -314,18 +317,18 @@ public class NavigationHelper { .commit(); } - public static void openChannelFragment(FragmentManager fragmentManager, int serviceId, String url, String name) { + public static void openChannelFragment(FragmentManager fragmentManager, int serviceId, ListUIHandler uiHandler, String name) { if (name == null) name = ""; defaultTransaction(fragmentManager) - .replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, url, name)) + .replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, uiHandler, name)) .addToBackStack(null) .commit(); } - public static void openPlaylistFragment(FragmentManager fragmentManager, int serviceId, String url, String name) { + public static void openPlaylistFragment(FragmentManager fragmentManager, int serviceId, ListUIHandler uiHandler, String name) { if (name == null) name = ""; defaultTransaction(fragmentManager) - .replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, url, name)) + .replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, uiHandler, name)) .addToBackStack(null) .commit(); } @@ -370,10 +373,10 @@ public class NavigationHelper { // Through Intents //////////////////////////////////////////////////////////////////////////*/ - public static void openSearch(Context context, int serviceId, String query) { + public static void openSearch(Context context, int serviceId, String searchString) { Intent mIntent = new Intent(context, MainActivity.class); mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId); - mIntent.putExtra(Constants.KEY_QUERY, query); + mIntent.putExtra(Constants.KEY_SEARCH_STRING, searchString); mIntent.putExtra(Constants.KEY_OPEN_SEARCH, true); context.startActivity(mIntent); } From decb167ba9d7b0ecfb6ddadee775051a543a469b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 10 Jul 2018 16:26:42 +0200 Subject: [PATCH 3/6] 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; From 14e0dcb085f826e636003e1fe1f9371bb1099bdc Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 15 Jul 2018 21:21:09 +0200 Subject: [PATCH 4/6] fix names from UIH to LinkHandler --- app/build.gradle | 2 +- .../main/java/org/schabi/newpipe/MainActivity.java | 1 - .../newpipe/fragments/list/BaseListFragment.java | 2 -- .../newpipe/fragments/list/BaseListInfoFragment.java | 4 ++-- .../fragments/list/channel/ChannelFragment.java | 2 +- .../newpipe/fragments/list/kiosk/KioskFragment.java | 12 ++++++------ .../fragments/list/playlist/PlaylistFragment.java | 2 +- .../fragments/list/search/SearchFragment.java | 2 -- .../org/schabi/newpipe/util/NavigationHelper.java | 4 ++-- 9 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 10aaf91a0..014f379f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:a1aaca1be' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:8ee068fd98' 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 f43d413e9..191332e19 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -49,7 +49,6 @@ import android.widget.TextView; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; 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 c4702046d..1db12bba9 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 @@ -16,11 +16,9 @@ import android.view.View; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import org.schabi.newpipe.extractor.uih.ListUIHandler; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; 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 9c3afb7f6..e702c602f 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 @@ -9,8 +9,8 @@ import android.view.View; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.uih.ListUIHandler; -import org.schabi.newpipe.extractor.uih.UIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; +import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.util.Constants; import java.util.Queue; 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 041b550ed..42ba8e0ac 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 @@ -33,7 +33,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import org.schabi.newpipe.extractor.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; 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 66ccfe6c3..114e92e43 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 @@ -18,9 +18,9 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskInfo; -import org.schabi.newpipe.extractor.uih.ListUIHFactory; -import org.schabi.newpipe.extractor.uih.ListUIHandler; -import org.schabi.newpipe.extractor.uih.UIHFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; +import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; @@ -72,10 +72,10 @@ public class KioskFragment extends BaseListInfoFragment { throws ExtractionException { KioskFragment instance = new KioskFragment(); StreamingService service = NewPipe.getService(serviceId); - ListUIHFactory kioskUIHFactory = service.getKioskList() - .getUIHFactoryByType(kioskId); + ListLinkHandlerFactory kioskLinkHandlerFactory = service.getKioskList() + .getListLinkHandlerFactoryByType(kioskId); instance.setInitialData(serviceId, - kioskUIHFactory.fromId(kioskId).getUrl(), kioskId); + kioskLinkHandlerFactory.fromId(kioskId).getUrl(), kioskId); instance.kioskId = kioskId; return instance; } 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 2f60276d7..b7a42791c 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 @@ -30,7 +30,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import org.schabi.newpipe.extractor.uih.ListUIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; 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 503bc86ee..f7ae11fcb 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 @@ -37,12 +37,10 @@ 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; import org.schabi.newpipe.extractor.search.SearchInfo; -import org.schabi.newpipe.extractor.uih.SearchQIHandler; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.list.BaseListFragment; import org.schabi.newpipe.local.history.HistoryRecordManager; 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 2271d79e1..85367e2a5 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -31,8 +31,8 @@ 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.VideoStream; -import org.schabi.newpipe.extractor.uih.ListUIHandler; -import org.schabi.newpipe.extractor.uih.SearchQIHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; +import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler; import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.list.channel.ChannelFragment; From 39e04de208839cd29e9e0353582037a8e5a732b8 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 18 Jul 2018 15:05:49 +0200 Subject: [PATCH 5/6] show radio pin for content filter again --- .../newpipe/fragments/list/search/SearchFragment.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 f7ae11fcb..77274c96a 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 @@ -358,9 +358,17 @@ public class SearchFragment supportActionBar.setDisplayHomeAsUpEnabled(true); } + int itemId = 0; + boolean isFirstItem = true; for(String filter : service.getSearchQIHFactory().getAvailableContentFilter()) { - menu.add(filter); + MenuItem item = menu.add(1, itemId++, 0, filter); + if(isFirstItem) { + item.setChecked(true); + isFirstItem = false; + } } + menu.setGroupCheckable(1, true, true); + restoreFilterChecked(menu, filterItemCheckedId); } From e60db5f928a2af528ea595f323110c3951dfd7e6 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 19 Jul 2018 16:18:57 +0200 Subject: [PATCH 6/6] make new filtersystem translatable --- app/build.gradle | 2 +- .../fragments/list/search/SearchFragment.java | 7 ++++++- .../java/org/schabi/newpipe/util/ServiceHelper.java | 12 ++++++++++++ app/src/main/res/values/strings.xml | 5 +++++ build.gradle | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 014f379f6..fbaab1214 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:8ee068fd98' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:1eff8c5708' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.8.9' 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 77274c96a..5e511c03b 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 @@ -51,6 +51,7 @@ import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.LayoutManagerSmoothScroller; import org.schabi.newpipe.util.NavigationHelper; +import org.schabi.newpipe.util.ServiceHelper; import java.io.IOException; import java.io.InterruptedIOException; @@ -360,8 +361,12 @@ public class SearchFragment int itemId = 0; boolean isFirstItem = true; + final Context c = getContext(); for(String filter : service.getSearchQIHFactory().getAvailableContentFilter()) { - MenuItem item = menu.add(1, itemId++, 0, filter); + MenuItem item = menu.add(1, + itemId++, + 0, + ServiceHelper.getTranslatedFilterString(filter, c)); if(isFirstItem) { item.setChecked(true); isFirstItem = false; 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 e7e52f393..7c781eb14 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -30,6 +30,18 @@ public class ServiceHelper { } } + public static String getTranslatedFilterString(String filter, Context c) { + switch(filter) { + case "all": return c.getString(R.string.all); + case "videos": return c.getString(R.string.videos); + case "channels": return c.getString(R.string.channels); + case "playlists": return c.getString(R.string.playlists); + case "tracks": return c.getString(R.string.tracks); + case "users": return c.getString(R.string.users); + default: return filter; + } + } + /** * Get a resource string with instructions for importing subscriptions for each service. * diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8686d21d3..502483667 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -125,7 +125,12 @@ Error report All Channel + Channels Playlist + Playlists + Videos + Tracks + Users Yes Later Disabled diff --git a/build.gradle b/build.gradle index a45c00aef..0448ed61e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files