Fix urltest color
This commit is contained in:
@@ -2,9 +2,12 @@ package io.nekohasekai.sfa.ktx
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.os.Build
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.google.android.material.color.MaterialColors
|
||||||
|
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
@@ -18,14 +21,27 @@ fun Context.getAttrColor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
fun colorForURLTestDelay(urlTestDelay: Int): Int {
|
fun colorForURLTestDelay(context: Context, urlTestDelay: Int): Int {
|
||||||
return if (urlTestDelay <= 0) {
|
if (urlTestDelay <= 0) {
|
||||||
Color.GRAY
|
return Color.GRAY
|
||||||
} else if (urlTestDelay <= 800) {
|
|
||||||
Color.GREEN
|
|
||||||
} else if (urlTestDelay <= 1500) {
|
|
||||||
Color.YELLOW
|
|
||||||
} else {
|
|
||||||
Color.RED
|
|
||||||
}
|
}
|
||||||
|
val colorRes =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && context.resources.configuration.isNightModeActive) {
|
||||||
|
if (urlTestDelay <= 800) {
|
||||||
|
android.R.color.holo_green_dark
|
||||||
|
} else if (urlTestDelay <= 1500) {
|
||||||
|
android.R.color.holo_orange_dark
|
||||||
|
} else {
|
||||||
|
android.R.color.holo_red_dark
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (urlTestDelay <= 800) {
|
||||||
|
android.R.color.holo_green_light
|
||||||
|
} else if (urlTestDelay <= 1500) {
|
||||||
|
android.R.color.holo_orange_light
|
||||||
|
} else {
|
||||||
|
android.R.color.holo_red_light
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MaterialColors.harmonizeWithPrimary(context, ContextCompat.getColor(context, colorRes))
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,12 @@ class GroupsFragment : Fragment(), CommandClientHandler {
|
|||||||
items.forEach {
|
items.forEach {
|
||||||
builder.append("■")
|
builder.append("■")
|
||||||
builder.setSpan(
|
builder.setSpan(
|
||||||
ForegroundColorSpan(colorForURLTestDelay(it.urlTestDelay)),
|
ForegroundColorSpan(
|
||||||
|
colorForURLTestDelay(
|
||||||
|
binding.root.context,
|
||||||
|
it.urlTestDelay
|
||||||
|
)
|
||||||
|
),
|
||||||
builder.length - 1,
|
builder.length - 1,
|
||||||
builder.length,
|
builder.length,
|
||||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||||
@@ -288,7 +293,12 @@ class GroupsFragment : Fragment(), CommandClientHandler {
|
|||||||
binding.itemStatus.isVisible = item.urlTestTime > 0
|
binding.itemStatus.isVisible = item.urlTestTime > 0
|
||||||
if (item.urlTestTime > 0) {
|
if (item.urlTestTime > 0) {
|
||||||
binding.itemStatus.text = "${item.urlTestDelay}ms"
|
binding.itemStatus.text = "${item.urlTestDelay}ms"
|
||||||
binding.itemStatus.setTextColor(colorForURLTestDelay(item.urlTestDelay))
|
binding.itemStatus.setTextColor(
|
||||||
|
colorForURLTestDelay(
|
||||||
|
binding.root.context,
|
||||||
|
item.urlTestDelay
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user