mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-14 04:35:05 +01:00
Add notification action to open GitHub release page
Co-authored-by: Jays2Kings <Jays2Kings@users.noreply.github.com>
This commit is contained in:
parent
a8c8f15e07
commit
3d8f123e05
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.data.updater
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
@ -23,9 +24,9 @@ class AppUpdateChecker {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun checkForUpdate(): AppUpdateResult {
|
||||
suspend fun checkForUpdate(context: Context): AppUpdateResult {
|
||||
return withIOContext {
|
||||
networkService.client
|
||||
val result = networkService.client
|
||||
.newCall(GET("https://api.github.com/repos/$repo/releases/latest"))
|
||||
.await()
|
||||
.parseAs<GithubRelease>()
|
||||
@ -39,6 +40,12 @@ class AppUpdateChecker {
|
||||
AppUpdateResult.NoNewUpdate
|
||||
}
|
||||
}
|
||||
|
||||
if (result is AppUpdateResult.NewUpdate) {
|
||||
AppUpdateNotifier(context).promptUpdate(result.release)
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,7 @@ class AppUpdateJob(private val context: Context, workerParams: WorkerParameters)
|
||||
|
||||
override suspend fun doWork() = coroutineScope {
|
||||
try {
|
||||
val result = AppUpdateChecker().checkForUpdate()
|
||||
if (result is AppUpdateResult.NewUpdate) {
|
||||
AppUpdateNotifier(context).promptUpdate(result.release.getDownloadLink())
|
||||
}
|
||||
AppUpdateChecker().checkForUpdate(context)
|
||||
Result.success()
|
||||
} catch (e: Exception) {
|
||||
Result.failure()
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.net.toUri
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
@ -25,22 +26,32 @@ internal class AppUpdateNotifier(private val context: Context) {
|
||||
context.notificationManager.notify(id, build())
|
||||
}
|
||||
|
||||
fun promptUpdate(url: String) {
|
||||
fun promptUpdate(release: GithubRelease) {
|
||||
val intent = Intent(context, AppUpdateService::class.java).apply {
|
||||
putExtra(AppUpdateService.EXTRA_DOWNLOAD_URL, url)
|
||||
putExtra(AppUpdateService.EXTRA_DOWNLOAD_URL, release.getDownloadLink())
|
||||
}
|
||||
val pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val updateIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val releaseIntent = Intent(Intent.ACTION_VIEW, release.releaseLink.toUri()).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
}
|
||||
val releaseInfoIntent = PendingIntent.getActivity(context, release.hashCode(), releaseIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
|
||||
with(notificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.update_check_notification_update_available))
|
||||
setContentTitle(context.getString(R.string.update_check_notification_update_available))
|
||||
setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
setContentIntent(pendingIntent)
|
||||
setContentIntent(updateIntent)
|
||||
|
||||
clearActions()
|
||||
addAction(
|
||||
android.R.drawable.stat_sys_download_done,
|
||||
context.getString(R.string.action_download),
|
||||
pendingIntent
|
||||
updateIntent,
|
||||
)
|
||||
addAction(
|
||||
R.drawable.ic_info_24dp,
|
||||
context.getString(R.string.whats_new),
|
||||
releaseInfoIntent,
|
||||
)
|
||||
}
|
||||
notificationBuilder.show()
|
||||
|
@ -5,17 +5,13 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Release object.
|
||||
* Contains information about the latest release from GitHub.
|
||||
*
|
||||
* @param version version of latest release.
|
||||
* @param info log of latest release.
|
||||
* @param assets assets of latest release.
|
||||
*/
|
||||
@Serializable
|
||||
data class GithubRelease(
|
||||
@SerialName("tag_name") val version: String,
|
||||
@SerialName("body") val info: String,
|
||||
@SerialName("html_url") val releaseLink: String,
|
||||
@SerialName("assets") private val assets: List<Assets>
|
||||
) {
|
||||
|
||||
@ -37,7 +33,6 @@ data class GithubRelease(
|
||||
|
||||
/**
|
||||
* Assets class containing download url.
|
||||
* @param downloadLink download url.
|
||||
*/
|
||||
@Serializable
|
||||
data class Assets(@SerialName("browser_download_url") val downloadLink: String)
|
||||
|
@ -336,7 +336,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
|
||||
lifecycleScope.launchIO {
|
||||
try {
|
||||
val result = AppUpdateChecker().checkForUpdate()
|
||||
val result = AppUpdateChecker().checkForUpdate(this@MainActivity)
|
||||
if (result is AppUpdateResult.NewUpdate) {
|
||||
NewUpdateDialogController(result).showDialog(router)
|
||||
}
|
||||
|
@ -107,11 +107,11 @@ class AboutController : SettingsController(), NoAppBarElevationController {
|
||||
private fun checkVersion() {
|
||||
if (activity == null) return
|
||||
|
||||
activity?.toast(R.string.update_check_look_for_updates)
|
||||
activity!!.toast(R.string.update_check_look_for_updates)
|
||||
|
||||
launchNow {
|
||||
try {
|
||||
when (val result = updateChecker.checkForUpdate()) {
|
||||
when (val result = updateChecker.checkForUpdate(activity!!)) {
|
||||
is AppUpdateResult.NewUpdate -> {
|
||||
NewUpdateDialogController(result).showDialog(router)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user