Skip to content

Commit 7eb5aa1

Browse files
authored
Merge pull request #7056 from TeamNewPipe/fix/playOnPopup
Fix handling exception in `playOnPopup` and toggle description tab
2 parents 08ebd7d + 4d51ebc commit 7eb5aa1

9 files changed

Lines changed: 81 additions & 44 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public abstract class BaseFragment extends Fragment {
1818
protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode());
19-
protected final boolean DEBUG = MainActivity.DEBUG;
19+
protected static final boolean DEBUG = MainActivity.DEBUG;
2020
protected AppCompatActivity activity;
2121
//These values are used for controlling fragments when they are part of the frontpage
2222
@State

app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,14 @@ class ErrorPanelHelper(
121121
ErrorActivity.reportError(context, errorInfo)
122122
}
123123

124-
errorTextView.setText(
125-
when (errorInfo.throwable) {
126-
is AgeRestrictedContentException -> R.string.restricted_video_no_stream
127-
is GeographicRestrictionException -> R.string.georestricted_content
128-
is PaidContentException -> R.string.paid_content
129-
is PrivateContentException -> R.string.private_content
130-
is SoundCloudGoPlusContentException -> R.string.soundcloud_go_plus_content
131-
is YoutubeMusicPremiumContentException -> R.string.youtube_music_premium_content
132-
is ContentNotAvailableException -> R.string.content_not_available
133-
is ContentNotSupportedException -> R.string.content_not_supported
134-
else -> {
135-
// show retry button only for content which is not unavailable or unsupported
136-
errorRetryButton.isVisible = true
137-
if (errorInfo.throwable != null && errorInfo.throwable!!.isNetworkRelated) {
138-
R.string.network_error
139-
} else {
140-
R.string.error_snackbar_message
141-
}
142-
}
143-
}
144-
)
124+
errorTextView.setText(getExceptionDescription(errorInfo.throwable))
125+
126+
if (errorInfo.throwable !is ContentNotAvailableException &&
127+
errorInfo.throwable !is ContentNotSupportedException
128+
) {
129+
// show retry button only for content which is not unavailable or unsupported
130+
errorRetryButton.isVisible = true
131+
}
145132
}
146133

147134
setRootVisible()
@@ -189,5 +176,27 @@ class ErrorPanelHelper(
189176
companion object {
190177
val TAG: String = ErrorPanelHelper::class.simpleName!!
191178
val DEBUG: Boolean = MainActivity.DEBUG
179+
180+
@StringRes
181+
public fun getExceptionDescription(throwable: Throwable?): Int {
182+
return when (throwable) {
183+
is AgeRestrictedContentException -> R.string.restricted_video_no_stream
184+
is GeographicRestrictionException -> R.string.georestricted_content
185+
is PaidContentException -> R.string.paid_content
186+
is PrivateContentException -> R.string.private_content
187+
is SoundCloudGoPlusContentException -> R.string.soundcloud_go_plus_content
188+
is YoutubeMusicPremiumContentException -> R.string.youtube_music_premium_content
189+
is ContentNotAvailableException -> R.string.content_not_available
190+
is ContentNotSupportedException -> R.string.content_not_supported
191+
else -> {
192+
// show retry button only for content which is not unavailable or unsupported
193+
if (throwable != null && throwable.isNetworkRelated) {
194+
R.string.network_error
195+
} else {
196+
R.string.error_snackbar_message
197+
}
198+
}
199+
}
200+
}
192201
}
193202
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.error;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Intent;
45
import android.content.SharedPreferences;
56
import android.os.Build;
@@ -66,6 +67,7 @@ public static String sanitizeRecaptchaUrl(@Nullable final String url) {
6667
private ActivityRecaptchaBinding recaptchaBinding;
6768
private String foundCookies = "";
6869

70+
@SuppressLint("SetJavaScriptEnabled")
6971
@Override
7072
protected void onCreate(final Bundle savedInstanceState) {
7173
ThemeHelper.setTheme(this);

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
423423
showRelatedItems = sharedPreferences.getBoolean(key, true);
424424
tabSettingsChanged = true;
425425
} else if (key.equals(getString(R.string.show_description_key))) {
426-
showComments = sharedPreferences.getBoolean(key, true);
426+
showDescription = sharedPreferences.getBoolean(key, true);
427427
tabSettingsChanged = true;
428428
}
429429
}

app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGrou
215215

216216
@Override
217217
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
218+
searchBinding = FragmentSearchBinding.bind(rootView);
218219
super.onViewCreated(rootView, savedInstanceState);
219220
showSearchOnStart();
220221
initSearchListeners();
@@ -341,7 +342,6 @@ public void onActivityResult(final int requestCode, final int resultCode, final
341342
@Override
342343
protected void initViews(final View rootView, final Bundle savedInstanceState) {
343344
super.initViews(rootView, savedInstanceState);
344-
searchBinding = FragmentSearchBinding.bind(rootView);
345345

346346
searchBinding.suggestionsList.setAdapter(suggestionListAdapter);
347347
new ItemTouchHelper(new ItemTouchHelper.Callback() {
@@ -807,18 +807,21 @@ private void initSuggestionObserver() {
807807
})
808808
.subscribeOn(Schedulers.io())
809809
.observeOn(AndroidSchedulers.mainThread())
810-
.subscribe(listNotification -> {
811-
if (listNotification.isOnNext()) {
812-
if (listNotification.getValue() != null) {
813-
handleSuggestions(listNotification.getValue());
814-
}
815-
} else if (listNotification.isOnError()
816-
&& listNotification.getError() != null
817-
&& !ExceptionUtils.isInterruptedCaused(listNotification.getError())) {
818-
showSnackBarError(new ErrorInfo(listNotification.getError(),
819-
UserAction.GET_SUGGESTIONS, searchString, serviceId));
820-
}
821-
});
810+
.subscribe(
811+
listNotification -> {
812+
if (listNotification.isOnNext()) {
813+
if (listNotification.getValue() != null) {
814+
handleSuggestions(listNotification.getValue());
815+
}
816+
} else if (listNotification.isOnError()
817+
&& listNotification.getError() != null
818+
&& !ExceptionUtils.isInterruptedCaused(
819+
listNotification.getError())) {
820+
showSnackBarError(new ErrorInfo(listNotification.getError(),
821+
UserAction.GET_SUGGESTIONS, searchString, serviceId));
822+
}
823+
}, throwable -> showSnackBarError(new ErrorInfo(
824+
throwable, UserAction.GET_SUGGESTIONS, searchString, serviceId)));
822825
}
823826

824827
@Override

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public void handleIntent(@NonNull final Intent intent) {
614614
playQueue.append(newQueue.getStreams());
615615

616616
if ((intent.getBooleanExtra(SELECT_ON_APPEND, false)
617-
|| currentState == STATE_COMPLETED) && newQueue.getStreams().size() > 0) {
617+
|| currentState == STATE_COMPLETED) && !newQueue.getStreams().isEmpty()) {
618618
playQueue.setIndex(sizeBeforeAppend);
619619
}
620620

@@ -2326,7 +2326,7 @@ public void onRepeatModeChanged(@RepeatMode final int repeatMode) {
23262326
Log.d(TAG, "ExoPlayer - onRepeatModeChanged() called with: "
23272327
+ "repeatMode = [" + repeatMode + "]");
23282328
}
2329-
setRepeatModeButton(((AppCompatImageButton) binding.repeatButton), repeatMode);
2329+
setRepeatModeButton(binding.repeatButton, repeatMode);
23302330
onShuffleOrRepeatModeChanged();
23312331
}
23322332

@@ -3189,7 +3189,7 @@ public void onScrolledDown(final RecyclerView recyclerView) {
31893189
private StreamSegmentAdapter.StreamSegmentListener getStreamSegmentListener() {
31903190
return (item, seconds) -> {
31913191
segmentAdapter.selectSegment(item);
3192-
seekTo(seconds * 1000);
3192+
seekTo(seconds * 1000L);
31933193
triggerProgressUpdate();
31943194
};
31953195
}
@@ -3199,7 +3199,7 @@ private int getNearestStreamSegmentPosition(final long playbackPosition) {
31993199
final List<StreamSegment> segments = currentMetadata.getMetadata().getStreamSegments();
32003200

32013201
for (int i = 0; i < segments.size(); i++) {
3202-
if (segments.get(i).getStartTimeSeconds() * 1000 > playbackPosition) {
3202+
if (segments.get(i).getStartTimeSeconds() * 1000L > playbackPosition) {
32033203
break;
32043204
}
32053205
nearestPosition++;

app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public static void openVideoDetailFragment(@NonNull final Context context,
360360
autoPlay = false;
361361
}
362362

363-
final RunnableWithVideoDetailFragment onVideoDetailFragmentReady = (detailFragment) -> {
363+
final RunnableWithVideoDetailFragment onVideoDetailFragmentReady = detailFragment -> {
364364
expandMainPlayer(detailFragment.requireActivity());
365365
detailFragment.setAutoPlay(autoPlay);
366366
if (switchingPlayers) {

app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static boolean checkSystemAlertWindowPermission(final Context context) {
119119

120120
public static boolean isPopupEnabled(final Context context) {
121121
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M
122-
|| PermissionHelper.checkSystemAlertWindowPermission(context);
122+
|| checkSystemAlertWindowPermission(context);
123123
}
124124

125125
public static void showPopupEnablementToast(final Context context) {

app/src/main/java/org/schabi/newpipe/util/external_communication/InternalUrlsHandler.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package org.schabi.newpipe.util.external_communication;
22

33
import android.content.Context;
4+
import android.util.Log;
45

56
import androidx.annotation.NonNull;
7+
import androidx.appcompat.app.AlertDialog;
68

9+
import org.schabi.newpipe.MainActivity;
10+
import org.schabi.newpipe.R;
11+
import org.schabi.newpipe.error.ErrorPanelHelper;
712
import org.schabi.newpipe.extractor.NewPipe;
813
import org.schabi.newpipe.extractor.StreamingService;
914
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -24,6 +29,9 @@
2429
import io.reactivex.rxjava3.schedulers.Schedulers;
2530

2631
public final class InternalUrlsHandler {
32+
private static final String TAG = InternalUrlsHandler.class.getSimpleName();
33+
private static final boolean DEBUG = MainActivity.DEBUG;
34+
2735
private static final Pattern AMPERSAND_TIMESTAMP_PATTERN = Pattern.compile("(.*)&t=(\\d+)");
2836
private static final Pattern HASHTAG_TIMESTAMP_PATTERN =
2937
Pattern.compile("(.*)#timestamp=(\\d+)");
@@ -93,7 +101,12 @@ private static boolean handleUrl(final Context context,
93101
return false;
94102
}
95103
final String matchedUrl = matcher.group(1);
96-
final int seconds = Integer.parseInt(matcher.group(2));
104+
final int seconds;
105+
if (matcher.group(2) == null) {
106+
seconds = -1;
107+
} else {
108+
seconds = Integer.parseInt(matcher.group(2));
109+
}
97110

98111
final StreamingService service;
99112
final StreamingService.LinkType linkType;
@@ -146,8 +159,18 @@ public static boolean playOnPopup(final Context context,
146159
.observeOn(AndroidSchedulers.mainThread())
147160
.subscribe(info -> {
148161
final PlayQueue playQueue
149-
= new SinglePlayQueue(info, seconds * 1000);
162+
= new SinglePlayQueue(info, seconds * 1000L);
150163
NavigationHelper.playOnPopupPlayer(context, playQueue, false);
164+
}, throwable -> {
165+
if (DEBUG) {
166+
Log.e(TAG, "Could not play on popup: " + url, throwable);
167+
}
168+
new AlertDialog.Builder(context)
169+
.setTitle(R.string.player_stream_failure)
170+
.setMessage(
171+
ErrorPanelHelper.Companion.getExceptionDescription(throwable))
172+
.setPositiveButton(R.string.ok, (v, b) -> { })
173+
.show();
151174
}));
152175
return true;
153176
}

0 commit comments

Comments
 (0)