kotlin based android app
This commit is contained in:
parent
bc09479dfb
commit
25d37ec9dd
|
|
@ -0,0 +1,5 @@
|
|||
.gradle/
|
||||
build/
|
||||
app/build/
|
||||
local.properties
|
||||
*.iml
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
# Blastoise Native Android Design Brief
|
||||
|
||||
Design direction: broadcast-console music app, not generic AI dashboard.
|
||||
|
||||
## Principles
|
||||
|
||||
- Put the listening task first: current channel, current track, transport, progress, channel switcher, and queue preview must stay visible on the main screen.
|
||||
- Use explicit states: connected, loading, disconnected, guest session, drift, buffering, and playback state are visible without opening logs.
|
||||
- Avoid generic AI decoration: no random blobs, ornamental gradients, nested cards, oversized empty hero areas, or decorative metrics.
|
||||
- Keep controls direct and tactile: large touch targets, clear labels, predictable placement, no hidden primary actions.
|
||||
- Keep diagnostics subordinate: useful for development, but visually quieter than playback.
|
||||
|
||||
## Theme
|
||||
|
||||
- Personality: late-night radio console, compact and technical.
|
||||
- Display/body font: Rajdhani.
|
||||
- Diagnostics font: JetBrains Mono.
|
||||
- Background: near-black.
|
||||
- Surfaces: layered blue-black panels.
|
||||
- Accents: safety orange for primary actions, level-meter green for live sync, brass for warnings/session state, restrained red for failures.
|
||||
- Avoid blue, cyan, and purple as dominant interface colors.
|
||||
- Corners: squared receiver hardware. Use small 2-4dp radii, never bubbly cards.
|
||||
|
||||
## Layout
|
||||
|
||||
- Header: app identity plus connection status.
|
||||
- Server row: compact editable endpoint and reconnect action.
|
||||
- Mode switch: RADIO and LIBRARY are first-class modes.
|
||||
- Main deck: station/library identity, track title, progress, transport, session/sync health.
|
||||
- Transport controls: use a real player strip with previous, seek back, large play/pause, seek forward, and next. Avoid generic equal-width text buttons for playback.
|
||||
- Radio channels: station cards that feel like playlists/radio rooms the user can join.
|
||||
- Library: dense track rows for direct local-style MP3 playback from the server library.
|
||||
- Queue: next few tracks for Radio mode, not the whole library.
|
||||
- Diagnostics: compact, monospaced, last few events.
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
# Blastoise Native Android
|
||||
|
||||
Native Kotlin listener app for the Blastoise/MusicRoom server.
|
||||
|
||||
## Build
|
||||
|
||||
From this directory:
|
||||
|
||||
```bat
|
||||
gradlew.bat :app:assembleDebug
|
||||
```
|
||||
|
||||
The debug APK is written to:
|
||||
|
||||
```text
|
||||
app\build\outputs\apk\debug\app-debug.apk
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
Use the root Android helper:
|
||||
|
||||
```bat
|
||||
..\run.bat
|
||||
```
|
||||
|
||||
Or install manually:
|
||||
|
||||
```bat
|
||||
gradlew.bat :app:installDebug
|
||||
adb shell am start -n com.peterino.blastoise/.MainActivity
|
||||
```
|
||||
|
||||
## MVP scope
|
||||
|
||||
- Defaults to `http://mhsgroove.peterino.com:3001` and auto-connects on launch.
|
||||
- Saves a server URL locally.
|
||||
- Uses `/api/channels` to establish an authenticated or guest session.
|
||||
- Supports `/api/auth/login` for named users.
|
||||
- Connects to `/api/channels/:id/ws`.
|
||||
- Plays `/api/tracks/:id` through AndroidX Media3.
|
||||
- Corrects playback drift when the server timestamp differs by 2 seconds or more.
|
||||
- Shows channel switching, queue preview, sync health, drift, session state, and recent WebSocket events on the main screen.
|
||||
|
||||
Offline track caching is intentionally not included yet.
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
plugins {
|
||||
id("com.android.application")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.peterino.blastoise"
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.peterino.blastoise"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "0.1.0"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val media3Version = "1.10.1"
|
||||
|
||||
implementation("androidx.media3:media3-exoplayer:$media3Version")
|
||||
implementation("androidx.media3:media3-session:$media3Version")
|
||||
implementation("androidx.media3:media3-common:$media3Version")
|
||||
implementation("com.squareup.okhttp3:okhttp:5.3.0")
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".PlaybackService"
|
||||
android:exported="true"
|
||||
android:foregroundServiceType="mediaPlayback">
|
||||
<intent-filter>
|
||||
<action android:name="androidx.media3.session.MediaSessionService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,117 @@
|
|||
package com.peterino.blastoise
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
data class Track(
|
||||
val id: String,
|
||||
val filename: String,
|
||||
val title: String,
|
||||
val duration: Double,
|
||||
)
|
||||
|
||||
data class ChannelInfo(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val description: String,
|
||||
val listenerCount: Int,
|
||||
val isDefault: Boolean,
|
||||
)
|
||||
|
||||
data class ChannelState(
|
||||
val track: Track?,
|
||||
val currentTimestamp: Double,
|
||||
val channelName: String,
|
||||
val channelId: String,
|
||||
val paused: Boolean,
|
||||
val queue: List<Track>?,
|
||||
val currentIndex: Int,
|
||||
val playbackMode: String,
|
||||
)
|
||||
|
||||
data class Playlist(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val description: String,
|
||||
val ownerId: Int,
|
||||
val ownerName: String,
|
||||
val isPublic: Boolean,
|
||||
val shareToken: String?,
|
||||
val trackIds: List<String>,
|
||||
)
|
||||
|
||||
data class PlaylistBundle(
|
||||
val mine: List<Playlist>,
|
||||
val shared: List<Playlist>,
|
||||
)
|
||||
|
||||
fun JSONObject.toTrack(): Track {
|
||||
return Track(
|
||||
id = optString("id", optString("filename")),
|
||||
filename = optString("filename"),
|
||||
title = optString("title", optString("filename", "Unknown")),
|
||||
duration = optDouble("duration", 0.0),
|
||||
)
|
||||
}
|
||||
|
||||
fun JSONObject.toChannelInfo(): ChannelInfo {
|
||||
return ChannelInfo(
|
||||
id = getString("id"),
|
||||
name = optString("name", "Channel"),
|
||||
description = optString("description", ""),
|
||||
listenerCount = optInt("listenerCount", 0),
|
||||
isDefault = optBoolean("isDefault", false),
|
||||
)
|
||||
}
|
||||
|
||||
fun JSONObject.toChannelState(): ChannelState {
|
||||
val trackJson = optJSONObject("track")
|
||||
val queueJson = optJSONArray("queue")
|
||||
val queue = if (queueJson == null) {
|
||||
null
|
||||
} else {
|
||||
(0 until queueJson.length()).map { queueJson.getJSONObject(it).toTrack() }
|
||||
}
|
||||
|
||||
return ChannelState(
|
||||
track = trackJson?.toTrack(),
|
||||
currentTimestamp = optDouble("currentTimestamp", 0.0),
|
||||
channelName = optString("channelName", ""),
|
||||
channelId = optString("channelId", ""),
|
||||
paused = optBoolean("paused", true),
|
||||
queue = queue,
|
||||
currentIndex = optInt("currentIndex", 0),
|
||||
playbackMode = optString("playbackMode", "repeat-all"),
|
||||
)
|
||||
}
|
||||
|
||||
fun JSONObject.toPlaylist(): Playlist {
|
||||
return Playlist(
|
||||
id = getString("id"),
|
||||
name = optString("name", "Playlist"),
|
||||
description = optString("description", ""),
|
||||
ownerId = optInt("ownerId", 0),
|
||||
ownerName = optString("ownerName", ""),
|
||||
isPublic = optBoolean("isPublic", false),
|
||||
shareToken = if (isNull("shareToken")) null else getString("shareToken"),
|
||||
trackIds = optJSONArray("trackIds").toStringList(),
|
||||
)
|
||||
}
|
||||
|
||||
fun JSONArray.toChannels(): List<ChannelInfo> {
|
||||
return (0 until length()).map { getJSONObject(it).toChannelInfo() }
|
||||
}
|
||||
|
||||
fun JSONArray.toTracks(): List<Track> {
|
||||
return (0 until length()).map { getJSONObject(it).toTrack() }
|
||||
}
|
||||
|
||||
fun JSONArray?.toPlaylists(): List<Playlist> {
|
||||
if (this == null) return emptyList()
|
||||
return (0 until length()).map { getJSONObject(it).toPlaylist() }
|
||||
}
|
||||
|
||||
fun JSONArray?.toStringList(): List<String> {
|
||||
if (this == null) return emptyList()
|
||||
return (0 until length()).mapNotNull { optString(it).takeIf(String::isNotBlank) }
|
||||
}
|
||||
|
|
@ -0,0 +1,373 @@
|
|||
package com.peterino.blastoise
|
||||
|
||||
import android.content.Context
|
||||
import okhttp3.Call
|
||||
import okhttp3.Callback
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.Response
|
||||
import okhttp3.WebSocket
|
||||
import okhttp3.WebSocketListener
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class MusicRoomClient(
|
||||
private val context: Context,
|
||||
private val listener: Listener,
|
||||
) {
|
||||
interface Listener {
|
||||
fun onStatus(message: String)
|
||||
fun onDebug(message: String)
|
||||
fun onChannels(channels: List<ChannelInfo>)
|
||||
fun onLibrary(tracks: List<Track>)
|
||||
fun onPlaylists(playlists: PlaylistBundle)
|
||||
fun onPlaylistDetail(playlist: Playlist)
|
||||
fun onChannelState(state: ChannelState)
|
||||
fun onSwitched(channelId: String)
|
||||
fun onError(message: String)
|
||||
}
|
||||
|
||||
private val client = OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(0, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
private var socket: WebSocket? = null
|
||||
|
||||
fun close() {
|
||||
socket?.close(1000, "closing")
|
||||
socket = null
|
||||
}
|
||||
|
||||
fun login(username: String, password: String) {
|
||||
listener.onDebug("POST /api/auth/login")
|
||||
val body = JSONObject()
|
||||
.put("username", username)
|
||||
.put("password", password)
|
||||
.toString()
|
||||
.toRequestBody("application/json".toMediaType())
|
||||
|
||||
val request = request("/api/auth/login")
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("login failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Login failed: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
captureCookie(it)
|
||||
listener.onDebug("login HTTP ${it.code}; cookie=${SessionStore.cookieHeader.isNotBlank()}")
|
||||
if (!it.isSuccessful) {
|
||||
listener.onError("Login failed: HTTP ${it.code}")
|
||||
return
|
||||
}
|
||||
SessionStore.save(context)
|
||||
listener.onStatus("Signed in")
|
||||
loadChannels()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun loadChannels() {
|
||||
listener.onDebug("GET /api/channels ${SessionStore.serverBaseUrl}")
|
||||
val request = request("/api/channels").build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("channels failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Could not load channels: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
captureCookie(it)
|
||||
SessionStore.save(context)
|
||||
listener.onDebug("channels HTTP ${it.code}; cookie=${SessionStore.cookieHeader.isNotBlank()}")
|
||||
if (!it.isSuccessful) {
|
||||
listener.onError("Could not load channels: HTTP ${it.code}")
|
||||
return
|
||||
}
|
||||
val json = it.body.string()
|
||||
val channels = JSONArray(json).toChannels()
|
||||
listener.onDebug("channels parsed: ${channels.size}")
|
||||
listener.onChannels(channels)
|
||||
listener.onStatus("Loaded ${channels.size} channel(s)")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun loadLibrary() {
|
||||
listener.onDebug("GET /api/library")
|
||||
val request = request("/api/library").build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("library failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Could not load library: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
captureCookie(it)
|
||||
SessionStore.save(context)
|
||||
listener.onDebug("library HTTP ${it.code}; cookie=${SessionStore.cookieHeader.isNotBlank()}")
|
||||
if (!it.isSuccessful) {
|
||||
listener.onError("Could not load library: HTTP ${it.code}")
|
||||
return
|
||||
}
|
||||
val tracks = JSONArray(it.body.string()).toTracks()
|
||||
listener.onDebug("library parsed: ${tracks.size}")
|
||||
listener.onLibrary(tracks)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun loadPlaylists() {
|
||||
listener.onDebug("GET /api/playlists")
|
||||
val request = request("/api/playlists").build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("playlists failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Could not load playlists: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
captureCookie(it)
|
||||
SessionStore.save(context)
|
||||
listener.onDebug("playlists HTTP ${it.code}; cookie=${SessionStore.cookieHeader.isNotBlank()}")
|
||||
if (!it.isSuccessful) {
|
||||
listener.onError("Could not load playlists: HTTP ${it.code}")
|
||||
return
|
||||
}
|
||||
val json = JSONObject(it.body.string())
|
||||
val bundle = PlaylistBundle(
|
||||
mine = json.optJSONArray("mine").toPlaylists(),
|
||||
shared = json.optJSONArray("shared").toPlaylists(),
|
||||
)
|
||||
listener.onDebug("playlists parsed: mine=${bundle.mine.size} shared=${bundle.shared.size}")
|
||||
listener.onPlaylists(bundle)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun loadPlaylist(playlistId: String) {
|
||||
listener.onDebug("GET /api/playlists/$playlistId")
|
||||
val request = request("/api/playlists/$playlistId").build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("playlist detail failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Could not load playlist: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
captureCookie(it)
|
||||
SessionStore.save(context)
|
||||
listener.onDebug("playlist detail HTTP ${it.code}")
|
||||
if (!it.isSuccessful) {
|
||||
listener.onError("Could not load playlist: HTTP ${it.code}")
|
||||
return
|
||||
}
|
||||
listener.onPlaylistDetail(JSONObject(it.body.string()).toPlaylist())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun connectChannel(channelId: String) {
|
||||
socket?.close(1000, "switching")
|
||||
listener.onDebug("WS connecting channel=$channelId")
|
||||
val builder = Request.Builder()
|
||||
.url(SessionStore.wsUrl(channelId))
|
||||
.header("User-Agent", SessionStore.userAgent)
|
||||
if (SessionStore.cookieHeader.isNotBlank()) {
|
||||
builder.header("Cookie", SessionStore.cookieHeader)
|
||||
}
|
||||
|
||||
socket = client.newWebSocket(builder.build(), object : WebSocketListener() {
|
||||
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||
listener.onDebug("WS open HTTP ${response.code}")
|
||||
listener.onStatus("Connected")
|
||||
loadChannelState(channelId)
|
||||
}
|
||||
|
||||
override fun onMessage(webSocket: WebSocket, text: String) {
|
||||
handleSocketMessage(text)
|
||||
}
|
||||
|
||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||
listener.onDebug("WS failure ${response?.code ?: "-"}: ${t.message ?: "websocket error"}")
|
||||
listener.onError("Disconnected: ${t.message ?: "websocket error"}")
|
||||
}
|
||||
|
||||
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
|
||||
listener.onDebug("WS closed $code $reason")
|
||||
listener.onStatus("Disconnected")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun sendAction(action: String) {
|
||||
listener.onDebug("WS send action=$action")
|
||||
socket?.send(JSONObject().put("action", action).toString())
|
||||
}
|
||||
|
||||
fun sendSeek(timestamp: Double) {
|
||||
listener.onDebug("WS send seek=${"%.1f".format(timestamp)}")
|
||||
socket?.send(
|
||||
JSONObject()
|
||||
.put("action", "seek")
|
||||
.put("timestamp", timestamp)
|
||||
.toString()
|
||||
)
|
||||
}
|
||||
|
||||
fun sendJump(index: Int) {
|
||||
listener.onDebug("WS send jump=$index")
|
||||
socket?.send(
|
||||
JSONObject()
|
||||
.put("action", "jump")
|
||||
.put("index", index)
|
||||
.toString()
|
||||
)
|
||||
}
|
||||
|
||||
fun setPlaybackMode(channelId: String, mode: String) {
|
||||
listener.onDebug("POST /api/channels/$channelId/mode $mode")
|
||||
val body = JSONObject()
|
||||
.put("mode", mode)
|
||||
.toString()
|
||||
.toRequestBody("application/json".toMediaType())
|
||||
val request = request("/api/channels/$channelId/mode")
|
||||
.post(body)
|
||||
.build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("mode failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Mode failed: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
listener.onDebug("mode HTTP ${it.code}")
|
||||
if (it.code == 403) {
|
||||
listener.onError("Mode denied")
|
||||
} else if (!it.isSuccessful) {
|
||||
listener.onError("Mode failed: HTTP ${it.code}")
|
||||
} else {
|
||||
listener.onStatus("Mode set")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun addTracksToQueue(channelId: String, trackIds: List<String>, insertAt: Int? = null) {
|
||||
if (trackIds.isEmpty()) return
|
||||
val insertLabel = insertAt?.let { " insertAt=$it" } ?: ""
|
||||
listener.onDebug("PATCH /api/channels/$channelId/queue add=${trackIds.size}$insertLabel")
|
||||
val bodyJson = JSONObject().put("add", JSONArray(trackIds))
|
||||
if (insertAt != null) bodyJson.put("insertAt", insertAt)
|
||||
val request = request("/api/channels/$channelId/queue")
|
||||
.patch(bodyJson.toString().toRequestBody("application/json".toMediaType()))
|
||||
.build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("queue add failure: ${e.message ?: "network error"}")
|
||||
listener.onError("Queue failed: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
listener.onDebug("queue add HTTP ${it.code}")
|
||||
if (it.code == 403) {
|
||||
listener.onError("Queue denied")
|
||||
} else if (!it.isSuccessful) {
|
||||
listener.onError("Queue failed: HTTP ${it.code}")
|
||||
} else {
|
||||
listener.onStatus(if (insertAt == null) "Queued ${trackIds.size}" else "Play next queued")
|
||||
currentChannelFromQueuePatch(channelId)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadChannelState(channelId: String) {
|
||||
listener.onDebug("GET /api/channels/$channelId")
|
||||
val request = request("/api/channels/$channelId").build()
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
listener.onDebug("channel state failure: ${e.message ?: "network error"}")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
if (!it.isSuccessful) {
|
||||
listener.onDebug("channel state HTTP ${it.code}")
|
||||
return
|
||||
}
|
||||
val json = JSONObject(it.body.string())
|
||||
listener.onDebug("channel state HTTP ${it.code}; queue=${json.optJSONArray("queue")?.length() ?: 0}")
|
||||
listener.onChannelState(json.toChannelState())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun currentChannelFromQueuePatch(channelId: String) {
|
||||
loadChannelState(channelId)
|
||||
loadChannels()
|
||||
}
|
||||
|
||||
private fun handleSocketMessage(text: String) {
|
||||
val json = JSONObject(text)
|
||||
val type = json.optString("type", "")
|
||||
val summary = when {
|
||||
type.isNotBlank() -> "type=$type"
|
||||
json.has("track") -> "state track=${json.optJSONObject("track")?.optString("title", "unknown") ?: "none"}"
|
||||
else -> "state"
|
||||
}
|
||||
listener.onDebug("WS message $summary")
|
||||
|
||||
when (type) {
|
||||
"" -> listener.onChannelState(json.toChannelState())
|
||||
"channel_list" -> {
|
||||
val channels = json.optJSONArray("channels")?.toChannels().orEmpty()
|
||||
listener.onChannels(channels)
|
||||
}
|
||||
"switched" -> listener.onSwitched(json.optString("channelId"))
|
||||
"kick" -> listener.onError("Disconnected: ${json.optString("reason", "kicked")}")
|
||||
"error" -> listener.onError(json.optString("message", "Server error"))
|
||||
else -> listener.onDebug("ignored server event type=$type")
|
||||
}
|
||||
}
|
||||
|
||||
private fun request(path: String): Request.Builder {
|
||||
val builder = Request.Builder()
|
||||
.url(SessionStore.httpUrl(path))
|
||||
.header("User-Agent", SessionStore.userAgent)
|
||||
if (SessionStore.cookieHeader.isNotBlank()) {
|
||||
builder.header("Cookie", SessionStore.cookieHeader)
|
||||
}
|
||||
return builder
|
||||
}
|
||||
|
||||
private fun captureCookie(response: Response) {
|
||||
response.headers("Set-Cookie")
|
||||
.map { it.substringBefore(";") }
|
||||
.firstOrNull { it.startsWith("blastoise_session=") }
|
||||
?.let { SessionStore.cookieHeader = it }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.peterino.blastoise
|
||||
|
||||
import androidx.media3.common.AudioAttributes
|
||||
import androidx.media3.common.C
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.datasource.DataSource
|
||||
import androidx.media3.datasource.DefaultHttpDataSource
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
|
||||
import androidx.media3.session.MediaSession
|
||||
import androidx.media3.session.MediaSessionService
|
||||
|
||||
@UnstableApi
|
||||
class PlaybackService : MediaSessionService() {
|
||||
private var mediaSession: MediaSession? = null
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
val httpDataSourceFactory = DataSource.Factory {
|
||||
val requestProperties = mutableMapOf<String, String>()
|
||||
if (SessionStore.cookieHeader.isNotBlank()) {
|
||||
requestProperties["Cookie"] = SessionStore.cookieHeader
|
||||
}
|
||||
|
||||
DefaultHttpDataSource.Factory()
|
||||
.setUserAgent(SessionStore.userAgent)
|
||||
.setAllowCrossProtocolRedirects(true)
|
||||
.setDefaultRequestProperties(requestProperties)
|
||||
.createDataSource()
|
||||
}
|
||||
|
||||
val mediaSourceFactory = DefaultMediaSourceFactory(this)
|
||||
.setDataSourceFactory(httpDataSourceFactory)
|
||||
|
||||
val audioAttributes = AudioAttributes.Builder()
|
||||
.setContentType(C.AUDIO_CONTENT_TYPE_MUSIC)
|
||||
.setUsage(C.USAGE_MEDIA)
|
||||
.build()
|
||||
|
||||
val player = ExoPlayer.Builder(this)
|
||||
.setMediaSourceFactory(mediaSourceFactory)
|
||||
.setAudioAttributes(audioAttributes, true)
|
||||
.setHandleAudioBecomingNoisy(true)
|
||||
.build()
|
||||
|
||||
mediaSession = MediaSession.Builder(this, player).build()
|
||||
}
|
||||
|
||||
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession? {
|
||||
return mediaSession
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
mediaSession?.run {
|
||||
player.release()
|
||||
release()
|
||||
}
|
||||
mediaSession = null
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.peterino.blastoise
|
||||
|
||||
import android.content.Context
|
||||
import java.net.URI
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
object SessionStore {
|
||||
const val defaultServerBaseUrl = "http://mhsgroove.peterino.com:3001"
|
||||
const val userAgent = "BlastoiseAndroid/0.1"
|
||||
|
||||
@Volatile
|
||||
var serverBaseUrl: String = defaultServerBaseUrl
|
||||
|
||||
@Volatile
|
||||
var cookieHeader: String = ""
|
||||
|
||||
fun load(context: Context) {
|
||||
val prefs = context.getSharedPreferences("blastoise", Context.MODE_PRIVATE)
|
||||
serverBaseUrl = prefs.getString("serverBaseUrl", defaultServerBaseUrl) ?: defaultServerBaseUrl
|
||||
if (serverBaseUrl.isBlank()) {
|
||||
serverBaseUrl = defaultServerBaseUrl
|
||||
}
|
||||
cookieHeader = prefs.getString("cookieHeader", "") ?: ""
|
||||
}
|
||||
|
||||
fun save(context: Context) {
|
||||
context.getSharedPreferences("blastoise", Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putString("serverBaseUrl", serverBaseUrl)
|
||||
.putString("cookieHeader", cookieHeader)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun setBaseUrl(input: String) {
|
||||
val trimmed = input.trim().trimEnd('/')
|
||||
serverBaseUrl = when {
|
||||
trimmed.isEmpty() -> defaultServerBaseUrl
|
||||
trimmed.startsWith("http://") || trimmed.startsWith("https://") -> trimmed
|
||||
else -> "http://$trimmed"
|
||||
}
|
||||
}
|
||||
|
||||
fun httpUrl(path: String): String {
|
||||
return serverBaseUrl.trimEnd('/') + path
|
||||
}
|
||||
|
||||
fun wsUrl(channelId: String): String {
|
||||
val uri = URI(serverBaseUrl)
|
||||
val scheme = if (uri.scheme == "https") "wss" else "ws"
|
||||
val authority = uri.rawAuthority
|
||||
return "$scheme://$authority/api/channels/${encodePath(channelId)}/ws"
|
||||
}
|
||||
|
||||
fun trackUrl(trackId: String): String {
|
||||
return httpUrl("/api/tracks/${encodePath(trackId)}")
|
||||
}
|
||||
|
||||
private fun encodePath(value: String): String {
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()).replace("+", "%20")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M10,4l2,2h8v14H4V4h6zM6,8v10h12V8H6zM14,10v4.6c0,1.32 -1.08,2.4 -2.4,2.4S9.2,15.92 9.2,14.6s1.08,-2.4 2.4,-2.4c0.35,0 0.69,0.08 1,0.22V10h1.4z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M6,5h4v14H6V5zM14,5h4v14h-4V5z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M8,5v14l11,-7L8,5z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M4,5h9v2H4V5zM4,9h9v2H4V9zM4,13h6v2H4v-2zM15,8l6,4 -6,4v-3h-3v-2h3V8z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M4,5h12v2H4V5zM4,10h12v2H4v-2zM4,15h8v2H4v-2zM17,14l5,3 -5,3v-6z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M3,5h12v2H3V5zM3,10h12v2H3v-2zM3,15h8v2H3v-2zM18,11v3h3v2h-3v3h-2v-3h-3v-2h3v-3h2z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M3.2,6.2L2.4,4.4 12,1l9.6,3.4 -0.8,1.8L12,3.1 3.2,6.2zM4,8h16v12H4V8zM6,10v8h12v-8H6zM8,12h5v2H8v-2zM8,15h8v2H8v-2z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M7,7h11v3l4,-4 -4,-4v3H5v6h2V7zM17,17H6v-3l-4,4 4,4v-3h13v-6h-2v4z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M11,6V3L5,8l6,5V9c3.31,0 6,2.69 6,6 0,1.3 -0.41,2.5 -1.12,3.48l1.5,1.5C18.39,18.62 19,16.9 19,15c0,-4.97 -4.03,-9 -8,-9zM8.8,16H7v-3.2l-0.9,0.7 -0.8,-1.1 2,-1.4h1.5v5zM14.2,12.5h-2.4v0.9c0.28,-0.13 0.58,-0.2 0.95,-0.2 1.2,0 2,0.83 2,1.93 0,1.24 -0.93,2.07 -2.35,2.07 -1,0 -1.75,-0.33 -2.27,-0.98l1.03,-0.93c0.33,0.37 0.68,0.55 1.17,0.55 0.5,0 0.82,-0.28 0.82,-0.72 0,-0.45 -0.34,-0.72 -0.87,-0.72 -0.37,0 -0.68,0.12 -0.98,0.34l-0.95,-0.47 0.18,-3.05h3.67v1.28z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M13,6V3l6,5 -6,5V9c-3.31,0 -6,2.69 -6,6 0,1.3 0.41,2.5 1.12,3.48l-1.5,1.5C5.61,18.62 5,16.9 5,15c0,-4.97 4.03,-9 8,-9zM9.8,16H8v-3.2l-0.9,0.7 -0.8,-1.1 2,-1.4h1.5v5zM15.2,12.5h-2.4v0.9c0.28,-0.13 0.58,-0.2 0.95,-0.2 1.2,0 2,0.83 2,1.93 0,1.24 -0.93,2.07 -2.35,2.07 -1,0 -1.75,-0.33 -2.27,-0.98l1.03,-0.93c0.33,0.37 0.68,0.55 1.17,0.55 0.5,0 0.82,-0.28 0.82,-0.72 0,-0.45 -0.34,-0.72 -0.87,-0.72 -0.37,0 -0.68,0.12 -0.98,0.34l-0.95,-0.47 0.18,-3.05h3.67v1.28z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5V4h-5.5zM14.83,13.41l-1.41,1.41 3.13,3.13L14.5,20H20v-5.5l-2.04,2.04 -3.13,-3.13z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M18,6l-8.5,6L18,18V6zM6,6v12h2V6H6z" />
|
||||
</vector>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">Blastoise</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<resources>
|
||||
<style name="AppTheme" parent="@android:style/Theme.Material.NoActionBar">
|
||||
<item name="android:fontFamily">sans</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:statusBarColor">#101418</item>
|
||||
<item name="android:navigationBarColor">#101418</item>
|
||||
<item name="android:colorAccent">#58A6FF</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
plugins {
|
||||
id("com.android.application") version "9.2.0" apply false
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
android.useAndroidX=true
|
||||
android.nonTransitiveRClass=true
|
||||
Binary file not shown.
|
|
@ -0,0 +1,7 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
@ -0,0 +1,248 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
@REM Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
@REM
|
||||
@REM This source code is licensed under the MIT license found in the
|
||||
@REM LICENSE file in the root directory of this source tree.
|
||||
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "BlastoiseNative"
|
||||
include(":app")
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
@echo off
|
||||
|
||||
echo ============================================
|
||||
echo MusicRoom Android - Dev Setup
|
||||
echo Blastoise Native Android - Dev Setup
|
||||
echo Installs all prerequisites via Scoop
|
||||
echo ============================================
|
||||
echo.
|
||||
|
|
@ -35,16 +35,10 @@ echo Done.
|
|||
echo.
|
||||
|
||||
:: Step 3: Install tools
|
||||
echo [3/5] Installing Node.js, JDK 17, Android CLI tools, and Gradle...
|
||||
echo [3/5] Installing JDK 17 and Android CLI tools...
|
||||
echo This may take several minutes.
|
||||
echo.
|
||||
|
||||
call scoop install nodejs-lts
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Failed to install Node.js
|
||||
pause & exit /b 1
|
||||
)
|
||||
|
||||
call scoop install temurin17-jdk
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Failed to install JDK 17
|
||||
|
|
@ -57,12 +51,6 @@ if errorlevel 1 (
|
|||
pause & exit /b 1
|
||||
)
|
||||
|
||||
call scoop install gradle
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Failed to install Gradle
|
||||
pause & exit /b 1
|
||||
)
|
||||
|
||||
echo All tools installed.
|
||||
echo.
|
||||
|
||||
|
|
@ -117,8 +105,16 @@ if not exist "%SDKMANAGER%" (
|
|||
echo Accepting licenses...
|
||||
echo y | call "%SDKMANAGER%" --licenses >nul 2>&1
|
||||
|
||||
echo Installing platform-tools, android-34, build-tools-34...
|
||||
call "%SDKMANAGER%" "platform-tools" "platforms;android-34" "build-tools;34.0.0"
|
||||
echo Installing platform-tools, emulator, android-36, build-tools-36, and an API 36 system image...
|
||||
call "%SDKMANAGER%" "platform-tools" "emulator" "platforms;android-36" "build-tools;36.0.0" "system-images;android-36;google_apis;x86_64"
|
||||
echo Done.
|
||||
echo.
|
||||
|
||||
echo Creating CLI emulator if needed...
|
||||
avdmanager list avd | findstr "Medium_Phone_API_36" >nul
|
||||
if errorlevel 1 (
|
||||
echo no | avdmanager create avd -n Medium_Phone_API_36 -k "system-images;android-36;google_apis;x86_64" -d "medium_phone"
|
||||
)
|
||||
echo Done.
|
||||
echo.
|
||||
|
||||
|
|
@ -127,10 +123,10 @@ echo ============================================
|
|||
echo Setup complete!
|
||||
echo.
|
||||
echo Tools installed via Scoop:
|
||||
echo Node.js LTS, JDK 17, Android CLI, Gradle
|
||||
echo JDK 17, Android CLI
|
||||
echo.
|
||||
echo Android SDK installed headlessly:
|
||||
echo platform-tools, android-34, build-tools-34
|
||||
echo platform-tools, emulator, android-36, build-tools-36
|
||||
echo.
|
||||
echo Environment:
|
||||
echo JAVA_HOME = %JAVA_HOME%
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
@echo off
|
||||
|
||||
echo ============================================
|
||||
echo MusicRoom Android - Run App
|
||||
echo Blastoise Native Android - Run App
|
||||
echo ============================================
|
||||
echo.
|
||||
|
||||
|
|
@ -9,13 +9,14 @@ echo.
|
|||
set "PATH=%PATH%;%USERPROFILE%\scoop\shims"
|
||||
set "JAVA_HOME=%USERPROFILE%\scoop\apps\temurin17-jdk\current"
|
||||
set "ANDROID_HOME=%LOCALAPPDATA%\Android\Sdk"
|
||||
set "PATH=%PATH%;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\emulator"
|
||||
set "PATH=%PATH%;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\emulator;%ANDROID_HOME%\cmdline-tools\latest\bin"
|
||||
set "PROJECT_DIR=%~dp0BlastoiseNative"
|
||||
|
||||
:: Start emulator if not already running
|
||||
adb devices 2>nul | findstr "emulator" >nul
|
||||
if errorlevel 1 (
|
||||
echo Starting emulator...
|
||||
start "" "%ANDROID_HOME%\emulator\emulator.exe" -avd Medium_Phone_API_36.0
|
||||
start "" "%ANDROID_HOME%\emulator\emulator.exe" -avd Medium_Phone_API_36
|
||||
echo Waiting for emulator to boot...
|
||||
adb wait-for-device
|
||||
:wait_boot
|
||||
|
|
@ -28,16 +29,24 @@ if errorlevel 1 (
|
|||
echo.
|
||||
)
|
||||
|
||||
:: Build and install the app
|
||||
::: Build, install, and run the app (starts Metro automatically)
|
||||
echo Building and installing MusicRoom...
|
||||
echo Building and installing Blastoise...
|
||||
echo.
|
||||
call bunx react-native run-android
|
||||
pushd "%PROJECT_DIR%"
|
||||
call gradlew.bat :app:installDebug
|
||||
if errorlevel 1 (
|
||||
popd
|
||||
echo.
|
||||
echo Build or install failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
popd
|
||||
|
||||
echo Launching app...
|
||||
adb shell am start -n com.peterino.blastoise/.MainActivity
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo App is running. Leave this window open --
|
||||
echo Metro is serving the JS bundle.
|
||||
echo Press Ctrl+C to stop Metro when done.
|
||||
echo App is installed and launched.
|
||||
echo ============================================
|
||||
pause
|
||||
|
|
|
|||
|
|
@ -0,0 +1,147 @@
|
|||
@echo off
|
||||
setlocal EnableExtensions EnableDelayedExpansion
|
||||
|
||||
echo ============================================
|
||||
echo Blastoise Native Android - Build and Launch
|
||||
echo ============================================
|
||||
echo.
|
||||
|
||||
set "ROOT_DIR=%~dp0"
|
||||
set "PROJECT_DIR=%ROOT_DIR%android\BlastoiseNative"
|
||||
set "APK_PATH=%PROJECT_DIR%\app\build\outputs\apk\debug\app-debug.apk"
|
||||
set "PACKAGE_ACTIVITY=com.peterino.blastoise/.MainActivity"
|
||||
|
||||
if "%~1"=="" (
|
||||
set "AVD_NAME=Medium_Phone_API_36.0"
|
||||
) else (
|
||||
set "AVD_NAME=%~1"
|
||||
)
|
||||
|
||||
set "PATH=%USERPROFILE%\scoop\shims;%PATH%"
|
||||
if not defined JAVA_HOME (
|
||||
if exist "%USERPROFILE%\scoop\apps\temurin17-jdk\current" (
|
||||
set "JAVA_HOME=%USERPROFILE%\scoop\apps\temurin17-jdk\current"
|
||||
)
|
||||
)
|
||||
if not defined ANDROID_HOME set "ANDROID_HOME=%LOCALAPPDATA%\Android\Sdk"
|
||||
set "PATH=%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\emulator;%ANDROID_HOME%\cmdline-tools\latest\bin;%PATH%"
|
||||
set "ADB_EXE=%ANDROID_HOME%\platform-tools\adb.exe"
|
||||
set "EMULATOR_EXE=%ANDROID_HOME%\emulator\emulator.exe"
|
||||
|
||||
if not exist "%PROJECT_DIR%\gradlew.bat" (
|
||||
echo ERROR: Native Android project not found:
|
||||
echo %PROJECT_DIR%
|
||||
goto :fail
|
||||
)
|
||||
|
||||
if not exist "%ADB_EXE%" (
|
||||
echo ERROR: adb not found at:
|
||||
echo %ADB_EXE%
|
||||
echo Run android\dev-setup.bat first.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
if not exist "%EMULATOR_EXE%" (
|
||||
echo ERROR: Android emulator not found at:
|
||||
echo %EMULATOR_EXE%
|
||||
echo Run android\dev-setup.bat first.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
"%EMULATOR_EXE%" -list-avds | findstr /X /C:"%AVD_NAME%" >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: AVD "%AVD_NAME%" was not found.
|
||||
echo.
|
||||
echo Available AVDs:
|
||||
"%EMULATOR_EXE%" -list-avds
|
||||
echo.
|
||||
echo Pass a different AVD name as the first argument, for example:
|
||||
echo run-android-native.bat Your_AVD_Name
|
||||
goto :fail
|
||||
)
|
||||
|
||||
echo Building debug APK...
|
||||
pushd "%PROJECT_DIR%"
|
||||
call gradlew.bat :app:assembleDebug
|
||||
if errorlevel 1 (
|
||||
popd
|
||||
echo.
|
||||
echo ERROR: Gradle build failed.
|
||||
goto :fail
|
||||
)
|
||||
popd
|
||||
|
||||
if not exist "%APK_PATH%" (
|
||||
echo ERROR: APK was not created:
|
||||
echo %APK_PATH%
|
||||
goto :fail
|
||||
)
|
||||
|
||||
"%ADB_EXE%" devices | findstr /R /C:"emulator-[0-9][0-9]*[ ]*device" >nul
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo Starting emulator "%AVD_NAME%"...
|
||||
start "" "%EMULATOR_EXE%" -avd "%AVD_NAME%"
|
||||
echo Waiting for emulator device...
|
||||
set /a WAIT_DEVICE_COUNT=0
|
||||
:wait_device
|
||||
"%ADB_EXE%" devices | findstr /R /C:"emulator-[0-9][0-9]*[ ]*device" >nul
|
||||
if errorlevel 1 (
|
||||
set /a WAIT_DEVICE_COUNT+=1
|
||||
if !WAIT_DEVICE_COUNT! GEQ 90 (
|
||||
echo ERROR: Emulator did not appear within 180 seconds.
|
||||
goto :fail
|
||||
)
|
||||
timeout /t 2 /nobreak >nul
|
||||
goto :wait_device
|
||||
)
|
||||
)
|
||||
|
||||
echo Waiting for Android boot completion...
|
||||
set /a WAIT_BOOT_COUNT=0
|
||||
:wait_boot
|
||||
set "BOOT_DONE="
|
||||
for /f "delims=" %%b in ('"%ADB_EXE%" shell getprop sys.boot_completed 2^>nul') do set "BOOT_DONE=%%b"
|
||||
if not "%BOOT_DONE%"=="1" (
|
||||
set /a WAIT_BOOT_COUNT+=1
|
||||
if !WAIT_BOOT_COUNT! GEQ 120 (
|
||||
echo ERROR: Android did not finish booting within 240 seconds.
|
||||
goto :fail
|
||||
)
|
||||
timeout /t 2 /nobreak >nul
|
||||
goto :wait_boot
|
||||
)
|
||||
|
||||
echo Installing APK...
|
||||
"%ADB_EXE%" install -r "%APK_PATH%"
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: APK install failed.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
echo Launching app...
|
||||
"%ADB_EXE%" shell am start -n %PACKAGE_ACTIVITY%
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: App launch failed.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo Blastoise is built, installed, and running.
|
||||
echo ============================================
|
||||
goto :done
|
||||
|
||||
:fail
|
||||
echo.
|
||||
echo ============================================
|
||||
echo Failed.
|
||||
echo ============================================
|
||||
if not "%NO_PAUSE%"=="1" pause
|
||||
exit /b 1
|
||||
|
||||
:done
|
||||
if not "%NO_PAUSE%"=="1" pause
|
||||
exit /b 0
|
||||
Loading…
Reference in New Issue