Initial RelayTV Android release
@@ -0,0 +1,22 @@
|
||||
# Gradle
|
||||
.gradle/
|
||||
build/
|
||||
app/build/
|
||||
|
||||
# Local config
|
||||
local.properties
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# Keystore
|
||||
*.jks
|
||||
*.keystore
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
#Build
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
plugins {
|
||||
id "com.android.application"
|
||||
id "org.jetbrains.kotlin.android"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "pro.relaytv"
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "pro.relaytv"
|
||||
minSdk 26
|
||||
targetSdk 34
|
||||
versionCode 2
|
||||
versionName "1.1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
|
||||
}
|
||||
debug {
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
kotlinOptions { jvmTarget = "17" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "androidx.core:core-ktx:1.13.1"
|
||||
implementation "androidx.appcompat:appcompat:1.7.0"
|
||||
implementation "androidx.activity:activity-ktx:1.9.2"
|
||||
implementation "com.google.android.material:material:1.12.0"
|
||||
implementation "androidx.core:core:1.13.1"
|
||||
|
||||
implementation "com.squareup.okhttp3:okhttp:4.12.0"
|
||||
implementation "androidx.work:work-runtime-ktx:2.9.1"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
@@ -0,0 +1,47 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:theme="@style/Theme.RelayTV">
|
||||
|
||||
<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>
|
||||
|
||||
<activity
|
||||
android:name=".ShareActivity"
|
||||
android:exported="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:finishOnTaskLaunch="true"
|
||||
android:taskAffinity=""
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.RelayTV.NoActionBar"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,121 @@
|
||||
package pro.relaytv
|
||||
|
||||
import android.content.Context
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.util.UUID
|
||||
|
||||
data class RelayHost(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val baseUrl: String,
|
||||
)
|
||||
|
||||
object HostStore {
|
||||
private const val PREF = "relaytv_prefs"
|
||||
private const val KEY_HOSTS = "hosts_json"
|
||||
private const val KEY_ACTIVE = "active_host_id"
|
||||
|
||||
|
||||
fun normalizeBaseUrl(input: String): String? {
|
||||
var s = input.trim()
|
||||
if (s.isBlank()) return null
|
||||
s = s.trimEnd('/')
|
||||
// If user entered host:port (no scheme), default to http://
|
||||
if (!s.contains("://")) {
|
||||
s = "http://" + s
|
||||
}
|
||||
val url = s.toHttpUrlOrNull() ?: return null
|
||||
return url.toString().trimEnd('/')
|
||||
}
|
||||
|
||||
private fun prefs(ctx: Context) = ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE)
|
||||
|
||||
fun ensureMigrated(ctx: Context) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
fun loadHosts(ctx: Context): List<RelayHost> {
|
||||
ensureMigrated(ctx)
|
||||
val raw = prefs(ctx).getString(KEY_HOSTS, null) ?: return emptyList()
|
||||
return try {
|
||||
val arr = JSONArray(raw)
|
||||
buildList {
|
||||
for (i in 0 until arr.length()) {
|
||||
val o = arr.getJSONObject(i)
|
||||
add(
|
||||
RelayHost(
|
||||
id = o.optString("id"),
|
||||
name = o.optString("name", "Server"),
|
||||
baseUrl = normalizeBaseUrl(o.optString("baseUrl")) ?: "",
|
||||
)
|
||||
)
|
||||
}
|
||||
}.filter { it.id.isNotBlank() && it.baseUrl.isNotBlank() }
|
||||
} catch (_: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun saveHosts(ctx: Context, hosts: List<RelayHost>) {
|
||||
val arr = JSONArray()
|
||||
hosts.forEach {
|
||||
arr.put(
|
||||
JSONObject()
|
||||
.put("id", it.id)
|
||||
.put("name", it.name)
|
||||
.put("baseUrl", normalizeBaseUrl(it.baseUrl) ?: "")
|
||||
)
|
||||
}
|
||||
prefs(ctx).edit().putString(KEY_HOSTS, arr.toString()).apply()
|
||||
}
|
||||
|
||||
fun getActiveHostId(ctx: Context): String? {
|
||||
ensureMigrated(ctx)
|
||||
return prefs(ctx).getString(KEY_ACTIVE, null)
|
||||
}
|
||||
|
||||
fun setActiveHostId(ctx: Context, id: String) {
|
||||
prefs(ctx).edit().putString(KEY_ACTIVE, id).apply()
|
||||
}
|
||||
|
||||
fun getActiveHost(ctx: Context): RelayHost? {
|
||||
val hosts = loadHosts(ctx)
|
||||
if (hosts.isEmpty()) return null
|
||||
val active = getActiveHostId(ctx)
|
||||
val hit = hosts.firstOrNull { it.id == active } ?: hosts.first()
|
||||
if (hit.id != active) setActiveHostId(ctx, hit.id)
|
||||
return hit
|
||||
}
|
||||
|
||||
fun getActiveBaseUrl(ctx: Context): String? {
|
||||
val hit = getActiveHost(ctx) ?: return null
|
||||
return normalizeBaseUrl(hit.baseUrl) ?: ""
|
||||
}
|
||||
|
||||
fun upsert(ctx: Context, host: RelayHost) {
|
||||
val hosts = loadHosts(ctx).toMutableList()
|
||||
val idx = hosts.indexOfFirst { it.id == host.id }
|
||||
if (idx >= 0) hosts[idx] = host else hosts.add(host)
|
||||
saveHosts(ctx, hosts)
|
||||
}
|
||||
|
||||
fun remove(ctx: Context, id: String) {
|
||||
val hosts = loadHosts(ctx).filterNot { it.id == id }
|
||||
saveHosts(ctx, hosts)
|
||||
val active = getActiveHostId(ctx)
|
||||
if (active == id) {
|
||||
val next = hosts.firstOrNull()
|
||||
if (next != null) setActiveHostId(ctx, next.id) else prefs(ctx).edit().remove(KEY_ACTIVE).apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun create(ctx: Context, name: String, baseUrl: String): RelayHost {
|
||||
val norm = normalizeBaseUrl(baseUrl) ?: ""
|
||||
val host = RelayHost(UUID.randomUUID().toString(), name.ifBlank { "Server" }, norm)
|
||||
upsert(ctx, host)
|
||||
if (getActiveHostId(ctx).isNullOrBlank()) setActiveHostId(ctx, host.id)
|
||||
return host
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package pro.relaytv
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.webkit.WebChromeClient
|
||||
import android.webkit.WebResourceError
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.EditText
|
||||
import android.widget.ListView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import okhttp3.Call
|
||||
import okhttp3.Callback
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private val requestNotificationPermission =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* no-op */ }
|
||||
|
||||
private lateinit var web: WebView
|
||||
private lateinit var toolbar: MaterialToolbar
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Android 13+ requires runtime permission for notifications.
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestNotificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main)
|
||||
val openServers = intent.getBooleanExtra("open_servers", false)
|
||||
toolbar = findViewById(R.id.toolbar)
|
||||
web = findViewById(R.id.web)
|
||||
|
||||
toolbar.setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
R.id.action_servers -> {
|
||||
showServerPicker()
|
||||
true
|
||||
}
|
||||
R.id.action_reload -> {
|
||||
web.reload()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
web.settings.javaScriptEnabled = true
|
||||
web.settings.domStorageEnabled = true
|
||||
web.settings.mediaPlaybackRequiresUserGesture = false
|
||||
web.settings.userAgentString = web.settings.userAgentString + " RelayTV/1.1.0"
|
||||
|
||||
web.webChromeClient = WebChromeClient()
|
||||
web.webViewClient = object : WebViewClient() {
|
||||
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
|
||||
if (request.isForMainFrame) {
|
||||
Toast.makeText(this@MainActivity, "Can't reach server. Switch servers.", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val base = HostStore.getActiveBaseUrl(this)
|
||||
if (openServers) {
|
||||
showServerPicker(force = base.isNullOrBlank())
|
||||
}
|
||||
|
||||
if (base.isNullOrBlank()) {
|
||||
showServerPicker(force = true)
|
||||
return
|
||||
}
|
||||
checkHealthAndLoad(base.trimEnd('/'))
|
||||
}
|
||||
|
||||
private fun checkHealthAndLoad(base: String) {
|
||||
val req = Net.get(base + "/health")
|
||||
Net.client.newCall(req).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
runOnUiThread {
|
||||
Toast.makeText(this@MainActivity, "Server not reachable. Switch servers.", Toast.LENGTH_LONG).show()
|
||||
showServerPicker(force = true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
response.use {
|
||||
if (!it.isSuccessful) {
|
||||
runOnUiThread {
|
||||
Toast.makeText(this@MainActivity, "Not a RelayTV server (HTTP ${it.code}).", Toast.LENGTH_LONG).show()
|
||||
showServerPicker(force = true)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
runOnUiThread { web.loadUrl(base + "/ui") }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showServerPicker(force: Boolean = false) {
|
||||
val view = LayoutInflater.from(this).inflate(R.layout.dialog_server_picker, null)
|
||||
val list = view.findViewById<ListView>(R.id.listServers)
|
||||
val btnAdd = view.findViewById<com.google.android.material.button.MaterialButton>(R.id.btnAdd)
|
||||
val btnEdit = view.findViewById<com.google.android.material.button.MaterialButton>(R.id.btnEdit)
|
||||
val btnRemove = view.findViewById<com.google.android.material.button.MaterialButton>(R.id.btnRemove)
|
||||
|
||||
fun refresh(selectionId: String? = HostStore.getActiveHostId(this)) {
|
||||
val hosts = HostStore.loadHosts(this)
|
||||
val labels = hosts.map { "${it.name} • ${it.baseUrl}" }
|
||||
list.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_single_choice, labels)
|
||||
list.choiceMode = ListView.CHOICE_MODE_SINGLE
|
||||
val idx = hosts.indexOfFirst { it.id == selectionId }.let { if (it >= 0) it else 0 }
|
||||
if (hosts.isNotEmpty()) list.setItemChecked(idx, true)
|
||||
btnEdit.isEnabled = hosts.isNotEmpty()
|
||||
btnRemove.isEnabled = hosts.isNotEmpty()
|
||||
}
|
||||
|
||||
refresh()
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(this)
|
||||
.setTitle(getString(R.string.select_server))
|
||||
.setView(view)
|
||||
.setNegativeButton(if (force) "Exit" else "Close") { d, _ ->
|
||||
d.dismiss()
|
||||
if (force && HostStore.getActiveBaseUrl(this).isNullOrBlank()) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
.setPositiveButton("Use") { d, _ ->
|
||||
val hosts = HostStore.loadHosts(this)
|
||||
if (hosts.isEmpty()) {
|
||||
Toast.makeText(this, "Add a server first.", Toast.LENGTH_SHORT).show()
|
||||
return@setPositiveButton
|
||||
}
|
||||
val pos = list.checkedItemPosition.coerceAtLeast(0)
|
||||
val chosen = hosts.getOrNull(pos) ?: hosts.first()
|
||||
HostStore.setActiveHostId(this, chosen.id)
|
||||
toolbar.subtitle = chosen.name
|
||||
checkHealthAndLoad(chosen.baseUrl)
|
||||
d.dismiss()
|
||||
}
|
||||
.create()
|
||||
|
||||
list.setOnItemClickListener { _, _, position, _ ->
|
||||
val hosts = HostStore.loadHosts(this)
|
||||
val chosen = hosts.getOrNull(position) ?: return@setOnItemClickListener
|
||||
toolbar.subtitle = chosen.name
|
||||
}
|
||||
fun showAddEdit(existing: RelayHost? = null) {
|
||||
val nameInput = EditText(this).apply {
|
||||
hint = getString(R.string.server_name)
|
||||
setText(existing?.name ?: "")
|
||||
}
|
||||
val urlInput = EditText(this).apply {
|
||||
hint = getString(R.string.server_url)
|
||||
setText(existing?.baseUrl ?: "")
|
||||
inputType = android.text.InputType.TYPE_TEXT_VARIATION_URI
|
||||
}
|
||||
|
||||
val container = LinearLayout(this).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
val pad = (16 * resources.displayMetrics.density).toInt()
|
||||
setPadding(pad, (8 * resources.displayMetrics.density).toInt(), pad, 0)
|
||||
addView(nameInput)
|
||||
addView(urlInput)
|
||||
}
|
||||
|
||||
val dlg = MaterialAlertDialogBuilder(this)
|
||||
.setTitle(if (existing == null) getString(R.string.add_server) else getString(R.string.edit_server))
|
||||
.setView(container)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
// We override the positive click to keep the dialog open on validation errors.
|
||||
.setPositiveButton("Save", null)
|
||||
.create()
|
||||
|
||||
dlg.setOnShowListener {
|
||||
val btn = dlg.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
btn.setOnClickListener {
|
||||
val name = nameInput.text.toString().trim().ifBlank { "Server" }
|
||||
val raw = urlInput.text.toString()
|
||||
val base = HostStore.normalizeBaseUrl(raw)
|
||||
|
||||
if (base.isNullOrBlank()) {
|
||||
Toast.makeText(this, "Enter a valid base URL (example: http://10.0.55.2:8787).", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
btn.isEnabled = false
|
||||
Toast.makeText(this, "Verifying server…", Toast.LENGTH_SHORT).show()
|
||||
|
||||
val req = Net.get(base + "/health")
|
||||
Net.client.newCall(req).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
runOnUiThread {
|
||||
btn.isEnabled = true
|
||||
Toast.makeText(this@MainActivity, "Can't reach server. Check address.", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
val ok = response.isSuccessful && try {
|
||||
val body = response.body?.string() ?: ""
|
||||
val o = org.json.JSONObject(body)
|
||||
o.optBoolean("ok", false)
|
||||
} catch (_: Exception) { false }
|
||||
|
||||
runOnUiThread {
|
||||
if (!ok) {
|
||||
btn.isEnabled = true
|
||||
Toast.makeText(this@MainActivity, "Not a RelayTV server (check /health).", Toast.LENGTH_LONG).show()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
val host = if (existing == null) {
|
||||
HostStore.create(this@MainActivity, name, base)
|
||||
} else {
|
||||
val updated = existing.copy(name = name, baseUrl = base)
|
||||
HostStore.upsert(this@MainActivity, updated)
|
||||
updated
|
||||
}
|
||||
|
||||
HostStore.setActiveHostId(this@MainActivity, host.id)
|
||||
refresh(host.id)
|
||||
dlg.dismiss()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
dlg.show()
|
||||
}
|
||||
|
||||
|
||||
btnAdd.setOnClickListener { showAddEdit(null) }
|
||||
|
||||
btnEdit.setOnClickListener {
|
||||
val hosts = HostStore.loadHosts(this)
|
||||
val pos = list.checkedItemPosition.coerceAtLeast(0)
|
||||
val existing = hosts.getOrNull(pos) ?: return@setOnClickListener
|
||||
showAddEdit(existing)
|
||||
}
|
||||
|
||||
btnRemove.setOnClickListener {
|
||||
val hosts = HostStore.loadHosts(this)
|
||||
val pos = list.checkedItemPosition.coerceAtLeast(0)
|
||||
val existing = hosts.getOrNull(pos) ?: return@setOnClickListener
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle("Remove server?")
|
||||
.setMessage("Remove ${existing.name}?")
|
||||
.setNegativeButton("Cancel", null)
|
||||
.setPositiveButton("Remove") { _, _ ->
|
||||
HostStore.remove(this, existing.id)
|
||||
refresh()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
// Show active server on toolbar
|
||||
HostStore.loadHosts(this).firstOrNull { it.id == HostStore.getActiveHostId(this) }?.let {
|
||||
toolbar.subtitle = it.name
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (this::web.isInitialized && web.canGoBack()) web.goBack() else super.onBackPressed()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package pro.relaytv
|
||||
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object Net {
|
||||
val client: OkHttpClient = OkHttpClient.Builder()
|
||||
.callTimeout(30, TimeUnit.SECONDS)
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(25, TimeUnit.SECONDS)
|
||||
.writeTimeout(25, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
fun get(url: String): Request = Request.Builder().url(url).get().build()
|
||||
|
||||
fun postJson(url: String, json: String): Request {
|
||||
val mt = "application/json; charset=utf-8".toMediaType()
|
||||
val body = json.toRequestBody(mt)
|
||||
return Request.Builder().url(url).post(body).build()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package pro.relaytv
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
/**
|
||||
* Kept for backward compatibility (older deep links / flows).
|
||||
* This activity simply opens the server picker inside MainActivity.
|
||||
*/
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
startActivity(android.content.Intent(this, MainActivity::class.java).apply {
|
||||
putExtra("open_servers", true)
|
||||
})
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package pro.relaytv
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.work.Data
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
|
||||
class ShareActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val base = HostStore.getActiveBaseUrl(this)?.trim()?.trimEnd('/')
|
||||
if (base.isNullOrBlank()) {
|
||||
// No server selected yet; open app so user can configure.
|
||||
startActivity(Intent(this, MainActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
putExtra("open_servers", true)
|
||||
})
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
val shared = intent.getStringExtra(Intent.EXTRA_TEXT) ?: ""
|
||||
val url = extractUrl(shared) ?: run { finish(); return }
|
||||
|
||||
val input = Data.Builder()
|
||||
.putString(ShareWorker.KEY_BASE, base)
|
||||
.putString(ShareWorker.KEY_URL, url)
|
||||
.build()
|
||||
|
||||
val req = OneTimeWorkRequestBuilder<ShareWorker>()
|
||||
.setInputData(input)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance(this).enqueue(req)
|
||||
val serverName = HostStore.getActiveHost(this)?.name?.ifBlank { "Server" } ?: "Server"
|
||||
Toast.makeText(this, "Sent to \"$serverName\"", Toast.LENGTH_SHORT).show()
|
||||
finishAndRemoveTask()
|
||||
}
|
||||
|
||||
private fun extractUrl(text: String): String? {
|
||||
val m = Regex("""https?://\S+""").find(text)
|
||||
return m?.value?.trim()?.trimEnd(')', ']', '>', '"', '\'')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package pro.relaytv
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import org.json.JSONObject
|
||||
|
||||
class ShareWorker(appContext: Context, params: WorkerParameters) : Worker(appContext, params) {
|
||||
|
||||
companion object {
|
||||
const val KEY_BASE = "base"
|
||||
const val KEY_URL = "url"
|
||||
private const val CHANNEL_ID = "relaytv_silent"
|
||||
private const val NOTIF_ID = 4242
|
||||
}
|
||||
|
||||
override fun doWork(): Result {
|
||||
val base = inputData.getString(KEY_BASE)?.trim()?.trimEnd('/') ?: return Result.failure()
|
||||
val url = inputData.getString(KEY_URL) ?: return Result.failure()
|
||||
return try {
|
||||
val payload = JSONObject().put("url", url).toString()
|
||||
val req = Net.postJson(base + "/smart", payload)
|
||||
|
||||
Net.client.newCall(req).execute().use { resp ->
|
||||
val body = resp.body?.string().orEmpty()
|
||||
val ok = resp.isSuccessful
|
||||
val msg = runCatching {
|
||||
val j = JSONObject(body)
|
||||
when (j.optString("status")) {
|
||||
"playing" -> "Playing now"
|
||||
"queued" -> "Enqueued"
|
||||
else -> if (ok) "Sent" else "Error"
|
||||
}
|
||||
}.getOrDefault(if (ok) "Sent" else "Error")
|
||||
|
||||
postNotification(msg, url, tapToOpen = true)
|
||||
if (ok) Result.success() else Result.retry()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val reason = (e.message ?: e.javaClass.simpleName).take(80)
|
||||
if (reason.contains("timeout", ignoreCase = true)) {
|
||||
postNotification("Sent (processing)", url, tapToOpen = true)
|
||||
Result.success()
|
||||
} else {
|
||||
postNotification("Send failed: $reason", url, tapToOpen = true)
|
||||
Result.retry()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun postNotification(title: String, text: String, tapToOpen: Boolean) {
|
||||
val nm = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val ch = NotificationChannel(CHANNEL_ID, "RelayTV", NotificationManager.IMPORTANCE_LOW)
|
||||
nm.createNotificationChannel(ch)
|
||||
}
|
||||
|
||||
val builder = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.ic_media_play)
|
||||
.setContentTitle(title)
|
||||
.setContentText(text.take(90))
|
||||
.setAutoCancel(true)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
|
||||
if (tapToOpen) {
|
||||
val openIntent = Intent(applicationContext, MainActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
}
|
||||
val pending = PendingIntent.getActivity(
|
||||
applicationContext,
|
||||
0,
|
||||
openIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||
)
|
||||
builder.setContentIntent(pending)
|
||||
}
|
||||
|
||||
nm.notify(NOTIF_ID, builder.build())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/relaytv_surface">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:title="@string/app_name"
|
||||
app:titleTextColor="@android:color/white"
|
||||
app:menu="@menu/main_menu" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<WebView
|
||||
android:id="@+id/web"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="RelayTV Server"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingBottom="10dp"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Base URL (HTTP or HTTPS). Example: http://nuc.lan:8787"
|
||||
android:textSize="14sp"
|
||||
android:paddingBottom="8dp"/>
|
||||
<EditText
|
||||
android:id="@+id/editBaseUrl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="http://nuc.lan:8787"
|
||||
android:inputType="textUri"
|
||||
android:singleLine="true"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="14dp">
|
||||
<Button
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Save"/>
|
||||
<Space
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
<Button
|
||||
android:id="@+id/btnDetect"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Auto-detect"/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/txtStatus"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textSize="13sp"
|
||||
android:paddingTop="10dp"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Tip: Share a link from BravePipe → RelayTV. It sends to /smart in the background and shows a notification (tap it to open UI)."
|
||||
android:textSize="13sp"
|
||||
android:paddingTop="16dp"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listServers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="260dp"
|
||||
android:choiceMode="singleChoice" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="12dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnAdd"
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/add_server"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnEdit"
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="@string/edit_server"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnRemove"
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="@string/remove_server"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/action_servers"
|
||||
android:title="@string/servers"
|
||||
android:icon="@android:drawable/ic_menu_manage"
|
||||
android:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_reload"
|
||||
android:title="Reload"
|
||||
android:icon="@android:drawable/ic_popup_sync"
|
||||
android:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- RelayTV brand (dark mode optimized) -->
|
||||
<color name="relaytv_surface">#0F1216</color> <!-- deep charcoal -->
|
||||
<color name="relaytv_primary">#2F7BFF</color> <!-- electric blue -->
|
||||
<color name="relaytv_on_primary">#FFFFFF</color>
|
||||
<color name="relaytv_secondary">#26D07C</color> <!-- neon green accent -->
|
||||
<color name="relaytv_on_secondary">#00140B</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">RelayTV</string>
|
||||
<string name="servers">Servers</string>
|
||||
<string name="add_server">Add server</string>
|
||||
<string name="edit_server">Edit server</string>
|
||||
<string name="remove_server">Remove server</string>
|
||||
<string name="select_server">Select RelayTV server</string>
|
||||
<string name="server_name">Name</string>
|
||||
<string name="server_url">Base URL</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,21 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<style name="Theme.RelayTV" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="colorPrimary">@color/relaytv_primary</item>
|
||||
<item name="colorOnPrimary">@color/relaytv_on_primary</item>
|
||||
<item name="colorSecondary">@color/relaytv_secondary</item>
|
||||
<item name="colorOnSecondary">@color/relaytv_on_secondary</item>
|
||||
<item name="android:navigationBarColor">@color/relaytv_surface</item>
|
||||
<item name="android:colorBackground">@color/relaytv_surface</item>
|
||||
|
||||
</style>
|
||||
<style name="Theme.RelayTV.NoActionBar" parent="Theme.Material3.DayNight.NoActionBar" />
|
||||
|
||||
<style name="Theme.RelayTV.Share" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackground">@android:color/transparent</item>
|
||||
<item name="android:backgroundDimEnabled">false</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<base-config cleartextTrafficPermitted="true" />
|
||||
</network-security-config>
|
||||
@@ -0,0 +1,4 @@
|
||||
plugins {
|
||||
id "com.android.application" version "8.5.2" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.9.24" apply false
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/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
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# 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" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
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" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-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,94 @@
|
||||
@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
|
||||
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -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,16 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "RelayTV"
|
||||
include(":app")
|
||||