From c934c25d779b0a69bd8cef2c812b677082fa17ba Mon Sep 17 00:00:00 2001 From: "u7322148@anu.edu.au" Date: Tue, 15 Oct 2024 23:44:55 +1100 Subject: [PATCH] Extended custom URL scheme to include service selection - Implemented the abilImplemented the ability for third-party apps to initiate a search in NewPipe on a specific service by using the custom URL scheme `newpipe://search?service=SERVICE_NAME&q=YOUR_QUERY`. - Added intent-filter to RouterActivity to handle the custom URL scheme. - Enhanced RouterActivity to parse the incoming service parameter, retrieve the corresponding service ID, and start MainActivity with the specified service and search query. - Added error handling for invalid service names: displays an error message to the user if the service name is invalid. - Tested the implementation using ADB commands to send an intent with the custom URI. Fixes: Expose search API with url #3475 Add new tag to customize urls add logic of handling custom search intents in onCreate method add comments to helping review add a new method to get the service by name improve the RouterActivity to handle the service name improve the RouterActivity --- app/src/main/AndroidManifest.xml | 8 +++ .../org/schabi/newpipe/RouterActivity.java | 50 +++++++++++++++++++ .../SeekbarPreviewThumbnailHolder.java | 13 ++++- .../schabi/newpipe/util/ServiceHelper.java | 10 ++++ 4 files changed, 79 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d11de9f478d..6692f8537d7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -406,6 +406,14 @@ + + + + + + + + finish()); when creating these DialogFragments diff --git a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java index 09c61b8b35a..c7e4cd78141 100644 --- a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java @@ -132,8 +132,17 @@ private void generateDataFrom(final Frameset frameset, final UUID updateRequestI // Get the bounds where the frame is found final int[] bounds = frameset.getFrameBoundsAt(currentPosMs); - generatedDataForUrl.put(currentPosMs, - createBitmapSupplier(srcBitMap, bounds, frameset)); + generatedDataForUrl.put(currentPosMs, () -> { + // It can happen, that the original bitmap could not be downloaded + // In such a case - we don't want a NullPointer - simply return null + if (srcBitMap == null) { + return null; + } + + // Cut out the corresponding bitmap form the "srcBitMap" + return Bitmap.createBitmap(srcBitMap, bounds[1], bounds[2], + frameset.getFrameWidth(), frameset.getFrameHeight()); + }); currentPosMs += frameset.getDurationPerFrame(); pos++; diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index c712157b35b..15e4841e78a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -121,6 +121,16 @@ public static int getSelectedServiceId(final Context context) { .getServiceId(); } + public static int getServiceIdByName(final String serviceName) throws IllegalArgumentException { + for (final StreamingService s : NewPipe.getServices()) { + if (s.getServiceInfo().getName().equalsIgnoreCase(serviceName)) { + return s.getServiceId(); + } + } + throw new IllegalArgumentException("Invalid service name"); + } + + @Nullable public static StreamingService getSelectedService(final Context context) { final String serviceName = PreferenceManager.getDefaultSharedPreferences(context)