From 5c2dc9c28eb1a7fd7008c23fe872f81f77c10091 Mon Sep 17 00:00:00 2001 From: aidewoode Date: Thu, 21 Mar 2024 14:15:40 +0800 Subject: [PATCH] Add remaining android bridge functions --- .../controllers/flash_bridge_controller.js | 2 +- app/javascript/native_bridge.js | 20 +++++++++++++++++++ app/views/albums/show.html.erb | 2 +- .../favorite_playlist/songs/index.html.erb | 2 +- app/views/playlists/songs/index.html.erb | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/javascript/controllers/flash_bridge_controller.js b/app/javascript/controllers/flash_bridge_controller.js index 32125c7c..78487cfb 100644 --- a/app/javascript/controllers/flash_bridge_controller.js +++ b/app/javascript/controllers/flash_bridge_controller.js @@ -7,6 +7,6 @@ export default class extends Controller { } connect () { - App.nativeBridge.showFlashMessage(this.element.textContent) + App.nativeBridge.showFlashMessage(this.element.textContent.trim()) } } diff --git a/app/javascript/native_bridge.js b/app/javascript/native_bridge.js index 5bce0d83..3a9c9752 100644 --- a/app/javascript/native_bridge.js +++ b/app/javascript/native_bridge.js @@ -9,6 +9,10 @@ class NativeBridge { resourceId: Number(resourceId) }) } + + if (isAndroidApp()) { + window.NativeBridge.playAll(resourceType, Number(resourceId)) + } } playSong (songId) { @@ -18,6 +22,10 @@ class NativeBridge { songId: Number(songId) }) } + + if (isAndroidApp()) { + window.NativeBridge.playSong(Number(songId)) + } } playNext (songId) { @@ -27,6 +35,10 @@ class NativeBridge { songId: Number(songId) }) } + + if (isAndroidApp()) { + window.NativeBridge.playNext(Number(songId)) + } } playLast (songId) { @@ -36,6 +48,10 @@ class NativeBridge { songId: Number(songId) }) } + + if (isAndroidApp()) { + window.NativeBridge.playLast(Number(songId)) + } } search (query) { @@ -62,6 +78,10 @@ class NativeBridge { message }) } + + if (isAndroidApp()) { + window.NativeBridge.showFlashMessage(message) + } } } diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index c267b817..cd1aa43b 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -23,7 +23,7 @@ "disabled-on-native" => "true", "turbo-frame" => "turbo-playlist", "action" => "playlist-songs-bridge#playAll", - "playlist-songs-bridge-resource-type-param" => "albums", + "playlist-songs-bridge-resource-type-param" => "album", "playlist-songs-bridge-resource-id-param" => @album.id } } diff --git a/app/views/favorite_playlist/songs/index.html.erb b/app/views/favorite_playlist/songs/index.html.erb index 2bfdec6f..eab17eb1 100644 --- a/app/views/favorite_playlist/songs/index.html.erb +++ b/app/views/favorite_playlist/songs/index.html.erb @@ -22,7 +22,7 @@ "disabled-on-native" => "true", "turbo-frame" => "turbo-playlist", "action" => "playlist-songs-bridge#playAll", - "playlist-songs-bridge-resource-type-param" => "playlists", + "playlist-songs-bridge-resource-type-param" => "playlist", "playlist-songs-bridge-resource-id-param" => @playlist.id } } diff --git a/app/views/playlists/songs/index.html.erb b/app/views/playlists/songs/index.html.erb index c9e76fc0..6733c230 100644 --- a/app/views/playlists/songs/index.html.erb +++ b/app/views/playlists/songs/index.html.erb @@ -24,7 +24,7 @@ "disabled-on-native" => "true", "turbo-frame" => "turbo-playlist", "action" => "playlist-songs-bridge#playAll", - "playlist-songs-bridge-resource-type-param" => "playlists", + "playlist-songs-bridge-resource-type-param" => "playlist", "playlist-songs-bridge-resource-id-param" => @playlist.id } }