Better handle url not supported in RouterActivity
Make sure the url not supported dialog is only shown when the url is really not supported, not on any ExtractionException
This commit is contained in:
parent
8ce18647f1
commit
285ea4e3fd
|
@ -150,6 +150,7 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
private void handleUrl(final String url) {
|
private void handleUrl(final String url) {
|
||||||
disposables.add(Observable
|
disposables.add(Observable
|
||||||
.fromCallable(() -> {
|
.fromCallable(() -> {
|
||||||
|
try {
|
||||||
if (currentServiceId == -1) {
|
if (currentServiceId == -1) {
|
||||||
currentService = NewPipe.getServiceByUrl(url);
|
currentService = NewPipe.getServiceByUrl(url);
|
||||||
currentServiceId = currentService.getServiceId();
|
currentServiceId = currentService.getServiceId();
|
||||||
|
@ -159,27 +160,29 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
currentService = NewPipe.getService(currentServiceId);
|
currentService = NewPipe.getService(currentServiceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return whether the url was found to be supported or not
|
||||||
return currentLinkType != LinkType.NONE;
|
return currentLinkType != LinkType.NONE;
|
||||||
|
} catch (final ExtractionException e) {
|
||||||
|
// this can be reached only when the url is completely unsupported
|
||||||
|
return false;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(result -> {
|
.subscribe(isUrlSupported -> {
|
||||||
if (result) {
|
if (isUrlSupported) {
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} else {
|
} else {
|
||||||
showUnsupportedUrlDialog(url);
|
showUnsupportedUrlDialog(url);
|
||||||
}
|
}
|
||||||
}, throwable -> handleError(this,
|
}, throwable -> handleError(this, new ErrorInfo(throwable,
|
||||||
new ErrorInfo(throwable, UserAction.SHARE_TO_NEWPIPE, url))));
|
UserAction.SHARE_TO_NEWPIPE, "Getting service from url: " + url))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context the context. If instance of {@link RouterActivity} it will be finished at the
|
* @param context the context. It will be {@code finish()}ed at the end of the handling if it is
|
||||||
* end, and if needed {@link #showUnsupportedUrlDialog(String)} will be called
|
* an instance of {@link RouterActivity}.
|
||||||
* on it.
|
* @param errorInfo the error information
|
||||||
* @param errorInfo The error information. The field {@link ErrorInfo#getRequest()} has to
|
|
||||||
* contain the url, if context is instance of {@link RouterActivity}, since it
|
|
||||||
* could be used to call {@link #showUnsupportedUrlDialog(String)}.
|
|
||||||
*/
|
*/
|
||||||
private static void handleError(final Context context, final ErrorInfo errorInfo) {
|
private static void handleError(final Context context, final ErrorInfo errorInfo) {
|
||||||
if (errorInfo.getThrowable() != null) {
|
if (errorInfo.getThrowable() != null) {
|
||||||
|
@ -214,10 +217,6 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
|
||||||
} else if (errorInfo.getThrowable() instanceof ContentNotSupportedException) {
|
} else if (errorInfo.getThrowable() instanceof ContentNotSupportedException) {
|
||||||
Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show();
|
||||||
} else if (errorInfo.getThrowable() instanceof ExtractionException
|
|
||||||
&& context instanceof RouterActivity) {
|
|
||||||
// unfortunately we cannot tell if the error is really caused by an unsupported url
|
|
||||||
((RouterActivity) context).showUnsupportedUrlDialog(errorInfo.getRequest());
|
|
||||||
} else {
|
} else {
|
||||||
ErrorActivity.reportError(context, errorInfo);
|
ErrorActivity.reportError(context, errorInfo);
|
||||||
}
|
}
|
||||||
|
@ -548,8 +547,8 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
.subscribe(intent -> {
|
.subscribe(intent -> {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}, throwable -> handleError(this,
|
}, throwable -> handleError(this, new ErrorInfo(throwable,
|
||||||
new ErrorInfo(throwable, UserAction.SHARE_TO_NEWPIPE, currentUrl)))
|
UserAction.SHARE_TO_NEWPIPE, "Starting info activity: " + currentUrl)))
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue