From 959a609f03b7e38a96eb8f0c6b8210da08f60a94 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Fri, 10 Apr 2020 11:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=96=E5=AD=90=E8=AF=A6=E6=83=85=E3=80=81?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E9=80=BB=E8=BE=91=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/main/forum/ForumDataRequest.java | 9 +++++---- .../community/pocket/data/model/Forum.java | 10 +++++----- .../pocket/data/model/ForumContent.java | 19 +++++++++---------- .../pocket/ui/login/LoginActivity.java | 5 +++++ .../pocket/ui/main/ui/forum/ForumPost.java | 9 ++++++--- .../main/ui/forum/data/ForumDataActivity.java | 16 ++++++++++------ .../main/ui/forum/data/ForumDataResponse.java | 3 ++- .../ui/forum/data/ForumDataViewModel.java | 4 ++-- .../ui/main/ui/forum/my/ForumMyFragment.java | 12 +++++++++++- .../main/ui/forum/news/ForumNewFragment.java | 13 ++++++++++++- 10 files changed, 67 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java index 90a00a8..d5c2dfd 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumDataRequest.java @@ -28,22 +28,23 @@ public class ForumDataRequest { //回帖 @HttpRequest("/forum/content/reply") - public void sendReply(MutableLiveData liveData, int forumId, String content) { + public void sendReply(MutableLiveData liveData, String forumId, String content) { HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse(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 liveData, int forumId) { + public void loadData(MutableLiveData liveData, String forumId) { HttpUtil.getRequest(HttpUtil.Method.GET, new SimpleHttpParse(liveData).getInterface(ForumDataResponse.class), - new FormBody.Builder().add("forumId", String.valueOf(forumId)).build()); + new FormBody.Builder().add("forumId", forumId).build()); } } diff --git a/app/src/main/java/com/community/pocket/data/model/Forum.java b/app/src/main/java/com/community/pocket/data/model/Forum.java index 736179d..e56ce11 100644 --- a/app/src/main/java/com/community/pocket/data/model/Forum.java +++ b/app/src/main/java/com/community/pocket/data/model/Forum.java @@ -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() { diff --git a/app/src/main/java/com/community/pocket/data/model/ForumContent.java b/app/src/main/java/com/community/pocket/data/model/ForumContent.java index e496f9b..65faebc 100644 --- a/app/src/main/java/com/community/pocket/data/model/ForumContent.java +++ b/app/src/main/java/com/community/pocket/data/model/ForumContent.java @@ -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; + } } diff --git a/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java b/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java index 6262464..33a2e24 100644 --- a/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java +++ b/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java @@ -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()); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java index a6e57cb..8b7f979 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java @@ -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 { } } } + } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java index d7c411d..3252f67 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java @@ -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 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 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); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java index 61395e8..b1f56e8 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataResponse.java @@ -30,7 +30,8 @@ public class ForumDataResponse extends Response { 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; diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java index cd1d244..0434b21 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataViewModel.java @@ -50,7 +50,7 @@ public class ForumDataViewModel extends BaseViewModel { * @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 { * * @param forumId 帖子id */ - void loadData(int forumId) { + void loadData(String forumId) { getRequest().loadData(forumContentResponse, forumId); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java index d4c6029..83cd6cd 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java @@ -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(); + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java index d2f4d1d..4b31720 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java @@ -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(); + } }