mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 20:01:50 +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 eu.kanade.tachiyomi.util.lang.withIOContext
|
||||||
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 {
|
suspend fun checkForUpdate(context: Context): AppUpdateResult {
|
||||||
if (BuildConfig.PREVIEW) {
|
// Limit checks to once a day at most
|
||||||
"tachiyomiorg/tachiyomi-preview"
|
if (Date().time < preferences.lastAppCheck().get() + TimeUnit.DAYS.toMillis(1)) {
|
||||||
} else {
|
return AppUpdateResult.NoNewUpdate
|
||||||
"tachiyomiorg/tachiyomi"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun checkForUpdate(context: Context): AppUpdateResult {
|
|
||||||
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 {
|
||||||
@ -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 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 {
|
||||||
|
|
||||||
@ -30,6 +31,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)
|
||||||
|
@ -9,6 +9,10 @@ import com.bluelinelabs.conductor.RouterTransaction
|
|||||||
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) {
|
||||||
|
@ -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.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
|
||||||
@ -69,8 +70,6 @@ import kotlinx.coroutines.flow.drop
|
|||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import java.util.Date
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||||
|
|
||||||
@ -153,11 +152,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) {
|
||||||
@ -322,19 +321,13 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
checkForExtensionUpdates()
|
checkForUpdates()
|
||||||
if (BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
checkForAppUpdates()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
lifecycleScope.launchIO {
|
||||||
|
// App updates
|
||||||
|
if (BuildConfig.INCLUDE_UPDATER) {
|
||||||
try {
|
try {
|
||||||
val result = AppUpdateChecker().checkForUpdate(this@MainActivity)
|
val result = AppUpdateChecker().checkForUpdate(this@MainActivity)
|
||||||
if (result is AppUpdateResult.NewUpdate) {
|
if (result is AppUpdateResult.NewUpdate) {
|
||||||
@ -344,15 +337,8 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
logcat(LogPriority.ERROR, e)
|
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)
|
||||||
@ -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) {
|
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…
Reference in New Issue
Block a user