Skip to content

Commit 2cb465c

Browse files
committed
Merge branch 'dev' into refactor
2 parents ccca89d + a3ddd61 commit 2cb465c

File tree

74 files changed

+217
-208
lines changed

Some content is hidden

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

74 files changed

+217
-208
lines changed

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/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,13 @@
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;
6261
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
6362
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
6463
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;
6864
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
69-
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
70-
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
7165
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
7266
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
7367
import org.schabi.newpipe.extractor.stream.StreamInfo;
74-
import org.schabi.newpipe.ktx.ExceptionUtils;
7568
import org.schabi.newpipe.local.dialog.PlaylistDialog;
7669
import org.schabi.newpipe.player.PlayerType;
7770
import org.schabi.newpipe.player.helper.PlayerHelper;
@@ -279,28 +272,11 @@ private static void handleError(final Context context, final ErrorInfo errorInfo
279272
final Intent intent = new Intent(context, ReCaptchaActivity.class);
280273
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
281274
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();
275+
} else if (errorInfo.getThrowable() instanceof ContentNotAvailableException
276+
|| errorInfo.getThrowable() instanceof ContentNotSupportedException) {
277+
// this exception does not usually indicate a problem that should be reported,
278+
// so just show a toast instead of the notification
279+
Toast.makeText(context, errorInfo.getMessage(context), Toast.LENGTH_LONG).show();
304280
} else {
305281
ErrorUtil.createNotification(context, errorInfo);
306282
}

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,7 +36,7 @@ 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,
39+
null,
4040
"ACRA report",
4141
R.string.app_ui_crash));
4242
}

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)