From d8888e3495da81321d5f5f302b2aea0b399634fa Mon Sep 17 00:00:00 2001 From: ktprograms Date: Sat, 14 Aug 2021 09:07:27 +0800 Subject: [PATCH] Catch error from ExtractorHelper.getStreamInfo, remove blockingGet --- .../newpipe/util/StreamDialogEntry.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 11b354b1f..06edd4d07 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.util; import android.content.Context; import android.net.Uri; +import android.widget.Toast; import androidx.fragment.app.Fragment; @@ -37,17 +38,23 @@ public enum StreamDialogEntry { final int serviceId = item.getServiceId(); final String url = item.getUrl(); // TODO: Some visual loading indicator - final String uploaderUrl = ExtractorHelper.getStreamInfo(serviceId, url, false) + ExtractorHelper.getStreamInfo(serviceId, url, false) .subscribeOn(Schedulers.io()) - .blockingGet() - .getUploaderUrl(); - NewPipeDatabase.getInstance(fragment.getContext()).streamDAO() - .setUploaderUrl(serviceId, url, uploaderUrl) - .subscribeOn(Schedulers.io()).subscribe(); - // For some reason `getParentFragmentManager()` doesn't work, but this does. - NavigationHelper.openChannelFragment( - fragment.requireActivity().getSupportFragmentManager(), - item.getServiceId(), uploaderUrl, item.getUploaderName()); + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + NewPipeDatabase.getInstance(fragment.getContext()).streamDAO() + .setUploaderUrl(serviceId, url, result.getUploaderUrl()) + .subscribeOn(Schedulers.io()).subscribe(); + // For some reason `getParentFragmentManager()` doesn't work, but this does. + NavigationHelper.openChannelFragment( + fragment.requireActivity().getSupportFragmentManager(), + item.getServiceId(), result.getUploaderUrl(), + item.getUploaderName()); + }, throwable -> Toast.makeText( + fragment.getContext(), + "Error at Show Channel Details", + Toast.LENGTH_SHORT + ).show()); } else { // For some reason `getParentFragmentManager()` doesn't work, but this does. NavigationHelper.openChannelFragment(