Skip to content

Commit

Permalink
feat(accessibility): add colored warning icon next to full rooms in e…
Browse files Browse the repository at this point in the history
…vent lists.

closes #32
  • Loading branch information
cbeyls committed Jan 5, 2024
1 parent 1b8db79 commit 711d9fb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
31 changes: 24 additions & 7 deletions app/src/main/java/be/digitalia/fosdem/adapters/BookmarksAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package be.digitalia.fosdem.adapters
import android.content.Context
import android.content.Intent
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
Expand All @@ -11,10 +12,12 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.appcompat.content.res.AppCompatResources
import androidx.collection.SimpleArrayMap
import androidx.core.content.ContextCompat
import androidx.core.text.set
import androidx.core.view.isGone
import androidx.core.widget.TextViewCompat
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -142,22 +145,36 @@ class BookmarksAdapter(context: Context, private val multiChoiceHelper: MultiCho
val startTimeString = event.startTime?.toLocalDateTimeOrNull(zoneId)?.format(timeFormatter) ?: "?"
val endTimeString = event.endTime?.toLocalDateTimeOrNull(zoneId)?.format(timeFormatter) ?: "?"
val roomName = event.roomName.orEmpty()
val detailsText: CharSequence = "${event.day.shortName}, $startTimeString$endTimeString | $roomName"
val detailsSpannable = SpannableString(detailsText)
var detailsText: CharSequence = "${event.day.shortName}, $startTimeString$endTimeString | $roomName"
var detailsDescription = detailsText

// Highlight the date and time with error color in case of conflicting schedules
if (isOverlapping(event, previous, next)) {
val endPosition = detailsText.indexOf(" | ")
detailsSpannable[0, endPosition] = ForegroundColorSpan(errorColor)
detailsSpannable[0, endPosition] = StyleSpan(Typeface.BOLD)
detailsText = SpannableString(detailsText)
detailsText[0, endPosition] = ForegroundColorSpan(errorColor)
detailsText[0, endPosition] = StyleSpan(Typeface.BOLD)
detailsDescription = context.getString(R.string.bookmark_conflict_content_description, detailsDescription)
}

val roomStatusDrawable: Drawable?
if (roomStatus != null) {
val color = ContextCompat.getColor(context, roomStatus.colorResId)
detailsSpannable[detailsText.length - roomName.length, detailsText.length] = ForegroundColorSpan(color)
val color = ContextCompat.getColorStateList(context, roomStatus.colorResId)!!
if (detailsText !is SpannableString) {
detailsText = SpannableString(detailsText)
}
detailsText[detailsText.length - roomName.length, detailsText.length] =
ForegroundColorSpan(color.defaultColor)
detailsDescription = "$detailsDescription (${context.getString(roomStatus.nameResId)})"
TextViewCompat.setCompoundDrawableTintList(details, color)
roomStatusDrawable = roomStatus.iconResId.let {
if (it != 0) AppCompatResources.getDrawable(context, it) else null
}
} else {
roomStatusDrawable = null
}
details.text = detailsSpannable
details.text = detailsText
details.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, roomStatusDrawable, null)
details.contentDescription = context.getString(R.string.details_content_description, detailsDescription)
}

Expand Down
21 changes: 16 additions & 5 deletions app/src/main/java/be/digitalia/fosdem/adapters/EventsAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package be.digitalia.fosdem.adapters

import android.content.Context
import android.content.Intent
import android.graphics.drawable.Drawable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
Expand All @@ -12,6 +13,7 @@ import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.text.set
import androidx.core.view.isGone
import androidx.core.widget.TextViewCompat
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -25,7 +27,7 @@ import be.digitalia.fosdem.utils.toLocalDateTimeOrNull
import java.time.ZoneId
import java.time.format.DateTimeFormatter

class EventsAdapter constructor(context: Context, private val showDay: Boolean = true) :
class EventsAdapter(context: Context, private val showDay: Boolean = true) :
PagingDataAdapter<StatusEvent, EventsAdapter.ViewHolder>(DIFF_CALLBACK) {

private val timeFormatter = DateUtils.getTimeFormatter(context)
Expand Down Expand Up @@ -129,14 +131,23 @@ class EventsAdapter constructor(context: Context, private val showDay: Boolean =
"$startTimeString$endTimeString | $roomName"
}
var detailsDescription = detailsText

val roomStatusDrawable: Drawable?
if (roomStatus != null) {
val color = ContextCompat.getColor(context, roomStatus.colorResId)
detailsText = SpannableString(detailsText).apply {
this[detailsText.length - roomName.length, detailsText.length] = ForegroundColorSpan(color)
}
val color = ContextCompat.getColorStateList(context, roomStatus.colorResId)!!
detailsText = SpannableString(detailsText)
detailsText[detailsText.length - roomName.length, detailsText.length] =
ForegroundColorSpan(color.defaultColor)
detailsDescription = "$detailsDescription (${context.getString(roomStatus.nameResId)})"
TextViewCompat.setCompoundDrawableTintList(details, color)
roomStatusDrawable = roomStatus.iconResId.let {
if (it != 0) AppCompatResources.getDrawable(context, it) else null
}
} else {
roomStatusDrawable = null
}
details.text = detailsText
details.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, roomStatusDrawable, null)
details.contentDescription = context.getString(R.string.details_content_description, detailsDescription)
}

Expand Down
18 changes: 13 additions & 5 deletions app/src/main/java/be/digitalia/fosdem/model/RoomStatus.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package be.digitalia.fosdem.model

import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import be.digitalia.fosdem.R

enum class RoomStatus(@StringRes @get:StringRes val nameResId: Int,
@ColorRes @get:ColorRes val colorResId: Int) {
OPEN(R.string.room_status_open, R.color.room_status_open),
FULL(R.string.room_status_full, R.color.room_status_full),
EMERGENCY_EVACUATION(R.string.room_status_emergency_evacuation, R.color.room_status_emergency_evacuation)
enum class RoomStatus(
@StringRes @get:StringRes val nameResId: Int,
@ColorRes @get:ColorRes val colorResId: Int,
@DrawableRes @get:DrawableRes val iconResId: Int
) {
OPEN(R.string.room_status_open, R.color.room_status_open, 0),
FULL(R.string.room_status_full, R.color.room_status_full, R.drawable.ic_warning_white_18sp),
EMERGENCY_EVACUATION(
R.string.room_status_emergency_evacuation,
R.color.room_status_emergency_evacuation,
R.drawable.ic_warning_white_18sp
)
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_warning_white_18sp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18sp"
android:height="18sp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:drawablePadding="8dp"
android:gravity="start"
android:textAlignment="viewStart"
android:textAppearance="?textAppearanceBody2"
Expand Down

0 comments on commit 711d9fb

Please sign in to comment.