if (intent.action == ACTION_STOP_DOWNLOADING) {
Log.d(TAG, "onStartCommand, ACTION_STOP_DOWNLOADING")
mapLoaderBinder.stop()
} else {
Log.d(TAG, "onStartCommand, start foreground")
val contentTitle = intent.getStringExtra(KEY_TITLE)
val contentText = intent.getStringExtra(KEY_TEXT)
val notificationIntent = Intent(this, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
val notification = AppNotificationCompat.Builder(this, NotificationUtils.DOWNLOADING_MAP_CHANNEL_ID)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSmallIcon(R.drawable.ic_file_download)
.setOngoing(true)
.setContentIntent(pendingIntent)
startForeground(1612, notification.build())
}
return START_STICKY
}
fun showDownloadProgress(fileName: String, progressValue: Int) {
val notificationBuilder = NotificationCompat.Builder(App.instance, DOWNLOADING_MAP_CHANNEL_ID)
val contentIntent = Intent(App.instance, MainActivity::class.java)
val contentPendingIntent = PendingIntent.getActivity(App.instance, 0, contentIntent, 0)
val buttonCloseIntent = Intent(App.instance, MapLoadingService::class.java)
buttonCloseIntent.action = MapLoadingService.ACTION_STOP_DOWNLOADING
val buttonClosePendingIntent = PendingIntent.getService(App.instance, 0, buttonCloseIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val stopButtonAction = NotificationCompat.Action.Builder(R.drawable.ic_stop, "Stop", buttonClosePendingIntent).build()
notificationBuilder
.setSmallIcon(R.drawable.ic_file_download)
.setPriority(Notification.PRIORITY_LOW)
.setContentTitle("Loading map file")
.setContentText(fileName)
.setContentInfo(progressValue.toString())
.setProgress(100, progressValue, false)
//.setContentIntent(contentPendingIntent)
.addAction(stopButtonAction)
val notificationManager = App.instance.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, notificationBuilder.build())
}