|
|
|
@ -9,6 +9,7 @@ import android.graphics.BitmapFactory
|
|
|
|
import android.net.Uri
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Build
|
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
|
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
import kotlinx.coroutines.CancellationException
|
|
|
|
import kotlinx.coroutines.CancellationException
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
@ -80,8 +81,18 @@ class AppUpdateService : BaseService() {
|
|
|
|
PendingIntent.FLAG_CANCEL_CURRENT
|
|
|
|
PendingIntent.FLAG_CANCEL_CURRENT
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
builder.addAction(
|
|
|
|
|
|
|
|
R.drawable.ic_download, getString(R.string.download),
|
|
|
|
|
|
|
|
PendingIntent.getActivity(
|
|
|
|
|
|
|
|
this,
|
|
|
|
|
|
|
|
NOTIFICATION_ID + 1,
|
|
|
|
|
|
|
|
Intent(Intent.ACTION_VIEW, Uri.parse(newVersion.apkUrl)),
|
|
|
|
|
|
|
|
PendingIntent.FLAG_CANCEL_CURRENT
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
builder.setSmallIcon(R.drawable.ic_stat_update)
|
|
|
|
builder.setSmallIcon(R.drawable.ic_stat_update)
|
|
|
|
builder.setAutoCancel(true)
|
|
|
|
builder.setAutoCancel(true)
|
|
|
|
|
|
|
|
builder.setColor(ContextCompat.getColor(this, R.color.blue_primary_dark))
|
|
|
|
builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
|
|
|
|
builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
|
|
|
|
manager.notify(NOTIFICATION_ID, builder.build())
|
|
|
|
manager.notify(NOTIFICATION_ID, builder.build())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -92,8 +103,12 @@ class AppUpdateService : BaseService() {
|
|
|
|
private const val CHANNEL_ID = "update"
|
|
|
|
private const val CHANNEL_ID = "update"
|
|
|
|
private val PERIOD = TimeUnit.HOURS.toMillis(6)
|
|
|
|
private val PERIOD = TimeUnit.HOURS.toMillis(6)
|
|
|
|
|
|
|
|
|
|
|
|
fun start(context: Context) =
|
|
|
|
fun start(context: Context) {
|
|
|
|
context.startService(Intent(context, AppUpdateService::class.java))
|
|
|
|
try {
|
|
|
|
|
|
|
|
context.startService(Intent(context, AppUpdateService::class.java))
|
|
|
|
|
|
|
|
} catch (_: IllegalStateException) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun startIfRequired(context: Context) {
|
|
|
|
fun startIfRequired(context: Context) {
|
|
|
|
val settings = AppSettings(context)
|
|
|
|
val settings = AppSettings(context)
|
|
|
|
|