Skip to content

Commit

Permalink
Merge pull request #7904 from Stypox/fix-raw-use-of-parameterized-class
Browse files Browse the repository at this point in the history
Solve Java warning "Raw use of parameterized class"
  • Loading branch information
litetex authored Feb 26, 2022
2 parents fb75519 + 4789cf6 commit 5be40f6
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void held(final StreamInfoItem selectedItem) {
}
});

infoListAdapter.setOnChannelSelectedListener(new OnClickGesture<ChannelInfoItem>() {
infoListAdapter.setOnChannelSelectedListener(new OnClickGesture<>() {
@Override
public void selected(final ChannelInfoItem selectedItem) {
try {
Expand All @@ -288,7 +288,7 @@ public void selected(final ChannelInfoItem selectedItem) {
}
});

infoListAdapter.setOnPlaylistSelectedListener(new OnClickGesture<PlaylistInfoItem>() {
infoListAdapter.setOnPlaylistSelectedListener(new OnClickGesture<>() {
@Override
public void selected(final PlaylistInfoItem selectedItem) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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;
Expand All @@ -27,8 +28,8 @@
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
Expand All @@ -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;

Expand Down Expand Up @@ -97,7 +98,7 @@ public void writeTo(final Queue<Object> objectsToSave) {
@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();
}

Expand All @@ -124,7 +125,7 @@ protected void doInitialLoadLogic() {
* @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) {
Expand All @@ -140,7 +141,7 @@ public void startLoading(final boolean forceLoad) {
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();
Expand All @@ -157,7 +158,7 @@ public void startLoading(final boolean forceLoad) {
*
* @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() {
Expand Down Expand Up @@ -194,7 +195,7 @@ private void allowDownwardFocusScroll() {
}

@Override
public void handleNextItems(final ListExtractor.InfoItemsPage result) {
public void handleNextItems(final ListExtractor.InfoItemsPage<I> result) {
super.handleNextItems(result);

currentNextPage = result.getNextPage();
Expand All @@ -218,7 +219,7 @@ protected boolean hasMoreItems() {
//////////////////////////////////////////////////////////////////////////*/

@Override
public void handleResult(@NonNull final I result) {
public void handleResult(@NonNull final L result) {
super.handleResult(result);

name = result.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
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;
Expand Down Expand Up @@ -374,7 +374,7 @@ private void updateSubscribeButton(final boolean isSubscribed) {
//////////////////////////////////////////////////////////////////////////*/

@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<StreamInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
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;

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;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void onDestroy() {
//////////////////////////////////////////////////////////////////////////*/

@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<CommentsInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreCommentItems(serviceId, currentInfo, currentNextPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -53,7 +54,7 @@
* </p>
*/

public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
public class KioskFragment extends BaseListInfoFragment<StreamInfoItem, KioskInfo> {
@State
String kioskId = "";
String kioskTranslatedName;
Expand Down Expand Up @@ -145,7 +146,7 @@ public Single<KioskInfo> loadResult(final boolean forceReload) {
}

@Override
public Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
public Single<ListExtractor.InfoItemsPage<StreamInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
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";

Expand Down Expand Up @@ -254,7 +254,7 @@ public void onDestroy() {
//////////////////////////////////////////////////////////////////////////*/

@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<StreamInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand All @@ -26,7 +27,7 @@

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";

Expand Down Expand Up @@ -86,7 +87,7 @@ protected Supplier<View> getListHeaderSupplier() {
}

@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
protected Single<ListExtractor.InfoItemsPage<InfoItem>> loadMoreItemsLogic() {
return Single.fromCallable(ListExtractor.InfoItemsPage::emptyPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -125,10 +124,11 @@ public static void writeTo(final List<SubscriptionItem> items, final OutputStrea
/**
* @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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

import androidx.annotation.NonNull;

import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

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>>
extends PlayQueue {
boolean isInitial;
private boolean isComplete;

Expand All @@ -27,12 +26,15 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext

private transient Disposable fetchReactor;

AbstractInfoPlayQueue(final U item) {
this(item.getServiceId(), item.getUrl(), null, Collections.emptyList(), 0);
protected AbstractInfoPlayQueue(final T info) {
this(info.getServiceId(), info.getUrl(), info.getNextPage(), info.getRelatedItems(), 0);
}

AbstractInfoPlayQueue(final int serviceId, final String url, final Page nextPage,
final List<StreamInfoItem> streams, final int index) {
protected AbstractInfoPlayQueue(final int serviceId,
final String url,
final Page nextPage,
final List<StreamInfoItem> streams,
final int index) {
super(index, extractListItems(streams));

this.baseUrl = url;
Expand All @@ -51,7 +53,7 @@ public boolean isComplete() {
}

SingleObserver<T> getHeadListObserver() {
return new SingleObserver<T>() {
return new SingleObserver<>() {
@Override
public void onSubscribe(@NonNull final Disposable d) {
if (isComplete || !isInitial || (fetchReactor != null
Expand Down Expand Up @@ -85,8 +87,8 @@ public void onError(@NonNull final Throwable e) {
};
}

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
Expand All @@ -98,7 +100,8 @@ public void onSubscribe(@NonNull final Disposable d) {
}

@Override
public void onSuccess(@NonNull final ListExtractor.InfoItemsPage result) {
public void onSuccess(
@NonNull final ListExtractor.InfoItemsPage<StreamInfoItem> result) {
if (!result.hasNextPage()) {
isComplete = true;
}
Expand Down Expand Up @@ -129,12 +132,6 @@ public void dispose() {
}

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));
}
}
return result;
return infoItems.stream().map(PlayQueueItem::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.util.ExtractorHelper;

Expand All @@ -12,13 +11,10 @@
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;

public final class ChannelPlayQueue extends AbstractInfoPlayQueue<ChannelInfo, ChannelInfoItem> {
public ChannelPlayQueue(final ChannelInfoItem item) {
super(item);
}
public final class ChannelPlayQueue extends AbstractInfoPlayQueue<ChannelInfo> {

public ChannelPlayQueue(final ChannelInfo info) {
this(info.getServiceId(), info.getUrl(), info.getNextPage(), info.getRelatedItems(), 0);
super(info);
}

public ChannelPlayQueue(final int serviceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.util.ExtractorHelper;

Expand All @@ -11,13 +10,10 @@
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;

public final class PlaylistPlayQueue extends AbstractInfoPlayQueue<PlaylistInfo, PlaylistInfoItem> {
public PlaylistPlayQueue(final PlaylistInfoItem item) {
super(item);
}
public final class PlaylistPlayQueue extends AbstractInfoPlayQueue<PlaylistInfo> {

public PlaylistPlayQueue(final PlaylistInfo info) {
this(info.getServiceId(), info.getUrl(), info.getNextPage(), info.getRelatedItems(), 0);
super(info);
}

public PlaylistPlayQueue(final int serviceId,
Expand Down
Loading

0 comments on commit 5be40f6

Please sign in to comment.