goodsDao = DaoMaster.newDevSession(this, GoodsDao.TABLENAME).getGoodsDao();
if (isNetworkConnected()) {//有网
mPresenter = new ShopCartPresenter(new ShopCartCall());
mPresenter.requestData(“159”, “1557736557381159”);
} else {//没网
mAdapter.addAll(goodsDao.loadAll());
mAdapter.notifyDataSetChanged();
}
}
public boolean isNetworkConnected() {
ConnectivityManager mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
return false;
}
goodsDao.insertOrReplaceInTx(data);//添加到数据库