朋友圈项目概述
.项目为Android Studio开发,软件为联网软件,基于Bmob后端服务器,主打纯原生代码,代码整体简洁,方法注释清晰,没有众多看不懂的类,适合新手,使得后期修改与创作更加简便。
.可发多图,无图,纯文字,也支持动态图发表与显示,支持登录注册,添加头像,大图浏览,裁剪,支持头像,评论,点赞,删除,分享,评论时会显示评论者的头像。
app演示
app主页面
app发帖页
app评论与详情页
主要代码
发帖包括文字图片
```
/**
* 上传图片
*/
private void tv_upload_database() {
//隐藏软硬盘
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
toast("发布中...");
String username=user.getUsername();
final Post post = new Post();
post.setContent(content);
post.setUserName(username);
post.setPraise(0);
post.setTime(getTime());
post.setUserIcon(getIntent().getStringExtra("headUrl"));
if (size == 0) {
post.setHaveIcon(false);
post.save(new SaveListener<String>() {
@Override
public void done(String s, BmobException e) {
if(e==null)
{
et_send.setText("");
toast("yes!发表成功");
finish();
}else {
toast("失败"+e.toString());
}
}
});
return;
}
size = 0;
final String[] filePaths = new String[imageItems.size()];
for (int i = 0; i < imageItems.size(); i++) {
filePaths[i] = imageItems.get(i).path;
}
dialog = new ProgressDialog(EditActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setTitle("上传图片中...");
dialog.setIndeterminate(false);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
BmobFile.uploadBatch(filePaths, new UploadBatchListener() {
@Override
public void onSuccess(List<BmobFile> list, List<String> list1) {
if (list1.size() == filePaths.length) {//如果数量相等,则代表文件全部上传完成
post.setHeadImgUrl(list1);
post.setHaveIcon(true);
post.save(new SaveListener<String>() {
@Override
public void done(String s, BmobException e) {
if (e == null) {
toast("发表成功");
finish();
}
}
});
}
}
@Override
public void onProgress(int i, int i1, int i2, int i3) {
dialog.setProgress(i2);
}
@Override
public void onError(int i, String s) {
dialog.dismiss();
}
});
}
```
查询评论
/*
查询评论
*/
private void findComments() {
showDialog();
BmobQuery<Comment> query = new BmobQuery<Comment>();
list.clear();
Post post = new Post();
post.setObjectId(obj);
query.addWhereEqualTo("post", new BmobPointer(post));
query.include("user,,author,post.author,comment.time,comment.user");
query.findObjects(new FindListener<Comment>() {
@Override
public void done(List<Comment> arg0, BmobException e) {
if (e == null) {
list.addAll(arg0);
//com_num = list.size();
al.dismiss();
adapter.notifyDataSetInvalidated();
} else {
al.dismiss();
toast("查询评论失败" + e.toString());
adapter.notifyDataSetChanged();
}
}
});
}
点赞
/*
点赞
*/
public void updates() {
Post post = new Post();
post.setObjectId(obj);
// TODO Auto-generated method stub
post.increment("praise");
//不知道什么原因点赞后图片会显消失,所以标记一下
post.setHaveIcon(isHaven);
post.update(new UpdateListener() {
@Override
public void done(BmobException e) {
if (e == null) {
toast("点赞成功!");
} else {
toast("点赞失败!");
}
}
});
}
删除帖子(只能删除自己的帖子)
/*
删除帖子
*/
private void del(){
Post p = new Post();
p.setObjectId(obj);
if (this.user.getObjectId().equals(auhthor_url)){
p.delete(new UpdateListener() {
@Override
public void done(BmobException e) {
if(e==null){
toast("删除成功");
CommentActivity.this.finish();
}else{
toast("失败:"+e.getMessage()+","+e.getErrorCode());
}
}
});
}else {
toast("您无权限删除别人发的帖子哦");
}
}
```项目源码下载
附上完整源码,在Bmob官网,希望大家支持一下。有问题可以随时问我哦