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.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.support.v4.view.GravityCompat
|
||||
import android.support.v4.widget.DrawerLayout
|
||||
import android.support.v7.graphics.drawable.DrawerArrowDrawable
|
||||
@ -42,8 +43,11 @@ import android.text.TextUtils
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.util.vibrate
|
||||
import exh.EXHMigrations
|
||||
import exh.eh.EHentaiUpdateWorker
|
||||
import exh.ui.migration.MetadataFetchDialog
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
@ -66,6 +70,35 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
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?) {
|
||||
setTheme(when (preferences.theme()) {
|
||||
2 -> R.style.Theme_Tachiyomi_Dark
|
||||
@ -151,13 +184,15 @@ class MainActivity : BaseActivity() {
|
||||
})
|
||||
|
||||
// --> EH
|
||||
//Hook long press hamburger menu to lock
|
||||
getToolbarNavigationIcon(toolbar)?.setOnLongClickListener {
|
||||
if(lockEnabled(preferences)) {
|
||||
doLock(true)
|
||||
vibrate(50) // Notify user of lock
|
||||
true
|
||||
} else false
|
||||
initWhenIdle {
|
||||
//Hook long press hamburger menu to lock
|
||||
getToolbarNavigationIcon(toolbar)?.setOnLongClickListener {
|
||||
if(lockEnabled(preferences)) {
|
||||
doLock(true)
|
||||
vibrate(50) // Notify user of lock
|
||||
true
|
||||
} else false
|
||||
}
|
||||
}
|
||||
|
||||
//Show lock
|
||||
@ -186,15 +221,23 @@ class MainActivity : BaseActivity() {
|
||||
if(EXHMigrations.upgrade(preferences)) {
|
||||
ChangelogDialogController().showDialog(router)
|
||||
}
|
||||
// Migrate metadata if empty (EH)
|
||||
if(!preferences.migrateLibraryAsked().getOrDefault()) {
|
||||
MetadataFetchDialog().askMigration(this, false)
|
||||
}
|
||||
|
||||
// Upload settings
|
||||
if(preferences.enableExhentai().getOrDefault()
|
||||
&& preferences.eh_showSettingsUploadWarning().getOrDefault())
|
||||
WarnConfigureDialogController.uploadSettings(router)
|
||||
initWhenIdle {
|
||||
// Migrate metadata if empty (EH)
|
||||
if(!preferences.migrateLibraryAsked().getOrDefault()) {
|
||||
MetadataFetchDialog().askMigration(this, false)
|
||||
}
|
||||
|
||||
// Upload settings
|
||||
if(preferences.enableExhentai().getOrDefault()
|
||||
&& preferences.eh_showSettingsUploadWarning().getOrDefault())
|
||||
WarnConfigureDialogController.uploadSettings(router)
|
||||
|
||||
// Scheduler uploader job if required
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
EHentaiUpdateWorker.scheduleBackground(this)
|
||||
}
|
||||
}
|
||||
// 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.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.jobScheduler
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
import exh.eh.EHentaiUpdateWorker
|
||||
@ -52,7 +53,7 @@ object DebugFunctions {
|
||||
|
||||
fun convertAllExhentaiGalleriesToEhentai() = convertSources(EXH_SOURCE_ID, EH_SOURCE_ID)
|
||||
|
||||
fun testLaunchBackgroundUpdater() {
|
||||
fun testLaunchEhentaiBackgroundUpdater() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
EHentaiUpdateWorker.launchBackgroundTest(app)
|
||||
} 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) {
|
||||
db.lowLevel().executeSQL(RawQuery.builder()
|
||||
.query("""
|
||||
|
@ -1,6 +1,7 @@
|
||||
package exh.debug
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.support.v7.preference.PreferenceScreen
|
||||
import android.text.Html
|
||||
import android.util.Log
|
||||
@ -64,6 +65,11 @@ class SettingsDebugController : SettingsController() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityStopped(activity: Activity) {
|
||||
super.onActivityStopped(activity)
|
||||
router.popCurrentController()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val MODIFIED_TEXT = Html.fromHtml("<font color='red'>MODIFIED</font>")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user