From 79705df4993cd1010197dd603685af71501dd7a3 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 18 Dec 2016 13:08:56 +0100 Subject: [PATCH] Apply material design guidelines to categories --- .../tachiyomi/ui/category/CategoryActivity.kt | 4 +- .../tachiyomi/ui/category/CategoryAdapter.kt | 15 +--- .../tachiyomi/ui/category/CategoryHolder.kt | 23 ++++--- .../main/res/layout/item_edit_categories.xml | 68 ++++++++----------- 4 files changed, 50 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt index 44d295b765..72e6af3a76 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt @@ -27,7 +27,9 @@ import nucleus.factory.RequiresPresenter * UI related actions should be called from here. */ @RequiresPresenter(CategoryPresenter::class) -class CategoryActivity : BaseRxActivity(), ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener, OnStartDragListener { +class CategoryActivity : + BaseRxActivity(), + ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener, OnStartDragListener { /** * Object used to show actionMode toolbar. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryAdapter.kt index a377276a19..ddac48e635 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryAdapter.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.ui.category import android.view.ViewGroup -import com.amulyakhare.textdrawable.util.ColorGenerator import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category @@ -17,18 +16,10 @@ import java.util.* * @param activity activity that created adapter * @constructor Creates a CategoryAdapter object */ -class CategoryAdapter(private val activity: CategoryActivity) : FlexibleAdapter(), ItemTouchHelperAdapter { - - /** - * Generator used to generate circle letter icons - */ - private val generator: ColorGenerator +class CategoryAdapter(private val activity: CategoryActivity) : + FlexibleAdapter(), ItemTouchHelperAdapter { init { - // Let generator use Material Design colors. - // Material design is love, material design is live! - generator = ColorGenerator.MATERIAL - // Set unique id's setHasStableIds(true) } @@ -54,7 +45,7 @@ class CategoryAdapter(private val activity: CategoryActivity) : FlexibleAdapter< override fun onBindViewHolder(holder: CategoryHolder, position: Int) { // Update holder values. val category = getItem(position) - holder.onSetValues(category, generator) + holder.onSetValues(category) //When user scrolls this bind the correct selection status holder.itemView.isActivated = isSelected(position) 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 f62db2cfa7..b9cec34456 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 @@ -24,7 +24,12 @@ import kotlinx.android.synthetic.main.item_edit_categories.view.* * * @constructor Create CategoryHolder object */ -class CategoryHolder(view: View, adapter: CategoryAdapter, listener: FlexibleViewHolder.OnListItemClickListener, dragListener: OnStartDragListener) : FlexibleViewHolder(view, adapter, listener) { +class CategoryHolder( + view: View, + adapter: CategoryAdapter, + listener: FlexibleViewHolder.OnListItemClickListener, + dragListener: OnStartDragListener +) : FlexibleViewHolder(view, adapter, listener) { init { // Create round letter image onclick to simulate long click @@ -46,29 +51,31 @@ class CategoryHolder(view: View, adapter: CategoryAdapter, listener: FlexibleVie * Update category item values. * * @param category category of item. - * @param generator generator used to generate circle letter icons. */ - fun onSetValues(category: Category, generator: ColorGenerator) { + fun onSetValues(category: Category) { // Set capitalized title. itemView.title.text = category.name.capitalize() // Update circle letter image. - itemView.image.setImageDrawable(getRound(category.name.substring(0, 1).toUpperCase(), generator)) + itemView.post { + itemView.image.setImageDrawable(getRound(category.name.take(1).toUpperCase())) + } } /** * Returns circle letter image * * @param text first letter of string - * @param generator the generator used to generate circle letter image */ - private fun getRound(text: String, generator: ColorGenerator): TextDrawable { + private fun getRound(text: String): TextDrawable { + val size = Math.min(itemView.image.width, itemView.image.height) return TextDrawable.builder() .beginConfig() + .width(size) + .height(size) .textColor(Color.WHITE) .useFont(Typeface.DEFAULT) - .toUpperCase() .endConfig() - .buildRound(text, generator.getColor(text)) + .buildRound(text, ColorGenerator.MATERIAL.getColor(text)) } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_edit_categories.xml b/app/src/main/res/layout/item_edit_categories.xml index 00fa12e329..42cbe12af2 100644 --- a/app/src/main/res/layout/item_edit_categories.xml +++ b/app/src/main/res/layout/item_edit_categories.xml @@ -1,53 +1,43 @@ - + + - - + android:paddingLeft="@dimen/material_component_lists_icon_left_padding" + android:paddingStart="@dimen/material_component_lists_icon_left_padding" + android:paddingRight="0dp" + android:paddingEnd="0dp"/> - \ No newline at end of file + + + \ No newline at end of file