public void refreshData(String keyWord) { mSearchedChannelAdapter.clear(); if (isSearchingName || isSearchingInfo || StrUtil.isEmpty(keyWord)) { return; } // 按频道名搜索 isSearchingName = true; BmobQuery<Channel> channelNameQuery = new BmobQuery<Channel>(); channelNameQuery.addWhereContains(Channel.NAME_KEY, keyWord); channelNameQuery.include(Channel.MANAGER_KEY); channelNameQuery.setLimit(10); channelNameQuery.order("-" + Channel.IS_ACTIVE_KEY + ",-" + Constants.UPDATED_AT_KEY); channelNameQuery.findObjects( mContext, new FindListener<Channel>() { @Override public void onSuccess(List<Channel> channels) { mSearchedChannelAdapter.addAll(channels); isSearchingName = false; } @Override public void onError(int arg0, String msg) { ShowToast(getString(R.string.server_query_error_tips) + ": " + msg); isSearchingName = false; } }); // 按频道信息搜索 isSearchingInfo = true; BmobQuery<Channel> channelInfoQuery = new BmobQuery<Channel>(); channelInfoQuery.addWhereContains(Channel.INFO_KEY, keyWord); channelInfoQuery.include(Channel.MANAGER_KEY); channelInfoQuery.setLimit(10); channelInfoQuery.order("-" + Channel.IS_ACTIVE_KEY + ",-" + Constants.UPDATED_AT_KEY); channelInfoQuery.findObjects( mContext, new FindListener<Channel>() { @Override public void onSuccess(List<Channel> channels) { for (Channel channel : channels) { if (!mSearchedChannelAdapter.contains(channel)) { mSearchedChannelAdapter.add(channel); } } isSearchingInfo = false; } @Override public void onError(int arg0, String msg) { ShowToast(getString(R.string.server_query_error_tips) + ": " + msg); isSearchingInfo = false; } }); }
private void initdata() { isLoading = true; MyUser myUser = BmobUser.getCurrentUser(MessageActivity.this, MyUser.class); BmobQuery<ReplyBean> reply = new BmobQuery<>(); reply.setLimit(endpage); reply.order("-createdAt"); reply.addWhereEqualTo("userid", new BmobPointer(myUser)); reply.include("userid,replyid,detailsid"); reply.findObjects( MessageActivity.this, new FindListener<ReplyBean>() { @Override public void onSuccess(List<ReplyBean> list) { replyBeans.clear(); replyBeans.addAll(list); messageAdapter.notifyDataSetChanged(); swipeLayout.setRefreshing(false); isLoading = false; } @Override public void onError(int i, String s) { ErrorReport.RrrorCode(i, MessageActivity.this); swipeLayout.setRefreshing(false); isLoading = false; } }); }
private void getData() { BmobQuery<Message> query = new BmobQuery<Message>(); if (TYPE_CHANNEL.equals(currentitemType)) { query.addWhereEqualTo(CHANNEL_NAME, currentItemName); } else { query.addWhereEqualTo(PUSHER_NAME, currentItemName); } query.addWhereEqualTo("isActivity", false); query.order("-createdAt"); // query.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK); // 先从缓存获取数据,如果没有,再从网络获取。 query.setLimit(50); query.findObjects( AppData.getContext(), new FindListener<Message>() { @Override public void onSuccess(List<Message> list) { if (list.size() != 0) { index_messageList = list; freshListView(); } else { Logger.d("频道无信息"); } endRefreshAnimation(); } @Override public void onError(int i, String s) { // Logger.e("查询失败:" + s); } }); }
private void loadData() { // data.clear(); isLoading = true; BmobQuery<CommunityItem> query = new BmobQuery<CommunityItem>(); // query.addWhereEqualTo("CommunityItem", ""); BmobDate date = new BmobDate(new Date(System.currentTimeMillis())); query.addWhereLessThan("createdAt", date); query.order("-createdAt"); query.include("author"); // 返回50条数据,如果不加上这条语句,默认返回10条数据 query.setLimit(Constant.NUMBERS_PER_PAGE); query.setSkip(Constant.NUMBERS_PER_PAGE * (pageNum++)); // 执行查询方法 query.findObjects( getContext(), new FindListener<CommunityItem>() { @Override public void onSuccess(List<CommunityItem> list) { LogUtil.d(LogUtil.TAG, "onSuccess list size--> " + list.size()); if (list.size() != 0 && list.get(list.size() - 1) != null) { if (isCleared == false) { data.clear(); isCleared = true; } if (list.size() < Constant.NUMBERS_PER_PAGE) { isAllLoaded = true; // ToastUtil.show(getContext(), "已加载完所有数据~"); } data.addAll(list); putImgData(data); mImageLoader.setImgUrls(imgUrls); mImageLoader.setAvatarImgUrls(imgUrlsAvatar); if (BmobUtil.getCurrentUser(getContext()) != null) { data = DatabaseManager.getInstance(getContext()).setFav(data); } communityListAdapter.setData(data); mListView.setOnScrollListener(myScrollListener); } else { isAllLoaded = true; // ToastUtil.show(getContext(), "暂无更多数据~"); if (list.size() == 0 && data.size() == 0) { pageNum--; return; } pageNum--; } swipeView.setRefreshing(false); progressBar.setVisibility(View.GONE); isLoading = false; } @Override public void onError(int code, String msg) { LogUtil.d(LogUtil.TAG, "onError --> msg -->" + msg + " code -->" + code); pageNum--; swipeView.setRefreshing(false); isLoading = false; } }); }
@Override public void initData(Bundle savedInstanceState) { super.initData(savedInstanceState); setPageName("周边"); setActionBarName("周边的小伙伴"); initMap(); gqzBitmap = BitmapHelp.getBitmapUtils(this); user = BmobUser.getCurrentUser(this, BUser.class); if (user != null) { BmobQuery<BUser> bmobQuery = new BmobQuery<BUser>(); bmobQuery.addWhereNear("gpsAdd", user.getGpsAdd()); bmobQuery.setLimit(10); // 获取最接近用户地点的10条数据 bmobQuery.findObjects( this, new FindListener<BUser>() { @Override public void onSuccess(List<BUser> lists) { users = lists; imgs = new ArrayList<RoundedCornerImageView>(); for (int i = 0; i < lists.size(); i++) { RoundedCornerImageView imageView = new RoundedCornerImageView(getBaseContext()); imageView.setLayoutParams(new LayoutParams(80, 80)); gqzBitmap.display(imageView, users.get(i).getUrl_head()); imgs.add(imageView); } MapUtil.startLocation(); } @Override public void onError(int arg0, String arg1) { GQZInject.toast(arg1); } }); } else { map.setMyLocationEnabled(true); // 关闭定位图层 MapUtil.startLocation(); GQZInject.toast("请先登录"); } }
public static long getRecordsFromServer() { updateNum = 0; BmobQuery<CoCoinRecord> query = new BmobQuery<CoCoinRecord>(); query.addWhereEqualTo( "userId", BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class).getObjectId()); query.setLimit(Integer.MAX_VALUE); query.findObjects( CoCoinApplication.getAppContext(), new FindListener<CoCoinRecord>() { @Override public void onSuccess(List<CoCoinRecord> object) { if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d( "CoCoin", "recordManager.getRecordsFromServer get " + object.size() + " records from server"); } updateNum = object.size(); for (CoCoinRecord coCoinRecord : object) { boolean exist = false; for (int i = RECORDS.size() - 1; i >= 0; i--) { if (coCoinRecord.getObjectId().equals(RECORDS.get(i).getLocalObjectId())) { exist = true; break; } } if (!exist) { CoCoinRecord newCoCoinRecord = new CoCoinRecord(); newCoCoinRecord.set(coCoinRecord); newCoCoinRecord.setId(-1); RECORDS.add(newCoCoinRecord); } } Collections.sort( RECORDS, new Comparator<CoCoinRecord>() { @Override public int compare(CoCoinRecord lhs, CoCoinRecord rhs) { if (lhs.getCalendar().before(rhs.getCalendar())) { return -1; } else if (lhs.getCalendar().after(rhs.getCalendar())) { return 1; } else { return 0; } } }); db.deleteAllRecords(); SUM = 0; for (int i = 0; i < RECORDS.size(); i++) { RECORDS.get(i).setLocalObjectId(RECORDS.get(i).getObjectId()); RECORDS.get(i).setIsUploaded(true); db.saveRecord(RECORDS.get(i)); SUM += (int) RECORDS.get(i).getMoney(); } if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d( "CoCoin", "recordManager.getRecordsFromServer save " + RECORDS.size() + " records"); } } @Override public void onError(int code, String msg) { if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d("CoCoin", "recordManager.getRecordsFromServer error " + msg); } } }); return updateNum; }