use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class NavStack method navBack.
public void navBack(Activity activity) throws Exception {
if (stack.size() == 0) {
// if stack is already empty here, activity was probably called
// from another app
activity.finish();
return;
}
// remove curent activty, since we dont want to return to itself
stack.pop();
if (stack.size() == 0) {
// if no more page is on the stack this means we are home
openMainActivity(activity);
return;
}
// this element will reapear, since by calling the old page
NavEntry entry = stack.pop();
// this element will be pushed on top again
try {
StreamingService service = NewPipe.getService(entry.serviceId);
switch(service.getLinkTypeByUrl(entry.url)) {
case STREAM:
openDetailActivity(activity, entry.url, entry.serviceId);
break;
case CHANNEL:
openChannelActivity(activity, entry.url, entry.serviceId);
break;
case NONE:
throw new Exception("Url not known to service. service=" + Integer.toString(entry.serviceId) + " url=" + entry.url);
default:
openMainActivity(activity);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class SubscriptionFragment method setupImportFromItems.
private void setupImportFromItems(final ViewGroup listHolder) {
final View previousBackupItem = addItemView(getString(R.string.previous_export), ThemeHelper.resolveResourceIdFromAttr(getContext(), R.attr.ic_backup), listHolder);
previousBackupItem.setOnClickListener(item -> onImportPreviousSelected());
final int iconColor = ThemeHelper.isLightThemeSelected(getContext()) ? Color.BLACK : Color.WHITE;
final String[] services = getResources().getStringArray(R.array.service_list);
for (String serviceName : services) {
try {
final StreamingService service = NewPipe.getService(serviceName);
final SubscriptionExtractor subscriptionExtractor = service.getSubscriptionExtractor();
if (subscriptionExtractor == null)
continue;
final List<SubscriptionExtractor.ContentSource> supportedSources = subscriptionExtractor.getSupportedSources();
if (supportedSources.isEmpty())
continue;
final View itemView = addItemView(serviceName, ServiceHelper.getIcon(service.getServiceId()), listHolder);
final ImageView iconView = itemView.findViewById(android.R.id.icon1);
iconView.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN);
itemView.setOnClickListener(selectedItem -> onImportFromServiceSelected(service.getServiceId()));
} catch (ExtractionException e) {
throw new RuntimeException("Services array contains an entry that it's not a valid service name (" + serviceName + ")", e);
}
}
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class ContentSettingsFragment method onResume.
@Override
public void onResume() {
super.onResume();
final String mainPageContentKey = getString(R.string.main_page_content_key);
final Preference mainPagePref = findPreference(getString(R.string.main_page_content_key));
final String bpk = getString(R.string.blank_page_key);
if (defaultPreferences.getString(mainPageContentKey, bpk).equals(getString(R.string.channel_page_key))) {
mainPagePref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error"));
} else if (defaultPreferences.getString(mainPageContentKey, bpk).equals(getString(R.string.kiosk_page_key))) {
try {
StreamingService service = NewPipe.getService(defaultPreferences.getInt(getString(R.string.main_page_selected_service), 0));
String kioskName = KioskTranslator.getTranslatedKioskName(defaultPreferences.getString(getString(R.string.main_page_selectd_kiosk_id), "Trending"), getContext());
String summary = String.format(getString(R.string.service_kiosk_string), service.getServiceInfo().getName(), kioskName);
mainPagePref.setSummary(summary);
} catch (Exception e) {
onError(e);
}
}
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class KioskFragment method getInstance.
public static KioskFragment getInstance(int serviceId, String kioskId) throws ExtractionException {
KioskFragment instance = new KioskFragment();
StreamingService service = NewPipe.getService(serviceId);
UrlIdHandler kioskTypeUrlIdHandler = service.getKioskList().getUrlIdHandlerByType(kioskId);
instance.setInitialData(serviceId, kioskTypeUrlIdHandler.getUrl(kioskId), kioskId);
instance.kioskId = kioskId;
return instance;
}
use of org.schabi.newpipe.extractor.StreamingService in project NewPipe by TeamNewPipe.
the class SearchFragment method search.
private void search(final String query) {
if (DEBUG)
Log.d(TAG, "search() called with: query = [" + query + "]");
if (query.isEmpty())
return;
try {
final StreamingService service = NewPipe.getServiceByUrl(query);
if (service != null) {
showLoading();
disposables.add(Observable.fromCallable(new Callable<Intent>() {
@Override
public Intent call() throws Exception {
return NavigationHelper.getIntentByLink(activity, service, query);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Intent>() {
@Override
public void accept(Intent intent) throws Exception {
getFragmentManager().popBackStackImmediate();
activity.startActivity(intent);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
showError(getString(R.string.url_not_supported_toast), false);
}
}));
return;
}
} catch (Exception e) {
// Exception occurred, it's not a url
}
lastSearchedQuery = query;
searchQuery = query;
currentPage = 0;
infoListAdapter.clearStreamItemList();
hideSuggestionsPanel();
hideKeyboardSearch();
historyRecordManager.onSearched(serviceId, query).observeOn(AndroidSchedulers.mainThread()).subscribe(ignored -> {
}, error -> showSnackBarError(error, UserAction.SEARCHED, NewPipe.getNameOfService(serviceId), query, 0));
suggestionPublisher.onNext(query);
startLoading(false);
}
Aggregations