use of com.nightonke.saver.model.User 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 com.nightonke.saver.model.User in project CoCoin by Nightonke.
the class AccountBookSettingActivity method changeAccountBookName.
// Change account book name/////////////////////////////////////////////////////////////////////////
private void changeAccountBookName() {
new MaterialDialog.Builder(this).theme(Theme.LIGHT).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).title(R.string.set_account_book_dialog_title).inputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS).inputRange(1, 16).positiveText(R.string.submit).input(SettingManager.getInstance().getAccountBookName(), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
// local change
SettingManager.getInstance().setAccountBookName(input.toString());
SettingManager.getInstance().setTodayViewTitleShouldChange(true);
SettingManager.getInstance().setMainViewTitleShouldChange(true);
accountBookName.setText(input.toString());
// update change
User user = getCurrentUser();
if (user != null) {
updateSettingsToServer(UPDATE_ACCOUNT_BOOK_NAME);
} else {
// the new account book name is changed successfully
showToast(2, "");
}
}
}).show();
}
use of com.nightonke.saver.model.User in project CoCoin by Nightonke.
the class AccountBookSettingActivity method changeLogo.
// change the user logo/////////////////////////////////////////////////////////////////////////////
private void changeLogo() {
User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
if (user == null) {
new MaterialDialog.Builder(this).iconRes(R.drawable.cocoin_logo).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.login_first_title).content(R.string.login_first_content).positiveText(R.string.ok).neutralText(R.string.cancel).onAny(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (which == DialogAction.POSITIVE) {
userOperator();
}
}
}).show();
return;
}
new MaterialDialog.Builder(this).iconRes(R.drawable.cocoin_logo).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.change_logo_title).content(R.string.change_logo_content).positiveText(R.string.from_gallery).negativeText(R.string.from_camera).neutralText(R.string.cancel).onAny(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (which == DialogAction.POSITIVE) {
Intent intent1 = new Intent(Intent.ACTION_PICK, null);
intent1.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
startActivityForResult(intent1, 1);
} else if (which == DialogAction.NEGATIVE) {
Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent2.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)));
startActivityForResult(intent2, 2);
}
}
}).show();
}
Aggregations