|
|
@@ -60,6 +60,7 @@ class WebService : BaseService() {
|
|
|
}
|
|
|
private var httpServer: HttpServer? = null
|
|
|
private var webSocketServer: WebSocketServer? = null
|
|
|
+ private var notificationList = mutableListOf(appCtx.getString(R.string.service_starting))
|
|
|
private var notificationContent = appCtx.getString(R.string.service_starting)
|
|
|
private val networkChangedListener by lazy {
|
|
|
NetworkChangedListener(this)
|
|
|
@@ -77,14 +78,14 @@ class WebService : BaseService() {
|
|
|
networkChangedListener.register()
|
|
|
networkChangedListener.onNetworkChanged = {
|
|
|
val addressList = NetworkUtils.getLocalIPAddress()
|
|
|
+ notificationList.clear()
|
|
|
if (addressList.any()) {
|
|
|
- val hostList = addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }
|
|
|
- hostAddress = hostList.first()
|
|
|
- notificationContent = hostList.joinToString(separator = "\n")
|
|
|
+ notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
|
|
|
+ hostAddress = notificationList.first()
|
|
|
startForegroundNotification()
|
|
|
} else {
|
|
|
hostAddress = getString(R.string.network_connection_unavailable)
|
|
|
- notificationContent = hostAddress
|
|
|
+ notificationList.add(hostAddress)
|
|
|
startForegroundNotification()
|
|
|
}
|
|
|
postEvent(EventBus.WEB_SERVICE, hostAddress)
|
|
|
@@ -139,9 +140,9 @@ class WebService : BaseService() {
|
|
|
try {
|
|
|
httpServer?.start()
|
|
|
webSocketServer?.start(1000 * 30) // 通信超时设置
|
|
|
- val hostList = addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }
|
|
|
- hostAddress = hostList.first()
|
|
|
- notificationContent = hostList.joinToString(separator = "\n")
|
|
|
+ notificationList.clear()
|
|
|
+ notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
|
|
|
+ hostAddress = notificationList.first()
|
|
|
isRun = true
|
|
|
postEvent(EventBus.WEB_SERVICE, hostAddress)
|
|
|
startForegroundNotification()
|
|
|
@@ -172,7 +173,7 @@ class WebService : BaseService() {
|
|
|
.setSmallIcon(R.drawable.ic_web_service_noti)
|
|
|
.setOngoing(true)
|
|
|
.setContentTitle(getString(R.string.web_service))
|
|
|
- .setContentText(notificationContent)
|
|
|
+ .setContentText(notificationList.joinToString("\n"))
|
|
|
.setContentIntent(
|
|
|
servicePendingIntent<WebService>("copyHostAddress")
|
|
|
)
|