Skip to content

fix query,use jacksonObjectMapper and view holder crash #1638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class EventService(
return eventDao.getFavoriteEvents()
}

fun getEventsByLocation(locationName: String): Single<List<Event>> {
fun getEventsByLocation(locationName: String?): Single<List<Event>> {
val query = "[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$locationName%\"}]"
return eventApi.searchEvents("name", query).flatMap { apiList ->
val eventIds = apiList.map { it.id }.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,16 @@ class EventViewHolder(override val containerView: View) : RecyclerView.ViewHolde

setFabBackground(event.favorite)

event.eventType.let {
if (it != null)
addchips(it.name)
}
event.eventTopic.let {
if (it != null)
addchips(it.name)
}
event.eventSubTopic.let {
if (it != null)
addchips(it.name)
if (containerView.chipTags != null) {
event.eventType?.let {
addchips(it.name)
}
event.eventTopic?.let {
addchips(it.name)
}
event.eventSubTopic?.let {
addchips(it.name)
}
}

event.originalImageUrl?.let { url ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ class EventsViewModel(
}

fun loadLocationEvents() {
val query = "[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%${mutableSavedLocation.value}%\"}]"
if (lastSearch != savedLocation.value) {
compositeDisposable.add(eventService.getEventsByLocation(query)
compositeDisposable.add(eventService.getEventsByLocation(mutableSavedLocation.value)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package org.fossasia.openevent.general.event.subtopic

import androidx.room.TypeConverter
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper

class EventSubTopicConverter {

@TypeConverter
fun toEventSubTopic(json: String): EventSubTopic? {
return ObjectMapper().readerFor(EventSubTopic::class.java).readValue<EventSubTopic>(json)
return jacksonObjectMapper().readerFor(EventSubTopic::class.java).readValue<EventSubTopic>(json)
}

@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package org.fossasia.openevent.general.event.topic

import androidx.room.TypeConverter
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper

class EventTopicConverter {
@TypeConverter
fun toEventTopic(json: String): EventTopic? {
return ObjectMapper().readerFor(EventTopic::class.java).readValue<EventTopic>(json)
return jacksonObjectMapper().readerFor(EventTopic::class.java).readValue<EventTopic>(json)
}

@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ class SimilarEventsViewModel(private val eventService: EventService, private val
}

fun loadSimilarLocationEvents(location: String) {
val query = "[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$location%\"}]"

compositeDisposable.add(eventService.getEventsByLocation(query)
compositeDisposable.add(eventService.getEventsByLocation(location)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package org.fossasia.openevent.general.event.types

import androidx.room.TypeConverter
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper

class EventTypeConverter {
@TypeConverter
fun toEventType(json: String): EventType? {
return ObjectMapper().readerFor(EventType::class.java).readValue<EventType>(json)
return jacksonObjectMapper().readerFor(EventType::class.java).readValue<EventType>(json)
}

@TypeConverter
Expand Down