Skip to content

Commit d7953d6

Browse files
Merge branch 'refactor' into History-Compose
2 parents 44538ce + b6bd87a commit d7953d6

100 files changed

Lines changed: 659 additions & 572 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/androidTest/java/org/schabi/newpipe/error/ErrorInfoTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1313

1414
import java.util.Arrays;
15+
import java.util.Objects;
1516

1617
import static org.junit.Assert.assertEquals;
1718
import static org.junit.Assert.assertTrue;
@@ -23,8 +24,23 @@
2324
@LargeTest
2425
public class ErrorInfoTest {
2526

27+
/**
28+
* @param errorInfo the error info to access
29+
* @return the private field errorInfo.message.stringRes using reflection
30+
*/
31+
private int getMessageFromErrorInfo(final ErrorInfo errorInfo)
32+
throws NoSuchFieldException, IllegalAccessException {
33+
final var message = ErrorInfo.class.getDeclaredField("message");
34+
message.setAccessible(true);
35+
final var messageValue = (ErrorInfo.Companion.ErrorMessage) message.get(errorInfo);
36+
37+
final var stringRes = ErrorInfo.Companion.ErrorMessage.class.getDeclaredField("stringRes");
38+
stringRes.setAccessible(true);
39+
return (int) Objects.requireNonNull(stringRes.get(messageValue));
40+
}
41+
2642
@Test
27-
public void errorInfoTestParcelable() {
43+
public void errorInfoTestParcelable() throws NoSuchFieldException, IllegalAccessException {
2844
final ErrorInfo info = new ErrorInfo(new ParsingException("Hello"),
2945
UserAction.USER_REPORT, "request", ServiceList.YouTube.getServiceId());
3046
// Obtain a Parcel object and write the parcelable object to it:
@@ -39,7 +55,7 @@ public void errorInfoTestParcelable() {
3955
assertEquals(ServiceList.YouTube.getServiceInfo().getName(),
4056
infoFromParcel.getServiceName());
4157
assertEquals("request", infoFromParcel.getRequest());
42-
assertEquals(R.string.parsing_error, infoFromParcel.getMessageStringId());
58+
assertEquals(R.string.parsing_error, getMessageFromErrorInfo(infoFromParcel));
4359

4460
parcel.recycle();
4561
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@
435435
</activity>
436436
<service
437437
android:name=".RouterActivity$FetcherService"
438+
android:foregroundServiceType="dataSync"
438439
android:exported="false" />
439440

440441
<!-- opting out of sending metrics to Google in Android System WebView -->

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,10 @@
5858
import org.schabi.newpipe.extractor.StreamingService;
5959
import org.schabi.newpipe.extractor.StreamingService.LinkType;
6060
import org.schabi.newpipe.extractor.channel.ChannelInfo;
61-
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
62-
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
63-
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
6461
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
65-
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
66-
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
67-
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
68-
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
69-
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
70-
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
7162
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
7263
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
7364
import org.schabi.newpipe.extractor.stream.StreamInfo;
74-
import org.schabi.newpipe.ktx.ExceptionUtils;
7565
import org.schabi.newpipe.local.dialog.PlaylistDialog;
7666
import org.schabi.newpipe.player.PlayerType;
7767
import org.schabi.newpipe.player.helper.PlayerHelper;
@@ -260,7 +250,8 @@ private void handleUrl(final String url) {
260250
showUnsupportedUrlDialog(url);
261251
}
262252
}, throwable -> handleError(this, new ErrorInfo(throwable,
263-
UserAction.SHARE_TO_NEWPIPE, "Getting service from url: " + url))));
253+
UserAction.SHARE_TO_NEWPIPE, "Getting service from url: " + url,
254+
null, url))));
264255
}
265256

266257
/**
@@ -269,40 +260,19 @@ private void handleUrl(final String url) {
269260
* @param errorInfo the error information
270261
*/
271262
private static void handleError(final Context context, final ErrorInfo errorInfo) {
272-
if (errorInfo.getThrowable() != null) {
273-
errorInfo.getThrowable().printStackTrace();
274-
}
275-
276-
if (errorInfo.getThrowable() instanceof ReCaptchaException) {
263+
if (errorInfo.getRecaptchaUrl() != null) {
277264
Toast.makeText(context, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
278265
// Starting ReCaptcha Challenge Activity
279266
final Intent intent = new Intent(context, ReCaptchaActivity.class);
280267
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
268+
intent.putExtra(ReCaptchaActivity.RECAPTCHA_URL_EXTRA, errorInfo.getRecaptchaUrl());
281269
context.startActivity(intent);
282-
} else if (errorInfo.getThrowable() != null
283-
&& ExceptionUtils.isNetworkRelated(errorInfo.getThrowable())) {
284-
Toast.makeText(context, R.string.network_error, Toast.LENGTH_LONG).show();
285-
} else if (errorInfo.getThrowable() instanceof AgeRestrictedContentException) {
286-
Toast.makeText(context, R.string.restricted_video_no_stream,
287-
Toast.LENGTH_LONG).show();
288-
} else if (errorInfo.getThrowable() instanceof GeographicRestrictionException) {
289-
Toast.makeText(context, R.string.georestricted_content, Toast.LENGTH_LONG).show();
290-
} else if (errorInfo.getThrowable() instanceof PaidContentException) {
291-
Toast.makeText(context, R.string.paid_content, Toast.LENGTH_LONG).show();
292-
} else if (errorInfo.getThrowable() instanceof PrivateContentException) {
293-
Toast.makeText(context, R.string.private_content, Toast.LENGTH_LONG).show();
294-
} else if (errorInfo.getThrowable() instanceof SoundCloudGoPlusContentException) {
295-
Toast.makeText(context, R.string.soundcloud_go_plus_content,
296-
Toast.LENGTH_LONG).show();
297-
} else if (errorInfo.getThrowable() instanceof YoutubeMusicPremiumContentException) {
298-
Toast.makeText(context, R.string.youtube_music_premium_content,
299-
Toast.LENGTH_LONG).show();
300-
} else if (errorInfo.getThrowable() instanceof ContentNotAvailableException) {
301-
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
302-
} else if (errorInfo.getThrowable() instanceof ContentNotSupportedException) {
303-
Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show();
304-
} else {
270+
} else if (errorInfo.isReportable()) {
305271
ErrorUtil.createNotification(context, errorInfo);
272+
} else {
273+
// this exception does not usually indicate a problem that should be reported,
274+
// so just show a toast instead of the notification
275+
Toast.makeText(context, errorInfo.getMessage(context), Toast.LENGTH_LONG).show();
306276
}
307277

308278
if (context instanceof RouterActivity) {
@@ -665,7 +635,8 @@ private void handleChoice(final String selectedChoiceKey) {
665635
startActivity(intent);
666636
finish();
667637
}, throwable -> handleError(this, new ErrorInfo(throwable,
668-
UserAction.SHARE_TO_NEWPIPE, "Starting info activity: " + currentUrl)))
638+
UserAction.SHARE_TO_NEWPIPE, "Starting info activity: " + currentUrl,
639+
null, currentUrl)))
669640
);
670641
return;
671642
}
@@ -852,10 +823,10 @@ private void openAddToPlaylistDialog(final int currentServiceId, final String cu
852823
})
853824
)),
854825
throwable -> runOnVisible(ctx -> handleError(ctx, new ErrorInfo(
855-
throwable,
856-
UserAction.REQUESTED_STREAM,
826+
throwable, UserAction.REQUESTED_STREAM,
857827
"Tried to add " + currentUrl + " to a playlist",
858-
((RouterActivity) ctx).currentService.getServiceId())
828+
((RouterActivity) ctx).currentService.getServiceId(),
829+
currentUrl)
859830
))
860831
)
861832
);
@@ -995,7 +966,7 @@ public void handleChoice(final Choice choice) {
995966
}
996967
}, throwable -> handleError(this, new ErrorInfo(throwable, finalUserAction,
997968
choice.url + " opened with " + choice.playerChoice,
998-
choice.serviceId)));
969+
choice.serviceId, choice.url)));
999970
}
1000971
}
1001972

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ private void fetchStreamsSize() {
389389
}
390390
}, throwable -> ErrorUtil.showSnackbar(context,
391391
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
392-
"Downloading video stream size",
393-
currentInfo.getServiceId()))));
392+
"Downloading video stream size", currentInfo))));
394393
disposables.add(StreamInfoWrapper.fetchMoreInfoForWrapper(getWrappedAudioStreams())
395394
.subscribe(result -> {
396395
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
@@ -399,8 +398,7 @@ private void fetchStreamsSize() {
399398
}
400399
}, throwable -> ErrorUtil.showSnackbar(context,
401400
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
402-
"Downloading audio stream size",
403-
currentInfo.getServiceId()))));
401+
"Downloading audio stream size", currentInfo))));
404402
disposables.add(StreamInfoWrapper.fetchMoreInfoForWrapper(wrappedSubtitleStreams)
405403
.subscribe(result -> {
406404
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
@@ -409,8 +407,7 @@ private void fetchStreamsSize() {
409407
}
410408
}, throwable -> ErrorUtil.showSnackbar(context,
411409
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
412-
"Downloading subtitle stream size",
413-
currentInfo.getServiceId()))));
410+
"Downloading subtitle stream size", currentInfo))));
414411
}
415412

416413
private void setupAudioTrackSpinner() {

app/src/main/java/org/schabi/newpipe/error/AcraReportSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public void send(@NonNull final Context context, @NonNull final CrashReportData
3636
ErrorUtil.openActivity(context, new ErrorInfo(
3737
new String[]{report.getString(ReportField.STACK_TRACE)},
3838
UserAction.UI_ERROR,
39-
ErrorInfo.SERVICE_NONE,
4039
"ACRA report",
40+
null,
4141
R.string.app_ui_crash));
4242
}
4343
}

app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected void onCreate(final Bundle savedInstanceState) {
115115

116116
// normal bugreport
117117
buildInfo(errorInfo);
118-
activityErrorBinding.errorMessageView.setText(errorInfo.getMessageStringId());
118+
activityErrorBinding.errorMessageView.setText(errorInfo.getMessage(this));
119119
activityErrorBinding.errorView.setText(formErrorText(errorInfo.getStackTraces()));
120120

121121
// print stack trace once again for debugging:

0 commit comments

Comments
 (0)