Java Code Examples for cn.bmob.v3.BmobQuery#setCachePolicy()
The following examples show how to use
cn.bmob.v3.BmobQuery#setCachePolicy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MsgManager.java From NewFastFrame with Apache License 2.0 | 5 votes |
public void getAllDefaultAvatarFromServer(final FindListener<String> findListener) { BmobQuery bmobQuery = new BmobQuery("sys_data"); bmobQuery.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK); bmobQuery.findObjectsByTable(new QueryListener<JSONArray>() { @Override public void done(JSONArray jsonArray, BmobException e) { if (e == null) { List<String> avatarList = null; if (jsonArray != null && jsonArray.length() > 0) { LogUtil.e(jsonArray.toString()); avatarList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject avatarJson = jsonObject.getJSONObject("avatar"); String avatar = avatarJson.getString("url"); if (avatar != null) { avatarList.add(avatar); } } catch (JSONException item) { item.printStackTrace(); } } } if (avatarList == null) { LogUtil.e("服务器上面没有头像数据"); } findListener.done(avatarList, null); } else { findListener.done(null, e); } } }); }
Example 2
Source File: MsgManager.java From NewFastFrame with Apache License 2.0 | 5 votes |
public void getAllDefaultWallPaperFromServer(final FindListener<String> findListener) { BmobQuery bmobQuery = new BmobQuery("sys_data"); bmobQuery.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK); bmobQuery.findObjectsByTable(new QueryListener<JSONArray>() { @Override public void done(JSONArray jsonArray, BmobException e) { if (e == null) { List<String> avatarList = null; if (jsonArray != null && jsonArray.length() > 0) { LogUtil.e(jsonArray.toString()); avatarList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject avatarJson = jsonObject.getJSONObject("wallpaper"); String avatar = avatarJson.getString("url"); if (avatar != null) { avatarList.add(avatar); } } catch (JSONException item) { item.printStackTrace(); } } } if (avatarList == null) { LogUtil.e("服务器上面没有背景数据"); } findListener.done(avatarList, null); } else { findListener.done(null, e); } } }); }
Example 3
Source File: MsgManager.java From NewFastFrame with Apache License 2.0 | 5 votes |
public void getAllDefaultTitleWallPaperFromServer(final FindListener<String> findListener) { BmobQuery bmobQuery = new BmobQuery("sys_data"); bmobQuery.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK); bmobQuery.findObjectsByTable(new QueryListener<JSONArray>() { @Override public void done(JSONArray jsonArray, BmobException e) { if (e == null) { List<String> avatarList = null; if (jsonArray != null && jsonArray.length() > 0) { LogUtil.e(jsonArray.toString()); avatarList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject avatarJson = jsonObject.getJSONObject("twallpaper"); String avatar = avatarJson.getString("url"); if (avatar != null) { avatarList.add(avatar); } } catch (JSONException item) { item.printStackTrace(); } } } if (avatarList == null) { LogUtil.e("服务器上面没有背景数据"); } findListener.done(avatarList, null); } else { findListener.done(null, e); } } }); }
Example 4
Source File: FindNotesAty.java From myapplication with Apache License 2.0 | 5 votes |
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(); } } }); }
Example 5
Source File: SecondFragment.java From myapplication with Apache License 2.0 | 4 votes |
/** * 获取数据:获取云端最近时间内的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); } } }); }
Example 6
Source File: SecondFragment.java From myapplication with Apache License 2.0 | 4 votes |
/** * 上拉加载更多数据:获取云端最近时间内的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); } } }); }