-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Move user mention search to CheckIn (#354)
fixes #351
- Loading branch information
Showing
8 changed files
with
130 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 8 additions & 30 deletions
38
app/src/main/kotlin/de/hbch/traewelling/shared/BottomSearchViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,15 @@ | ||
package de.hbch.traewelling.shared | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import de.hbch.traewelling.api.TraewellingApi | ||
import de.hbch.traewelling.api.models.user.User | ||
|
||
class BottomSearchViewModel : ViewModel() { | ||
private var _clickHandler: ((String) -> Unit)? = null | ||
|
||
private val _userResults = MutableLiveData<List<User>?>(null) | ||
val userResults: LiveData<List<User>?> get() = _userResults | ||
|
||
private val _displayResults = MutableLiveData(false) | ||
val displayResults: LiveData<Boolean> get() = _displayResults | ||
|
||
suspend fun searchUsers(query: String) { | ||
_displayResults.postValue(true) | ||
val data = try { TraewellingApi.userService.searchUsers(query).data } catch (_: Exception) { listOf() } | ||
_userResults.postValue(data) | ||
} | ||
|
||
fun reset() { | ||
_displayResults.postValue(false) | ||
_userResults.postValue(null) | ||
_clickHandler = null | ||
} | ||
|
||
fun registerClickHandler(handler: (String) -> Unit) { | ||
_clickHandler = handler | ||
} | ||
|
||
fun onClick(selection: String) { | ||
_clickHandler?.invoke(selection) | ||
} | ||
} | ||
suspend fun searchUsers(query: String): List<User> { | ||
return try { | ||
TraewellingApi.userService.searchUsers(query).data | ||
} catch (_: Exception) { | ||
listOf() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.