Skip to content

Commit de7b8d3

Browse files
Merge branch 'refactor' into History-Compose
# Conflicts: # app/src/main/res/values-be/strings.xml
2 parents 287db90 + 47299c9 commit de7b8d3

File tree

131 files changed

+1983
-674
lines changed

Some content is hidden

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

131 files changed

+1983
-674
lines changed

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
@@ -429,5 +432,10 @@
429432
<meta-data
430433
android:name="com.samsung.android.multidisplay.keep_process_alive"
431434
android:value="true" />
435+
<!-- Android Auto -->
436+
<meta-data android:name="com.google.android.gms.car.application"
437+
android:resource="@xml/automotive_app_desc" />
438+
<meta-data android:name="com.google.android.gms.car.notification.SmallIcon"
439+
android:resource="@mipmap/ic_launcher" />
432440
</application>
433441
</manifest>

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

Lines changed: 21 additions & 2 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;
@@ -136,6 +137,19 @@ protected void onCreate(final Bundle savedInstanceState) {
136137
ThemeHelper.setDayNightMode(this);
137138
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
138139

140+
// Fixes text color turning black in dark/black mode:
141+
// https://github.com/TeamNewPipe/NewPipe/issues/12016
142+
// For further reference see: https://issuetracker.google.com/issues/37124582
143+
if (DeviceUtils.supportsWebView()) {
144+
try {
145+
new WebView(this);
146+
} catch (final Throwable e) {
147+
if (DEBUG) {
148+
Log.e(TAG, "Failed to create WebView", e);
149+
}
150+
}
151+
}
152+
139153
assureCorrectAppLanguage(this);
140154
super.onCreate(savedInstanceState);
141155

@@ -578,8 +592,8 @@ public void onBackPressed() {
578592
if (player instanceof BackPressable backPressable && !backPressable.onBackPressed()) {
579593
BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder)
580594
.setState(BottomSheetBehavior.STATE_COLLAPSED);
581-
return;
582595
}
596+
return;
583597
}
584598

585599
if (fragmentManager.getBackStackEntryCount() == 1) {
@@ -826,7 +840,8 @@ private void openMiniPlayerUponPlayerStarted() {
826840
@Override
827841
public void onReceive(final Context context, final Intent intent) {
828842
if (Objects.equals(intent.getAction(),
829-
VideoDetailFragment.ACTION_PLAYER_STARTED)) {
843+
VideoDetailFragment.ACTION_PLAYER_STARTED)
844+
&& PlayerHolder.getInstance().isPlayerOpen()) {
830845
openMiniPlayerIfMissing();
831846
// At this point the player is added 100%, we can unregister. Other actions
832847
// are useless since the fragment will not be removed after that.
@@ -838,6 +853,10 @@ public void onReceive(final Context context, final Intent intent) {
838853
final IntentFilter intentFilter = new IntentFilter();
839854
intentFilter.addAction(VideoDetailFragment.ACTION_PLAYER_STARTED);
840855
registerReceiver(broadcastReceiver, intentFilter);
856+
857+
// If the PlayerHolder is not bound yet, but the service is running, try to bind to it.
858+
// Once the connection is established, the ACTION_PLAYER_STARTED will be sent.
859+
PlayerHolder.getInstance().tryBindIfNeeded(this);
841860
}
842861
}
843862

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
}

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

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@
9595
import org.schabi.newpipe.player.PlayerService;
9696
import org.schabi.newpipe.player.PlayerType;
9797
import org.schabi.newpipe.player.event.OnKeyDownListener;
98-
import org.schabi.newpipe.player.event.PlayerHolderLifecycleEventListener;
99-
import org.schabi.newpipe.player.event.PlayerServiceEventListener;
98+
import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
10099
import org.schabi.newpipe.player.helper.PlayerHelper;
101100
import org.schabi.newpipe.player.helper.PlayerHolder;
102101
import org.schabi.newpipe.player.playqueue.PlayQueue;
@@ -137,8 +136,7 @@
137136
public final class VideoDetailFragment
138137
extends BaseStateFragment<StreamInfo>
139138
implements BackPressable,
140-
PlayerServiceEventListener,
141-
PlayerHolderLifecycleEventListener,
139+
PlayerServiceExtendedEventListener,
142140
OnKeyDownListener {
143141
public static final String KEY_SWITCHING_PLAYERS = "switching_players";
144142

@@ -236,10 +234,14 @@ public final class VideoDetailFragment
236234
// Service management
237235
//////////////////////////////////////////////////////////////////////////*/
238236
@Override
239-
public void onServiceConnected(final PlayerService connectedPlayerService,
240-
final boolean playAfterConnect) {
241-
player = connectedPlayerService.getPlayer();
237+
public void onServiceConnected(@NonNull final PlayerService connectedPlayerService) {
242238
playerService = connectedPlayerService;
239+
}
240+
241+
@Override
242+
public void onPlayerConnected(@NonNull final Player connectedPlayer,
243+
final boolean playAfterConnect) {
244+
player = connectedPlayer;
243245

244246
// It will do nothing if the player is not in fullscreen mode
245247
hideSystemUiIfNeeded();
@@ -271,11 +273,18 @@ && isAutoplayEnabled()
271273
updateOverlayPlayQueueButtonVisibility();
272274
}
273275

276+
@Override
277+
public void onPlayerDisconnected() {
278+
player = null;
279+
// the binding could be null at this point, if the app is finishing
280+
if (binding != null) {
281+
restoreDefaultBrightness();
282+
}
283+
}
284+
274285
@Override
275286
public void onServiceDisconnected() {
276287
playerService = null;
277-
player = null;
278-
restoreDefaultBrightness();
279288
}
280289

281290

@@ -394,7 +403,7 @@ public void onDestroy() {
394403
if (activity.isFinishing() && isPlayerAvailable() && player.videoPlayerSelected()) {
395404
playerHolder.stopService();
396405
} else {
397-
playerHolder.unsetListeners();
406+
playerHolder.setListener(null);
398407
}
399408

400409
PreferenceManager.getDefaultSharedPreferences(activity)
@@ -659,10 +668,10 @@ protected void initListeners() {
659668
});
660669

661670
setupBottomPlayer();
662-
if (playerHolder.isNotBoundYet()) {
671+
if (!playerHolder.isBound()) {
663672
setHeightThumbnail();
664673
} else {
665-
playerHolder.startService(false, this, this);
674+
playerHolder.startService(false, this);
666675
}
667676
}
668677

@@ -1053,7 +1062,7 @@ private void openPopupPlayer(final boolean append) {
10531062

10541063
// See UI changes while remote playQueue changes
10551064
if (!isPlayerAvailable()) {
1056-
playerHolder.startService(false, this, this);
1065+
playerHolder.startService(false, this);
10571066
} else {
10581067
// FIXME Workaround #7427
10591068
player.setRecovery();
@@ -1116,7 +1125,7 @@ public void openVideoPlayerAutoFullscreen() {
11161125
private void openNormalBackgroundPlayer(final boolean append) {
11171126
// See UI changes while remote playQueue changes
11181127
if (!isPlayerAvailable()) {
1119-
playerHolder.startService(false, this, this);
1128+
playerHolder.startService(false, this);
11201129
}
11211130

11221131
final PlayQueue queue = setupPlayQueueForIntent(append);
@@ -1130,7 +1139,7 @@ private void openNormalBackgroundPlayer(final boolean append) {
11301139

11311140
private void openMainPlayer() {
11321141
if (!isPlayerServiceAvailable()) {
1133-
playerHolder.startService(autoPlayEnabled, this, this);
1142+
playerHolder.startService(autoPlayEnabled, this);
11341143
return;
11351144
}
11361145
if (currentInfo == null) {
@@ -1385,11 +1394,9 @@ public void onReceive(final Context context, final Intent intent) {
13851394
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
13861395
}
13871396
// Rebound to the service if it was closed via notification or mini player
1388-
if (playerHolder.isNotBoundYet()) {
1397+
if (!playerHolder.isBound()) {
13891398
playerHolder.startService(
1390-
false,
1391-
VideoDetailFragment.this,
1392-
VideoDetailFragment.this);
1399+
false, VideoDetailFragment.this);
13931400
}
13941401
break;
13951402
}
@@ -1838,13 +1845,16 @@ public void onPlayerError(final PlaybackException error, final boolean isCatchab
18381845

18391846
@Override
18401847
public void onServiceStopped() {
1841-
setOverlayPlayPauseImage(false);
1842-
if (currentInfo != null) {
1843-
updateOverlayData(currentInfo.getName(),
1844-
currentInfo.getUploaderName(),
1845-
currentInfo.getThumbnails());
1848+
// the binding could be null at this point, if the app is finishing
1849+
if (binding != null) {
1850+
setOverlayPlayPauseImage(false);
1851+
if (currentInfo != null) {
1852+
updateOverlayData(currentInfo.getName(),
1853+
currentInfo.getUploaderName(),
1854+
currentInfo.getThumbnails());
1855+
}
1856+
updateOverlayPlayQueueButtonVisibility();
18461857
}
1847-
updateOverlayPlayQueueButtonVisibility();
18481858
}
18491859

18501860
@Override

0 commit comments

Comments
 (0)