结合RxJava Observable,SharedPreferences和MVP

时间:2018-11-01 21:45:23

标签: android sharedpreferences observable rx-java2 mvp

如何在observable内部使用sharedPreferences,因为我知道在observable之外获取价值是一个坏习惯。

我有这样的东西:

class City {
    private String tempCelsius;
    private String tempKelvin;
    // other fields

    public getTempCelsius() {
        return tempCelsius;
    }

    public getTempKelvin() {
        return tempKelvin;
    }
}

在主持人中,我有:

    public Single<City> getData() {
        return dataManager.loadCitiesFromDb().
            map(city -> dataManager.makeApiCall(city)
                //getting data, error handling
            )
            .subscribe(city -> view.showCityData(city));
    }

通过我的DataManager包含PreferenceHelper实例的方式。

如何基于SharedPreferences中的值来showCityData使用温度。

如果Kelvin使用City的方法getTempKelvin(),否则,如果Celsius使用City的方法getTempCelsius()

我从Api收到了两个消息,但根据保存的首选项只需要显示一次。

0 个答案:

没有答案