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.ViewGroup
import android.widget.*
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.ColorUtils
import androidx.core.text.HtmlCompat
import androidx.core.text.util.LinkifyCompat
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
@ -455,7 +452,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
private class ScreenshotViewHolder(context: Context) :
RecyclerView.ViewHolder(FrameLayout(context)) {
val image: AppCompatImageView
val image: ShapeableImageView
val placeholder: Drawable
@ -466,20 +463,25 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
itemView as FrameLayout
itemView.foreground =
itemView.context.getDrawableFromAttr(android.R.attr.selectableItemBackground)
val backgroundColor =
itemView.context.getColorFromAttr(android.R.attr.colorBackground).defaultColor
val accentColor =
itemView.context.getColorFromAttr(android.R.attr.colorAccent).defaultColor
val primaryColor =
itemView.context.getColorFromAttr(android.R.attr.textColor).defaultColor
val surfaceColor =
itemView.context.getColorFromAttr(R.attr.colorSurface).defaultColor
image = object : AppCompatImageView(context) {
image = object : ShapeableImageView(context) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
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(
image,
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()
placeholder.setTint(ColorUtils.blendARGB(primaryColor, accentColor, 0.5f)
.let { ColorUtils.blendARGB(0x00ffffff and it, it, 0.2f) })
placeholder.setTint(surfaceColor)
this.placeholder = PaddingDrawable(placeholder, 2f)
}
}
@ -529,6 +530,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
itemView.context.theme
)
backgroundTintList = itemView.context.getColorFromAttr(R.attr.colorSurface)
typeface = TypefaceExtra.bold
setPadding(15, 5, 15, 5)
setTextColor(itemView.context.getColorFromAttr(R.attr.colorPrimary))
}
@ -1166,7 +1168,8 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
}
if (updateAll || updateStatus) {
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) {
when (status) {
is Status.Pending -> {
@ -1341,7 +1344,6 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
item.screenshot
)
) {
transformations(RoundedCornersTransformation(4.toPx))
placeholder(holder.placeholder)
error(holder.placeholder)
size(cellSize)

View File

@ -8,7 +8,6 @@ import android.os.Bundle
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.ImageView
import androidx.core.graphics.ColorUtils
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
@ -69,15 +68,8 @@ class ScreenshotsFragment() : DialogFragment() {
WindowCompat.setDecorFitsSystemWindows(window, false)
}
val background =
dialog.context.getColorFromAttr(R.attr.colorSurface).defaultColor
decorView?.setBackgroundColor(background.let {
ColorUtils.blendARGB(
0x00ffffff and it,
it,
1f
)
})
val background = dialog.context.getColorFromAttr(R.attr.colorSurface).defaultColor
decorView?.setBackgroundColor(background)
decorView?.setPadding(0, 0, 0, 0)
if (window != null) {
window.attributes = window.attributes.apply {
@ -85,10 +77,8 @@ class ScreenshotsFragment() : DialogFragment() {
format = PixelFormat.TRANSLUCENT
windowAnimations = run {
val typedArray = dialog.context.obtainStyledAttributes(
null,
intArrayOf(android.R.attr.windowAnimationStyle),
android.R.attr.dialogTheme,
0
null, intArrayOf(android.R.attr.windowAnimationStyle),
android.R.attr.dialogTheme, 0
)
try {
typedArray.getResourceId(0, 0)
@ -198,8 +188,7 @@ class ScreenshotsFragment() : DialogFragment() {
val placeholder =
itemView.context.getDrawableCompat(R.drawable.ic_photo_camera).mutate()
placeholder.setTint(itemView.context.getColorFromAttr(R.attr.colorSurface).defaultColor
.let { ColorUtils.blendARGB(0x00ffffff and it, it, 0.25f) })
placeholder.setTint(itemView.context.getColorFromAttr(R.attr.colorSurface).defaultColor)
this.placeholder = PaddingDrawable(placeholder, 4f)
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,11 +3,10 @@
<color name="green50">#E8F5E9</color>
<color name="green100">#A3EBB7</color>
<color name="green200">#6EC898</color>
<color name="green300">#58C189</color>
<color name="green400">#3EDA86</color>
<color name="green300">#51DF93</color>
<color name="red200">#EF9A9A</color>
<color name="red300">#E57373</color>
<color name="red300">#EF8A8A</color>
<color name="pitch_black">#000000</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 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="colorSurface">@color/green50</item>
<item name="colorOnSurface">@color/black</item>
@ -79,9 +79,27 @@
<item name="colorOnSurfaceVariant">?attr/colorOnSurface</item>
</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">
<item name="trackTint">@color/switch_track_color</item>
<item name="thumbTint">@color/switch_thumb_tint</item>
</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>