@@ -5,6 +5,25 @@ import android.util.Log
55import androidx.core.content.edit
66import androidx.preference.PreferenceManager
77import org.schabi.newpipe.R
8+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.AddToPlaylist
9+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Background
10+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.BackgroundFromHere
11+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.BackgroundShuffled
12+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Delete
13+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Download
14+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Enqueue
15+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.EnqueueNext
16+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.MarkAsWatched
17+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.OpenInBrowser
18+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.PlayWithKodi
19+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Popup
20+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Remove
21+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Rename
22+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.SetAsPlaylistThumbnail
23+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Share
24+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.ShowDetails
25+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.UnsetPlaylistThumbnail
26+ import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Unsubscribe
827
928private const val TAG : String = " LongPressMenuSettings"
1029
@@ -20,12 +39,35 @@ fun storeIsHeaderEnabledToSettings(context: Context, enabled: Boolean) {
2039 }
2140}
2241
42+ // ShowChannelDetails is not enabled by default, since navigating to channel details can
43+ // also be done by clicking on the uploader name in the long press menu header.
44+ // PlayWithKodi is only added by default if it is enabled in settings.
45+ private val DefaultEnabledActions : List <LongPressAction .Type > = listOf (
46+ ShowDetails , Enqueue , EnqueueNext , Background , Popup , BackgroundFromHere ,
47+ BackgroundShuffled , Download , AddToPlaylist , Share , OpenInBrowser , MarkAsWatched ,
48+ Rename , SetAsPlaylistThumbnail , UnsetPlaylistThumbnail , Delete , Unsubscribe , Remove
49+ )
50+
51+ private fun getShowPlayWithKodi (context : Context ): Boolean {
52+ return PreferenceManager .getDefaultSharedPreferences(context)
53+ .getBoolean(context.getString(R .string.show_play_with_kodi_key), false )
54+ }
55+
56+ fun getDefaultEnabledLongPressActions (context : Context ): List <LongPressAction .Type > {
57+ return if (getShowPlayWithKodi(context)) {
58+ // only include Kodi in the default actions if it is enabled in settings
59+ DefaultEnabledActions + listOf (PlayWithKodi )
60+ } else {
61+ DefaultEnabledActions
62+ }
63+ }
64+
2365fun loadLongPressActionArrangementFromSettings (context : Context ): List <LongPressAction .Type > {
2466 val key = context.getString(R .string.long_press_menu_action_arrangement_key)
2567 val items = PreferenceManager .getDefaultSharedPreferences(context)
2668 .getString(key, null )
2769 if (items == null ) {
28- return LongPressAction . Type . DefaultEnabledActions
70+ return getDefaultEnabledLongPressActions(context)
2971 }
3072
3173 try {
@@ -45,7 +87,7 @@ fun loadLongPressActionArrangementFromSettings(context: Context): List<LongPress
4587 return actionsDistinct
4688 } catch (e: NoSuchElementException ) {
4789 Log .e(TAG , " Invalid action in settings" , e)
48- return LongPressAction . Type . DefaultEnabledActions
90+ return getDefaultEnabledLongPressActions(context)
4991 }
5092}
5193
@@ -56,3 +98,15 @@ fun storeLongPressActionArrangementToSettings(context: Context, actions: List<Lo
5698 putString(key, items)
5799 }
58100}
101+
102+ fun addOrRemoveKodiLongPressAction (context : Context ) {
103+ val actions = loadLongPressActionArrangementFromSettings(context).toMutableList()
104+ if (getShowPlayWithKodi(context)) {
105+ if (! actions.contains(PlayWithKodi )) {
106+ actions.add(PlayWithKodi )
107+ }
108+ } else {
109+ actions.remove(PlayWithKodi )
110+ }
111+ storeLongPressActionArrangementToSettings(context, actions)
112+ }
0 commit comments