Show error message on EditText
This commit is contained in:
parent
e6313378d5
commit
d28908c615
2 changed files with 10 additions and 0 deletions
|
@ -44,6 +44,10 @@ class AddServerFragment : Fragment() {
|
|||
binding.progressCircular.visibility = View.GONE
|
||||
})
|
||||
|
||||
viewModel.error.observe(viewLifecycleOwner, {
|
||||
binding.editTextServerAddress.error = it
|
||||
})
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
|
@ -16,14 +16,20 @@ class AddServerViewModel(val application: Application) : ViewModel() {
|
|||
val navigateToLogin: LiveData<Boolean>
|
||||
get() = _navigateToLogin
|
||||
|
||||
private val _error = MutableLiveData<String>()
|
||||
val error: LiveData<String>
|
||||
get() = _error
|
||||
|
||||
fun checkServer(baseUrl: String) {
|
||||
viewModelScope.launch {
|
||||
val jellyfinApi = JellyfinApi.newInstance(application, baseUrl)
|
||||
try {
|
||||
jellyfinApi.systemApi.getPublicSystemInfo()
|
||||
_error.value = null
|
||||
_navigateToLogin.value = true
|
||||
} catch (e: Exception) {
|
||||
Log.e("JellyfinApi", "${e.message}")
|
||||
_error.value = e.message
|
||||
_navigateToLogin.value = false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue