From 834060a2df1857d0851d234bd2c87f668fdd104d Mon Sep 17 00:00:00 2001 From: Secozzi Date: Wed, 27 Nov 2024 12:26:47 +0100 Subject: [PATCH 1/2] feat(custombuttons): Add documentation for custom buttons and mpvkt.lua interface --- CUSTOMBUTTONS.md | 43 +++++++++++++++++++ .../custombuttons/CustomButtonsScreen.kt | 7 +++ .../ui/custombuttons/CustomButtonsScreen.kt | 5 +++ .../mehiz/mpvkt/ui/player/PlayerActivity.kt | 4 +- .../mehiz/mpvkt/ui/player/PlayerViewModel.kt | 4 +- 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 CUSTOMBUTTONS.md diff --git a/CUSTOMBUTTONS.md b/CUSTOMBUTTONS.md new file mode 100644 index 0000000..794ce80 --- /dev/null +++ b/CUSTOMBUTTONS.md @@ -0,0 +1,43 @@ +# CUSTOM BUTTONS + +Custom buttons provides a way to execute lua code by pressing a button in the player. mpvKt also provides an interface to interact with some parts of the player. + +The interface is defined in a file placed in the `scripts` directory and can be accessed through the `mpvkt` table. + +## Lua interface + +### `mpvkt.show_text(text)` +Display a message on the player. + +### `mpvkt.hide_ui()` +Hide the player UI. + +### `mpvkt.show_ui()` +Show the player UI. + +### `mpvkt.toggle_ui()` +Toggle the visibility of the player UI. + +### `mpvkt.show_subtitle_settings()` +Show the subtitle settings sheet. + +### `mpvkt.show_subtitle_delay()` +Show the subtitle delay sheet. + +### `mpvkt.show_audio_delay()` +Show the subtitle delay sheet. + +### `mpvkt.show_video_filters()` +Show the video filters sheet. + +### `mpvkt.set_button_title(text)` +Change the title for the primary custom button. + +### `mpvkt.reset_button_title(text)` +Reset the title for the primary custom button. + +## Call a custom button from key input or from lua + +Custom buttons can be called from key inputs or from other lua scripts, if so desired. This is done through `script-message` with the message `call_button_` for normal press and `call_button__long` for long press, where `` is the id for the button (shown in top right when editing a button). + +Example: `a script-message call_button_1` will call the button of id 1 when `a` is pressed, if added to `input.conf`. \ No newline at end of file diff --git a/app/src/main/java/live/mehiz/mpvkt/presentation/custombuttons/CustomButtonsScreen.kt b/app/src/main/java/live/mehiz/mpvkt/presentation/custombuttons/CustomButtonsScreen.kt index 0c32b12..760f8a0 100644 --- a/app/src/main/java/live/mehiz/mpvkt/presentation/custombuttons/CustomButtonsScreen.kt +++ b/app/src/main/java/live/mehiz/mpvkt/presentation/custombuttons/CustomButtonsScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.automirrored.outlined.HelpOutline import androidx.compose.material.icons.filled.Add import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExtendedFloatingActionButton @@ -48,6 +49,7 @@ fun CustomButtonsScreen( onClickMoveUp: (CustomButtonEntity) -> Unit, onClickMoveDown: (CustomButtonEntity) -> Unit, onTogglePrimary: (CustomButtonEntity) -> Unit, + onClickFaq: () -> Unit, onNavigateBack: () -> Unit, ) { val lazyListState = rememberLazyListState() @@ -62,6 +64,11 @@ fun CustomButtonsScreen( Icon(Icons.AutoMirrored.Default.ArrowBack, null) } }, + actions = { + IconButton(onClick = { onClickFaq() }) { + Icon(Icons.AutoMirrored.Outlined.HelpOutline, null) + } + } ) }, floatingActionButton = { diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt b/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt index cb36eb9..026659b 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt @@ -3,6 +3,7 @@ package live.mehiz.mpvkt.ui.custombuttons import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.ui.platform.LocalUriHandler import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import kotlinx.collections.immutable.toImmutableList @@ -21,6 +22,7 @@ object CustomButtonsScreen : Screen() { @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow + val uriHandler = LocalUriHandler.current val viewModel = koinViewModel() val playerPreferences = koinInject() @@ -37,6 +39,7 @@ object CustomButtonsScreen : Screen() { onTogglePrimary = viewModel::togglePrimary, onClickMoveUp = viewModel::moveUp, onClickMoveDown = viewModel::moveDown, + onClickFaq = { uriHandler.openUri(CUSTOM_BUTTONS_DOC_URL) }, onNavigateBack = navigator::pop, ) @@ -82,3 +85,5 @@ sealed interface CustomButtonDialog { data class Edit(val customButton: CustomButtonEntity) : CustomButtonDialog data class Delete(val customButton: CustomButtonEntity) : CustomButtonDialog } + +private const val CUSTOM_BUTTONS_DOC_URL = "https://github.com/abdallahmehiz/mpvKt/blob/main/CUSTOMBUTTONS.md" diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt index 1453672..abed1ba 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt @@ -302,11 +302,11 @@ class PlayerActivity : AppCompatActivity() { appendLine("function button${button.id}()") appendLine(button.content) appendLine("end") - appendLine("mp.register_script_message('call_button${button.id}', button${button.id})") + appendLine("mp.register_script_message('call_button_${button.id}', button${button.id})") appendLine("function button${button.id}long()") appendLine(button.longPressContent) appendLine("end") - appendLine("mp.register_script_message('call_button${button.id}long', button${button.id}long)") + appendLine("mp.register_script_message('call_button_${button.id}_long', button${button.id}long)") } } diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt index 7afc4ae..f89d902 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt @@ -583,9 +583,9 @@ fun Float.normalize(inMin: Float, inMax: Float, outMin: Float, outMax: Float): F } fun CustomButtonEntity.execute() { - MPVLib.command(arrayOf("script-message", "call_button$id")) + MPVLib.command(arrayOf("script-message", "call_button_$id")) } fun CustomButtonEntity.executeLongClick() { - MPVLib.command(arrayOf("script-message", "call_button${id}long")) + MPVLib.command(arrayOf("script-message", "call_button_${id}_long")) } From 6c747342b819c3c1c2e3021a959d8574bbffc845 Mon Sep 17 00:00:00 2001 From: Secozzi Date: Wed, 27 Nov 2024 22:58:15 +0100 Subject: [PATCH 2/2] Move documentation to /docs and change into rst --- CUSTOMBUTTONS.md | 43 ----------------- .../ui/custombuttons/CustomButtonsScreen.kt | 2 +- docs/CUSTOMBUTTONS.rst | 46 +++++++++++++++++++ 3 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 CUSTOMBUTTONS.md create mode 100644 docs/CUSTOMBUTTONS.rst diff --git a/CUSTOMBUTTONS.md b/CUSTOMBUTTONS.md deleted file mode 100644 index 794ce80..0000000 --- a/CUSTOMBUTTONS.md +++ /dev/null @@ -1,43 +0,0 @@ -# CUSTOM BUTTONS - -Custom buttons provides a way to execute lua code by pressing a button in the player. mpvKt also provides an interface to interact with some parts of the player. - -The interface is defined in a file placed in the `scripts` directory and can be accessed through the `mpvkt` table. - -## Lua interface - -### `mpvkt.show_text(text)` -Display a message on the player. - -### `mpvkt.hide_ui()` -Hide the player UI. - -### `mpvkt.show_ui()` -Show the player UI. - -### `mpvkt.toggle_ui()` -Toggle the visibility of the player UI. - -### `mpvkt.show_subtitle_settings()` -Show the subtitle settings sheet. - -### `mpvkt.show_subtitle_delay()` -Show the subtitle delay sheet. - -### `mpvkt.show_audio_delay()` -Show the subtitle delay sheet. - -### `mpvkt.show_video_filters()` -Show the video filters sheet. - -### `mpvkt.set_button_title(text)` -Change the title for the primary custom button. - -### `mpvkt.reset_button_title(text)` -Reset the title for the primary custom button. - -## Call a custom button from key input or from lua - -Custom buttons can be called from key inputs or from other lua scripts, if so desired. This is done through `script-message` with the message `call_button_` for normal press and `call_button__long` for long press, where `` is the id for the button (shown in top right when editing a button). - -Example: `a script-message call_button_1` will call the button of id 1 when `a` is pressed, if added to `input.conf`. \ No newline at end of file diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt b/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt index 026659b..4a899c6 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/custombuttons/CustomButtonsScreen.kt @@ -86,4 +86,4 @@ sealed interface CustomButtonDialog { data class Delete(val customButton: CustomButtonEntity) : CustomButtonDialog } -private const val CUSTOM_BUTTONS_DOC_URL = "https://github.com/abdallahmehiz/mpvKt/blob/main/CUSTOMBUTTONS.md" +private const val CUSTOM_BUTTONS_DOC_URL = "https://github.com/abdallahmehiz/mpvKt/blob/main/docs/CUSTOMBUTTONS.rst" diff --git a/docs/CUSTOMBUTTONS.rst b/docs/CUSTOMBUTTONS.rst new file mode 100644 index 0000000..0854108 --- /dev/null +++ b/docs/CUSTOMBUTTONS.rst @@ -0,0 +1,46 @@ +CUSTOM BUTTONS +============== + +Custom buttons provides a way to execute lua code by pressing a button in the player. mpvKt also provides an interface to interact with some parts of the player. + +The interface is defined in a file placed in the ``scripts`` directory and can be accessed through the ``mpvkt`` table. + +Lua interface +------------- + +``mpvkt.show_text(text)`` + Display a message on the player. + +``mpvkt.hide_ui()`` + Hide the player UI. + +``mpvkt.show_ui()`` + Show the player UI. + +``mpvkt.toggle_ui()`` + Toggle the visibility of the player UI. + +``mpvkt.show_subtitle_settings()`` + Show the subtitle settings sheet. + +``mpvkt.show_subtitle_delay()`` + Show the subtitle delay sheet. + +``mpvkt.show_audio_delay()`` + Show the subtitle delay sheet. + +``mpvkt.show_video_filters()`` + Show the video filters sheet. + +``mpvkt.set_button_title(text)`` + Change the title for the primary custom button. + +``mpvkt.reset_button_title(text)`` + Reset the title for the primary custom button. + +Call a custom button from key input or from lua +----------------------------------------------- + +Custom buttons can be called from key inputs or from other lua scripts, if so desired. This is done through ``script-message`` with the message ``call_button_`` for normal press and ``call_button__long`` for long press, where ```` is the id for the button (shown in top right when editing a button). + +Example: ``a script-message call_button_1`` will call the button of id 1 when ``a`` is pressed, if added to ``input.conf``.