From f811cc5c870656297ab915e1d9d351a8b6ae3902 Mon Sep 17 00:00:00 2001 From: NerdNumber9 Date: Tue, 30 Jul 2019 19:29:12 -0400 Subject: [PATCH] Initial work on auto-migrate --- .../tachiyomi/ui/library/LibraryController.kt | 5 + .../java/exh/ui/base/BaseExhController.kt | 29 +++ .../manga/design/MigrationDesignController.kt | 91 ++++++++ .../manga/design/MigrationSourceAdapter.kt | 10 + .../manga/design/MigrationSourceHolder.kt | 40 ++++ .../manga/design/MigrationSourceItem.kt | 51 +++++ .../process/MigrationProcedureController.kt | 34 +++ .../eh_ic_arrow_drop_down_white_100dp.xml | 5 + .../res/drawable/eh_ic_check_white_24dp.xml | 5 + .../res/drawable/eh_ic_clear_white_24dp.xml | 5 + app/src/main/res/layout/eh_manga_card.xml | 199 ++++++++++++++++++ .../main/res/layout/eh_migration_design.xml | 93 ++++++++ .../main/res/layout/eh_migration_process.xml | 26 +++ .../res/layout/eh_migration_process_item.xml | 81 +++++++ app/src/main/res/layout/eh_source_item.xml | 43 ++++ app/src/main/res/menu/library_selection.xml | 5 + 16 files changed, 722 insertions(+) create mode 100644 app/src/main/java/exh/ui/base/BaseExhController.kt create mode 100644 app/src/main/java/exh/ui/migration/manga/design/MigrationDesignController.kt create mode 100644 app/src/main/java/exh/ui/migration/manga/design/MigrationSourceAdapter.kt create mode 100644 app/src/main/java/exh/ui/migration/manga/design/MigrationSourceHolder.kt create mode 100644 app/src/main/java/exh/ui/migration/manga/design/MigrationSourceItem.kt create mode 100644 app/src/main/java/exh/ui/migration/manga/process/MigrationProcedureController.kt create mode 100644 app/src/main/res/drawable/eh_ic_arrow_drop_down_white_100dp.xml create mode 100644 app/src/main/res/drawable/eh_ic_check_white_24dp.xml create mode 100644 app/src/main/res/drawable/eh_ic_clear_white_24dp.xml create mode 100644 app/src/main/res/layout/eh_manga_card.xml create mode 100644 app/src/main/res/layout/eh_migration_design.xml create mode 100644 app/src/main/res/layout/eh_migration_process.xml create mode 100644 app/src/main/res/layout/eh_migration_process_item.xml create mode 100644 app/src/main/res/layout/eh_source_item.xml 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 b91fb9ed1..f0ceffc11 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 @@ -39,6 +39,7 @@ import eu.kanade.tachiyomi.util.toast import exh.favorites.FavoritesIntroDialog import exh.favorites.FavoritesSyncStatus import exh.ui.LoaderManager +import exh.ui.migration.manga.design.MigrationDesignController import kotlinx.android.synthetic.main.library_controller.* import kotlinx.android.synthetic.main.main_activity.* import rx.Subscription @@ -435,6 +436,10 @@ class LibraryController( } R.id.action_move_to_category -> showChangeMangaCategoriesDialog() R.id.action_delete -> showDeleteMangaDialog() + R.id.action_auto_source_migration -> { + destroyActionModeIfNeeded() + router.pushController(MigrationDesignController().withFadeTransaction()) + } else -> return false } return true diff --git a/app/src/main/java/exh/ui/base/BaseExhController.kt b/app/src/main/java/exh/ui/base/BaseExhController.kt new file mode 100644 index 000000000..05ef7bdf3 --- /dev/null +++ b/app/src/main/java/exh/ui/base/BaseExhController.kt @@ -0,0 +1,29 @@ +package exh.ui.base + +import android.support.annotation.LayoutRes +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import eu.kanade.tachiyomi.ui.base.controller.BaseController +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.cancel +import kotlin.coroutines.CoroutineContext + +abstract class BaseExhController : BaseController(), CoroutineScope { + abstract val layoutId: Int + @LayoutRes get + + override val coroutineContext: CoroutineContext = Job() + Dispatchers.Default + + override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { + return inflater.inflate(layoutId, container, false) + } + + override fun onDestroy() { + super.onDestroy() + + cancel() + } +} diff --git a/app/src/main/java/exh/ui/migration/manga/design/MigrationDesignController.kt b/app/src/main/java/exh/ui/migration/manga/design/MigrationDesignController.kt new file mode 100644 index 000000000..eeb7f2b90 --- /dev/null +++ b/app/src/main/java/exh/ui/migration/manga/design/MigrationDesignController.kt @@ -0,0 +1,91 @@ +package exh.ui.migration.manga.design + +import android.support.v7.widget.LinearLayoutManager +import android.view.View +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.source.online.HttpSource +import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import exh.ui.base.BaseExhController +import exh.ui.migration.manga.process.MigrationProcedureController +import kotlinx.android.synthetic.main.eh_migration_design.* +import uy.kohesive.injekt.injectLazy + +// TODO Handle config changes +// TODO Select all in library +class MigrationDesignController : BaseExhController(), FlexibleAdapter.OnItemClickListener { + private val sourceManager: SourceManager by injectLazy() + private val prefs: PreferencesHelper by injectLazy() + + override val layoutId: Int = R.layout.eh_migration_design + + private var adapter: FlexibleAdapter? = null + + override fun getTitle() = "Select target sources" + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + + adapter = MigrationSourceAdapter( + getEnabledSources().map { MigrationSourceItem(it, true) }, + this + ) + recycler.layoutManager = LinearLayoutManager(view.context) + recycler.setHasFixedSize(true) + recycler.adapter = adapter + adapter?.isHandleDragEnabled = true + + migration_mode.setOnClickListener { + prioritize_chapter_count.toggle() + } + + fuzzy_search.setOnClickListener { + use_smart_search.toggle() + } + + prioritize_chapter_count.setOnCheckedChangeListener { _, b -> + updatePrioritizeChapterCount(b) + } + + updatePrioritizeChapterCount(prioritize_chapter_count.isChecked) + + begin_migration_btn.setOnClickListener { + router.replaceTopController(MigrationProcedureController().withFadeTransaction()) + } + } + + private fun updatePrioritizeChapterCount(migrationMode: Boolean) { + migration_mode.text = if(migrationMode) { + "Use source with most chapters and use the above list to break ties" + } else { + "Use the first source in the list that has at least one chapter of the manga" + } + } + + override fun onItemClick(view: View, position: Int): Boolean { + adapter?.getItem(position)?.let { + it.sourceEnabled = !it.sourceEnabled + } + adapter?.notifyItemChanged(position) + return false + } + + /** + * Returns a list of enabled sources ordered by language and name. + * + * @return list containing enabled sources. + */ + private fun getEnabledSources(): List { + val languages = prefs.enabledLanguages().getOrDefault() + val hiddenCatalogues = prefs.hiddenCatalogues().getOrDefault() + + return sourceManager.getVisibleCatalogueSources() + .filterIsInstance() + .filter { it.lang in languages } + .filterNot { it.id.toString() in hiddenCatalogues } + .sortedBy { "(${it.lang}) ${it.name}" } + } +} \ No newline at end of file diff --git a/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceAdapter.kt b/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceAdapter.kt new file mode 100644 index 000000000..01e0a87f8 --- /dev/null +++ b/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceAdapter.kt @@ -0,0 +1,10 @@ +package exh.ui.migration.manga.design + +import eu.davidea.flexibleadapter.FlexibleAdapter + +class MigrationSourceAdapter(val items: List, + val controller: MigrationDesignController): FlexibleAdapter( + items, + controller, + true +) \ No newline at end of file diff --git a/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceHolder.kt b/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceHolder.kt new file mode 100644 index 000000000..3634ad390 --- /dev/null +++ b/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceHolder.kt @@ -0,0 +1,40 @@ +package exh.ui.migration.manga.design + +import android.view.View +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.source.online.HttpSource +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder +import eu.kanade.tachiyomi.util.getRound +import kotlinx.android.synthetic.main.eh_source_item.* +import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG + +class MigrationSourceHolder(view: View, val adapter: FlexibleAdapter): + BaseFlexibleViewHolder(view, adapter) { + init { + setDragHandleView(reorder) + } + + fun bind(source: HttpSource, sourceEnabled: Boolean) { + // Set capitalized title. + title.text = source.name.capitalize() + + // Update circle letter image. + itemView.post { + image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(),false)) + } + + if(sourceEnabled) { + title.alpha = 1.0f + image.alpha = 1.0f + title.paintFlags = title.paintFlags and STRIKE_THRU_TEXT_FLAG.inv() + } else { + title.alpha = DISABLED_ALPHA + image.alpha = DISABLED_ALPHA + title.paintFlags = title.paintFlags or STRIKE_THRU_TEXT_FLAG + } + } + + companion object { + private const val DISABLED_ALPHA = 0.3f + } +} \ No newline at end of file diff --git a/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceItem.kt b/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceItem.kt new file mode 100644 index 000000000..a31d4f552 --- /dev/null +++ b/app/src/main/java/exh/ui/migration/manga/design/MigrationSourceItem.kt @@ -0,0 +1,51 @@ +package exh.ui.migration.manga.design + +import android.support.v7.widget.RecyclerView +import android.view.View +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.AbstractFlexibleItem +import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.source.online.HttpSource + +class MigrationSourceItem(val source: HttpSource, var sourceEnabled: Boolean): AbstractFlexibleItem() { + override fun getLayoutRes() = R.layout.eh_source_item + + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): MigrationSourceHolder { + return MigrationSourceHolder(view, adapter as MigrationSourceAdapter) + } + + /** + * Binds the given view holder with this item. + * + * @param adapter The adapter of this item. + * @param holder The holder to bind. + * @param position The position of this item in the adapter. + * @param payloads List of partial changes. + */ + override fun bindViewHolder(adapter: FlexibleAdapter>, + holder: MigrationSourceHolder, + position: Int, + payloads: List?) { + holder.bind(source, sourceEnabled) + } + + /** + * Returns true if this item is draggable. + */ + override fun isDraggable(): Boolean { + return true + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other is MigrationSourceItem) { + return source.id == other.source.id + } + return false + } + + override fun hashCode(): Int { + return source.id.hashCode() + } +} \ No newline at end of file diff --git a/app/src/main/java/exh/ui/migration/manga/process/MigrationProcedureController.kt b/app/src/main/java/exh/ui/migration/manga/process/MigrationProcedureController.kt new file mode 100644 index 000000000..820b9cb02 --- /dev/null +++ b/app/src/main/java/exh/ui/migration/manga/process/MigrationProcedureController.kt @@ -0,0 +1,34 @@ +package exh.ui.migration.manga.process + +import android.content.pm.ActivityInfo +import android.os.Build +import android.view.View +import eu.kanade.tachiyomi.R +import exh.ui.base.BaseExhController + +class MigrationProcedureController : BaseExhController() { + override val layoutId = R.layout.eh_migration_process + + private var titleText = "Migrate manga (1/300)" + + override fun getTitle(): String { + return titleText + } + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + setTitle() + + activity?.requestedOrientation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + } else { + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + } + } + + override fun onDestroy() { + super.onDestroy() + + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/eh_ic_arrow_drop_down_white_100dp.xml b/app/src/main/res/drawable/eh_ic_arrow_drop_down_white_100dp.xml new file mode 100644 index 000000000..6003fd238 --- /dev/null +++ b/app/src/main/res/drawable/eh_ic_arrow_drop_down_white_100dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/eh_ic_check_white_24dp.xml b/app/src/main/res/drawable/eh_ic_check_white_24dp.xml new file mode 100644 index 000000000..bb672af94 --- /dev/null +++ b/app/src/main/res/drawable/eh_ic_check_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/eh_ic_clear_white_24dp.xml b/app/src/main/res/drawable/eh_ic_clear_white_24dp.xml new file mode 100644 index 000000000..fa3c5af03 --- /dev/null +++ b/app/src/main/res/drawable/eh_ic_clear_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/eh_manga_card.xml b/app/src/main/res/layout/eh_manga_card.xml new file mode 100644 index 000000000..796c841cc --- /dev/null +++ b/app/src/main/res/layout/eh_manga_card.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/eh_migration_design.xml b/app/src/main/res/layout/eh_migration_design.xml new file mode 100644 index 000000000..bc0de101d --- /dev/null +++ b/app/src/main/res/layout/eh_migration_design.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + +