diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/BaseFlexibleViewHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/BaseFlexibleViewHolder.kt new file mode 100644 index 000000000..3cc6b9c2a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/BaseFlexibleViewHolder.kt @@ -0,0 +1,15 @@ +package eu.kanade.tachiyomi.ui.base.holder + +import android.view.View +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.viewholders.FlexibleViewHolder +import kotlinx.android.extensions.LayoutContainer + +abstract class BaseFlexibleViewHolder(view: View, + adapter: FlexibleAdapter<*>, + stickyHeader: Boolean = false) : + FlexibleViewHolder(view, adapter, stickyHeader), LayoutContainer { + + override val containerView: View? + get() = itemView +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/BaseViewHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/BaseViewHolder.kt new file mode 100644 index 000000000..c809b7eeb --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/BaseViewHolder.kt @@ -0,0 +1,11 @@ +package eu.kanade.tachiyomi.ui.base.holder + +import android.support.v7.widget.RecyclerView +import android.view.View +import kotlinx.android.extensions.LayoutContainer + +abstract class BaseViewHolder(view: View) : RecyclerView.ViewHolder(view), LayoutContainer { + + override val containerView: View? + get() = itemView +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/LangHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/LangHolder.kt index ea1fe6f0a..0c7fad877 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/LangHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/LangHolder.kt @@ -2,15 +2,16 @@ package eu.kanade.tachiyomi.ui.catalogue import android.view.View import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R -import kotlinx.android.synthetic.main.catalogue_main_controller_card.view.* +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder +import kotlinx.android.synthetic.main.catalogue_main_controller_card.* import java.util.* -class LangHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter, true) { +class LangHolder(view: View, adapter: FlexibleAdapter<*>) : + BaseFlexibleViewHolder(view, adapter, true) { fun bind(item: LangItem) { - itemView.title.text = when { + title.text = when { item.code == "" -> itemView.context.getString(R.string.other_source) else -> { val locale = Locale(item.code) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt index e361b7b9c..5a052d0e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt @@ -3,53 +3,51 @@ package eu.kanade.tachiyomi.ui.catalogue import android.os.Build import android.view.View import android.view.ViewGroup -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.online.LoginSource +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.dpToPx import eu.kanade.tachiyomi.util.getRound import eu.kanade.tachiyomi.util.gone import eu.kanade.tachiyomi.util.visible import io.github.mthli.slice.Slice -import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.view.* +import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.* -class SourceHolder(view: View, adapter: CatalogueAdapter) : FlexibleViewHolder(view, adapter) { +class SourceHolder(view: View, adapter: CatalogueAdapter) : BaseFlexibleViewHolder(view, adapter) { - private val slice = Slice(itemView.card).apply { + private val slice = Slice(card).apply { setColor(adapter.cardBackground) } init { - itemView.source_browse.setOnClickListener { + source_browse.setOnClickListener { adapter.browseClickListener.onBrowseClick(adapterPosition) } - itemView.source_latest.setOnClickListener { + source_latest.setOnClickListener { adapter.latestClickListener.onLatestClick(adapterPosition) } } fun bind(item: SourceItem) { val source = item.source - with(itemView) { - setCardEdges(item) + setCardEdges(item) - // Set source name - title.text = source.name + // Set source name + title.text = source.name - // Set circle letter image. - post { - image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(),false)) - } + // Set circle letter image. + itemView.post { + image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(),false)) + } - // If source is login, show only login option - if (source is LoginSource && !source.isLogged()) { - source_browse.setText(R.string.login) - source_latest.gone() - } else { - source_browse.setText(R.string.browse) - source_latest.visible() - } + // If source is login, show only login option + if (source is LoginSource && !source.isLogged()) { + source_browse.setText(R.string.login) + source_latest.gone() + } else { + source_browse.setText(R.string.browse) + source_latest.visible() } } @@ -94,7 +92,7 @@ class SourceHolder(view: View, adapter: CatalogueAdapter) : FlexibleViewHolder(v } private fun setMargins(left: Int, top: Int, right: Int, bottom: Int) { - val v = itemView.card + val v = card if (v.layoutParams is ViewGroup.MarginLayoutParams) { val p = v.layoutParams as ViewGroup.MarginLayoutParams p.setMargins(left, top, right, bottom) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt index 6d3d2e746..c2ef105fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt @@ -6,7 +6,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.widget.StateImageViewTarget -import kotlinx.android.synthetic.main.catalogue_grid_item.view.* +import kotlinx.android.synthetic.main.catalogue_grid_item.* /** * Class used to hold the displayed data of a manga in the catalogue, like the cover or the title. @@ -27,16 +27,16 @@ class CatalogueGridHolder(private val view: View, private val adapter: FlexibleA */ override fun onSetValues(manga: Manga) { // Set manga title - view.title.text = manga.title + title.text = manga.title // Set alpha of thumbnail. - view.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f + thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f setImage(manga) } override fun setImage(manga: Manga) { - GlideApp.with(view.context).clear(view.thumbnail) + GlideApp.with(view.context).clear(thumbnail) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(view.context) .load(manga) @@ -44,7 +44,7 @@ class CatalogueGridHolder(private val view: View, private val adapter: FlexibleA .centerCrop() .skipMemoryCache(true) .placeholder(android.R.color.transparent) - .into(StateImageViewTarget(view.thumbnail, view.progress)) + .into(StateImageViewTarget(thumbnail, progress)) } } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueHolder.kt index 174bb8075..9a0ec3916 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueHolder.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.ui.catalogue.browse import android.view.View import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder /** * Generic class used to hold the displayed data of a manga in the catalogue. @@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga * @param adapter the adapter handling this holder. */ abstract class CatalogueHolder(view: View, adapter: FlexibleAdapter<*>) : - FlexibleViewHolder(view, adapter) { + BaseFlexibleViewHolder(view, adapter) { /** * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueListHolder.kt index 928a304d9..c0bb0f0ec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueListHolder.kt @@ -6,7 +6,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.util.getResourceColor -import kotlinx.android.synthetic.main.catalogue_list_item.view.* +import kotlinx.android.synthetic.main.catalogue_list_item.* /** * Class used to hold the displayed data of a manga in the catalogue, like the cover or the title. @@ -29,14 +29,14 @@ class CatalogueListHolder(private val view: View, adapter: FlexibleAdapter<*>) : * @param manga the manga to bind. */ override fun onSetValues(manga: Manga) { - view.title.text = manga.title - view.title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor) + title.text = manga.title + title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor) setImage(manga) } override fun setImage(manga: Manga) { - GlideApp.with(view.context).clear(view.thumbnail) + GlideApp.with(view.context).clear(thumbnail) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(view.context) .load(manga) @@ -46,7 +46,7 @@ class CatalogueListHolder(private val view: View, adapter: FlexibleAdapter<*>) : .dontAnimate() .skipMemoryCache(true) .placeholder(android.R.color.transparent) - .into(view.thumbnail) + .into(thumbnail) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchCardHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchCardHolder.kt index e35a2ceb7..b67e89394 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchCardHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchCardHolder.kt @@ -2,14 +2,14 @@ package eu.kanade.tachiyomi.ui.catalogue.global_search import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.widget.StateImageViewTarget -import kotlinx.android.synthetic.main.catalogue_global_search_controller_card_item.view.* +import kotlinx.android.synthetic.main.catalogue_global_search_controller_card_item.* class CatalogueSearchCardHolder(view: View, adapter: CatalogueSearchCardAdapter) - : FlexibleViewHolder(view, adapter) { + : BaseFlexibleViewHolder(view, adapter) { init { // Call onMangaClickListener when item is pressed. @@ -22,13 +22,13 @@ class CatalogueSearchCardHolder(view: View, adapter: CatalogueSearchCardAdapter) } fun bind(manga: Manga) { - itemView.tvTitle.text = manga.title + tvTitle.text = manga.title setImage(manga) } fun setImage(manga: Manga) { - GlideApp.with(itemView.context).clear(itemView.itemImage) + GlideApp.with(itemView.context).clear(itemImage) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(itemView.context) .load(manga) @@ -36,7 +36,7 @@ class CatalogueSearchCardHolder(view: View, adapter: CatalogueSearchCardAdapter) .centerCrop() .skipMemoryCache(true) .placeholder(android.R.color.transparent) - .into(StateImageViewTarget(itemView.itemImage, itemView.progress)) + .into(StateImageViewTarget(itemImage, progress)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchHolder.kt index 0714c4342..b0c06cbbe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchHolder.kt @@ -2,14 +2,14 @@ package eu.kanade.tachiyomi.ui.catalogue.global_search import android.support.v7.widget.LinearLayoutManager import android.view.View -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.gone import eu.kanade.tachiyomi.util.setVectorCompat import eu.kanade.tachiyomi.util.visible -import kotlinx.android.synthetic.main.catalogue_global_search_controller_card.view.* +import kotlinx.android.synthetic.main.catalogue_global_search_controller_card.* /** * Holder that binds the [CatalogueSearchItem] containing catalogue cards. @@ -17,7 +17,8 @@ import kotlinx.android.synthetic.main.catalogue_global_search_controller_card.vi * @param view view of [CatalogueSearchItem] * @param adapter instance of [CatalogueSearchAdapter] */ -class CatalogueSearchHolder(view: View, val adapter: CatalogueSearchAdapter) : FlexibleViewHolder(view, adapter) { +class CatalogueSearchHolder(view: View, val adapter: CatalogueSearchAdapter) : + BaseFlexibleViewHolder(view, adapter) { /** * Adapter containing manga from search results. @@ -27,14 +28,12 @@ class CatalogueSearchHolder(view: View, val adapter: CatalogueSearchAdapter) : F private var lastBoundResults: List? = null init { - with(itemView) { - // Set layout horizontal. - recycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) - recycler.adapter = mangaAdapter + // Set layout horizontal. + recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false) + recycler.adapter = mangaAdapter - nothing_found_icon.setVectorCompat(R.drawable.ic_search_black_112dp, - context.getResourceColor(android.R.attr.textColorHint)) - } + nothing_found_icon.setVectorCompat(R.drawable.ic_search_black_112dp, + view.context.getResourceColor(android.R.attr.textColorHint)) } /** @@ -46,28 +45,26 @@ class CatalogueSearchHolder(view: View, val adapter: CatalogueSearchAdapter) : F val source = item.source val results = item.results - with(itemView) { - // Set Title witch country code if available. - title.text = if (!source.lang.isEmpty()) "${source.name} (${source.lang})" else source.name + // Set Title witch country code if available. + title.text = if (!source.lang.isEmpty()) "${source.name} (${source.lang})" else source.name - when { - results == null -> { - progress.visible() - nothing_found.gone() - } - results.isEmpty() -> { - progress.gone() - nothing_found.visible() - } - else -> { - progress.gone() - nothing_found.gone() - } + when { + results == null -> { + progress.visible() + nothing_found.gone() } - if (results !== lastBoundResults) { - mangaAdapter.updateDataSet(results) - lastBoundResults = results + results.isEmpty() -> { + progress.gone() + nothing_found.visible() } + else -> { + progress.gone() + nothing_found.gone() + } + } + if (results !== lastBoundResults) { + mangaAdapter.updateDataSet(results) + lastBoundResults = results } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt index 0dd3c1fa7..b37df4022 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt @@ -1,14 +1,10 @@ package eu.kanade.tachiyomi.ui.category -import android.graphics.Color -import android.graphics.Typeface import android.view.View -import com.amulyakhare.textdrawable.TextDrawable -import com.amulyakhare.textdrawable.util.ColorGenerator -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.data.database.models.Category +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.getRound -import kotlinx.android.synthetic.main.categories_item.view.* +import kotlinx.android.synthetic.main.categories_item.* /** * Holder used to display category items. @@ -16,16 +12,16 @@ import kotlinx.android.synthetic.main.categories_item.view.* * @param view The view used by category items. * @param adapter The adapter containing this holder. */ -class CategoryHolder(view: View, val adapter: CategoryAdapter) : FlexibleViewHolder(view, adapter) { +class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleViewHolder(view, adapter) { init { // Create round letter image onclick to simulate long click - itemView.image.setOnClickListener { + image.setOnClickListener { // Simulate long click on this view to enter selection mode onLongClick(view) } - setDragHandleView(itemView.reorder) + setDragHandleView(reorder) } /** @@ -35,11 +31,11 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : FlexibleViewHol */ fun bind(category: Category) { // Set capitalized title. - itemView.title.text = category.name.capitalize() + title.text = category.name.capitalize() // Update circle letter image. itemView.post { - itemView.image.setImageDrawable(itemView.image.getRound(category.name.take(1).toUpperCase(),false)) + image.setImageDrawable(image.getRound(category.name.take(1).toUpperCase(),false)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt index 39211c01c..fefc804a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt @@ -1,8 +1,8 @@ package eu.kanade.tachiyomi.ui.download -import android.support.v7.widget.RecyclerView import android.view.View import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder import kotlinx.android.synthetic.main.download_item.view.* /** @@ -12,7 +12,7 @@ import kotlinx.android.synthetic.main.download_item.view.* * @param view the inflated view for this holder. * @constructor creates a new download holder. */ -class DownloadHolder(private val view: View) : RecyclerView.ViewHolder(view) { +class DownloadHolder(private val view: View) : BaseViewHolder(view) { private lateinit var download: Download diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 429e80e98..2bc68cf3d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -5,7 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource -import kotlinx.android.synthetic.main.catalogue_grid_item.view.* +import kotlinx.android.synthetic.main.catalogue_grid_item.* /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -30,30 +30,28 @@ class LibraryGridHolder( */ override fun onSetValues(item: LibraryItem) { // Update the title of the manga. - view.title.text = item.manga.title + title.text = item.manga.title // Update the unread count and its visibility. - with(view.unread_text) { + with(unread_text) { visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE text = item.manga.unread.toString() } // Update the download count and its visibility. - with(view.download_text) { + with(download_text) { visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE text = item.downloadCount.toString() } //set local visibility if its local manga - with(view.local_text) { - visibility = if(item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE - } + local_text.visibility = if(item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE // Update the cover. - GlideApp.with(view.context).clear(view.thumbnail) + GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context) .load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() - .into(view.thumbnail) + .into(thumbnail) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt index ff29155c4..41d7f9879 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.library import android.view.View import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.viewholders.FlexibleViewHolder +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder /** * Generic class used to hold the displayed data of a manga in the library. @@ -14,7 +14,7 @@ import eu.davidea.viewholders.FlexibleViewHolder abstract class LibraryHolder( view: View, adapter: FlexibleAdapter<*> -) : FlexibleViewHolder(view, adapter) { +) : BaseFlexibleViewHolder(view, adapter) { /** * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 37a23fe37..83cc69e25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -5,7 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource -import kotlinx.android.synthetic.main.catalogue_list_item.view.* +import kotlinx.android.synthetic.main.catalogue_list_item.* /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -30,38 +30,36 @@ class LibraryListHolder( */ override fun onSetValues(item: LibraryItem) { // Update the title of the manga. - itemView.title.text = item.manga.title + title.text = item.manga.title // Update the unread count and its visibility. - with(itemView.unread_text) { + with(unread_text) { visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE text = item.manga.unread.toString() } // Update the download count and its visibility. - with(itemView.download_text) { + with(download_text) { visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE text = "${item.downloadCount}" } //show local text badge if local manga - with(itemView.local_text) { - visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE - } + local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE // Create thumbnail onclick to simulate long click - itemView.thumbnail.setOnClickListener { + thumbnail.setOnClickListener { // Simulate long click on this view to enter selection mode onLongClick(itemView) } // Update the cover. - GlideApp.with(itemView.context).clear(itemView.thumbnail) + GlideApp.with(itemView.context).clear(thumbnail) GlideApp.with(itemView.context) .load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .circleCrop() .dontAnimate() - .into(itemView.thumbnail) + .into(thumbnail) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt index 936763bf7..5be199cae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt @@ -2,41 +2,41 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.view.View import android.widget.PopupMenu -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.gone import eu.kanade.tachiyomi.util.setVectorCompat -import kotlinx.android.synthetic.main.chapters_item.view.* +import kotlinx.android.synthetic.main.chapters_item.* import java.util.* class ChapterHolder( private val view: View, private val adapter: ChaptersAdapter -) : FlexibleViewHolder(view, adapter) { +) : BaseFlexibleViewHolder(view, adapter) { init { // We need to post a Runnable to show the popup to make sure that the PopupMenu is // correctly positioned. The reason being that the view may change position before the // PopupMenu is shown. - view.chapter_menu.setOnClickListener { it.post { showPopupMenu(it) } } + chapter_menu.setOnClickListener { it.post { showPopupMenu(it) } } } - fun bind(item: ChapterItem, manga: Manga) = with(view) { + fun bind(item: ChapterItem, manga: Manga) { val chapter = item.chapter chapter_title.text = when (manga.displayMode) { Manga.DISPLAY_NUMBER -> { val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) - context.getString(R.string.display_mode_chapter, number) + itemView.context.getString(R.string.display_mode_chapter, number) } else -> chapter.name } // Set the correct drawable for dropdown and update the tint to match theme. - view.chapter_menu.setVectorCompat(R.drawable.ic_more_horiz_black_24dp, view.context.getResourceColor(R.attr.icon_color)) + chapter_menu.setVectorCompat(R.drawable.ic_more_horiz_black_24dp, view.context.getResourceColor(R.attr.icon_color)) // Set correct text color chapter_title.setTextColor(if (chapter.read) adapter.readColor else adapter.unreadColor) @@ -53,14 +53,14 @@ class ChapterHolder( chapter_scanlator.text = chapter.scanlator //allow longer titles if there is no scanlator (most sources) if (chapter_scanlator.text.isNullOrBlank()) { - chapter_title.setMaxLines(2) + chapter_title.maxLines = 2 chapter_scanlator.gone() } else { - chapter_title.setMaxLines(1) + chapter_title.maxLines = 1 } chapter_pages.text = if (!chapter.read && chapter.last_page_read > 0) { - context.getString(R.string.chapter_progress, chapter.last_page_read + 1) + itemView.context.getString(R.string.chapter_progress, chapter.last_page_read + 1) } else { "" } @@ -68,7 +68,7 @@ class ChapterHolder( notifyStatus(item.status) } - fun notifyStatus(status: Int) = with(view.download_text) { + fun notifyStatus(status: Int) = with(download_text) { when (status) { Download.QUEUE -> setText(R.string.chapter_queued) Download.DOWNLOADING -> setText(R.string.chapter_downloading) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt index e5972f296..2996bc929 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt @@ -1,29 +1,29 @@ package eu.kanade.tachiyomi.ui.manga.track import android.annotation.SuppressLint -import android.support.v7.widget.RecyclerView import android.view.View import eu.kanade.tachiyomi.R -import kotlinx.android.synthetic.main.track_item.view.* +import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder +import kotlinx.android.synthetic.main.track_item.* -class TrackHolder(view: View, adapter: TrackAdapter) : RecyclerView.ViewHolder(view) { +class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) { init { val listener = adapter.rowClickListener - view.title_container.setOnClickListener { listener.onTitleClick(adapterPosition) } - view.status_container.setOnClickListener { listener.onStatusClick(adapterPosition) } - view.chapters_container.setOnClickListener { listener.onChaptersClick(adapterPosition) } - view.score_container.setOnClickListener { listener.onScoreClick(adapterPosition) } + title_container.setOnClickListener { listener.onTitleClick(adapterPosition) } + status_container.setOnClickListener { listener.onStatusClick(adapterPosition) } + chapters_container.setOnClickListener { listener.onChaptersClick(adapterPosition) } + score_container.setOnClickListener { listener.onScoreClick(adapterPosition) } } @SuppressLint("SetTextI18n") @Suppress("DEPRECATION") - fun bind(item: TrackItem) = with(itemView) { + fun bind(item: TrackItem) { val track = item.track track_logo.setImageResource(item.service.getLogo()) logo.setBackgroundColor(item.service.getLogoColor()) if (track != null) { - track_title.setTextAppearance(context, R.style.TextAppearance_Regular_Body1_Secondary) + track_title.setTextAppearance(itemView.context, R.style.TextAppearance_Regular_Body1_Secondary) track_title.setAllCaps(false) track_title.text = track.title track_chapters.text = "${track.last_chapter_read}/" + @@ -31,7 +31,7 @@ class TrackHolder(view: View, adapter: TrackAdapter) : RecyclerView.ViewHolder(v track_status.text = item.service.getStatus(track.status) track_score.text = if (track.score == 0f) "-" else item.service.displayScore(track) } else { - track_title.setTextAppearance(context, R.style.TextAppearance_Medium_Button) + track_title.setTextAppearance(itemView.context, R.style.TextAppearance_Medium_Button) track_title.setText(R.string.action_edit) track_chapters.text = "" track_score.text = "" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt index 39958bd98..dedccad24 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon -import android.support.v7.widget.RecyclerView import android.view.MotionEvent import android.view.View import android.view.ViewGroup @@ -11,10 +10,11 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.viewer.base.PageDecodeErrorLayout import eu.kanade.tachiyomi.util.inflate -import kotlinx.android.synthetic.main.reader_webtoon_item.view.* +import kotlinx.android.synthetic.main.reader_webtoon_item.* import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit * @constructor creates a new webtoon holder. */ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) : - RecyclerView.ViewHolder(view) { + BaseViewHolder(view) { /** * Page of a chapter. @@ -54,7 +54,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) private var decodeErrorLayout: View? = null init { - with(view.image_view) { + with(image_view) { setMaxTileSize(readerActivity.maxBitmapSize) setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED) setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE) @@ -78,11 +78,11 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) }) } - view.progress_container.layoutParams = FrameLayout.LayoutParams( + progress_container.layoutParams = FrameLayout.LayoutParams( MATCH_PARENT, webtoonReader.screenHeight) view.setOnTouchListener(adapter.touchListener) - view.retry_button.setOnTouchListener { _, event -> + retry_button.setOnTouchListener { _, event -> if (event.action == MotionEvent.ACTION_UP) { readerActivity.presenter.retryPage(page) } @@ -111,9 +111,9 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) (view as ViewGroup).removeView(it) decodeErrorLayout = null } - view.image_view.recycle() - view.image_view.visibility = View.GONE - view.progress_container.visibility = View.VISIBLE + image_view.recycle() + image_view.visibility = View.GONE + progress_container.visibility = View.VISIBLE } /** @@ -150,7 +150,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) .onBackpressureLatest() .observeOn(AndroidSchedulers.mainThread()) .subscribe { progress -> - view.progress_text.text = if (progress > 0) { + progress_text.text = if (progress > 0) { view.context.getString(R.string.download_progress, progress) } else { view.context.getString(R.string.downloading) @@ -279,14 +279,14 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) * Called when the image is decoded and going to be displayed. */ private fun onImageDecoded() { - view.progress_container.visibility = View.GONE + progress_container.visibility = View.GONE } /** * Called when the image fails to decode. */ private fun onImageDecodeError() { - view.progress_container.visibility = View.GONE + progress_container.visibility = View.GONE val page = page ?: return if (decodeErrorLayout != null || !webtoonReader.isAdded) return 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 37a72f537..4a5f139d9 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 @@ -3,13 +3,13 @@ package eu.kanade.tachiyomi.ui.recent_updates import android.view.View import android.widget.PopupMenu 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.data.glide.GlideApp +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.setVectorCompat -import kotlinx.android.synthetic.main.recent_chapters_item.view.* +import kotlinx.android.synthetic.main.recent_chapters_item.* /** * Holder that contains chapter item @@ -22,7 +22,7 @@ import kotlinx.android.synthetic.main.recent_chapters_item.view.* * @constructor creates a new recent chapter holder. */ class RecentChapterHolder(private val view: View, private val adapter: RecentChaptersAdapter) : - FlexibleViewHolder(view, adapter) { + BaseFlexibleViewHolder(view, adapter) { /** * Color of read chapter @@ -43,8 +43,8 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha // We need to post a Runnable to show the popup to make sure that the PopupMenu is // 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 { + chapter_menu.setOnClickListener { it.post { showPopupMenu(it) } } + manga_cover.setOnClickListener { adapter.coverClickListener.onCoverClick(adapterPosition) } } @@ -58,31 +58,31 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha this.item = item // Set chapter title - view.chapter_title.text = item.chapter.name + chapter_title.text = item.chapter.name // Set manga title - view.manga_title.text = item.manga.title + manga_title.text = item.manga.title // Set the correct drawable for dropdown and update the tint to match theme. - view.chapter_menu_icon.setVectorCompat(R.drawable.ic_more_horiz_black_24dp, view.context.getResourceColor(R.attr.icon_color)) + chapter_menu_icon.setVectorCompat(R.drawable.ic_more_horiz_black_24dp, view.context.getResourceColor(R.attr.icon_color)) // Set cover - GlideApp.with(itemView.context).clear(itemView.manga_cover) + GlideApp.with(itemView.context).clear(manga_cover) if (!item.manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(itemView.context) .load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .circleCrop() - .into(itemView.manga_cover) + .into(manga_cover) } // Check if chapter is read and set correct color if (item.chapter.read) { - view.chapter_title.setTextColor(readColor) - view.manga_title.setTextColor(readColor) + chapter_title.setTextColor(readColor) + manga_title.setTextColor(readColor) } else { - view.chapter_title.setTextColor(unreadColor) - view.manga_title.setTextColor(unreadColor) + chapter_title.setTextColor(unreadColor) + manga_title.setTextColor(unreadColor) } // Set chapter status @@ -94,7 +94,7 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha * * @param status download status */ - fun notifyStatus(status: Int) = with(view.download_text) { + fun notifyStatus(status: Int) = with(download_text) { when (status) { Download.QUEUE -> setText(R.string.chapter_queued) Download.DOWNLOADING -> setText(R.string.chapter_downloading) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt index ecabfb873..07db9a509 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt @@ -2,11 +2,11 @@ package eu.kanade.tachiyomi.ui.recently_read import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy -import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory import eu.kanade.tachiyomi.data.glide.GlideApp -import kotlinx.android.synthetic.main.recently_read_item.view.* +import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder +import kotlinx.android.synthetic.main.recently_read_item.* import java.util.* /** @@ -21,18 +21,18 @@ import java.util.* class RecentlyReadHolder( view: View, val adapter: RecentlyReadAdapter -) : FlexibleViewHolder(view, adapter) { +) : BaseFlexibleViewHolder(view, adapter) { init { - itemView.remove.setOnClickListener { + remove.setOnClickListener { adapter.removeClickListener.onRemoveClick(adapterPosition) } - itemView.resume.setOnClickListener { + resume.setOnClickListener { adapter.resumeClickListener.onResumeClick(adapterPosition) } - itemView.cover.setOnClickListener { + cover.setOnClickListener { adapter.coverClickListener.onCoverClick(adapterPosition) } } @@ -47,24 +47,24 @@ class RecentlyReadHolder( val (manga, chapter, history) = item // Set manga title - itemView.manga_title.text = manga.title + manga_title.text = manga.title // Set source + chapter title val formattedNumber = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) - itemView.manga_source.text = itemView.context.getString(R.string.recent_manga_source) + manga_source.text = itemView.context.getString(R.string.recent_manga_source) .format(adapter.sourceManager.get(manga.source)?.toString(), formattedNumber) // Set last read timestamp title - itemView.last_read.text = adapter.dateFormat.format(Date(history.last_read)) + last_read.text = adapter.dateFormat.format(Date(history.last_read)) // Set cover - GlideApp.with(itemView.context).clear(itemView.cover) + GlideApp.with(itemView.context).clear(cover) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(itemView.context) .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() - .into(itemView.cover) + .into(cover) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt index 1a2f6c458..7f391eced 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.ui.setting import android.app.Dialog +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.support.v7.preference.PreferenceScreen import android.view.View @@ -22,8 +24,6 @@ import java.text.ParseException import java.text.SimpleDateFormat import java.util.* import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys -import android.content.Intent -import android.net.Uri class SettingsAboutController : SettingsController() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt index 25f847b72..c7982d0d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt @@ -3,8 +3,6 @@ package eu.kanade.tachiyomi.ui.setting import android.graphics.drawable.Drawable import android.support.v7.preference.PreferenceGroup import android.support.v7.preference.PreferenceScreen -import com.bluelinelabs.conductor.ControllerChangeHandler -import com.bluelinelabs.conductor.ControllerChangeType import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager