Fixes for this new auto migration ui

This commit is contained in:
Jay 2020-01-04 04:14:40 -08:00
parent 10206ae7b3
commit 6d6ff95982
6 changed files with 67 additions and 60 deletions

View file

@ -84,7 +84,6 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle),
super.onViewCreated(view) super.onViewCreated(view)
setTitle() setTitle()
val config = this.config ?: return val config = this.config ?: return
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
val newMigratingManga = migratingManga ?: run { val newMigratingManga = migratingManga ?: run {
val new = config.mangaIds.map { val new = config.mangaIds.map {

View file

@ -30,10 +30,6 @@ class MigrationProcessAdapter(
super.updateDataSet(items) super.updateDataSet(items)
} }
fun indexOf(item: MigrationProcessItem): Int {
return items.indexOf(item)
}
interface MigrationProcessInterface { interface MigrationProcessInterface {
fun onMenuItemClick(position: Int, item: MenuItem) fun onMenuItemClick(position: Int, item: MenuItem)
fun enableButtons() fun enableButtons()

View file

@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.getResourceColor
import eu.kanade.tachiyomi.util.gone import eu.kanade.tachiyomi.util.gone
import eu.kanade.tachiyomi.util.invisible
import eu.kanade.tachiyomi.util.launchUI import eu.kanade.tachiyomi.util.launchUI
import eu.kanade.tachiyomi.util.setVectorCompat import eu.kanade.tachiyomi.util.setVectorCompat
import eu.kanade.tachiyomi.util.visible import eu.kanade.tachiyomi.util.visible
@ -31,6 +32,8 @@ class MigrationProcessHolder(
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
init { init {
// We need to post a Runnable to show the popup to make sure that the PopupMenu is // 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) { fun bind(item: MigrationProcessItem) {
this.item = item
launchUI { launchUI {
val manga = item.manga.manga() val manga = item.manga.manga()
val source = item.manga.mangaSource() 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 skip_manga.setVectorCompat(R.drawable.baseline_close_24, view.context.getResourceColor(R
.attr.icon_color)) .attr.icon_color))
migration_menu.gone() migration_menu.invisible()
skip_manga.visible()
migration_manga_card_to.resetManga()
if (manga != null) { if (manga != null) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
migration_manga_card_from.loading_group.gone() migration_manga_card_from.attachManga(manga, source)
attachManga(migration_manga_card_from, manga, source)
migration_manga_card_from.setOnClickListener { migration_manga_card_from.setOnClickListener {
adapter.controller.router.pushController( adapter.controller.router.pushController(
MangaController( MangaController(
@ -81,9 +87,11 @@ class MigrationProcessHolder(
sourceManager.get(it) sourceManager.get(it)
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
if (item.manga.mangaId != this@MigrationProcessHolder.item?.manga?.mangaId) {
return@withContext
}
if (searchResult != null && resultSource != null) { if (searchResult != null && resultSource != null) {
migration_manga_card_to.loading_group.gone() migration_manga_card_to.attachManga(searchResult, resultSource)
attachManga(migration_manga_card_to, searchResult, resultSource)
migration_manga_card_to.setOnClickListener { migration_manga_card_to.setOnClickListener {
adapter.controller.router.pushController( adapter.controller.router.pushController(
MangaController( MangaController(
@ -107,22 +115,32 @@ class MigrationProcessHolder(
migration_manga_card_to.loading_group.visible() migration_manga_card_to.loading_group.visible()
} }
fun attachManga(view: View, manga: Manga, source: Source) { private fun View.resetManga() {
view.loading_group.gone() 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) GlideApp.with(view.context.applicationContext)
.load(manga) .load(manga)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .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) view.context.getString(R.string.unknown)
} else { } else {
manga.title manga.title
} }
view.gradient.visible() gradient.visible()
view.manga_source_label.text = /*if (source.id == MERGED_SOURCE_ID) { manga_source_label.text = /*if (source.id == MERGED_SOURCE_ID) {
MergedSource.MangaConfig.readFromUrl(gson, manga.url).children.map { MergedSource.MangaConfig.readFromUrl(gson, manga.url).children.map {
sourceManager.getOrStub(it.source).toString() sourceManager.getOrStub(it.source).toString()
}.distinct().joinToString() }.distinct().joinToString()
@ -131,15 +149,15 @@ class MigrationProcessHolder(
// } // }
val mangaChapters = db.getChapters(manga).executeAsBlocking() val mangaChapters = db.getChapters(manga).executeAsBlocking()
view.manga_chapters.visible() manga_chapters.visible()
view.manga_chapters.text = mangaChapters.size.toString() manga_chapters.text = mangaChapters.size.toString()
val latestChapter = mangaChapters.maxBy { it.chapter_number }?.chapter_number ?: -1f val latestChapter = mangaChapters.maxBy { it.chapter_number }?.chapter_number ?: -1f
if (latestChapter > 0f) { 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)) DecimalFormat("#.#").format(latestChapter))
} else { } else {
view.manga_last_chapter_label.setText(R.string.unknown) manga_last_chapter_label.setText(R.string.unknown)
} }
} }

View file

@ -42,7 +42,7 @@ class MigrationProcessItem(val manga: MigratingManga) :
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return manga.mangaId.hashCode() return manga.mangaId.toInt()
} }
} }

View file

@ -1,38 +1,35 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center|start"> android:gravity="center">
<include <include
android:id="@+id/migration_manga_card_from" android:id="@+id/migration_manga_card_from"
layout="@layout/migration_new_manga_card" layout="@layout/migration_new_manga_card"
android:layout_width="150dp" android:layout_width="150dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="16dp" app:layout_constraintEnd_toStartOf="@+id/imageView"
android:layout_marginEnd="16dp" app:layout_constraintHorizontal_bias="0.5"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintWidth_max="450dp" />
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_marginStart="-10dp"
android:layout_marginEnd="-10dp"
android:layout_marginBottom="30dp"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:contentDescription="migrating to" android:contentDescription="@string/migrating_to"
android:scaleType="center" android:scaleType="center"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginBottom="45dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/migration_manga_card_from" app:layout_constraintEnd_toStartOf="@+id/migration_manga_card_to"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/migration_manga_card_from"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_keyboard_arrow_right_black_24dp" /> app:srcCompat="@drawable/ic_keyboard_arrow_right_black_24dp" />
<include <include
@ -40,40 +37,36 @@
layout="@layout/migration_new_manga_card" layout="@layout/migration_new_manga_card"
android:layout_width="150dp" android:layout_width="150dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="16dp" app:layout_constraintEnd_toStartOf="@+id/migration_menu"
android:layout_marginEnd="16dp" app:layout_constraintHorizontal_bias="0.5"
android:layout_marginRight="16dp" app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintWidth_max="450dp" />
<ImageView <ImageView
android:id="@+id/migration_menu" android:id="@+id/migration_menu"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="30dp"
android:contentDescription="@string/description_cover" android:contentDescription="@string/description_cover"
android:paddingTop="30dp" android:paddingTop="30dp"
android:paddingBottom="30dp" android:paddingBottom="30dp"
app:layout_constraintRight_toRightOf="parent" android:layout_marginBottom="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/migration_manga_card_to"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert_black_24dp" /> app:srcCompat="@drawable/ic_more_vert_black_24dp"
android:visibility="invisible"/>
<ImageView <ImageView
android:id="@+id/skip_manga" android:id="@+id/skip_manga"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" app:layout_constraintBottom_toBottomOf="@+id/migration_menu"
android:layout_marginBottom="30dp" app:layout_constraintEnd_toEndOf="@+id/migration_menu"
android:contentDescription="@string/description_cover" app:layout_constraintStart_toStartOf="@+id/migration_menu"
android:paddingTop="30dp" app:layout_constraintTop_toTopOf="@+id/migration_menu"
android:paddingBottom="30dp" app:srcCompat="@drawable/baseline_close_24" />
app:layout_constraintRight_toRightOf="parent" </androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/baseline_close_24"
android:visibility="gone"/>
</LinearLayout>

View file

@ -565,5 +565,6 @@
<string name="keep_old_manga">Keep old manga</string> <string name="keep_old_manga">Keep old manga</string>
<string name="use_intelligent_search">Use intelligent search algorithm</string> <string name="use_intelligent_search">Use intelligent search algorithm</string>
<string name="begin_migration">Begin migration</string> <string name="begin_migration">Begin migration</string>
<string name="migrating_to">migrating to</string>
</resources> </resources>