|
|
|
|
@ -16,6 +16,7 @@ import com.utun.chat.data.LogManager
|
|
|
|
|
import com.utun.chat.data.NativeLib |
|
|
|
|
import com.utun.chat.data.NetworkActivityMonitor |
|
|
|
|
import com.utun.chat.data.NetworkChangeMonitor |
|
|
|
|
import com.utun.chat.data.fileStatusResource |
|
|
|
|
|
|
|
|
|
class HeadlessService : Service() { |
|
|
|
|
companion object { |
|
|
|
|
@ -27,6 +28,11 @@ class HeadlessService : Service() {
|
|
|
|
|
service.getSystemService(NotificationManager::class.java).notify(1, service.notification()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fun refreshFiles() { |
|
|
|
|
currentService?.let { service -> |
|
|
|
|
service.getSystemService(NotificationManager::class.java).notify(1, service.notification()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreate() { |
|
|
|
|
@ -67,23 +73,43 @@ class HeadlessService : Service() {
|
|
|
|
|
override fun onBind(intent: Intent?): IBinder? = null |
|
|
|
|
|
|
|
|
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { |
|
|
|
|
if (intent?.action == "com.utun.chat.CANCEL_FILES") { |
|
|
|
|
ChatApplication.instance.memberFiles.cancel() |
|
|
|
|
return START_STICKY |
|
|
|
|
} |
|
|
|
|
val source = if (intent == null) "sticky_restart" else intent.action ?: "manual" |
|
|
|
|
LogManager.addLog("INFO", "SRV", "Service start command: source=$source startId=$startId flags=$flags ready=${NativeLib.isReady()}") |
|
|
|
|
return START_STICKY |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun notification(): android.app.Notification { |
|
|
|
|
val operation = ChatApplication.instance.memberFiles.operation.value |
|
|
|
|
val intent = Intent(this, MainActivity::class.java) |
|
|
|
|
operation?.let { op -> |
|
|
|
|
intent.putExtra("files_group", op.location.group).putExtra("files_server", op.location.server) |
|
|
|
|
.putExtra("files_owner", op.location.owner).putExtra("files_path", op.location.path) |
|
|
|
|
} |
|
|
|
|
val pendingIntent = PendingIntent.getActivity(this, 0, intent, |
|
|
|
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
return NotificationCompat.Builder(AppLanguage.context(), "utun_channel") |
|
|
|
|
val builder = NotificationCompat.Builder(AppLanguage.context(), "utun_channel") |
|
|
|
|
.setContentTitle("vibechat") |
|
|
|
|
.setContentText(AppLanguage.text(R.string.service_notification)) |
|
|
|
|
.setSmallIcon(android.R.drawable.ic_dialog_info) |
|
|
|
|
.setContentIntent(pendingIntent) |
|
|
|
|
.setOngoing(true) |
|
|
|
|
.setOnlyAlertOnce(true) |
|
|
|
|
.build() |
|
|
|
|
if (operation != null) { |
|
|
|
|
val detail = operation.status?.let { AppLanguage.text(fileStatusResource(it)) } ?: AppLanguage.text(operation.stage) |
|
|
|
|
builder.setContentText("${operation.name}: $detail") |
|
|
|
|
if (operation.active) { |
|
|
|
|
val percent = if (operation.total == 0L) 0 else (operation.done.toDouble() * 100 / operation.total).toInt() |
|
|
|
|
builder.setProgress(100, percent, operation.total == 0L) |
|
|
|
|
val cancel = PendingIntent.getService(this, 21, Intent(this, HeadlessService::class.java) |
|
|
|
|
.setAction("com.utun.chat.CANCEL_FILES"), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
builder.addAction(android.R.drawable.ic_menu_close_clear_cancel, AppLanguage.text(R.string.cancel), cancel) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return builder.build() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun createNotificationChannel() { |
|
|
|
|
|