Search in sources :

Example 21 with User

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.");
        }
    });
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 22 with User

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User)

Example 23 with User

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();
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File)

Aggregations

BmobUser (cn.bmob.v3.BmobUser)23 User (com.nightonke.saver.model.User)23 File (java.io.File)9 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)8 Handler (android.os.Handler)7 View (android.view.View)7 TextView (android.widget.TextView)7 BmobQuery (cn.bmob.v3.BmobQuery)7 UpdateListener (cn.bmob.v3.listener.UpdateListener)7 Logo (com.nightonke.saver.model.Logo)7 Bitmap (android.graphics.Bitmap)6 BmobFile (cn.bmob.v3.datatype.BmobFile)6 FutureCallback (com.koushikdutta.async.future.FutureCallback)6 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)6 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 ActionBar (android.support.v7.app.ActionBar)4 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)4 SaveListener (cn.bmob.v3.listener.SaveListener)4 DescriptionAnimation (com.daimajia.slider.library.Animations.DescriptionAnimation)4