From 2c8790c545b7554a01065cd3dcd1337f424f9477 Mon Sep 17 00:00:00 2001 From: Gianmarco David Date: Wed, 4 Jan 2017 12:50:31 +0100 Subject: [PATCH] Added circular thumbnails to the catalogue list view, like the ones in the library list view (#616) * Added circular thumbnails to the catalogue list view, like the ones in the library list view * Moved setImage to CatalogueHolder parent class and adapted the code so that when the manga is initialized, the thumbnail is set both in the case of grid and list * In catalog, when switching between grid and list, initialize mangas only if going to grid view or if over wifi --- .../ui/catalogue/CatalogueFragment.kt | 11 ++-- .../ui/catalogue/CatalogueGridHolder.kt | 8 +-- .../tachiyomi/ui/catalogue/CatalogueHolder.kt | 9 +++ .../ui/catalogue/CatalogueListHolder.kt | 19 +++++++ .../ui/catalogue/CataloguePresenter.kt | 10 +--- .../ui/library/LibraryCategoryAdapter.kt | 2 +- .../tachiyomi/ui/library/LibraryListHolder.kt | 2 +- .../main/res/layout/item_catalogue_list.xml | 52 +++++++++++++++-- app/src/main/res/layout/item_library_list.xml | 56 ------------------- .../main/res/layout/library_list_recycler.xml | 3 +- 10 files changed, 87 insertions(+), 85 deletions(-) delete mode 100644 app/src/main/res/layout/item_library_list.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt index 55b8c4b29..388d93f09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt @@ -19,6 +19,7 @@ import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaActivity +import eu.kanade.tachiyomi.util.connectivityManager import eu.kanade.tachiyomi.util.inflate import eu.kanade.tachiyomi.util.snack import eu.kanade.tachiyomi.util.toast @@ -420,8 +421,8 @@ open class CatalogueFragment : BaseRxFragment(), FlexibleVie val isListMode = presenter.isListMode activity.invalidateOptionsMenu() switcher.showNext() - if (!isListMode) { - // Initialize mangas if going to grid view + if (!isListMode || !context.connectivityManager.isActiveNetworkMetered) { + // Initialize mangas if going to grid view or if over wifi when going to list view presenter.initializeMangas(adapter.items) } } @@ -444,8 +445,10 @@ open class CatalogueFragment : BaseRxFragment(), FlexibleVie * @param manga the manga to find. * @return the holder of the manga or null if it's not bound. */ - private fun getHolder(manga: Manga): CatalogueGridHolder? { - return catalogue_grid.findViewHolderForItemId(manga.id!!) as? CatalogueGridHolder + private fun getHolder(manga: Manga): CatalogueHolder? { + return (catalogue_grid.findViewHolderForItemId(manga.id!!) ?: + catalogue_list.findViewHolderForItemId(manga.id!!)) + as? CatalogueHolder } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueGridHolder.kt index 0dcd4e182..f057164e8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueGridHolder.kt @@ -34,13 +34,7 @@ class CatalogueGridHolder(private val view: View, private val adapter: Catalogue setImage(manga) } - /** - * Updates the image for this holder. Useful to update the image when the manga is initialized - * and the url is now known. - * - * @param manga the manga to bind. - */ - fun setImage(manga: Manga) { + override fun setImage(manga: Manga) { Glide.clear(view.thumbnail) if (!manga.thumbnail_url.isNullOrEmpty()) { Glide.with(view.context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueHolder.kt index 1280a0be8..e6a1c63e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueHolder.kt @@ -21,4 +21,13 @@ abstract class CatalogueHolder(view: View, adapter: CatalogueAdapter, listener: * @param manga the manga to bind. */ abstract fun onSetValues(manga: Manga) + + + /** + * Updates the image for this holder. Useful to update the image when the manga is initialized + * and the url is now known. + * + * @param manga the manga to bind. + */ + abstract fun setImage(manga: Manga) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueListHolder.kt index 262311cc2..10d9e6bed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueListHolder.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.ui.catalogue import android.view.View +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.util.getResourceColor import kotlinx.android.synthetic.main.item_catalogue_list.view.* @@ -29,5 +31,22 @@ class CatalogueListHolder(private val view: View, adapter: CatalogueAdapter, lis override fun onSetValues(manga: Manga) { view.title.text = manga.title view.title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor) + + setImage(manga) } + + override fun setImage(manga: Manga) { + Glide.clear(view.thumbnail) + if (!manga.thumbnail_url.isNullOrEmpty()) { + Glide.with(view.context) + .load(manga) + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .centerCrop() + .dontAnimate() + .skipMemoryCache(true) + .placeholder(android.R.color.transparent) + .into(view.thumbnail) + } + } + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt index 03adb70e6..b6cb0bfa6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt @@ -140,9 +140,7 @@ open class CataloguePresenter : BasePresenter() { this.query = query this.appliedFilters = filters - if (!isListMode) { - subscribeToMangaInitializer() - } + subscribeToMangaInitializer() // Create a new pager. pager = createPager(query, filters) @@ -200,11 +198,7 @@ open class CataloguePresenter : BasePresenter() { */ private fun setDisplayMode(asList: Boolean) { isListMode = asList - if (asList) { - initializerSubscription?.let { remove(it) } - } else { - subscribeToMangaInitializer() - } + subscribeToMangaInitializer() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index c5bc50303..2d7e8a75b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -91,7 +91,7 @@ class LibraryCategoryAdapter(val fragment: LibraryCategoryView) : } return LibraryGridHolder(view, this, fragment) } else { - val view = parent.inflate(R.layout.item_library_list) + val view = parent.inflate(R.layout.item_catalogue_list) return LibraryListHolder(view, this, fragment) } } 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 d0928262b..22dd444c9 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.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder -import kotlinx.android.synthetic.main.item_library_list.view.* +import kotlinx.android.synthetic.main.item_catalogue_list.view.* /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. diff --git a/app/src/main/res/layout/item_catalogue_list.xml b/app/src/main/res/layout/item_catalogue_list.xml index f9d1b20f8..dac38717a 100644 --- a/app/src/main/res/layout/item_catalogue_list.xml +++ b/app/src/main/res/layout/item_catalogue_list.xml @@ -1,17 +1,57 @@ - + + + android:paddingLeft="@dimen/material_component_lists_text_left_padding" + android:paddingStart="@dimen/material_component_lists_text_left_padding" + android:paddingRight="@dimen/material_component_lists_right_padding" + android:paddingEnd="@dimen/material_component_lists_right_padding"> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_library_list.xml b/app/src/main/res/layout/item_library_list.xml deleted file mode 100644 index d846ab9d0..000000000 --- a/app/src/main/res/layout/item_library_list.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/library_list_recycler.xml b/app/src/main/res/layout/library_list_recycler.xml index 8f5dc91b3..07f543f3d 100644 --- a/app/src/main/res/layout/library_list_recycler.xml +++ b/app/src/main/res/layout/library_list_recycler.xml @@ -5,5 +5,4 @@ android:id="@+id/library_list" android:layout_width="match_parent" android:layout_height="match_parent" - tools:listitem="@layout/item_library_list" /> - + tools:listitem="@layout/item_catalogue_list" />