diff --git a/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt b/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt index 8895c66..854d251 100644 --- a/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt +++ b/app/src/main/java/keijumt/devandroid/viewmodel/MainViewModel.kt @@ -1,7 +1,28 @@ package keijumt.devandroid.viewmodel import android.arch.lifecycle.ViewModel +import android.databinding.ObservableField +import io.reactivex.rxkotlin.subscribeBy +import io.reactivex.schedulers.Schedulers +import keijumt.devandroid.api.response.mapper.toAddressEntity +import keijumt.devandroid.repository.PostalCodeRepository import javax.inject.Inject -class MainViewModel @Inject constructor() : ViewModel() { +class MainViewModel @Inject constructor(val postalCodeRepository: PostalCodeRepository) : ViewModel() { + + val postalCode = ObservableField() + var address = ObservableField() + + fun search() { + postalCodeRepository.search(6731102) + .subscribeOn(Schedulers.io()) + .subscribeBy( + onSuccess = { postalCode -> + val addressEntity = postalCode.toAddressEntity() + address.set(addressEntity.address) + println("hoge") + }, + onError = {} + ) + } } \ No newline at end of file