Search in sources :

Example 1 with MyUser

use of com.fafu.zhengxianyou.livingincampus.bean.MyUser in project LivingInCampus by DulCoder.

the class UserFragment method logOff.

/**
 * 退出登录相关
 */
private void logOff() {
    MyUser user = new MyUser();
    user.logOut();
    loginReg.setClickable(true);
    logout.setVisibility(View.GONE);
    myIcon.setImageResource(R.drawable.overcast);
    myId.setText("未登录");
    MyApplication.editor.remove("icon");
    editor.remove("nickName");
    editor.commit();
    Config.setMyIcon(null);
    Config.setNickName(null);
}
Also used : MyUser(com.fafu.zhengxianyou.livingincampus.bean.MyUser)

Example 2 with MyUser

use of com.fafu.zhengxianyou.livingincampus.bean.MyUser in project LivingInCampus by DulCoder.

the class AddCommunityFragment method publish.

/**
 * 发布信息的相关逻辑
 */
private void publish() {
    icon = Config.getMyIcon();
    nickname = Config.getNickName();
    if (icon != null && nickname != null) {
        // 判断是否登录
        content = etCommunity.getText().toString();
        if (TextUtils.isEmpty(content)) {
            Utils.toast(mContext, "输入不能为空");
        } else if (content.length() > 140) {
            Utils.toast(mContext, "内容字数不能大于140");
        } else {
            Date date = new Date();
            DateFormat format = DateFormat.getDateTimeInstance();
            // 获取当前时间
            datetime = format.format(date);
            MyUser user = BmobUser.getCurrentUser(MyUser.class);
            final CommunityItem communityItem = new CommunityItem();
            communityItem.setMyIcon(icon);
            communityItem.setNickName(nickname);
            communityItem.setDatetime(datetime);
            communityItem.setContent(content);
            communityItem.setAuthor(user);
            communityItem.save(new SaveListener<String>() {

                @Override
                public void done(String s, BmobException e) {
                    if (e != null) {
                        Utils.toast(mContext, e.getErrorCode() + e.getMessage());
                    } else {
                        getFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(R.id.community_container, CommunityFragment.newInstance()).commit();
                    }
                }
            });
        }
    } else {
        Utils.toast(mContext, "请登录");
    }
}
Also used : SaveListener(cn.bmob.v3.listener.SaveListener) MyUser(com.fafu.zhengxianyou.livingincampus.bean.MyUser) BmobException(cn.bmob.v3.exception.BmobException) DateFormat(java.text.DateFormat) CommunityItem(com.fafu.zhengxianyou.livingincampus.bean.CommunityItem) Date(java.util.Date)

Example 3 with MyUser

use of com.fafu.zhengxianyou.livingincampus.bean.MyUser in project LivingInCampus by DulCoder.

the class LoginFragment method login.

private void login() {
    name = et_login.getText().toString();
    password = et_password.getText().toString();
    final MyUser user = new MyUser();
    user.setUsername(name);
    user.setPassword(password);
    user.login(new SaveListener<MyUser>() {

        @Override
        public void done(MyUser myUser, BmobException e) {
            try {
                if (e == null) {
                    MyApplication.editor.putBoolean("isChecked", cb_choice.isChecked());
                    if (cb_choice.isChecked()) {
                        editor.putString("name", name);
                        editor.putString("password", password);
                    }
                    String icon = myUser.getMyIcon();
                    String nickName = myUser.getNickName();
                    editor.putString("icon", icon);
                    editor.putString("nickName", nickName);
                    editor.commit();
                    getActivity().finish();
                } else {
                    Log.e("err1", e.getErrorCode() + "" + e.getMessage());
                }
            } catch (Exception exception) {
                Log.e("err", exception.getMessage() + "");
                Utils.toast(mContext, "正在登录");
            }
        }
    });
}
Also used : MyUser(com.fafu.zhengxianyou.livingincampus.bean.MyUser) BmobException(cn.bmob.v3.exception.BmobException) BmobException(cn.bmob.v3.exception.BmobException)

Example 4 with MyUser

use of com.fafu.zhengxianyou.livingincampus.bean.MyUser in project LivingInCampus by DulCoder.

the class RegisterFragment method register.

/**
 * 注册相关逻辑
 */
private void register(String login, String password, String nickName, String myIcon) {
    MyUser user = new MyUser();
    email = et_email.getText().toString();
    user.setEmail(email);
    user.setNickName(nickName);
    user.setMyIcon(myIcon);
    user.setUsername(login);
    user.setPassword(password);
    try {
        user.signUp(new SaveListener<MyUser>() {

            @Override
            public void done(MyUser myUser, BmobException e) {
                if (e == null) {
                    toast("注册成功");
                    goBack();
                } else {
                    int error = e.getErrorCode();
                    toast("e" + error);
                }
            }
        });
    } catch (Exception exception) {
        Log.e("ERROR", exception.getMessage());
    }
}
Also used : MyUser(com.fafu.zhengxianyou.livingincampus.bean.MyUser) BmobException(cn.bmob.v3.exception.BmobException) BmobException(cn.bmob.v3.exception.BmobException)

Aggregations

MyUser (com.fafu.zhengxianyou.livingincampus.bean.MyUser)4 BmobException (cn.bmob.v3.exception.BmobException)3 SaveListener (cn.bmob.v3.listener.SaveListener)1 CommunityItem (com.fafu.zhengxianyou.livingincampus.bean.CommunityItem)1 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1