db.getTitleProductDAO().getLastDate()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(s -> dateWrite = s, throwable -> Log.d(TAG, "DownloadDataServer: " + throwable));
/*когда получаем dateWrite, обращаемся к серверу/серверам*/
if (dateWrite == null)
dateWrite = "2000-01-01";
networkService.getJSONApiTittleProduct()
.getPostWithID(dateWrite)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe(postTittleProducts -> {
for (PostTittleProduct i : postTittleProducts) {
TitleProduct titleProduct = TitleProduct.builder()
.id_product(i.getId_product())
.product_name(i.getProduct_name_ru())
.product_name_low(i.getProduct_name_ru().toLowerCase())
.date_write(i.getDate_write())
.build();
db.getTitleProductDAO().add(titleProduct);
}
}, throwable -> Log.d(TAG, "getJSONApiTittleProduct: " + throwable));
/* дата последнейзаписи */
@Query("Select date_write from title_product where date_write = (select max(date_write) " +
"from title_product)")
Maybe<String> getLastDate();
public class ModelMainActivity implements iModelMainActivity {
private static final String TAG = "ModelMainActivity";
public ModelMainActivity() {
MainApp.app().appComponent().inject(this);
/**тут качаем с сервера - нужно сделать это нормально**/
new DownloadDataServer();
}
@Override
public Observable updateDB() {
return Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> emitter) throws Exception {
Thread.sleep(2000);
emitter.onNext("");
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
}
}