use of cn.bmob.v3.listener.FindListener in project CoCoin by Nightonke.
the class AccountBookSettingActivity method downloadLogoFromServer.
// download logo to local///////////////////////////////////////////////////////////////////////////
private void downloadLogoFromServer() {
User user = getCurrentUser();
if (user.getLogoObjectId() == null) {
// the user has no logo
return;
}
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/////////////////////////////////////////////////////////
Log.d("Saver", "There is an old logo");
String url = object.get(0).getFile().getUrl();
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) {
Bitmap bitmap = BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
if (bitmap == null) {
Log.d("Saver", "Logo misses");
} else {
logo.setImageBitmap(bitmap);
}
SettingManager.getInstance().setHasLogo(true);
}
});
SettingManager.getInstance().setTodayViewLogoShouldChange(true);
}
@Override
public void onError(int code, String msg) {
// the picture is lost
Log.d("Saver", "Can't find the old logo in server.");
}
});
}
use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.
the class TalentPresenter method showTalent.
public void showTalent(boolean isForce) {
final TalentDao talentDao = getDaoSession().getTalentDao();
if (!isForce && talentDao.count() > 0) {
if (getView() != null) {
List<Talent> list = talentDao.queryBuilder().orderAsc(TalentDao.Properties.Position).list();
getView().showTalentList(list);
}
return;
}
if (getView() != null) {
getView().showLoading();
}
BmobQuery<Talent> query = new BmobQuery<>(Constants.BMOB_TALENT);
query.setLimit(45).order("position").findObjects(new FindListener<Talent>() {
@Override
public void done(final List<Talent> list, BmobException e) {
if (getView() != null) {
getView().closeLoading();
if (e == null) {
getView().showTalentList(list);
if (!saveFlag) {
saveFlag = true;
new Thread(new Runnable() {
@Override
public void run() {
for (Talent talent : list) {
talentDao.insert(talent);
}
saveFlag = false;
}
});
}
} else {
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.
the class EquJJCPresenter method showEquJJCList.
public void showEquJJCList(boolean isForce) {
final EquipmentDao equipmentDao = getDaoSession().getEquipmentDao();
if (!isForce && equipmentDao.count() > 0) {
if (getView() != null) {
List<Equipment> equipmentList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).orderAsc(EquipmentDao.Properties.Id).list();
getView().showEquJJCList(equipmentList);
}
return;
}
if (getView() != null) {
getView().showLoading();
}
BmobQuery<Equipment> query = new BmobQuery<>(Constants.BMOB_EQUIPMENT);
query.addWhereEqualTo("type", "JJC").order("id").setLimit(300).findObjects(new FindListener<Equipment>() {
@Override
public void done(final List<Equipment> list, BmobException e) {
if (getView() != null) {
getView().closeLoading();
if (e == null) {
getView().showEquJJCList(list);
if (!saveFlag) {
saveFlag = true;
new Thread(new Runnable() {
@Override
public void run() {
List<Equipment> jjcList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).list();
for (Equipment equipment : jjcList) {
equipmentDao.delete(equipment);
}
for (Equipment equipment : list) {
equipmentDao.insert(equipment);
}
saveFlag = false;
}
}).start();
}
} else {
getView().loadFailure();
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.
the class HeroSkillPresenter method showSkill.
public void showSkill(final String UNCode, boolean isForce) {
final SkillDao skillDao = getDaoSession().getSkillDao();
if (!isForce && getView() != null) {
List<Skill> list = skillDao.queryBuilder().where(SkillDao.Properties.UNCode.eq(UNCode)).list();
if (!ListUtils.isEmpty(list)) {
getView().showSkill(list);
return;
}
}
BmobQuery<Skill> query = new BmobQuery<>(Constants.BMOB_SKILL);
query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Skill>() {
@Override
public void done(final List<Skill> list, BmobException e) {
if (getView() != null) {
if (e == null) {
if (!ListUtils.isEmpty(list)) {
getView().showSkill(list);
if (!isSaving) {
isSaving = true;
new Thread(new Runnable() {
@Override
public void run() {
List<Skill> oldList = skillDao.queryBuilder().where(SkillDao.Properties.UNCode.eq(UNCode)).list();
for (Skill skill : oldList) {
skillDao.delete(skill);
}
for (Skill skill : list) {
skillDao.save(skill);
}
isSaving = false;
}
}).start();
}
}
} else {
getView().loadFailure();
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.
the class HeroSoundPresenter method showSound.
public void showSound(final String UNCode, boolean isForce) {
final SoundDao soundDao = getDaoSession().getSoundDao();
if (!isForce && getView() != null) {
List<Sound> list = soundDao.queryBuilder().where(SoundDao.Properties.UNCode.eq(UNCode)).list();
if (!ListUtils.isEmpty(list)) {
getView().showSound(list);
return;
}
}
BmobQuery<Sound> query = new BmobQuery<>(Constants.BMOB_Sound);
query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Sound>() {
@Override
public void done(final List<Sound> list, BmobException e) {
if (getView() != null) {
if (e == null) {
getView().showSound(list);
if (!isSaving) {
isSaving = true;
new Thread(new Runnable() {
@Override
public void run() {
List<Sound> oldList = soundDao.queryBuilder().where(SoundDao.Properties.UNCode.eq(UNCode)).list();
for (Sound sound : oldList) {
soundDao.delete(sound);
}
for (Sound sound : list) {
soundDao.insert(sound);
}
isSaving = false;
}
}).start();
}
} else {
getView().loadFailure();
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
Aggregations