From 3044dca9bb49978739fe6bb2b6cabad65c4748b0 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 21 Feb 2020 21:39:50 -0800 Subject: [PATCH] Migrations now using mat grid style Migrations will also no longer be cancelled by switching tabs --- .../tachiyomi/ui/library/LibraryBadge.kt | 4 + .../tachiyomi/ui/library/LibraryController.kt | 2 +- .../ui/library/LibraryListController.kt | 7 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 15 +++ .../manga/process/MigrationListController.kt | 11 +- .../manga/process/MigrationProcessHolder.kt | 59 +++++---- .../main/res/layout/migration_manga_card.xml | 125 ------------------ .../res/layout/migration_process_item.xml | 6 +- 8 files changed, 69 insertions(+), 160 deletions(-) delete mode 100644 app/src/main/res/layout/migration_manga_card.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt index fd7ca0fe33..f3221ebbb2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt @@ -59,6 +59,10 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS } } + fun setChapters(chapters: Int?) { + setUnreadDownload(chapters ?: 0, 0, chapters != null) + } + fun setInLibrary(inLibrary: Boolean) { badge_view.visibility = if (inLibrary) View.VISIBLE else View.GONE unread_angle.visibility = View.GONE diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index f22aa1ec17..70e20d0834 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -208,7 +208,7 @@ open class LibraryController( presenter.onRestore() val library = presenter.getAllManga() - if (library != null) presenter.updateViewBlocking() //onNextLibraryUpdate(presenter.categories, library) + if (library != null) presenter.updateViewBlocking() else { contentView().alpha = 0f presenter.getLibraryBlocking() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt index 402b2f8893..1fe979f744 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt @@ -170,6 +170,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), } override fun onNextLibraryUpdate(mangaMap: List, freshStart: Boolean) { + val recyclerLayout = recycler_layout ?: return if (mangaMap.isNotEmpty()) { empty_view?.hide() } else { @@ -179,7 +180,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), spinner.onItemSelectedListener = null - spinnerAdapter = SpinnerAdapter(view!!.context, R.layout.library_spinner_textview, + spinnerAdapter = SpinnerAdapter(spinner.context, R.layout.library_spinner_textview, presenter.categories.map { it.name }.toTypedArray()) spinnerAdapter?.setDropDownViewResource(R.layout.library_spinner_entry_text) spinner.adapter = spinnerAdapter @@ -188,8 +189,8 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), spinner.setSelection(min(presenter.categories.size - 1, activeCategory + 1)) if (!freshStart) { justStarted = false - if (recycler_layout.alpha == 0f) - recycler_layout.animate().alpha(1f).setDuration(500).start() + if (recyclerLayout.alpha == 0f) + recyclerLayout.animate().alpha(1f).setDuration(500).start() }else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 4e1cd7b2ff..983fd3a1f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -18,6 +18,7 @@ import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.graphics.drawable.DrawerArrowDrawable import androidx.biometric.BiometricManager import androidx.core.view.GravityCompat +import com.afollestad.materialdialogs.MaterialDialog import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler @@ -49,6 +50,7 @@ import eu.kanade.tachiyomi.ui.extension.ExtensionController import eu.kanade.tachiyomi.ui.library.LibraryController import eu.kanade.tachiyomi.ui.library.LibraryListController import eu.kanade.tachiyomi.ui.manga.MangaController +import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController import eu.kanade.tachiyomi.ui.setting.SettingsMainController @@ -128,6 +130,19 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { navigationView.setOnNavigationItemSelectedListener { item -> val id = item.itemId + val currentController = router.backstack.lastOrNull()?.controller() + if (currentController is MigrationListController && + currentController.migrationsJob?.isCancelled == false) { + MaterialDialog(this).show { + title(R.string.stop_migration) + positiveButton(R.string.action_stop) { + currentController.migrationsJob?.cancel() + this@MainActivity.navigationView.selectedItemId = id + } + negativeButton(android.R.string.cancel) + } + return@setOnNavigationItemSelectedListener false + } val currentRoot = router.backstack.firstOrNull() if (currentRoot?.tag()?.toIntOrNull() != id) { 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 473ac4cd09..8f10a22dec 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 @@ -27,12 +27,12 @@ import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.migration.MigrationMangaDialog import eu.kanade.tachiyomi.ui.migration.SearchController -import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener -import eu.kanade.tachiyomi.util.system.await -import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource -import eu.kanade.tachiyomi.util.system.toast +import eu.kanade.tachiyomi.util.system.await import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.launchUI +import eu.kanade.tachiyomi.util.system.toast +import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import kotlinx.android.synthetic.main.chapters_controller.* import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope @@ -69,7 +69,8 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), private val smartSearchEngine = SmartSearchEngine(coroutineContext, config?.extraSearchParams) - private var migrationsJob: Job? = null + var migrationsJob: Job? = null + private set private var migratingManga: MutableList? = null private var selectedPosition:Int? = null private var manaulMigrations = 0 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 edd7f2be06..35a5ec4f75 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 @@ -2,7 +2,9 @@ package eu.kanade.tachiyomi.ui.migration.manga.process import android.view.View import androidx.appcompat.widget.PopupMenu +import androidx.constraintlayout.widget.ConstraintLayout import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga @@ -13,13 +15,15 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.invisible -import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.visible -import kotlinx.android.synthetic.main.migration_manga_card.view.* +import eu.kanade.tachiyomi.widget.StateImageViewTarget +import kotlinx.android.synthetic.main.catalogue_grid_item.view.* import kotlinx.android.synthetic.main.migration_process_item.* +import kotlinx.android.synthetic.main.unread_download_badge.view.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import uy.kohesive.injekt.injectLazy @@ -62,7 +66,7 @@ class MigrationProcessHolder( migration_manga_card_to.resetManga() if (manga != null) { withContext(Dispatchers.Main) { - migration_manga_card_from.attachManga(manga, source) + migration_manga_card_from.attachManga(manga, source, false) migration_manga_card_from.setOnClickListener { adapter.controller.router.pushController( MangaController( @@ -94,7 +98,7 @@ class MigrationProcessHolder( return@withContext } if (searchResult != null && resultSource != null) { - migration_manga_card_to.attachManga(searchResult, resultSource) + migration_manga_card_to.attachManga(searchResult, resultSource, true) migration_manga_card_to.setOnClickListener { adapter.controller.router.pushController( MangaController( @@ -103,7 +107,7 @@ class MigrationProcessHolder( ) } } else { - migration_manga_card_to.loading_group.gone() + migration_manga_card_to.progress.gone() migration_manga_card_to.title.text = view.context.applicationContext.getString(R.string.no_alternatives_found) } @@ -116,32 +120,40 @@ class MigrationProcessHolder( } private fun View.resetManga() { - loading_group.visible() - thumbnail.setImageDrawable(null) + progress.visible() + cover_thumbnail.setImageDrawable(null) + compact_title.text = "" title.text = "" - manga_source_label.text = "" - manga_chapters.text = "" - manga_chapters.gone() - manga_last_chapter_label.text = "" + subtitle.text = "" + badge_view.setChapters(null) + (layoutParams as ConstraintLayout.LayoutParams).verticalBias = 0.5f + subtitle.text = "" migration_manga_card_to.setOnClickListener(null) } - private fun View.attachManga(manga: Manga, source: Source) { - loading_group.gone() - GlideApp.with(view.context.applicationContext) - .load(manga) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .centerCrop() - .into(thumbnail) + private fun View.attachManga(manga: Manga, source: Source, isTo: Boolean) { + (layoutParams as ConstraintLayout.LayoutParams).verticalBias = 1f + progress.gone() + GlideApp.with(view.context.applicationContext).load(manga).apply { + diskCacheStrategy(DiskCacheStrategy.RESOURCE) + if (isTo) { + transition(DrawableTransitionOptions.withCrossFade()) + .into(StateImageViewTarget(cover_thumbnail, progress)) + } + else + into(cover_thumbnail) + } - title.text = if (manga.currentTitle().isBlank()) { + compact_title.visible() + gradient.visible() + compact_title.text = if (manga.currentTitle().isBlank()) { view.context.getString(R.string.unknown) } else { manga.currentTitle() } gradient.visible() - manga_source_label.text = /*if (source.id == MERGED_SOURCE_ID) { + title.text = /*if (source.id == MERGED_SOURCE_ID) { MergedSource.MangaConfig.readFromUrl(gson, manga.url).children.map { sourceManager.getOrStub(it.source).toString() }.distinct().joinToString() @@ -150,15 +162,14 @@ class MigrationProcessHolder( // } val mangaChapters = db.getChapters(manga).executeAsBlocking() - manga_chapters.visible() - manga_chapters.text = mangaChapters.size.toString() + badge_view.setChapters(mangaChapters.size) val latestChapter = mangaChapters.maxBy { it.chapter_number }?.chapter_number ?: -1f if (latestChapter > 0f) { - manga_last_chapter_label.text = context.getString(R.string.latest_x, + subtitle.text = context.getString(R.string.latest_x, DecimalFormat("#.#").format(latestChapter)) } else { - manga_last_chapter_label.text = context.getString(R.string.latest_x, + subtitle.text = context.getString(R.string.latest_x, context.getString(R.string.unknown)) } } diff --git a/app/src/main/res/layout/migration_manga_card.xml b/app/src/main/res/layout/migration_manga_card.xml deleted file mode 100644 index 1ff7a6a88a..0000000000 --- a/app/src/main/res/layout/migration_manga_card.xml +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/migration_process_item.xml b/app/src/main/res/layout/migration_process_item.xml index 964db25db3..22e27d7b25 100644 --- a/app/src/main/res/layout/migration_process_item.xml +++ b/app/src/main/res/layout/migration_process_item.xml @@ -8,8 +8,9 @@