Java Code Examples for cn.bmob.v3.BmobQuery#setLimit()
The following examples show how to use
cn.bmob.v3.BmobQuery#setLimit() .
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: SampleAdapter.java From styT with Apache License 2.0 | 6 votes |
@Override protected void onBindItemViewHolder(ItemViewHolder holder, final int headerPosition, final int itemPosition) { final Comment weibo = weibos.get(itemPosition); MyUser user = BmobUser.getCurrentUser(MyUser.class); BmobQuery<Comment> query = new BmobQuery<>(); //query.addWhereEqualTo("author", user); // 查询当前用户的所有微博 query.order("-updatedAt"); query.include("author");// 希望在查询微博信息的同时也把发布人的信息查询出来,可以使用include方法 query.setLimit(4); query.findObjects(new FindListener<Comment>() { @Override public void done(List<Comment> object, BmobException e) { if (e == null) { weibos = object; adapter.notifyDataSetChanged(); } else { } } }); //adapter = new MyAdapter(getActivity()); holder.listView.setAdapter(adapter); }
Example 2
Source File: OrderActivity.java From BitkyShop with MIT License | 6 votes |
private void queryDefaultAddressFromBmob() { BmobQuery<ReceiveAddress> bmobQuery = new BmobQuery<>(); bmobQuery.addWhereEqualTo("userObjectId", order.getUserObjectId()); bmobQuery.addWhereEqualTo("isDefault", true); bmobQuery.setLimit(50); bmobQuery.findObjects(new FindListener<ReceiveAddress>() { @Override public void done(List<ReceiveAddress> list, BmobException e) { if (e != null) { toastUtil.show(e.getMessage()); return; } if (list.size() > 0) { receiveAddress = list.get(0); name.setText(receiveAddress.getName()); phone.setText(receiveAddress.getPhone()); address.setText(receiveAddress.getAddress()); } } }); }
Example 3
Source File: OwnChannelFragment.java From VSigner with GNU General Public License v2.0 | 6 votes |
public void refreshData() { BmobQuery<Channel> channelQuery = new BmobQuery<Channel>(); channelQuery.addWhereEqualTo(Channel.MANAGER_KEY, mCurrentUser.getObjectId()); channelQuery.include(Channel.MANAGER_KEY); channelQuery.setLimit(Constants.QUERY_MAX_NUMBER); channelQuery.order("-" + Channel.IS_ACTIVE_KEY + ",-" + Constants.UPDATED_AT_KEY); channelQuery.findObjects(mContext, new FindListener<Channel>() { @Override public void onSuccess(List<Channel> channels) { mOwnChannelAdapter.clear(); mOwnChannelAdapter.addAll(channels); mPullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED); } @Override public void onError(int arg0, String msg) { mPullToRefreshLayout.refreshFinish(PullToRefreshLayout.FAIL); } }); }
Example 4
Source File: ShareInfoPresenter.java From NewFastFrame with Apache License 2.0 | 6 votes |
public void getFirstPostNotifyBean() { BmobQuery<PostNotifyBean> bmobQuery = new BmobQuery<>(); bmobQuery.addWhereEqualTo("toUser", new BmobPointer(UserManager.getInstance().getCurrentUser())); bmobQuery.addWhereEqualTo("readStatus", ConstantUtil.READ_STATUS_READED); bmobQuery.order("-createdAt"); bmobQuery.setLimit(1); bmobQuery.include("relatedUser"); addSubscription(bmobQuery.findObjects(new FindListener<PostNotifyBean>() { @Override public void done(List<PostNotifyBean> list, BmobException e) { if (e == null && list != null && list.size() > 0) { RxBusManager.getInstance().post(new UnReadPostNotifyEvent(list.get(0))); } } })); }
Example 5
Source File: ShowSignerActivity.java From VSigner with GNU General Public License v2.0 | 6 votes |
public void refreshData() { BmobQuery<ChannelSigner> channelQuery = new BmobQuery<ChannelSigner>(); channelQuery.addWhereEqualTo(ChannelSigner.CHANNEL_KEY, mChannel.getObjectId()); channelQuery.addWhereGreaterThanOrEqualTo(ChannelSigner.SIGN_DATE_KEY, mChannel.getStartSignDate()); channelQuery.include(String.format("%1$s,%2$s", ChannelSigner.SIGNER_KEY, ChannelSigner.CHANNEL_KEY)); channelQuery.setLimit(Constants.QUERY_MAX_NUMBER); channelQuery.order(ChannelSigner.SIGNER_KEY); channelQuery.findObjects(mContext, new FindListener<ChannelSigner>() { @Override public void onSuccess(List<ChannelSigner> channelSigners) { mChannelSignerAdapter.clear(); mChannelSignerAdapter.addAll(channelSigners); mPullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED); } @Override public void onError(int arg0, String msg) { mPullToRefreshLayout.refreshFinish(PullToRefreshLayout.FAIL); } }); }
Example 6
Source File: OrderManagerPresenter.java From BitkyShop with MIT License | 6 votes |
public void queryOrderFormBmob(String objectId, int status) { userObjectId = objectId; this.status = status; BmobQuery<Order> bmobQuery = new BmobQuery<>(); bmobQuery.addWhereEqualTo("userObjectId", objectId); if (status != Order.NONE) { bmobQuery.addWhereEqualTo("status", status); } bmobQuery.order("-createdAt"); bmobQuery.setLimit(countLimit); bmobQuery.findObjects(new FindListener<Order>() { @Override public void done(List<Order> list, BmobException e) { if (e != null) { activity.showMessage("您还没有买过东西!"); return; } activity.initCloudOrder(list); } }); }
Example 7
Source File: LoginActivity.java From Swface with Apache License 2.0 | 6 votes |
private void startSearchUser(final String username, final String password) { BmobQuery<UserLogin> query = new BmobQuery<>(); query.addWhereEqualTo("username", username); query.setLimit(1); query.findObjects(new FindListener<UserLogin>() { @Override public void done(List<UserLogin> list, BmobException e) { if (e == null && !list.isEmpty()) { startLogin(list.get(0)); } else if (e == null) { startRegister(username, password); } else { showNormalDia("温馨提示", "登录失败!请检查网络连接"); Log.e(TAG, "query.findObjects: ", e); } } }); }
Example 8
Source File: LoginActivity.java From Mobike with Apache License 2.0 | 6 votes |
private void RegOK() { mDialog.show(); mPhone = mEtPhone.getText().toString().trim().replace("\\s*", "");// TODO: 2017/6/21 测试后删除 BmobQuery<MyUser> query = new BmobQuery<MyUser>(); query.addWhereEqualTo("username", mPhone); query.setLimit(1); query.findObjects(new FindListener<MyUser>() { @Override public void done(List<MyUser> list, BmobException e) { if (e == null) { if (list.size() > 0 && list != null) { Log.d(TAG, "cheackUser: ok"); toLogin(); } else { Log.d(TAG, "cheackUser: notRegister"); toRegister(); } } else { Log.d(TAG, "done: " + e); DismissMyDialog(); } } }); }
Example 9
Source File: SettingsActivity.java From Mobike with Apache License 2.0 | 6 votes |
private void findNew() { mDialog.show(); BmobQuery<VersionInfo> query = new BmobQuery<>("VersionInfo"); query.order("-updatedAt"); query.setLimit(1);//最新1条 query.findObjects(new FindListener<VersionInfo>() { @Override public void done(List<VersionInfo> list, BmobException e) { if (e == null && !list.isEmpty()) { dismissDialog(); chackVersion(list.get(0)); } else { ToastUtils.show(SettingsActivity.this, "检查新版本失败"); Logger.d(e); } dismissDialog(); } }); }
Example 10
Source File: SubscribeChannelDetail.java From VSigner with GNU General Public License v2.0 | 5 votes |
/** * 根据channel更新当前界面信息 * @param channel */ private void updateView(Channel channel) { mChannelNameTextView.setText(channel.getName()); mChannelInfoTextView.setText(channel.getInfo()); mManagerNameTextView.setText(String.format(getString(R.string.user_name_format), channel.getManager().getRealname(), channel.getManager().getUsername())); showProgressDialog(getString(R.string.server_query_tips)); BmobQuery<ChannelSubscriber> channelSubscriberQuery = new BmobQuery<ChannelSubscriber>(); channelSubscriberQuery.addWhereEqualTo(ChannelSubscriber.SUBSCRIBER_KEY, mCurrentUser.getObjectId()); channelSubscriberQuery.addWhereEqualTo(ChannelSubscriber.CHANNEL_KEY, mChannel.getObjectId()); channelSubscriberQuery.setLimit(Constants.QUERY_MAX_NUMBER); channelSubscriberQuery.order("-" + Constants.UPDATED_AT_KEY); channelSubscriberQuery.findObjects(mContext, new FindListener<ChannelSubscriber>() { @Override public void onSuccess(List<ChannelSubscriber> channelSubscribers) { mSubscribeChannelButton.setEnabled(true); hideProgressDialog(); if(channelSubscribers.size() > 0) { mSubscribeChannelButton.setText(R.string.already_subscribed); mChannelSubscriber = channelSubscribers.get(0); } else { mSubscribeChannelButton.setText(R.string.subscribe_channel); } } @Override public void onError(int arg0, String msg) { mSubscribeChannelButton.setEnabled(false); } }); }
Example 11
Source File: AddressOptionPresenter.java From BitkyShop with MIT License | 5 votes |
public void getCurrentUserAddress(String userObjectId) { BmobQuery<ReceiveAddress> bmobQuery = new BmobQuery<>(); bmobQuery.addWhereEqualTo("userObjectId", userObjectId); bmobQuery.setLimit(50); bmobQuery.findObjects(new FindListener<ReceiveAddress>() { @Override public void done(List<ReceiveAddress> list, BmobException e) { if (e != null) { activity.showMessage("您还没有添加收货地址哦!", null); return; } activity.initReceiveAddress(list); } }); }
Example 12
Source File: ProfileActivity.java From ZhihuDaily with MIT License | 5 votes |
private void loadMoreData() { BmobQuery<DailyStory> query = new BmobQuery<>(); query.setLimit(pagesize); query.setSkip(pageindex * pagesize); query.order("-createdAt"); query.addWhereEqualTo("user", ZhihuApplication.user.getObjectId()); query.findObjects(getApplicationContext(), new FindListener<DailyStory>() { @Override public void onSuccess(List<DailyStory> list) { if (list != null && list.size() > 0) { // 数据去重 LinkedHashSet<DailyStory> set = new LinkedHashSet<>(list); List<DailyStory> dailyStoryList = new ArrayList<>(set); mAdapter.addData(dailyStoryList); pageindex++; isLoading = false; if (list.size() < pagesize) { mAdapter.setIsFooterGone(true); } } } @Override public void onError(int i, String s) { } }); }
Example 13
Source File: UserManager.java From NewFastFrame with Apache License 2.0 | 5 votes |
public void queryNearbyPeople(int num, int flag, FindListener<User> findListener) { User currentUser = getCurrentUser(); BmobQuery<User> query = new BmobQuery<>(); if (flag == 1) { query.addWhereEqualTo("sex", false); } else if (flag == 2) { query.addWhereEqualTo("sex", true); } double longitude; double latitude; if (currentUser.getLocation() != null) { longitude = currentUser.getLocation().getLongitude(); latitude = currentUser.getLocation().getLatitude(); } else { SharedPreferences sharedPreferences = BaseApplication.getAppComponent() .getSharedPreferences(); if (sharedPreferences.getString(ConstantUtil.LONGITUDE, null) == null) { findListener.done(null, new BmobException("定位信息为空!!!!")); return; } longitude = Double.parseDouble(sharedPreferences.getString(ConstantUtil.LONGITUDE, null)); latitude = Double.parseDouble(sharedPreferences.getString(ConstantUtil.LATITUDE, null)); updateUserInfo(ConstantUtil.LOCATION, longitude + "&" + latitude, null); } query.addWhereNear("location", new BmobGeoPoint(longitude, latitude)); query.addWhereNotEqualTo("objectId", currentUser.getObjectId()); query.setSkip(num); query.setLimit(10); query.findObjects(findListener); }
Example 14
Source File: MainActivity.java From bmob-android-demo-paging with GNU General Public License v3.0 | 4 votes |
/** * 分页获取数据 * * @param page * 页码 * @param actionType * ListView的操作类型(下拉刷新、上拉加载更多) */ private void queryData(int page, final int actionType) { Log.i("bmob", "pageN:" + page + " limit:" + limit + " actionType:" + actionType); BmobQuery<TestData> query = new BmobQuery<>(); // 按时间降序查询 query.order("-createdAt"); int count = 0; // 如果是加载更多 if (actionType == STATE_MORE) { // 处理时间查询 Date date = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = sdf.parse(lastTime); Log.i("0414", date.toString()); } catch (ParseException e) { e.printStackTrace(); } // 只查询小于等于最后一个item发表时间的数据 query.addWhereLessThanOrEqualTo("createdAt", new BmobDate(date)); // 跳过之前页数并去掉重复数据 query.setSkip(page * count + 1); } else { // 下拉刷新 page = 0; query.setSkip(page); } // 设置每页数据个数 query.setLimit(limit); // 查找数据 query.findObjects(MainActivity.this, new FindListener<TestData>() { @Override public void onSuccess(List<TestData> list) { if (list.size() > 0) { if (actionType == STATE_REFRESH) { // 当是下拉刷新操作时,将当前页的编号重置为0,并把bankCards清空,重新添加 curPage = 0; bankCards.clear(); // 获取最后时间 lastTime = list.get(list.size() - 1).getCreatedAt(); } // 将本次查询的数据添加到bankCards中 for (TestData td : list) { bankCards.add(td); } // 这里在每次加载完数据后,将当前页码+1,这样在上拉刷新的onPullUpToRefresh方法中就不需要操作curPage了 curPage++; // showToast("第"+(page+1)+"页数据加载完成"); } else if (actionType == STATE_MORE) { showToast("没有更多数据了"); } else if (actionType == STATE_REFRESH) { showToast("没有数据"); } mPullToRefreshView.onRefreshComplete(); } @Override public void onError(int arg0, String arg1) { showToast("查询失败:" + arg1); mPullToRefreshView.onRefreshComplete(); } }); }
Example 15
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 16
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); } } }); }
Example 17
Source File: Blanknt.java From styT with Apache License 2.0 | 4 votes |
/** * 初始化数据 */ private void query(int page) { BmobQuery<BILIBILI> helpsBmobQuery = new BmobQuery<BILIBILI>(); helpsBmobQuery.setLimit(Constant.NUMBER_PAGER); helpsBmobQuery.order("-createdAt"); // BmobDate date=new BmobDate(new Date(System.currentTimeMillis())); // helpsBmobQuery.addWhereLessThan("createdAt",date); helpsBmobQuery.setSkip(Constant.NUMBER_PAGER * page); helpsBmobQuery.include("user,phontofile"); // helpsBmobQuery.include("phontofile"); helpsBmobQuery.findObjects(new FindListener<BILIBILI>() { @Override public void done(List<BILIBILI> object, BmobException e) { if (e == null) { //mProgressDialog.dismiss(); if (object.size() > 0) { if (refleshType == RefleshType.REFRESH) { numPage = 0; mItemList.clear(); } if (object.size() < Constant.NUMBER_PAGER) { } mItemList.addAll(object); numPage++; adapter.notifyDataSetChanged(); materialRefreshLayout.finishRefresh(); materialRefreshLayout.finishRefreshLoadMore(); } else if (refleshType == RefleshType.REFRESH) { materialRefreshLayout.finishRefresh(); } else if (refleshType == RefleshType.LOAD_MORE) { materialRefreshLayout.finishRefreshLoadMore(); } else { numPage--; } } else { //mProgressDialog.dismiss(); materialRefreshLayout.finishRefresh(); materialRefreshLayout.finishRefreshLoadMore(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog alert = builder.setMessage("未获取到数据,请检查网络数据后重试。") .setNegativeButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .create(); alert.show(); } } }); }
Example 18
Source File: LoginActivity.java From SmartOrnament with Apache License 2.0 | 4 votes |
private void login() { final String name = usrName.getText().toString(); final String password = psd.getText().toString(); if (!name.equals("") && !password.equals("")) { BmobQuery<UserInfo> query = new BmobQuery<UserInfo>(); query.addWhereEqualTo("name", name); query.setLimit(1); //因为用户名不能重复,所以只要查询一个结果 query.findObjects(new FindListener<UserInfo>() { @Override public void done(List<UserInfo> list, BmobException e) { if (e == null) { if (list.get(0).getPsd().equals(password)) { //先别忙着让人跳转到主界面,先得保存一下登录的记录,如是否是记住密码和自动登录,以及用户名和密码 SharedPreferences.Editor editor=prefs.edit(); // if (remember.isChecked()){//选中记住密码就得记录勾选的状态和用户的信息 editor.putBoolean("remeberPsd",true); editor.putString("usr",name).commit(); editor.putString("psd",password); editor.commit(); // } // if (auto.isChecked()){ editor.putBoolean("autoLogin",true).commit(); // } Log.i("Test1111", "云端登录成功"); // Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_SHORT).show(); Intent intent=new Intent(LoginActivity.this,MainActivity.class); startActivity(intent); finish(); } else { Toast.makeText(LoginActivity.this, "用户名与密码不匹配,请检查。", Toast.LENGTH_SHORT).show(); } } else {//下面是查询失败的情况 if (e.getErrorCode() == 9015) { Toast.makeText(LoginActivity.this, "你输入的用户不存在。", Toast.LENGTH_SHORT).show(); } if (e.getErrorCode() == 9016) { Toast.makeText(LoginActivity.this, "网络请求错误,请检查你的网络。", Toast.LENGTH_SHORT).show(); } } } }); }else { Toast.makeText(LoginActivity.this, "用户名或密码不能为空", Toast.LENGTH_SHORT).show(); } }
Example 19
Source File: ChatActivity.java From stynico with MIT License | 4 votes |
private void CheckMessage() { BmobQuery<Content> query = new BmobQuery<Content>(); //查询playerName叫“比目”的数据 query.addWhereEqualTo("room_id", "校园情色"); //返回50条数据,如果不加上这条语句,默认返回10条数据 query.setLimit(120); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date lastDate = sdf.parse(lastCreatedAt); query.addWhereGreaterThan("createdAt", new BmobDate(lastDate)); query.order("createdAt"); } catch (ParseException e) { e.printStackTrace(); } //执行查询方法 query.findObjects(this, new FindListener<Content>() { @Override public void onSuccess(List<Content> object) { mProgressDialog.dismiss(); // TODO Auto-generated method stub for (Content content : object) { //获取上一次最近时间 Content content1=new Content(); content1.setNickname(content.getNickname()); content1.setRoom_id(content.getRoom_id()); content1.setContent(content.getContent()); //content1.setTime(content.getCreatedAt()); //更新最近的接受到的聊天消息的时间 if (lastContent.equals(content.getContent()) && lastCreatedAt.equals(content.getCreatedAt())) { // Toast.makeText(ChatActivity.this,"1",Toast.LENGTH_SHORT).show(); } else if (GetNumberFromString.change(lastCreatedAt) >= GetNumberFromString.change(content.getCreatedAt())) { } else { // Toast.makeText(ChatActivity.this,"12",Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { mMsgs.smoothScrollToPosition(mMsgs.getCount() - 1);//移动到尾部 mMsgs.setSelection(mMsgs.getBottom()); } }, 1000); //保存最近的时间 lastCreatedAt = content.getCreatedAt(); mDatas.add(content1); lastContent = content1.getContent(); } } // adapter.notifyDataSetChanged(); } @Override public void onError(int code, String msg) { // TODO Auto-generated method stub //Toast.makeText(ChatActivity.this, "获取消息失败", Toast.LENGTH_SHORT).show(); } }); }
Example 20
Source File: ReviewContentListFragment.java From AndroidReview with GNU General Public License v3.0 | 4 votes |
private void putToRefreshByContent(final int actionType) { //初始化Bmob查询类 BmobQuery<Content> query = new BmobQuery<>(); query.setLimit(PAGE_LIMIT); if (actionType == REFRESH_TYPE_PULL) { mCurrentPageCount = 0; query.setSkip(0); } else { int currentPageLimit = mAdapter.getCount(); if (currentPageLimit < PAGE_LIMIT) { query.setSkip(currentPageLimit); } else { query.setSkip(PAGE_LIMIT * (mCurrentPageCount + 1)); } } String sql = "select title,small,createdAt from Content where point='"+mPoint.getObjectId()+"' order by updatedAt DESC"; query.doSQLQuery(AppContext.getInstance(), sql, new SQLQueryListener<Content>() { @Override public void done(BmobQueryResult<Content> bmobQueryResult, BmobException e) { if (e == null) { //请求成功 List<Content> list = bmobQueryResult.getResults(); if (actionType == REFRESH_TYPE_PULL) { mContentListAdapter.notifyAdapter(list); //把数据缓存到本地 SaveCacheAsyncTask savecaheTask = new SaveCacheAsyncTask(getContext(), (Serializable) list, CacheHelper.CONTENT_LIST_CACHE_KEY + mPoint.getName()); savecaheTask.execute(); if (list.size() != 0) { mLoadingLayout.setLoadingLayout(LoadingLayout.HIDE_LAYOUT); mPtrFrameLayout.setVisibility(View.VISIBLE); } else { mLoadingLayout.setLoadingLayout(LoadingLayout.NETWORK_REFRESH); mPtrFrameLayout.setVisibility(View.GONE); } //更新UI mPtrFrameLayout.refreshComplete(); } else { //如果目前的数据数量大于等 该知识点的所有内容数量 即视为加载完全部数据。 加上后面的大于条件是为了防止 用户在上啦加载时服务器增加了一条数据而导致上啦加载出现数据错乱 if (mContentListAdapter.getCount() == mContentCount || mContentListAdapter.getCount() > mContentCount) { sPutUpState = PULL_UP_STATE_NOMORE; updateFooterViewStateText(); } else { mContentListAdapter.addData(list); removeFootView(); } } } else { //请求失败 Logger.e(e.getMessage()); if (actionType == REFRESH_TYPE_PULL) { //更新UI toastError(mLoadingLayout, getContext()); } else { sPutUpState = PULL_UP_STATE_EEROR; updateFooterViewStateText(); } } } }); }