Skip to content

Commit

Permalink
Merge pull request #446 from FossifyOrg/fix_theme_issues
Browse files Browse the repository at this point in the history
Fix text color in attendee suggestions
  • Loading branch information
naveensingh authored Jan 25, 2025
2 parents 035e116 + c8a1b82 commit eacae27
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@ import org.fossify.calendar.activities.SimpleActivity
import org.fossify.calendar.databinding.ItemAutocompleteTitleSubtitleBinding
import org.fossify.calendar.models.Attendee
import org.fossify.commons.extensions.beVisibleIf
import org.fossify.commons.extensions.getProperTextColor
import org.fossify.commons.extensions.isDynamicTheme
import org.fossify.commons.extensions.normalizeString
import org.fossify.commons.helpers.SimpleContactsHelper

class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val attendees: ArrayList<Attendee>) : ArrayAdapter<Attendee>(activity, 0, attendees) {
class AutoCompleteTextViewAdapter(
val activity: SimpleActivity,
val attendees: ArrayList<Attendee>,
) : ArrayAdapter<Attendee>(activity, 0, attendees) {
var resultList = ArrayList<Attendee>()

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val attendee = resultList[position]
val attendeeHasName = attendee.name.isNotEmpty()
var listItem = convertView
if (listItem == null || listItem.tag != attendeeHasName) {
listItem = ItemAutocompleteTitleSubtitleBinding.inflate(activity.layoutInflater, parent, false).root
listItem = ItemAutocompleteTitleSubtitleBinding.inflate(
activity.layoutInflater, parent, false
).apply {
// TODO: Dark text color is set for dynamic theme only because light themes are
// configured with dark overflow menu background for some reason ¯\_(ツ)_/¯
if (activity.isDynamicTheme()) {
val textColor = activity.getProperTextColor()
itemAutocompleteTitle.setTextColor(textColor)
itemAutocompleteSubtitle.setTextColor(textColor)
}
}.root
}

val nameToUse = when {
Expand All @@ -29,7 +44,6 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val attendees: A
else -> "A"
}

val placeholder = BitmapDrawable(activity.resources, SimpleContactsHelper(context).getContactLetterIcon(nameToUse))
listItem.tag = attendeeHasName
ItemAutocompleteTitleSubtitleBinding.bind(listItem).apply {
itemAutocompleteTitle.text = if (attendeeHasName) {
Expand All @@ -40,6 +54,11 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val attendees: A

itemAutocompleteSubtitle.text = attendee.email
itemAutocompleteSubtitle.beVisibleIf(attendeeHasName)

val placeholder = BitmapDrawable(
activity.resources,
SimpleContactsHelper(context).getContactLetterIcon(nameToUse)
)
attendee.updateImage(context, itemAutocompleteImage, placeholder)
}

Expand All @@ -53,7 +72,10 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val attendees: A
val results = mutableListOf<Attendee>()
val searchString = constraint.toString().normalizeString()
attendees.forEach {
if (it.email.contains(searchString, true) || it.name.contains(searchString, true)) {
if (
it.email.contains(searchString, true) ||
it.name.contains(searchString, true)
) {
results.add(it)
}
}
Expand Down Expand Up @@ -83,7 +105,9 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val attendees: A
}
}

override fun convertResultToString(resultValue: Any?) = (resultValue as? Attendee)?.getPublicName()
override fun convertResultToString(resultValue: Any?): String? {
return (resultValue as? Attendee)?.getPublicName()
}
}

override fun getItem(index: Int) = resultList[index]
Expand Down

0 comments on commit eacae27

Please sign in to comment.