本文整理汇总了Java中cn.bmob.v3.BmobQuery.setMaxCacheAge方法的典型用法代码示例。如果您正苦于以下问题:Java BmobQuery.setMaxCacheAge方法的具体用法?Java BmobQuery.setMaxCacheAge怎么用?Java BmobQuery.setMaxCacheAge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.bmob.v3.BmobQuery
的用法示例。
在下文中一共展示了BmobQuery.setMaxCacheAge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateDatas
import cn.bmob.v3.BmobQuery; //导入方法依赖的package包/类
private void generateDatas() {
String currentUserNameStr = (String) BmobUser.getObjectByKey("username");
Log.i(TAG, "currentUserNameStr >> " + currentUserNameStr);
BmobQuery<NotesBean> query1 = new BmobQuery<>();
query1.addWhereLessThanOrEqualTo("createdAt", new BmobDate(new Date()));
BmobQuery<NotesBean> query2 = new BmobQuery<>();
query2.addWhereEqualTo("userNameStr", currentUserNameStr);
List<BmobQuery<NotesBean>> andQuerys = new ArrayList<>();
andQuerys.add(query1);
andQuerys.add(query2);
BmobQuery<NotesBean> notesInfoBmobQuery = new BmobQuery<>();
notesInfoBmobQuery.and(andQuerys);
notesInfoBmobQuery.order("-createdAt"); // 按时间降序排列
// 设定查询缓存策略-CACHE_ELSE_NETWORK: 先从缓存读取数据, 如果没有, 再从网络获取.
notesInfoBmobQuery.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK);
notesInfoBmobQuery.setMaxCacheAge(TimeUnit.DAYS.toMillis(7)); //此表示缓存一天
notesInfoBmobQuery.findObjects(new FindListener<NotesBean>() {
@Override
public void done(List<NotesBean> list, BmobException e) {
if (!list.isEmpty()) {
for (NotesBean notesBean : list) {
mDatas.add(notesBean);
}
if (!mDatas.isEmpty()) {
mMaterialDialog.dismiss();
mFindNotesAdapter.notifyDataSetChanged();
}
} else {
mMaterialDialog.dismiss();
Toast.makeText(FindNotesAty.this, "暂无数据", Toast.LENGTH_SHORT).show();
}
}
});
}
示例2: generateData
import cn.bmob.v3.BmobQuery; //导入方法依赖的package包/类
/**
* 获取数据:获取云端最近时间内的5条数据
*/
private void generateData() {
Log.i("LOG", "mDate in generateData >>> " + mDate);
BmobQuery<ComUserPostInfo> postInfoBmobQuery = new BmobQuery<ComUserPostInfo>();
postInfoBmobQuery.addWhereLessThanOrEqualTo("createdAt", new BmobDate(mDate));
postInfoBmobQuery.order("-createdAt"); // 按时间降序排列
postInfoBmobQuery.setLimit(QUERY_ITEM_LIMITS); // 设定返回的查询条数
// 设定查询缓存策略-CACHE_ELSE_NETWORK: 先从缓存读取数据, 如果没有, 再从网络获取.
postInfoBmobQuery.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK);
postInfoBmobQuery.setMaxCacheAge(TimeUnit.DAYS.toMillis(7)); //此表示缓存一天
postInfoBmobQuery.findObjects(new FindListener<ComUserPostInfo>() {
@Override
public void done(List<ComUserPostInfo> list, BmobException e) {
if (e == null) {
mNoDataTv.setVisibility(View.GONE);
for (ComUserPostInfo comUserPostInfo : list) {
mList.add(comUserPostInfo);
}
// get the last item post time
if (!mList.isEmpty()) {
mComAppAdapter = new ComAppAdapter(getActivity());
mComAppAdapter.setData(mList);
mListView.setAdapter(mComAppAdapter);
ComUserPostInfo lastPostInfo = mList.get(mList.size() - 1);
Log.i("LOG", "lastPostInfo.getUserTimeStr() in generateData " +
lastPostInfo.getUserTimeStr());
lastItemPostTimeStr = lastPostInfo.getUserTimeStr();
} else {
mNoDataTv.setText("暂无数据!");
mNoDataTv.setVisibility(View.VISIBLE);
}
mProgressBar.setVisibility(ProgressBar.GONE);
} else {
mProgressBar.setVisibility(ProgressBar.GONE);
mNoDataTv.setText("加载数据出错");
mNoDataTv.setVisibility(View.VISIBLE);
}
}
});
}
示例3: generateRefleshData
import cn.bmob.v3.BmobQuery; //导入方法依赖的package包/类
/**
* 下拉刷新数据:获取云端最近时间内的5条数据
* 思路:记录第一次加载应用或下拉刷新的时间,
* 取第二次或之后下拉刷新的时间这一段时间内的数据;
* 从Bmob云端进行复合查询
*/
private void generateRefleshData() {
final List<ComUserPostInfo> tempList = new ArrayList<>();
// 使用复合查询
Log.i("LOG", "mDate in generateRefleshData query1 >>> " + mDate);
BmobQuery<ComUserPostInfo> query1 = new BmobQuery<>();
query1.addWhereGreaterThanOrEqualTo("createdAt", new BmobDate(mDate));
mDate = new Date(); // 获取当前最新时间
Log.i("LOG", "mDate in generateRefleshData query2 >>> " + mDate);
BmobQuery<ComUserPostInfo> query2 = new BmobQuery<>();
query2.addWhereLessThanOrEqualTo("createdAt", new BmobDate(mDate));
List<BmobQuery<ComUserPostInfo>> andQuerys = new ArrayList<>();
andQuerys.add(query1);
andQuerys.add(query2);
BmobQuery<ComUserPostInfo> postInfoBmobQuery = new BmobQuery<>();
postInfoBmobQuery.and(andQuerys);
postInfoBmobQuery.addWhereLessThanOrEqualTo("createdAt", new BmobDate(mDate));
postInfoBmobQuery.order("-createdAt"); // 按时间降序排列
postInfoBmobQuery.setLimit(QUERY_ITEM_LIMITS); // 设定返回的查询条数
// 设定查询缓存策略-NETWORK_ELSE_CACHE: 先从网络读取数据, 如果没有, 再从缓存获取.
postInfoBmobQuery.setCachePolicy(BmobQuery.CachePolicy.NETWORK_ELSE_CACHE);
postInfoBmobQuery.setMaxCacheAge(TimeUnit.DAYS.toMillis(7)); //此表示缓存一天
postInfoBmobQuery.findObjects(new FindListener<ComUserPostInfo>() {
@Override
public void done(List<ComUserPostInfo> list, BmobException e) {
if (e == null) {
if (list.size() == 0) {
SystemUtils.showHandlerToast(getActivity(), "没有更多内容了...");
Log.i("LOG", "list.size() in generateRefleshData >>> " + list.size());
} else {
for (ComUserPostInfo comUserPostInfo : list) {
tempList.add(comUserPostInfo);
}
// add and remove the same element
mList.addAll(0, tempList);
mList = SystemUtils.removeDuplicateData(mList);
mComAppAdapter = new ComAppAdapter(getActivity());
mComAppAdapter.setData(mList);
mListView.setAdapter(mComAppAdapter);
}
mProgressBar.setVisibility(ProgressBar.GONE);
} else {
mProgressBar.setVisibility(ProgressBar.GONE);
}
}
});
}
示例4: generateLoadMoreData
import cn.bmob.v3.BmobQuery; //导入方法依赖的package包/类
/**
* 上拉加载更多数据:获取云端最近时间内的5条数据
* 思路:获取应用第一次打开时加载的数据的最后一个时间,
* 上滑加载更多时, 数据取该日期之前的数据, 之后更新时间
*/
private void generateLoadMoreData() {
// get last item post time
Date newdate = DateUtil.string2Date(lastItemPostTimeStr);
Log.i("LOG", "newdate in generateLoadMoreData >>> " + newdate);
BmobQuery<ComUserPostInfo> postInfoBmobQuery = new BmobQuery<>();
postInfoBmobQuery.addWhereLessThanOrEqualTo("createdAt", new BmobDate(newdate));
postInfoBmobQuery.order("-createdAt"); // 按时间降序排列
postInfoBmobQuery.setLimit(QUERY_ITEM_LIMITS); // 设定返回的查询条数
// 设定查询缓存策略-CACHE_ELSE_NETWORK: 先从网络读取数据, 如果没有, 再从缓存获取.
postInfoBmobQuery.setCachePolicy(BmobQuery.CachePolicy.NETWORK_ELSE_CACHE);
postInfoBmobQuery.setMaxCacheAge(TimeUnit.DAYS.toMillis(7)); //此表示缓存一天
postInfoBmobQuery.findObjects(new FindListener<ComUserPostInfo>() {
@Override
public void done(List<ComUserPostInfo> list, BmobException e) {
if (e == null) {
if (list.size() == 0) {
SystemUtils.showHandlerToast(getActivity(), "没有更多内容了...");
Log.i("LOG", "list.size() in generateLoadMoreData >>> " + list.size());
} else {
for (ComUserPostInfo comUserPostInfo : list) {
mList.add(comUserPostInfo);
}
// 监听数据的变化, 上拉加载更多后处于当前可视的最后一个item位置
mComAppAdapter.notifyDataSetChanged();
// get the last item post time
if (!mList.isEmpty()) {
ComUserPostInfo lastPostInfo = mList.get(mList.size() - 1);
Log.i("LOG", "lastPostInfo.getUserTimeStr() in generateLoadMoreData" +
lastPostInfo.getUserTimeStr());
lastItemPostTimeStr = lastPostInfo.getUserTimeStr();
}
}
mProgressBar.setVisibility(ProgressBar.GONE);
} else {
mProgressBar.setVisibility(ProgressBar.GONE);
}
}
});
}