帖子详情、回复逻辑完善

0515
panqihua 5 years ago
parent 591d163f55
commit 959a609f03
  1. 9
      app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java
  2. 10
      app/src/main/java/com/community/pocket/data/model/Forum.java
  3. 19
      app/src/main/java/com/community/pocket/data/model/ForumContent.java
  4. 5
      app/src/main/java/com/community/pocket/ui/login/LoginActivity.java
  5. 9
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java
  6. 16
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java
  7. 3
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java
  8. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java
  9. 12
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java
  10. 13
      app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java

@ -28,22 +28,23 @@ public class ForumDataRequest {
//回帖 //回帖
@HttpRequest("/forum/content/reply") @HttpRequest("/forum/content/reply")
public void sendReply(MutableLiveData<ForumDataResponse> liveData, int forumId, String content) { public void sendReply(MutableLiveData<ForumDataResponse> liveData, String forumId, String content) {
HttpUtil.getRequest(HttpUtil.Method.POST, HttpUtil.getRequest(HttpUtil.Method.POST,
new SimpleHttpParse<ForumDataResponse>(liveData).getInterface(ForumDataResponse.class), new SimpleHttpParse<ForumDataResponse>(liveData).getInterface(ForumDataResponse.class),
new FormBody.Builder() new FormBody.Builder()
.add("forumId", String.valueOf(forumId)) .add("forumId", forumId)
.add("content", content) .add("content", content)
.add("token", LocalToken.getToken()) .add("token", LocalToken.getToken())
.add("username", LocalToken.getUsername())
.build() .build()
); );
} }
//获取帖子详情数据 //获取帖子详情数据
@HttpRequest("/forum/content") @HttpRequest("/forum/content")
public void loadData(MutableLiveData<ForumDataResponse> liveData, int forumId) { public void loadData(MutableLiveData<ForumDataResponse> liveData, String forumId) {
HttpUtil.getRequest(HttpUtil.Method.GET, HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<ForumDataResponse>(liveData).getInterface(ForumDataResponse.class), new SimpleHttpParse<ForumDataResponse>(liveData).getInterface(ForumDataResponse.class),
new FormBody.Builder().add("forumId", String.valueOf(forumId)).build()); new FormBody.Builder().add("forumId", forumId).build());
} }
} }

@ -3,7 +3,7 @@ package com.community.pocket.data.model;
//帖子简介内容 //帖子简介内容
public class Forum { public class Forum {
//帖子id //帖子id
private String forumId; private String id;
//发帖人头像 //发帖人头像
private String headImg; private String headImg;
//发帖人 //发帖人
@ -17,12 +17,12 @@ public class Forum {
//回复数 //回复数
private Integer reply; private Integer reply;
public String getForumId() { public String getId() {
return forumId; return id;
} }
public void setForumId(String forumId) { public void setId(String id) {
this.forumId = forumId; this.id = id;
} }
public String getHeadImg() { public String getHeadImg() {

@ -8,14 +8,13 @@ public class ForumContent {
private String headImg; private String headImg;
//用户名 //用户名
private String username; private String username;
//信用分
private Integer score;
//发帖时间 //发帖时间
private Long time; private Long time;
//楼层 //楼层
private Integer tower; private Integer tower;
//帖子正文 //帖子正文
private String content; private String content;
private MyInfo myInfo;
public String getHeadImg() { public String getHeadImg() {
return headImg; return headImg;
@ -33,14 +32,6 @@ public class ForumContent {
this.username = username; this.username = username;
} }
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
public Long getTime() { public Long getTime() {
return time; return time;
} }
@ -64,4 +55,12 @@ public class ForumContent {
public void setContent(String content) { public void setContent(String content) {
this.content = content; this.content = content;
} }
public MyInfo getMyInfo() {
return myInfo;
}
public void setMyInfo(MyInfo myInfo) {
this.myInfo = myInfo;
}
} }

@ -200,6 +200,11 @@ public class LoginActivity extends BaseActivity {
.add("token", currentToken.getToken()) .add("token", currentToken.getToken())
.build() .build()
); );
} else if (tokenList != null && tokenList.size() > 1) {
for (Token token : tokenList) {
sInstance.tokenDao().delete(token);
}
loginViewModel.getCheckToken().postValue(new LoginResponse());
} else { } else {
loginViewModel.getCheckToken().postValue(new LoginResponse()); loginViewModel.getCheckToken().postValue(new LoginResponse());
} }

@ -36,8 +36,9 @@ public abstract class ForumPost extends BaseFragment {
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.size(); i++) { for (int i = 0; i < forumList.size(); i++) {
Forum forum = forumList.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 title = childView.findViewById(R.id.post_title); TextView title = childView.findViewById(R.id.post_title);
@ -63,8 +64,9 @@ public abstract class ForumPost extends BaseFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(getContext(), ForumDataActivity.class); Intent intent = new Intent(getContext(), ForumDataActivity.class);
intent.putExtra(Param.forumId.name(), 1); intent.putExtra(Param.forumId.name(), forum.getId());
startActivity(intent); startActivityForResult(intent, 1);
// startActivity(intent);
} }
}); });
@ -72,4 +74,5 @@ public abstract class ForumPost extends BaseFragment {
} }
} }
} }
} }

@ -1,5 +1,6 @@
package com.community.pocket.ui.main.ui.forum.data; package com.community.pocket.ui.main.ui.forum.data;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -65,17 +66,17 @@ public class ForumDataActivity extends BaseActivity {
private Button openReply; private Button openReply;
//帖子id //帖子id
private int forumId; private String forumId;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumDataViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumDataViewModel.class);
Intent intent = getIntent(); Intent intent = getIntent();
forumId = intent.getIntExtra(Param.forumId.name(), 0); forumId = intent.getStringExtra(Param.forumId.name());
if (forumId == 0) { if (forumId == null) {
Toast.makeText(getApplicationContext(), R.string.forum_data_fail, Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), R.string.forum_data_fail, Toast.LENGTH_LONG).show();
finish(); finish();
} else { } else {
@ -109,6 +110,7 @@ public class ForumDataActivity extends BaseActivity {
if (forumDataResponse.getResult() == Response.Result.OK) { if (forumDataResponse.getResult() == Response.Result.OK) {
handler.sendEmptyMessage(0); handler.sendEmptyMessage(0);
viewModel.loadData(forumId);
} }
} }
}); });
@ -127,7 +129,7 @@ public class ForumDataActivity extends BaseActivity {
List<ForumContent> forumContents = listForumDataResponse.getForumContentList(); List<ForumContent> forumContents = listForumDataResponse.getForumContentList();
initFirst(forumContents.get(0)); initFirst(forumContents.get(0));
if (forumContents.size() > 1) { if (forumContents.size() > 1) {
createReply(forumContents.subList(1, forumContents.size() - 1)); createReply(forumContents.subList(1, forumContents.size()));
} }
} }
} }
@ -201,6 +203,7 @@ public class ForumDataActivity extends BaseActivity {
*/ */
@Event(value = R.id.back) @Event(value = R.id.back)
private void back(View view) { private void back(View view) {
setResult(Activity.RESULT_OK);
finish(); finish();
} }
@ -208,6 +211,7 @@ public class ForumDataActivity extends BaseActivity {
* 创建楼层数据 * 创建楼层数据
*/ */
private void createReply(List<ForumContent> forumContentList) { private void createReply(List<ForumContent> forumContentList) {
replyLayout.removeAllViews();
for (ForumContent forumContent : forumContentList) { for (ForumContent forumContent : forumContentList) {
View view = View.inflate(this, R.layout.forum_data_content, null); View view = View.inflate(this, R.layout.forum_data_content, null);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
@ -226,7 +230,7 @@ public class ForumDataActivity extends BaseActivity {
TextView name = view.findViewById(R.id.name); TextView name = view.findViewById(R.id.name);
name.setText(forumContent.getUsername()); name.setText(forumContent.getUsername());
TextView score = view.findViewById(R.id.score); TextView score = view.findViewById(R.id.score);
score.setText(String.valueOf(forumContent.getScore())); score.setText(String.valueOf(forumContent.getMyInfo().getCreditScore()));
TextView time = view.findViewById(R.id.time); TextView time = view.findViewById(R.id.time);
time.setText(DateFormat.format(getString(R.string.dateformat), forumContent.getTime())); time.setText(DateFormat.format(getString(R.string.dateformat), forumContent.getTime()));
TextView tower = view.findViewById(R.id.tower); TextView tower = view.findViewById(R.id.tower);

@ -30,7 +30,8 @@ public class ForumDataResponse extends Response<ForumDataResponse.Msg> {
ok(R.string.forum_data_ok), ok(R.string.forum_data_ok),
fail(R.string.forum_data_fail), fail(R.string.forum_data_fail),
reply_ok(R.string.forum_reply_ok), reply_ok(R.string.forum_reply_ok),
reply_fail(R.string.forum_reply_fail); reply_fail(R.string.forum_reply_fail),
token(R.string.invalid_token);
private Integer msg; private Integer msg;

@ -50,7 +50,7 @@ public class ForumDataViewModel extends BaseViewModel<ForumDataRequest> {
* @param forumId 帖子id * @param forumId 帖子id
* @param content 内容 * @param content 内容
*/ */
void sendReply(int forumId, String content) { void sendReply(String forumId, String content) {
getRequest().sendReply(replayResponse, forumId, content); getRequest().sendReply(replayResponse, forumId, content);
} }
@ -59,7 +59,7 @@ public class ForumDataViewModel extends BaseViewModel<ForumDataRequest> {
* *
* @param forumId 帖子id * @param forumId 帖子id
*/ */
void loadData(int forumId) { void loadData(String forumId) {
getRequest().loadData(forumContentResponse, forumId); getRequest().loadData(forumContentResponse, forumId);
} }

@ -1,5 +1,6 @@
package com.community.pocket.ui.main.ui.forum.my; package com.community.pocket.ui.main.ui.forum.my;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
@ -20,11 +21,13 @@ import org.xutils.view.annotation.ContentView;
@ContentView(R.layout.forum_my_fragment) @ContentView(R.layout.forum_my_fragment)
public class ForumMyFragment extends ForumPost { public class ForumMyFragment extends ForumPost {
private ForumMyViewModel viewModel;
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
ForumMyViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class);
viewModel.loadForumMy(); viewModel.loadForumMy();
@ -49,4 +52,11 @@ public class ForumMyFragment extends ForumPost {
protected int own() { protected int own() {
return View.GONE; return View.GONE;
} }
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
viewModel.loadForumMy();
}
} }

@ -1,5 +1,6 @@
package com.community.pocket.ui.main.ui.forum.news; package com.community.pocket.ui.main.ui.forum.news;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
@ -20,11 +21,13 @@ import org.xutils.view.annotation.ContentView;
@ContentView(R.layout.forum_new_fragment) @ContentView(R.layout.forum_new_fragment)
public class ForumNewFragment extends ForumPost { public class ForumNewFragment extends ForumPost {
private ForumNewViewModel viewModel;
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
ForumNewViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumNewViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumNewViewModel.class);
viewModel.loadForumNew(); viewModel.loadForumNew();
@ -49,4 +52,12 @@ public class ForumNewFragment extends ForumPost {
protected int own() { protected int own() {
return View.VISIBLE; return View.VISIBLE;
} }
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
viewModel.loadForumNew();
}
} }

Loading…
Cancel
Save