com.avos.avoscloud.FindCallback Java Examples

The following examples show how to use com.avos.avoscloud.FindCallback. 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: SocialPlatform.java    From AnimeTaste with MIT License 6 votes vote down vote up
@Override
public void onComplete(final Platform platform, int action,
		HashMap<String, Object> res) {

	AVQuery<AVObject> query = new AVQuery<AVObject>("Users");
	query.whereEqualTo("platform", platform.getName());
	query.whereEqualTo("uid", platform.getDb().getUserId());
	query.setLimit(1);
	query.findInBackground(new FindCallback<AVObject>() {
		@Override
		public void done(List<AVObject> objects, AVException e) {
			if (e == null) {
				if (objects.size() > 0) {
					saveInformation(platform, true, objects.get(0));
				} else {
					saveInformation(platform, false, null);
				}
			} else {
				mHandler.sendEmptyMessage(AUTH_SAVE_FAILED);
			}
		}
	});

}
 
Example #2
Source File: AboutAppActivity.java    From AnyTime with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_about_app);
	this.getActionBar().setDisplayHomeAsUpEnabled(true);
	submitButton = (Button) findViewById(R.id.button_about_app_submit_user_input);
	submitEditText = (EditText) findViewById(R.id.editText_about_app_user_input);
	mUserResponseListView = (ListView) findViewById(R.id.listView_user_back);
	submitButton.setOnClickListener(buttonListener);

   FindCallback<AVObject> findCallback=new FindCallback<AVObject>() {
     public void done(List<AVObject> avObjects, AVException e) {
       if (e == null) {
         Message msg = new Message();
         msg.what = 3;
         msg.obj = avObjects;
         mHandler.sendMessage(msg);
       } else {
         showError(activity.getString(R.string.network_error));
       }
     }
   };
	AVQuery<AVObject> query = new AVQuery<AVObject>("SuggestionByUser");
	query.whereEqualTo("UserObjectId", getUserId());
	query.findInBackground(findCallback);
}
 
Example #3
Source File: DoingListFragment.java    From AnyTime with Apache License 2.0 6 votes vote down vote up
private void SetChildrenList(final String groupObjectId) {
   FindCallback<AVObject> findCallback=new FindCallback<AVObject>() {
     @Override
     public void done(List<AVObject> avObjects, AVException e) {
       if (e == null) {
         ArrayList<DoingListData> childrenList = new ArrayList<DoingListData>();
         for (AVObject avo : avObjects) {
           childrenList.add(new DoingListData(avo.getObjectId(),
               avo.getString("ChildName")));
         }
         for (DoingListData dld : mDoingListData) {
           if (dld.objectId.equals(groupObjectId)) {
             dld.doingListData = childrenList;
           }
         }
         adapter.setGroups(mDoingListData);
         expandableListView.setVisibility(View.VISIBLE);
         messageText.setVisibility(View.INVISIBLE);
         adapter.notifyDataSetChanged();
       } else {
         ERROR();
       }
     }
   };
   AVService.findChildrenList(groupObjectId, findCallback);
}
 
Example #4
Source File: DoingListFragment.java    From AnyTime with Apache License 2.0 6 votes vote down vote up
private void LoadingData() {
   FindCallback<AVObject> findCallback = new FindCallback<AVObject>() {
     @Override
     public void done(List<AVObject> avObjects, AVException e) {
       if (e == null) {
         for (AVObject avo : avObjects) {
           mDoingListData.add(new DoingListData(avo.getObjectId(),
               avo.getString("GroupName")));
         }
         mHandler.obtainMessage(1).sendToTarget();
         adapter.notifyDataSetChanged();
       } else {
         ERROR();
       }
     }
   };
   AVService.findDoingListGroup(findCallback);
}
 
Example #5
Source File: QuestionDataRepository.java    From AndroidPlusJava with GNU General Public License v3.0 6 votes vote down vote up
private void getHotQuestionListFromServer(final LoadCallback<Question> callback, final boolean isLoadMore) {
    final AVQuery<Question> questionAVQuery = AVObject.getQuery(Question.class);
    questionAVQuery.limit(Constant.DEFAULT_PAGE_SIZE).include(Question.USER)
    .selectKeys(Arrays.asList(Question.USER_AVATAR, Question.USER_NAME, Question.TITLE, Question.DESC, Question.FAVOUR_COUNT, Question.ANSWER_COUNT))
            .orderByDescending(Question.FAVOUR_COUNT)
            .addDescendingOrder(Question.CREATED_AT)
            .whereGreaterThan(Question.FAVOUR_COUNT, 0);
    if (isLoadMore) {
        questionAVQuery.whereLessThan(Question.CREATED_AT, getLastHotQuestionCreatedAt());
    }
    questionAVQuery.findInBackground(new FindCallback<Question>() {
        @Override
        public void done(List<Question> list, AVException e) {
            if (e == null) {
                if (isLoadMore) {
                    mHotQuestionListCache.addAll(list);
                } else {
                    mHotQuestionListCache = list;
                }
                callback.onLoadSuccess(list);
            } else {
                callback.onLoadFailed(e.getLocalizedMessage());
            }
        }
    });
}
 
Example #6
Source File: LaunchImage.java    From MainScreenShow with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 从服务器查看是否需要下载图片
 *
 * @param callBack
 */
public void isDownloadImage(final IsDownloadCallBack callBack) {

    AVQuery<AVObject> query = new AVQuery<AVObject>(CLASS_NAME);
    query.orderByDescending(ID);
    query.setLimit(1);
    query.findInBackground(new FindCallback<AVObject>() {
        @Override
        public void done(List<AVObject> list, AVException e) {
            if (null == e) {
                if (list.size() == 1) {
                    if (sp.getInt("image", -1) < list.get(0).getInt(ID)) {

                        callBack.done(true, list.get(0));
                    } else {
                        callBack.done(false, null);
                    }

                } else
                    callBack.done(false, null);
            } else
                callBack.done(false, null);
        }
    });
}
 
Example #7
Source File: CommonRepository.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void queryMsgList(User user, final QueryMsgListCallback callback) {
    AVQuery<Msg> query = AVQuery.getQuery(Msg.class);
    query.whereEqualTo(Api.OWNER, user);
    query.include(Api.APPLY_USER);
    query.include(Api.APPLY_BOOK);
    query.orderByDescending(Api.CREATED_AT);// 按创建时间,降序排列
    query.findInBackground(new FindCallback<Msg>() {
        @Override
        public void done(List<Msg> list, AVException e) {
            if (e == null) {
                // 设置消息为已读
                for (Msg msg : list) {
                    msg.setRead(true);
                }
                AVObject.saveAllInBackground(list);
                callback.querySuccess(list);
            } else {
                callback.queryFail(new Error(e));
            }
        }
    });
}
 
Example #8
Source File: CommonRepository.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void queryUnReadMsg(User user, final QueryUnReadMsgCallback callback) {
    AVQuery<Msg> query = AVQuery.getQuery(Msg.class);
    query.whereEqualTo(Api.OWNER, user);
    query.findInBackground(new FindCallback<Msg>() {
        @Override
        public void done(List<Msg> list, AVException e) {
            if (e == null) {
                int count = 0;
                for (Msg msg : list) {
                    if (!msg.isRead()) {
                        count++;
                    }
                }
                callback.querySuccess(count);
            } else {
                callback.queryFail(new Error(e));
            }
        }
    });
}
 
Example #9
Source File: MSS.java    From MainScreenShow with GNU General Public License v2.0 6 votes vote down vote up
private void loadAppInfo() {
    if (AVOSCloud.applicationContext == null) return;
    AVQuery<AVObject> avQuery = new AVQuery<>("App");
    avQuery.findInBackground(new FindCallback<AVObject>() {
        @Override
        public void done(final List<AVObject> list, AVException e) {
            if (list != null && list.size() == 1) {
                final AVObject avObject = list.get(0);
                new AlertDialog.Builder(MSS.this)
                        .setMessage(avObject.getString("text"))
                        .setPositiveButton("去围观", new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String url = avObject.getString("url");
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse(url);
                                intent.setData(content_url);
                                startActivity(intent);
                            }
                        }).show();
            }
        }
    });
}
 
Example #10
Source File: AccountRepository.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void queryBooks(final User user, final QueryBooksCallback callback) {
    AVQuery<AccountBook> query = AVQuery.getQuery(AccountBook.class);
    query.whereEqualTo(Api.OWNER, user);
    query.include(Api.SHARES);
    query.findInBackground(new FindCallback<AccountBook>() {
        @Override
        public void done(final List<AccountBook> list, AVException e) {
            if (e == null) {
                callback.querySuccess(list);
            } else {
                callback.queryFail(new Error(e));
            }
        }
    });
}
 
Example #11
Source File: AccountRepository.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void queryBookTotalMoney(long bid, final QueryBookTotalMoneyCallback callback) {
    AVQuery<Account> query = new AVQuery<>(Api.TAB_ACCOUNT);
    query.whereEqualTo(Api.BID, bid);
    query.findInBackground(new FindCallback<Account>() {
        @Override
        public void done(List<Account> list, AVException e) {
            if (e == null) {
                double costTotalMoney = 0;
                double incomeTotalMoney = 0;
                for (Account account : list) {
                    double money = Double.parseDouble(account.getMoney());
                    if (AppConfig.TYPE_COST == account.getType()) {
                        costTotalMoney = ArithUtils.add(costTotalMoney, money);
                    } else {
                        incomeTotalMoney = ArithUtils.add(incomeTotalMoney, money);
                    }
                }
                callback.querySuccess(costTotalMoney, incomeTotalMoney);
            } else {
                callback.queryFail(new Error(e));
            }
        }
    });
}
 
Example #12
Source File: User.java    From AndroidPlusJava with GNU General Public License v3.0 6 votes vote down vote up
public static void getUser(final LoadCallback<User> loadCallback, String objectId) {
    AVQuery<User> userAVQuery = AVQuery.getQuery(User.class);
    userAVQuery.whereEqualTo(AVUser.OBJECT_ID, objectId);
    userAVQuery.findInBackground(new FindCallback<User>() {
        @Override
        public void done(List<User> list, AVException e) {
            if (e == null) {
                loadCallback.onLoadSuccess(list);
            } else {
                loadCallback.onLoadFailed(e.getLocalizedMessage());
            }

        }
    });

}
 
Example #13
Source File: AccountRepository.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void queryTypeDetailAccount(String startDate, String endDate, String cType, int type, int page, final QueryAccountsCallback callback) {
    AVQuery<Account> startDateQuery = new AVQuery<>(Api.TAB_ACCOUNT);
    User user = UserUtils.getUser();
    if(type != -1)
        startDateQuery.whereEqualTo(Api.TYPE, type);
    startDateQuery.whereEqualTo(Api.OWNER, user);
    startDateQuery.whereEqualTo(Api.CTYPE, cType);
    startDateQuery.whereGreaterThanOrEqualTo(Api.DATE,
            DateUtils.getDateWithDateString(startDate, DateUtils.FORMAT_MAIN_TAB));

    AVQuery<Account> endDateQuery = new AVQuery<>(Api.TAB_ACCOUNT);
    if(type != -1)
        endDateQuery.whereEqualTo(Api.TYPE, type);
    endDateQuery.whereEqualTo(Api.OWNER, user);
    startDateQuery.whereEqualTo(Api.CTYPE, cType);
    endDateQuery.whereLessThan(Api.DATE,
            DateUtils.getDateWithDateString(endDate, DateUtils.FORMAT_MAIN_TAB));

    AVQuery<Account> query = AVQuery.and(Arrays.asList(startDateQuery, endDateQuery));
    query.orderByDescending(Api.DATE);// 按时间,降序排列
    query.include(Api.OWNER);
    if(page != -1){
        query.limit(AppConfig.LIMIT);
        query.skip((page - 1) * AppConfig.LIMIT);
    }
    query.findInBackground(new FindCallback<Account>() {
        @Override
        public void done(List<Account> list, AVException e) {
            if (e == null) {
                callback.querySuccess(list);
            } else {
                callback.queryFail(new Error(e));
            }
        }
    });
}
 
Example #14
Source File: AddFriendActivity.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public void searchUser(String searchName, int skip,
					   FindCallback<AVUser> findCallback) {
	AVQuery<AVUser> q = AVUser.getQuery(AVUser.class);
	q.whereContains("username", searchName);
	q.limit(10);
	q.skip(skip);
	AVUser user = AVUser.getCurrentUser();
	List<String> friendIds = getFriendIds();
	friendIds.add(user.getObjectId());
	q.whereNotContainedIn("objectId", friendIds);
	q.orderByDescending("updateAt");
	q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
	q.findInBackground(findCallback);
}
 
Example #15
Source File: AddFriendActivity.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
private void search(String searchName) {
	searchUser(searchName, mAdapter.getCount(), new FindCallback<AVUser>() {
		@Override
		public void done(List<AVUser> users, AVException e) {
			stopLoadMore();
			if (e != null) {
				e.printStackTrace();
				Utils.toast("网络错误");
			} else {
				Utils.handleListResult(mListView, mAdapter, users);
			}
		}
	});
}
 
Example #16
Source File: LoveFragment.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public void getLovePhone() {
	AVQuery<AVObject> queryPhone = new AVQuery<AVObject>("_User");
	queryPhone.whereEqualTo("mobilePhoneNumber", lPhone + "");
	queryPhone.findInBackground(new FindCallback<AVObject>() {
		public void done(List<AVObject> avObjects, AVException e) {
			if (e == null) {
				if (avObjects.size() == 0) {
					itsLovePhone = "";
				} else {
					itsLovePhone = avObjects.get(0).getString(
							"unrequitedLoverPhone")
							+ "";
				}

				if (itsLovePhone.equals(myPhone)) {
					status.setText("情投意合");
					statusWord.setText("爱情开始咯");
					container.setBackgroundResource(R.drawable.twolove);
					arrow.setVisibility(View.VISIBLE);
				} else {
					statusWord.setText("我懂,你的暗恋苦楚");
					status.setText("单相思");
				}
			} else {
				Log.d("失败", "查询错误: " + e.getMessage());
			}
		}
	});
}
 
Example #17
Source File: LoveFragment.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public void toQuery() {
	AVQuery<AVObject> query = new AVQuery<AVObject>("_User");
	query.whereEqualTo("username", userStr);
	query.findInBackground(new FindCallback<AVObject>() {
		public void done(List<AVObject> avObjects, AVException e) {
			if (e == null) {
				Log.d("成功", "查询到 " + avObjects.size() + " 条符合条件的数据");
				myPhone = avObjects.get(0).getString("mobilePhoneNumber");
				lPhone = avObjects.get(0).getString("unrequitedLoverPhone");

				userId = avObjects.get(0).getObjectId();

				if (lPhone == null || lPhone.equals("")) {
					bind.setVisibility(View.VISIBLE);
					loverPhone.setVisibility(View.VISIBLE);
					loverName.setVisibility(View.VISIBLE);
					Log.d("Leancloud", "没有暗恋对象");
					status.setText("未暗恋");
					statusWord.setText("我懂,你的暗恋苦楚");
				} else {
					Log.d("Leancloud", "有暗恋对象");
					changeLove.setVisibility(View.VISIBLE);
					getLovePhone();
				}

			} else {
				Log.d("失败", "查询错误: " + e.getMessage());
			}
		}
	});
}
 
Example #18
Source File: InviteBll.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
/**
	 * 获得最新的邀请数据
	 *
	 * @return
	 */
	public Observable<List<Invitation>> getNewlyInvitationData()
	{
		return Observable.create(new Observable.OnSubscribe<List<Invitation>>()
		{
			@Override
			public void call(final Subscriber<? super List<Invitation>> subscriber)
			{
				AVQuery<Invitation> query = AVObject.getQuery(Invitation.class);
				query.orderByDescending(AVObject.CREATED_AT);
				query.whereNotEqualTo(Invitation.FIELD_IS_EXPIRE, true);
				query.include(Invitation.FIELD_AUTHOR);
				query.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
//				query.setCachePolicy(AVQuery.CachePolicy.CACHE_THEN_NETWORK);
				query.findInBackground(new FindCallback<Invitation>()
				{
					@Override
					public void done(List<Invitation> invitations, AVException e)
					{
						if (e == null)
						{
							subscriber.onNext(invitations);
						} else
						{
							subscriber.onError(e);
						}
					}
				});
//				try
//				{
//					List<Invitation> invitations = query.find();
//					subscriber.onNext(invitations);
//				} catch (AVException e)
//				{
//					e.printStackTrace();
//					subscriber.onError(e);
//				}
			}
		});
	}
 
Example #19
Source File: AccountRepository.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void queryAccounts(User user, String startDate, String endDate, int type, int page, final QueryAccountsCallback callback) {
    AVQuery<Account> startDateQuery = new AVQuery<>(Api.TAB_ACCOUNT);
    if(type != -1)
        startDateQuery.whereEqualTo(Api.TYPE, type);
    startDateQuery.whereEqualTo(Api.OWNER, user);
    startDateQuery.whereGreaterThanOrEqualTo(Api.DATE,
            DateUtils.getDateWithDateString(startDate, DateUtils.FORMAT_MAIN_TAB));

    AVQuery<Account> endDateQuery = new AVQuery<>(Api.TAB_ACCOUNT);
    if(type != -1)
        endDateQuery.whereEqualTo(Api.TYPE, type);
    endDateQuery.whereEqualTo(Api.OWNER, user);
    endDateQuery.whereLessThan(Api.DATE,
            DateUtils.getDateWithDateString(endDate, DateUtils.FORMAT_MAIN_TAB));

    AVQuery<Account> query = AVQuery.and(Arrays.asList(startDateQuery, endDateQuery));
    query.orderByDescending(Api.DATE);// 按时间,降序排列
    query.include(Api.OWNER);
    if(page != -1){
        query.limit(AppConfig.LIMIT);
        query.skip((page - 1) * AppConfig.LIMIT);
    }
    query.findInBackground(new FindCallback<Account>() {
        @Override
        public void done(List<Account> list, AVException e) {
            if (e == null) {
                callback.querySuccess(list);
            } else {
                callback.queryFail(new Error(e));
            }
        }
    });
}
 
Example #20
Source File: ArticleDataRepository.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
private void getArticlesFromServer(final int tagId, final LoadCallback<Article> callback, final boolean isLoadMore) {
    //获取文章查询对象
    final AVQuery<Article> articleAVQuery = AVQuery.getQuery(Article.class);
    //配置查询条件
    articleAVQuery.include(Article.USER)
            .selectKeys(Arrays.asList(Article.TITLE, Article.DESC,
                    Article.FAVOUR_COUNT, Article.TAG, Article.URL,
                    Article.USER_NAME, Article.USER_AVATAR))
            .limit(Constant.DEFAULT_PAGE_SIZE);
    //如果是热门标签,则按文章点赞数排序,以创建时间为第二排序条件,并且点赞次数大于0
    if (tagId == Article.TAG_HOT) {
        articleAVQuery.orderByDescending(Article.FAVOUR_COUNT)
                .addDescendingOrder(Article.CREATED_AT)
                .whereGreaterThan(Article.FAVOUR_COUNT, 0);
    } else {//其他标签,以文章创建时间排序
        articleAVQuery.whereEqualTo(Article.TAG, tagId)
                .orderByDescending(Article.CREATED_AT);
    }
    //加载更多数据的处理
    if (isLoadMore) {
        articleAVQuery.whereLessThan(Article.CREATED_AT, getLastTagArticleCreatedAt(tagId));

    }
    //开始查询
    articleAVQuery.findInBackground(new FindCallback<Article>() {
        @Override
        public void done(List<Article> list, AVException e) {
            if (e == null) {
                if (isLoadMore) {
                    mArticleByTagCache.get(tagId).addAll(list);
                } else {
                    mArticleByTagCache.put(tagId, list);
                }
                callback.onLoadSuccess(list);
            } else {
                callback.onLoadFailed(e.getLocalizedMessage());
            }
        }
    });
}
 
Example #21
Source File: QuestionDataRepository.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
private void getRecentQuestionListFromServer(final LoadCallback<Question> callback, final boolean isLoadMore) {
    //获取查询对象
    final AVQuery<Question> questionAVQuery = AVObject.getQuery(Question.class);
    questionAVQuery.limit(Constant.DEFAULT_PAGE_SIZE)//限制结果个数,默认10条数据
            .include(Question.USER)//结果包含提问用户数据
            .selectKeys(Arrays.asList(Question.TITLE,
                    Question.DESC, Question.FAVOUR_COUNT, Question.ANSWER_COUNT,
                    Question.USER_NAME, Question.USER_AVATAR))//过滤用户数据字段
            .orderByDescending(AVObject.CREATED_AT);//按创建时间降序

    //查询更多时的处理
    if (isLoadMore) {
        //查询数据的创建时间小于已有数据列表最后一条数据的创建时间
        questionAVQuery.whereLessThan(AVObject.CREATED_AT, getLastQuestionCreateAt());
    }
    //开始查询
    questionAVQuery.findInBackground(new FindCallback<Question>() {
        @Override
        public void done(List<Question> list, AVException e) {
            if (e == null) {
                if (isLoadMore) {
                    mRecentQuestionListCache.addAll(list);
                } else {
                    mRecentQuestionListCache = list;
                }
                callback.onLoadSuccess(list);
            } else {
                callback.onLoadFailed(e.getLocalizedMessage());
            }
        }
    });
}
 
Example #22
Source File: AnswerDataRepository.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
private void getHotAnswerListByQuestionFromServer(String questionId, final LoadCallback<Answer> callback, final boolean isLoadMore) {
    final AVQuery<Answer> answerAVQuery = AVObject.getQuery(Answer.class);
    Question question = getQuestionWithoutData(questionId);
    answerAVQuery.limit(Constant.DEFAULT_PAGE_SIZE).include(Answer.USER).include(Answer.QUESTION)
            .selectKeys(Arrays.asList(Answer.USER_NAME, Answer.USER_AVATAR,
                    Answer.LIKE_COUNT, Answer.COMMENT_COUNT, Answer.CONTENT, Answer.QUESTION_TITLE))
            .whereEqualTo(Answer.QUESTION, question)
            .whereGreaterThan(Answer.LIKE_COUNT, 0)
            .orderByDescending(Answer.LIKE_COUNT)
            .addDescendingOrder(AVObject.CREATED_AT);
    if (isLoadMore) {
        answerAVQuery.whereLessThan(AVObject.CREATED_AT, getLastHotAnswerCreatedAt());
    }
    answerAVQuery.findInBackground(new FindCallback<Answer>() {
        @Override
        public void done(List<Answer> list, AVException e) {
            if (e == null) {
                if (isLoadMore) {
                    mHotAnswerListCache.addAll(list);
                } else {
                    mHotAnswerListCache = list;
                }
                callback.onLoadSuccess(list);
            } else {
                callback.onLoadFailed(e.getLocalizedMessage());
            }
        }
    });
}
 
Example #23
Source File: AnswerDataRepository.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
private void getRecentAnswerListFromServer(final LoadCallback<Answer> callback, final boolean isLoadMore) {
    final AVQuery<Answer> answerAVQuery = AVObject.getQuery(Answer.class);
    answerAVQuery.limit(Constant.DEFAULT_PAGE_SIZE)
            .include(Answer.USER)
            .include(Answer.QUESTION)
            .selectKeys(Arrays.asList(Answer.USER_NAME, Answer.QUESTION_TITLE,
                    Answer.LIKE_COUNT, Answer.COMMENT_COUNT, Answer.CONTENT))
            .orderByDescending(AVObject.CREATED_AT);
    if (isLoadMore) {
        answerAVQuery.whereLessThan(Answer.CREATED_AT, getLastRecentAnswerCreatedAt());
    }
    answerAVQuery.findInBackground(new FindCallback<Answer>() {
        @Override
        public void done(List<Answer> list, AVException e) {
            if (e == null) {
                if (isLoadMore) {
                    mRecentAnswerListCache.addAll(list);
                } else {
                    mRecentAnswerListCache = list;
                }
                callback.onLoadSuccess(list);
            } else {
                callback.onLoadFailed(e.getLocalizedMessage());
            }
        }
    });
}
 
Example #24
Source File: AnswerDataRepository.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
public void getAnswerListByQuestionFromServer(String questionId, final LoadCallback<Answer> callback, final boolean isLoadMore) {
    final AVQuery<Answer> answerAVQuery = AVObject.getQuery(Answer.class);
    Question question = getQuestionWithoutData(questionId);
    answerAVQuery.limit(Constant.DEFAULT_PAGE_SIZE)
            .include(Answer.USER)
            .include(Answer.QUESTION)
            .selectKeys(Arrays.asList(Answer.CONTENT,
                    Answer.LIKE_COUNT,
                    Answer.COMMENT_COUNT,
                    Answer.USER_NAME,
                    Answer.USER_AVATAR,
                    Answer.QUESTION_TITLE))
            .whereEqualTo(Answer.QUESTION, question)
            .orderByDescending(AVObject.CREATED_AT);
    if (isLoadMore) {
        answerAVQuery.whereLessThan(AVObject.CREATED_AT, getLastRecentAnswerCreatedAt());
    }
    answerAVQuery.findInBackground(new FindCallback<Answer>() {
        @Override
        public void done(List<Answer> list, AVException e) {
            if (e == null) {
                if (isLoadMore) {
                    mRecentAnswerListCache.addAll(list);
                } else {
                    mRecentAnswerListCache = list;
                }
                callback.onLoadSuccess(list);
            } else {
                callback.onLoadFailed(e.getLocalizedMessage());
            }
        }
    });
}
 
Example #25
Source File: UpdateVersion.java    From MainScreenShow with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 从网络检查有没有新版本
 *
 * @param callBack 回调,返回检查结果,如果没有版本更新则返回当前版本号
 */
public void checkVersionFromNetwork(final CallBack callBack) {

    if (!getVersionName().equals("0.0.0")) {
        AVQuery<AVObject> query = new AVQuery<AVObject>(CLASS_NAME);
        query.orderByDescending(VERSION_NAME);
        query.whereGreaterThan(VERSION_NAME, getVersionName());
        query.findInBackground(new FindCallback<AVObject>() {

            @Override
            public void done(List<AVObject> versions, AVException e) {

                if (null == e) {
                    if (versions.size() > 0) {

                        String versionInfo = "";
                        String versionName = versions.get(0).getString(
                                VERSION_NAME);
                        String versionUrl = versions.get(0).getString(
                                VERSION_URL);
                        for (int i = 0; i < versions.size(); i++) {

                            versionInfo = versionInfo
                                    + "\r\nV  "
                                    + versions.get(i).getString(
                                    VERSION_NAME) + "\r\n";
                            versionInfo = versionInfo
                                    + versions.get(i).getString(
                                    VERSION_INFO) + "\r\n";
                        }
                        putNewVersionInfo(versionName, versionUrl, versionInfo);
                        callBack.done(versionName, versionUrl, versionInfo);
                    } else {
                        callBack.done(getVersionName(), "", "");
                    }
                } else {
                    callBack.done(getVersionName(), "", "");
                }
            }
        });
    }
}