Ejemplo n.º 1
0
  /**
   * 添加路线
   *
   * @param route 路线
   * @param listener 回调
   */
  public void addRoute(final Route route, final OnRouteListener listener) {
    BmobQuery<Route> query1 = new BmobQuery<>();
    query1.addWhereEqualTo("name", route.getName());
    BmobQuery<Route> query2 = new BmobQuery<>();
    query2.addWhereEqualTo("creator", UserManager.getInstance(mContext).getUser());
    List<BmobQuery<Route>> andQuerys = new ArrayList<>();
    andQuerys.add(query1);
    andQuerys.add(query2);

    BmobQuery<Route> mainQuery = new BmobQuery<>();
    mainQuery.and(andQuerys);
    mainQuery.findObjects(
        mContext,
        new FindListener<Route>() {
          @Override
          public void onSuccess(List<Route> list) {
            if (list.size() > 0) {
              listener.onError(null);
            } else {
              saveRoute(route, listener);
            }
          }

          @Override
          public void onError(int i, String s) {
            listener.onError(null);
          }
        });
  }
  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);
          }
        });
  }
Ejemplo n.º 3
0
  private void querydata() {
    BmobQuery<NewsdalyComment> query = new BmobQuery<NewsdalyComment>();
    DalyNews dalyNews = new DalyNews();
    String i = getIntent().getStringExtra("id");
    dalyNews.setObjectId(i);
    query.addWhereEqualTo("dalyNews", new BmobPointer(dalyNews));
    query.findObjects(
        this,
        new FindListener<NewsdalyComment>() {

          @Override
          public void onSuccess(List<NewsdalyComment> object) {
            // TODO Auto-generated method stub
            for (NewsdalyComment content : object) {
              String c = content.getComment();
              String name = content.getCommentname();
              TextView tx = new TextView(NewsDaylyActivity.this);
              tx.setTextSize(15);
              tx.setText("用户:" + name + "\n" + c);
              layout_content.addView(tx);
            }
          }

          @Override
          public void onError(int arg0, String arg1) {
            // TODO Auto-generated method stub
            Toast.makeText(NewsDaylyActivity.this, "服务器暂未响应!", Toast.LENGTH_SHORT).show();
          }
        });
  }
Ejemplo n.º 4
0
  private void loaddate() {
    isLoading = true;
    MyUser myUser = BmobUser.getCurrentUser(MessageActivity.this, MyUser.class);
    BmobQuery<ReplyBean> Query = new BmobQuery<ReplyBean>();
    Query.order("-createdAt");
    Query.setSkip(page);
    Query.addWhereEqualTo("userid", new BmobPointer(myUser));
    Query.include("userid,replyid,detailsid");
    Query.findObjects(
        MessageActivity.this,
        new FindListener<ReplyBean>() {
          @Override
          public void onSuccess(List<ReplyBean> object) {
            replyBeans.addAll(object);
            if (object.size() == endpage) {
              page = page + endpage;
            } else {
              flag = false;
            }
            messageAdapter.notifyDataSetChanged();
            isLoading = false;
          }

          @Override
          public void onError(int code, String msg) {
            // TODO Auto-generated method stub
            ErrorReport.RrrorCode(code, MessageActivity.this);
            isLoading = false;
          }
        });
  }
Ejemplo n.º 5
0
  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;
          }
        });
  }
Ejemplo n.º 6
0
  // 查询符合时间和用户id条件的记录
  public void getData(
      int year_c, int month_c, int jumpYear, int jumpMonth, final Handler handler, String id) {

    String dateString =
        String.valueOf(year_c + jumpYear)
            .concat("-")
            .concat(String.valueOf(month_c + jumpMonth))
            .concat("-")
            .concat("31");
    String dateString2 =
        String.valueOf(year_c + jumpYear)
            .concat("-")
            .concat(String.valueOf(month_c + jumpMonth))
            .concat("-")
            .concat("01");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date1 = null;
    Date date2 = null;
    try {
      date1 = sdf.parse(dateString);
      date2 = sdf.parse(dateString2);
    } catch (ParseException e) {
    }

    BmobQuery<Sign> my_sign = new BmobQuery<Sign>();
    my_sign.addWhereLessThanOrEqualTo("createdAt", new BmobDate(date1));

    BmobQuery<Sign> my_sign2 = new BmobQuery<Sign>();
    my_sign2.addWhereGreaterThanOrEqualTo("createdAt", new BmobDate(date2));

    BmobQuery<Sign> my_sign3 = new BmobQuery<Sign>();
    my_sign3.addWhereEqualTo("user_id", id);

    List<BmobQuery<Sign>> andQuerys = new ArrayList<BmobQuery<Sign>>();
    andQuerys.add(my_sign);
    andQuerys.add(my_sign2);
    andQuerys.add(my_sign3);

    BmobQuery<Sign> sign = new BmobQuery<Sign>();
    sign.and(andQuerys);
    sign.findObjects(
        this.mContext,
        new FindListener<Sign>() {
          @Override
          public void onSuccess(List<Sign> list) {

            Message message = handler.obtainMessage();
            message.what = 1;
            message.obj = list;
            handler.sendMessage(message);
          }

          @Override
          public void onError(int i, String s) {}
        });
  }
Ejemplo n.º 7
0
  /**
   * 复制景点
   *
   * @param myDailys 日程列表
   * @param dailys 日程列表
   * @param current 当前位置
   * @param listener 回调
   */
  private void copySight(
      final List<Daily> myDailys,
      final List<Daily> dailys,
      final int current,
      final OnRouteListener listener) {
    BmobQuery<Sight> query = new BmobQuery<>();
    query.addWhereEqualTo("daily", new BmobPointer(dailys.get(current)));
    query.order("index");
    query.findObjects(
        mContext,
        new FindListener<Sight>() {
          @Override
          public void onSuccess(List<Sight> list) {
            List<BmobObject> sights = new ArrayList<>();
            Sight sight;
            for (int i = 0; i < list.size(); i++) {
              sight = new Sight();
              sight.setDaily(myDailys.get(current));
              sight.setName(list.get(i).getName());
              sight.setAddress(list.get(i).getAddress());
              sight.setLongitude(list.get(i).getLongitude());
              sight.setLatitude(list.get(i).getLatitude());
              sight.setDetailUrl(list.get(i).getDetailUrl());
              sight.setUid(list.get(i).getUid());
              sight.setIndex(list.get(i).getIndex());
              sights.add(sight);
            }
            new BmobObject()
                .insertBatch(
                    mContext,
                    sights,
                    new SaveListener() {
                      @Override
                      public void onSuccess() {}

                      @Override
                      public void onFailure(int i, String s) {}
                    });
            if (current + 1 != myDailys.size()) {
              copySight(myDailys, dailys, current + 1, listener);
            } else {
              listener.onSuccess(null);
            }
          }

          @Override
          public void onError(int i, String s) {
            listener.onError(s);
          }
        });
  }
  private void initData() {
    BmobQuery<Transaction> query = new BmobQuery<Transaction>();
    query.addWhereEqualTo("hasdeal", false);
    query.findObjects(
        this,
        new FindListener<Transaction>() {
          @Override
          public void onSuccess(List<Transaction> list) {
            updateView(list);
          }

          @Override
          public void onError(int i, String s) {
            Toast.makeText(NewTransactionActivity.this, s.toString(), Toast.LENGTH_SHORT).show();
          }
        });
  }
  /** 根据用户名查询用户的其他信息 */
  void queryUserInfomation() {
    queryUser = new BmobQuery<>();
    query.addWhereEqualTo("username", MyApplication.getCurrentName());
    queryUser.findObjects(
        view.getContext(),
        new FindListener<User>() {
          @Override
          public void onSuccess(List<User> list) {
            headPictureUrl = list.get(0).getPicture().getFileUrl(view.getContext());

            new LoadUserTask().execute();
          }

          @Override
          public void onError(int i, String s) {}
        });
  }
  /** 判断记录是否为空并且查询数据 */
  void judgeAndquery() {
    query = new BmobQuery<DemandObject>();
    al = new ArrayList<>();
    query.addWhereEqualTo("publishMan", MyApplication.getCurrentName());
    query.count(
        view.getContext(),
        DemandObject.class,
        new CountListener() {
          @Override
          public void onSuccess(int i) {
            if (i > 0) {
              querydata();
            } else {
              progressDialog.dismiss();
              Toast.makeText(view.getContext(), "你还没有捐赠物品,赶紧去捐赠物品吧☺", Toast.LENGTH_LONG).show();
              swipeLayout.setRefreshing(false);
            }
          }

          @Override
          public void onFailure(int i, String s) {}
        });
  }
Ejemplo n.º 11
0
  @Override
  public void onBindViewHolder(final MyViewHolder viewHolder, int position) {
    post = list.get(position);
    iv_avator = (ImageView) viewHolder.getView(R.id.iv_avator);
    TextView tv_author = (TextView) viewHolder.getView(R.id.tv_author);
    TextView tv_time = (TextView) viewHolder.getView(R.id.tv_time);
    TextView tv_content = (TextView) viewHolder.getView(R.id.tv_content);
    tv_praise = (TextView) viewHolder.getView(R.id.tv_praise);
    tv_reply = (TextView) viewHolder.getView(R.id.tv_reply);

    btn_praise = (Button) viewHolder.getView(R.id.btn_praise);
    btn_share = (Button) viewHolder.getView(R.id.btn_share);
    btn_reply = (Button) viewHolder.getView(R.id.btn_reply);

    ll_praise = (LinearLayout) viewHolder.getView(R.id.ll_praise);
    ll_share = (LinearLayout) viewHolder.getView(R.id.ll_share);

    iv_sex = (ImageView) viewHolder.getView(R.id.iv_sex);

    if (post.getAuthor().getSex().equals("男")) {
      iv_sex.setImageResource(R.drawable.blue_male);
    } else {
      iv_sex.setImageResource(R.drawable.red_female);
    }
    tv_praise.setTag(position);
    tv_praise.setText("赞");
    if (post.getPraiseCount() == 0) {
      tv_praise.setText("赞");
    } else {
      tv_praise.setText(post.getPraiseCount() + "");
    }
    tv_reply.setText("评论");
    BmobQuery<Reply> query = new BmobQuery<Reply>();
    query.addWhereEqualTo("post", post);
    query.count(
        context,
        Reply.class,
        new CountListener() {
          @Override
          public void onSuccess(int i) {
            if (i != 0) {
              tv_reply.setText(i + "");
            }
          }

          @Override
          public void onFailure(int i, String s) {}
        });

    iv_avator.setOnClickListener(this);
    iv_avator.setTag(position);

    ll_praise.setOnClickListener(this);
    ll_praise.setTag(position);
    ll_share.setOnClickListener(this);
    ll_share.setTag(position);

    if (post.getIsPraise()) {
      btn_praise.setBackgroundResource(R.drawable.praise_press);
    } else {
      btn_praise.setBackgroundResource(R.drawable.praise_normal);
    }

    String avatar = post.getAvator();
    if (avatar != null && !avatar.equals("")) {
      ImageLoader.getInstance().displayImage(avatar, iv_avator, ImageLoadOptions.getOptions());
    } else {
      if (post.getAuthor().getSex().equals("男")) {
        iv_avator.setImageResource(R.mipmap.male_default_icon);
      } else {
        iv_avator.setImageResource(R.mipmap.female_default_icon);
      }
    }
    // 设置时间
    long time = TimeUtil.stringToLong(post.getCreatedAt(), "yyyy-MM-dd HH:mm:ss");
    tv_time.setText(TimeUtil.getDescriptionTimeFromTimestamp(time));
    // 设置用户名
    tv_author.setText(post.getAuthor().getNick());
    // 设置文字内容
    SpannableString spannableString = FaceTextUtil.toSpannableString(context, post.getContent());
    tv_content.setText(spannableString);
    tv_content.setVisibility(View.VISIBLE);
    final List<String> imagesUrl = post.getImages();
    iv_content = (ImageView) viewHolder.getView(R.id.iv_content);
    if (imagesUrl != null && imagesUrl.size() > 0) {
      // 只取出第一张图片
      String url = imagesUrl.get(0);
      iv_content.setVisibility(View.VISIBLE);
      ImageLoader.getInstance().displayImage(url, iv_content, ImageLoadOptions.getOptions());

    } else {
      // layout_content.setVisibility(View.GONE);
      iv_content.setVisibility(View.GONE);
    }
    iv_content.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent intent = new Intent(context, ImageBrowserActivity.class);
            ArrayList<String> photos = new ArrayList<String>();
            photos.add(imagesUrl.get(0));
            intent.putStringArrayListExtra("photos", photos);
            intent.putExtra("position", 0);
            context.startActivity(intent);
          }
        });
    // 如果设置了回调,则设置点击事件
    if (mOnItemClickLitener != null) {
      view.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              int pos = viewHolder.getLayoutPosition();
              mOnItemClickLitener.onItemClick(view, pos);
            }
          });

      view.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              int pos = viewHolder.getLayoutPosition();
              mOnItemClickLitener.onItemLongClick(view, pos);
              return false;
            }
          });
    }
  }
Ejemplo n.º 12
0
  @Override
  public View bindView(int arg0, View convertView, ViewGroup arg2) {
    // TODO Auto-generated method stub
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.item_answer_in_list_elinc, null);
    }
    final Answer contract = getList().get(arg0);
    final Integer[] like_number = new Integer[1];
    final TextView answer_number = ViewHolder.get(convertView, R.id.answer_number);

    TextView answer_content = ViewHolder.get(convertView, R.id.answer_content);
    TextView answer_date = ViewHolder.get(convertView, R.id.answer_date);
    final TextView answer_responder = ViewHolder.get(convertView, R.id.answer_responder);
    CircleImageView avatar_for_responder = ViewHolder.get(convertView, R.id.avatar_for_responder);
    ImageView avatar_for_answer_iv = ViewHolder.get(convertView, R.id.avatar_for_answer_iv);
    answer_content.setText(contract.getAnswerContent());
    answer_responder.setText(contract.getResponder().getUsername());
    answer_date.setText(Tool.showdate(contract.getCreatedAt()));
    String avatar = contract.getResponder().getAvatar();
    final ImageView like_answer;
    like_answer = ViewHolder.get(convertView, R.id.like_answer);
    refreshNumber(contract, answer_number, R.drawable.no_like, like_answer);

    // 初始化点赞按钮
    BmobQuery<User> query1 = new BmobQuery<User>();
    BmobQuery<User> query2 = new BmobQuery<User>();
    Answer ans = new Answer();
    ans.setObjectId(contract.getObjectId());
    User u = BmobUser.getCurrentUser(context, User.class);
    query1.addWhereEqualTo("objectId", u.getObjectId());
    query2.addWhereRelatedTo("likedBy", new BmobPointer(ans));
    List<BmobQuery<User>> queries = new ArrayList<BmobQuery<User>>();
    queries.add(query1);
    queries.add(query2);
    BmobQuery<User> mainQuery = new BmobQuery<User>();
    mainQuery.and(queries);
    mainQuery.count(
        context,
        User.class,
        new CountListener() {
          @Override
          public void onSuccess(int count) {
            if (count > 0) {

              refreshNumber(contract, answer_number, R.drawable.like, like_answer);
              like_answer.setBackgroundResource(R.drawable.like);
              Log.i("life", "多对多关联添加成功");
            } else {
              /*还没有点赞*/
              refreshNumber(contract, answer_number, R.drawable.no_like, like_answer);
              // ShowToast("点赞成功");
              like_answer.setBackgroundResource(R.drawable.no_like);
            }
          }

          @Override
          public void onFailure(int code, String msg) {
            // TODO Auto-generated method stub
            // ShowToast("count failure:"+msg);
            ShowToast("亲,断网了呢");
          }
        });

    like_answer.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            BmobQuery<User> query1 = new BmobQuery<User>();
            BmobQuery<User> query2 = new BmobQuery<User>();
            Answer ans = new Answer();
            ans.setObjectId(contract.getObjectId());
            User u = BmobUser.getCurrentUser(context, User.class);
            query1.addWhereEqualTo("objectId", u.getObjectId());
            query2.addWhereRelatedTo("likedBy", new BmobPointer(ans));
            List<BmobQuery<User>> queries = new ArrayList<BmobQuery<User>>();
            queries.add(query1);
            queries.add(query2);
            BmobQuery<User> mainQuery = new BmobQuery<User>();
            mainQuery.and(queries);
            mainQuery.count(
                context,
                User.class,
                new CountListener() {
                  @Override
                  public void onSuccess(int count) {
                    if (count > 0) {
                      /*如果已经点赞了*/
                      User user = BmobUser.getCurrentUser(context, User.class);
                      Answer ans = new Answer();
                      ans.setObjectId(contract.getObjectId());
                      BmobRelation relation = new BmobRelation();
                      relation.remove(user);
                      ans.setLikedBy(relation);
                      ans.update(
                          context,
                          new UpdateListener() {
                            @Override
                            public void onSuccess() {
                              // TODO Auto-generated method stub
                              refreshNumber(
                                  contract, answer_number, R.drawable.no_like, like_answer);
                              Log.i("life", "多对多关联添加成功");
                            }

                            @Override
                            public void onFailure(int arg0, String arg1) {
                              // TODO Auto-generated method stub
                              ShowToast("亲,怎么没网了呢");
                              Log.i("life", "多对多关联添加失败");
                            }
                          });
                    } else {
                      /*还没有点赞*/
                      User user = BmobUser.getCurrentUser(context, User.class);
                      Answer ans = new Answer();
                      ans.setObjectId(contract.getObjectId());
                      BmobRelation relation = new BmobRelation();
                      relation.add(user);
                      ans.setLikedBy(relation);
                      ans.update(
                          context,
                          new UpdateListener() {
                            @Override
                            public void onSuccess() {
                              // TODO Auto-generated method stub
                              refreshNumber(contract, answer_number, R.drawable.like, like_answer);
                              // ShowToast("点赞成功");
                              Log.i("life", "多对多关联添加成功");
                            }

                            @Override
                            public void onFailure(int arg0, String arg1) {
                              // TODO Auto-generated method stub
                              ShowToast("亲,怎么没网了呢");
                              Log.i("life", "多对多关联添加失败");
                            }
                          });
                    }
                  }

                  @Override
                  public void onFailure(int code, String msg) {
                    // TODO Auto-generated method stub
                    // ShowToast("count failure:"+msg);
                    ShowToast("亲,断网了呢");
                  }
                });
          }
        });

    // =======================================================================
    if (avatar != null && !avatar.equals("")) { // 加载头像-为了不每次都加载头像
      ImageLoader.getInstance()
          .displayImage(
              avatar, avatar_for_responder, ImageLoadOptions.getOptions(), animateFirstListener);
    } else {
      avatar_for_responder.setImageResource(R.drawable.head);
    }

    final String answeravatar = contract.getAnswerAvatar();
    if (answeravatar != null && !answeravatar.equals("")) { // 加载头像-为了不每次都加载头像
      ImageLoader.getInstance()
          .displayImage(
              answeravatar,
              avatar_for_answer_iv,
              ImageLoadOptions.getOptions(),
              animateFirstListener);
      avatar_for_answer_iv.setVisibility(View.VISIBLE);
    }
    avatar_for_answer_iv.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(context, ImageBrowserActivity.class);
            ArrayList<String> photos = new ArrayList<String>();
            photos.add(answeravatar);
            intent.putStringArrayListExtra("photos", photos);
            intent.putExtra("position", 0);
            context.startActivity(intent);
          }
        });
    answer_responder.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            User u = BmobUser.getCurrentUser(context, User.class);
            bundle.putString("username", answer_responder.getText().toString());
            if (answer_responder.getText().toString().equals(u.getUsername().toString())) {
              bundle.putString("from", "me");
            } else {
              bundle.putString("from", "add");
            }
            intent.putExtras(bundle);
            intent.setClass(context, SetMyInfoActivity.class);
            context.startActivity(intent);
          }
        });

    avatar_for_responder.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            User u = BmobUser.getCurrentUser(context, User.class);
            bundle.putString("username", answer_responder.getText().toString());
            if (answer_responder.getText().toString().equals(u.getUsername().toString())) {
              bundle.putString("from", "me");
            } else {
              bundle.putString("from", "add");
            }
            intent.putExtras(bundle);
            intent.setClass(context, SetMyInfoActivity.class);
            context.startActivity(intent);
          }
        });
    return convertView;
  }
  /**
   * 获取网络数据
   *
   * @param flag 0 获取组名 ,1 获取联系人 ,2 更新整张表
   */
  private void networkDatabase(final int flag) {

    Log.i("开始获取好友数据3", "" + currentUser);
    BmobQuery<Contacts> query = new BmobQuery<Contacts>();
    query.addWhereEqualTo("userId", currentUser);
    final ContactPerson cp = new ContactPerson();
    final DBAccess ac = new DBAccess(getActivity());
    query.findObjects(
        getActivity(),
        new FindListener<Contacts>() {

          @Override
          public void onError(int arg0, String arg1) {
            adapter = new PrivateManagerDbAdater(getActivity(), null, null);
            expandableListView.setAdapter(adapter);
          }

          @Override
          public void onSuccess(List<Contacts> c) {
            if (c.size() > 0) {
              for (Contacts cs : c) {
                if (flag == 0) {
                  if (cs.getPrivateGroup() != null) {
                    ArrayList = cs.getPrivateGroup();
                    ac.updateTable3Single(
                        currentUser, ConstantValue.DB_MetaData3.PRIVATE_GROUP, cp.getClientGroup());
                  }

                } else if (flag == 1) {

                  if (cs.getPrivateFriend() != null) {
                    list = cs.getPrivateFriend();
                    ac.updateTable3Single(
                        currentUser,
                        ConstantValue.DB_MetaData3.PRIVATE_FRIEND,
                        cp.getPrivateFriend());
                  }
                } else {
                  ArrayList = cs.getPrivateGroup();
                  list = cs.getPrivateFriend();
                  cp.setObjectIds(cs.getObjectId());
                  cp.setUserId(cs.getUserId());
                  try {
                    cp.setClientGroups(cs.getClientGroup());
                    cp.setClientFriends(cs.getClientFriend());
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }
                Log.i("网络好友数据", "" + cs.getPrivateGroup() + cs.getPrivateFriend() + "/" + flag);
              }
              adapter = new PrivateManagerDbAdater(getActivity(), ArrayList, list);
              expandableListView.setAdapter(adapter);

              // 将网络获取的好友列表添加到本地
              try {
                cp.setPrivateGroups(ArrayList);
                cp.setPrivateFriends(list);
              } catch (IOException e) {
                e.printStackTrace();
              }
              if (flag == 2) {
                ac.insertTable3(cp);
              }
            }
          }
        });
  }
Ejemplo n.º 14
0
  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;
  }
Ejemplo n.º 15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    username = Preference.getString("username");
    password = Preference.getString("password");

    if (BmobUser.getCurrentUser(this) != null) {
      BmobQuery<UserInfo> query = new BmobQuery<UserInfo>();
      query.addWhereEqualTo("userId", BmobUser.getCurrentUser(this).getObjectId());
      query.findObjects(
          this,
          new FindListener<UserInfo>() {
            @Override
            public void onSuccess(List<UserInfo> object) {
              if (object != null && object.size() > 0) {
                Log.e("查询到用户信息数据");
                ImageApp.getInstance().setUserinfo(object.get(0));
                launch(Main_new.class);
                finish();
              }
            }

            @Override
            public void onError(int code, String msg) {
              Log.e("BmobUser.getCurrentUser(this)不为空,但是查询用户信息数据失败后进入主页面");
              new Handler()
                  .postDelayed(
                      new Runnable() {
                        @Override
                        public void run() {
                          launch(Main_new.class);
                          finish();
                        }
                      },
                      2000);
            }
          });
    } else {
      if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) {
        final BmobUser user = new BmobUser();
        user.setUsername(username);
        user.setPassword(password);
        user.login(
            this,
            new SaveListener() {
              @Override
              public void onSuccess() {
                Log.e("登录成功");
                BmobUser bmobuser = BmobUser.getCurrentUser(SplashActivity.this);
                if (bmobuser != null) {
                  BmobQuery<UserInfo> query = new BmobQuery<UserInfo>();
                  query.addWhereEqualTo("userId", user.getObjectId());
                  query.findObjects(
                      SplashActivity.this,
                      new FindListener<UserInfo>() {
                        @Override
                        public void onSuccess(List<UserInfo> object) {
                          if (object != null && object.size() > 0) {
                            Log.e("登录成功后,查询到用户信息数据");
                            ImageApp.getInstance().setUserinfo(object.get(0));
                            launch(Main_new.class);
                            finish();
                          }
                        }

                        @Override
                        public void onError(int code, String msg) {
                          Log.e("登录成功,获取用户信息失败后进入主界面");
                          launch(Main_new.class);
                          finish();
                        }
                      });
                }
              }

              @Override
              public void onFailure(int arg0, String arg1) {
                Log.e("登录失败后进入主界面");
                new Handler()
                    .postDelayed(
                        new Runnable() {
                          @Override
                          public void run() {
                            launch(Main_new.class);
                            finish();
                          }
                        },
                        2000);
              }
            });
      } else {
        Log.e("没有username和password的用户直接进入主页");
        new Handler()
            .postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    launch(Main_new.class);
                    finish();
                  }
                },
                2000);
      }
    }
  }