1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 11:02:35 +01:00

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'
}
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'

View File

@ -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());

View File

@ -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;

View File

@ -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);

View File

@ -162,10 +162,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> 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<I, N> extends BaseStateFragment<I> 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<I, N> extends BaseStateFragment<I> 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());
}

View File

@ -30,7 +30,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
@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<I extends ListInfo>
// 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 : "";
}
}

View File

@ -91,9 +91,9 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
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<ChannelInfo> {
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<ChannelInfo> {
@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, uiHandler.getUrl(), currentNextPageUrl);
return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl);
}
@Override
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()) {
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,
UserAction.REQUESTED_CHANNEL,
NewPipe.getNameOfService(serviceId),
uiHandler.getUrl(),
url,
errorId);
return true;
}

View File

@ -75,7 +75,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
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<KioskInfo> {
.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<KioskInfo> {
.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<KioskInfo> {
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);
}
}
}

View File

@ -83,9 +83,9 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
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<PlaylistInfo> {
@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, uiHandler.getUrl(), currentNextPageUrl);
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl);
}
@Override
protected Single<PlaylistInfo> 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<PlaylistInfo> {
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<PlaylistInfo> {
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<PlaylistInfo> {
onUnrecoverableError(exception,
UserAction.REQUESTED_PLAYLIST,
NewPipe.getNameOfService(serviceId),
uiHandler.getUrl(),
url,
errorId);
return true;
}

View File

@ -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<String> 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<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;
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;

View File

@ -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) {

View File

@ -324,9 +324,7 @@ public class SubscriptionFragment extends BaseStateFragment<List<SubscriptionEnt
// 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.getUrl(),
selectedItem.getName());
} catch (Exception 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.services.youtube.extractors.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,20 +65,33 @@ public final class ExtractorHelper {
}
public static Single<SearchInfo> searchFor(final int serviceId,
final SearchQIHandler query,
final String searchString,
final List<String> 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<InfoItemsPage> getMoreSearchItems(final int serviceId,
final SearchQIHandler query,
final String pageUrl,
final String contentCountry) {
final String searchString,
final List<String> 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));
}
});
}
/**

View File

@ -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;
}

View File

@ -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;