【发布时间】:2018-08-02 23:31:56
【问题描述】:
如果我的数据库表为空,我正在尝试使用我的调用 api 的响应更新我的数据库(房间)并返回到我的 recyclerview
API
@GET("user/patient/")
Flowable<ResponsePatient> getPatients(@Header("Authorization") String userToken);
FactoryData.class
public Flowable<List<Patient>> getPatientFromApi(){
String token = preferences.getValue(SDConstants.token);
return apiNetwork.getPatients(token).map(new Function<ResponsePatient, List<Patient>>() {
@Override
public List<Patient> apply(ResponsePatient responsePatient) throws Exception {
return PatientMapper.transform(responsePatient);
}
});
}
public Flowable<List<Patient>> listPatient(){
return appDataBase.patientDao().listPatient()
.switchIfEmpty(getPatientFromApi())
.doOnNext(s -> appDataBase.patientDao().saveAll(s));
}
我不知道该怎么做。我很感激任何帮助。
【问题讨论】:
标签: retrofit2 repository-pattern rx-java2 android-room