*** Это код, и мой ответ возвращает ноль, я использую наблюдаемые и живые данные RXjav2. Я хочу быть в курсе, мое местоположение - Лагос, и это запрашивается в интерфейсе модернизации. Я использую API стека погоды
2020-02-29 15: 49: 10.309 17988-17988 / com.example.weatherapp D / network: null
data class Weather (
@SerializedName("name")
val location: String,
@SerializedName("weather_descriptions")
val description: List<String>,
@SerializedName("temperature")
val temperature: Long,
@SerializedName("wind_speed")
val windSpeed: Long,
@SerializedName("wind_dir")
val windDir: String,
@SerializedName("precip")
val precipitation: Long,
@SerializedName("humidity")
val humidity: Long,
@SerializedName("visibility")
val visibility: Long,
@SerializedName("weather_icons")
val icon: List<String>
): Parcelable
data class Request(
@SerializedName("language")
val language: String,
@SerializedName("query")
val query: String,
@SerializedName("type")
val type: String,
@SerializedName("unit")
val unit: String
)
data class Location(
@SerializedName("country")
val country: String,
@SerializedName("lat")
val lat: String,
@SerializedName("localtime")
val localtime: String,
@SerializedName("localtime_epoch")
val localtime_epoch: Int,
@SerializedName("lon")
val lon: String,
@SerializedName("name")
val name: String,
@SerializedName("region")
val region: String,
@SerializedName("timezone_id")
val timezone_id: String,
@SerializedName("utc_offset")
val utc_offset: String
)
Класс данных ответа
data class WeatherResponse(
@SerializedName("current")
val current: Weather,
@SerializedName("location")
val location: Location,
@SerializedName("request")
val request: Request
)
Сетевой интерфейс
interface ApixuApi {
@GET("current///")
fun getWeather(@Query("access_key") api: String = Util.API_KEY,
@Query("query") location: String = "Lagos"): Observable<WeatherResponse>
Интерфейс источника данных
interface DataSource {
fun getWeather(): LiveData<WeatherResponse>
fun refreshWeather()
fun saveWeather(weather: Weather)
fun clearWeather()
}
package com.example.weatherapp.dataSource
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.weatherapp.model.Weather
import com.example.weatherapp.model.WeatherResponse
import com.example.weatherapp.network.ApixuApi
import com.example.weatherapp.util.NetworkState
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
class RemoteDataSource(private val api: ApixuApi, private val compositeDisposable: CompositeDisposable) : DataSource {
private val _networkState = MutableLiveData<NetworkState>()
val networkState: LiveData<NetworkState>
get() = _networkState
private val _apiResponse = MutableLiveData<WeatherResponse>()
val apiResponse
get() = _apiResponse
override fun getWeather(): LiveData<WeatherResponse> {
_networkState.postValue(NetworkState.LOADING)
var data:Weather? = null
try {
compositeDisposable.add(
api.getWeather()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(
{
// data = _apiResponse.value.current
// data = it
//data = _apiResponse.value!!.current
data = _apiResponse.value!!.current
Log.d("remotedd", _apiResponse.value!!.current.toString())
_networkState.postValue(NetworkState.LOADED)
},
{
_networkState.postValue(NetworkState.ERROR)
Log.d("networks", it.message.toString())
}
)
)
}catch (e: Exception){
Log.d("networks", e.message.toString())
}
return apiResponse
}
override fun refreshWeather() {
_apiResponse.value = getWeather().value
}
override fun saveWeather(weather: Weather) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun clearWeather() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
Мне нужна помощь, чтобы понять, мой ответ нулевой