Skip to content

Commit c410bcc

Browse files
committed
Implement long pressing on subscriptions
1 parent b1df59f commit c410bcc

3 files changed

Lines changed: 24 additions & 36 deletions

File tree

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 & 33 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
@@ -31,7 +29,6 @@ import java.util.Date
3129
import java.util.Locale
3230
import org.schabi.newpipe.R
3331
import org.schabi.newpipe.database.feed.model.FeedGroupEntity.Companion.GROUP_ALL_ID
34-
import org.schabi.newpipe.databinding.DialogTitleBinding
3532
import org.schabi.newpipe.databinding.FeedItemCarouselBinding
3633
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
3734
import org.schabi.newpipe.error.ErrorInfo
@@ -56,12 +53,14 @@ import org.schabi.newpipe.local.subscription.workers.SubscriptionExportWorker
5653
import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput
5754
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard
5855
import org.schabi.newpipe.streams.io.StoredFileHelper
56+
import org.schabi.newpipe.ui.components.menu.LongPressAction
57+
import org.schabi.newpipe.ui.components.menu.LongPressable
58+
import org.schabi.newpipe.ui.components.menu.openLongPressMenuInActivity
5959
import org.schabi.newpipe.ui.emptystate.setEmptyStateComposable
6060
import org.schabi.newpipe.util.NavigationHelper
6161
import org.schabi.newpipe.util.OnClickGesture
6262
import org.schabi.newpipe.util.ServiceHelper
6363
import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountChannels
64-
import org.schabi.newpipe.util.external_communication.ShareUtils
6564

6665
class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
6766
private var _binding: FragmentSubscriptionBinding? = null
@@ -334,36 +333,14 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
334333
}
335334

336335
private fun showLongTapDialog(selectedItem: ChannelInfoItem) {
337-
val commands = arrayOf(
338-
getString(R.string.share),
339-
getString(R.string.open_in_browser),
340-
getString(R.string.unsubscribe)
336+
openLongPressMenuInActivity(
337+
requireActivity(),
338+
LongPressable.fromChannelInfoItem(selectedItem),
339+
LongPressAction.fromChannelInfoItem(
340+
item = selectedItem,
341+
onUnsubscribe = { deleteChannel(selectedItem) }
342+
)
341343
)
342-
343-
val actions = DialogInterface.OnClickListener { _, i ->
344-
when (i) {
345-
0 -> ShareUtils.shareText(
346-
requireContext(),
347-
selectedItem.name,
348-
selectedItem.url,
349-
selectedItem.thumbnails
350-
)
351-
352-
1 -> ShareUtils.openUrlInBrowser(requireContext(), selectedItem.url)
353-
354-
2 -> deleteChannel(selectedItem)
355-
}
356-
}
357-
358-
val dialogTitleBinding = DialogTitleBinding.inflate(LayoutInflater.from(requireContext()))
359-
dialogTitleBinding.root.isSelected = true
360-
dialogTitleBinding.itemTitleView.text = selectedItem.name
361-
dialogTitleBinding.itemAdditionalDetails.visibility = View.GONE
362-
363-
AlertDialog.Builder(requireContext())
364-
.setCustomTitle(dialogTitleBinding.root)
365-
.setItems(commands, actions)
366-
.show()
367344
}
368345

369346
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
@@ -79,6 +79,7 @@ data class LongPressAction(
7979
Rename(R.string.rename, Icons.Default.Edit),
8080
SetAsPlaylistThumbnail(R.string.set_as_playlist_thumbnail, Icons.Default.Image),
8181
UnsetPlaylistThumbnail(R.string.unset_playlist_thumbnail, Icons.Default.HideImage),
82+
Unsubscribe(R.string.unsubscribe, Icons.Default.Delete),
8283
;
8384

8485
// TODO allow actions to return disposables
@@ -302,7 +303,10 @@ data class LongPressAction(
302303
}
303304

304305
@JvmStatic
305-
fun fromChannelInfoItem(item: ChannelInfoItem): List<LongPressAction> {
306+
fun fromChannelInfoItem(
307+
item: ChannelInfoItem,
308+
onUnsubscribe: Runnable?,
309+
): List<LongPressAction> {
306310
return buildPlayerActionList { ChannelTabPlayQueue(item.serviceId, item.url) } +
307311
buildShareActionList(item) +
308312
listOf(
@@ -314,7 +318,14 @@ data class LongPressAction(
314318
item.name,
315319
)
316320
},
317-
)
321+
) +
322+
(
323+
onUnsubscribe
324+
?.let { onUnsubscribe ->
325+
listOf(Type.Unsubscribe.buildAction { onUnsubscribe.run() })
326+
}
327+
?: listOf()
328+
)
318329
}
319330

320331
@JvmStatic

0 commit comments

Comments
 (0)