Minor cleanup
(cherry picked from commit 93e2b88d41143b7485172a29bb40b7ed5478a0ac) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt # app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
This commit is contained in:
parent
8d291b1bc3
commit
e28d72bf9c
@ -11,26 +11,22 @@ import eu.kanade.tachiyomi.util.lang.withIOContext
|
|||||||
import exh.syDebugVersion
|
import exh.syDebugVersion
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class AppUpdateChecker {
|
class AppUpdateChecker {
|
||||||
|
|
||||||
private val networkService: NetworkHelper by injectLazy()
|
private val networkService: NetworkHelper by injectLazy()
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
private val repo: String by lazy {
|
|
||||||
// Sy -->
|
|
||||||
if (syDebugVersion != "0") {
|
|
||||||
"jobobby04/TachiyomiSYPreview"
|
|
||||||
} else {
|
|
||||||
"jobobby04/tachiyomiSY"
|
|
||||||
}
|
|
||||||
// SY <--
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun checkForUpdate(context: Context): AppUpdateResult {
|
suspend fun checkForUpdate(context: Context): AppUpdateResult {
|
||||||
|
// Limit checks to once a day at most
|
||||||
|
if (Date().time < preferences.lastAppCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
||||||
|
return AppUpdateResult.NoNewUpdate
|
||||||
|
}
|
||||||
|
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val result = networkService.client
|
val result = networkService.client
|
||||||
.newCall(GET("https://api.github.com/repos/$repo/releases/latest"))
|
.newCall(GET("https://api.github.com/repos/$GITHUB_REPO/releases/latest"))
|
||||||
.await()
|
.await()
|
||||||
.parseAs<GithubRelease>()
|
.parseAs<GithubRelease>()
|
||||||
.let {
|
.let {
|
||||||
@ -71,3 +67,13 @@ class AppUpdateChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val GITHUB_REPO: String by lazy {
|
||||||
|
// Sy -->
|
||||||
|
if (syDebugVersion != "0") {
|
||||||
|
"jobobby04/TachiyomiSYPreview"
|
||||||
|
} else {
|
||||||
|
"jobobby04/tachiyomiSY"
|
||||||
|
}
|
||||||
|
// SY <--
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ import exh.source.BlacklistedSources
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
internal class ExtensionGithubApi {
|
internal class ExtensionGithubApi {
|
||||||
|
|
||||||
@ -39,6 +40,11 @@ internal class ExtensionGithubApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun checkForUpdates(context: Context): List<Extension.Installed> {
|
suspend fun checkForUpdates(context: Context): List<Extension.Installed> {
|
||||||
|
// Limit checks to once a day at most
|
||||||
|
if (Date().time < preferences.lastExtCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
val extensions = findExtensions()
|
val extensions = findExtensions()
|
||||||
|
|
||||||
preferences.lastExtCheck().set(Date().time)
|
preferences.lastExtCheck().set(Date().time)
|
||||||
|
@ -10,6 +10,10 @@ import eu.kanade.tachiyomi.ui.base.changehandler.OneWayFadeChangeHandler
|
|||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||||
|
|
||||||
|
fun Router.setRoot(controller: Controller, id: Int) {
|
||||||
|
setRoot(controller.withFadeTransaction().tag(id.toString()))
|
||||||
|
}
|
||||||
|
|
||||||
fun Router.popControllerWithTag(tag: String): Boolean {
|
fun Router.popControllerWithTag(tag: String): Boolean {
|
||||||
val controller = getControllerWithTag(tag)
|
val controller = getControllerWithTag(tag)
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
|
@ -46,6 +46,7 @@ import eu.kanade.tachiyomi.ui.base.controller.FabController
|
|||||||
import eu.kanade.tachiyomi.ui.base.controller.NoAppBarElevationController
|
import eu.kanade.tachiyomi.ui.base.controller.NoAppBarElevationController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
||||||
|
import eu.kanade.tachiyomi.ui.base.controller.setRoot
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.browse.BrowseController
|
import eu.kanade.tachiyomi.ui.browse.BrowseController
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
|
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
|
||||||
@ -180,11 +181,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
val currentRoot = router.backstack.firstOrNull()
|
val currentRoot = router.backstack.firstOrNull()
|
||||||
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.nav_library -> setRoot(LibraryController(), id)
|
R.id.nav_library -> router.setRoot(LibraryController(), id)
|
||||||
R.id.nav_updates -> setRoot(UpdatesController(), id)
|
R.id.nav_updates -> router.setRoot(UpdatesController(), id)
|
||||||
R.id.nav_history -> setRoot(HistoryController(), id)
|
R.id.nav_history -> router.setRoot(HistoryController(), id)
|
||||||
R.id.nav_browse -> setRoot(BrowseController(), id)
|
R.id.nav_browse -> router.setRoot(BrowseController(), id)
|
||||||
R.id.nav_more -> setRoot(MoreController(), id)
|
R.id.nav_more -> router.setRoot(MoreController(), id)
|
||||||
}
|
}
|
||||||
} else if (!isHandlingShortcut) {
|
} else if (!isHandlingShortcut) {
|
||||||
when (id) {
|
when (id) {
|
||||||
@ -376,37 +377,24 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
checkForExtensionUpdates()
|
checkForUpdates()
|
||||||
if (BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
checkForAppUpdates()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForAppUpdates() {
|
private fun checkForUpdates() {
|
||||||
// Limit checks to once a day at most
|
|
||||||
if (Date().time < preferences.lastAppCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
lifecycleScope.launchIO {
|
lifecycleScope.launchIO {
|
||||||
try {
|
// App updates
|
||||||
val result = AppUpdateChecker().checkForUpdate(this@MainActivity)
|
if (BuildConfig.INCLUDE_UPDATER) {
|
||||||
if (result is AppUpdateResult.NewUpdate) {
|
try {
|
||||||
NewUpdateDialogController(result).showDialog(router)
|
val result = AppUpdateChecker().checkForUpdate(this@MainActivity)
|
||||||
|
if (result is AppUpdateResult.NewUpdate) {
|
||||||
|
NewUpdateDialogController(result).showDialog(router)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR, e)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
logcat(LogPriority.ERROR, e)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkForExtensionUpdates() {
|
// Extension updates
|
||||||
// Limit checks to once a day at most
|
|
||||||
if (Date().time < preferences.lastExtCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
lifecycleScope.launchIO {
|
|
||||||
try {
|
try {
|
||||||
val pendingUpdates = ExtensionGithubApi().checkForUpdates(this@MainActivity)
|
val pendingUpdates = ExtensionGithubApi().checkForUpdates(this@MainActivity)
|
||||||
preferences.extensionUpdatesCount().set(pendingUpdates.size)
|
preferences.extensionUpdatesCount().set(pendingUpdates.size)
|
||||||
@ -556,10 +544,6 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setRoot(controller: Controller, id: Int) {
|
|
||||||
router.setRoot(controller.withFadeTransaction().tag(id.toString()))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun syncActivityViewWithController(to: Controller?, from: Controller? = null, isPush: Boolean = true) {
|
private fun syncActivityViewWithController(to: Controller?, from: Controller? = null, isPush: Boolean = true) {
|
||||||
if (from is DialogController || to is DialogController) {
|
if (from is DialogController || to is DialogController) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user