make the new extractor refactorings work with SoundCloud

This commit is contained in:
Christian Schabesberger 2018-07-10 16:26:42 +02:00
parent d5a500c037
commit decb167ba9
15 changed files with 163 additions and 150 deletions

View File

@ -54,7 +54,7 @@ dependencies {
exclude module: 'support-annotations' exclude module: 'support-annotations'
} }
implementation 'com.github.TeamNewPipe:NewPipeExtractor:4746a1c48a8682' implementation 'com.github.TeamNewPipe:NewPipeExtractor:a1aaca1be'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.8.9' testImplementation 'org.mockito:mockito-core:2.8.9'

View File

@ -410,17 +410,13 @@ public class MainActivity extends AppCompatActivity {
case CHANNEL: case CHANNEL:
NavigationHelper.openChannelFragment(getSupportFragmentManager(), NavigationHelper.openChannelFragment(getSupportFragmentManager(),
serviceId, serviceId,
NewPipe.getService(serviceId) url,
.getChannelUIHFactory()
.fromUrl(url),
title); title);
break; break;
case PLAYLIST: case PLAYLIST:
NavigationHelper.openPlaylistFragment(getSupportFragmentManager(), NavigationHelper.openPlaylistFragment(getSupportFragmentManager(),
serviceId, serviceId,
NewPipe.getService(serviceId) url,
.getChannelUIHFactory()
.fromUrl(url),
title); title);
break; break;
} }
@ -431,9 +427,7 @@ public class MainActivity extends AppCompatActivity {
NavigationHelper.openSearchFragment( NavigationHelper.openSearchFragment(
getSupportFragmentManager(), getSupportFragmentManager(),
serviceId, serviceId,
NewPipe.getService(serviceId) searchString);
.getSearchQIHFactory()
.fromQuery(searchString));
} else { } else {
NavigationHelper.gotoMainFragment(getSupportFragmentManager()); NavigationHelper.gotoMainFragment(getSupportFragmentManager());

View File

@ -132,9 +132,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
NavigationHelper.openSearchFragment( NavigationHelper.openSearchFragment(
getFragmentManager(), getFragmentManager(),
ServiceHelper.getSelectedServiceId(activity), ServiceHelper.getSelectedServiceId(activity),
NewPipe.getService(currentServiceId) "");
.getSearchQIHFactory()
.fromQuery(""));
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), 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), String name = preferences.getString(getString(R.string.main_page_selected_channel_name),
FALLBACK_CHANNEL_NAME); FALLBACK_CHANNEL_NAME);
ChannelFragment fragment = ChannelFragment.getInstance(serviceId, ChannelFragment fragment = ChannelFragment.getInstance(serviceId,
NewPipe.getService(currentServiceId).getPlaylistUIHFactory().fromUrl(url), url,
name); name);
fragment.useAsFrontPage(true); fragment.useAsFrontPage(true);
return fragment; return fragment;

View File

@ -371,9 +371,7 @@ public class VideoDetailFragment
NavigationHelper.openChannelFragment( NavigationHelper.openChannelFragment(
getFragmentManager(), getFragmentManager(),
currentInfo.getServiceId(), currentInfo.getServiceId(),
NewPipe.getService(currentInfo.getServiceId()) currentInfo.getUploaderUrl(),
.getChannelUIHFactory()
.fromUrl(currentInfo.getUploaderUrl()),
currentInfo.getUploaderName()); currentInfo.getUploaderName());
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);

View File

@ -162,10 +162,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
getParentFragment().getFragmentManager() getParentFragment().getFragmentManager()
: getFragmentManager(), : getFragmentManager(),
selectedItem.getServiceId(), selectedItem.getServiceId(),
NewPipe.getService(selectedItem selectedItem.getUrl(),
.getServiceId())
.getChannelUIHFactory()
.fromUrl(selectedItem.getUrl()),
selectedItem.getName()); selectedItem.getName());
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
@ -183,9 +180,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
? getParentFragment().getFragmentManager() ? getParentFragment().getFragmentManager()
: getFragmentManager(), : getFragmentManager(),
selectedItem.getServiceId(), selectedItem.getServiceId(),
NewPipe.getService(selectedItem.getServiceId()) selectedItem.getUrl(),
.getPlaylistUIHFactory()
.fromUrl(selectedItem.getUrl()),
selectedItem.getName()); selectedItem.getName());
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
@ -204,7 +199,9 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
private void onStreamSelected(StreamInfoItem selectedItem) { private void onStreamSelected(StreamInfoItem selectedItem) {
onItemSelected(selectedItem); onItemSelected(selectedItem);
NavigationHelper.openVideoDetailFragment(useAsFrontPage ? getParentFragment().getFragmentManager() : getFragmentManager(), NavigationHelper.openVideoDetailFragment(useAsFrontPage
? getParentFragment().getFragmentManager()
: getFragmentManager(),
selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName());
} }

View File

@ -30,7 +30,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
@State @State
protected String name; protected String name;
@State @State
protected ListUIHandler uiHandler; protected String url;
protected I currentInfo; protected I currentInfo;
protected String currentNextPageUrl; protected String currentNextPageUrl;
@ -187,9 +187,9 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
// Utils // Utils
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
protected void setInitialData(int serviceId, ListUIHandler uiHandler, String name) { protected void setInitialData(int serviceId, String url, String name) {
this.serviceId = serviceId; this.serviceId = serviceId;
this.uiHandler = uiHandler; this.url = url;
this.name = !TextUtils.isEmpty(name) ? name : ""; this.name = !TextUtils.isEmpty(name) ? name : "";
} }
} }

View File

@ -91,9 +91,9 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
private MenuItem menuRssButton; 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(); ChannelFragment instance = new ChannelFragment();
instance.setInitialData(serviceId, uiHandler, name); instance.setInitialData(serviceId, url, name);
return instance; return instance;
} }
@ -237,10 +237,10 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
openRssFeed(); openRssFeed();
break; break;
case R.id.menu_item_openInBrowser: case R.id.menu_item_openInBrowser:
openUrlInBrowser(uiHandler.getUrl()); openUrlInBrowser(url);
break; break;
case R.id.menu_item_share: case R.id.menu_item_share:
shareUrl(name, uiHandler.getUrl()); shareUrl(name, url);
break; break;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -406,12 +406,12 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
@Override @Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() { protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, uiHandler.getUrl(), currentNextPageUrl); return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl);
} }
@Override @Override
protected Single<ChannelInfo> loadResult(boolean forceLoad) { protected Single<ChannelInfo> 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<ChannelInfo> {
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.REQUESTED_CHANNEL, NewPipe.getNameOfService(serviceId), 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<ChannelInfo> {
onUnrecoverableError(exception, onUnrecoverableError(exception,
UserAction.REQUESTED_CHANNEL, UserAction.REQUESTED_CHANNEL,
NewPipe.getNameOfService(serviceId), NewPipe.getNameOfService(serviceId),
uiHandler.getUrl(), url,
errorId); errorId);
return true; return true;
} }

View File

@ -75,7 +75,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
ListUIHFactory kioskUIHFactory = service.getKioskList() ListUIHFactory kioskUIHFactory = service.getKioskList()
.getUIHFactoryByType(kioskId); .getUIHFactoryByType(kioskId);
instance.setInitialData(serviceId, instance.setInitialData(serviceId,
kioskUIHFactory.fromId(kioskId), kioskId); kioskUIHFactory.fromId(kioskId).getUrl(), kioskId);
instance.kioskId = kioskId; instance.kioskId = kioskId;
return instance; return instance;
} }
@ -135,7 +135,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
.getString(getString(R.string.content_country_key), .getString(getString(R.string.content_country_key),
getString(R.string.default_country_value)); getString(R.string.default_country_value));
return ExtractorHelper.getKioskInfo(serviceId, return ExtractorHelper.getKioskInfo(serviceId,
uiHandler.getUrl(), url,
contentCountry, contentCountry,
forceReload); forceReload);
} }
@ -147,7 +147,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
.getString(getString(R.string.content_country_key), .getString(getString(R.string.content_country_key),
getString(R.string.default_country_value)); getString(R.string.default_country_value));
return ExtractorHelper.getMoreKioskItems(serviceId, return ExtractorHelper.getMoreKioskItems(serviceId,
uiHandler.getUrl(), url,
currentNextPageUrl, currentNextPageUrl,
contentCountry); contentCountry);
} }
@ -183,7 +183,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), showSnackBarError(result.getErrors(),
UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId) UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId)
, "Get next page of: " + uiHandler.getUrl(), 0); , "Get next page of: " + url, 0);
} }
} }
} }

View File

@ -83,9 +83,9 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
private MenuItem playlistBookmarkButton; 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(); PlaylistFragment instance = new PlaylistFragment();
instance.setInitialData(serviceId, uiHandler, name); instance.setInitialData(serviceId, url, name);
return instance; return instance;
} }
@ -220,22 +220,22 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
@Override @Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() { protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, uiHandler.getUrl(), currentNextPageUrl); return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl);
} }
@Override @Override
protected Single<PlaylistInfo> loadResult(boolean forceLoad) { protected Single<PlaylistInfo> loadResult(boolean forceLoad) {
return ExtractorHelper.getPlaylistInfo(serviceId, uiHandler.getUrl(), forceLoad); return ExtractorHelper.getPlaylistInfo(serviceId, url, forceLoad);
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_item_openInBrowser: case R.id.menu_item_openInBrowser:
openUrlInBrowser(uiHandler.getUrl()); openUrlInBrowser(url);
break; break;
case R.id.menu_item_share: case R.id.menu_item_share:
shareUrl(name, uiHandler.getUrl()); shareUrl(name, url);
break; break;
case R.id.menu_item_bookmark: case R.id.menu_item_bookmark:
onBookmarkClicked(); onBookmarkClicked();
@ -275,9 +275,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
try { try {
NavigationHelper.openChannelFragment(getFragmentManager(), NavigationHelper.openChannelFragment(getFragmentManager(),
result.getServiceId(), result.getServiceId(),
NewPipe.getService(serviceId) result.getUploaderUrl(),
.getChannelUIHFactory()
.fromUrl(result.getUploaderUrl()),
result.getUploaderName()); result.getUploaderName());
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
@ -337,7 +335,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId) 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<PlaylistInfo> {
onUnrecoverableError(exception, onUnrecoverableError(exception,
UserAction.REQUESTED_PLAYLIST, UserAction.REQUESTED_PLAYLIST,
NewPipe.getNameOfService(serviceId), NewPipe.getNameOfService(serviceId),
uiHandler.getUrl(), url,
errorId); errorId);
return true; return true;
} }

View File

@ -29,12 +29,15 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import com.facebook.stetho.common.ListUtil;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.database.history.model.SearchHistoryEntry; import org.schabi.newpipe.database.history.model.SearchHistoryEntry;
import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor;
@ -55,6 +58,7 @@ import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.net.SocketException; import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
@ -69,6 +73,8 @@ import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.PublishSubject;
import static java.util.Arrays.asList;
import static org.schabi.newpipe.util.AnimationUtils.animateView; import static org.schabi.newpipe.util.AnimationUtils.animateView;
public class SearchFragment public class SearchFragment
@ -95,10 +101,19 @@ public class SearchFragment
@State @State
protected int serviceId = Constants.NO_SERVICE_ID; protected int serviceId = Constants.NO_SERVICE_ID;
// this three represet the current search query
@State @State
protected SearchQIHandler searchQuery; protected String searchString;
@State @State
protected SearchQIHandler lastSearchedQuery; protected String[] contentFilter;
@State
protected String sortFilter;
// these represtent the last search
@State
protected String lastSearchedString;
@State @State
protected boolean wasSearchFocused = false; 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 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(); searchFragment.setSearchOnResume();
} }
@ -212,12 +227,12 @@ public class SearchFragment
"", R.string.general_error)); "", R.string.general_error));
} }
if (!TextUtils.isEmpty(searchQuery.getSearchString())) { if (!TextUtils.isEmpty(searchString)) {
if (wasLoading.getAndSet(false)) { if (wasLoading.getAndSet(false)) {
search(searchQuery); search(searchString, contentFilter, sortFilter);
} else if (infoListAdapter.getItemsList().size() == 0) { } else if (infoListAdapter.getItemsList().size() == 0) {
if (savedState == null) { if (savedState == null) {
search(searchQuery); search(searchString, contentFilter, sortFilter);
} else if (!isLoading.get() && !wasSearchFocused) { } else if (!isLoading.get() && !wasSearchFocused) {
infoListAdapter.clearStreamItemList(); infoListAdapter.clearStreamItemList();
showEmptyState(); showEmptyState();
@ -227,7 +242,7 @@ public class SearchFragment
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) initSuggestionObserver(); if (suggestionDisposable == null || suggestionDisposable.isDisposed()) initSuggestionObserver();
if (TextUtils.isEmpty(searchQuery.getSearchString()) || wasSearchFocused) { if (TextUtils.isEmpty(searchString) || wasSearchFocused) {
showKeyboardSearch(); showKeyboardSearch();
showSuggestionsPanel(); showSuggestionsPanel();
} else { } else {
@ -257,8 +272,8 @@ public class SearchFragment
switch (requestCode) { switch (requestCode) {
case ReCaptchaActivity.RECAPTCHA_REQUEST: case ReCaptchaActivity.RECAPTCHA_REQUEST:
if (resultCode == Activity.RESULT_OK if (resultCode == Activity.RESULT_OK
&& !TextUtils.isEmpty(searchQuery.getSearchString())) { && !TextUtils.isEmpty(searchString)) {
search(searchQuery); search(searchString, contentFilter, sortFilter);
} else Log.e(TAG, "ReCaptcha failed"); } else Log.e(TAG, "ReCaptcha failed");
break; break;
@ -305,18 +320,9 @@ public class SearchFragment
@Override @Override
public void onSaveInstanceState(Bundle bundle) { public void onSaveInstanceState(Bundle bundle) {
try { searchString = searchEditText != null
searchQuery = searchEditText != null ? searchEditText.getText().toString()
? NewPipe.getService(serviceId).getSearchQIHFactory().fromQuery( : searchString;
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); super.onSaveInstanceState(bundle);
} }
@ -326,12 +332,11 @@ public class SearchFragment
@Override @Override
public void reloadContent() { public void reloadContent() {
if (!TextUtils.isEmpty(searchQuery.getSearchString()) if (!TextUtils.isEmpty(searchString)
|| (searchEditText != null && !TextUtils.isEmpty(searchEditText.getText()))) { || (searchEditText != null && !TextUtils.isEmpty(searchEditText.getText()))) {
search(!TextUtils.isEmpty(searchQuery.getSearchString()) search(!TextUtils.isEmpty(searchString)
? searchQuery ? searchString
: getSearchQuery(searchEditText.getText().toString(), : searchEditText.getText().toString(), new String[0], "");
new ArrayList<>(0), ""));
} else { } else {
if (searchEditText != null) { if (searchEditText != null) {
searchEditText.setText(""); searchEditText.setText("");
@ -387,14 +392,21 @@ public class SearchFragment
private TextWatcher textWatcher; private TextWatcher textWatcher;
private void showSearchOnStart() { private void showSearchOnStart() {
if (DEBUG) Log.d(TAG, "showSearchOnStart() called, searchQuery → " + searchQuery+", lastSearchedQuery → " + lastSearchedQuery); if (DEBUG) Log.d(TAG, "showSearchOnStart() called, searchQuery → "
searchEditText.setText(searchQuery.getSearchString()); + 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.setTranslationX(100);
searchToolbarContainer.setAlpha(0f); searchToolbarContainer.setAlpha(0f);
searchToolbarContainer.setVisibility(View.VISIBLE); 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 { } else {
searchToolbarContainer.setTranslationX(0); searchToolbarContainer.setTranslationX(0);
searchToolbarContainer.setAlpha(1f); searchToolbarContainer.setAlpha(1f);
@ -435,7 +447,7 @@ public class SearchFragment
suggestionListAdapter.setListener(new SuggestionListAdapter.OnSuggestionItemSelected() { suggestionListAdapter.setListener(new SuggestionListAdapter.OnSuggestionItemSelected() {
@Override @Override
public void onSuggestionItemSelected(SuggestionItem item) { public void onSuggestionItemSelected(SuggestionItem item) {
search(getSearchQuery(item.query, new ArrayList<>(), "")); search(item.query, new String[0], "");
searchEditText.setText(item.query); searchEditText.setText(item.query);
} }
@ -476,7 +488,7 @@ public class SearchFragment
if (event != null if (event != null
&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
|| event.getAction() == EditorInfo.IME_ACTION_SEARCH)) { || event.getAction() == EditorInfo.IME_ACTION_SEARCH)) {
search(getSearchQuery(searchEditText.getText().toString(), new ArrayList<>(), "")); search(searchEditText.getText().toString(), new String[0], "");
return true; return true;
} }
return false; return false;
@ -557,10 +569,12 @@ public class SearchFragment
@Override @Override
public boolean onBackPressed() { 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(); hideSuggestionsPanel();
hideKeyboardSearch(); hideKeyboardSearch();
searchEditText.setText(lastSearchedQuery.getSearchString()); searchEditText.setText(lastSearchedString);
return true; return true;
} }
return false; return false;
@ -576,8 +590,8 @@ public class SearchFragment
final Observable<String> observable = suggestionPublisher final Observable<String> observable = suggestionPublisher
.debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS) .debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS)
.startWith(searchQuery != null .startWith(searchString != null
? searchQuery.getSearchString() ? searchString
: "") : "")
.filter(searchString -> isSuggestionsEnabled); .filter(searchString -> isSuggestionsEnabled);
@ -650,17 +664,17 @@ public class SearchFragment
// no-op // no-op
} }
private void search(final SearchQIHandler query) { private void search(final String searchString, String[] contentFilter, String sortFilter) {
if (DEBUG) Log.d(TAG, "search() called with: query = [" + query + "]"); if (DEBUG) Log.d(TAG, "search() called with: query = [" + searchString + "]");
if (query.getSearchString().isEmpty()) return; if (searchString.isEmpty()) return;
try { try {
final StreamingService service = NewPipe.getServiceByUrl(query.getUrl()); final StreamingService service = NewPipe.getServiceByUrl(searchString);
if (service != null) { if (service != null) {
showLoading(); showLoading();
disposables.add(Observable disposables.add(Observable
.fromCallable(() -> .fromCallable(() ->
NavigationHelper.getIntentByLink(activity, service, query.getUrl())) NavigationHelper.getIntentByLink(activity, service, searchString))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(intent -> { .subscribe(intent -> {
@ -674,21 +688,20 @@ public class SearchFragment
// Exception occurred, it's not a url // Exception occurred, it's not a url
} }
lastSearchedQuery = query; lastSearchedString = this.searchString;
searchQuery = query; this.searchString = searchString;
currentPageUrl = "";
infoListAdapter.clearStreamItemList(); infoListAdapter.clearStreamItemList();
hideSuggestionsPanel(); hideSuggestionsPanel();
hideKeyboardSearch(); hideKeyboardSearch();
historyRecordManager.onSearched(serviceId, query.getSearchString()) historyRecordManager.onSearched(serviceId, searchString)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
ignored -> {}, ignored -> {},
error -> showSnackBarError(error, UserAction.SEARCHED, 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); startLoading(false);
} }
@ -697,11 +710,16 @@ public class SearchFragment
super.startLoading(forceLoad); super.startLoading(forceLoad);
if (disposables != null) disposables.clear(); if (disposables != null) disposables.clear();
if (searchDisposable != null) searchDisposable.dispose(); if (searchDisposable != null) searchDisposable.dispose();
searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, contentCountry) searchDisposable = ExtractorHelper.searchFor(serviceId,
searchString,
Arrays.asList(contentFilter),
sortFilter,
contentCountry)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doOnEvent((searchResult, throwable) -> isLoading.set(false)) .doOnEvent((searchResult, throwable) -> isLoading.set(false))
.subscribe(this::handleResult, this::onError); .subscribe(this::handleResult, this::onError);
} }
@Override @Override
@ -709,8 +727,13 @@ public class SearchFragment
isLoading.set(true); isLoading.set(true);
showListFooter(true); showListFooter(true);
if (searchDisposable != null) searchDisposable.dispose(); if (searchDisposable != null) searchDisposable.dispose();
searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchDisposable = ExtractorHelper.getMoreSearchItems(
searchQuery, nextPageUrl, contentCountry) serviceId,
searchString,
asList(contentFilter),
sortFilter,
nextPageUrl,
contentCountry)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doOnEvent((nextItemsResult, throwable) -> isLoading.set(false)) .doOnEvent((nextItemsResult, throwable) -> isLoading.set(false))
@ -737,31 +760,18 @@ public class SearchFragment
this.filterItemCheckedId = item.getItemId(); this.filterItemCheckedId = item.getItemId();
item.setChecked(true); item.setChecked(true);
searchQuery = getSearchQuery(searchQuery.getSearchString(), contentFilter, ""); this.contentFilter = new String[] {contentFilter.get(0)};
if (!TextUtils.isEmpty(searchQuery.getSearchString())) { if (!TextUtils.isEmpty(searchString)) {
search(searchQuery); 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.serviceId = serviceId;
this.searchQuery = searchQuery; this.searchString = searchString;
} this.contentFilter = contentfilter;
this.sortFilter = sortFilter;
private SearchQIHandler getSearchQuery(String searchString,
List<String> 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;
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -786,7 +796,7 @@ public class SearchFragment
? R.string.parsing_error ? R.string.parsing_error
: R.string.general_error; : R.string.general_error;
onUnrecoverableError(exception, UserAction.GET_SUGGESTIONS, 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) { public void handleResult(@NonNull SearchInfo result) {
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.SEARCHED, 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 (infoListAdapter.getItemsList().size() == 0) {
if (!result.getRelatedItems().isEmpty()) { if (!result.getRelatedItems().isEmpty()) {
@ -841,7 +853,7 @@ public class SearchFragment
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.SEARCHED, showSnackBarError(result.getErrors(), UserAction.SEARCHED,
NewPipe.getNameOfService(serviceId) NewPipe.getNameOfService(serviceId)
, "\"" + searchQuery + "\" → page: " + nextPageUrl, 0); , "\"" + searchString + "\" → page: " + nextPageUrl, 0);
} }
super.handleNextItems(result); super.handleNextItems(result);
} }
@ -858,7 +870,7 @@ public class SearchFragment
? R.string.parsing_error ? R.string.parsing_error
: R.string.general_error; : R.string.general_error;
onUnrecoverableError(exception, UserAction.SEARCHED, onUnrecoverableError(exception, UserAction.SEARCHED,
NewPipe.getNameOfService(serviceId), searchQuery.getSearchString(), errorId); NewPipe.getNameOfService(serviceId), searchString, errorId);
} }
return true; return true;

View File

@ -117,9 +117,7 @@ public final class BookmarkFragment
NavigationHelper.openPlaylistFragment( NavigationHelper.openPlaylistFragment(
fragmentManager, fragmentManager,
entry.getServiceId(), entry.getServiceId(),
NewPipe.getService(entry.getServiceId()) entry.getUrl(),
.getPlaylistUIHFactory()
.fromUrl(entry.getUrl()),
entry.getName()); entry.getName());
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -324,9 +324,7 @@ public class SubscriptionFragment extends BaseStateFragment<List<SubscriptionEnt
// Requires the parent fragment to find holder for fragment replacement // Requires the parent fragment to find holder for fragment replacement
NavigationHelper.openChannelFragment(getParentFragment().getFragmentManager(), NavigationHelper.openChannelFragment(getParentFragment().getFragmentManager(),
selectedItem.getServiceId(), selectedItem.getServiceId(),
NewPipe.getService(selectedItem.getServiceId()) selectedItem.getUrl(),
.getChannelUIHFactory()
.fromUrl(selectedItem.getUrl()),
selectedItem.getName()); selectedItem.getName());
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);

View File

@ -40,7 +40,6 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.search.SearchInfo; import org.schabi.newpipe.extractor.search.SearchInfo;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo; 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.ErrorActivity;
import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.report.UserAction;
@ -66,20 +65,33 @@ public final class ExtractorHelper {
} }
public static Single<SearchInfo> searchFor(final int serviceId, public static Single<SearchInfo> searchFor(final int serviceId,
final SearchQIHandler query, final String searchString,
final List<String> contentFilter,
final String sortFilter,
final String contentCountry) { final String contentCountry) {
checkServiceId(serviceId); checkServiceId(serviceId);
return Single.fromCallable(() -> 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<InfoItemsPage> getMoreSearchItems(final int serviceId, public static Single<InfoItemsPage> getMoreSearchItems(final int serviceId,
final SearchQIHandler query, final String searchString,
final List<String> contentFilter,
final String sortFilter,
final String pageUrl, final String pageUrl,
final String contentCountry) { final String contentCountry) {
checkServiceId(serviceId); checkServiceId(serviceId);
return Single.fromCallable(() -> 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)); serviceId == -1 ? "none" : NewPipe.getNameOfService(serviceId), url + (optionalErrorMessage == null ? "" : optionalErrorMessage), errorId));
} }
}); });
} }
/** /**

View File

@ -286,9 +286,11 @@ public class NavigationHelper {
return fragmentManager.popBackStackImmediate(SEARCH_FRAGMENT_TAG, 0); 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) defaultTransaction(fragmentManager)
.replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, query)) .replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, searchString))
.addToBackStack(SEARCH_FRAGMENT_TAG) .addToBackStack(SEARCH_FRAGMENT_TAG)
.commit(); .commit();
} }
@ -317,18 +319,25 @@ public class NavigationHelper {
.commit(); .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 = ""; if (name == null) name = "";
defaultTransaction(fragmentManager) defaultTransaction(fragmentManager)
.replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, uiHandler, name)) .replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, url, name))
.addToBackStack(null) .addToBackStack(null)
.commit(); .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 = ""; if (name == null) name = "";
defaultTransaction(fragmentManager) defaultTransaction(fragmentManager)
.replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, uiHandler, name)) .replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, url, name))
.addToBackStack(null) .addToBackStack(null)
.commit(); .commit();
} }
@ -470,7 +479,8 @@ public class NavigationHelper {
switch (linkType) { switch (linkType) {
case STREAM: 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)); .getBoolean(context.getString(R.string.autoplay_through_intent_key), false));
break; break;
} }

View File

@ -5,7 +5,6 @@ import android.preference.PreferenceManager;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;