diff --git a/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt b/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt index 854d251..c3e9b1a 100644 --- a/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt +++ b/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt @@ -9,20 +9,28 @@ import javax.inject.Inject class MainViewModel @Inject constructor(val postalCodeRepository: PostalCodeRepository) : ViewModel() { - - val postalCode = ObservableField() + + val postalCode = ObservableField("") var address = ObservableField() fun search() { - postalCodeRepository.search(6731102) + if (postalCode.get().isNullOrEmpty()) { + return + } + postalCodeRepository.search(postalCode.get()?.toInt()!!) .subscribeOn(Schedulers.io()) .subscribeBy( onSuccess = { postalCode -> - val addressEntity = postalCode.toAddressEntity() - address.set(addressEntity.address) - println("hoge") + if (postalCode.results != null) { + val addressEntity = postalCode.toAddressEntity() + address.set(addressEntity.address) + } else { + address.set("Address does not exist.") + } }, - onError = {} + onError = { + address.set("") + } ) } } \ No newline at end of file