完善帖子逻辑

0515
panqihua 5 years ago
parent 3c4aa20b44
commit 82a5f22852
  1. 2
      app/build.gradle
  2. 4
      app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java
  3. 11
      app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java
  4. 44
      app/src/main/java/com/community/pocket/data/model/Active.java
  5. 24
      app/src/main/java/com/community/pocket/data/model/Complain.java
  6. 93
      app/src/main/java/com/community/pocket/data/model/Forum.java
  7. 10
      app/src/main/java/com/community/pocket/data/model/ForumStatus.java
  8. 7
      app/src/main/java/com/community/pocket/data/model/ForumType.java
  9. 62
      app/src/main/java/com/community/pocket/data/model/Page.java
  10. 32
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java
  11. 11
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java
  12. 9
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyResponse.java
  13. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java
  14. 10
      app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java
  15. 9
      app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewResponse.java
  16. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewViewModel.java
  17. 11
      app/src/main/res/layout/main/layout/forum/layout/post.xml
  18. 3
      app/src/main/res/values-en-rUS/strings.xml
  19. 3
      app/src/main/res/values-zh-rCN/strings.xml
  20. 3
      app/src/main/res/values/strings.xml

@ -39,6 +39,7 @@ android {
buildConfigField('String','API_HOST',"\""+RAP2_API_HOST+"\"") buildConfigField('String','API_HOST',"\""+RAP2_API_HOST+"\"")
signingConfig=signingConfigs.debug signingConfig=signingConfigs.debug
debuggable = true
} }
release { release {
@ -53,6 +54,7 @@ android {
buildConfigField('String','API_HOST',"\""+API_HOST+"\"") buildConfigField('String','API_HOST',"\""+API_HOST+"\"")
signingConfig=signingConfigs.debug signingConfig=signingConfigs.debug
debuggable = true
} }
} }
sourceSets { sourceSets {

@ -31,11 +31,11 @@ public class ForumMyRequest {
* 加载我的帖子 * 加载我的帖子
*/ */
@HttpRequest("/forum/my") @HttpRequest("/forum/my")
public void loadForumMy(MutableLiveData<ForumMyResponse> liveData) { public void loadForumMy(MutableLiveData<ForumMyResponse> liveData, int page) {
HttpUtil.getRequest(HttpUtil.Method.GET, HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<ForumMyResponse>(liveData).getInterface(ForumMyResponse.class), new SimpleHttpParse<ForumMyResponse>(liveData).getInterface(ForumMyResponse.class),
new FormBody.Builder() new FormBody.Builder()
.add("token", LocalToken.getToken()) .add("currentPage", String.valueOf(page))
.add("username", LocalToken.getUsername()) .add("username", LocalToken.getUsername())
.build()); .build());
} }

@ -2,11 +2,14 @@ package com.community.pocket.data.main.forum;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import com.community.pocket.data.model.ForumStatus;
import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse; import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse;
import com.community.pocket.util.HttpRequest; import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil; import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse; import com.community.pocket.util.SimpleHttpParse;
import okhttp3.FormBody;
/** /**
* 最新帖子列表数据接口 * 最新帖子列表数据接口
*/ */
@ -24,8 +27,12 @@ public class ForumNewRequest {
} }
@HttpRequest("/forum/new") @HttpRequest("/forum/new")
public void loadForumNew(MutableLiveData<ForumNewResponse> liveData) { public void loadForumNew(MutableLiveData<ForumNewResponse> liveData, int page) {
HttpUtil.getRequest(HttpUtil.Method.GET, HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<ForumNewResponse>(liveData).getInterface(ForumNewResponse.class)); new SimpleHttpParse<ForumNewResponse>(liveData).getInterface(ForumNewResponse.class),
new FormBody.Builder()
.add("status", ForumStatus.ok.name())
.add("currentPage", String.valueOf(page))
.build());
} }
} }

@ -0,0 +1,44 @@
package com.community.pocket.data.model;
public class Active {
//帖子id
private String id;
//活动开始时间
private String activeStartTime;
//活动结束时间
private String activeEndTime;
//活动信用分
private String activeScore;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getActiveStartTime() {
return activeStartTime;
}
public void setActiveStartTime(String activeStartTime) {
this.activeStartTime = activeStartTime;
}
public String getActiveEndTime() {
return activeEndTime;
}
public void setActiveEndTime(String activeEndTime) {
this.activeEndTime = activeEndTime;
}
public String getActiveScore() {
return activeScore;
}
public void setActiveScore(String activeScore) {
this.activeScore = activeScore;
}
}

@ -0,0 +1,24 @@
package com.community.pocket.data.model;
public class Complain {
private String id;
//投诉人
private String complain;
public String getComplain() {
return complain;
}
public void setComplain(String complain) {
this.complain = complain;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

@ -2,51 +2,50 @@ package com.community.pocket.data.model;
//帖子简介内容 //帖子简介内容
public class Forum { public class Forum {
//帖子id //帖子
private String id; private String id;
//发帖人头像
private String headImg;
//发帖人
private String username;
//发帖时间
private Long time;
//帖子标题 //帖子标题
private String title; private String title;
//帖子内容
private String content;
//回复数 //回复数
private Integer reply; private Integer reply;
//帖子类型
private ForumType forumType;
//缩略内容
private String content;
//发帖人
private String username;
//发帖时间
private Long time;
//审核状态
private ForumStatus status;
public String getId() { //其他信息
return id; private Active activeDto;
}
public void setId(String id) { private Complain complainDto;
this.id = id;
}
public String getHeadImg() { public Active getActiveDto() {
return headImg; return activeDto;
} }
public void setHeadImg(String headImg) { public void setActiveDto(Active activeDto) {
this.headImg = headImg; this.activeDto = activeDto;
} }
public String getUsername() { public Complain getComplainDto() {
return username; return complainDto;
} }
public void setUsername(String username) { public void setComplainDto(Complain complainDto) {
this.username = username; this.complainDto = complainDto;
} }
public Long getTime() { public String getId() {
return time; return id;
} }
public void setTime(Long time) { public void setId(String id) {
this.time = time; this.id = id;
} }
public String getTitle() { public String getTitle() {
@ -57,6 +56,22 @@ public class Forum {
this.title = title; this.title = title;
} }
public Integer getReply() {
return reply;
}
public void setReply(Integer reply) {
this.reply = reply;
}
public ForumType getForumType() {
return forumType;
}
public void setForumType(ForumType forumType) {
this.forumType = forumType;
}
public String getContent() { public String getContent() {
return content; return content;
} }
@ -65,11 +80,27 @@ public class Forum {
this.content = content; this.content = content;
} }
public Integer getReply() { public String getUsername() {
return reply; return username;
} }
public void setReply(Integer reply) { public void setUsername(String username) {
this.reply = reply; this.username = username;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public ForumStatus getStatus() {
return status;
}
public void setStatus(ForumStatus status) {
this.status = status;
} }
} }

@ -0,0 +1,10 @@
package com.community.pocket.data.model;
/**
* 审核状态
*/
public enum ForumStatus {
uncheck,
ok,
fail
}

@ -0,0 +1,7 @@
package com.community.pocket.data.model;
public enum ForumType {
active,
topic,
complan
}

@ -0,0 +1,62 @@
package com.community.pocket.data.model;
import java.util.List;
//分页数据
public class Page<T> {
//总记录数
private Long count;
//总页数
private Long totalPage;
//当前页数
private Long currentPage;
//数据集合
private List<T> list;
//分页大小
private Integer pageSize;
public Integer getPageSize() {
return pageSize;
}
public Long getCount() {
return count;
}
public Long getTotalPage() {
return totalPage;
}
public Long getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Long currentPage) {
this.currentPage = currentPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public void setCount(Long count) {
this.count = count;
}
public void setTotalPage(Long totalPage) {
this.totalPage = totalPage;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public boolean isEmpty() {
return this.count == 0;
}
}

@ -11,19 +11,20 @@ import android.widget.Toast;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.Forum;
import com.community.pocket.data.model.Page;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.main.ui.forum.data.ForumDataActivity; import com.community.pocket.ui.main.ui.forum.data.ForumDataActivity;
import com.community.pocket.util.Param; import com.community.pocket.util.Param;
import org.xutils.view.annotation.ViewInject; import org.xutils.view.annotation.ViewInject;
import java.util.List;
public abstract class ForumPost extends BaseFragment { public abstract class ForumPost extends BaseFragment {
//显示发帖人
protected abstract int showAuthor();
protected abstract int own(); //显示审核状态
protected abstract int showStatus();
@ViewInject(R.id.post_layout) @ViewInject(R.id.post_layout)
private LinearLayout layout; private LinearLayout layout;
@ -31,22 +32,35 @@ public abstract class ForumPost extends BaseFragment {
/** /**
* 加载帖子数据 * 加载帖子数据
*/ */
protected void loadPost(List<Forum> forumList) { protected void loadPost(Page<Forum> forumList) {
if (forumList.isEmpty()) { if (forumList.isEmpty()) {
Toast.makeText(getContext(), R.string.no_more_forum, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), R.string.no_more_forum, Toast.LENGTH_LONG).show();
} else { } else {
layout.removeAllViews(); for (int i = 0; i < forumList.getList().size(); i++) {
for (int i = 0; i < forumList.size(); i++) { final Forum forum = forumList.getList().get(i);
final Forum forum = forumList.get(i);
View childView = View.inflate(getContext(), R.layout.post, null); View childView = View.inflate(getContext(), R.layout.post, null);
TextView status = childView.findViewById(R.id.check_status);
status.setVisibility(showStatus());
switch (forum.getStatus()) {
case ok:
status.setText(R.string.forum_status_ok);
break;
case fail:
status.setText(R.string.forum_status_fail);
break;
case uncheck:
status.setText(R.string.forum_status_uncheck);
break;
}
TextView title = childView.findViewById(R.id.post_title); TextView title = childView.findViewById(R.id.post_title);
title.setText(forum.getTitle()); title.setText(forum.getTitle());
TextView content = childView.findViewById(R.id.post_content); TextView content = childView.findViewById(R.id.post_content);
content.setText(forum.getContent()); content.setText(forum.getContent());
TextView author = childView.findViewById(R.id.poster); TextView author = childView.findViewById(R.id.poster);
author.setVisibility(own()); author.setVisibility(showAuthor());
author.setText(getString(R.string.poster, forum.getUsername())); author.setText(getString(R.string.poster, forum.getUsername()));
TextView postReply = childView.findViewById(R.id.post_reply); TextView postReply = childView.findViewById(R.id.post_reply);

@ -29,7 +29,7 @@ public class ForumMyFragment extends ForumPost {
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class);
viewModel.loadForumMy(); viewModel.loadForumMy(1);
//监听我的帖子加载状态 //监听我的帖子加载状态
viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), new Observer<ForumMyResponse>() { viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), new Observer<ForumMyResponse>() {
@ -49,14 +49,19 @@ public class ForumMyFragment extends ForumPost {
} }
@Override @Override
protected int own() { protected int showAuthor() {
return View.GONE; return View.GONE;
} }
@Override
protected int showStatus() {
return View.VISIBLE;
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
viewModel.loadForumMy(); viewModel.loadForumMy(1);
} }
} }

@ -4,21 +4,20 @@ import androidx.annotation.StringRes;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.Forum;
import com.community.pocket.data.model.Page;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.util.CustomMessage; import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
public class ForumMyResponse extends Response<ForumMyResponse.Msg> { public class ForumMyResponse extends Response<ForumMyResponse.Msg> {
private List<Forum> forumList; private Page<Forum> forumList;
List<Forum> getForumList() { Page<Forum> getForumList() {
return forumList; return forumList;
} }
public void setForumList(List<Forum> forumList) { public void setForumList(Page<Forum> forumList) {
this.forumList = forumList; this.forumList = forumList;
} }

@ -15,8 +15,8 @@ public class ForumMyViewModel extends BaseViewModel<ForumMyRequest> {
return forumMyResponse; return forumMyResponse;
} }
void loadForumMy() { void loadForumMy(int page) {
getRequest().loadForumMy(forumMyResponse); getRequest().loadForumMy(forumMyResponse, page);
} }
@Override @Override

@ -29,7 +29,7 @@ public class ForumNewFragment extends ForumPost {
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumNewViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumNewViewModel.class);
viewModel.loadForumNew(); viewModel.loadForumNew(1);
//监听最新帖子请求状态 //监听最新帖子请求状态
viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), new Observer<ForumNewResponse>() { viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), new Observer<ForumNewResponse>() {
@ -49,15 +49,19 @@ public class ForumNewFragment extends ForumPost {
} }
@Override @Override
protected int own() { protected int showAuthor() {
return View.VISIBLE; return View.VISIBLE;
} }
@Override
protected int showStatus() {
return View.GONE;
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
viewModel.loadForumNew(); viewModel.loadForumNew(1);
} }
} }

@ -4,18 +4,17 @@ import androidx.annotation.StringRes;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.Forum;
import com.community.pocket.data.model.Page;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.util.CustomMessage; import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
/** /**
* 最新帖子响应实体 * 最新帖子响应实体
*/ */
public class ForumNewResponse extends Response<ForumNewResponse.Msg> { public class ForumNewResponse extends Response<ForumNewResponse.Msg> {
private List<Forum> forumList; private Page<Forum> forumList;
enum Msg implements CustomMessage { enum Msg implements CustomMessage {
ok(R.string.load_forum_new_ok), ok(R.string.load_forum_new_ok),
@ -35,11 +34,11 @@ public class ForumNewResponse extends Response<ForumNewResponse.Msg> {
} }
} }
List<Forum> getForumList() { Page<Forum> getForumList() {
return forumList; return forumList;
} }
public void setForumList(List<Forum> forumList) { public void setForumList(Page<Forum> forumList) {
this.forumList = forumList; this.forumList = forumList;
} }
} }

@ -17,8 +17,8 @@ public class ForumNewViewModel extends BaseViewModel<ForumNewRequest> {
return forumNewResponse; return forumNewResponse;
} }
void loadForumNew() { void loadForumNew(int page) {
getRequest().loadForumNew(forumNewResponse); getRequest().loadForumNew(forumNewResponse, page);
} }
@Override @Override

@ -5,6 +5,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/border"> android:background="@drawable/border">
<TextView
android:id="@+id/check_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/post_title" android:id="@+id/post_title"
android:layout_width="0dp" android:layout_width="0dp"
@ -13,7 +22,7 @@
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@id/check_status" />
<ImageView <ImageView
android:id="@+id/headimg" android:id="@+id/headimg"

@ -172,4 +172,7 @@
<string name="modify_oldpwd_fail">modify error</string> <string name="modify_oldpwd_fail">modify error</string>
<string name="prompt_choose_date">please choose date</string> <string name="prompt_choose_date">please choose date</string>
<string name="visitor_invalid_date">date error</string> <string name="visitor_invalid_date">date error</string>
<string name="forum_status_ok">check ok</string>
<string name="forum_status_fail">check fail</string>
<string name="forum_status_uncheck">uncheck</string>
</resources> </resources>

@ -172,4 +172,7 @@
<string name="modify_oldpwd_fail">修改密码失败,原密码不正确</string> <string name="modify_oldpwd_fail">修改密码失败,原密码不正确</string>
<string name="prompt_choose_date">请选择预约日期</string> <string name="prompt_choose_date">请选择预约日期</string>
<string name="visitor_invalid_date">上门日期不能是%1s以前</string> <string name="visitor_invalid_date">上门日期不能是%1s以前</string>
<string name="forum_status_ok">审核通过</string>
<string name="forum_status_fail">审核不通过</string>
<string name="forum_status_uncheck">未审核</string>
</resources> </resources>

@ -173,6 +173,9 @@
<string name="modify_oldpwd_fail">modify error</string> <string name="modify_oldpwd_fail">modify error</string>
<string name="prompt_choose_date">please choose date</string> <string name="prompt_choose_date">please choose date</string>
<string name="visitor_invalid_date">date error</string> <string name="visitor_invalid_date">date error</string>
<string name="forum_status_ok">check ok</string>
<string name="forum_status_fail">check fail</string>
<string name="forum_status_uncheck">uncheck</string>
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save