1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

use .orEmpty() where applicable

This commit is contained in:
Christophe Beyls 2021-12-26 16:05:00 +01:00
parent 782a1d60df
commit d35d8257ec
8 changed files with 15 additions and 14 deletions

View file

@ -21,6 +21,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.sample
@ -42,6 +43,7 @@ class SearchResultActivity : AppCompatActivity(R.layout.search_result) {
@OptIn(kotlinx.coroutines.FlowPreview::class)
searchEditText.textChangeEvents
.conflate()
.onEach {
// immediately update the button state
searchClearButton.isGone = it.isNullOrEmpty()
@ -49,7 +51,7 @@ class SearchResultActivity : AppCompatActivity(R.layout.search_result) {
.sample(SEARCH_INPUT_SAMPLE_MILLIS)
.onEach {
// only update the results every SEARCH_INPUT_SAMPLE_MILLIS
viewModel.query = it?.toString() ?: ""
viewModel.query = it?.toString().orEmpty()
}
.launchIn(lifecycleScope)
@ -74,7 +76,7 @@ class SearchResultActivity : AppCompatActivity(R.layout.search_result) {
private fun handleIntent(intent: Intent) {
val query = when (intent.action) {
Intent.ACTION_SEARCH, GMS_ACTION_SEARCH -> intent.getStringExtra(SearchManager.QUERY)
?.trimNonAlpha() ?: ""
?.trimNonAlpha().orEmpty()
else -> ""
}
viewModel.query = query

View file

@ -134,7 +134,7 @@ class BookmarksAdapter(context: Context, private val multiChoiceHelper: MultiCho
val endTime = event.endTime
val startTimeString = if (startTime != null) timeDateFormat.format(startTime) else "?"
val endTimeString = if (endTime != null) timeDateFormat.format(endTime) else "?"
val roomName = event.roomName ?: ""
val roomName = event.roomName.orEmpty()
val detailsText: CharSequence = "${event.day.shortName}, $startTimeString$endTimeString | $roomName"
val detailsSpannable = SpannableString(detailsText)
var detailsDescription = detailsText

View file

@ -99,7 +99,7 @@ class EventsAdapter constructor(context: Context, private val showDay: Boolean =
val bookmarkDrawable = if (isBookmarked) AppCompatResources.getDrawable(context, R.drawable.ic_bookmark_white_24dp) else null
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(title, null, null, bookmarkDrawable, null)
title.contentDescription = if (isBookmarked) {
context.getString(R.string.in_bookmarks_content_description, event.title ?: "")
context.getString(R.string.in_bookmarks_content_description, event.title.orEmpty())
} else null
val personsSummary = event.personsSummary
persons.text = personsSummary
@ -116,7 +116,7 @@ class EventsAdapter constructor(context: Context, private val showDay: Boolean =
val endTime = event.endTime
val startTimeString = if (startTime != null) timeDateFormat.format(startTime) else "?"
val endTimeString = if (endTime != null) timeDateFormat.format(endTime) else "?"
val roomName = event.roomName ?: ""
val roomName = event.roomName.orEmpty()
var detailsText: CharSequence = if (showDay) {
"${event.day.shortName}, $startTimeString$endTimeString | $roomName"
} else {

View file

@ -132,14 +132,13 @@ class TrackScheduleAdapter(context: Context, private val listener: EventClickLis
val bookmarkDrawable = if (isBookmarked) AppCompatResources.getDrawable(context, R.drawable.ic_bookmark_white_24dp) else null
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(title, null, null, bookmarkDrawable, null)
title.contentDescription = if (isBookmarked) {
context.getString(R.string.in_bookmarks_content_description, event.title ?: "")
context.getString(R.string.in_bookmarks_content_description, event.title.orEmpty())
} else null
val personsSummary = event.personsSummary
persons.text = personsSummary
persons.isGone = personsSummary.isNullOrEmpty()
room.text = event.roomName
room.contentDescription = context.getString(R.string.room_content_description, event.roomName
?: "")
room.contentDescription = context.getString(R.string.room_content_description, event.roomName.orEmpty())
}
fun bindTimeColors(event: Event, currentTime: Long) {

View file

@ -187,8 +187,8 @@ class EventDetailsFragment : Fragment(R.layout.fragment_event_details) {
}
private fun createShareChooserIntent(): Intent {
val title = event.title ?: ""
val url = event.url ?: ""
val title = event.title.orEmpty()
val url = event.url.orEmpty()
return ShareCompat.IntentBuilder(requireActivity())
.setSubject("$title ($CONFERENCE_NAME)")
.setType("text/plain")
@ -215,7 +215,7 @@ class EventDetailsFragment : Fragment(R.layout.fragment_event_details) {
var description = event.abstractText
if (description.isNullOrEmpty()) {
description = event.description ?: ""
description = event.description.orEmpty()
}
description = description.stripHtml()
// Add speaker info if available

View file

@ -56,5 +56,5 @@ data class Event(
return FosdemUrls.getEvent(s, DateUtils.getYear(day.date.time))
}
override fun toString(): String = title ?: ""
override fun toString(): String = title.orEmpty()
}

View file

@ -24,7 +24,7 @@ data class Person(
return FosdemUrls.getPerson(n.toSlug(), year)
}
override fun toString(): String = name ?: ""
override fun toString(): String = name.orEmpty()
companion object {
const val TABLE_NAME = "persons"

View file

@ -34,7 +34,7 @@ class SearchViewModel @Inject constructor(scheduleDao: ScheduleDao, private val
}
var query: String
get() = queryLiveData.value ?: ""
get() = queryLiveData.value.orEmpty()
set(value) {
if (value != queryLiveData.value) {
state[STATE_QUERY] = value