Solve Java warning "Raw use of parameterized class"

This commit is contained in:
Stypox 2022-02-19 16:53:37 +01:00
parent af80d96b9e
commit 62abfa96b8
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
13 changed files with 74 additions and 67 deletions

View File

@ -272,7 +272,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
}
});
infoListAdapter.setOnChannelSelectedListener(new OnClickGesture<ChannelInfoItem>() {
infoListAdapter.setOnChannelSelectedListener(new OnClickGesture<>() {
@Override
public void selected(final ChannelInfoItem selectedItem) {
try {
@ -288,7 +288,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
}
});
infoListAdapter.setOnPlaylistSelectedListener(new OnClickGesture<PlaylistInfoItem>() {
infoListAdapter.setOnPlaylistSelectedListener(new OnClickGesture<>() {
@Override
public void selected(final PlaylistInfoItem selectedItem) {
try {

View File

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.Page;
@ -27,8 +28,8 @@ import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
public abstract class BaseListInfoFragment<I extends ListInfo>
extends BaseListFragment<I, ListExtractor.InfoItemsPage> {
public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInfo<I>>
extends BaseListFragment<L, ListExtractor.InfoItemsPage<I>> {
@State
protected int serviceId = Constants.NO_SERVICE_ID;
@State
@ -37,7 +38,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
protected String url;
private final UserAction errorUserAction;
protected I currentInfo;
protected L currentInfo;
protected Page currentNextPage;
protected Disposable currentWorker;
@ -97,7 +98,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
@SuppressWarnings("unchecked")
public void readFrom(@NonNull final Queue<Object> savedObjects) throws Exception {
super.readFrom(savedObjects);
currentInfo = (I) savedObjects.poll();
currentInfo = (L) savedObjects.poll();
currentNextPage = (Page) savedObjects.poll();
}
@ -124,7 +125,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
* @param forceLoad allow or disallow the result to come from the cache
* @return Rx {@link Single} containing the {@link ListInfo}
*/
protected abstract Single<I> loadResult(boolean forceLoad);
protected abstract Single<L> loadResult(boolean forceLoad);
@Override
public void startLoading(final boolean forceLoad) {
@ -140,7 +141,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
currentWorker = loadResult(forceLoad)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@NonNull I result) -> {
.subscribe((@NonNull L result) -> {
isLoading.set(false);
currentInfo = result;
currentNextPage = result.getNextPage();
@ -157,7 +158,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
*
* @return Rx {@link Single} containing the {@link ListExtractor.InfoItemsPage}
*/
protected abstract Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic();
protected abstract Single<ListExtractor.InfoItemsPage<I>> loadMoreItemsLogic();
@Override
protected void loadMoreItems() {
@ -194,7 +195,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
}
@Override
public void handleNextItems(final ListExtractor.InfoItemsPage result) {
public void handleNextItems(final ListExtractor.InfoItemsPage<I> result) {
super.handleNextItems(result);
currentNextPage = result.getNextPage();
@ -218,7 +219,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
//////////////////////////////////////////////////////////////////////////*/
@Override
public void handleResult(@NonNull final I result) {
public void handleResult(@NonNull final L result) {
super.handleResult(result);
name = result.getName();

View File

@ -64,7 +64,7 @@ import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;
public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
public class ChannelFragment extends BaseListInfoFragment<StreamInfoItem, ChannelInfo>
implements View.OnClickListener {
private static final int BUTTON_DEBOUNCE_INTERVAL = 100;
@ -374,7 +374,7 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
//////////////////////////////////////////////////////////////////////////*/
@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<StreamInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPage);
}

View File

@ -15,6 +15,7 @@ import org.schabi.newpipe.R;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.ktx.ViewUtils;
import org.schabi.newpipe.util.ExtractorHelper;
@ -22,7 +23,7 @@ import org.schabi.newpipe.util.ExtractorHelper;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
public class CommentsFragment extends BaseListInfoFragment<CommentsInfoItem, CommentsInfo> {
private final CompositeDisposable disposables = new CompositeDisposable();
private TextView emptyStateDesc;
@ -67,7 +68,7 @@ public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
//////////////////////////////////////////////////////////////////////////*/
@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<CommentsInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreCommentItems(serviceId, currentInfo, currentNextPage);
}

View File

@ -21,6 +21,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.KioskTranslator;
@ -53,7 +54,7 @@ import io.reactivex.rxjava3.core.Single;
* </p>
*/
public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
public class KioskFragment extends BaseListInfoFragment<StreamInfoItem, KioskInfo> {
@State
String kioskId = "";
String kioskTranslatedName;
@ -145,7 +146,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
}
@Override
public Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
public Single<ListExtractor.InfoItemsPage<StreamInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPage);
}

View File

@ -64,7 +64,7 @@ import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;
public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, PlaylistInfo> {
private static final String PICASSO_PLAYLIST_TAG = "PICASSO_PLAYLIST_TAG";
@ -249,7 +249,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
//////////////////////////////////////////////////////////////////////////*/
@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<StreamInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPage);
}

View File

@ -15,6 +15,7 @@ import androidx.preference.PreferenceManager;
import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.RelatedItemsHeaderBinding;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
@ -26,7 +27,7 @@ import java.util.function.Supplier;
import io.reactivex.rxjava3.core.Single;
public class RelatedItemsFragment extends BaseListInfoFragment<RelatedItemInfo>
public class RelatedItemsFragment extends BaseListInfoFragment<InfoItem, RelatedItemInfo>
implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String INFO_KEY = "related_info_key";
@ -86,7 +87,7 @@ public class RelatedItemsFragment extends BaseListInfoFragment<RelatedItemInfo>
}
@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<InfoItem>> loadMoreItemsLogic() {
return Single.fromCallable(ListExtractor.InfoItemsPage::emptyPage);
}

View File

@ -25,7 +25,6 @@ import com.grack.nanojson.JsonAppendableWriter;
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonSink;
import com.grack.nanojson.JsonWriter;
import org.schabi.newpipe.BuildConfig;
@ -125,10 +124,11 @@ public final class ImportExportJsonHelper {
/**
* @see #writeTo(List, OutputStream, ImportExportEventListener)
* @param items the list of subscriptions items
* @param writer the output {@link JsonSink}
* @param writer the output {@link JsonAppendableWriter}
* @param eventListener listener for the events generated
*/
public static void writeTo(final List<SubscriptionItem> items, final JsonSink writer,
public static void writeTo(final List<SubscriptionItem> items,
final JsonAppendableWriter writer,
@Nullable final ImportExportEventListener eventListener) {
if (eventListener != null) {
eventListener.onSizeReceived(items.size());

View File

@ -17,7 +17,8 @@ import java.util.List;
import io.reactivex.rxjava3.core.SingleObserver;
import io.reactivex.rxjava3.disposables.Disposable;
abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> extends PlayQueue {
abstract class AbstractInfoPlayQueue<T extends ListInfo<StreamInfoItem>, U extends InfoItem>
extends PlayQueue {
boolean isInitial;
private boolean isComplete;
@ -51,7 +52,7 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
}
SingleObserver<T> getHeadListObserver() {
return new SingleObserver<T>() {
return new SingleObserver<>() {
@Override
public void onSubscribe(@NonNull final Disposable d) {
if (isComplete || !isInitial || (fetchReactor != null
@ -85,8 +86,8 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
};
}
SingleObserver<ListExtractor.InfoItemsPage> getNextPageObserver() {
return new SingleObserver<ListExtractor.InfoItemsPage>() {
SingleObserver<ListExtractor.InfoItemsPage<StreamInfoItem>> getNextPageObserver() {
return new SingleObserver<>() {
@Override
public void onSubscribe(@NonNull final Disposable d) {
if (isComplete || isInitial || (fetchReactor != null
@ -98,7 +99,8 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
}
@Override
public void onSuccess(@NonNull final ListExtractor.InfoItemsPage result) {
public void onSuccess(
@NonNull final ListExtractor.InfoItemsPage<StreamInfoItem> result) {
if (!result.hasNextPage()) {
isComplete = true;
}
@ -130,10 +132,8 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
private static List<PlayQueueItem> extractListItems(final List<StreamInfoItem> infoItems) {
final List<PlayQueueItem> result = new ArrayList<>();
for (final InfoItem stream : infoItems) {
if (stream instanceof StreamInfoItem) {
result.add(new PlayQueueItem((StreamInfoItem) stream));
}
for (final StreamInfoItem stream : infoItems) {
result.add(new PlayQueueItem(stream));
}
return result;
}

View File

@ -8,7 +8,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonSink;
import com.grack.nanojson.JsonStringWriter;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.LocalItem.LocalItemType;
@ -132,7 +132,7 @@ public abstract class Tab {
// JSON Handling
//////////////////////////////////////////////////////////////////////////*/
public void writeJsonOn(final JsonSink jsonSink) {
public void writeJsonOn(final JsonStringWriter jsonSink) {
jsonSink.object();
jsonSink.value(JSON_TAB_ID_KEY, getTabId());
@ -141,7 +141,7 @@ public abstract class Tab {
jsonSink.end();
}
protected void writeDataToJson(final JsonSink writerSink) {
protected void writeDataToJson(final JsonStringWriter writerSink) {
// No-op
}
@ -355,7 +355,7 @@ public abstract class Tab {
}
@Override
protected void writeDataToJson(final JsonSink writerSink) {
protected void writeDataToJson(final JsonStringWriter writerSink) {
writerSink.value(JSON_KIOSK_SERVICE_ID_KEY, kioskServiceId)
.value(JSON_KIOSK_ID_KEY, kioskId);
}
@ -437,7 +437,7 @@ public abstract class Tab {
}
@Override
protected void writeDataToJson(final JsonSink writerSink) {
protected void writeDataToJson(final JsonStringWriter writerSink) {
writerSink.value(JSON_CHANNEL_SERVICE_ID_KEY, channelServiceId)
.value(JSON_CHANNEL_URL_KEY, channelUrl)
.value(JSON_CHANNEL_NAME_KEY, channelName);
@ -584,7 +584,7 @@ public abstract class Tab {
}
@Override
protected void writeDataToJson(final JsonSink writerSink) {
protected void writeDataToJson(final JsonStringWriter writerSink) {
writerSink.value(JSON_PLAYLIST_SERVICE_ID_KEY, playlistServiceId)
.value(JSON_PLAYLIST_URL_KEY, playlistUrl)
.value(JSON_PLAYLIST_NAME_KEY, playlistName)

View File

@ -30,6 +30,7 @@ import androidx.preference.PreferenceManager;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.util.external_communication.TextLinkifier;
import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.InfoItem;
@ -84,11 +85,12 @@ public final class ExtractorHelper {
.fromQuery(searchString, contentFilter, sortFilter)));
}
public static Single<InfoItemsPage> getMoreSearchItems(final int serviceId,
final String searchString,
final List<String> contentFilter,
final String sortFilter,
final Page page) {
public static Single<InfoItemsPage<InfoItem>> getMoreSearchItems(
final int serviceId,
final String searchString,
final List<String> contentFilter,
final String sortFilter,
final Page page) {
checkServiceId(serviceId);
return Single.fromCallable(() ->
SearchInfo.getMoreItems(NewPipe.getService(serviceId),
@ -124,8 +126,9 @@ public final class ExtractorHelper {
ChannelInfo.getInfo(NewPipe.getService(serviceId), url)));
}
public static Single<InfoItemsPage> getMoreChannelItems(final int serviceId, final String url,
final Page nextPage) {
public static Single<InfoItemsPage<StreamInfoItem>> getMoreChannelItems(final int serviceId,
final String url,
final Page nextPage) {
checkServiceId(serviceId);
return Single.fromCallable(() ->
ChannelInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage));
@ -155,15 +158,17 @@ public final class ExtractorHelper {
CommentsInfo.getInfo(NewPipe.getService(serviceId), url)));
}
public static Single<InfoItemsPage> getMoreCommentItems(final int serviceId,
final CommentsInfo info,
final Page nextPage) {
public static Single<InfoItemsPage<CommentsInfoItem>> getMoreCommentItems(
final int serviceId,
final CommentsInfo info,
final Page nextPage) {
checkServiceId(serviceId);
return Single.fromCallable(() ->
CommentsInfo.getMoreItems(NewPipe.getService(serviceId), info, nextPage));
}
public static Single<PlaylistInfo> getPlaylistInfo(final int serviceId, final String url,
public static Single<PlaylistInfo> getPlaylistInfo(final int serviceId,
final String url,
final boolean forceLoad) {
checkServiceId(serviceId);
return checkCache(forceLoad, serviceId, url, InfoItem.InfoType.PLAYLIST,
@ -171,8 +176,9 @@ public final class ExtractorHelper {
PlaylistInfo.getInfo(NewPipe.getService(serviceId), url)));
}
public static Single<InfoItemsPage> getMorePlaylistItems(final int serviceId, final String url,
final Page nextPage) {
public static Single<InfoItemsPage<StreamInfoItem>> getMorePlaylistItems(final int serviceId,
final String url,
final Page nextPage) {
checkServiceId(serviceId);
return Single.fromCallable(() ->
PlaylistInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage));
@ -184,8 +190,9 @@ public final class ExtractorHelper {
Single.fromCallable(() -> KioskInfo.getInfo(NewPipe.getService(serviceId), url)));
}
public static Single<InfoItemsPage> getMoreKioskItems(final int serviceId, final String url,
final Page nextPage) {
public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int serviceId,
final String url,
final Page nextPage) {
return Single.fromCallable(() ->
KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage));
}

View File

@ -19,7 +19,7 @@ public final class SerializedCache {
private static final boolean DEBUG = MainActivity.DEBUG;
private static final SerializedCache INSTANCE = new SerializedCache();
private static final int MAX_ITEMS_ON_CACHE = 5;
private static final LruCache<String, CacheData> LRU_CACHE =
private static final LruCache<String, CacheData<?>> LRU_CACHE =
new LruCache<>(MAX_ITEMS_ON_CACHE);
private static final String TAG = "SerializedCache";
@ -47,7 +47,7 @@ public final class SerializedCache {
Log.d(TAG, "get() called with: key = [" + key + "]");
}
synchronized (LRU_CACHE) {
final CacheData data = LRU_CACHE.get(key);
final CacheData<?> data = LRU_CACHE.get(key);
return data != null ? getItem(data, type) : null;
}
}
@ -91,7 +91,7 @@ public final class SerializedCache {
}
@Nullable
private <T> T getItem(@NonNull final CacheData data, @NonNull final Class<T> type) {
private <T> T getItem(@NonNull final CacheData<?> data, @NonNull final Class<T> type) {
return type.isAssignableFrom(data.type) ? type.cast(data.item) : null;
}

View File

@ -12,6 +12,7 @@ import android.widget.TextView;
import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@ -137,7 +138,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
}
if (streamsWrapper.getSizeInBytes(position) > 0) {
final SecondaryStreamHelper secondary = secondaryStreams == null ? null
final SecondaryStreamHelper<U> secondary = secondaryStreams == null ? null
: secondaryStreams.get(position);
if (secondary != null) {
final long size
@ -153,16 +154,11 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
if (stream instanceof SubtitlesStream) {
formatNameView.setText(((SubtitlesStream) stream).getLanguageTag());
} else if (stream.getFormat() == MediaFormat.WEBMA_OPUS) {
// noinspection AndroidLintSetTextI18n
formatNameView.setText("opus");
} else {
switch (stream.getFormat()) {
case WEBMA_OPUS:
// noinspection AndroidLintSetTextI18n
formatNameView.setText("opus");
break;
default:
formatNameView.setText(stream.getFormat().getName());
break;
}
formatNameView.setText(stream.getFormat().getName());
}
qualityView.setText(qualityString);