Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11446a92a5 | ||
|
|
b988e7cea0 | ||
|
|
f4996bef8e | ||
|
|
27169e9d0f | ||
|
|
a083660e03 | ||
|
|
3de3d7e893 | ||
|
|
efcec098bd | ||
|
|
d0c055fec9 | ||
|
|
9790f9d69c | ||
|
|
ea36319fe3 | ||
|
|
fc224e3e09 | ||
|
|
583ec62e39 | ||
|
|
bff0d29ee8 | ||
|
|
abb6f254bc |
@@ -11,8 +11,8 @@ android {
|
||||
applicationId = "ru.ua1zbe.svxremote"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 4
|
||||
versionName = "1.0.2"
|
||||
versionCode = 6
|
||||
versionName = "1.0.4"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<activity
|
||||
android:name=".SplashActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.SvxRemote">
|
||||
<intent-filter>
|
||||
@@ -39,6 +40,7 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="portrait"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden" />
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.PixelFormat
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
@@ -16,6 +19,7 @@ import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.ImageButton
|
||||
@@ -55,10 +59,12 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
private lateinit var micDb: TextView
|
||||
private lateinit var pttButton: PttButton
|
||||
private lateinit var btnSettings: ImageButton
|
||||
private lateinit var btnMonitor: ImageButton
|
||||
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
private var connected = false
|
||||
private var monitoring = false
|
||||
private var settings: ConnectionSettings = ConnectionSettings("", 5300, "", "", 11)
|
||||
|
||||
private var svc: SvxService? = null
|
||||
@@ -78,6 +84,7 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
SplashActivity.mainAlive = true
|
||||
setContentView(R.layout.activity_main)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
checkForUpdates()
|
||||
@@ -98,44 +105,41 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
micDb = findViewById(R.id.mic_db)
|
||||
pttButton = findViewById(R.id.ptt_button)
|
||||
btnSettings = findViewById(R.id.btn_settings)
|
||||
btnMonitor = findViewById(R.id.btn_monitor)
|
||||
pttButton.enabled2 = false
|
||||
|
||||
btnMonitor.setOnClickListener { toggleMonitoring() }
|
||||
updateMonitorButton()
|
||||
val testText = intent?.getStringExtra("node_toast_test")
|
||||
if (testText != null) {
|
||||
mainHandler.postDelayed({ showNodeOverlay(testText) }, 1500)
|
||||
}
|
||||
|
||||
btnSettings.setOnClickListener {
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
}
|
||||
|
||||
findViewById<ImageButton>(R.id.btn_power).setOnClickListener {
|
||||
svc?.disconnect()
|
||||
stopService(Intent(this, SvxService::class.java))
|
||||
SplashActivity.mainAlive = false
|
||||
finishAffinity()
|
||||
}
|
||||
|
||||
lblTg.setOnClickListener { showGroupsDialog() }
|
||||
|
||||
lblCallsign.setOnClickListener { showNodesDialog() }
|
||||
|
||||
connectZone.setOnClickListener {
|
||||
val s = svc
|
||||
if (connected && s != null) {
|
||||
s.disconnect()
|
||||
if (connected) {
|
||||
svc?.disconnect()
|
||||
} else {
|
||||
settings = Prefs.load(this)
|
||||
if (settings.host.isBlank() || settings.callsign.isBlank()) {
|
||||
toast(getString(R.string.toast_need_settings))
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), REQ_MIC)
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 33 &&
|
||||
checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQ_NOTIF)
|
||||
}
|
||||
startForegroundService(Intent(this, SvxService::class.java))
|
||||
bindService(Intent(this, SvxService::class.java), svcConn, Context.BIND_AUTO_CREATE)
|
||||
mainHandler.postDelayed({
|
||||
svc?.connect(
|
||||
ReflectorClient.Settings(
|
||||
host = settings.host,
|
||||
port = settings.port,
|
||||
callsign = settings.callsign,
|
||||
authKey = settings.authKey,
|
||||
talkGroup = settings.talkGroup
|
||||
)
|
||||
)
|
||||
}, 300)
|
||||
requestPermissionsIfNeeded()
|
||||
connect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,14 +170,30 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
refreshUi()
|
||||
}
|
||||
|
||||
private var autoConnectAttempted = false
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
settings = Prefs.load(this)
|
||||
refreshUi()
|
||||
if (!autoConnectAttempted &&
|
||||
settings.host.isNotBlank() &&
|
||||
settings.callsign.isNotBlank()
|
||||
) {
|
||||
autoConnectAttempted = true
|
||||
requestPermissionsIfNeeded()
|
||||
connect()
|
||||
}
|
||||
if (pendingUpdate != null && updateDialog == null && canInstall()) {
|
||||
startUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
hideNodeOverlay()
|
||||
mainHandler.removeCallbacksAndMessages(null)
|
||||
SplashActivity.mainAlive = false
|
||||
svc?.listener = null
|
||||
unbindService(svcConn)
|
||||
}
|
||||
@@ -226,7 +246,11 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
ReflectorClient.STATE_READY -> {
|
||||
connected = true
|
||||
updatePttEnabled()
|
||||
statusChip.text = getString(R.string.status_connected)
|
||||
statusChip.text = if (monitoring) {
|
||||
getString(R.string.status_monitoring, monitorTgLabel())
|
||||
} else {
|
||||
getString(R.string.status_connected)
|
||||
}
|
||||
statusChip.setTextColor(getColor(R.color.accent))
|
||||
lblTxState.text = getString(R.string.status_big_connected)
|
||||
lblTxState.setTextColor(getColor(R.color.accent))
|
||||
@@ -267,7 +291,11 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
|
||||
override fun onTalkerStart(tg: Long, callsign: String) {
|
||||
mainHandler.post {
|
||||
lblTalkerTitle.text = getString(R.string.talker_now, callsign)
|
||||
lblTalkerTitle.text = if (monitoring) {
|
||||
getString(R.string.talker_mon, callsign, tg)
|
||||
} else {
|
||||
getString(R.string.talker_now, callsign)
|
||||
}
|
||||
lblTalker.text = callsign
|
||||
}
|
||||
}
|
||||
@@ -276,6 +304,53 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
// последний говоривший остаётся на экране
|
||||
}
|
||||
|
||||
override fun onNodeJoined(callsign: String, tg: Long?) {
|
||||
showNodeToast(R.string.toast_node_joined, callsign, tg)
|
||||
}
|
||||
|
||||
override fun onNodeLeft(callsign: String, tg: Long?) {
|
||||
showNodeToast(R.string.toast_node_left, callsign, tg)
|
||||
}
|
||||
|
||||
private fun showNodeToast(tpl: Int, callsign: String, tg: Long?) {
|
||||
if (!Prefs.nodeToastsEnabled(this)) return
|
||||
if (callsign.equals(settings.callsign, ignoreCase = true)) return
|
||||
val suffix = if (tg != null) getString(R.string.node_tg_suffix, tg) else ""
|
||||
mainHandler.post { showNodeOverlay(getString(tpl, callsign, suffix)) }
|
||||
}
|
||||
|
||||
private var nodeOverlay: View? = null
|
||||
|
||||
private fun showNodeOverlay(text: String) {
|
||||
hideNodeOverlay()
|
||||
val view = layoutInflater.inflate(R.layout.view_node_toast, null, false)
|
||||
view.findViewById<TextView>(R.id.lbl_node_toast).text = text
|
||||
try {
|
||||
windowManager.addView(
|
||||
view,
|
||||
WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
|
||||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT
|
||||
).apply { gravity = Gravity.CENTER }
|
||||
)
|
||||
nodeOverlay = view
|
||||
mainHandler.postDelayed({ hideNodeOverlay() }, 5000)
|
||||
} catch (_: Exception) {
|
||||
toast(text)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideNodeOverlay() {
|
||||
nodeOverlay?.let { v ->
|
||||
try { windowManager.removeView(v) } catch (_: Exception) { }
|
||||
nodeOverlay = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAudioPacket(packet: ByteArray, seq: Int) {
|
||||
}
|
||||
|
||||
@@ -306,7 +381,109 @@ class MainActivity : Activity(), SvxService.Listener {
|
||||
}
|
||||
|
||||
private fun updatePttEnabled() {
|
||||
pttButton.enabled2 = connected
|
||||
pttButton.enabled2 = connected && !monitoring
|
||||
}
|
||||
|
||||
private fun requestPermissionsIfNeeded() {
|
||||
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), REQ_MIC)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 33 &&
|
||||
checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQ_NOTIF)
|
||||
}
|
||||
}
|
||||
|
||||
/** Запустить сервис и подключиться с текущими настройками. */
|
||||
private fun connect() {
|
||||
startForegroundService(Intent(this, SvxService::class.java))
|
||||
bindService(Intent(this, SvxService::class.java), svcConn, Context.BIND_AUTO_CREATE)
|
||||
mainHandler.postDelayed({
|
||||
svc?.connect(
|
||||
ReflectorClient.Settings(
|
||||
host = settings.host,
|
||||
port = settings.port,
|
||||
callsign = settings.callsign,
|
||||
authKey = settings.authKey,
|
||||
talkGroup = settings.talkGroup,
|
||||
monitorTgs = if (monitoring) settings.groups else null
|
||||
)
|
||||
)
|
||||
}, 300)
|
||||
}
|
||||
|
||||
/** Включить/выключить режим мониторинга групп с переподключением. */
|
||||
private fun toggleMonitoring() {
|
||||
monitoring = !monitoring
|
||||
updateMonitorButton()
|
||||
updatePttEnabled()
|
||||
if (connected) {
|
||||
svc?.disconnect()
|
||||
mainHandler.postDelayed({ connect() }, 500)
|
||||
} else {
|
||||
connect()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMonitorButton() {
|
||||
val active = monitoring
|
||||
btnMonitor.imageTintList = ColorStateList.valueOf(
|
||||
if (active) Color.parseColor("#58A6FF") else Color.parseColor("#8B949E")
|
||||
)
|
||||
btnMonitor.setBackgroundResource(if (active) R.drawable.bg_monitor_on else 0)
|
||||
btnMonitor.contentDescription =
|
||||
getString(if (active) R.string.btn_monitor_on else R.string.btn_monitor)
|
||||
}
|
||||
|
||||
/** Переключиться на другую группу: пересохранить и переподключиться. */
|
||||
private fun switchGroup(tg: Long) {
|
||||
settings = settings.copy(talkGroup = tg)
|
||||
Prefs.save(this, settings)
|
||||
refreshUi()
|
||||
svc?.disconnect()
|
||||
mainHandler.postDelayed({ connect() }, 500)
|
||||
}
|
||||
|
||||
private fun monitorTgLabel(): String =
|
||||
settings.groups.joinToString(", ") { "TG$it" }
|
||||
|
||||
private fun showNodesDialog() {
|
||||
val nodes = svc?.nodeList().orEmpty()
|
||||
if (nodes.isEmpty()) {
|
||||
toast(getString(R.string.toast_nodes_empty))
|
||||
return
|
||||
}
|
||||
val myCs = settings.callsign.trim()
|
||||
val items = nodes
|
||||
.map { (cs, tg) ->
|
||||
val t = tg ?: if (cs.equals(myCs, ignoreCase = true)) settings.talkGroup else null
|
||||
if (t != null) getString(R.string.node_with_tg, cs, t) else cs
|
||||
}
|
||||
.sorted()
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.nodes_title, items.size))
|
||||
.setItems(items.toTypedArray(), null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun showGroupsDialog() {
|
||||
val groups = (settings.groups + settings.talkGroup).distinct()
|
||||
if (groups.isEmpty()) {
|
||||
toast(getString(R.string.toast_groups_empty))
|
||||
return
|
||||
}
|
||||
val current = settings.talkGroup
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.select_tg)
|
||||
.setItems(groups.map { tg ->
|
||||
val label = getString(R.string.tg_badge, tg)
|
||||
if (tg == current) "$label ✓" else label
|
||||
}.toTypedArray()) { _, which ->
|
||||
val tg = groups[which]
|
||||
if (tg != current) switchGroup(tg)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun checkForUpdates() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package ru.ua1zbe.svxremote
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import ru.ua1zbe.svxremote.prefs.ConnectionSettings
|
||||
@@ -15,6 +16,7 @@ class SettingsActivity : Activity() {
|
||||
private lateinit var inputCallsign: EditText
|
||||
private lateinit var inputAuthKey: EditText
|
||||
private lateinit var inputTg: EditText
|
||||
private lateinit var inputGroups: EditText
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -25,6 +27,9 @@ class SettingsActivity : Activity() {
|
||||
inputCallsign = findViewById(R.id.input_callsign)
|
||||
inputAuthKey = findViewById(R.id.input_auth_key)
|
||||
inputTg = findViewById(R.id.input_tg)
|
||||
inputGroups = findViewById(R.id.input_groups)
|
||||
val chkNodeToasts = findViewById<CheckBox>(R.id.chk_node_toasts)
|
||||
chkNodeToasts.isChecked = Prefs.nodeToastsEnabled(this)
|
||||
|
||||
val s = Prefs.load(this)
|
||||
inputHost.setText(s.host)
|
||||
@@ -32,6 +37,7 @@ class SettingsActivity : Activity() {
|
||||
inputCallsign.setText(s.callsign)
|
||||
inputAuthKey.setText(s.authKey)
|
||||
inputTg.setText(s.talkGroup.toString())
|
||||
inputGroups.setText(s.groups.joinToString(", "))
|
||||
|
||||
findViewById<Button>(R.id.btn_save).setOnClickListener {
|
||||
val host = inputHost.text.toString().trim()
|
||||
@@ -39,6 +45,10 @@ class SettingsActivity : Activity() {
|
||||
val callsign = inputCallsign.text.toString().trim()
|
||||
val authKey = inputAuthKey.text.toString()
|
||||
val tg = inputTg.text.toString().trim().toLongOrNull() ?: 11
|
||||
val groups = inputGroups.text.toString()
|
||||
.split(',')
|
||||
.mapNotNull { it.trim().toLongOrNull() }
|
||||
.distinct()
|
||||
|
||||
if (host.isBlank() || callsign.isBlank()) {
|
||||
toast(getString(R.string.toast_settings_empty))
|
||||
@@ -52,9 +62,11 @@ class SettingsActivity : Activity() {
|
||||
port = port.coerceIn(1, 65535),
|
||||
callsign = callsign,
|
||||
authKey = authKey,
|
||||
talkGroup = tg.coerceAtLeast(0)
|
||||
talkGroup = tg.coerceAtLeast(0),
|
||||
groups = groups
|
||||
)
|
||||
)
|
||||
Prefs.setNodeToastsEnabled(this, chkNodeToasts.isChecked)
|
||||
toast(getString(R.string.saved))
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -9,15 +9,23 @@ import android.view.animation.AccelerateDecelerateInterpolator
|
||||
/** Красивая заставка с плавным появлением логотипа. */
|
||||
class SplashActivity : Activity() {
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
var mainAlive = false
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (mainAlive) {
|
||||
openMain()
|
||||
return
|
||||
}
|
||||
setContentView(R.layout.activity_splash)
|
||||
|
||||
val title = findViewById<View>(R.id.splash_title)
|
||||
val subtitle = findViewById<View>(R.id.splash_subtitle)
|
||||
val line = findViewById<View>(R.id.splash_line)
|
||||
|
||||
val baseAlpha = title.alpha
|
||||
title.alpha = 0f
|
||||
subtitle.alpha = 0f
|
||||
line.alpha = 0f
|
||||
@@ -44,10 +52,21 @@ class SplashActivity : Activity() {
|
||||
.start()
|
||||
|
||||
window.decorView.postDelayed({
|
||||
openMain()
|
||||
}, 4000)
|
||||
}
|
||||
|
||||
private fun openMain() {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
)
|
||||
val testText = this.intent?.getStringExtra("node_toast_test")
|
||||
if (testText != null) intent.putExtra("node_toast_test", testText)
|
||||
startActivity(intent)
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
finish()
|
||||
}, 4000)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package ru.ua1zbe.svxremote
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
@@ -22,6 +23,8 @@ class SvxService : Service(), ReflectorClient.Callbacks {
|
||||
fun onServerInfo(info: MsgParser.ServerInfo)
|
||||
fun onTalkerStart(tg: Long, callsign: String)
|
||||
fun onTalkerStop(tg: Long, callsign: String)
|
||||
fun onNodeJoined(callsign: String, tg: Long?)
|
||||
fun onNodeLeft(callsign: String, tg: Long?)
|
||||
fun onAudioPacket(packet: ByteArray, seq: Int)
|
||||
fun onAudioFlush()
|
||||
fun onError(detail: String)
|
||||
@@ -53,11 +56,22 @@ class SvxService : Service(), ReflectorClient.Callbacks {
|
||||
nm.createNotificationChannel(
|
||||
NotificationChannel("svx", "SVXRemote", NotificationManager.IMPORTANCE_LOW)
|
||||
)
|
||||
updateNotification(getString(R.string.notif_connected))
|
||||
}
|
||||
|
||||
private fun updateNotification(text: String) {
|
||||
val contentIntent = PendingIntent.getActivity(
|
||||
this, 0,
|
||||
Intent(this, MainActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val n = Notification.Builder(this, "svx")
|
||||
.setContentTitle("SVXRemote")
|
||||
.setContentText(getString(R.string.notif_connected))
|
||||
.setSmallIcon(android.R.drawable.ic_menu_call)
|
||||
.setContentText(text)
|
||||
.setSmallIcon(R.drawable.ic_launcher_fg)
|
||||
.setOngoing(true)
|
||||
.setContentIntent(contentIntent)
|
||||
.build()
|
||||
startForeground(1, n)
|
||||
}
|
||||
@@ -86,7 +100,10 @@ class SvxService : Service(), ReflectorClient.Callbacks {
|
||||
|
||||
override fun onState(state: Int, detail: String?) {
|
||||
when (state) {
|
||||
ReflectorClient.STATE_READY -> engine.startDecoder()
|
||||
ReflectorClient.STATE_READY -> {
|
||||
updateNotification(getString(R.string.notif_connected))
|
||||
engine.startDecoder()
|
||||
}
|
||||
ReflectorClient.STATE_DISCONNECTED -> {
|
||||
engine.stopDecoder()
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
@@ -96,23 +113,47 @@ class SvxService : Service(), ReflectorClient.Callbacks {
|
||||
}
|
||||
|
||||
override fun onServerInfo(info: MsgParser.ServerInfo) {
|
||||
synchronized(nodeSet) {
|
||||
nodeSet.clear()
|
||||
nodeSet.addAll(info.nodes)
|
||||
}
|
||||
listener?.onServerInfo(info)
|
||||
}
|
||||
|
||||
private val nodeSet = LinkedHashSet<String>()
|
||||
private val nodeTgs = HashMap<String, Long>()
|
||||
|
||||
/** Текущий список узлов и известные группы (копия для UI). */
|
||||
fun nodeList(): List<Pair<String, Long?>> = synchronized(nodeSet) {
|
||||
nodeSet.map { it to nodeTgs[it] }
|
||||
}
|
||||
|
||||
override fun onNodeJoined(callsign: String, tg: Long?) {
|
||||
synchronized(nodeSet) { nodeSet.add(callsign) }
|
||||
listener?.onNodeJoined(callsign, tg)
|
||||
}
|
||||
|
||||
override fun onNodeLeft(callsign: String, tg: Long?) {
|
||||
synchronized(nodeSet) {
|
||||
nodeSet.remove(callsign)
|
||||
nodeTgs.remove(callsign)
|
||||
}
|
||||
listener?.onNodeLeft(callsign, tg)
|
||||
}
|
||||
|
||||
override fun onTalkerStart(tg: Long, callsign: String) {
|
||||
synchronized(nodeSet) {
|
||||
if (callsign in nodeSet) nodeTgs[callsign] = tg
|
||||
}
|
||||
updateNotification(getString(R.string.notif_talking, callsign))
|
||||
listener?.onTalkerStart(tg, callsign)
|
||||
}
|
||||
|
||||
override fun onTalkerStop(tg: Long, callsign: String) {
|
||||
updateNotification(getString(R.string.notif_last_talker, callsign))
|
||||
listener?.onTalkerStop(tg, callsign)
|
||||
}
|
||||
|
||||
override fun onNodeJoined(callsign: String) {
|
||||
}
|
||||
|
||||
override fun onNodeLeft(callsign: String) {
|
||||
}
|
||||
|
||||
override fun onAudioPacket(packet: ByteArray, seq: Int) {
|
||||
engine.onAudioPacket(packet)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ data class ConnectionSettings(
|
||||
val port: Int,
|
||||
val callsign: String,
|
||||
val authKey: String,
|
||||
val talkGroup: Long
|
||||
val talkGroup: Long,
|
||||
val groups: List<Long> = emptyList()
|
||||
)
|
||||
|
||||
object Prefs {
|
||||
@@ -21,7 +22,12 @@ object Prefs {
|
||||
port = sp.getInt("port", 5300),
|
||||
callsign = sp.getString("callsign", "") ?: "",
|
||||
authKey = sp.getString("auth_key", "") ?: "",
|
||||
talkGroup = sp.getLong("tg", 11)
|
||||
talkGroup = sp.getLong("tg", 11),
|
||||
groups = (sp.getString("groups", "") ?: "")
|
||||
.split(',')
|
||||
.mapNotNull { it.trim().toLongOrNull() }
|
||||
.distinct()
|
||||
.ifEmpty { listOf(9L, 11L, 12L, 13L) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -33,6 +39,17 @@ object Prefs {
|
||||
.putString("callsign", s.callsign.trim())
|
||||
.putString("auth_key", s.authKey)
|
||||
.putLong("tg", s.talkGroup)
|
||||
.putString("groups", s.groups.distinct().joinToString(","))
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun nodeToastsEnabled(context: Context): Boolean {
|
||||
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
.getBoolean("node_toasts", true)
|
||||
}
|
||||
|
||||
fun setNodeToastsEnabled(context: Context, enabled: Boolean) {
|
||||
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
.edit().putBoolean("node_toasts", enabled).apply()
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ class ReflectorClient(
|
||||
fun onServerInfo(info: MsgParser.ServerInfo)
|
||||
fun onTalkerStart(tg: Long, callsign: String)
|
||||
fun onTalkerStop(tg: Long, callsign: String)
|
||||
fun onNodeJoined(callsign: String)
|
||||
fun onNodeLeft(callsign: String)
|
||||
fun onNodeJoined(callsign: String, tg: Long?)
|
||||
fun onNodeLeft(callsign: String, tg: Long?)
|
||||
/** Входящий аудиопакет Opus. */
|
||||
fun onAudioPacket(packet: ByteArray, seq: Int)
|
||||
fun onAudioFlush()
|
||||
@@ -58,7 +58,9 @@ class ReflectorClient(
|
||||
val port: Int,
|
||||
val callsign: String,
|
||||
val authKey: String,
|
||||
val talkGroup: Long
|
||||
val talkGroup: Long,
|
||||
/** Список групп для мониторинга; null = обычный режим (своя группа). */
|
||||
val monitorTgs: List<Long>? = null
|
||||
)
|
||||
|
||||
@Volatile
|
||||
@@ -361,19 +363,25 @@ class ReflectorClient(
|
||||
// (иначе сервер не шлёт аудио группы и не показывает
|
||||
// подписку в статусе: monitoredTGs остаётся пустым).
|
||||
sendTcp(socket, MsgBuilder.nodeInfo(CLIENT_SW_INFO, CLIENT_SW_VERSION))
|
||||
val monitor = s.monitorTgs
|
||||
if (monitor.isNullOrEmpty()) {
|
||||
sendTcp(socket, MsgBuilder.selectTg(s.talkGroup))
|
||||
sendTcp(socket, MsgBuilder.tgMonitor(listOf(s.talkGroup)))
|
||||
} else {
|
||||
sendTcp(socket, MsgBuilder.selectTg(0))
|
||||
sendTcp(socket, MsgBuilder.tgMonitor(monitor))
|
||||
}
|
||||
openUdp(s)
|
||||
}
|
||||
|
||||
ReflectorProtocol.MSG_NODE_JOINED -> {
|
||||
val cs = parseSimpleString(msg.fields)
|
||||
callbacks.onNodeJoined(cs)
|
||||
val (cs, tg) = parseNodeEvent(msg.fields)
|
||||
callbacks.onNodeJoined(cs, tg)
|
||||
}
|
||||
|
||||
ReflectorProtocol.MSG_NODE_LEFT -> {
|
||||
val cs = parseSimpleString(msg.fields)
|
||||
callbacks.onNodeLeft(cs)
|
||||
val (cs, tg) = parseNodeEvent(msg.fields)
|
||||
callbacks.onNodeLeft(cs, tg)
|
||||
}
|
||||
|
||||
ReflectorProtocol.MSG_TALKER_START -> {
|
||||
@@ -404,6 +412,17 @@ class ReflectorClient(
|
||||
return true
|
||||
}
|
||||
|
||||
private fun parseNodeEvent(fields: ByteArray): Pair<String, Long?> {
|
||||
return try {
|
||||
val r = BinReader(fields)
|
||||
val cs = r.str().ifEmpty { "?" }
|
||||
val tg = try { r.str().toLongOrNull() } catch (_: Exception) { null }
|
||||
cs to tg
|
||||
} catch (_: Exception) {
|
||||
"?" to null
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseSimpleString(fields: ByteArray): String {
|
||||
return try {
|
||||
BinReader(fields).str().ifEmpty { "?" }
|
||||
|
||||
BIN
app/src/main/res/drawable-nodpi/ic_launcher_fg.png
Normal file
BIN
app/src/main/res/drawable-nodpi/ic_launcher_fg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
5
app/src/main/res/drawable/bg_monitor_on.xml
Normal file
5
app/src/main/res/drawable/bg_monitor_on.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="#3358A6FF" />
|
||||
</shape>
|
||||
7
app/src/main/res/drawable/bg_node_toast.xml
Normal file
7
app/src/main/res/drawable/bg_node_toast.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#E61B222A" />
|
||||
<corners android:radius="24dp" />
|
||||
<stroke android:width="1dp" android:color="#40FFFFFF" />
|
||||
</shape>
|
||||
10
app/src/main/res/drawable/ic_headset.xml
Normal file
10
app/src/main/res/drawable/ic_headset.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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="#8B949E"
|
||||
android:pathData="M12,1c-4.97,0 -9,4.03 -9,9v7c0,1.66 1.34,3 3,3h3v-8L5,12v-2c0,-3.87 3.13,-7 7,-7s7,3.13 7,7v2h-4v8h3c1.66,0 3,-1.34 3,-3v-7c0,-4.97 -4.03,-9 -9,-9z" />
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<group
|
||||
android:translateX="30"
|
||||
android:translateY="30"
|
||||
android:scaleX="1.5"
|
||||
android:scaleY="1.5">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z" />
|
||||
</group>
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_power.xml
Normal file
10
app/src/main/res/drawable/ic_power.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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="#8B949E"
|
||||
android:pathData="M13,3h-2v10h2L13,3zM17.83,5.17l-1.42,1.42C17.99,7.86 19,9.81 19,12c0,3.87 -3.13,7 -7,7s-7,-3.13 -7,-7c0,-2.19 1.01,-4.14 2.58,-5.41L6.17,5.17C4.23,6.82 3,9.26 3,12c0,4.97 4.03,9 9,9s9,-4.03 9,-9C21,9.26 19.77,6.82 17.83,5.17z" />
|
||||
</vector>
|
||||
@@ -14,6 +14,15 @@
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_power"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_power"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/btn_power"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
@@ -56,18 +65,45 @@
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lbl_callsign"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="28sp"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:text="@string/settings_not_configured" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_monitor"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:src="@drawable/ic_headset"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/btn_monitor"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lbl_tg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="14dp"
|
||||
android:textColor="@color/warn"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:fontFamily="monospace" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lbl_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -78,16 +114,6 @@
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lbl_tg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:textColor="@color/warn"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:fontFamily="monospace" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Статус соединения -->
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
android:id="@+id/input_tg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:inputType="number"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColorHint="@color/text_secondary"
|
||||
@@ -119,6 +119,35 @@
|
||||
android:padding="12dp"
|
||||
android:hint="11" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/pref_groups"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/input_groups"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:inputType="text"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColorHint="@color/text_secondary"
|
||||
android:textSize="16sp"
|
||||
android:background="@drawable/bg_input"
|
||||
android:padding="12dp"
|
||||
android:hint="9, 11, 12, 13" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/chk_node_toasts"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:text="@string/pref_node_toasts"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_save"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
20
app/src/main/res/layout/view_node_toast.xml
Normal file
20
app/src/main/res/layout/view_node_toast.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/node_toast_root"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_node_toast"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingTop="14dp"
|
||||
android:paddingBottom="14dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lbl_node_toast"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="#F0F0F0"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</FrameLayout>
|
||||
@@ -9,13 +9,28 @@
|
||||
<string name="pref_callsign">Позывной</string>
|
||||
<string name="pref_auth_key">Пароль (AUTH_KEY)</string>
|
||||
<string name="pref_tg">Группа вещания (TG)</string>
|
||||
<string name="pref_groups">Группы для переключения (через запятую)</string>
|
||||
<string name="select_tg">Выбор группы</string>
|
||||
<string name="toast_groups_empty">Добавьте группы в настройках</string>
|
||||
<string name="nodes_title">Узлы в сети (%1$d)</string>
|
||||
<string name="toast_nodes_empty">Нет подключенных узлов</string>
|
||||
<string name="pref_node_toasts">Всплывающее уведомление о подключении/отключении узлов</string>
|
||||
<string name="toast_node_joined">Подключился: %1$s%2$s</string>
|
||||
<string name="toast_node_left">Отключился: %1$s%2$s</string>
|
||||
<string name="node_tg_suffix"> (группа %1$d)</string>
|
||||
<string name="node_with_tg">%1$s — TG%2$d</string>
|
||||
<string name="btn_save">Сохранить</string>
|
||||
<string name="app_version">SVXhomyak — v1.0.2</string>
|
||||
<string name="app_version">SVXhomyak — v1.0.4</string>
|
||||
<string name="saved">Сохранено</string>
|
||||
<string name="pref_callsign_hint">например UA1ZBE</string>
|
||||
|
||||
<string name="status_disconnected">Отключено</string>
|
||||
<string name="app_title">SVXHomyak</string>
|
||||
<string name="btn_power">Выключить: отключиться и закрыть</string>
|
||||
<string name="btn_monitor">Мониторинг групп (нажмите, чтобы включить)</string>
|
||||
<string name="btn_monitor_on">Мониторинг групп включен (нажмите, чтобы выключить)</string>
|
||||
<string name="status_monitoring">Мониторинг: %1$s</string>
|
||||
<string name="talker_mon">Говорит: %1$s · TG%2$d</string>
|
||||
<string name="status_big_disconnected">DISCONNECTED</string>
|
||||
<string name="status_big_connected">CONNECTED</string>
|
||||
<string name="status_big_talking">ПЕРЕДАЧА</string>
|
||||
@@ -26,7 +41,7 @@
|
||||
<string name="meter_mic">MIC</string>
|
||||
<string name="meter_idle">---</string>
|
||||
<string name="meter_db">-%1$d dB</string>
|
||||
<string name="tg_badge">TG%1$d</string>
|
||||
<string name="tg_badge">TG%1$d ▾</string>
|
||||
<string name="talker_last_none">Последний: —</string>
|
||||
<string name="status_connecting">Подключение…</string>
|
||||
<string name="status_connecting_ssl">Проверка ключа…</string>
|
||||
@@ -34,6 +49,8 @@
|
||||
<string name="status_auth_failed">Ошибка авторизации</string>
|
||||
<string name="status_error">Ошибка: %1$s</string>
|
||||
<string name="notif_connected">Соединение с рефлектором активно</string>
|
||||
<string name="notif_talking">Говорит: %1$s</string>
|
||||
<string name="notif_last_talker">Последний: %1$s</string>
|
||||
|
||||
<string name="btn_connect">Подключиться</string>
|
||||
<string name="btn_disconnect">Отключиться</string>
|
||||
|
||||
Reference in New Issue
Block a user