Search in sources :

Example 1 with User

use of com.nightonke.saver.model.User in project CoCoin by Nightonke.

the class ShowActivity method buttonClickOperation.

private void buttonClickOperation(boolean longClick, int position) {
    switch(CURRENT_STATE) {
        case NEW_PASSWORD:
            if (CoCoinUtil.ClickButtonDelete(position)) {
                if (longClick) {
                    CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].init();
                    newPassword = "";
                } else {
                    CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].clear(newPassword.length() - 1);
                    if (newPassword.length() != 0)
                        newPassword = newPassword.substring(0, newPassword.length() - 1);
                }
            } else if (CoCoinUtil.ClickButtonCommit(position)) {
            } else {
                CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].set(newPassword.length());
                newPassword += CoCoinUtil.BUTTONS[position];
                if (newPassword.length() == 4) {
                    // finish the new password input
                    CURRENT_STATE = PASSWORD_AGAIN;
                    viewPager.setCurrentItem(PASSWORD_AGAIN, true);
                }
            }
            break;
        case PASSWORD_AGAIN:
            if (CoCoinUtil.ClickButtonDelete(position)) {
                if (longClick) {
                    CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].init();
                    againPassword = "";
                } else {
                    CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].clear(againPassword.length() - 1);
                    if (againPassword.length() != 0)
                        againPassword = againPassword.substring(0, againPassword.length() - 1);
                }
            } else if (CoCoinUtil.ClickButtonCommit(position)) {
            } else {
                CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].set(againPassword.length());
                againPassword += CoCoinUtil.BUTTONS[position];
                if (againPassword.length() == 4) {
                    // if the password again is equal to the new password
                    if (againPassword.equals(newPassword)) {
                        CURRENT_STATE = -1;
                        showToast(2);
                        SettingManager.getInstance().setPassword(newPassword);
                        SettingManager.getInstance().setFirstTime(false);
                        if (SettingManager.getInstance().getLoggenOn()) {
                            User currentUser = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
                            currentUser.setAccountBookPassword(newPassword);
                            currentUser.update(CoCoinApplication.getAppContext(), currentUser.getObjectId(), new UpdateListener() {

                                @Override
                                public void onSuccess() {
                                    Log.d("Saver", "Set password successfully.");
                                }

                                @Override
                                public void onFailure(int code, String msg) {
                                    Log.d("Saver", "Set password failed.");
                                }
                            });
                        }
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                finish();
                            }
                        }, 1000);
                    } else {
                        CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE].clear(4);
                        CoCoinFragmentManager.passwordChangeFragment[CURRENT_STATE - 1].init();
                        CURRENT_STATE = NEW_PASSWORD;
                        viewPager.setCurrentItem(NEW_PASSWORD, true);
                        newPassword = "";
                        againPassword = "";
                        showToast(1);
                    }
                }
            }
            break;
        default:
            break;
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) Handler(android.os.Handler) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 2 with User

use of com.nightonke.saver.model.User in project CoCoin by Nightonke.

the class AccountBookSettingActivity method updateSettingsToServer.

// update part of settings//////////////////////////////////////////////////////////////////////////
private void updateSettingsToServer(final int setting) {
    User currentUser = getCurrentUser();
    if (currentUser == null) {
        Log.d("Saver", "User hasn't log in.");
        return;
    }
    switch(setting) {
        case UPDATE_LOGO:
            // logo
            break;
        case UPDATE_IS_MONTH_LIMIT:
            // is month limit
            currentUser.setIsMonthLimit(SettingManager.getInstance().getIsMonthLimit());
            break;
        case UPDATE_MONTH_LIMIT:
            // month limit
            currentUser.setMonthLimit(SettingManager.getInstance().getMonthLimit());
            break;
        case UPDATE_IS_COLOR_REMIND:
            // is color remind
            currentUser.setIsColorRemind(SettingManager.getInstance().getIsColorRemind());
            break;
        case UPDATE_MONTH_WARNING:
            // month warning
            currentUser.setMonthWarning(SettingManager.getInstance().getMonthWarning());
            break;
        case UPDATE_REMIND_COLOR:
            // remind color
            currentUser.setRemindColor(SettingManager.getInstance().getRemindColor());
            break;
        case UPDATE_IS_FORBIDDEN:
            // is forbidden
            currentUser.setIsForbidden(SettingManager.getInstance().getIsForbidden());
            break;
        case UPDATE_ACCOUNT_BOOK_NAME:
            // account book name
            currentUser.setAccountBookName(SettingManager.getInstance().getAccountBookName());
            break;
        case UPDATE_ACCOUNT_BOOK_PASSWORD:
            // account book password
            currentUser.setAccountBookPassword(SettingManager.getInstance().getPassword());
            break;
        case UPDATE_SHOW_PICTURE:
            // show picture
            currentUser.setShowPicture(SettingManager.getInstance().getShowPicture());
            break;
        case UPDATE_IS_HOLLOW:
            // is hollow
            currentUser.setIsHollow(SettingManager.getInstance().getIsHollow());
            break;
        case UPDATE_LOGO_ID:
            // has a logo which has been updated
            currentUser.setLogoObjectId(SettingManager.getInstance().getLogoObjectId());
            break;
    }
    currentUser.update(CoCoinApplication.getAppContext(), currentUser.getObjectId(), new UpdateListener() {

        @Override
        public void onSuccess() {
            Log.d("Saver", "Update " + setting + " successfully.");
            // the new account book name is updated to server successfully
            if (setting == UPDATE_ACCOUNT_BOOK_NAME)
                showToast(0, "");
        }

        @Override
        public void onFailure(int code, String msg) {
            Log.d("Saver", "Update " + setting + " fail.");
            // the new account book name is failed to updated to server
            if (setting == UPDATE_ACCOUNT_BOOK_NAME)
                showToast(1, "");
        }
    });
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 3 with User

use of com.nightonke.saver.model.User in project CoCoin by Nightonke.

the class AccountBookTagViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                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/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        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) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 4 with User

use of com.nightonke.saver.model.User in project CoCoin by Nightonke.

the class AccountBookTodayViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                Log.d("CoCoin", user.getLogoObjectId());
                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/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        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) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) BmobFile(cn.bmob.v3.datatype.BmobFile) BmobProFile(com.bmob.BmobProFile) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 5 with User

use of com.nightonke.saver.model.User in project CoCoin by Nightonke.

the class AccountBookTodayViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account_book_today_view);
    SuperToast.cancelAllSuperToasts();
    mContext = this;
    mViewPager = (MaterialViewPager) findViewById(R.id.materialViewPager);
    userName = (TextView) findViewById(R.id.user_name);
    userEmail = (TextView) findViewById(R.id.user_email);
    userName.setTypeface(CoCoinUtil.typefaceLatoRegular);
    userEmail.setTypeface(CoCoinUtil.typefaceLatoLight);
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        userName.setText(user.getUsername());
        userEmail.setText(user.getEmail());
    }
    setFonts();
    View view = mViewPager.getRootView();
    title = (TextView) view.findViewById(R.id.logo_white);
    title.setTypeface(CoCoinUtil.typefaceLatoLight);
    title.setText(SettingManager.getInstance().getAccountBookName());
    mViewPager.getPagerTitleStrip().setTypeface(CoCoinUtil.GetTypeface(), Typeface.NORMAL);
    setTitle("");
    toolbar = mViewPager.getToolbar();
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    custom = (MaterialRippleLayout) mDrawer.findViewById(R.id.custom_layout);
    tags = (MaterialRippleLayout) mDrawer.findViewById(R.id.tag_layout);
    months = (MaterialRippleLayout) mDrawer.findViewById(R.id.month_layout);
    list = (MaterialRippleLayout) mDrawer.findViewById(R.id.list_layout);
    report = (MaterialRippleLayout) mDrawer.findViewById(R.id.report_layout);
    sync = (MaterialRippleLayout) mDrawer.findViewById(R.id.sync_layout);
    settings = (MaterialRippleLayout) mDrawer.findViewById(R.id.settings_layout);
    help = (MaterialRippleLayout) mDrawer.findViewById(R.id.help_layout);
    feedback = (MaterialRippleLayout) mDrawer.findViewById(R.id.feedback_layout);
    about = (MaterialRippleLayout) mDrawer.findViewById(R.id.about_layout);
    syncIcon = (MaterialIconView) mDrawer.findViewById(R.id.sync_icon);
    setIconEnable(syncIcon, SettingManager.getInstance().getLoggenOn());
    monthExpenseTip = (TextView) mDrawer.findViewById(R.id.month_expense_tip);
    monthExpenseTip.setTypeface(CoCoinUtil.GetTypeface());
    monthExpense = (RiseNumberTextView) mDrawer.findViewById(R.id.month_expense);
    monthExpense.setTypeface(CoCoinUtil.typefaceLatoLight);
    if (SettingManager.getInstance().getIsMonthLimit()) {
        monthExpenseTip.setVisibility(View.VISIBLE);
        monthExpense.setText("0");
    } else {
        monthExpenseTip.setVisibility(View.INVISIBLE);
        monthExpense.setVisibility(View.INVISIBLE);
    }
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setHomeButtonEnabled(true);
        }
    }
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0) {

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            monthExpense.setText("0");
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            monthExpense.withNumber(RecordManager.getCurrentMonthExpense()).setDuration(500).start();
        }
    };
    mDrawer.setDrawerListener(mDrawerToggle);
    View logo = findViewById(R.id.logo_white);
    if (logo != null) {
        logo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mViewPager.notifyHeaderChanged();
            }
        });
    }
    todayModeAdapter = new TodayViewFragmentAdapter(getSupportFragmentManager());
    mViewPager.getViewPager().setOffscreenPageLimit(todayModeAdapter.getCount());
    mViewPager.getViewPager().setAdapter(todayModeAdapter);
    mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager());
    mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {

        @Override
        public HeaderDesign getHeaderDesign(int page) {
            return HeaderDesign.fromColorAndDrawable(CoCoinUtil.GetTagColor(page - 2), CoCoinUtil.GetTagDrawable(-3));
        }
    });
    setListeners();
    profileImage = (CircleImageView) mDrawer.findViewById(R.id.profile_image);
    profileImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SettingManager.getInstance().getLoggenOn()) {
                CoCoinUtil.showToast(mContext, R.string.change_logo_tip);
            } else {
                CoCoinUtil.showToast(mContext, R.string.login_tip);
            }
        }
    });
    mDemoSlider = (SliderLayout) findViewById(R.id.slider);
    HashMap<String, Integer> urls = CoCoinUtil.GetDrawerTopUrl();
    for (String name : urls.keySet()) {
        CustomSliderView customSliderView = new CustomSliderView(this);
        // initialize a SliderLayout
        customSliderView.image(urls.get(name)).setScaleType(BaseSliderView.ScaleType.Fit);
        mDemoSlider.addSlider(customSliderView);
    }
    mDemoSlider.setPresetTransformer(SliderLayout.Transformer.ZoomOut);
    mDemoSlider.setCustomAnimation(new DescriptionAnimation());
    mDemoSlider.setDuration(4000);
    mDemoSlider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator));
    loadLogo();
}
Also used : MaterialViewPager(com.github.florent37.materialviewpager.MaterialViewPager) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) HeaderDesign(com.github.florent37.materialviewpager.header.HeaderDesign) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) CustomSliderView(com.nightonke.saver.ui.CustomSliderView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) View(android.view.View) TextView(android.widget.TextView) BaseSliderView(com.daimajia.slider.library.SliderTypes.BaseSliderView) CustomSliderView(com.nightonke.saver.ui.CustomSliderView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) TodayViewFragmentAdapter(com.nightonke.saver.adapter.TodayViewFragmentAdapter) DescriptionAnimation(com.daimajia.slider.library.Animations.DescriptionAnimation) ActionBar(android.support.v7.app.ActionBar)

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