Use enum directly instead of its value.

This commit is contained in:
Onuray Sahin 2020-09-28 19:05:33 +03:00 committed by Benoit Marty
parent 430a0d2492
commit e21f306635
3 changed files with 6 additions and 5 deletions

View File

@ -55,7 +55,7 @@ internal class DefaultSearchTask @Inject constructor(
searchCategories = SearchRequestCategories( searchCategories = SearchRequestCategories(
roomEvents = SearchRequestRoomEvents( roomEvents = SearchRequestRoomEvents(
searchTerm = params.searchTerm, searchTerm = params.searchTerm,
orderBy = if (params.orderByRecent) SearchRequestOrder.RECENT.value else SearchRequestOrder.RANK.value, orderBy = if (params.orderByRecent) SearchRequestOrder.RECENT else SearchRequestOrder.RANK,
filter = SearchRequestFilter( filter = SearchRequestFilter(
limit = params.limit, limit = params.limit,
rooms = listOf(params.roomId) rooms = listOf(params.roomId)

View File

@ -17,13 +17,14 @@
package org.matrix.android.sdk.internal.session.search.request package org.matrix.android.sdk.internal.session.search.request
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
/** /**
* Represents the order in which to search for results. * Represents the order in which to search for results.
*/ */
@JsonClass(generateAdapter = false) @JsonClass(generateAdapter = false)
internal enum class SearchRequestOrder(val value: String) { internal enum class SearchRequestOrder {
RANK("rank"), @Json(name = "rank") RANK,
RECENT("recent") @Json(name = "recent") RECENT
} }

View File

@ -29,7 +29,7 @@ internal data class SearchRequestRoomEvents(
val filter: SearchRequestFilter? = null, val filter: SearchRequestFilter? = null,
// By default, this is "rank". One of: ["recent", "rank"] // By default, this is "rank". One of: ["recent", "rank"]
@Json(name = "order_by") @Json(name = "order_by")
val orderBy: String? = null, val orderBy: SearchRequestOrder? = null,
// Configures whether any context for the events returned are included in the response. // Configures whether any context for the events returned are included in the response.
@Json(name = "event_context") @Json(name = "event_context")
val eventContext: SearchRequestEventContext? = null val eventContext: SearchRequestEventContext? = null