Skip to content

Commit f2bfa97

Browse files
authored
Merge branch 'TeamNewPipe:dev' into moddev
2 parents 01bb211 + f3858e7 commit f2bfa97

173 files changed

Lines changed: 2141 additions & 610 deletions

File tree

Some content is hidden

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

.github/workflows/image-minimizer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ module.exports = async ({github, context}) => {
3333

3434
// Regex for finding images (simple variant) ![ALT_TEXT](https://*.githubusercontent.com/<number>/<variousHexStringsAnd->.<fileExtension>)
3535
const REGEX_USER_CONTENT_IMAGE_LOOKUP = /\!\[([^\]]*)\]\((https:\/\/[-a-z0-9]+\.githubusercontent\.com\/\d+\/[-0-9a-f]{32,512}\.(jpg|gif|png))\)/gm;
36-
const REGEX_ASSETS_IMAGE_LOCKUP = /\!\[([^\]]*)\]\((https:\/\/github\.com\/[-\w\d]+\/[-\w\d]+\/assets\/\d+\/[\-0-9a-f]{32,512})\)/gm;
36+
const REGEX_ASSETS_IMAGE_LOOKUP = /\!\[([^\]]*)\]\((https:\/\/github\.com\/(?:user-attachments\/assets|[-\w\d]+\/[-\w\d]+\/assets\/\d+)\/[\-0-9a-f]{32,512})\)/gm;
3737

3838
// Check if we found something
3939
let foundSimpleImages = REGEX_USER_CONTENT_IMAGE_LOOKUP.test(initialBody)
40-
|| REGEX_ASSETS_IMAGE_LOCKUP.test(initialBody);
40+
|| REGEX_ASSETS_IMAGE_LOOKUP.test(initialBody);
4141
if (!foundSimpleImages) {
4242
console.log('Found no simple images to process');
4343
return;
@@ -52,7 +52,7 @@ module.exports = async ({github, context}) => {
5252

5353
// Try to find and replace the images with minimized ones
5454
let newBody = await replaceAsync(initialBody, REGEX_USER_CONTENT_IMAGE_LOOKUP, minimizeAsync);
55-
newBody = await replaceAsync(newBody, REGEX_ASSETS_IMAGE_LOCKUP, minimizeAsync);
55+
newBody = await replaceAsync(newBody, REGEX_ASSETS_IMAGE_LOOKUP, minimizeAsync);
5656

5757
if (!wasMatchModified) {
5858
console.log('Nothing was modified. Skipping update');

app/build.gradle

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ android {
2323
if (System.properties.containsKey('versionCodeOverride')) {
2424
versionCode System.getProperty('versionCodeOverride') as Integer
2525
} else {
26-
versionCode 1003
26+
versionCode 1004
2727
}
28-
versionName "0.27.6"
28+
versionName "0.27.7"
2929
if (System.properties.containsKey('versionNameSuffix')) {
3030
versionNameSuffix System.getProperty('versionNameSuffix')
3131
}
@@ -97,6 +97,10 @@ android {
9797
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
9898
}
9999

100+
androidResources {
101+
generateLocaleConfig = true
102+
}
103+
100104
buildFeatures {
101105
viewBinding true
102106
buildConfig true
@@ -207,8 +211,10 @@ dependencies {
207211
// This works thanks to JitPack: https://jitpack.io/
208212
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
209213
// WORKAROUND: if you get errors with the NewPipeExtractor dependency, replace `v0.24.3` with
210-
// the corresponding commit hash, since JitPack is sometimes buggy
211-
implementation 'com.github.TeamNewPipe:NewPipeExtractor:9f83b385a'
214+
// the corresponding commit hash, since JitPack sometimes deletes artifacts.
215+
// If there’s already a git hash, just add more of it to the end (or remove a letter)
216+
// to cause jitpack to regenerate the artifact.
217+
implementation 'com.github.TeamNewPipe.NewPipeExtractor:NewPipeExtractor:v0.24.6'
212218
implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'
213219

214220
/** Checkstyle **/

app/proguard-rules.pro

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55

66
## Rules for NewPipeExtractor
77
-keep class org.schabi.newpipe.extractor.timeago.patterns.** { *; }
8+
## Rules for Rhino and Rhino Engine
9+
-keep class org.mozilla.javascript.* { *; }
810
-keep class org.mozilla.javascript.** { *; }
11+
-keep class org.mozilla.javascript.engine.** { *; }
912
-keep class org.mozilla.classfile.ClassFileWriter
1013
-dontwarn org.mozilla.javascript.JavaToJSONConverters
1114
-dontwarn org.mozilla.javascript.tools.**
15+
-keep class javax.script.** { *; }
16+
-dontwarn javax.script.**
17+
-keep class jdk.dynalink.** { *; }
18+
-dontwarn jdk.dynalink.**
1219

1320
## Rules for ExoPlayer
1421
-keep class com.google.android.exoplayer2.** { *; }

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<intent-filter>
6565
<action android:name="android.intent.action.MEDIA_BUTTON" />
6666
</intent-filter>
67+
<intent-filter>
68+
<action android:name="android.media.browse.MediaBrowserService"/>
69+
</intent-filter>
6770
</service>
6871

6972
<activity
@@ -424,5 +427,10 @@
424427
<meta-data
425428
android:name="com.samsung.android.multidisplay.keep_process_alive"
426429
android:value="true" />
430+
<!-- Android Auto -->
431+
<meta-data android:name="com.google.android.gms.car.application"
432+
android:resource="@xml/automotive_app_desc" />
433+
<meta-data android:name="com.google.android.gms.car.notification.SmallIcon"
434+
android:resource="@mipmap/ic_launcher" />
427435
</application>
428436
</manifest>

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

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import android.view.MenuItem;
3939
import android.view.View;
4040
import android.view.ViewGroup;
41+
import android.webkit.WebView;
4142
import android.widget.AdapterView;
4243
import android.widget.ArrayAdapter;
4344
import android.widget.FrameLayout;
@@ -125,7 +126,10 @@ public class MainActivity extends AppCompatActivity {
125126
private static final int ITEM_ID_ABOUT = 2;
126127

127128
private static final int ORDER = 0;
129+
public static final String KEY_IS_IN_BACKGROUND = "is_in_background";
128130

131+
private SharedPreferences sharedPreferences;
132+
private SharedPreferences.Editor sharedPrefEditor;
129133
/*//////////////////////////////////////////////////////////////////////////
130134
// Activity's LifeCycle
131135
//////////////////////////////////////////////////////////////////////////*/
@@ -140,8 +144,23 @@ protected void onCreate(final Bundle savedInstanceState) {
140144
ThemeHelper.setDayNightMode(this);
141145
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
142146

147+
// Fixes text color turning black in dark/black mode:
148+
// https://github.com/TeamNewPipe/NewPipe/issues/12016
149+
// For further reference see: https://issuetracker.google.com/issues/37124582
150+
if (DeviceUtils.supportsWebView()) {
151+
try {
152+
new WebView(this);
153+
} catch (final Throwable e) {
154+
if (DEBUG) {
155+
Log.e(TAG, "Failed to create WebView", e);
156+
}
157+
}
158+
}
159+
143160
assureCorrectAppLanguage(this);
144161
super.onCreate(savedInstanceState);
162+
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
163+
sharedPrefEditor = sharedPreferences.edit();
145164

146165
mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
147166
drawerLayoutBinding = mainBinding.drawerLayout;
@@ -176,23 +195,38 @@ protected void onCreate(final Bundle savedInstanceState) {
176195
&& ReleaseVersionUtil.INSTANCE.isReleaseApk()) {
177196
UpdateSettingsFragment.askForConsentToUpdateChecks(this);
178197
}
198+
199+
Localization.migrateAppLanguageSettingIfNecessary(getApplicationContext());
179200
}
180201

181202
@Override
182203
protected void onPostCreate(final Bundle savedInstanceState) {
183204
super.onPostCreate(savedInstanceState);
184205

185206
final App app = App.getApp();
186-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
187207

188-
if (prefs.getBoolean(app.getString(R.string.update_app_key), false)
189-
&& prefs.getBoolean(app.getString(R.string.update_check_consent_key), false)) {
208+
if (sharedPreferences.getBoolean(app.getString(R.string.update_app_key), false)
209+
&& sharedPreferences
210+
.getBoolean(app.getString(R.string.update_check_consent_key), false)) {
190211
// Start the worker which is checking all conditions
191212
// and eventually searching for a new version.
192213
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);
193214
}
194215
}
195216

217+
@Override
218+
protected void onStart() {
219+
super.onStart();
220+
sharedPrefEditor.putBoolean(KEY_IS_IN_BACKGROUND, false).apply();
221+
Log.d(TAG, "App moved to foreground");
222+
}
223+
224+
@Override
225+
protected void onStop() {
226+
super.onStop();
227+
sharedPrefEditor.putBoolean(KEY_IS_IN_BACKGROUND, true).apply();
228+
Log.d(TAG, "App moved to background");
229+
}
196230
private void setupDrawer() throws ExtractionException {
197231
addDrawerMenuForCurrentService();
198232

@@ -492,21 +526,19 @@ protected void onResume() {
492526
ErrorUtil.showUiErrorSnackbar(this, "Setting up service toggle", e);
493527
}
494528

495-
final SharedPreferences sharedPreferences =
496-
PreferenceManager.getDefaultSharedPreferences(this);
497529
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
498530
if (DEBUG) {
499531
Log.d(TAG, "Theme has changed, recreating activity...");
500532
}
501-
sharedPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, false).apply();
533+
sharedPrefEditor.putBoolean(Constants.KEY_THEME_CHANGE, false).apply();
502534
ActivityCompat.recreate(this);
503535
}
504536

505537
if (sharedPreferences.getBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false)) {
506538
if (DEBUG) {
507539
Log.d(TAG, "main page has changed, recreating main fragment...");
508540
}
509-
sharedPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply();
541+
sharedPrefEditor.putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply();
510542
NavigationHelper.openMainActivity(this);
511543
}
512544

@@ -848,7 +880,8 @@ private void openMiniPlayerUponPlayerStarted() {
848880
@Override
849881
public void onReceive(final Context context, final Intent intent) {
850882
if (Objects.equals(intent.getAction(),
851-
VideoDetailFragment.ACTION_PLAYER_STARTED)) {
883+
VideoDetailFragment.ACTION_PLAYER_STARTED)
884+
&& PlayerHolder.getInstance().isPlayerOpen()) {
852885
openMiniPlayerIfMissing();
853886
// At this point the player is added 100%, we can unregister. Other actions
854887
// are useless since the fragment will not be removed after that.
@@ -860,6 +893,10 @@ public void onReceive(final Context context, final Intent intent) {
860893
final IntentFilter intentFilter = new IntentFilter();
861894
intentFilter.addAction(VideoDetailFragment.ACTION_PLAYER_STARTED);
862895
registerReceiver(broadcastReceiver, intentFilter);
896+
897+
// If the PlayerHolder is not bound yet, but the service is running, try to bind to it.
898+
// Once the connection is established, the ACTION_PLAYER_STARTED will be sent.
899+
PlayerHolder.getInstance().tryBindIfNeeded(this);
863900
}
864901
}
865902

app/src/main/java/org/schabi/newpipe/database/history/model/StreamHistoryEntry.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.schabi.newpipe.database.history.model
33
import androidx.room.ColumnInfo
44
import androidx.room.Embedded
55
import org.schabi.newpipe.database.stream.model.StreamEntity
6+
import org.schabi.newpipe.extractor.stream.StreamInfoItem
7+
import org.schabi.newpipe.util.image.ImageStrategy
68
import java.time.OffsetDateTime
79

810
data class StreamHistoryEntry(
@@ -27,4 +29,17 @@ data class StreamHistoryEntry(
2729
return this.streamEntity.uid == other.streamEntity.uid && streamId == other.streamId &&
2830
accessDate.isEqual(other.accessDate)
2931
}
32+
33+
fun toStreamInfoItem(): StreamInfoItem =
34+
StreamInfoItem(
35+
streamEntity.serviceId,
36+
streamEntity.url,
37+
streamEntity.title,
38+
streamEntity.streamType,
39+
).apply {
40+
duration = streamEntity.duration
41+
uploaderName = streamEntity.uploader
42+
uploaderUrl = streamEntity.uploaderUrl
43+
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
44+
}
3045
}

app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java

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

3+
import androidx.annotation.Nullable;
4+
35
import org.schabi.newpipe.database.LocalItem;
46

57
public interface PlaylistLocalItem extends LocalItem {
@@ -10,4 +12,7 @@ public interface PlaylistLocalItem extends LocalItem {
1012
long getUid();
1113

1214
void setDisplayIndex(long displayIndex);
15+
16+
@Nullable
17+
String getThumbnailUrl();
1318
}

app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistMetadataEntry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_THUMBNAIL_STREAM_ID;
1010
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_THUMBNAIL_URL;
1111

12+
import androidx.annotation.Nullable;
13+
1214
public class PlaylistMetadataEntry implements PlaylistLocalItem {
1315
public static final String PLAYLIST_STREAM_COUNT = "streamCount";
1416

@@ -71,4 +73,10 @@ public long getUid() {
7173
public void setDisplayIndex(final long displayIndex) {
7274
this.displayIndex = displayIndex;
7375
}
76+
77+
@Nullable
78+
@Override
79+
public String getThumbnailUrl() {
80+
return thumbnailUrl;
81+
}
7482
}

app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistRemoteDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface PlaylistRemoteDAO extends BasicDAO<PlaylistRemoteEntity> {
3434

3535
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE + " WHERE "
3636
+ REMOTE_PLAYLIST_ID + " = :playlistId")
37-
Flowable<List<PlaylistRemoteEntity>> getPlaylist(long playlistId);
37+
Flowable<PlaylistRemoteEntity> getPlaylist(long playlistId);
3838

3939
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE + " WHERE "
4040
+ REMOTE_PLAYLIST_URL + " = :url AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")

app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.text.TextUtils;
44

5+
import androidx.annotation.Nullable;
56
import androidx.room.ColumnInfo;
67
import androidx.room.Entity;
78
import androidx.room.Ignore;
@@ -134,6 +135,8 @@ public void setName(final String name) {
134135
this.name = name;
135136
}
136137

138+
@Nullable
139+
@Override
137140
public String getThumbnailUrl() {
138141
return thumbnailUrl;
139142
}

0 commit comments

Comments
 (0)