Correctly handle Kodi action in long press menu
Automatically enable/disable it when changing the "Show play with Kodi" setting Include it in the default actions if the "Show play with Kodi" setting is enabled Hide the Kodi action if Kodi would not support the service.
This commit is contained in:
parent
f495cc075e
commit
59841e966e
@ -1,5 +1,7 @@
|
||||
package org.schabi.newpipe.settings;
|
||||
|
||||
import static org.schabi.newpipe.ui.components.menu.LongPressMenuSettingsKt.addOrRemoveKodiLongPressAction;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
@ -49,6 +51,8 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
|
||||
updateSeekOptions();
|
||||
} else if (getString(R.string.show_higher_resolutions_key).equals(key)) {
|
||||
updateResolutionOptions();
|
||||
} else if (getString(R.string.show_play_with_kodi_key).equals(key)) {
|
||||
addOrRemoveKodiLongPressAction(requireContext());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -106,16 +106,6 @@ data class LongPressAction(
|
||||
enabled: () -> Boolean = { true },
|
||||
action: suspend (context: Context) -> Unit
|
||||
) = LongPressAction(this, action, enabled)
|
||||
|
||||
companion object {
|
||||
// ShowChannelDetails is not enabled by default, since navigating to channel details can
|
||||
// also be done by clicking on the uploader name in the long press menu header
|
||||
val DefaultEnabledActions: List<Type> = listOf(
|
||||
ShowDetails, Enqueue, EnqueueNext, Background, Popup, BackgroundFromHere,
|
||||
BackgroundShuffled, Download, AddToPlaylist, Share, OpenInBrowser, MarkAsWatched,
|
||||
Rename, SetAsPlaylistThumbnail, UnsetPlaylistThumbnail, Delete, Unsubscribe, Remove
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ -249,11 +239,17 @@ data class LongPressAction(
|
||||
withContext(Dispatchers.IO) {
|
||||
HistoryRecordManager(context).markAsWatched(item).await()
|
||||
}
|
||||
},
|
||||
Type.PlayWithKodi.buildAction { context ->
|
||||
KoreUtils.playWithKore(context, item.url.toUri())
|
||||
}
|
||||
)
|
||||
) +
|
||||
if (KoreUtils.isServiceSupportedByKore(item.serviceId)) {
|
||||
listOf(
|
||||
Type.PlayWithKodi.buildAction(
|
||||
enabled = { KoreUtils.isServiceSupportedByKore(item.serviceId) }
|
||||
) { context -> KoreUtils.playWithKore(context, item.url.toUri()) }
|
||||
)
|
||||
} else {
|
||||
listOf()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +260,6 @@ data class LongPressAction(
|
||||
fun fromStreamInfoItem(
|
||||
item: StreamInfoItem,
|
||||
queueFromHere: (() -> PlayQueue)?
|
||||
/* TODO isKodiEnabled: Boolean, */
|
||||
): List<LongPressAction> {
|
||||
return buildPlayerActionList { context -> fetchItemInfoIfSparse(context, item) } +
|
||||
(queueFromHere?.let { buildPlayerFromHereActionList(queueFromHere) } ?: listOf()) +
|
||||
|
||||
@ -114,7 +114,7 @@ fun LongPressMenuEditorPage(onBackClick: () -> Unit) {
|
||||
title = stringResource(R.string.long_press_menu_actions_editor),
|
||||
onBackClick = onBackClick,
|
||||
actions = {
|
||||
ResetToDefaultsButton(state::resetToDefaults)
|
||||
ResetToDefaultsButton { state.resetToDefaults(context) }
|
||||
}
|
||||
) { paddingValues ->
|
||||
// test scrolling on Android TV by adding `.padding(horizontal = 350.dp)` here
|
||||
|
||||
@ -88,9 +88,9 @@ class LongPressMenuEditorState(
|
||||
}.toList()
|
||||
}
|
||||
|
||||
fun resetToDefaults() {
|
||||
fun resetToDefaults(context: Context) {
|
||||
items.clear()
|
||||
items.addAll(buildItemsInList(true, LongPressAction.Type.DefaultEnabledActions))
|
||||
items.addAll(buildItemsInList(true, getDefaultEnabledLongPressActions(context)))
|
||||
}
|
||||
|
||||
private fun findItemForOffsetOrClosestInRow(offset: IntOffset): LazyGridItemInfo? {
|
||||
|
||||
@ -5,6 +5,25 @@ import android.util.Log
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.schabi.newpipe.R
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.AddToPlaylist
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Background
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.BackgroundFromHere
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.BackgroundShuffled
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Delete
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Download
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Enqueue
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.EnqueueNext
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.MarkAsWatched
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.OpenInBrowser
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.PlayWithKodi
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Popup
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Remove
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Rename
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.SetAsPlaylistThumbnail
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Share
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.ShowDetails
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.UnsetPlaylistThumbnail
|
||||
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.Unsubscribe
|
||||
|
||||
private const val TAG: String = "LongPressMenuSettings"
|
||||
|
||||
@ -20,12 +39,35 @@ fun storeIsHeaderEnabledToSettings(context: Context, enabled: Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
// ShowChannelDetails is not enabled by default, since navigating to channel details can
|
||||
// also be done by clicking on the uploader name in the long press menu header.
|
||||
// PlayWithKodi is only added by default if it is enabled in settings.
|
||||
private val DefaultEnabledActions: List<LongPressAction.Type> = listOf(
|
||||
ShowDetails, Enqueue, EnqueueNext, Background, Popup, BackgroundFromHere,
|
||||
BackgroundShuffled, Download, AddToPlaylist, Share, OpenInBrowser, MarkAsWatched,
|
||||
Rename, SetAsPlaylistThumbnail, UnsetPlaylistThumbnail, Delete, Unsubscribe, Remove
|
||||
)
|
||||
|
||||
private fun getShowPlayWithKodi(context: Context): Boolean {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false)
|
||||
}
|
||||
|
||||
fun getDefaultEnabledLongPressActions(context: Context): List<LongPressAction.Type> {
|
||||
return if (getShowPlayWithKodi(context)) {
|
||||
// only include Kodi in the default actions if it is enabled in settings
|
||||
DefaultEnabledActions + listOf(PlayWithKodi)
|
||||
} else {
|
||||
DefaultEnabledActions
|
||||
}
|
||||
}
|
||||
|
||||
fun loadLongPressActionArrangementFromSettings(context: Context): List<LongPressAction.Type> {
|
||||
val key = context.getString(R.string.long_press_menu_action_arrangement_key)
|
||||
val items = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(key, null)
|
||||
if (items == null) {
|
||||
return LongPressAction.Type.DefaultEnabledActions
|
||||
return getDefaultEnabledLongPressActions(context)
|
||||
}
|
||||
|
||||
try {
|
||||
@ -45,7 +87,7 @@ fun loadLongPressActionArrangementFromSettings(context: Context): List<LongPress
|
||||
return actionsDistinct
|
||||
} catch (e: NoSuchElementException) {
|
||||
Log.e(TAG, "Invalid action in settings", e)
|
||||
return LongPressAction.Type.DefaultEnabledActions
|
||||
return getDefaultEnabledLongPressActions(context)
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,3 +98,15 @@ fun storeLongPressActionArrangementToSettings(context: Context, actions: List<Lo
|
||||
putString(key, items)
|
||||
}
|
||||
}
|
||||
|
||||
fun addOrRemoveKodiLongPressAction(context: Context) {
|
||||
val actions = loadLongPressActionArrangementFromSettings(context).toMutableList()
|
||||
if (getShowPlayWithKodi(context)) {
|
||||
if (!actions.contains(PlayWithKodi)) {
|
||||
actions.add(PlayWithKodi)
|
||||
}
|
||||
} else {
|
||||
actions.remove(PlayWithKodi)
|
||||
}
|
||||
storeLongPressActionArrangementToSettings(context, actions)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user