diff --git a/app/src/main/java/io/nekohasekai/sfa/ktx/Colors.kt b/app/src/main/java/io/nekohasekai/sfa/ktx/Colors.kt index 9c5b1f2..17631bb 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ktx/Colors.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ktx/Colors.kt @@ -2,9 +2,12 @@ package io.nekohasekai.sfa.ktx import android.content.Context import android.graphics.Color +import android.os.Build import android.util.TypedValue import androidx.annotation.AttrRes import androidx.annotation.ColorInt +import androidx.core.content.ContextCompat +import com.google.android.material.color.MaterialColors @ColorInt @@ -18,14 +21,27 @@ fun Context.getAttrColor( } @ColorInt -fun colorForURLTestDelay(urlTestDelay: Int): Int { - return if (urlTestDelay <= 0) { - Color.GRAY - } else if (urlTestDelay <= 800) { - Color.GREEN - } else if (urlTestDelay <= 1500) { - Color.YELLOW - } else { - Color.RED +fun colorForURLTestDelay(context: Context, urlTestDelay: Int): Int { + if (urlTestDelay <= 0) { + return Color.GRAY } + 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)) } \ No newline at end of file diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/GroupsFragment.kt b/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/GroupsFragment.kt index 6c0096a..0958ab2 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/GroupsFragment.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/GroupsFragment.kt @@ -212,7 +212,12 @@ class GroupsFragment : Fragment(), CommandClientHandler { items.forEach { builder.append("■") builder.setSpan( - ForegroundColorSpan(colorForURLTestDelay(it.urlTestDelay)), + ForegroundColorSpan( + colorForURLTestDelay( + binding.root.context, + it.urlTestDelay + ) + ), builder.length - 1, builder.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE @@ -288,7 +293,12 @@ class GroupsFragment : Fragment(), CommandClientHandler { binding.itemStatus.isVisible = item.urlTestTime > 0 if (item.urlTestTime > 0) { binding.itemStatus.text = "${item.urlTestDelay}ms" - binding.itemStatus.setTextColor(colorForURLTestDelay(item.urlTestDelay)) + binding.itemStatus.setTextColor( + colorForURLTestDelay( + binding.root.context, + item.urlTestDelay + ) + ) } } }