帖子详情、回复逻辑完善

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")
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,
new SimpleHttpParse<ForumDataResponse>(liveData).getInterface(ForumDataResponse.class),
new FormBody.Builder()
.add("forumId", String.valueOf(forumId))
.add("forumId", forumId)
.add("content", content)
.add("token", LocalToken.getToken())
.add("username", LocalToken.getUsername())
.build()
);
}
//获取帖子详情数据
@HttpRequest("/forum/content")
public void loadData(MutableLiveData<ForumDataResponse> liveData, int forumId) {
public void loadData(MutableLiveData<ForumDataResponse> liveData, String forumId) {
HttpUtil.getRequest(HttpUtil.Method.GET,
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 {
//帖子id
private String forumId;
private String id;
//发帖人头像
private String headImg;
//发帖人
@ -17,12 +17,12 @@ public class Forum {
//回复数
private Integer reply;
public String getForumId() {
return forumId;
public String getId() {
return id;
}
public void setForumId(String forumId) {
this.forumId = forumId;
public void setId(String id) {
this.id = id;
}
public String getHeadImg() {

@ -8,14 +8,13 @@ public class ForumContent {
private String headImg;
//用户名
private String username;
//信用分
private Integer score;
//发帖时间
private Long time;
//楼层
private Integer tower;
//帖子正文
private String content;
private MyInfo myInfo;
public String getHeadImg() {
return headImg;
@ -33,14 +32,6 @@ public class ForumContent {
this.username = username;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
public Long getTime() {
return time;
}
@ -64,4 +55,12 @@ public class ForumContent {
public void setContent(String 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())
.build()
);
} else if (tokenList != null && tokenList.size() > 1) {
for (Token token : tokenList) {
sInstance.tokenDao().delete(token);
}
loginViewModel.getCheckToken().postValue(new LoginResponse());
} else {
loginViewModel.getCheckToken().postValue(new LoginResponse());
}

@ -36,8 +36,9 @@ public abstract class ForumPost extends BaseFragment {
if (forumList.isEmpty()) {
Toast.makeText(getContext(), R.string.no_more_forum, Toast.LENGTH_LONG).show();
} else {
layout.removeAllViews();
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);
TextView title = childView.findViewById(R.id.post_title);
@ -63,8 +64,9 @@ public abstract class ForumPost extends BaseFragment {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), ForumDataActivity.class);
intent.putExtra(Param.forumId.name(), 1);
startActivity(intent);
intent.putExtra(Param.forumId.name(), forum.getId());
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;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
@ -65,17 +66,17 @@ public class ForumDataActivity extends BaseActivity {
private Button openReply;
//帖子id
private int forumId;
private String forumId;
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumDataViewModel.class);
Intent intent = getIntent();
forumId = intent.getIntExtra(Param.forumId.name(), 0);
if (forumId == 0) {
forumId = intent.getStringExtra(Param.forumId.name());
if (forumId == null) {
Toast.makeText(getApplicationContext(), R.string.forum_data_fail, Toast.LENGTH_LONG).show();
finish();
} else {
@ -109,6 +110,7 @@ public class ForumDataActivity extends BaseActivity {
if (forumDataResponse.getResult() == Response.Result.OK) {
handler.sendEmptyMessage(0);
viewModel.loadData(forumId);
}
}
});
@ -127,7 +129,7 @@ public class ForumDataActivity extends BaseActivity {
List<ForumContent> forumContents = listForumDataResponse.getForumContentList();
initFirst(forumContents.get(0));
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)
private void back(View view) {
setResult(Activity.RESULT_OK);
finish();
}
@ -208,6 +211,7 @@ public class ForumDataActivity extends BaseActivity {
* 创建楼层数据
*/
private void createReply(List<ForumContent> forumContentList) {
replyLayout.removeAllViews();
for (ForumContent forumContent : forumContentList) {
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);
@ -226,7 +230,7 @@ public class ForumDataActivity extends BaseActivity {
TextView name = view.findViewById(R.id.name);
name.setText(forumContent.getUsername());
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);
time.setText(DateFormat.format(getString(R.string.dateformat), forumContent.getTime()));
TextView tower = view.findViewById(R.id.tower);

@ -30,7 +30,8 @@ public class ForumDataResponse extends Response<ForumDataResponse.Msg> {
ok(R.string.forum_data_ok),
fail(R.string.forum_data_fail),
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;

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

@ -1,5 +1,6 @@
package com.community.pocket.ui.main.ui.forum.my;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@ -20,11 +21,13 @@ import org.xutils.view.annotation.ContentView;
@ContentView(R.layout.forum_my_fragment)
public class ForumMyFragment extends ForumPost {
private ForumMyViewModel viewModel;
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle 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();
@ -49,4 +52,11 @@ public class ForumMyFragment extends ForumPost {
protected int own() {
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;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@ -20,11 +21,13 @@ import org.xutils.view.annotation.ContentView;
@ContentView(R.layout.forum_new_fragment)
public class ForumNewFragment extends ForumPost {
private ForumNewViewModel viewModel;
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle 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();
@ -49,4 +52,12 @@ public class ForumNewFragment extends ForumPost {
protected int own() {
return View.VISIBLE;
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
viewModel.loadForumNew();
}
}

Loading…
Cancel
Save