|
50 | 50 | import org.schabi.newpipe.util.ListHelper; |
51 | 51 | import org.schabi.newpipe.util.NavigationHelper; |
52 | 52 | import org.schabi.newpipe.util.PermissionHelper; |
| 53 | +import org.schabi.newpipe.util.ShareUtils; |
53 | 54 | import org.schabi.newpipe.util.ThemeHelper; |
54 | 55 | import org.schabi.newpipe.util.urlfinder.UrlFinder; |
55 | 56 | import org.schabi.newpipe.views.FocusOverlayView; |
@@ -159,27 +160,36 @@ private void handleUrl(final String url) { |
159 | 160 | if (result) { |
160 | 161 | onSuccess(); |
161 | 162 | } else { |
162 | | - onError(); |
| 163 | + showUnsupportedUrlDialog(url); |
163 | 164 | } |
164 | | - }, this::handleError)); |
| 165 | + }, throwable -> handleError(throwable, url))); |
165 | 166 | } |
166 | 167 |
|
167 | | - private void handleError(final Throwable error) { |
168 | | - error.printStackTrace(); |
| 168 | + private void handleError(final Throwable throwable, final String url) { |
| 169 | + throwable.printStackTrace(); |
169 | 170 |
|
170 | | - if (error instanceof ExtractionException) { |
171 | | - Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show(); |
| 171 | + if (throwable instanceof ExtractionException) { |
| 172 | + showUnsupportedUrlDialog(url); |
172 | 173 | } else { |
173 | | - ExtractorHelper.handleGeneralException(this, -1, null, error, |
| 174 | + ExtractorHelper.handleGeneralException(this, -1, url, throwable, |
174 | 175 | UserAction.SOMETHING_ELSE, null); |
| 176 | + finish(); |
175 | 177 | } |
176 | | - |
177 | | - finish(); |
178 | 178 | } |
179 | 179 |
|
180 | | - private void onError() { |
181 | | - Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show(); |
182 | | - finish(); |
| 180 | + private void showUnsupportedUrlDialog(final String url) { |
| 181 | + final Context context = getThemeWrapperContext(); |
| 182 | + new AlertDialog.Builder(context) |
| 183 | + .setTitle(R.string.unsupported_url) |
| 184 | + .setMessage(R.string.unsupported_url_dialog_message) |
| 185 | + .setIcon(ThemeHelper.resolveResourceIdFromAttr(context, R.attr.ic_share)) |
| 186 | + .setPositiveButton(R.string.open_in_browser, |
| 187 | + (dialog, which) -> ShareUtils.openUrlInBrowser(this, url)) |
| 188 | + .setNegativeButton(R.string.share, |
| 189 | + (dialog, which) -> ShareUtils.shareUrl(this, "", url)) // no subject |
| 190 | + .setNeutralButton(R.string.cancel, null) |
| 191 | + .setOnDismissListener(dialog -> finish()) |
| 192 | + .show(); |
183 | 193 | } |
184 | 194 |
|
185 | 195 | protected void onSuccess() { |
@@ -459,7 +469,7 @@ private void handleChoice(final String selectedChoiceKey) { |
459 | 469 | startActivity(intent); |
460 | 470 |
|
461 | 471 | finish(); |
462 | | - }, this::handleError) |
| 472 | + }, throwable -> handleError(throwable, currentUrl)) |
463 | 473 | ); |
464 | 474 | return; |
465 | 475 | } |
@@ -493,7 +503,9 @@ private void openDownloadDialog() { |
493 | 503 | downloadDialog.show(fm, "downloadDialog"); |
494 | 504 | fm.executePendingTransactions(); |
495 | 505 | downloadDialog.getDialog().setOnDismissListener(dialog -> finish()); |
496 | | - }, (@NonNull Throwable throwable) -> onError()); |
| 506 | + }, (@NonNull Throwable throwable) -> { |
| 507 | + showUnsupportedUrlDialog(currentUrl); |
| 508 | + }); |
497 | 509 | } |
498 | 510 |
|
499 | 511 | @Override |
|
0 commit comments