From fa8f5bc0d85db143bd8112f7d74625d508e6d7ed Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 8 May 2017 03:22:49 -0400 Subject: [PATCH] Add images and 'view chapters' to library updates (#785) * added option to open manga directly from library update added covers for manga in library update added ability to click covers to open manga directly from library update * Removed 3 dot option to open manga Adjusted covers to circles and material standard for recent chapter * fixed potential null pointer on cover click * adjusted circle imageview size for recently read --- .../ui/recent_updates/RecentChapterHolder.kt | 16 ++++++++++++++++ .../ui/recent_updates/RecentChaptersAdapter.kt | 6 ++++++ .../recent_updates/RecentChaptersController.kt | 18 +++++++++++++++++- .../main/res/layout/item_recent_chapters.xml | 16 +++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt index 0855fde50..c55039af6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt @@ -2,10 +2,13 @@ package eu.kanade.tachiyomi.ui.recent_updates import android.view.View import android.widget.PopupMenu +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.util.getResourceColor +import jp.wasabeef.glide.transformations.CropCircleTransformation import kotlinx.android.synthetic.main.item_recent_chapters.view.* /** @@ -41,6 +44,9 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha // correctly positioned. The reason being that the view may change position before the // PopupMenu is shown. view.chapter_menu.setOnClickListener { it.post { showPopupMenu(it) } } + view.manga_cover.setOnClickListener { + adapter.coverClickListener.onCoverClick(adapterPosition) + } } /** @@ -57,6 +63,16 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha // Set manga title view.manga_title.text = item.manga.title + // Set cover + Glide.clear(itemView.manga_cover) + if (!item.manga.thumbnail_url.isNullOrEmpty()) { + Glide.with(itemView.context) + .load(item.manga) + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .bitmapTransform(CropCircleTransformation(view.context)) + .into(itemView.manga_cover) + } + // Check if chapter is read and set correct color if (item.chapter.read) { view.chapter_title.setTextColor(readColor) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt index 6be10bc38..233c90fce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt @@ -6,8 +6,14 @@ import eu.davidea.flexibleadapter.items.IFlexible class RecentChaptersAdapter(val controller: RecentChaptersController) : FlexibleAdapter>(null, controller, true) { + val coverClickListener: OnCoverClickListener = controller + init { setDisplayHeadersAtStartUp(true) setStickyHeaders(true) } + + interface OnCoverClickListener { + fun onCoverClick(position: Int) + } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 75e7034b4..eda0d3ce6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -6,6 +6,8 @@ import android.support.v7.view.ActionMode import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager import android.view.* +import com.bluelinelabs.conductor.RouterTransaction +import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.jakewharton.rxbinding.support.v4.widget.refreshes import com.jakewharton.rxbinding.support.v7.widget.scrollStateChanges import eu.davidea.flexibleadapter.FlexibleAdapter @@ -15,6 +17,7 @@ import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.toast import kotlinx.android.synthetic.main.fragment_recent_chapters.view.* @@ -31,7 +34,8 @@ class RecentChaptersController : NucleusController(), FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnUpdateListener, - ConfirmDeleteChaptersDialog.Listener { + ConfirmDeleteChaptersDialog.Listener, + RecentChaptersAdapter.OnCoverClickListener { /** * Action mode for multiple selection. @@ -247,6 +251,18 @@ class RecentChaptersController : NucleusController(), presenter.deleteChapters(listOf(chapter)) } + override fun onCoverClick(position: Int) { + val chapterClicked = adapter?.getItem(position) as? RecentChapterItem ?: return + openManga(chapterClicked) + + } + + fun openManga(chapter: RecentChapterItem) { + router.pushController(RouterTransaction.with(MangaController(chapter.manga)) + .pushChangeHandler(FadeChangeHandler()) + .popChangeHandler(FadeChangeHandler())) + } + /** * Called when chapters are deleted */ diff --git a/app/src/main/res/layout/item_recent_chapters.xml b/app/src/main/res/layout/item_recent_chapters.xml index 68877ceb5..471978496 100644 --- a/app/src/main/res/layout/item_recent_chapters.xml +++ b/app/src/main/res/layout/item_recent_chapters.xml @@ -13,7 +13,9 @@ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingRight="?android:attr/listPreferredItemPaddingRight" - android:paddingStart="?android:attr/listPreferredItemPaddingStart"> + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:layout_alignParentTop="true" + android:layout_toEndOf="@+id/manga_cover"> + \ No newline at end of file