Newer
Older
DevAndroid / app / src / main / java / keijumt / devandroid / viewmodel / MainViewModel.kt
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(val postalCodeRepository: PostalCodeRepository) : ViewModel() {
    
    val postalCode = ObservableField<String>()
    var address = ObservableField<String>()

    fun search() {
        postalCodeRepository.search(6731102)
                .subscribeOn(Schedulers.io())
                .subscribeBy(
                        onSuccess = { postalCode ->
                            val addressEntity = postalCode.toAddressEntity()
                            address.set(addressEntity.address)
                            println("hoge")
                        },
                        onError = {}
                )
    }
}