Skip to content

Commit 6c41326

Browse files
committed
Replace InfoItemDialog with LongPressMenu
1 parent 25a1095 commit 6c41326

File tree

11 files changed

+166
-322
lines changed

11 files changed

+166
-322
lines changed

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.schabi.newpipe.ktx.ViewUtils.animate;
44
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
5+
import static org.schabi.newpipe.ui.components.menu.LongPressMenuKt.openLongPressMenuInActivity;
56

67
import android.content.Context;
78
import android.content.SharedPreferences;
@@ -27,7 +28,8 @@
2728
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
2829
import org.schabi.newpipe.info_list.InfoListAdapter;
2930
import org.schabi.newpipe.info_list.ItemViewMode;
30-
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
31+
import org.schabi.newpipe.ui.components.menu.LongPressAction;
32+
import org.schabi.newpipe.ui.components.menu.LongPressable;
3133
import org.schabi.newpipe.util.NavigationHelper;
3234
import org.schabi.newpipe.util.OnClickGesture;
3335
import org.schabi.newpipe.util.StateSaver;
@@ -387,11 +389,11 @@ protected void onScrollToBottom() {
387389
}
388390

389391
protected void showInfoItemDialog(final StreamInfoItem item) {
390-
try {
391-
new InfoItemDialog.Builder(getActivity(), getContext(), this, item).create().show();
392-
} catch (final IllegalArgumentException e) {
393-
InfoItemDialog.Builder.reportErrorDuringInitialization(e, item);
394-
}
392+
openLongPressMenuInActivity(
393+
requireActivity(),
394+
LongPressable.fromStreamInfoItem(item),
395+
LongPressAction.fromStreamInfoItem(item)
396+
);
395397
}
396398

397399
/*//////////////////////////////////////////////////////////////////////////

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import static org.schabi.newpipe.extractor.utils.Utils.isBlank;
44
import static org.schabi.newpipe.ktx.ViewUtils.animate;
55
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
6-
import static org.schabi.newpipe.ui.components.menu.LongPressMenuKt.getLongPressMenuView;
6+
import static org.schabi.newpipe.ui.components.menu.LongPressMenuKt.openLongPressMenuInActivity;
77
import static org.schabi.newpipe.util.ServiceHelper.getServiceById;
88

9-
import android.content.Context;
109
import android.os.Bundle;
1110
import android.text.TextUtils;
1211
import android.util.Log;
@@ -43,8 +42,6 @@
4342
import org.schabi.newpipe.extractor.stream.Description;
4443
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
4544
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
46-
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
47-
import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry;
4845
import org.schabi.newpipe.local.dialog.PlaylistDialog;
4946
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
5047
import org.schabi.newpipe.player.playqueue.PlayQueue;
@@ -153,35 +150,12 @@ private PlayQueue getPlayQueueStartingAt(final StreamInfoItem infoItem) {
153150

154151
@Override
155152
protected void showInfoItemDialog(final StreamInfoItem item) {
156-
activity.addContentView(
157-
getLongPressMenuView(
158-
requireContext(),
159-
LongPressable.from(item),
160-
LongPressAction.buildActionList(item, false)
161-
),
162-
new ViewGroup.LayoutParams(
163-
ViewGroup.LayoutParams.MATCH_PARENT,
164-
ViewGroup.LayoutParams.MATCH_PARENT
165-
)
153+
openLongPressMenuInActivity(
154+
activity,
155+
LongPressable.fromStreamInfoItem(item),
156+
// TODO handle play queue starting at
157+
LongPressAction.fromStreamInfoItem(item)
166158
);
167-
if (Context.class.getSimpleName().startsWith("C")) {
168-
return;
169-
}
170-
final Context context = getContext();
171-
try {
172-
final InfoItemDialog.Builder dialogBuilder =
173-
new InfoItemDialog.Builder(getActivity(), context, this, item);
174-
175-
dialogBuilder
176-
.setAction(
177-
StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
178-
(f, infoItem) -> NavigationHelper.playOnBackgroundPlayer(
179-
context, getPlayQueueStartingAt(infoItem), true))
180-
.create()
181-
.show();
182-
} catch (final IllegalArgumentException e) {
183-
InfoItemDialog.Builder.reportErrorDuringInitialization(e, item);
184-
}
185159
}
186160

187161
@Override

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.schabi.newpipe.local.feed
2121

2222
import android.annotation.SuppressLint
23-
import android.app.Activity
2423
import android.content.Context
2524
import android.content.Intent
2625
import android.content.SharedPreferences
@@ -63,17 +62,18 @@ import org.schabi.newpipe.error.ErrorUtil
6362
import org.schabi.newpipe.error.UserAction
6463
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
6564
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
66-
import org.schabi.newpipe.extractor.stream.StreamInfoItem
6765
import org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty
6866
import org.schabi.newpipe.fragments.BaseStateFragment
6967
import org.schabi.newpipe.info_list.ItemViewMode
70-
import org.schabi.newpipe.info_list.dialog.InfoItemDialog
7168
import org.schabi.newpipe.ktx.animate
7269
import org.schabi.newpipe.ktx.animateHideRecyclerViewAllowingScrolling
7370
import org.schabi.newpipe.ktx.slideUp
7471
import org.schabi.newpipe.local.feed.item.StreamItem
7572
import org.schabi.newpipe.local.feed.service.FeedLoadService
7673
import org.schabi.newpipe.local.subscription.SubscriptionManager
74+
import org.schabi.newpipe.ui.components.menu.LongPressAction
75+
import org.schabi.newpipe.ui.components.menu.LongPressable
76+
import org.schabi.newpipe.ui.components.menu.openLongPressMenuInActivity
7777
import org.schabi.newpipe.ui.emptystate.setEmptyStateComposable
7878
import org.schabi.newpipe.util.DeviceUtils
7979
import org.schabi.newpipe.util.Localization
@@ -379,14 +379,6 @@ class FeedFragment : BaseStateFragment<FeedState>() {
379379
feedBinding.loadingProgressBar.max = progressState.maxProgress
380380
}
381381

382-
private fun showInfoItemDialog(item: StreamInfoItem) {
383-
val context = context
384-
val activity: Activity? = getActivity()
385-
if (context == null || context.resources == null || activity == null) return
386-
387-
InfoItemDialog.Builder(activity, context, this, item).create().show()
388-
}
389-
390382
private val listenerStreamItem = object : OnItemClickListener, OnItemLongClickListener {
391383
override fun onItemClick(item: Item<*>, view: View) {
392384
if (item is StreamItem && !isRefreshing) {
@@ -400,7 +392,11 @@ class FeedFragment : BaseStateFragment<FeedState>() {
400392

401393
override fun onItemLongClick(item: Item<*>, view: View): Boolean {
402394
if (item is StreamItem && !isRefreshing) {
403-
showInfoItemDialog(item.streamWithState.stream.toStreamInfoItem())
395+
openLongPressMenuInActivity(
396+
requireActivity(),
397+
LongPressable.fromStreamEntity(item.streamWithState.stream),
398+
LongPressAction.fromStreamEntity(item.streamWithState.stream),
399+
)
404400
return true
405401
}
406402
return false

app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.local.history;
22

3-
import android.content.Context;
3+
import static org.schabi.newpipe.ui.components.menu.LongPressMenuKt.openLongPressMenuInActivity;
4+
45
import android.os.Bundle;
56
import android.os.Parcelable;
67
import android.view.LayoutInflater;
@@ -9,14 +10,12 @@
910
import android.view.MenuItem;
1011
import android.view.View;
1112
import android.view.ViewGroup;
12-
import android.widget.Toast;
1313

1414
import androidx.annotation.NonNull;
1515
import androidx.annotation.Nullable;
1616
import androidx.viewbinding.ViewBinding;
1717

1818
import com.evernote.android.state.State;
19-
import com.google.android.material.snackbar.Snackbar;
2019

2120
import org.reactivestreams.Subscriber;
2221
import org.reactivestreams.Subscription;
@@ -30,12 +29,12 @@
3029
import org.schabi.newpipe.error.UserAction;
3130
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
3231
import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder;
33-
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
34-
import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry;
3532
import org.schabi.newpipe.local.BaseLocalListFragment;
3633
import org.schabi.newpipe.player.playqueue.PlayQueue;
3734
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
3835
import org.schabi.newpipe.settings.HistorySettingsFragment;
36+
import org.schabi.newpipe.ui.components.menu.LongPressAction;
37+
import org.schabi.newpipe.ui.components.menu.LongPressable;
3938
import org.schabi.newpipe.util.NavigationHelper;
4039
import org.schabi.newpipe.util.OnClickGesture;
4140
import org.schabi.newpipe.util.PlayButtonHelper;
@@ -48,7 +47,6 @@
4847

4948
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
5049
import io.reactivex.rxjava3.disposables.CompositeDisposable;
51-
import io.reactivex.rxjava3.disposables.Disposable;
5250

5351
public class StatisticsPlaylistFragment
5452
extends BaseLocalListFragment<List<StreamStatisticsEntry>, Void>
@@ -318,50 +316,11 @@ private PlayQueue getPlayQueueStartingAt(final StreamStatisticsEntry infoItem) {
318316
}
319317

320318
private void showInfoItemDialog(final StreamStatisticsEntry item) {
321-
final Context context = getContext();
322-
final StreamInfoItem infoItem = item.toStreamInfoItem();
323-
324-
try {
325-
final InfoItemDialog.Builder dialogBuilder =
326-
new InfoItemDialog.Builder(getActivity(), context, this, infoItem);
327-
328-
// set entries in the middle; the others are added automatically
329-
dialogBuilder
330-
.addEntry(StreamDialogDefaultEntry.DELETE)
331-
.setAction(
332-
StreamDialogDefaultEntry.DELETE,
333-
(f, i) -> deleteEntry(
334-
Math.max(itemListAdapter.getItemsList().indexOf(item), 0)))
335-
.create()
336-
.show();
337-
} catch (final IllegalArgumentException e) {
338-
InfoItemDialog.Builder.reportErrorDuringInitialization(e, infoItem);
339-
}
340-
}
341-
342-
private void deleteEntry(final int index) {
343-
final LocalItem infoItem = itemListAdapter.getItemsList().get(index);
344-
if (infoItem instanceof StreamStatisticsEntry) {
345-
final StreamStatisticsEntry entry = (StreamStatisticsEntry) infoItem;
346-
final Disposable onDelete = recordManager
347-
.deleteStreamHistoryAndState(entry.getStreamId())
348-
.observeOn(AndroidSchedulers.mainThread())
349-
.subscribe(
350-
() -> {
351-
if (getView() != null) {
352-
Snackbar.make(getView(), R.string.one_item_deleted,
353-
Snackbar.LENGTH_SHORT).show();
354-
} else {
355-
Toast.makeText(getContext(),
356-
R.string.one_item_deleted,
357-
Toast.LENGTH_SHORT).show();
358-
}
359-
},
360-
throwable -> showSnackBarError(new ErrorInfo(throwable,
361-
UserAction.DELETE_FROM_HISTORY, "Deleting item")));
362-
363-
disposables.add(onDelete);
364-
}
319+
openLongPressMenuInActivity(
320+
requireActivity(),
321+
LongPressable.fromStreamEntity(item.getStreamEntity()),
322+
LongPressAction.fromStreamStatisticsEntry(item)
323+
);
365324
}
366325

367326
@Override

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.schabi.newpipe.local.playlist.PlayListShareMode.JUST_URLS;
77
import static org.schabi.newpipe.local.playlist.PlayListShareMode.WITH_TITLES;
88
import static org.schabi.newpipe.local.playlist.PlayListShareMode.YOUTUBE_TEMP_PLAYLIST;
9+
import static org.schabi.newpipe.ui.components.menu.LongPressMenuKt.openLongPressMenuInActivity;
910
import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout;
1011

1112

@@ -49,12 +50,12 @@
4950
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
5051
import org.schabi.newpipe.fragments.MainFragment;
5152
import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder;
52-
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
53-
import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry;
5453
import org.schabi.newpipe.local.BaseLocalListFragment;
5554
import org.schabi.newpipe.local.history.HistoryRecordManager;
5655
import org.schabi.newpipe.player.playqueue.PlayQueue;
5756
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
57+
import org.schabi.newpipe.ui.components.menu.LongPressAction;
58+
import org.schabi.newpipe.ui.components.menu.LongPressable;
5859
import org.schabi.newpipe.util.Localization;
5960
import org.schabi.newpipe.util.NavigationHelper;
6061
import org.schabi.newpipe.util.OnClickGesture;
@@ -797,39 +798,16 @@ private PlayQueue getPlayQueueStartingAt(final PlaylistStreamEntry infoItem) {
797798
}
798799

799800
protected void showInfoItemDialog(final PlaylistStreamEntry item) {
800-
final StreamInfoItem infoItem = item.toStreamInfoItem();
801-
802-
try {
803-
final Context context = getContext();
804-
final InfoItemDialog.Builder dialogBuilder =
805-
new InfoItemDialog.Builder(getActivity(), context, this, infoItem);
806-
807-
// add entries in the middle
808-
dialogBuilder.addAllEntries(
809-
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
810-
StreamDialogDefaultEntry.DELETE
811-
);
812-
813-
// set custom actions
814-
// all entries modified below have already been added within the builder
815-
dialogBuilder
816-
.setAction(
817-
StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
818-
(f, i) -> NavigationHelper.playOnBackgroundPlayer(
819-
context, getPlayQueueStartingAt(item), true))
820-
.setAction(
821-
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
822-
(f, i) ->
823-
changeThumbnailStreamId(item.getStreamEntity().getUid(),
824-
true))
825-
.setAction(
826-
StreamDialogDefaultEntry.DELETE,
827-
(f, i) -> deleteItem(item))
828-
.create()
829-
.show();
830-
} catch (final IllegalArgumentException e) {
831-
InfoItemDialog.Builder.reportErrorDuringInitialization(e, infoItem);
832-
}
801+
openLongPressMenuInActivity(
802+
requireActivity(),
803+
LongPressable.fromStreamEntity(item.getStreamEntity()),
804+
// TODO getPlayQueueStartingAt(), resumePlayback=true
805+
LongPressAction.fromPlaylistStreamEntry(
806+
item,
807+
() -> deleteItem(item),
808+
() -> changeThumbnailStreamId(item.getStreamEntity().getUid(), true)
809+
)
810+
);
833811
}
834812

835813
private void setInitialData(final long pid, final String title) {

app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import androidx.compose.foundation.lazy.LazyListScope
55
import androidx.compose.foundation.lazy.rememberLazyListState
66
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
77
import androidx.compose.runtime.Composable
8-
import androidx.compose.runtime.getValue
9-
import androidx.compose.runtime.mutableStateOf
108
import androidx.compose.runtime.remember
11-
import androidx.compose.runtime.setValue
129
import androidx.compose.ui.Modifier
1310
import androidx.compose.ui.input.nestedscroll.nestedScroll
1411
import androidx.compose.ui.platform.LocalContext
@@ -50,20 +47,6 @@ fun ItemList(
5047
}
5148
}
5249

53-
// Handle long clicks for stream items
54-
// TODO: Adjust the menu display depending on where it was triggered
55-
var selectedStream by remember { mutableStateOf<StreamInfoItem?>(null) }
56-
val onLongClick = remember {
57-
{ stream: StreamInfoItem ->
58-
selectedStream = stream
59-
}
60-
}
61-
val onDismissPopup = remember {
62-
{
63-
selectedStream = null
64-
}
65-
}
66-
6750
val showProgress = DependentPreferenceHelper.getPositionsInListsEnabled(context)
6851
val nestedScrollModifier = Modifier.nestedScroll(rememberNestedScrollInteropConnection())
6952

@@ -80,10 +63,7 @@ fun ItemList(
8063
val item = items[it]
8164

8265
if (item is StreamInfoItem) {
83-
val isSelected = selectedStream == item
84-
StreamListItem(
85-
item, showProgress, isSelected, onClick, onLongClick, onDismissPopup
86-
)
66+
StreamListItem(item, showProgress, onClick)
8767
} else if (item is PlaylistInfoItem) {
8868
PlaylistListItem(item, onClick)
8969
}

0 commit comments

Comments
 (0)