2727import android .view .View ;
2828import android .widget .TextView ;
2929
30+ import androidx .annotation .NonNull ;
3031import androidx .annotation .Nullable ;
3132import androidx .core .text .HtmlCompat ;
3233import androidx .preference .PreferenceManager ;
@@ -113,14 +114,14 @@ public static Single<List<String>> suggestionsFor(final int serviceId, final Str
113114 public static Single <StreamInfo > getStreamInfo (final int serviceId , final String url ,
114115 final boolean forceLoad ) {
115116 checkServiceId (serviceId );
116- return checkCache (forceLoad , serviceId , url , InfoItem . InfoType .STREAM ,
117+ return checkCache (forceLoad , serviceId , url , InfoCache . Type .STREAM ,
117118 Single .fromCallable (() -> StreamInfo .getInfo (NewPipe .getService (serviceId ), url )));
118119 }
119120
120121 public static Single <ChannelInfo > getChannelInfo (final int serviceId , final String url ,
121122 final boolean forceLoad ) {
122123 checkServiceId (serviceId );
123- return checkCache (forceLoad , serviceId , url , InfoItem . InfoType .CHANNEL ,
124+ return checkCache (forceLoad , serviceId , url , InfoCache . Type .CHANNEL ,
124125 Single .fromCallable (() ->
125126 ChannelInfo .getInfo (NewPipe .getService (serviceId ), url )));
126127 }
@@ -130,7 +131,7 @@ public static Single<ChannelTabInfo> getChannelTab(final int serviceId,
130131 final boolean forceLoad ) {
131132 checkServiceId (serviceId );
132133 return checkCache (forceLoad , serviceId ,
133- listLinkHandler .getUrl (), InfoItem . InfoType . CHANNEL ,
134+ listLinkHandler .getUrl (), InfoCache . Type . CHANNEL_TAB ,
134135 Single .fromCallable (() ->
135136 ChannelTabInfo .getInfo (NewPipe .getService (serviceId ), listLinkHandler )));
136137 }
@@ -145,10 +146,11 @@ public static Single<InfoItemsPage<InfoItem>> getMoreChannelTabItems(
145146 listLinkHandler , nextPage ));
146147 }
147148
148- public static Single <CommentsInfo > getCommentsInfo (final int serviceId , final String url ,
149+ public static Single <CommentsInfo > getCommentsInfo (final int serviceId ,
150+ final String url ,
149151 final boolean forceLoad ) {
150152 checkServiceId (serviceId );
151- return checkCache (forceLoad , serviceId , url , InfoItem . InfoType . COMMENT ,
153+ return checkCache (forceLoad , serviceId , url , InfoCache . Type . COMMENTS ,
152154 Single .fromCallable (() ->
153155 CommentsInfo .getInfo (NewPipe .getService (serviceId ), url )));
154156 }
@@ -175,7 +177,7 @@ public static Single<PlaylistInfo> getPlaylistInfo(final int serviceId,
175177 final String url ,
176178 final boolean forceLoad ) {
177179 checkServiceId (serviceId );
178- return checkCache (forceLoad , serviceId , url , InfoItem . InfoType .PLAYLIST ,
180+ return checkCache (forceLoad , serviceId , url , InfoCache . Type .PLAYLIST ,
179181 Single .fromCallable (() ->
180182 PlaylistInfo .getInfo (NewPipe .getService (serviceId ), url )));
181183 }
@@ -188,9 +190,10 @@ public static Single<InfoItemsPage<StreamInfoItem>> getMorePlaylistItems(final i
188190 PlaylistInfo .getMoreItems (NewPipe .getService (serviceId ), url , nextPage ));
189191 }
190192
191- public static Single <KioskInfo > getKioskInfo (final int serviceId , final String url ,
193+ public static Single <KioskInfo > getKioskInfo (final int serviceId ,
194+ final String url ,
192195 final boolean forceLoad ) {
193- return checkCache (forceLoad , serviceId , url , InfoItem . InfoType . PLAYLIST ,
196+ return checkCache (forceLoad , serviceId , url , InfoCache . Type . KIOSK ,
194197 Single .fromCallable (() -> KioskInfo .getInfo (NewPipe .getService (serviceId ), url )));
195198 }
196199
@@ -202,7 +205,7 @@ public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int
202205 }
203206
204207 /*//////////////////////////////////////////////////////////////////////////
205- // Utils
208+ // Cache
206209 //////////////////////////////////////////////////////////////////////////*/
207210
208211 /**
@@ -214,24 +217,25 @@ public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int
214217 * @param forceLoad whether to force loading from the network instead of from the cache
215218 * @param serviceId the service to load from
216219 * @param url the URL to load
217- * @param infoType the {@link InfoItem.InfoType } of the item
220+ * @param cacheType the {@link InfoCache.Type } of the item
218221 * @param loadFromNetwork the {@link Single} to load the item from the network
219222 * @return a {@link Single} that loads the item
220223 */
221224 private static <I extends Info > Single <I > checkCache (final boolean forceLoad ,
222- final int serviceId , final String url ,
223- final InfoItem .InfoType infoType ,
224- final Single <I > loadFromNetwork ) {
225+ final int serviceId ,
226+ @ NonNull final String url ,
227+ @ NonNull final InfoCache .Type cacheType ,
228+ @ NonNull final Single <I > loadFromNetwork ) {
225229 checkServiceId (serviceId );
226230 final Single <I > actualLoadFromNetwork = loadFromNetwork
227- .doOnSuccess (info -> CACHE .putInfo (serviceId , url , info , infoType ));
231+ .doOnSuccess (info -> CACHE .putInfo (serviceId , url , info , cacheType ));
228232
229233 final Single <I > load ;
230234 if (forceLoad ) {
231- CACHE .removeInfo (serviceId , url , infoType );
235+ CACHE .removeInfo (serviceId , url , cacheType );
232236 load = actualLoadFromNetwork ;
233237 } else {
234- load = Maybe .concat (ExtractorHelper .loadFromCache (serviceId , url , infoType ),
238+ load = Maybe .concat (ExtractorHelper .loadFromCache (serviceId , url , cacheType ),
235239 actualLoadFromNetwork .toMaybe ())
236240 .firstElement () // Take the first valid
237241 .toSingle ();
@@ -246,15 +250,17 @@ private static <I extends Info> Single<I> checkCache(final boolean forceLoad,
246250 * @param <I> the item type's class that extends {@link Info}
247251 * @param serviceId the service to load from
248252 * @param url the URL to load
249- * @param infoType the {@link InfoItem.InfoType } of the item
253+ * @param cacheType the {@link InfoCache.Type } of the item
250254 * @return a {@link Single} that loads the item
251255 */
252- private static <I extends Info > Maybe <I > loadFromCache (final int serviceId , final String url ,
253- final InfoItem .InfoType infoType ) {
256+ private static <I extends Info > Maybe <I > loadFromCache (
257+ final int serviceId ,
258+ @ NonNull final String url ,
259+ @ NonNull final InfoCache .Type cacheType ) {
254260 checkServiceId (serviceId );
255261 return Maybe .defer (() -> {
256262 //noinspection unchecked
257- final I info = (I ) CACHE .getFromKey (serviceId , url , infoType );
263+ final I info = (I ) CACHE .getFromKey (serviceId , url , cacheType );
258264 if (MainActivity .DEBUG ) {
259265 Log .d (TAG , "loadFromCache() called, info > " + info );
260266 }
@@ -268,11 +274,17 @@ private static <I extends Info> Maybe<I> loadFromCache(final int serviceId, fina
268274 });
269275 }
270276
271- public static boolean isCached (final int serviceId , final String url ,
272- final InfoItem .InfoType infoType ) {
273- return null != loadFromCache (serviceId , url , infoType ).blockingGet ();
277+ public static boolean isCached (final int serviceId ,
278+ @ NonNull final String url ,
279+ @ NonNull final InfoCache .Type cacheType ) {
280+ return null != loadFromCache (serviceId , url , cacheType ).blockingGet ();
274281 }
275282
283+
284+ /*//////////////////////////////////////////////////////////////////////////
285+ // Utils
286+ //////////////////////////////////////////////////////////////////////////*/
287+
276288 /**
277289 * Formats the text contained in the meta info list as HTML and puts it into the text view,
278290 * while also making the separator visible. If the list is null or empty, or the user chose not
0 commit comments