Update: Rounded Icons

Update: Use ShapeableImageView
This commit is contained in:
LooKeR 2021-10-16 09:47:32 +05:30
parent 649055d7f1
commit 7a36d943c0
15 changed files with 51 additions and 30 deletions

View File

@ -23,10 +23,15 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.* import android.widget.*
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import androidx.core.text.util.LinkifyCompat import androidx.core.text.util.LinkifyCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import coil.transform.RoundedCornersTransformation
import com.google.android.material.imageview.ShapeableImageView
import com.google.android.material.switchmaterial.SwitchMaterial
import com.looker.droidify.R import com.looker.droidify.R
import com.looker.droidify.content.Preferences import com.looker.droidify.content.Preferences
import com.looker.droidify.content.ProductPreferences import com.looker.droidify.content.ProductPreferences
@ -304,7 +309,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private enum class Payload { REFRESH, STATUS } private enum class Payload { REFRESH, STATUS }
private class HeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private class HeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val icon = itemView.findViewById<ImageView>(R.id.icon)!! val icon = itemView.findViewById<ShapeableImageView>(R.id.icon)!!
val name = itemView.findViewById<TextView>(R.id.name)!! val name = itemView.findViewById<TextView>(R.id.name)!!
val version = itemView.findViewById<TextView>(R.id.version)!! val version = itemView.findViewById<TextView>(R.id.version)!!
val packageName = itemView.findViewById<TextView>(R.id.package_name)!! val packageName = itemView.findViewById<TextView>(R.id.package_name)!!
@ -331,7 +336,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private class SwitchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private class SwitchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val title = itemView.findViewById<TextView>(R.id.title)!! val title = itemView.findViewById<TextView>(R.id.title)!!
val enabled = itemView.findViewById<Switch>(R.id.enabled)!! val enabled = itemView.findViewById<SwitchMaterial>(R.id.enabled)!!
val statefulViews: Sequence<View> val statefulViews: Sequence<View>
get() = sequenceOf(itemView, title, enabled) get() = sequenceOf(itemView, title, enabled)
@ -339,7 +344,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val title = itemView.findViewById<TextView>(R.id.title)!! val title = itemView.findViewById<TextView>(R.id.title)!!
val icon = itemView.findViewById<ImageView>(R.id.icon)!! val icon = itemView.findViewById<ShapeableImageView>(R.id.icon)!!
} }
private class ExpandViewHolder(context: Context) : RecyclerView.ViewHolder(TextView(context)) { private class ExpandViewHolder(context: Context) : RecyclerView.ViewHolder(TextView(context)) {
@ -352,7 +357,11 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
itemView.setTextSizeScaled(14) itemView.setTextSizeScaled(14)
itemView.setTextColor(itemView.context.getColorFromAttr(android.R.attr.textColor)) itemView.setTextColor(itemView.context.getColorFromAttr(android.R.attr.textColor))
itemView.background = itemView.background =
itemView.resources.getDrawable(R.drawable.background_border, context.theme) ResourcesCompat.getDrawable(
itemView.resources,
R.drawable.background_border,
context.theme
)
itemView.gravity = Gravity.CENTER itemView.gravity = Gravity.CENTER
itemView.isAllCaps = true itemView.isAllCaps = true
itemView.layoutParams = RecyclerView.LayoutParams( itemView.layoutParams = RecyclerView.LayoutParams(
@ -400,7 +409,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private val measurement = Measurement<Int>() private val measurement = Measurement<Int>()
} }
val icon = itemView.findViewById<ImageView>(R.id.icon)!! val icon = itemView.findViewById<ShapeableImageView>(R.id.icon)!!
val text = itemView.findViewById<TextView>(R.id.text)!! val text = itemView.findViewById<TextView>(R.id.text)!!
val link = itemView.findViewById<TextView>(R.id.link)!! val link = itemView.findViewById<TextView>(R.id.link)!!
@ -424,7 +433,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private val measurement = Measurement<Int>() private val measurement = Measurement<Int>()
} }
val icon = itemView.findViewById<ImageView>(R.id.icon)!! val icon = itemView.findViewById<ShapeableImageView>(R.id.icon)!!
val text = itemView.findViewById<TextView>(R.id.text)!! val text = itemView.findViewById<TextView>(R.id.text)!!
init { init {
@ -443,7 +452,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private class ScreenshotViewHolder(context: Context) : private class ScreenshotViewHolder(context: Context) :
RecyclerView.ViewHolder(FrameLayout(context)) { RecyclerView.ViewHolder(FrameLayout(context)) {
val image: ImageView val image: AppCompatImageView
val placeholder: Drawable val placeholder: Drawable
@ -461,13 +470,12 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
val primaryColor = val primaryColor =
itemView.context.getColorFromAttr(android.R.attr.textColor).defaultColor itemView.context.getColorFromAttr(android.R.attr.textColor).defaultColor
image = object : ImageView(context) { image = object : AppCompatImageView(context) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec) super.onMeasure(widthMeasureSpec, heightMeasureSpec)
setMeasuredDimension(measuredWidth, measuredWidth) setMeasuredDimension(measuredWidth, measuredWidth)
} }
} }
image.scaleType = ImageView.ScaleType.CENTER_CROP
image.setBackgroundColor(ColorUtils.blendARGB(backgroundColor, accentColor, 0.1f)) image.setBackgroundColor(ColorUtils.blendARGB(backgroundColor, accentColor, 0.1f))
itemView.addView( itemView.addView(
image, image,
@ -1124,6 +1132,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
item.product.icon, item.product.metadataIcon, item.repository item.product.icon, item.product.metadataIcon, item.repository
) )
) { ) {
transformations(RoundedCornersTransformation(4.toPx))
placeholder(holder.progressIcon) placeholder(holder.progressIcon)
error(holder.defaultIcon) error(holder.defaultIcon)
} }
@ -1328,6 +1337,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
item.screenshot item.screenshot
) )
) { ) {
transformations(RoundedCornersTransformation(4.toPx))
placeholder(holder.placeholder) placeholder(holder.placeholder)
error(holder.placeholder) error(holder.placeholder)
size(cellSize) size(cellSize)

View File

@ -8,10 +8,11 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.AnimationUtils import android.view.animation.AnimationUtils
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import coil.transform.RoundedCornersTransformation
import com.google.android.material.imageview.ShapeableImageView
import com.looker.droidify.R import com.looker.droidify.R
import com.looker.droidify.database.Database import com.looker.droidify.database.Database
import com.looker.droidify.entity.ProductItem import com.looker.droidify.entity.ProductItem
@ -32,7 +33,7 @@ class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
val name = itemView.findViewById<TextView>(R.id.name)!! val name = itemView.findViewById<TextView>(R.id.name)!!
val status = itemView.findViewById<TextView>(R.id.status)!! val status = itemView.findViewById<TextView>(R.id.status)!!
val summary = itemView.findViewById<TextView>(R.id.summary)!! val summary = itemView.findViewById<TextView>(R.id.summary)!!
val icon = itemView.findViewById<ImageView>(R.id.icon)!! val icon = itemView.findViewById<ShapeableImageView>(R.id.icon)!!
val progressIcon: Drawable val progressIcon: Drawable
val defaultIcon: Drawable val defaultIcon: Drawable
@ -151,6 +152,7 @@ class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
productItem.icon, productItem.metadataIcon, repository productItem.icon, productItem.metadataIcon, repository
) )
) { ) {
transformations(RoundedCornersTransformation(4.toPx))
placeholder(holder.progressIcon) placeholder(holder.progressIcon)
error(holder.defaultIcon) error(holder.defaultIcon)
} }

View File

@ -2,9 +2,9 @@ package com.looker.droidify.screen
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Switch
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.switchmaterial.SwitchMaterial
import com.looker.droidify.R import com.looker.droidify.R
import com.looker.droidify.database.Database import com.looker.droidify.database.Database
import com.looker.droidify.entity.Repository import com.looker.droidify.entity.Repository
@ -20,7 +20,7 @@ class RepositoriesAdapter(
private class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val name = itemView.findViewById<TextView>(R.id.name)!! val name = itemView.findViewById<TextView>(R.id.name)!!
val enabled = itemView.findViewById<Switch>(R.id.enabled)!! val enabled = itemView.findViewById<SwitchMaterial>(R.id.enabled)!!
var listenSwitch = true var listenSwitch = true
} }

View File

@ -20,6 +20,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.imageview.ShapeableImageView
import com.looker.droidify.R import com.looker.droidify.R
import com.looker.droidify.content.Preferences import com.looker.droidify.content.Preferences
import com.looker.droidify.database.Database import com.looker.droidify.database.Database
@ -53,7 +54,7 @@ class TabsFragment : ScreenFragment() {
val sectionLayout = view.findViewById<ViewGroup>(R.id.section_layout)!! val sectionLayout = view.findViewById<ViewGroup>(R.id.section_layout)!!
val sectionChange = view.findViewById<View>(R.id.section_change)!! val sectionChange = view.findViewById<View>(R.id.section_change)!!
val sectionName = view.findViewById<TextView>(R.id.section_name)!! val sectionName = view.findViewById<TextView>(R.id.section_name)!!
val sectionIcon = view.findViewById<ImageView>(R.id.section_icon)!! val sectionIcon = view.findViewById<ShapeableImageView>(R.id.section_icon)!!
} }
private var searchMenuItem: MenuItem? = null private var searchMenuItem: MenuItem? = null

View File

@ -29,6 +29,13 @@ object TypefaceExtra {
val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!! val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!!
} }
val Number.toPx
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this.toFloat(),
Resources.getSystem().displayMetrics
)
fun Context.getDrawableCompat(resId: Int): Drawable { fun Context.getDrawableCompat(resId: Int): Drawable {
val drawable = if (!Android.sdk(24)) { val drawable = if (!Android.sdk(24)) {
val fileName = TypedValue().apply { resources.getValue(resId, this, true) }.string val fileName = TypedValue().apply { resources.getValue(resId, this, true) }.string
@ -92,10 +99,6 @@ fun ViewGroup.inflate(layoutResId: Int): View {
return LayoutInflater.from(context).inflate(layoutResId, this, false) return LayoutInflater.from(context).inflate(layoutResId, this, false)
} }
fun ImageView.load(uri: String, builder: ImageRequest.Builder.() -> Unit = {}) {
this.load(uri = uri, builder = builder)
}
fun ImageView.load(uri: Uri, builder: ImageRequest.Builder.() -> Unit = {}) { fun ImageView.load(uri: Uri, builder: ImageRequest.Builder.() -> Unit = {}) {
this.load(uri = uri, builder = builder) this.load(uri = uri, builder = builder)
} }

View File

@ -46,7 +46,7 @@
android:textSize="16sp" android:textSize="16sp"
tools:ignore="Autofill,HardcodedText" /> tools:ignore="Autofill,HardcodedText" />
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/address_mirror" android:id="@+id/address_mirror"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="match_parent" android:layout_height="match_parent"

View File

@ -16,13 +16,14 @@
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_marginHorizontal="10dp"
android:background="@drawable/background_border" /> android:background="@drawable/background_border" />
<FrameLayout <FrameLayout
android:id="@+id/toolbar_extra" android:id="@+id/toolbar_extra"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginHorizontal="10dp" /> android:layout_marginHorizontal="10dp" />
</LinearLayout> </LinearLayout>
@ -33,7 +34,7 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:background="?android:attr/colorBackground" android:background="?android:attr/colorBackground"
android:paddingHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:paddingTop="10dp" /> android:layout_marginTop="10dp" />
</com.looker.droidify.widget.FragmentLinearLayout> </com.looker.droidify.widget.FragmentLinearLayout>

View File

@ -8,7 +8,7 @@
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingEnd="16dp"> android:paddingEnd="16dp">
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"

View File

@ -8,7 +8,7 @@
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingEnd="16dp"> android:paddingEnd="16dp">
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"

View File

@ -16,7 +16,7 @@
android:orientation="horizontal" android:orientation="horizontal"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"

View File

@ -9,7 +9,7 @@
android:paddingStart="14dp" android:paddingStart="14dp"
android:paddingEnd="16dp"> android:paddingEnd="16dp">
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="44dp" android:layout_width="44dp"
android:layout_height="44dp" android:layout_height="44dp"

View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="54dp" android:layout_height="54dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
@ -16,10 +17,11 @@
android:textColor="?android:attr/textColor" android:textColor="?android:attr/textColor"
android:textSize="16sp" /> android:textSize="16sp" />
<Switch <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enabled" android:id="@+id/enabled"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
app:thumbTint="?android:attr/colorPrimary"
android:paddingStart="12dp" android:paddingStart="12dp"
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />

View File

@ -17,7 +17,7 @@
android:textColor="?android:attr/textColor" android:textColor="?android:attr/textColor"
android:textSize="14sp" /> android:textSize="14sp" />
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"

View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
@ -16,10 +17,11 @@
android:textColor="?android:attr/textColor" android:textColor="?android:attr/textColor"
android:textSize="16sp" /> android:textSize="16sp" />
<Switch <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enabled" android:id="@+id/enabled"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
app:thumbTint="?android:attr/colorPrimary"
android:clickable="false" android:clickable="false"
android:paddingStart="12dp" android:paddingStart="12dp"
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />

View File

@ -40,7 +40,7 @@
android:textColor="?android:attr/textColor" android:textColor="?android:attr/textColor"
android:textSize="16sp" /> android:textSize="16sp" />
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/section_icon" android:id="@+id/section_icon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"