Search in sources :

Example 11 with FindListener

use of cn.bmob.v3.listener.FindListener in project expression by happy-yuxuan.

the class UMyOrdersActivity method dealResult.

private void dealResult() {
    L.i("da_phone = " + tv_phone.getText().toString());
    L.i("addr = " + tv_addr.getText().toString());
    List<BmobQuery<UserDqInfomation>> queries = new ArrayList<BmobQuery<UserDqInfomation>>();
    BmobQuery<UserDqInfomation> q1 = new BmobQuery<UserDqInfomation>();
    q1.addWhereEqualTo("dq_phone", tv_phone.getText().toString());
    BmobQuery<UserDqInfomation> q2 = new BmobQuery<UserDqInfomation>();
    q2.addWhereEqualTo("addr", tv_addr.getText().toString());
    BmobQuery<UserDqInfomation> q3 = new BmobQuery<UserDqInfomation>();
    BmobUser user = MyUser.getCurrentUser();
    String username = user.getUsername();
    q3.addWhereEqualTo("username", username);
    queries.add(q1);
    queries.add(q2);
    queries.add(q3);
    // 找到objId
    BmobQuery<UserDqInfomation> query = new BmobQuery<UserDqInfomation>();
    query.and(queries);
    // 执行查询方法 获得 objId
    query.findObjects(new FindListener<UserDqInfomation>() {

        @Override
        public void done(List<UserDqInfomation> object, BmobException e) {
            if (e == null) {
                UserDqInfomation udi = new UserDqInfomation();
                udi.setSuccess(true);
                // 执行更新方法
                udi.update(object.get(0).getObjectId(), new UpdateListener() {

                    @Override
                    public void done(BmobException e) {
                        if (e == null) {
                            L.i(" success 更新成功");
                            displayList.dismiss();
                            queryData();
                            Toast.makeText(UMyOrdersActivity.this, "代取成功,我们将一直为您服务", Toast.LENGTH_SHORT).show();
                        } else {
                            L.i("bmob 更新失败:" + e.getMessage() + "," + e.getErrorCode());
                            Toast.makeText(UMyOrdersActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            } else {
                L.i("query dq_phone at UMyOrderActivity 失败:" + e.getMessage() + "," + e.getErrorCode());
                Toast.makeText(UMyOrdersActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) UserDqInfomation(com.yuxuan.admin.expression.entity.UserDqInfomation) BmobQuery(cn.bmob.v3.BmobQuery) BmobUser(cn.bmob.v3.BmobUser) ArrayList(java.util.ArrayList) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 12 with FindListener

use of cn.bmob.v3.listener.FindListener in project expression by happy-yuxuan.

the class UMyPaiJianActivity method initData.

// 从bmob获取数据
private void initData() {
    dialog.show();
    // 查询所有下单代取的用户
    BmobQuery<UserDqInfomation> query = new BmobQuery<UserDqInfomation>();
    query.addWhereEqualTo("success", false);
    query.findObjects(new FindListener<UserDqInfomation>() {

        @Override
        public void done(List<UserDqInfomation> object, BmobException e) {
            if (e == null) {
                L.i("queryAllData = " + object.size());
                for (final UserDqInfomation u : object) {
                    String dq_phone = u.getDq_phone();
                    // 查询当前用户需要派送的用户
                    BmobQuery<MyUser> q = new BmobQuery<MyUser>();
                    q.addWhereEqualTo("mobilePhoneNumber", dq_phone);
                    q.findObjects(new FindListener<MyUser>() {

                        @Override
                        public void done(List<MyUser> object, BmobException e) {
                            dialog.dismiss();
                            if (e == null) {
                                MyOrdersData buffer;
                                String sendUsername = object.get(0).getUsername();
                                String username = BmobUser.getCurrentUser().getUsername();
                                L.i(username + "--" + sendUsername);
                                if (sendUsername.equals(username)) {
                                    String rusername = u.getUsername();
                                    String addr = u.getAddr();
                                    String phone = u.getPhone();
                                    String status = u.getStatus();
                                    String other = u.getOther();
                                    buffer = new MyOrdersData();
                                    buffer.setUsername(rusername);
                                    buffer.setAddr(addr);
                                    buffer.setPhoneNumber(phone);
                                    buffer.setOther(other);
                                    buffer.setStatus(status);
                                    data.add(buffer);
                                    hander.sendEmptyMessage(StaticClass.LOAD_DATA_OK);
                                }
                            } else {
                                L.i("querDqUsername fail:" + e.getMessage());
                                hander.sendEmptyMessage(StaticClass.LOAD_DATA_FAIL);
                                Toast.makeText(UMyPaiJianActivity.this, "加载数据失败", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            } else {
                L.i("queryteamFlag fail:" + e.getMessage());
                hander.sendEmptyMessage(StaticClass.LOAD_DATA_FAIL);
                Toast.makeText(UMyPaiJianActivity.this, "加载数据失败", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : MyUser(com.yuxuan.admin.expression.entity.MyUser) BmobException(cn.bmob.v3.exception.BmobException) UserDqInfomation(com.yuxuan.admin.expression.entity.UserDqInfomation) MyOrdersData(com.yuxuan.admin.expression.entity.MyOrdersData) FindListener(cn.bmob.v3.listener.FindListener) BmobQuery(cn.bmob.v3.BmobQuery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with FindListener

use of cn.bmob.v3.listener.FindListener in project SmartCampus by Vegen.

the class LostAndFoundPresenter method getLostList.

@Override
public void getLostList(int SKIP, int skip) {
    BmobQuery<Lost> query = new BmobQuery<Lost>();
    // query.setCachePolicy(BmobQuery.CachePolicy.CACHE_THEN_NETWORK);   // 先从缓存获取数据,如果没有,再从网络获取。
    // 按照时间降序
    query.order("-createdAt");
    // 每次加载条数
    query.setLimit(SKIP);
    // 偏移量
    query.setSkip(skip);
    Subscription subscription = query.findObjects(new FindListener<Lost>() {

        @Override
        public void done(List<Lost> list, BmobException e) {
            if (mView != null) {
                if (e == null) {
                    // 请求成功
                    mView.showLostList(list);
                    mView.hideLoading(false);
                    if (list == null || list.isEmpty()) {
                        mView.loadMoreEnd(true);
                    }
                } else {
                    mView.showMessage(HttpError.getErrorMessage(e));
                    mView.hideLoading(true);
                    mView.loadMoreFail();
                }
            }
        }
    });
    mHttpLinkers.add(new SubscriptionHolder(subscription));
}
Also used : Lost(com.itculturalfestival.smartcampus.entity.db.Lost) BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) SubscriptionHolder(com.itculturalfestival.smartcampus.network.SubscriptionHolder) Subscription(rx.Subscription)

Example 14 with FindListener

use of cn.bmob.v3.listener.FindListener in project CoCoin by Nightonke.

the class AccountBookListViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
                bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                    @Override
                    public void onSuccess(List<Logo> object) {
                        // there has been an old logo in the server/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                            @Override
                            public void onCompleted(Exception e, File file) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 15 with FindListener

use of cn.bmob.v3.listener.FindListener in project CoCoin by Nightonke.

the class AccountBookMonthViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
                bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                    @Override
                    public void onSuccess(List<Logo> object) {
                        // there has been an old logo in the server/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                            @Override
                            public void onCompleted(Exception e, File file) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : User(com.nightonke.saver.model.User) BmobUser(cn.bmob.v3.BmobUser) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Aggregations

BmobQuery (cn.bmob.v3.BmobQuery)23 BmobException (cn.bmob.v3.exception.BmobException)16 BmobUser (cn.bmob.v3.BmobUser)12 User (com.nightonke.saver.model.User)8 File (java.io.File)8 Logo (com.nightonke.saver.model.Logo)7 Bitmap (android.graphics.Bitmap)6 FutureCallback (com.koushikdutta.async.future.FutureCallback)6 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 List (java.util.List)6 BmobFile (cn.bmob.v3.datatype.BmobFile)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 UpdateListener (cn.bmob.v3.listener.UpdateListener)3 UserDqInfomation (com.yuxuan.admin.expression.entity.UserDqInfomation)3 SaveListener (cn.bmob.v3.listener.SaveListener)2 TalentDao (cn.nicolite.palm300heroes.db.dao.TalentDao)2 Talent (cn.nicolite.palm300heroes.model.bean.Talent)2 BmobProFile (com.bmob.BmobProFile)2