Improve: better color preview

This commit is contained in:
zt515 2017-11-03 23:43:24 +08:00
parent 26d131d5c6
commit fbe04df42e
4 changed files with 47 additions and 18 deletions

View File

@ -11,13 +11,16 @@ import io.neoterm.ui.customize.model.ColorItem
class ColorItemViewHolder(private val rootView: View, private val listener: ColorItemAdapter.Listener) : SortedListAdapter.ViewHolder<ColorItem>(rootView) { class ColorItemViewHolder(private val rootView: View, private val listener: ColorItemAdapter.Listener) : SortedListAdapter.ViewHolder<ColorItem>(rootView) {
private val colorItemName: TextView = rootView.findViewById<TextView>(R.id.color_item_name) private val colorItemName: TextView = rootView.findViewById<TextView>(R.id.color_item_name)
private val colorItemDesc: TextView = rootView.findViewById<TextView>(R.id.color_item_description) private val colorItemDesc: TextView = rootView.findViewById<TextView>(R.id.color_item_description)
private val colorView: View = rootView.findViewById<View>(R.id.color_item_view)
override fun performBind(item: ColorItem) { override fun performBind(item: ColorItem) {
rootView.setOnClickListener { listener.onModelClicked(item) } rootView.setOnClickListener { listener.onModelClicked(item) }
colorItemName.text = item.colorName colorItemName.text = item.colorName
colorItemDesc.text = item.colorValue colorItemDesc.text = item.colorValue
if (item.colorValue.isNotEmpty()) { if (item.colorValue.isNotEmpty()) {
colorItemDesc.setTextColor(TerminalColors.parse(item.colorValue)) val color = TerminalColors.parse(item.colorValue)
colorView.setBackgroundColor(color)
colorItemDesc.setTextColor(color)
} }
} }
} }

View File

@ -3,28 +3,45 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/package_item_padding" android:layout_gravity="center"
android:background="?attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:background="?attr/selectableItemBackground" android:orientation="horizontal"
android:orientation="vertical"> android:padding="@dimen/package_item_padding">
<TextView <View
android:id="@+id/color_item_name" android:id="@+id/color_item_view"
style="@style/TextAppearance.AppCompat.Medium" android:layout_width="@dimen/preview_layout_width"
android:layout_height="@dimen/preview_layout_height"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1" android:layout_marginEnd="@dimen/preview_layout_margin_small"
android:textColor="@color/textColor" android:layout_marginLeft="@dimen/preview_layout_margin_small"
tools:text="Color Item Name" /> android:layout_marginRight="@dimen/preview_layout_margin_small"
android:layout_marginStart="@dimen/preview_layout_margin_small"
android:orientation="vertical">
<TextView <TextView
android:id="@+id/color_item_description" android:id="@+id/color_item_name"
android:layout_width="match_parent" style="@style/TextAppearance.AppCompat.Medium"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_marginStart="@dimen/text_margin" android:layout_height="wrap_content"
android:maxLines="3" android:maxLines="1"
android:textColor="@color/textColorSecondary" android:textColor="@color/textColor"
tools:text="Color Item Description" /> tools:text="Color Item Name" />
<TextView
android:id="@+id/color_item_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:textColor="@color/textColorSecondary"
tools:text="Color Item Description" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -51,6 +51,12 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginBottom="@dimen/preview_layout_margin_small"
android:layout_marginEnd="@dimen/preview_layout_margin_small"
android:layout_marginLeft="@dimen/preview_layout_margin_small"
android:layout_marginRight="@dimen/preview_layout_margin_small"
android:layout_marginStart="@dimen/preview_layout_margin_small"
android:layout_marginTop="0dp"
android:layout_weight="1.0" android:layout_weight="1.0"
android:orientation="vertical"> android:orientation="vertical">

View File

@ -2,7 +2,10 @@
<dimen name="app_bar_height">180dp</dimen> <dimen name="app_bar_height">180dp</dimen>
<dimen name="fab_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen>
<dimen name="text_margin">16dp</dimen> <dimen name="text_margin">16dp</dimen>
<dimen name="preview_layout_margin_small">8dp</dimen>
<dimen name="preview_layout_margin">32dp</dimen> <dimen name="preview_layout_margin">32dp</dimen>
<dimen name="preview_layout_height">32dp</dimen>
<dimen name="preview_layout_width">32dp</dimen>
<dimen name="eks_height">32dp</dimen> <dimen name="eks_height">32dp</dimen>
<dimen name="eks_height_two_line">72dp</dimen> <dimen name="eks_height_two_line">72dp</dimen>
<dimen name="eks_height_one_line">36dp</dimen> <dimen name="eks_height_one_line">36dp</dimen>