本文整理匯總了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);
}
}
});
}