Re-schedule EHentai updater job on app boot
Idle-until-urgent some stuff in app init Close debug menu onStop
This commit is contained in:
parent
7a3f6e9f63
commit
d5f4db5eb7
@ -10,6 +10,7 @@ import android.content.Intent
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Looper
|
||||||
import android.support.v4.view.GravityCompat
|
import android.support.v4.view.GravityCompat
|
||||||
import android.support.v4.widget.DrawerLayout
|
import android.support.v4.widget.DrawerLayout
|
||||||
import android.support.v7.graphics.drawable.DrawerArrowDrawable
|
import android.support.v7.graphics.drawable.DrawerArrowDrawable
|
||||||
@ -42,8 +43,11 @@ import android.text.TextUtils
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.kanade.tachiyomi.util.vibrate
|
import eu.kanade.tachiyomi.util.vibrate
|
||||||
import exh.EXHMigrations
|
import exh.EXHMigrations
|
||||||
|
import exh.eh.EHentaiUpdateWorker
|
||||||
import exh.ui.migration.MetadataFetchDialog
|
import exh.ui.migration.MetadataFetchDialog
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : BaseActivity() {
|
class MainActivity : BaseActivity() {
|
||||||
@ -66,6 +70,35 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
lateinit var tabAnimator: TabsAnimator
|
lateinit var tabAnimator: TabsAnimator
|
||||||
|
|
||||||
|
// Idle-until-urgent
|
||||||
|
private var firstPaint = false
|
||||||
|
private val iuuQueue = LinkedList<() -> Unit>()
|
||||||
|
|
||||||
|
private fun initWhenIdle(task: () -> Unit) {
|
||||||
|
// Avoid sync issues by enforcing main thread
|
||||||
|
if(Looper.myLooper() != Looper.getMainLooper())
|
||||||
|
throw IllegalStateException("Can only be called on main thread!")
|
||||||
|
|
||||||
|
if(firstPaint) {
|
||||||
|
task()
|
||||||
|
} else {
|
||||||
|
iuuQueue += task
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
if(!firstPaint) {
|
||||||
|
drawer.postDelayed({
|
||||||
|
if(!firstPaint) {
|
||||||
|
firstPaint = true
|
||||||
|
iuuQueue.forEach { it() }
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setTheme(when (preferences.theme()) {
|
setTheme(when (preferences.theme()) {
|
||||||
2 -> R.style.Theme_Tachiyomi_Dark
|
2 -> R.style.Theme_Tachiyomi_Dark
|
||||||
@ -151,6 +184,7 @@ class MainActivity : BaseActivity() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// --> EH
|
// --> EH
|
||||||
|
initWhenIdle {
|
||||||
//Hook long press hamburger menu to lock
|
//Hook long press hamburger menu to lock
|
||||||
getToolbarNavigationIcon(toolbar)?.setOnLongClickListener {
|
getToolbarNavigationIcon(toolbar)?.setOnLongClickListener {
|
||||||
if(lockEnabled(preferences)) {
|
if(lockEnabled(preferences)) {
|
||||||
@ -159,6 +193,7 @@ class MainActivity : BaseActivity() {
|
|||||||
true
|
true
|
||||||
} else false
|
} else false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Show lock
|
//Show lock
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@ -186,6 +221,8 @@ class MainActivity : BaseActivity() {
|
|||||||
if(EXHMigrations.upgrade(preferences)) {
|
if(EXHMigrations.upgrade(preferences)) {
|
||||||
ChangelogDialogController().showDialog(router)
|
ChangelogDialogController().showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initWhenIdle {
|
||||||
// Migrate metadata if empty (EH)
|
// Migrate metadata if empty (EH)
|
||||||
if(!preferences.migrateLibraryAsked().getOrDefault()) {
|
if(!preferences.migrateLibraryAsked().getOrDefault()) {
|
||||||
MetadataFetchDialog().askMigration(this, false)
|
MetadataFetchDialog().askMigration(this, false)
|
||||||
@ -195,6 +232,12 @@ class MainActivity : BaseActivity() {
|
|||||||
if(preferences.enableExhentai().getOrDefault()
|
if(preferences.enableExhentai().getOrDefault()
|
||||||
&& preferences.eh_showSettingsUploadWarning().getOrDefault())
|
&& preferences.eh_showSettingsUploadWarning().getOrDefault())
|
||||||
WarnConfigureDialogController.uploadSettings(router)
|
WarnConfigureDialogController.uploadSettings(router)
|
||||||
|
|
||||||
|
// Scheduler uploader job if required
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
EHentaiUpdateWorker.scheduleBackground(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
// EXH <--
|
// EXH <--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
|
import eu.kanade.tachiyomi.util.jobScheduler
|
||||||
import exh.EH_SOURCE_ID
|
import exh.EH_SOURCE_ID
|
||||||
import exh.EXH_SOURCE_ID
|
import exh.EXH_SOURCE_ID
|
||||||
import exh.eh.EHentaiUpdateWorker
|
import exh.eh.EHentaiUpdateWorker
|
||||||
@ -52,7 +53,7 @@ object DebugFunctions {
|
|||||||
|
|
||||||
fun convertAllExhentaiGalleriesToEhentai() = convertSources(EXH_SOURCE_ID, EH_SOURCE_ID)
|
fun convertAllExhentaiGalleriesToEhentai() = convertSources(EXH_SOURCE_ID, EH_SOURCE_ID)
|
||||||
|
|
||||||
fun testLaunchBackgroundUpdater() {
|
fun testLaunchEhentaiBackgroundUpdater() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
EHentaiUpdateWorker.launchBackgroundTest(app)
|
EHentaiUpdateWorker.launchBackgroundTest(app)
|
||||||
} else {
|
} else {
|
||||||
@ -60,6 +61,35 @@ object DebugFunctions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun rescheduleEhentaiBackgroundUpdater() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
EHentaiUpdateWorker.scheduleBackground(app)
|
||||||
|
} else {
|
||||||
|
error("OS/SDK version too old!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun listScheduledJobs() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
app.jobScheduler.allPendingJobs.map { j ->
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
info: ${j.id},
|
||||||
|
isPeriod: ${j.isPeriodic},
|
||||||
|
isPersisted: ${j.isPersisted},
|
||||||
|
intervalMillis: ${j.intervalMillis},
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
}.joinToString(",\n")
|
||||||
|
} else {
|
||||||
|
error("OS/SDK version too old!")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancelAllScheduledJobs() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
app.jobScheduler.cancelAll()
|
||||||
|
} else {
|
||||||
|
error("OS/SDK version too old!")
|
||||||
|
}
|
||||||
|
|
||||||
private fun convertSources(from: Long, to: Long) {
|
private fun convertSources(from: Long, to: Long) {
|
||||||
db.lowLevel().executeSQL(RawQuery.builder()
|
db.lowLevel().executeSQL(RawQuery.builder()
|
||||||
.query("""
|
.query("""
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package exh.debug
|
package exh.debug
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
import android.support.v7.preference.PreferenceScreen
|
import android.support.v7.preference.PreferenceScreen
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -64,6 +65,11 @@ class SettingsDebugController : SettingsController() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActivityStopped(activity: Activity) {
|
||||||
|
super.onActivityStopped(activity)
|
||||||
|
router.popCurrentController()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val MODIFIED_TEXT = Html.fromHtml("<font color='red'>MODIFIED</font>")
|
private val MODIFIED_TEXT = Html.fromHtml("<font color='red'>MODIFIED</font>")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user