Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ task formatKtlint(type: JavaExec) {
}

afterEvaluate {
preDebugBuild.dependsOn runCheckstyle, runKtlint
//preDebugBuild.dependsOn runCheckstyle, runKtlint
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.EmptyFragment;
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
import org.schabi.newpipe.fragments.list.playlist.AppendPlaylistDialog;
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.MainVideoPlayer;
import org.schabi.newpipe.player.PopupVideoPlayer;
Expand Down Expand Up @@ -409,7 +409,7 @@ public void onClick(final View v) {
break;
case R.id.detail_controls_playlist_append:
if (getFragmentManager() != null && currentInfo != null) {
PlaylistAppendDialog.fromStreamInfo(currentInfo)
AppendPlaylistDialog.fromStreamInfo(currentInfo)
.show(getFragmentManager(), TAG);
}
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.schabi.newpipe.fragments.list;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
Expand All @@ -14,26 +13,15 @@

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
import org.schabi.newpipe.info_list.InfoItemDialog;
import org.schabi.newpipe.info_list.InfoListAdapter;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.OnClickGesture;
import org.schabi.newpipe.info_list.ItemListAdapter;
import org.schabi.newpipe.util.StateSaver;
import org.schabi.newpipe.util.StreamDialogEntry;
import org.schabi.newpipe.views.SuperScrollLayoutManager;

import java.util.List;
Expand All @@ -54,7 +42,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
// Views
//////////////////////////////////////////////////////////////////////////*/

protected InfoListAdapter infoListAdapter;
protected ItemListAdapter itemListAdapter;
protected RecyclerView itemsList;
private int focusedPosition = -1;

Expand All @@ -66,8 +54,8 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
public void onAttach(final Context context) {
super.onAttach(context);

if (infoListAdapter == null) {
infoListAdapter = new InfoListAdapter(activity);
if (itemListAdapter == null) {
itemListAdapter = new ItemListAdapter(activity);
}
}

Expand Down Expand Up @@ -103,8 +91,8 @@ public void onResume() {
final boolean useGrid = isGridLayout();
itemsList.setLayoutManager(useGrid
? getGridLayoutManager() : getListLayoutManager());
infoListAdapter.setUseGridVariant(useGrid);
infoListAdapter.notifyDataSetChanged();
itemListAdapter.setUseGridVariant(useGrid);
itemListAdapter.notifyDataSetChanged();
}
updateFlags = 0;
}
Expand All @@ -127,7 +115,7 @@ public void setUseDefaultStateSaving(final boolean useDefaultStateSaving) {
@Override
public String generateSuffix() {
// Naive solution, but it's good for now (the items don't change)
return "." + infoListAdapter.getItemsList().size() + ".list";
return "." + itemListAdapter.getItemList().size() + ".list";
}

private int getFocusedPosition() {
Expand All @@ -147,7 +135,7 @@ public void writeTo(final Queue<Object> objectsToSave) {
return;
}

objectsToSave.add(infoListAdapter.getItemsList());
objectsToSave.add(itemListAdapter.getItemList());
objectsToSave.add(getFocusedPosition());
}

Expand All @@ -158,8 +146,8 @@ public void readFrom(@NonNull final Queue<Object> savedObjects) throws Exception
return;
}

infoListAdapter.getItemsList().clear();
infoListAdapter.getItemsList().addAll((List<InfoItem>) savedObjects.poll());
itemListAdapter.getItemList().clear();
itemListAdapter.getItemList().addAll((List<InfoItem>) savedObjects.poll());
restoreFocus((Integer) savedObjects.poll());
}

Expand Down Expand Up @@ -230,7 +218,7 @@ protected RecyclerView.LayoutManager getGridLayoutManager() {
final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels
/ (double) width);
final GridLayoutManager lm = new GridLayoutManager(activity, spanCount);
lm.setSpanSizeLookup(infoListAdapter.getSpanSizeLookup(spanCount));
lm.setSpanSizeLookup(itemListAdapter.getSpanSizeLookup(spanCount));
return lm;
}

Expand All @@ -242,70 +230,16 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
itemsList = rootView.findViewById(R.id.items_list);
itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager());

infoListAdapter.setUseGridVariant(useGrid);
infoListAdapter.setFooter(getListFooter());
infoListAdapter.setHeader(getListHeader());
itemListAdapter.setUseGridVariant(useGrid);
itemListAdapter.setFooter(getListFooter());
itemListAdapter.setHeader(getListHeader());

itemsList.setAdapter(infoListAdapter);
}

protected void onItemSelected(final InfoItem selectedItem) {
if (DEBUG) {
Log.d(TAG, "onItemSelected() called with: selectedItem = [" + selectedItem + "]");
}
itemsList.setAdapter(itemListAdapter);
}

@Override
protected void initListeners() {
super.initListeners();
infoListAdapter.setOnStreamSelectedListener(new OnClickGesture<StreamInfoItem>() {
@Override
public void selected(final StreamInfoItem selectedItem) {
onStreamSelected(selectedItem);
}

@Override
public void held(final StreamInfoItem selectedItem) {
showStreamDialog(selectedItem);
}
});

infoListAdapter.setOnChannelSelectedListener(new OnClickGesture<ChannelInfoItem>() {
@Override
public void selected(final ChannelInfoItem selectedItem) {
try {
onItemSelected(selectedItem);
NavigationHelper.openChannelFragment(getFM(),
selectedItem.getServiceId(),
selectedItem.getUrl(),
selectedItem.getName());
} catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
}
}
});

infoListAdapter.setOnPlaylistSelectedListener(new OnClickGesture<PlaylistInfoItem>() {
@Override
public void selected(final PlaylistInfoItem selectedItem) {
try {
onItemSelected(selectedItem);
NavigationHelper.openPlaylistFragment(getFM(),
selectedItem.getServiceId(),
selectedItem.getUrl(),
selectedItem.getName());
} catch (Exception e) {
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
}
}
});

infoListAdapter.setOnCommentsSelectedListener(new OnClickGesture<CommentsInfoItem>() {
@Override
public void selected(final CommentsInfoItem selectedItem) {
onItemSelected(selectedItem);
}
});

itemsList.clearOnScrollListeners();
itemsList.addOnScrollListener(new OnScrollBelowItemsListener() {
Expand All @@ -316,46 +250,13 @@ public void onScrolledDown(final RecyclerView recyclerView) {
});
}

private void onStreamSelected(final StreamInfoItem selectedItem) {
onItemSelected(selectedItem);
NavigationHelper.openVideoDetailFragment(getFM(),
selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName());
}

protected void onScrollToBottom() {
if (hasMoreItems() && !isLoading.get()) {
loadMoreItems();
}
}


protected void showStreamDialog(final StreamInfoItem item) {
final Context context = getContext();
final Activity activity = getActivity();
if (context == null || context.getResources() == null || activity == null) {
return;
}

if (item.getStreamType() == StreamType.AUDIO_STREAM) {
StreamDialogEntry.setEnabledEntries(
StreamDialogEntry.enqueue_on_background,
StreamDialogEntry.start_here_on_background,
StreamDialogEntry.append_playlist,
StreamDialogEntry.share);
} else {
StreamDialogEntry.setEnabledEntries(
StreamDialogEntry.enqueue_on_background,
StreamDialogEntry.enqueue_on_popup,
StreamDialogEntry.start_here_on_background,
StreamDialogEntry.start_here_on_popup,
StreamDialogEntry.append_playlist,
StreamDialogEntry.share);
}

new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context),
(dialog, which) -> StreamDialogEntry.clickOn(which, this, item)).show();
}

/*//////////////////////////////////////////////////////////////////////////
// Menu
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -418,8 +319,8 @@ public void showEmptyState() {
@Override
public void showListFooter(final boolean show) {
itemsList.post(() -> {
if (infoListAdapter != null && itemsList != null) {
infoListAdapter.showFooter(show);
if (itemListAdapter != null && itemsList != null) {
itemListAdapter.showFooter(show);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onResume() {
super.onResume();
// Check if it was loading when the fragment was stopped/paused,
if (wasLoading.getAndSet(false)) {
if (hasMoreItems() && infoListAdapter.getItemsList().size() > 0) {
if (hasMoreItems() && itemListAdapter.getItemList().size() > 0) {
loadMoreItems();
} else {
doInitialLoadLogic();
Expand Down Expand Up @@ -119,7 +119,7 @@ public void startLoading(final boolean forceLoad) {
super.startLoading(forceLoad);

showListFooter(false);
infoListAdapter.clearStreamItemList();
itemListAdapter.clearStreamItemList();

currentInfo = null;
if (currentWorker != null) {
Expand Down Expand Up @@ -183,7 +183,7 @@ private void allowDownwardFocusScroll() {
public void handleNextItems(final ListExtractor.InfoItemsPage result) {
super.handleNextItems(result);
currentNextPage = result.getNextPage();
infoListAdapter.addInfoItemList(result.getItems());
itemListAdapter.addItems(result.getItems());

showListFooter(hasMoreItems());
}
Expand All @@ -204,12 +204,12 @@ public void handleResult(@NonNull final I result) {
name = result.getName();
setTitle(name);

if (infoListAdapter.getItemsList().size() == 0) {
if (itemListAdapter.getItemList().size() == 0) {
if (result.getRelatedItems().size() > 0) {
infoListAdapter.addInfoItemList(result.getRelatedItems());
itemListAdapter.addItems(result.getRelatedItems());
showListFooter(hasMoreItems());
} else {
infoListAdapter.clearStreamItemList();
itemListAdapter.clearStreamItemList();
showEmptyState();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.schabi.newpipe.R;
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
Expand Down Expand Up @@ -549,7 +548,7 @@ private PlayQueue getPlayQueue() {

private PlayQueue getPlayQueue(final int index) {
final List<StreamInfoItem> streamItems = new ArrayList<>();
for (InfoItem i : infoListAdapter.getItemsList()) {
for (Object i : itemListAdapter.getItemList()) {
if (i instanceof StreamInfoItem) {
streamItems.add((StreamInfoItem) i);
}
Expand Down
Loading