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
This commit is contained in:
Gianmarco David 2017-01-04 12:50:31 +01:00 committed by Bram van de Kerkhof
parent d0260acd3d
commit 2c8790c545
10 changed files with 87 additions and 85 deletions

View file

@ -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.base.fragment.BaseRxFragment
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaActivity import eu.kanade.tachiyomi.ui.manga.MangaActivity
import eu.kanade.tachiyomi.util.connectivityManager
import eu.kanade.tachiyomi.util.inflate import eu.kanade.tachiyomi.util.inflate
import eu.kanade.tachiyomi.util.snack import eu.kanade.tachiyomi.util.snack
import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.util.toast
@ -420,8 +421,8 @@ open class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleVie
val isListMode = presenter.isListMode val isListMode = presenter.isListMode
activity.invalidateOptionsMenu() activity.invalidateOptionsMenu()
switcher.showNext() switcher.showNext()
if (!isListMode) { if (!isListMode || !context.connectivityManager.isActiveNetworkMetered) {
// Initialize mangas if going to grid view // Initialize mangas if going to grid view or if over wifi when going to list view
presenter.initializeMangas(adapter.items) presenter.initializeMangas(adapter.items)
} }
} }
@ -444,8 +445,10 @@ open class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleVie
* @param manga the manga to find. * @param manga the manga to find.
* @return the holder of the manga or null if it's not bound. * @return the holder of the manga or null if it's not bound.
*/ */
private fun getHolder(manga: Manga): CatalogueGridHolder? { private fun getHolder(manga: Manga): CatalogueHolder? {
return catalogue_grid.findViewHolderForItemId(manga.id!!) as? CatalogueGridHolder return (catalogue_grid.findViewHolderForItemId(manga.id!!) ?:
catalogue_list.findViewHolderForItemId(manga.id!!))
as? CatalogueHolder
} }
/** /**

View file

@ -34,13 +34,7 @@ class CatalogueGridHolder(private val view: View, private val adapter: Catalogue
setImage(manga) setImage(manga)
} }
/** override fun setImage(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.
*/
fun setImage(manga: Manga) {
Glide.clear(view.thumbnail) Glide.clear(view.thumbnail)
if (!manga.thumbnail_url.isNullOrEmpty()) { if (!manga.thumbnail_url.isNullOrEmpty()) {
Glide.with(view.context) Glide.with(view.context)

View file

@ -21,4 +21,13 @@ abstract class CatalogueHolder(view: View, adapter: CatalogueAdapter, listener:
* @param manga the manga to bind. * @param manga the manga to bind.
*/ */
abstract fun onSetValues(manga: Manga) 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)
} }

View file

@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.ui.catalogue package eu.kanade.tachiyomi.ui.catalogue
import android.view.View 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.data.database.models.Manga
import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.getResourceColor
import kotlinx.android.synthetic.main.item_catalogue_list.view.* 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) { override fun onSetValues(manga: Manga) {
view.title.text = manga.title view.title.text = manga.title
view.title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor) 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)
} }
} }
}

View file

@ -140,9 +140,7 @@ open class CataloguePresenter : BasePresenter<CatalogueFragment>() {
this.query = query this.query = query
this.appliedFilters = filters this.appliedFilters = filters
if (!isListMode) {
subscribeToMangaInitializer() subscribeToMangaInitializer()
}
// Create a new pager. // Create a new pager.
pager = createPager(query, filters) pager = createPager(query, filters)
@ -200,12 +198,8 @@ open class CataloguePresenter : BasePresenter<CatalogueFragment>() {
*/ */
private fun setDisplayMode(asList: Boolean) { private fun setDisplayMode(asList: Boolean) {
isListMode = asList isListMode = asList
if (asList) {
initializerSubscription?.let { remove(it) }
} else {
subscribeToMangaInitializer() subscribeToMangaInitializer()
} }
}
/** /**
* Subscribes to the initializer of manga details and updates the view if needed. * Subscribes to the initializer of manga details and updates the view if needed.

View file

@ -91,7 +91,7 @@ class LibraryCategoryAdapter(val fragment: LibraryCategoryView) :
} }
return LibraryGridHolder(view, this, fragment) return LibraryGridHolder(view, this, fragment)
} else { } else {
val view = parent.inflate(R.layout.item_library_list) val view = parent.inflate(R.layout.item_catalogue_list)
return LibraryListHolder(view, this, fragment) return LibraryListHolder(view, this, fragment)
} }
} }

View file

@ -5,7 +5,7 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder 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. * Class used to hold the displayed data of a manga in the library, like the cover or the title.

View file

@ -1,17 +1,57 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall" android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height"
android:background="?attr/selectable_list_drawable"> android:background="?attr/selectable_list_drawable">
<TextView <de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/title" android:id="@+id/thumbnail"
style="@style/TextAppearance.Regular.Body1" android:layout_width="@dimen/material_component_lists_single_line_with_avatar_height"
android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height"
android:layout_gravity="center_vertical"
android:paddingEnd="0dp"
android:paddingLeft="@dimen/material_component_lists_icon_left_padding"
android:paddingRight="0dp"
android:paddingStart="@dimen/material_component_lists_icon_left_padding"
tools:src="@drawable/icon"/>
<RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:paddingLeft="?android:listPreferredItemPaddingLeft" android:paddingLeft="@dimen/material_component_lists_text_left_padding"
android:paddingRight="?android:listPreferredItemPaddingLeft"/> 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">
<TextView
android:id="@+id/unread_text"
style="@style/TextAppearance.Regular.Caption.Hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingStart="4dp"
android:paddingLeft="4dp"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Caption.Hint"
android:visibility="gone"
tools:text="22"/>
<TextView
android:id="@+id/title"
style="@style/TextAppearance.Regular.SubHeading"
android:layout_toLeftOf="@id/unread_text"
android:layout_toStartOf="@id/unread_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
tools:text="Manga title"/>
</RelativeLayout>
</FrameLayout> </FrameLayout>

View file

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height"
android:background="?attr/selectable_list_drawable">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/material_component_lists_single_line_with_avatar_height"
android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height"
android:layout_gravity="center_vertical"
android:paddingEnd="0dp"
android:paddingLeft="@dimen/material_component_lists_icon_left_padding"
android:paddingRight="0dp"
android:paddingStart="@dimen/material_component_lists_icon_left_padding"
tools:src="@drawable/icon"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
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">
<TextView
android:id="@+id/unread_text"
style="@style/TextAppearance.Regular.Caption.Hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingStart="4dp"
android:paddingLeft="4dp"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Caption.Hint"
tools:text="22"/>
<TextView
android:id="@+id/title"
style="@style/TextAppearance.Regular.SubHeading"
android:layout_toLeftOf="@id/unread_text"
android:layout_toStartOf="@id/unread_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
tools:text="Manga title"/>
</RelativeLayout>
</FrameLayout>

View file

@ -5,5 +5,4 @@
android:id="@+id/library_list" android:id="@+id/library_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:listitem="@layout/item_library_list" /> tools:listitem="@layout/item_catalogue_list" />