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