Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose search issue #3475 #11615

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@
<data android:sspPattern="bandcamp.com/?show=*" />
</intent-filter>

<!-- customized search URL filter -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="newpipe" android:host="search" />
</intent-filter>

</activity>
<service
android:name=".RouterActivity$FetcherService"
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
Expand Down Expand Up @@ -84,6 +85,7 @@
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import org.schabi.newpipe.util.urlfinder.UrlFinder;
Expand Down Expand Up @@ -126,6 +128,12 @@ public class RouterActivity extends AppCompatActivity {
private AlertDialog alertDialogChoice = null;
private FragmentManager.FragmentLifecycleCallbacks dismissListener = null;

/**
* Initializes the activity based on the incoming intent. This activity acts as a router
* to direct the user to different parts of the app based on the URL or action specified
* in the intent. It handles special URLs like 'newpipe://search?q=query' to trigger
* search directly or standard URLs to open specific videos, playlists, or channels.
*/
@Override
protected void onCreate(final Bundle savedInstanceState) {
ThemeHelper.setDayNightMode(this);
Expand All @@ -152,8 +160,31 @@ protected void onCreate(final Bundle savedInstanceState) {
getWindow().setAttributes(params);

super.onCreate(savedInstanceState);
// Restoring state with Icepick for handling screen rotations more efficiently
Icepick.restoreInstanceState(this, savedInstanceState);

final Intent actionIntent = getIntent();
final Uri data = actionIntent.getData();
if (data != null) {
final String scheme = data.getScheme();
final String host = data.getHost();
if ("newpipe".equals(scheme) && "search".equals(host)) {
final String query = data.getQueryParameter("q");
if (query != null) {
// Enable the search function
final Intent searchIntent = new Intent(this, MainActivity.class);
searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
searchIntent.putExtra(Constants.KEY_OPEN_SEARCH, true);
searchIntent.putExtra(Constants.KEY_SERVICE_ID,
ServiceHelper.getSelectedServiceId(this));
searchIntent.putExtra(Constants.KEY_SEARCH_STRING, query);
startActivity(searchIntent);
finish();
return;
}
}
}

// FragmentManager will take care to recreate (Playlist|Download)Dialog when screen rotates
// We used to .setOnDismissListener(dialog -> finish()); when creating these DialogFragments
// but those callbacks won't survive a config change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -156,33 +165,6 @@ private void generateDataFrom(final Frameset frameset, final UUID updateRequestI
}
}

private Supplier<Bitmap> createBitmapSupplier(final Bitmap srcBitMap,
final int[] bounds,
final Frameset frameset) {
return () -> {
// It can happen, that the original bitmap could not be downloaded
// (or it was recycled though that should not happen)
// In such a case - we don't want a NullPointer/
// "cannot use a recycled source in createBitmap" Exception -> simply return null
if (srcBitMap == null || srcBitMap.isRecycled()) {
return null;
}

// Cut out the corresponding bitmap form the "srcBitMap"
final Bitmap cutOutBitmap = Bitmap.createBitmap(srcBitMap, bounds[1], bounds[2],
frameset.getFrameWidth(), frameset.getFrameHeight());

// If the cut out bitmap is identical to its source,
// we need to copy the bitmap to create a new instance.
// createBitmap allows itself to return the original object that is was created with
// this leads to recycled bitmaps being returned (if they are identical)
// Reference: https://stackoverflow.com/a/23683075 + first comment
// Fixes: https://github.com/TeamNewPipe/NewPipe/issues/11461
return cutOutBitmap == srcBitMap
? cutOutBitmap.copy(cutOutBitmap.getConfig(), true) : cutOutBitmap;
};
}

@Nullable
private Bitmap getBitMapFrom(final String url) {
if (url == null) {
Expand Down
Loading