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)!!
}