|
|
@ -1,7 +1,7 @@ |
|
|
|
package io.legado.app.model |
|
|
|
package io.legado.app.model |
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.IntentAction |
|
|
|
import io.legado.app.constant.IntentAction |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
@ -15,8 +15,6 @@ import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.startService |
|
|
|
import io.legado.app.utils.startService |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import java.text.SimpleDateFormat |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
@ -24,12 +22,8 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
val logs = arrayListOf<String>() |
|
|
|
|
|
|
|
val cacheBookMap = ConcurrentHashMap<String, CacheBook>() |
|
|
|
val cacheBookMap = ConcurrentHashMap<String, CacheBook>() |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ConstantLocale") |
|
|
|
|
|
|
|
private val logTimeFormat = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
|
fun getOrCreate(bookUrl: String): CacheBook? { |
|
|
|
fun getOrCreate(bookUrl: String): CacheBook? { |
|
|
|
val book = appDb.bookDao.getBook(bookUrl) ?: return null |
|
|
|
val book = appDb.bookDao.getBook(bookUrl) ?: return null |
|
|
@ -60,16 +54,6 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
return cacheBook |
|
|
|
return cacheBook |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun addLog(log: String?) { |
|
|
|
|
|
|
|
log ?: return |
|
|
|
|
|
|
|
synchronized(logs) { |
|
|
|
|
|
|
|
if (logs.size > 1000) { |
|
|
|
|
|
|
|
logs.removeLastOrNull() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
logs.add(0, logTimeFormat.format(Date()) + " " + log) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun start(context: Context, bookUrl: String, start: Int, end: Int) { |
|
|
|
fun start(context: Context, bookUrl: String, start: Int, end: Int) { |
|
|
|
context.startService<CacheBookService> { |
|
|
|
context.startService<CacheBookService> { |
|
|
|
action = IntentAction.start |
|
|
|
action = IntentAction.start |
|
|
@ -185,7 +169,7 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
if (errorDownloadMap[index] ?: 0 < 3) { |
|
|
|
if (errorDownloadMap[index] ?: 0 < 3) { |
|
|
|
waitDownloadSet.add(index) |
|
|
|
waitDownloadSet.add(index) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
addLog("${book.name}-${chapterTitle} ${error.localizedMessage}") |
|
|
|
AppLog.addLog("${book.name}-${chapterTitle} ${error.localizedMessage}") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|