mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-14 04:35:05 +01:00
Minor cleanup
This commit is contained in:
parent
7cd54dc8f0
commit
93e2b88d41
@ -10,24 +10,22 @@ import eu.kanade.tachiyomi.network.parseAs
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class AppUpdateChecker {
|
||||
|
||||
private val networkService: NetworkHelper by injectLazy()
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
private val repo: String by lazy {
|
||||
if (BuildConfig.PREVIEW) {
|
||||
"tachiyomiorg/tachiyomi-preview"
|
||||
} else {
|
||||
"tachiyomiorg/tachiyomi"
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
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()
|
||||
.parseAs<GithubRelease>()
|
||||
.let {
|
||||
@ -64,3 +62,11 @@ class AppUpdateChecker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val GITHUB_REPO: String by lazy {
|
||||
if (BuildConfig.PREVIEW) {
|
||||
"tachiyomiorg/tachiyomi-preview"
|
||||
} else {
|
||||
"tachiyomiorg/tachiyomi"
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import kotlinx.serialization.Serializable
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
internal class ExtensionGithubApi {
|
||||
|
||||
@ -30,6 +31,11 @@ internal class ExtensionGithubApi {
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
preferences.lastExtCheck().set(Date().time)
|
||||
|
@ -9,6 +9,10 @@ import com.bluelinelabs.conductor.RouterTransaction
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
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 {
|
||||
val controller = getControllerWithTag(tag)
|
||||
if (controller != null) {
|
||||
|
@ -45,6 +45,7 @@ import eu.kanade.tachiyomi.ui.base.controller.FabController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NoAppBarElevationController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||
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.browse.BrowseController
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
|
||||
@ -69,8 +70,6 @@ import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import logcat.LogPriority
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
|
||||
@ -153,11 +152,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
val currentRoot = router.backstack.firstOrNull()
|
||||
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
||||
when (id) {
|
||||
R.id.nav_library -> setRoot(LibraryController(), id)
|
||||
R.id.nav_updates -> setRoot(UpdatesController(), id)
|
||||
R.id.nav_history -> setRoot(HistoryController(), id)
|
||||
R.id.nav_browse -> setRoot(BrowseController(), id)
|
||||
R.id.nav_more -> setRoot(MoreController(), id)
|
||||
R.id.nav_library -> router.setRoot(LibraryController(), id)
|
||||
R.id.nav_updates -> router.setRoot(UpdatesController(), id)
|
||||
R.id.nav_history -> router.setRoot(HistoryController(), id)
|
||||
R.id.nav_browse -> router.setRoot(BrowseController(), id)
|
||||
R.id.nav_more -> router.setRoot(MoreController(), id)
|
||||
}
|
||||
} else if (!isHandlingShortcut) {
|
||||
when (id) {
|
||||
@ -322,37 +321,24 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
checkForExtensionUpdates()
|
||||
if (BuildConfig.INCLUDE_UPDATER) {
|
||||
checkForAppUpdates()
|
||||
}
|
||||
checkForUpdates()
|
||||
}
|
||||
|
||||
private fun checkForAppUpdates() {
|
||||
// Limit checks to once a day at most
|
||||
if (Date().time < preferences.lastAppCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
||||
return
|
||||
}
|
||||
|
||||
private fun checkForUpdates() {
|
||||
lifecycleScope.launchIO {
|
||||
try {
|
||||
val result = AppUpdateChecker().checkForUpdate(this@MainActivity)
|
||||
if (result is AppUpdateResult.NewUpdate) {
|
||||
NewUpdateDialogController(result).showDialog(router)
|
||||
// App updates
|
||||
if (BuildConfig.INCLUDE_UPDATER) {
|
||||
try {
|
||||
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() {
|
||||
// Limit checks to once a day at most
|
||||
if (Date().time < preferences.lastExtCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
||||
return
|
||||
}
|
||||
|
||||
lifecycleScope.launchIO {
|
||||
// Extension updates
|
||||
try {
|
||||
val pendingUpdates = ExtensionGithubApi().checkForUpdates(this@MainActivity)
|
||||
preferences.extensionUpdatesCount().set(pendingUpdates.size)
|
||||
@ -502,10 +488,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) {
|
||||
if (from is DialogController || to is DialogController) {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user