Show error message on EditText

This commit is contained in:
Jarne Demeulemeester 2021-06-10 11:25:22 +02:00
parent e6313378d5
commit d28908c615
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
2 changed files with 10 additions and 0 deletions

View file

@ -44,6 +44,10 @@ class AddServerFragment : Fragment() {
binding.progressCircular.visibility = View.GONE
})
viewModel.error.observe(viewLifecycleOwner, {
binding.editTextServerAddress.error = it
})
return binding.root
}
}

View file

@ -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
}
}