25 lines
887 B
Kotlin
25 lines
887 B
Kotlin
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.ext
|
|
|
|
import android.content.Context
|
|
import androidx.annotation.ColorInt
|
|
import androidx.core.content.ContextCompat
|
|
import org.mozilla.fenix.R
|
|
import org.mozilla.fenix.home.sessioncontrol.TabCollection
|
|
import kotlin.math.abs
|
|
|
|
/**
|
|
* Selects one of the predefined collection icon colors based on the id.
|
|
*/
|
|
@ColorInt
|
|
fun TabCollection.getIconColor(context: Context): Int {
|
|
val iconColors = context.resources.obtainTypedArray(R.array.collection_icon_colors)
|
|
val index = abs(id % iconColors.length()).toInt()
|
|
val color = iconColors.getColor(index, ContextCompat.getColor(context, R.color.white_color))
|
|
iconColors.recycle()
|
|
return color
|
|
}
|