Cleanup
This commit is contained in:
parent
a21d7f4f90
commit
484cb86ca9
@ -17,10 +17,10 @@ import java.util.Date
|
||||
class MigrationProcessAdapter(
|
||||
val controller: MigrationListController
|
||||
) : FlexibleAdapter<MigrationProcessItem>(null, controller, true) {
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
var items: List<MigrationProcessItem> = emptyList()
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
val menuItemListener: MigrationProcessInterface = controller
|
||||
|
||||
@ -43,14 +43,10 @@ class MigrationProcessAdapter(
|
||||
if (allMangasDone()) menuItemListener.enableButtons()
|
||||
}
|
||||
|
||||
fun allMangasDone() = (
|
||||
items.all {
|
||||
it.manga.migrationStatus != MigrationStatus
|
||||
.RUNNING
|
||||
} && items.any { it.manga.migrationStatus == MigrationStatus.MANGA_FOUND }
|
||||
)
|
||||
fun allMangasDone() = items.all { it.manga.migrationStatus != MigrationStatus.RUNNING } &&
|
||||
items.any { it.manga.migrationStatus == MigrationStatus.MANGA_FOUND }
|
||||
|
||||
fun mangasSkipped() = (items.count { it.manga.migrationStatus == MigrationStatus.MANGA_NOT_FOUND })
|
||||
fun mangasSkipped() = items.count { it.manga.migrationStatus == MigrationStatus.MANGA_NOT_FOUND }
|
||||
|
||||
suspend fun performMigrations(copy: Boolean) {
|
||||
withContext(Dispatchers.IO) {
|
||||
@ -108,8 +104,7 @@ class MigrationProcessAdapter(
|
||||
// Update chapters read
|
||||
if (MigrationFlags.hasChapters(flags)) {
|
||||
val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking()
|
||||
val maxChapterRead =
|
||||
prevMangaChapters.filter { it.read }.maxByOrNull { it.chapter_number }?.chapter_number
|
||||
val maxChapterRead = prevMangaChapters.filter { it.read }.maxByOrNull { it.chapter_number }?.chapter_number
|
||||
if (maxChapterRead != null) {
|
||||
val dbChapters = db.getChapters(manga).executeAsBlocking()
|
||||
for (chapter in dbChapters) {
|
||||
|
@ -46,9 +46,9 @@ class MigrationProcessHolder(
|
||||
private val view: View,
|
||||
private val adapter: MigrationProcessAdapter
|
||||
) : BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
private val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
private var item: MigrationProcessItem? = null
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
|
||||
@ -150,7 +150,6 @@ class MigrationProcessHolder(
|
||||
manga_chapters.text = ""
|
||||
manga_chapters.isVisible = false
|
||||
manga_last_chapter_label.text = ""
|
||||
migration_manga_card_to.clicks()
|
||||
}
|
||||
|
||||
private suspend fun View.attachManga(manga: Manga, source: Source) {
|
||||
|
@ -172,11 +172,11 @@ class SmartSearchEngine(
|
||||
* @return a manga from the database.
|
||||
*/
|
||||
suspend fun networkToLocalManga(sManga: SManga, sourceId: Long): Manga {
|
||||
var localManga = db.getManga(sManga.url, sourceId).executeAsBlocking()
|
||||
var localManga = db.getManga(sManga.url, sourceId).await()
|
||||
if (localManga == null) {
|
||||
val newManga = Manga.create(sManga.url, sManga.title, sourceId)
|
||||
newManga.copyFrom(sManga)
|
||||
val result = db.insertManga(newManga).executeAsBlocking()
|
||||
val result = db.insertManga(newManga).await()
|
||||
newManga.id = result.insertedId()
|
||||
localManga = newManga
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import kotlinx.coroutines.launch
|
||||
class SmartSearchPresenter(private val source: CatalogueSource?, private val config: SourceController.SmartSearchConfig?) :
|
||||
BasePresenter<SmartSearchController>() {
|
||||
|
||||
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||
|
||||
val smartSearchChannel = Channel<SearchResults>()
|
||||
|
||||
@ -27,7 +27,7 @@ class SmartSearchPresenter(private val source: CatalogueSource?, private val con
|
||||
super.onCreate(savedState)
|
||||
|
||||
if (source != null && config != null) {
|
||||
scope.launch(Dispatchers.Default) {
|
||||
scope.launch {
|
||||
val result = try {
|
||||
val resultManga = smartSearchEngine.smartSearch(source, config.origTitle)
|
||||
if (resultManga != null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user