Improve: Theming Again (What did u expect?!)

This commit is contained in:
LooKeR 2021-10-17 20:15:08 +05:30
parent e8d1331faf
commit 95d1c6954f
11 changed files with 68 additions and 52 deletions

View File

@ -22,13 +22,10 @@ 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.content.res.ResourcesCompat
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.imageview.ShapeableImageView
import com.google.android.material.switchmaterial.SwitchMaterial import com.google.android.material.switchmaterial.SwitchMaterial
import com.looker.droidify.R import com.looker.droidify.R
@ -455,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: AppCompatImageView val image: ShapeableImageView
val placeholder: Drawable val placeholder: Drawable
@ -466,20 +463,25 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
itemView as FrameLayout itemView as FrameLayout
itemView.foreground = itemView.foreground =
itemView.context.getDrawableFromAttr(android.R.attr.selectableItemBackground) itemView.context.getDrawableFromAttr(android.R.attr.selectableItemBackground)
val backgroundColor = val surfaceColor =
itemView.context.getColorFromAttr(android.R.attr.colorBackground).defaultColor itemView.context.getColorFromAttr(R.attr.colorSurface).defaultColor
val accentColor =
itemView.context.getColorFromAttr(android.R.attr.colorAccent).defaultColor
val primaryColor =
itemView.context.getColorFromAttr(android.R.attr.textColor).defaultColor
image = object : AppCompatImageView(context) {
image = object : ShapeableImageView(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.setBackgroundColor(ColorUtils.blendARGB(backgroundColor, accentColor, 0.1f))
val radius = image.context.resources.getDimension(R.dimen.shape_medium_corner)
val shapeAppearanceModel = image.shapeAppearanceModel.toBuilder()
.setAllCornerSizes(radius)
.build()
image.shapeAppearanceModel = shapeAppearanceModel
image.setBackgroundColor(surfaceColor)
itemView.addView( itemView.addView(
image, image,
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
@ -491,8 +493,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
) )
val placeholder = image.context.getDrawableCompat(R.drawable.ic_photo_camera).mutate() val placeholder = image.context.getDrawableCompat(R.drawable.ic_photo_camera).mutate()
placeholder.setTint(ColorUtils.blendARGB(primaryColor, accentColor, 0.5f) placeholder.setTint(surfaceColor)
.let { ColorUtils.blendARGB(0x00ffffff and it, it, 0.2f) })
this.placeholder = PaddingDrawable(placeholder, 2f) this.placeholder = PaddingDrawable(placeholder, 2f)
} }
} }
@ -529,6 +530,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
itemView.context.theme itemView.context.theme
) )
backgroundTintList = itemView.context.getColorFromAttr(R.attr.colorSurface) backgroundTintList = itemView.context.getColorFromAttr(R.attr.colorSurface)
typeface = TypefaceExtra.bold
setPadding(15, 5, 15, 5) setPadding(15, 5, 15, 5)
setTextColor(itemView.context.getColorFromAttr(R.attr.colorPrimary)) setTextColor(itemView.context.getColorFromAttr(R.attr.colorPrimary))
} }
@ -1166,7 +1168,8 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
} }
if (updateAll || updateStatus) { if (updateAll || updateStatus) {
val status = status val status = status
holder.statusLayout.visibility = if (status != null) View.VISIBLE else View.GONE holder.statusLayout.visibility =
if (status != null) View.VISIBLE else View.INVISIBLE
if (status != null) { if (status != null) {
when (status) { when (status) {
is Status.Pending -> { is Status.Pending -> {
@ -1341,7 +1344,6 @@ 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,7 +8,6 @@ import android.os.Bundle
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowManager import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import androidx.core.graphics.ColorUtils
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
@ -69,15 +68,8 @@ class ScreenshotsFragment() : DialogFragment() {
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
} }
val background = val background = dialog.context.getColorFromAttr(R.attr.colorSurface).defaultColor
dialog.context.getColorFromAttr(R.attr.colorSurface).defaultColor decorView?.setBackgroundColor(background)
decorView?.setBackgroundColor(background.let {
ColorUtils.blendARGB(
0x00ffffff and it,
it,
1f
)
})
decorView?.setPadding(0, 0, 0, 0) decorView?.setPadding(0, 0, 0, 0)
if (window != null) { if (window != null) {
window.attributes = window.attributes.apply { window.attributes = window.attributes.apply {
@ -85,10 +77,8 @@ class ScreenshotsFragment() : DialogFragment() {
format = PixelFormat.TRANSLUCENT format = PixelFormat.TRANSLUCENT
windowAnimations = run { windowAnimations = run {
val typedArray = dialog.context.obtainStyledAttributes( val typedArray = dialog.context.obtainStyledAttributes(
null, null, intArrayOf(android.R.attr.windowAnimationStyle),
intArrayOf(android.R.attr.windowAnimationStyle), android.R.attr.dialogTheme, 0
android.R.attr.dialogTheme,
0
) )
try { try {
typedArray.getResourceId(0, 0) typedArray.getResourceId(0, 0)
@ -198,8 +188,7 @@ class ScreenshotsFragment() : DialogFragment() {
val placeholder = val placeholder =
itemView.context.getDrawableCompat(R.drawable.ic_photo_camera).mutate() itemView.context.getDrawableCompat(R.drawable.ic_photo_camera).mutate()
placeholder.setTint(itemView.context.getColorFromAttr(R.attr.colorSurface).defaultColor placeholder.setTint(itemView.context.getColorFromAttr(R.attr.colorSurface).defaultColor)
.let { ColorUtils.blendARGB(0x00ffffff and it, it, 0.25f) })
this.placeholder = PaddingDrawable(placeholder, 4f) this.placeholder = PaddingDrawable(placeholder, 4f)
} }
} }

View File

@ -25,6 +25,7 @@ import org.xmlpull.v1.XmlPullParser
import kotlin.math.roundToInt import kotlin.math.roundToInt
object TypefaceExtra { object TypefaceExtra {
val bold = Typeface.create("sans-serif-medium", Typeface.BOLD)!!
val medium = Typeface.create("sans-serif-medium", Typeface.NORMAL)!! val medium = Typeface.create("sans-serif-medium", Typeface.NORMAL)!!
val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!! val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!!
} }

View File

@ -4,7 +4,7 @@
<translate <translate
android:duration="400" android:duration="400"
android:fromXDelta="0%" android:fromXDelta="0%"
android:fromYDelta="-100%" android:fromYDelta="-50%"
android:toXDelta="0%" android:toXDelta="0%"
android:toYDelta="0%" /> android:toYDelta="0%" />
</set> </set>

View File

@ -4,7 +4,7 @@
<translate <translate
android:duration="400" android:duration="400"
android:fromXDelta="0%" android:fromXDelta="0%"
android:fromYDelta="100%" android:fromYDelta="50%"
android:toXDelta="0%" android:toXDelta="0%"
android:toYDelta="0%" /> android:toYDelta="0%" />
</set> </set>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp" /> <corners android:radius="@dimen/shape_medium_corner" />
</shape> </shape>

View File

@ -21,14 +21,13 @@
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"
android:layout_marginStart="1.667dp" app:shapeAppearanceOverlay="@style/Shape.Medium"
android:layout_marginEnd="1.667dp"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp" android:layout_marginStart="@dimen/text_margin"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
@ -82,19 +81,17 @@
<com.google.android.material.progressindicator.LinearProgressIndicator <com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress" android:id="@+id/progress"
style="@style/Theme.Progress"
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:layout_marginBottom="2dp"
app:trackCornerRadius="2dp" />
</LinearLayout> </LinearLayout>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/action" android:id="@+id/action"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="56dp"
android:layout_gravity="bottom" app:shapeAppearanceOverlay="@style/Shape.Medium" />
app:cornerRadius="8dp" />
</LinearLayout> </LinearLayout>

View File

@ -5,10 +5,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="72dp" android:layout_height="72dp"
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
app:cardBackgroundColor="@null" android:orientation="horizontal"
app:cardCornerRadius="12dp" app:cardBackgroundColor="?android:attr/colorBackground"
app:cardElevation="0dp" app:cardElevation="0dp"
app:strokeColor="@null" app:strokeColor="@null"
app:cardCornerRadius="@dimen/shape_medium_corner"
app:strokeWidth="0dp"> app:strokeWidth="0dp">
<LinearLayout <LinearLayout
@ -19,8 +20,9 @@
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="44dp" android:layout_width="56dp"
android:layout_height="44dp" android:layout_height="56dp"
app:shapeAppearanceOverlay="@style/Shape.Small"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<LinearLayout <LinearLayout

View File

@ -3,11 +3,10 @@
<color name="green50">#E8F5E9</color> <color name="green50">#E8F5E9</color>
<color name="green100">#A3EBB7</color> <color name="green100">#A3EBB7</color>
<color name="green200">#6EC898</color> <color name="green200">#6EC898</color>
<color name="green300">#58C189</color> <color name="green300">#51DF93</color>
<color name="green400">#3EDA86</color>
<color name="red200">#EF9A9A</color> <color name="red200">#EF9A9A</color>
<color name="red300">#E57373</color> <color name="red300">#EF8A8A</color>
<color name="pitch_black">#000000</color> <color name="pitch_black">#000000</color>
<color name="black">#1E1E1E</color> <color name="black">#1E1E1E</color>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_margin">16dp</dimen>
<dimen name="shape_margin">8dp</dimen>
<dimen name="shape_small_corner">4dp</dimen>
<dimen name="shape_medium_corner">12dp</dimen>
<dimen name="shape_large_corner">16dp</dimen>
</resources>

View File

@ -6,7 +6,7 @@
</style> </style>
<style name="Theme.Main.Light" parent="Theme.Material3.Light.NoActionBar"> <style name="Theme.Main.Light" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/green400</item> <item name="colorPrimary">@color/green300</item>
<item name="colorOnPrimary">@color/black</item> <item name="colorOnPrimary">@color/black</item>
<item name="colorSurface">@color/green50</item> <item name="colorSurface">@color/green50</item>
<item name="colorOnSurface">@color/black</item> <item name="colorOnSurface">@color/black</item>
@ -79,9 +79,27 @@
<item name="colorOnSurfaceVariant">?attr/colorOnSurface</item> <item name="colorOnSurfaceVariant">?attr/colorOnSurface</item>
</style> </style>
<style name="Theme.Progress" parent="Widget.Material3.LinearProgressIndicator">
<item name="trackColor">?attr/colorSurface</item>
<item name="trackThickness">8dp</item>
<item name="trackCornerRadius">4dp</item>
</style>
<style name="Theme.Switch" parent="Widget.Material3.CompoundButton.Switch"> <style name="Theme.Switch" parent="Widget.Material3.CompoundButton.Switch">
<item name="trackTint">@color/switch_track_color</item> <item name="trackTint">@color/switch_track_color</item>
<item name="thumbTint">@color/switch_thumb_tint</item> <item name="thumbTint">@color/switch_thumb_tint</item>
</style> </style>
<style name="Shape.Small" parent="ShapeAppearance.Material3.SmallComponent">
<item name="cornerSize">@dimen/shape_small_corner</item>
</style>
<style name="Shape.Medium" parent="ShapeAppearance.Material3.MediumComponent">
<item name="cornerSize">@dimen/shape_medium_corner</item>
</style>
<style name="Shape.Large" parent="ShapeAppearance.Material3.LargeComponent">
<item name="cornerSize">@dimen/shape_large_corner</item>
</style>
</resources> </resources>