Search in sources :

Example 6 with StreamingService

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();
    }
}
Also used : StreamingService(org.schabi.newpipe.extractor.StreamingService)

Example 7 with StreamingService

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);
        }
    }
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) SubscriptionExtractor(org.schabi.newpipe.extractor.subscription.SubscriptionExtractor) StreamingService(org.schabi.newpipe.extractor.StreamingService) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) AnimationUtils.animateView(org.schabi.newpipe.util.AnimationUtils.animateView) CollapsibleView(org.schabi.newpipe.views.CollapsibleView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 8 with StreamingService

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);
        }
    }
}
Also used : ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) StreamingService(org.schabi.newpipe.extractor.StreamingService) ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) IOException(java.io.IOException)

Example 9 with StreamingService

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;
}
Also used : StreamingService(org.schabi.newpipe.extractor.StreamingService) UrlIdHandler(org.schabi.newpipe.extractor.UrlIdHandler)

Example 10 with StreamingService

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);
}
Also used : Consumer(io.reactivex.functions.Consumer) Intent(android.content.Intent) StreamingService(org.schabi.newpipe.extractor.StreamingService) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) IOException(java.io.IOException)

Aggregations

StreamingService (org.schabi.newpipe.extractor.StreamingService)12 ExtractionException (org.schabi.newpipe.extractor.exceptions.ExtractionException)5 Intent (android.content.Intent)4 View (android.view.View)3 TextView (android.widget.TextView)3 IOException (java.io.IOException)3 Handler (android.os.Handler)2 RecyclerView (android.support.v7.widget.RecyclerView)2 MenuItem (android.view.MenuItem)2 ImageView (android.widget.ImageView)2 ParsingException (org.schabi.newpipe.extractor.exceptions.ParsingException)2 StyleRes (android.support.annotation.StyleRes)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 Toolbar (android.support.v7.widget.Toolbar)1 Consumer (io.reactivex.functions.Consumer)1 InterruptedIOException (java.io.InterruptedIOException)1