22
22
import org .schabi .newpipe .NewPipeDatabase ;
23
23
import org .schabi .newpipe .R ;
24
24
import org .schabi .newpipe .database .AppDatabase ;
25
+ import org .schabi .newpipe .database .history .model .StreamHistoryEntry ;
25
26
import org .schabi .newpipe .database .playlist .PlaylistMetadataEntry ;
26
27
import org .schabi .newpipe .database .playlist .PlaylistStreamEntry ;
27
28
import org .schabi .newpipe .local .playlist .LocalPlaylistManager ;
@@ -64,6 +65,10 @@ public void release() {
64
65
private static final String ID_ROOT = "//${BuildConfig.APPLICATION_ID}/r" ;
65
66
@ NonNull
66
67
private static final String ID_BOOKMARKS = ID_ROOT + "/playlists" ;
68
+ @ NonNull
69
+ private static final String ID_HISTORY = ID_ROOT + "/history" ;
70
+ @ NonNull
71
+ private static final String ID_STREAM = ID_ROOT + "/stream" ;
67
72
68
73
private MediaItem createRootMediaItem (final String mediaId , final String folderName ) {
69
74
final var builder = new MediaDescriptionCompat .Builder ();
@@ -130,7 +135,9 @@ public void onLoadChildren(@NonNull final String parentId,
130
135
mediaItems .add (
131
136
createRootMediaItem (ID_BOOKMARKS ,
132
137
playerService .getResources ().getString (R .string .tab_bookmarks )));
133
-
138
+ mediaItems .add (
139
+ createRootMediaItem (ID_HISTORY ,
140
+ playerService .getResources ().getString (R .string .action_history )));
134
141
} else if (parentId .startsWith (ID_BOOKMARKS )) {
135
142
final var path = parentIdUri .getPathSegments ();
136
143
if (path .size () == 2 ) {
@@ -141,16 +148,38 @@ public void onLoadChildren(@NonNull final String parentId,
141
148
} else {
142
149
Log .w (TAG , "Unknown playlist uri " + parentId );
143
150
}
151
+ } else if (parentId .equals (ID_HISTORY )) {
152
+ populateHistory (mediaItems );
144
153
}
145
154
result .sendResult (mediaItems );
146
155
}
147
156
148
- private LocalPlaylistManager getPlaylistManager () {
157
+ private void populateHistory (final List <MediaItem > mediaItems ) {
158
+ final var streamHistory = getDatabase ().streamHistoryDAO ();
159
+ final var history = streamHistory .getHistory ().blockingFirst ();
160
+ mediaItems .addAll (history .stream ().map (this ::createHistoryMediaItem )
161
+ .collect (Collectors .toList ()));
162
+ }
163
+
164
+ private MediaItem createHistoryMediaItem (@ NonNull final StreamHistoryEntry streamHistoryEntry ) {
165
+ final var builder = new MediaDescriptionCompat .Builder ();
166
+ builder .setMediaId (ID_STREAM + '/' + streamHistoryEntry .getStreamId ())
167
+ .setTitle (streamHistoryEntry .getStreamEntity ().getTitle ())
168
+ .setIconUri (Uri .parse (streamHistoryEntry .getStreamEntity ().getThumbnailUrl ()));
169
+
170
+ return new MediaItem (builder .build (), MediaItem .FLAG_PLAYABLE );
171
+ }
172
+
173
+ private AppDatabase getDatabase () {
149
174
if (database == null ) {
150
175
database = NewPipeDatabase .getInstance (playerService );
151
176
}
177
+ return database ;
178
+ }
179
+
180
+ private LocalPlaylistManager getPlaylistManager () {
152
181
if (localPlaylistManager == null ) {
153
- localPlaylistManager = new LocalPlaylistManager (database );
182
+ localPlaylistManager = new LocalPlaylistManager (getDatabase () );
154
183
}
155
184
return localPlaylistManager ;
156
185
}
@@ -202,6 +231,15 @@ private PlayQueue extractPlayQueueFromMediaId(final String mediaId) {
202
231
203
232
return new SinglePlayQueue (items , index );
204
233
}
234
+ } else if (mediaId .startsWith (ID_STREAM )) {
235
+ final var path = mediaIdUri .getPathSegments ();
236
+ if (path .size () == 3 ) {
237
+ final long streamId = Long .parseLong (path .get (2 ));
238
+ final var items = getDatabase ().streamHistoryDAO ().getHistory ()
239
+ .blockingFirst ().stream ().filter (it -> it .getStreamId () == streamId )
240
+ .map (StreamHistoryEntry ::toStreamInfoItem ).collect (Collectors .toList ());
241
+ return new SinglePlayQueue (items , 0 );
242
+ }
205
243
}
206
244
207
245
playbackError (R .string .error_http_not_found ,
0 commit comments