Skip to content
Closed
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
18 changes: 18 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>

<activity
android:name=".ClearCacheActivity"
android:excludeFromRecents="true"
android:exported="true"
android:label="@string/clear_cache_shortcut_label"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="org.schabi.newpipe.action.CLEAR_CACHE" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<receiver
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/org/schabi/newpipe/ClearCacheActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package org.schabi.newpipe

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import coil3.imageLoader
import org.schabi.newpipe.util.InfoCache

/**
* Invisible activity that clears NewPipe's caches (metadata + image caches) and
* immediately returns to the previous screen. It is used as the target of the
* "Clear cache" long-press shortcut on the app icon, so that users can wipe the
* caches without having to open the app and dig through the settings.
*
* See https://github.com/TeamNewPipe/NewPipe/issues/8981
*/
class ClearCacheActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Metadata cache (video info, streams metadata, ...)
InfoCache.getInstance().clearCache()

// Image caches (memory + disk) used for all the images loaded by Coil
imageLoader.memoryCache?.clear()
imageLoader.diskCache?.clear()

Toast.makeText(applicationContext, R.string.clear_cache_complete_notice, Toast.LENGTH_SHORT)
.show()

// Do not open the app: the user just asked for the cache to be cleared from
// the home screen, so go straight back to whatever was shown before us.
finish()
}
}
42 changes: 42 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@
};
}

public boolean onKeyDown(final int keyCode) {

Check failure on line 1533 in app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=TeamNewPipe_NewPipe&issues=AaFS_vfhViSJcr00mCK8&open=AaFS_vfhViSJcr00mCK8&pullRequest=13930
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (DeviceUtils.isTv(context) && isControlsVisible()) {
Expand All @@ -1553,6 +1553,26 @@
return true;
}

// On non-TV devices with a hardware keyboard, arrow keys should seek
// instead of jumping between UI elements or focusing player controls.
// TV devices keep their D-pad navigation behavior.
// See https://github.com/TeamNewPipe/NewPipe/issues/10448
if (!DeviceUtils.isTv(context)) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
player.fastRewind();
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
player.fastForward();
return true;
case KeyEvent.KEYCODE_DPAD_CENTER:
player.playPause();
return true;
default:
break; // UP/DDOWN keep falling through to the UI logic below
}
}

if (isControlsVisible()) {
hideControls(DEFAULT_CONTROLS_DURATION, DPAD_CONTROLS_HIDE_TIME);
} else {
Expand All @@ -1562,6 +1582,28 @@
return true;
}
break;
case KeyEvent.KEYCODE_SPACE:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
player.playPause();
return true;
case KeyEvent.KEYCODE_MEDIA_PLAY:
player.play();
return true;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
player.pause();
return true;
case KeyEvent.KEYCODE_J:
case KeyEvent.KEYCODE_MEDIA_FAST_REWIND:

Check failure on line 1596 in app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java

View workflow job for this annotation

GitHub Actions / test-android (23, default, x86)

cannot find symbol

Check failure on line 1596 in app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java

View workflow job for this annotation

GitHub Actions / test-android (23, default, x86)

cannot find symbol
player.fastRewind();
return true;
case KeyEvent.KEYCODE_L:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
player.fastForward();
return true;
case KeyEvent.KEYCODE_M:
case KeyEvent.KEYCODE_VOLUME_MUTE:
player.toggleMute();
return true;
default:
break; // ignore other keys
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
<string name="metadata_cache_wipe_title">Wipe cached metadata</string>
<string name="metadata_cache_wipe_summary">Remove all cached webpage data</string>
<string name="metadata_cache_wipe_complete_notice">Metadata cache wiped</string>
<string name="clear_cache_shortcut_label">Clear cache</string>
<string name="clear_cache_shortcut_long_label">Clear NewPipe cache</string>
<string name="clear_cache_complete_notice">Cache cleared</string>
<string name="auto_queue_title">Auto-enqueue next stream</string>
<string name="auto_queue_summary">Continue ending (non-repeating) playback queue by appending a related stream</string>
<string name="auto_queue_toggle">Auto-enqueuing</string>
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">

<!--
Long-press "Clear cache" action on the app icon.
See https://github.com/TeamNewPipe/NewPipe/issues/8981
-->
<shortcut
android:shortcutId="clear_cache"
android:enabled="true"
android:icon="@drawable/ic_delete"
android:shortcutShortLabel="@string/clear_cache_shortcut_label"
android:shortcutLongLabel="@string/clear_cache_shortcut_long_label">
<intent android:action="org.schabi.newpipe.action.CLEAR_CACHE" />

<!--
The intent is resolved within this app via ClearCacheActivity's
intent-filter, so no targetPackage is needed (the debug build's
applicationIdSuffix must not be hardcoded here).
-->
</shortcut>

</shortcuts>
Loading