Skip to content

Commit fced4c0

Browse files
committed
Implement long pressing on subscriptions
1 parent 59af0fe commit fced4c0

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void held(final ChannelInfoItem selectedItem) {
290290
openLongPressMenuInActivity(
291291
requireActivity(),
292292
LongPressable.fromChannelInfoItem(selectedItem),
293-
LongPressAction.fromChannelInfoItem(selectedItem)
293+
LongPressAction.fromChannelInfoItem(selectedItem, null)
294294
);
295295
}
296296
});

app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.schabi.newpipe.local.subscription
22

33
import android.app.Activity
44
import android.content.Context
5-
import android.content.DialogInterface
65
import android.os.Bundle
76
import android.os.Parcelable
87
import android.view.LayoutInflater
@@ -17,7 +16,6 @@ import android.widget.Toast
1716
import androidx.activity.result.ActivityResult
1817
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
1918
import androidx.annotation.StringRes
20-
import androidx.appcompat.app.AlertDialog
2119
import androidx.lifecycle.ViewModelProvider
2220
import androidx.recyclerview.widget.GridLayoutManager
2321
import com.evernote.android.state.State
@@ -28,7 +26,6 @@ import com.xwray.groupie.viewbinding.GroupieViewHolder
2826
import io.reactivex.rxjava3.disposables.CompositeDisposable
2927
import org.schabi.newpipe.R
3028
import org.schabi.newpipe.database.feed.model.FeedGroupEntity.Companion.GROUP_ALL_ID
31-
import org.schabi.newpipe.databinding.DialogTitleBinding
3229
import org.schabi.newpipe.databinding.FeedItemCarouselBinding
3330
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
3431
import org.schabi.newpipe.error.ErrorInfo
@@ -53,12 +50,14 @@ import org.schabi.newpipe.local.subscription.workers.SubscriptionExportWorker
5350
import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput
5451
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard
5552
import org.schabi.newpipe.streams.io.StoredFileHelper
53+
import org.schabi.newpipe.ui.components.menu.LongPressAction
54+
import org.schabi.newpipe.ui.components.menu.LongPressable
55+
import org.schabi.newpipe.ui.components.menu.openLongPressMenuInActivity
5656
import org.schabi.newpipe.ui.emptystate.setEmptyStateComposable
5757
import org.schabi.newpipe.util.NavigationHelper
5858
import org.schabi.newpipe.util.OnClickGesture
5959
import org.schabi.newpipe.util.ServiceHelper
6060
import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountChannels
61-
import org.schabi.newpipe.util.external_communication.ShareUtils
6261
import java.text.SimpleDateFormat
6362
import java.util.Date
6463
import java.util.Locale
@@ -329,31 +328,14 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
329328
}
330329

331330
private fun showLongTapDialog(selectedItem: ChannelInfoItem) {
332-
val commands = arrayOf(
333-
getString(R.string.share),
334-
getString(R.string.open_in_browser),
335-
getString(R.string.unsubscribe)
331+
openLongPressMenuInActivity(
332+
requireActivity(),
333+
LongPressable.fromChannelInfoItem(selectedItem),
334+
LongPressAction.fromChannelInfoItem(
335+
item = selectedItem,
336+
onUnsubscribe = { deleteChannel(selectedItem) }
337+
)
336338
)
337-
338-
val actions = DialogInterface.OnClickListener { _, i ->
339-
when (i) {
340-
0 -> ShareUtils.shareText(
341-
requireContext(), selectedItem.name, selectedItem.url, selectedItem.thumbnails
342-
)
343-
1 -> ShareUtils.openUrlInBrowser(requireContext(), selectedItem.url)
344-
2 -> deleteChannel(selectedItem)
345-
}
346-
}
347-
348-
val dialogTitleBinding = DialogTitleBinding.inflate(LayoutInflater.from(requireContext()))
349-
dialogTitleBinding.root.isSelected = true
350-
dialogTitleBinding.itemTitleView.text = selectedItem.name
351-
dialogTitleBinding.itemAdditionalDetails.visibility = View.GONE
352-
353-
AlertDialog.Builder(requireContext())
354-
.setCustomTitle(dialogTitleBinding.root)
355-
.setItems(commands, actions)
356-
.show()
357339
}
358340

359341
private fun deleteChannel(selectedItem: ChannelInfoItem) {

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressAction.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ data class LongPressAction(
7676
Rename(R.string.rename, Icons.Default.Edit),
7777
SetAsPlaylistThumbnail(R.string.set_as_playlist_thumbnail, Icons.Default.Image),
7878
UnsetPlaylistThumbnail(R.string.unset_playlist_thumbnail, Icons.Default.HideImage),
79+
Unsubscribe(R.string.unsubscribe, Icons.Default.Delete),
7980
;
8081

8182
// TODO allow actions to return disposables
@@ -285,7 +286,10 @@ data class LongPressAction(
285286
}
286287

287288
@JvmStatic
288-
fun fromChannelInfoItem(item: ChannelInfoItem): List<LongPressAction> {
289+
fun fromChannelInfoItem(
290+
item: ChannelInfoItem,
291+
onUnsubscribe: Runnable?,
292+
): List<LongPressAction> {
289293
return buildPlayerActionList { ChannelTabPlayQueue(item.serviceId, item.url) } +
290294
buildShareActionList(item) +
291295
listOf(
@@ -297,7 +301,14 @@ data class LongPressAction(
297301
item.name,
298302
)
299303
},
300-
)
304+
) +
305+
(
306+
onUnsubscribe
307+
?.let { onUnsubscribe ->
308+
listOf(Type.Unsubscribe.buildAction { onUnsubscribe.run() })
309+
}
310+
?: listOf()
311+
)
301312
}
302313

303314
@JvmStatic

0 commit comments

Comments
 (0)