Search in sources :

Example 1 with CommunityItem

use of com.fafu.zhengxianyou.livingincampus.bean.CommunityItem 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)

Aggregations

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