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, "请登录");
}
}
Aggregations