diff --git a/app/src/main/java/chat/revolt/components/chat/specialembeds/AppleMusicEmbed.kt b/app/src/main/java/chat/revolt/components/chat/specialembeds/AppleMusicEmbed.kt new file mode 100644 index 00000000..8c765071 --- /dev/null +++ b/app/src/main/java/chat/revolt/components/chat/specialembeds/AppleMusicEmbed.kt @@ -0,0 +1,56 @@ +package chat.revolt.components.chat.specialembeds + +import android.annotation.SuppressLint +import android.net.Uri +import android.webkit.WebView +import androidx.compose.foundation.layout.requiredHeight +import androidx.compose.foundation.layout.width +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.unit.dp +import androidx.compose.ui.viewinterop.AndroidView +import chat.revolt.api.schemas.Special +import chat.revolt.api.settings.GlobalState +import chat.revolt.ui.theme.isThemeDark + +@SuppressLint("SetJavaScriptEnabled") +@Composable +fun AppleMusicEmbed(special: Special, modifier: Modifier = Modifier) { + val useDarkTheme = isThemeDark(GlobalState.theme) + + AndroidView( + factory = { ctx -> + WebView(ctx).apply { + settings.apply { + javaScriptEnabled = true + mediaPlaybackRequiresUserGesture = false + javaScriptCanOpenWindowsAutomatically = true + builtInZoomControls = false + loadWithOverviewMode = true + useWideViewPort = true + displayZoomControls = false + setSupportZoom(false) + isVerticalScrollBarEnabled = false + isHorizontalScrollBarEnabled = false + } + } + }, + update = { + val embedUrl = Uri.Builder().apply { + scheme("https") + authority("embed.music.apple.com") + appendPath("album") + appendPath("") + appendPath(special.albumID) + appendQueryParameter("theme", if (useDarkTheme) "dark" else "light") + } + it.loadUrl(embedUrl.toString()) + }, + modifier = modifier + .clip(MaterialTheme.shapes.medium) + .width(400.dp) + .requiredHeight(450.dp) + ) +} \ No newline at end of file diff --git a/app/src/main/java/chat/revolt/components/chat/specialembeds/SpecialEmbedSwitch.kt b/app/src/main/java/chat/revolt/components/chat/specialembeds/SpecialEmbedSwitch.kt index 06e08e52..20320b14 100644 --- a/app/src/main/java/chat/revolt/components/chat/specialembeds/SpecialEmbedSwitch.kt +++ b/app/src/main/java/chat/revolt/components/chat/specialembeds/SpecialEmbedSwitch.kt @@ -8,6 +8,7 @@ import chat.revolt.api.schemas.Special fun SpecialEmbedSwitch(special: Special, modifier: Modifier = Modifier) { when (special.type) { "YouTube" -> YoutubeEmbedSwitch(special, modifier) + "AppleMusic" -> AppleMusicEmbed(special, modifier) else -> {} } } \ No newline at end of file