phase 3: polish compatibility and deprecation handling
This commit is contained in:
@@ -38,7 +38,6 @@ dependencies {
|
||||
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 "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||
|
||||
implementation "com.squareup.okhttp3:okhttp:4.12.0"
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.widget.EditText
|
||||
import android.widget.ListView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -83,6 +84,17 @@ class MainActivity : AppCompatActivity() {
|
||||
toolbar = findViewById(R.id.toolbar)
|
||||
web = findViewById(R.id.web)
|
||||
swipeRefresh = findViewById(R.id.swipeRefresh)
|
||||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
if (this@MainActivity::web.isInitialized && web.canGoBack()) {
|
||||
web.goBack()
|
||||
return
|
||||
}
|
||||
isEnabled = false
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
isEnabled = true
|
||||
}
|
||||
})
|
||||
|
||||
toolbar.setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
@@ -537,8 +549,4 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (this::web.isInitialized && web.canGoBack()) web.goBack() else super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ class NsdRelayTvScanner(context: Context) {
|
||||
val serviceTag = attributes?.get("service")?.toUtf8()?.lowercase()
|
||||
if (!serviceTag.isNullOrBlank() && serviceTag != "relaytv") return
|
||||
|
||||
val ip = (info.host?.hostAddress ?: "").trim().substringBefore('%')
|
||||
val ip = nsdHostAddress(info)
|
||||
if (ip.isBlank()) return
|
||||
val host = if (ip.contains(":")) "[$ip]" else ip
|
||||
val base = HostStore.normalizeBaseUrl("http://$host:${info.port}") ?: return
|
||||
val path = attributes?.get("path")?.toUtf8()?.ifBlank { "/ui" } ?: "/ui"
|
||||
val name = info.serviceName?.trim().orEmpty().ifBlank { "RelayTV" }
|
||||
val name = info.serviceName.trim().ifBlank { "RelayTV" }
|
||||
|
||||
val server = DiscoveredRelayTvServer(name = name, baseUrl = base, path = path)
|
||||
found[base] = server
|
||||
@@ -96,7 +96,7 @@ class NsdRelayTvScanner(context: Context) {
|
||||
override fun onServiceFound(serviceInfo: NsdServiceInfo) {
|
||||
if (!serviceInfo.serviceType.equals(SERVICE_TYPE, ignoreCase = true)) return
|
||||
|
||||
nsdManager.resolveService(serviceInfo, object : NsdManager.ResolveListener {
|
||||
resolveServiceCompat(serviceInfo, object : NsdManager.ResolveListener {
|
||||
override fun onResolveFailed(serviceInfo: NsdServiceInfo, errorCode: Int) = Unit
|
||||
|
||||
override fun onServiceResolved(serviceInfo: NsdServiceInfo) {
|
||||
@@ -106,7 +106,7 @@ class NsdRelayTvScanner(context: Context) {
|
||||
}
|
||||
|
||||
override fun onServiceLost(serviceInfo: NsdServiceInfo) {
|
||||
val ip = (serviceInfo.host?.hostAddress ?: "").trim().substringBefore('%')
|
||||
val ip = nsdHostAddress(serviceInfo)
|
||||
if (ip.isBlank()) return
|
||||
val host = if (ip.contains(":")) "[$ip]" else ip
|
||||
val base = HostStore.normalizeBaseUrl("http://$host:${serviceInfo.port}") ?: return
|
||||
@@ -158,6 +158,15 @@ class NsdRelayTvScanner(context: Context) {
|
||||
}
|
||||
multicastLock = null
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun resolveServiceCompat(serviceInfo: NsdServiceInfo, listener: NsdManager.ResolveListener) {
|
||||
nsdManager.resolveService(serviceInfo, listener)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun nsdHostAddress(serviceInfo: NsdServiceInfo): String =
|
||||
(serviceInfo.host?.hostAddress ?: "").trim().substringBefore('%')
|
||||
}
|
||||
|
||||
private fun ByteArray.toUtf8(): String = toString(Charsets.UTF_8).trim()
|
||||
|
||||
@@ -85,8 +85,10 @@ check_sdk() {
|
||||
|
||||
if command -v sdkmanager >/dev/null 2>&1; then
|
||||
ok "Found command: sdkmanager"
|
||||
elif [[ -x "${sdk_root}/cmdline-tools/latest/bin/sdkmanager" ]]; then
|
||||
ok "Found sdkmanager at ${sdk_root}/cmdline-tools/latest/bin/sdkmanager"
|
||||
else
|
||||
warn "sdkmanager not in PATH. bootstrap script can still work if cmdline-tools path is set manually."
|
||||
warn "sdkmanager not found in PATH or ${sdk_root}/cmdline-tools/latest/bin."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user