mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
Fix background colors for unit types
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
package com.simplemobiletools.calculator.adapters
|
||||
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.graphics.drawable.RippleDrawable
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.simplemobiletools.calculator.R
|
||||
import com.simplemobiletools.calculator.activities.SimpleActivity
|
||||
import com.simplemobiletools.calculator.databinding.ItemUnitTypeBinding
|
||||
import com.simplemobiletools.calculator.extensions.getStrokeColor
|
||||
import com.simplemobiletools.calculator.helpers.converters.Converter
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.getProperPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
||||
class UnitTypesAdapter (val activity: SimpleActivity, val items: List<Converter>, val itemClick: (id: Int) -> Unit) : RecyclerView.Adapter<UnitTypesAdapter.ViewHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
|
||||
@ -28,6 +31,12 @@ class UnitTypesAdapter (val activity: SimpleActivity, val items: List<Converter>
|
||||
binding.unitImage.setImageResource(item.imageResId)
|
||||
binding.unitLabel.setText(item.nameResId)
|
||||
|
||||
val rippleBg = ResourcesCompat.getDrawable(resources, R.drawable.unit_type_background, context.theme) as RippleDrawable
|
||||
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.background_holder) as LayerDrawable
|
||||
layerDrawable.findDrawableByLayerId(R.id.background_stroke).applyColorFilter(context.getStrokeColor())
|
||||
layerDrawable.findDrawableByLayerId(R.id.background_shape).applyColorFilter(context.getProperBackgroundColor().darkenColor(2))
|
||||
binding.unitBackground.background = rippleBg
|
||||
|
||||
binding.unitLabel.setTextColor(activity.getProperTextColor())
|
||||
binding.unitImage.applyColorFilter(activity.getProperPrimaryColor())
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
@ -15,6 +16,9 @@ import com.simplemobiletools.calculator.databases.CalculatorDatabase
|
||||
import com.simplemobiletools.calculator.helpers.Config
|
||||
import com.simplemobiletools.calculator.helpers.MyWidgetProvider
|
||||
import com.simplemobiletools.calculator.interfaces.CalculatorDao
|
||||
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.isUsingSystemDarkTheme
|
||||
import com.simplemobiletools.commons.extensions.lightenColor
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||
@ -64,3 +68,20 @@ fun Context.launchChangeAppLanguageIntent() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getStrokeColor(): Int {
|
||||
return if (config.isUsingSystemTheme) {
|
||||
if (isUsingSystemDarkTheme()) {
|
||||
resources.getColor(com.simplemobiletools.commons.R.color.md_grey_800, theme)
|
||||
} else {
|
||||
resources.getColor(com.simplemobiletools.commons.R.color.md_grey_400, theme)
|
||||
}
|
||||
} else {
|
||||
val lighterColor = getProperBackgroundColor().lightenColor()
|
||||
if (lighterColor == Color.WHITE || lighterColor == Color.BLACK) {
|
||||
resources.getColor(com.simplemobiletools.commons.R.color.divider_grey, theme)
|
||||
} else {
|
||||
lighterColor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="#22ffffff">
|
||||
<item android:id="@+id/clipboard_background_holder">
|
||||
<item android:id="@+id/background_holder">
|
||||
<layer-list>
|
||||
<item android:id="@+id/clipboard_background_shape">
|
||||
<item android:id="@+id/background_shape">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="@dimen/medium_margin" />
|
||||
<solid android:color="@color/md_grey_800" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@+id/clipboard_background_stroke">
|
||||
<item android:id="@+id/background_stroke">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent" />
|
||||
<stroke
|
||||
|
@ -2,6 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/unit_type_size"
|
||||
android:layout_height="@dimen/unit_type_size"
|
||||
android:id="@+id/unit_background"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_margin="@dimen/small_margin"
|
||||
android:background="@drawable/unit_type_background"
|
||||
|
Reference in New Issue
Block a user