Move Colored Action to UserEntryPresentationHelper.kt

Treatment is now replaced by Bolus + Carbs (blue and orange)
This commit is contained in:
Philoul 2021-03-29 09:49:08 +02:00
parent 74b911d875
commit 6956a17bf6
2 changed files with 9 additions and 3 deletions

View file

@ -128,7 +128,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
override fun onBindViewHolder(holder: UserEntryViewHolder, position: Int) { override fun onBindViewHolder(holder: UserEntryViewHolder, position: Int) {
val current = entries[position] val current = entries[position]
holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp) holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp)
holder.binding.action.text = userEntryPresentationHelper.actionToColoredString(current.action)
if (current.s != "") { if (current.s != "") {
holder.binding.s.text = current.s holder.binding.s.text = current.s
holder.binding.s.visibility = View.VISIBLE holder.binding.s.visibility = View.VISIBLE
@ -170,8 +170,6 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
holder.binding.iconSource.visibility = View.VISIBLE holder.binding.iconSource.visibility = View.VISIBLE
holder.binding.values.text = valuesWithUnitString.trim() holder.binding.values.text = valuesWithUnitString.trim()
holder.binding.values.visibility = if (holder.binding.values.text != "") View.VISIBLE else View.GONE holder.binding.values.visibility = if (holder.binding.values.text != "") View.VISIBLE else View.GONE
holder.binding.action.text = translator.translate(current.action)
holder.binding.action.setTextColor(resourceHelper.gc(userEntryPresentationHelper.colorId(current.action.colorGroup)))
} }
inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.utils package info.nightscout.androidaps.utils
import android.text.Spanned
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
@ -64,6 +65,13 @@ class UserEntryPresentationHelper @Inject constructor(
Sources.Unknown -> R.drawable.ic_generic_icon Sources.Unknown -> R.drawable.ic_generic_icon
} }
fun actionToColoredString(action: Action): Spanned = when (action) {
Action.TREATMENT -> HtmlHelper.fromHtml(coloredAction(Action.BOLUS) + " + " + coloredAction(Action.CARBS))
else -> HtmlHelper.fromHtml(coloredAction(action))
}
private fun coloredAction(action: Action): String = "<font color='${resourceHelper.gc(colorId(action.colorGroup))}'>${translator.translate(action)}</font>"
fun listToPresentationString(list: List<XXXValueWithUnit>) = fun listToPresentationString(list: List<XXXValueWithUnit>) =
list.joinToString(separator = " ", transform = this::toPresentationString) list.joinToString(separator = " ", transform = this::toPresentationString)