formatting

This commit is contained in:
Felix 2020-04-21 18:27:44 +02:00
parent 1d950ceabd
commit 27d86f6a7d
4 changed files with 19 additions and 20 deletions

View file

@ -81,7 +81,7 @@ object ChaosflixUtil {
return getUsefullTags(events, acronym).size > 2
}
fun getUsefullTags(events: List<Event>, acronym: String): List<String>{
fun getUsefullTags(events: List<Event>, acronym: String): List<String> {
val tagList = events.map { it.tags ?: emptyArray() }
.toTypedArray()
.flatten()

View file

@ -39,10 +39,10 @@ class BrowseViewModel(
val filter: LiveData<Filter> by lazy {
val mld = MediatorLiveData<Filter>()
mld.addSource(filterTags){
mld.addSource(filterTags) {
mld.postValue(Filter(text = filterText.value ?: "", tags = it))
}
mld.addSource(filterText){
mld.addSource(filterText) {
mld.postValue(Filter(text = it, tags = filterTags.value ?: emptySet()))
}
mld
@ -89,7 +89,7 @@ class BrowseViewModel(
val mediator = MediatorLiveData<List<Event>>()
mediator.addSource(filter) {
val currentEvents = events.value
if(currentEvents != null && it != null){
if (currentEvents != null && it != null) {
mediator.postValue(filterEvents(currentEvents, text = it.text, tags = it.tags))
}
}
@ -102,13 +102,13 @@ class BrowseViewModel(
private fun filterEvents(events: List<Event>?, text: String?, tags: Set<String>): List<Event>? {
return events
?.filter {
text == null
|| text.isBlank()
|| it.getFilteredProperties().any { it.contains(text,ignoreCase = true) }
text == null ||
text.isBlank() ||
it.getFilteredProperties().any { it.contains(text, ignoreCase = true) }
}
?.filter {
tags.isEmpty()
|| it.tags?.toHashSet()?.containsAll(tags) ?: false
tags.isEmpty() ||
it.tags?.toHashSet()?.containsAll(tags) ?: false
}
}
@ -208,8 +208,8 @@ class BrowseViewModel(
}
data class Filter(
val text: String,
val tags: Set<String>
val text: String,
val tags: Set<String>
)
companion object {

View file

@ -17,7 +17,6 @@ class ConferenceEventListFragment : EventsListFragment() {
private var filterTextChip: Chip? = null
private val filterTagChips: MutableMap<String, Chip> = mutableMapOf()
override fun navigateToDetails(event: Event) {
findNavController().navigate(ConferenceEventListFragmentDirections.actionEventsListFragmentToEventDetailsFragment(eventGuid = event.guid))
}
@ -45,9 +44,9 @@ class ConferenceEventListFragment : EventsListFragment() {
})
viewModel.filter.observe(viewLifecycleOwner, Observer { filter ->
Log.d(TAG, "Current filter: $filter")
if(filter != null){
if (filter != null) {
val currentFilter = viewModel.filter.value
if(!currentFilter?.text.isNullOrBlank()){
if (!currentFilter?.text.isNullOrBlank()) {
val textChip = filterTextChip ?: Chip(requireContext()).apply {
isCloseIconVisible = true
setOnCloseIconClickListener {
@ -57,7 +56,7 @@ class ConferenceEventListFragment : EventsListFragment() {
}
textChip.text = "Search: ${filter.text}"
binding.filterChipGroup.apply {
if(!contains(textChip)){
if (!contains(textChip)) {
addView(textChip)
}
}
@ -68,7 +67,7 @@ class ConferenceEventListFragment : EventsListFragment() {
}
filterTagChips.values.forEach { binding.filterChipGroup.removeView(it) }
for(tag in filter.tags){
for (tag in filter.tags) {
val chip = filterTagChips[tag] ?: Chip(requireContext()).apply {
text = "Tag: $tag"
isCloseIconVisible = true
@ -80,7 +79,7 @@ class ConferenceEventListFragment : EventsListFragment() {
binding.filterChipGroup.addView(this)
filterTagChips[tag] = this
}
if(!binding.filterChipGroup.contains(chip)){
if (!binding.filterChipGroup.contains(chip)) {
binding.filterChipGroup.addView(chip)
}
}

View file

@ -39,7 +39,7 @@ class FilterBottomSheet : BottomSheetDialogFragment() {
conference?.let { conf ->
viewModel.getUsefullTags(conf).observe(viewLifecycleOwner, Observer { tags ->
filterTagChips.forEach {
if(!tags.contains(it.key)){
if (!tags.contains(it.key)) {
binding.tagChipGroup.removeView(it.value)
filterTagChips.remove(it.key)
}
@ -49,7 +49,7 @@ class FilterBottomSheet : BottomSheetDialogFragment() {
text = tag
isCheckable = true
setOnCheckedChangeListener { _, isChecked ->
if(isChecked){
if (isChecked) {
val newTags = (viewModel.filterTags.value ?: emptySet()).plus(tag)
viewModel.filterTags.postValue(newTags)
} else {
@ -59,7 +59,7 @@ class FilterBottomSheet : BottomSheetDialogFragment() {
}
filterTagChips[tag] = this
}
if(!binding.tagChipGroup.contains(chip)){
if (!binding.tagChipGroup.contains(chip)) {
binding.tagChipGroup.addView(chip)
}
}