Optimize imports, disallow wildcard imports because of klint, run linter
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
package exh.eh
|
||||
|
||||
class EHentaiThrottleManager(private val max: Int = THROTTLE_MAX,
|
||||
private val inc: Int = THROTTLE_INC) {
|
||||
class EHentaiThrottleManager(
|
||||
private val max: Int = THROTTLE_MAX,
|
||||
private val inc: Int = THROTTLE_INC
|
||||
) {
|
||||
private var lastThrottleTime: Long = 0
|
||||
var throttleTime: Long = 0
|
||||
private set
|
||||
|
||||
fun throttle() {
|
||||
//Throttle requests if necessary
|
||||
// Throttle requests if necessary
|
||||
val now = System.currentTimeMillis()
|
||||
val timeDiff = now - lastThrottleTime
|
||||
if(timeDiff < throttleTime)
|
||||
if (timeDiff < throttleTime)
|
||||
Thread.sleep(throttleTime - timeDiff)
|
||||
|
||||
if(throttleTime < max)
|
||||
if (throttleTime < max)
|
||||
throttleTime += inc
|
||||
|
||||
lastThrottleTime = System.currentTimeMillis()
|
||||
@@ -28,4 +30,4 @@ class EHentaiThrottleManager(private val max: Int = THROTTLE_MAX,
|
||||
const val THROTTLE_MAX = 5500
|
||||
const val THROTTLE_INC = 20
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
||||
import exh.metadata.metadata.EHentaiSearchMetadata
|
||||
import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||
import java.io.File
|
||||
import rx.Observable
|
||||
import rx.Single
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
|
||||
data class ChapterChain(val manga: Manga, val chapters: List<Chapter>)
|
||||
|
||||
@@ -61,7 +61,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
|
||||
val chainsAsChapters = chains.flatMap { it.chapters }
|
||||
|
||||
if(toDiscard.isNotEmpty()) {
|
||||
if (toDiscard.isNotEmpty()) {
|
||||
var new = false
|
||||
|
||||
// Copy chain chapters to curChapters
|
||||
@@ -75,9 +75,9 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
|
||||
chain.chapters.map { chapter ->
|
||||
// Convert old style chapters to new style chapters if possible
|
||||
if(chapter.date_upload <= 0
|
||||
&& meta?.datePosted != null
|
||||
&& meta?.title != null) {
|
||||
if (chapter.date_upload <= 0 &&
|
||||
meta?.datePosted != null &&
|
||||
meta?.title != null) {
|
||||
chapter.name = meta!!.title!!
|
||||
chapter.date_upload = meta!!.datePosted!!
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
if (existing != null) {
|
||||
existing.read = existing.read || chapter.read
|
||||
existing.last_page_read = existing.last_page_read.coerceAtLeast(chapter.last_page_read)
|
||||
if(newLastPageRead != null && existing.last_page_read <= 0) {
|
||||
if (newLastPageRead != null && existing.last_page_read <= 0) {
|
||||
existing.last_page_read = newLastPageRead
|
||||
}
|
||||
existing.bookmark = existing.bookmark || chapter.bookmark
|
||||
@@ -107,7 +107,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
bookmark = chapter.bookmark
|
||||
|
||||
last_page_read = chapter.last_page_read
|
||||
if(newLastPageRead != null && last_page_read <= 0) {
|
||||
if (newLastPageRead != null && last_page_read <= 0) {
|
||||
last_page_read = newLastPageRead
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
}
|
||||
|
||||
data class GalleryEntry(val gId: String, val gToken: String) {
|
||||
class Serializer: MemAutoFlushingLookupTable.EntrySerializer<GalleryEntry> {
|
||||
class Serializer : MemAutoFlushingLookupTable.EntrySerializer<GalleryEntry> {
|
||||
/**
|
||||
* Serialize an entry as a String.
|
||||
*/
|
||||
|
||||
@@ -20,8 +20,8 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.util.system.jobScheduler
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.system.jobScheduler
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
import exh.debug.DebugToggles
|
||||
@@ -31,18 +31,23 @@ import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||
import exh.metadata.metadata.base.insertFlatMetadata
|
||||
import exh.util.await
|
||||
import exh.util.cancellable
|
||||
import kotlinx.coroutines.*
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import rx.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
class EHentaiUpdateWorker : JobService(), CoroutineScope {
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.Default + Job()
|
||||
|
||||
@@ -215,8 +220,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
val (acceptedRoot, discardedRoots, hasNew) =
|
||||
updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters).await()
|
||||
|
||||
if((new.isNotEmpty() && manga.id == acceptedRoot.manga.id)
|
||||
|| (hasNew && updatedManga.none { it.id == acceptedRoot.manga.id })) {
|
||||
if ((new.isNotEmpty() && manga.id == acceptedRoot.manga.id) ||
|
||||
(hasNew && updatedManga.none { it.id == acceptedRoot.manga.id })) {
|
||||
updatedManga += acceptedRoot.manga
|
||||
}
|
||||
|
||||
@@ -235,7 +240,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
)
|
||||
)
|
||||
|
||||
if(updatedManga.isNotEmpty()) {
|
||||
if (updatedManga.isNotEmpty()) {
|
||||
updateNotifier.showResultNotification(updatedManga)
|
||||
}
|
||||
}
|
||||
@@ -254,10 +259,10 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
val newChapters = source.fetchChapterList(manga).toSingle().await(Schedulers.io())
|
||||
val (new, _) = syncChaptersWithSource(db, newChapters, manga, source) // Not suspending, but does block, maybe fix this?
|
||||
return new to db.getChapters(manga).await()
|
||||
} catch(t: Throwable) {
|
||||
if(t is EHentai.GalleryNotFoundException) {
|
||||
} catch (t: Throwable) {
|
||||
if (t is EHentai.GalleryNotFoundException) {
|
||||
val meta = db.getFlatMetadataForManga(manga.id!!).await()?.raise<EHentaiSearchMetadata>()
|
||||
if(meta != null) {
|
||||
if (meta != null) {
|
||||
// Age dead galleries
|
||||
logger.d("Aged %s - notfound", manga.id)
|
||||
meta.aged = true
|
||||
@@ -286,18 +291,20 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
|
||||
private fun Context.baseBackgroundJobInfo(isTest: Boolean): JobInfo.Builder {
|
||||
return JobInfo.Builder(
|
||||
if(isTest) JOB_ID_UPDATE_BACKGROUND_TEST
|
||||
if (isTest) JOB_ID_UPDATE_BACKGROUND_TEST
|
||||
else JOB_ID_UPDATE_BACKGROUND, componentName())
|
||||
}
|
||||
|
||||
private fun Context.periodicBackgroundJobInfo(period: Long,
|
||||
requireCharging: Boolean,
|
||||
requireUnmetered: Boolean): JobInfo {
|
||||
private fun Context.periodicBackgroundJobInfo(
|
||||
period: Long,
|
||||
requireCharging: Boolean,
|
||||
requireUnmetered: Boolean
|
||||
): JobInfo {
|
||||
return baseBackgroundJobInfo(false)
|
||||
.setPeriodic(period)
|
||||
.setPersisted(true)
|
||||
.setRequiredNetworkType(
|
||||
if(requireUnmetered) JobInfo.NETWORK_TYPE_UNMETERED
|
||||
if (requireUnmetered) JobInfo.NETWORK_TYPE_UNMETERED
|
||||
else JobInfo.NETWORK_TYPE_ANY)
|
||||
.apply {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
@@ -321,7 +328,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
|
||||
fun launchBackgroundTest(context: Context) {
|
||||
val jobScheduler = context.jobScheduler
|
||||
if(jobScheduler.schedule(context.testBackgroundJobInfo()) == JobScheduler.RESULT_FAILURE) {
|
||||
if (jobScheduler.schedule(context.testBackgroundJobInfo()) == JobScheduler.RESULT_FAILURE) {
|
||||
logger.e("Failed to schedule background test job!")
|
||||
} else {
|
||||
logger.d("Successfully scheduled background test job!")
|
||||
@@ -344,7 +351,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
wifiRestriction
|
||||
)
|
||||
|
||||
if(context.jobScheduler.schedule(jobInfo) == JobScheduler.RESULT_FAILURE) {
|
||||
if (context.jobScheduler.schedule(jobInfo) == JobScheduler.RESULT_FAILURE) {
|
||||
logger.e("Failed to schedule background update job!")
|
||||
} else {
|
||||
logger.d("Successfully scheduled background update job!")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package exh.eh
|
||||
|
||||
data class EHentaiUpdaterStats(
|
||||
val startTime: Long,
|
||||
val possibleUpdates: Int,
|
||||
val updateCount: Int
|
||||
)
|
||||
val startTime: Long,
|
||||
val possibleUpdates: Int,
|
||||
val updateCount: Int
|
||||
)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package exh.eh
|
||||
|
||||
class GalleryNotUpdatedException(val network: Boolean, cause: Throwable): RuntimeException(cause)
|
||||
class GalleryNotUpdatedException(val network: Boolean, cause: Throwable) : RuntimeException(cause)
|
||||
|
||||
@@ -3,9 +3,6 @@ package exh.eh
|
||||
import android.util.SparseArray
|
||||
import androidx.core.util.AtomicFile
|
||||
import com.elvishew.xlog.XLog
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
@@ -13,6 +10,18 @@ import java.io.InputStream
|
||||
import java.nio.ByteBuffer
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* In memory Int -> Obj lookup table implementation that
|
||||
@@ -23,9 +32,9 @@ import kotlin.coroutines.CoroutineContext
|
||||
* @author nulldev
|
||||
*/
|
||||
class MemAutoFlushingLookupTable<T>(
|
||||
file: File,
|
||||
private val serializer: EntrySerializer<T>,
|
||||
private val debounceTimeMs: Long = 3000
|
||||
file: File,
|
||||
private val serializer: EntrySerializer<T>,
|
||||
private val debounceTimeMs: Long = 3000
|
||||
) : CoroutineScope, Closeable {
|
||||
/**
|
||||
* The context of this scope.
|
||||
@@ -49,7 +58,7 @@ class MemAutoFlushingLookupTable<T>(
|
||||
private val atomicFile = AtomicFile(file)
|
||||
|
||||
private val shutdownHook = thread(start = false) {
|
||||
if(!flushed) writeSynchronously()
|
||||
if (!flushed) writeSynchronously()
|
||||
}
|
||||
|
||||
init {
|
||||
@@ -62,9 +71,9 @@ class MemAutoFlushingLookupTable<T>(
|
||||
var readIter = 0
|
||||
while (true) {
|
||||
val readThisIter = read(targetArray, readIter, byteCount - readIter)
|
||||
if(readThisIter <= 0) return false // No more data to read
|
||||
if (readThisIter <= 0) return false // No more data to read
|
||||
readIter += readThisIter
|
||||
if(readIter == byteCount) return true
|
||||
if (readIter == byteCount) return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,16 +83,16 @@ class MemAutoFlushingLookupTable<T>(
|
||||
atomicFile.openRead().buffered().use { input ->
|
||||
val bb = ByteBuffer.allocate(8)
|
||||
|
||||
while(true) {
|
||||
if(!input.requireBytes(bb.array(), 8)) break
|
||||
while (true) {
|
||||
if (!input.requireBytes(bb.array(), 8)) break
|
||||
val k = bb.getInt(0)
|
||||
val size = bb.getInt(4)
|
||||
val strBArr = ByteArray(size)
|
||||
if(!input.requireBytes(strBArr, size)) break
|
||||
if (!input.requireBytes(strBArr, size)) break
|
||||
table.put(k, serializer.read(strBArr.toString(Charsets.UTF_8)))
|
||||
}
|
||||
}
|
||||
} catch(e: FileNotFoundException) {
|
||||
} catch (e: FileNotFoundException) {
|
||||
XLog.d("Lookup table not found!", e)
|
||||
// Ignored
|
||||
}
|
||||
@@ -97,11 +106,11 @@ class MemAutoFlushingLookupTable<T>(
|
||||
flushed = false
|
||||
launch {
|
||||
delay(debounceTimeMs)
|
||||
if(id != writeCounter) return@launch
|
||||
if (id != writeCounter) return@launch
|
||||
|
||||
mutex.withLock {
|
||||
// Second check inside of mutex to prevent dupe writes
|
||||
if(id != writeCounter) return@launch
|
||||
if (id != writeCounter) return@launch
|
||||
withContext(NonCancellable) {
|
||||
writeSynchronously()
|
||||
|
||||
@@ -118,7 +127,7 @@ class MemAutoFlushingLookupTable<T>(
|
||||
val fos = atomicFile.startWrite()
|
||||
try {
|
||||
val out = fos.buffered()
|
||||
for(i in 0 until table.size()) {
|
||||
for (i in 0 until table.size()) {
|
||||
val k = table.keyAt(i)
|
||||
val v = serializer.write(table.valueAt(i)).toByteArray(Charsets.UTF_8)
|
||||
bb.putInt(0, k)
|
||||
@@ -128,7 +137,7 @@ class MemAutoFlushingLookupTable<T>(
|
||||
}
|
||||
out.flush()
|
||||
atomicFile.finishWrite(fos)
|
||||
} catch(t: Throwable) {
|
||||
} catch (t: Throwable) {
|
||||
atomicFile.failWrite(fos)
|
||||
throw t
|
||||
}
|
||||
@@ -212,4 +221,4 @@ class MemAutoFlushingLookupTable<T>(
|
||||
private const val INITIAL_SIZE = 1000
|
||||
private const val ENTRY_SIZE_BYTES = 8
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user