From 6d6ff9598205e11c767cedf2fbe261f746df0624 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 4 Jan 2020 04:14:40 -0800 Subject: [PATCH] Fixes for this new auto migration ui --- .../manga/process/MigrationListController.kt | 1 - .../manga/process/MigrationProcessAdapter.kt | 4 -- .../manga/process/MigrationProcessHolder.kt | 50 +++++++++----- .../manga/process/MigrationProcessItem.kt | 2 +- .../res/layout/migration_new_process_item.xml | 69 +++++++++---------- app/src/main/res/values/strings.xml | 1 + 6 files changed, 67 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index a47d350832..36d03db538 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -84,7 +84,6 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), super.onViewCreated(view) setTitle() val config = this.config ?: return - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT val newMigratingManga = migratingManga ?: run { val new = config.mangaIds.map { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt index 888a1e2807..fae8e1c3f3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt @@ -30,10 +30,6 @@ class MigrationProcessAdapter( super.updateDataSet(items) } - fun indexOf(item: MigrationProcessItem): Int { - return items.indexOf(item) - } - interface MigrationProcessInterface { fun onMenuItemClick(position: Int, item: MenuItem) fun enableButtons() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt index ac3749dadb..7012a23266 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.gone +import eu.kanade.tachiyomi.util.invisible import eu.kanade.tachiyomi.util.launchUI import eu.kanade.tachiyomi.util.setVectorCompat import eu.kanade.tachiyomi.util.visible @@ -31,6 +32,8 @@ class MigrationProcessHolder( private val db: DatabaseHelper by injectLazy() private val sourceManager: SourceManager by injectLazy() + private var item:MigrationProcessItem? = null + init { // We need to post a Runnable to show the popup to make sure that the PopupMenu is @@ -41,18 +44,21 @@ class MigrationProcessHolder( } fun bind(item: MigrationProcessItem) { + this.item = item launchUI { val manga = item.manga.manga() val source = item.manga.mangaSource() - migration_menu.setVectorCompat(R.drawable.ic_more_vert_black_24dp, view.context.getResourceColor(R.attr.icon_color)) + migration_menu.setVectorCompat(R.drawable.ic_more_vert_black_24dp, view.context + .getResourceColor(R.attr.icon_color)) skip_manga.setVectorCompat(R.drawable.baseline_close_24, view.context.getResourceColor(R .attr.icon_color)) - migration_menu.gone() + migration_menu.invisible() + skip_manga.visible() + migration_manga_card_to.resetManga() if (manga != null) { withContext(Dispatchers.Main) { - migration_manga_card_from.loading_group.gone() - attachManga(migration_manga_card_from, manga, source) + migration_manga_card_from.attachManga(manga, source) migration_manga_card_from.setOnClickListener { adapter.controller.router.pushController( MangaController( @@ -81,9 +87,11 @@ class MigrationProcessHolder( sourceManager.get(it) } withContext(Dispatchers.Main) { + if (item.manga.mangaId != this@MigrationProcessHolder.item?.manga?.mangaId) { + return@withContext + } if (searchResult != null && resultSource != null) { - migration_manga_card_to.loading_group.gone() - attachManga(migration_manga_card_to, searchResult, resultSource) + migration_manga_card_to.attachManga(searchResult, resultSource) migration_manga_card_to.setOnClickListener { adapter.controller.router.pushController( MangaController( @@ -107,22 +115,32 @@ class MigrationProcessHolder( migration_manga_card_to.loading_group.visible() } - fun attachManga(view: View, manga: Manga, source: Source) { - view.loading_group.gone() + private fun View.resetManga() { + loading_group.visible() + thumbnail.setImageDrawable(null) + title.text = "" + manga_source_label.text = "" + manga_chapters.text = "" + manga_chapters.gone() + manga_last_chapter_label.text = "" + } + + private fun View.attachManga(manga: Manga, source: Source) { + loading_group.gone() GlideApp.with(view.context.applicationContext) .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() - .into(view.thumbnail) + .into(thumbnail) - view.title.text = if (manga.title.isBlank()) { + title.text = if (manga.title.isBlank()) { view.context.getString(R.string.unknown) } else { manga.title } - view.gradient.visible() - view.manga_source_label.text = /*if (source.id == MERGED_SOURCE_ID) { + gradient.visible() + manga_source_label.text = /*if (source.id == MERGED_SOURCE_ID) { MergedSource.MangaConfig.readFromUrl(gson, manga.url).children.map { sourceManager.getOrStub(it.source).toString() }.distinct().joinToString() @@ -131,15 +149,15 @@ class MigrationProcessHolder( // } val mangaChapters = db.getChapters(manga).executeAsBlocking() - view.manga_chapters.visible() - view.manga_chapters.text = mangaChapters.size.toString() + manga_chapters.visible() + manga_chapters.text = mangaChapters.size.toString() val latestChapter = mangaChapters.maxBy { it.chapter_number }?.chapter_number ?: -1f if (latestChapter > 0f) { - view.manga_last_chapter_label.text = view.context.getString(R.string.latest_x, + manga_last_chapter_label.text = context.getString(R.string.latest_x, DecimalFormat("#.#").format(latestChapter)) } else { - view.manga_last_chapter_label.setText(R.string.unknown) + manga_last_chapter_label.setText(R.string.unknown) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessItem.kt index 45bff997fd..57a2438c2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessItem.kt @@ -42,7 +42,7 @@ class MigrationProcessItem(val manga: MigratingManga) : } override fun hashCode(): Int { - return manga.mangaId.hashCode() + return manga.mangaId.toInt() } } \ No newline at end of file diff --git a/app/src/main/res/layout/migration_new_process_item.xml b/app/src/main/res/layout/migration_new_process_item.xml index 1905caec63..2c405917b4 100644 --- a/app/src/main/res/layout/migration_new_process_item.xml +++ b/app/src/main/res/layout/migration_new_process_item.xml @@ -1,38 +1,35 @@ - + android:gravity="center"> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/migration_menu" + app:layout_constraintHorizontal_bias="0.5" + app:layout_constraintStart_toEndOf="@+id/imageView" + app:layout_constraintTop_toTopOf="parent" /> + app:srcCompat="@drawable/ic_more_vert_black_24dp" + android:visibility="invisible"/> - \ No newline at end of file + app:layout_constraintBottom_toBottomOf="@+id/migration_menu" + app:layout_constraintEnd_toEndOf="@+id/migration_menu" + app:layout_constraintStart_toStartOf="@+id/migration_menu" + app:layout_constraintTop_toTopOf="@+id/migration_menu" + app:srcCompat="@drawable/baseline_close_24" /> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 18dfd5163d..f0851804af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -565,5 +565,6 @@ Keep old manga Use intelligent search algorithm Begin migration + migrating to