diff --git a/app/build.gradle b/app/build.gradle index a385347..08f48dc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,19 +26,21 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + vectorDrawables.useSupportLibrary = true } buildTypes { - debug{ - buildConfigField('String','API_HOST',"\""+RAP2_API_HOST+"\"") + debug { + buildConfigField('String', 'API_HOST', "\"" + RAP2_API_HOST + "\"") - signingConfig=signingConfigs.debug + signingConfig = signingConfigs.debug } rap2debug { - buildConfigField('String','API_HOST',"\""+RAP2_API_HOST+"\"") + buildConfigField('String', 'API_HOST', "\"" + RAP2_API_HOST + "\"") - signingConfig=signingConfigs.debug + signingConfig = signingConfigs.debug debuggable = true } @@ -46,14 +48,14 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - buildConfigField('String','API_HOST',"\""+API_HOST+"\"") + buildConfigField('String', 'API_HOST', "\"" + API_HOST + "\"") - signingConfig=signingConfigs.debug + signingConfig = signingConfigs.debug } serverdebug { - buildConfigField('String','API_HOST',"\""+API_HOST+"\"") + buildConfigField('String', 'API_HOST', "\"" + API_HOST + "\"") - signingConfig=signingConfigs.debug + signingConfig = signingConfigs.debug debuggable = true } } @@ -64,8 +66,8 @@ android { 'src/main/res/layout/main', 'src/main/res/layout/main/layout', 'src/main/res/layout/main/layout/forum', 'src/main/res/layout/main/layout/forum/layout', 'src/main/res/layout/main/layout/visitor', 'src/main/res/layout/main/layout/visitor/layout', - 'src/main/res/layout/main/layout/info','src/main/res/layout/main/layout/info/layout', - 'src/main/res/layout/main/layout/garbage','src/main/res/layout/main/layout/garbage/layout' + 'src/main/res/layout/main/layout/info', 'src/main/res/layout/main/layout/info/layout', + 'src/main/res/layout/main/layout/garbage', 'src/main/res/layout/main/layout/garbage/layout' } } } @@ -102,7 +104,8 @@ dependencies { def room_version = '2.2.5' implementation "androidx.room:room-runtime:$room_version" - annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor + annotationProcessor "androidx.room:room-compiler:$room_version" + // For Kotlin use kapt instead of annotationProcessor // Test helpers testImplementation "androidx.room:room-testing:$room_version" diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java index b2f1248..c0024cd 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumNewRequest.java @@ -3,6 +3,7 @@ package com.community.pocket.data.main.forum; import androidx.lifecycle.MutableLiveData; import com.community.pocket.data.model.ForumStatus; +import com.community.pocket.data.model.ForumType; import com.community.pocket.ui.main.ui.forum.news.ForumNewResponse; import com.community.pocket.util.HttpRequest; import com.community.pocket.util.HttpUtil; @@ -33,6 +34,9 @@ public class ForumNewRequest { new FormBody.Builder() .add("status", ForumStatus.ok.name()) .add("currentPage", String.valueOf(page)) + .add("forumType", ForumType.active.name()) + .add("forumType", ForumType.score.name()) + .add("forumType", ForumType.topic.name()) .build()); } } diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java index 3d70e80..b4df0fa 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumPostRequest.java @@ -3,6 +3,7 @@ package com.community.pocket.data.main.forum; import androidx.lifecycle.MutableLiveData; +import com.community.pocket.data.model.ForumType; import com.community.pocket.data.model.LocalToken; import com.community.pocket.ui.main.ui.forum.post.ForumPostResponse; import com.community.pocket.ui.main.ui.forum.post.QueryUserResponse; @@ -30,17 +31,19 @@ public class ForumPostRequest { //发送活动贴 @HttpRequest("/forum/sendActive") - public void sendActive(MutableLiveData liveData, String title, String content, String activeStartTime, String activeEndTime, String activeScore) { + public void sendActive(MutableLiveData liveData, String title, String content, String activeStartTime, String activeEndTime, String activeScore, String registrationDeadline) { HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse(liveData).getInterface(ForumPostResponse.class), new FormBody.Builder() .add("title", title) .add("content", content) + .add("registrationDeadline", registrationDeadline) .add("activeStartTime", activeStartTime) .add("activeEndTime", activeEndTime) .add("activeScore", activeScore) .add("token", LocalToken.getToken()) .add("username", LocalToken.getUsername()) + .add("forumType", ForumType.active.name()) .build()); } @@ -55,6 +58,7 @@ public class ForumPostRequest { .add("complain", complain) .add("token", LocalToken.getToken()) .add("username", LocalToken.getUsername()) + .add("forumType", ForumType.complan.name()) .build()); } @@ -68,6 +72,7 @@ public class ForumPostRequest { .add("content", content) .add("token", LocalToken.getToken()) .add("username", LocalToken.getUsername()) + .add("forumType", ForumType.topic.name()) .build()); } @@ -81,4 +86,19 @@ public class ForumPostRequest { .add("username", LocalToken.getUsername()) .build()); } + + //发送结算贴 + @HttpRequest("/forum/sendScore") + public void sendScore(MutableLiveData liveData, String title, String content, String activeScore) { + HttpUtil.getRequest(HttpUtil.Method.POST, + new SimpleHttpParse(liveData).getInterface(ForumPostResponse.class), + new FormBody.Builder() + .add("title", title) + .add("content", content) + .add("activeScore", activeScore) + .add("token", LocalToken.getToken()) + .add("username", LocalToken.getUsername()) + .add("forumType", ForumType.score.name()) + .build()); + } } diff --git a/app/src/main/java/com/community/pocket/data/model/Active.java b/app/src/main/java/com/community/pocket/data/model/Active.java index 253dd12..fcb7de9 100644 --- a/app/src/main/java/com/community/pocket/data/model/Active.java +++ b/app/src/main/java/com/community/pocket/data/model/Active.java @@ -3,12 +3,14 @@ package com.community.pocket.data.model; public class Active { //帖子id private String id; + //报名截止日期 + private String registrationDeadline; //活动开始时间 private String activeStartTime; //活动结束时间 private String activeEndTime; //活动信用分 - private String activeScore; + private Integer activeScore; public String getId() { return id; @@ -18,6 +20,14 @@ public class Active { this.id = id; } + public String getRegistrationDeadline() { + return registrationDeadline; + } + + public void setRegistrationDeadline(String registrationDeadline) { + this.registrationDeadline = registrationDeadline; + } + public String getActiveStartTime() { return activeStartTime; } @@ -34,11 +44,11 @@ public class Active { this.activeEndTime = activeEndTime; } - public String getActiveScore() { + public Integer getActiveScore() { return activeScore; } - public void setActiveScore(String activeScore) { + public void setActiveScore(Integer activeScore) { this.activeScore = activeScore; } } \ No newline at end of file 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 ecd5bf6..632ff32 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 @@ -24,6 +24,8 @@ public class Forum { private Complain complainDto; + private Score score; + public Active getActiveDto() { return activeDto; } @@ -103,4 +105,12 @@ public class Forum { public void setStatus(ForumStatus status) { this.status = status; } + + public Score getScore() { + return score; + } + + public void setScore(Score score) { + this.score = score; + } } 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 65faebc..d734406 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 @@ -14,7 +14,7 @@ public class ForumContent { private Integer tower; //帖子正文 private String content; - private MyInfo myInfo; + private MyInfo info; public String getHeadImg() { return headImg; @@ -56,11 +56,11 @@ public class ForumContent { this.content = content; } - public MyInfo getMyInfo() { - return myInfo; + public MyInfo getInfo() { + return info; } - public void setMyInfo(MyInfo myInfo) { - this.myInfo = myInfo; + public void setInfo(MyInfo info) { + this.info = info; } } diff --git a/app/src/main/java/com/community/pocket/data/model/ForumType.java b/app/src/main/java/com/community/pocket/data/model/ForumType.java index 0d61754..67e1bf0 100644 --- a/app/src/main/java/com/community/pocket/data/model/ForumType.java +++ b/app/src/main/java/com/community/pocket/data/model/ForumType.java @@ -1,7 +1,15 @@ package com.community.pocket.data.model; +/** + * 帖子类型 + */ public enum ForumType { + //悬赏 active, + //话题 topic, - complan + //投诉 + complan, + //结算 + score } diff --git a/app/src/main/java/com/community/pocket/data/model/Score.java b/app/src/main/java/com/community/pocket/data/model/Score.java new file mode 100644 index 0000000..6d41ce9 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/Score.java @@ -0,0 +1,26 @@ +package com.community.pocket.data.model; + +/** + * 结算贴 + */ +public class Score { + private String id; + //结算分数 + private Integer activeScore; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Integer getActiveScore() { + return activeScore; + } + + public void setActiveScore(Integer activeScore) { + this.activeScore = activeScore; + } +} 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 2859185..c690e60 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 @@ -37,6 +37,7 @@ public abstract class ForumPost extends BaseFragment { if (forumList.isEmpty()) { Toast.makeText(getContext(), R.string.no_more_forum, Toast.LENGTH_LONG).show(); } else { + layout.removeViews(1, layout.getChildCount() - 1); for (int i = 0; i < forumList.getList().size(); i++) { final Forum forum = forumList.getList().get(i); 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 3252f67..8470971 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 @@ -19,11 +19,16 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.widget.NestedScrollView; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; +import com.community.pocket.data.model.Active; +import com.community.pocket.data.model.Complain; +import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.ForumContent; +import com.community.pocket.data.model.Score; import com.community.pocket.ui.BaseActivity; import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.main.ui.share.Response; @@ -61,6 +66,10 @@ public class ForumDataActivity extends BaseActivity { //弹窗控制 private Handler handler; + //帖子类型信息 + @ViewInject(R.id.other_content) + private LinearLayout otherContent; + //打开回贴弹窗按钮 @ViewInject(R.id.open_reply) private Button openReply; @@ -68,6 +77,10 @@ public class ForumDataActivity extends BaseActivity { //帖子id private String forumId; + //滚动布局 + @ViewInject(R.id.scrollview) + private NestedScrollView scrollView; + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -127,7 +140,7 @@ public class ForumDataActivity extends BaseActivity { if (listForumDataResponse.getResult() == Response.Result.OK) { List forumContents = listForumDataResponse.getForumContentList(); - initFirst(forumContents.get(0)); + initFirst(forumContents.get(0), listForumDataResponse.getForum()); if (forumContents.size() > 1) { createReply(forumContents.subList(1, forumContents.size())); } @@ -194,8 +207,45 @@ public class ForumDataActivity extends BaseActivity { /** * 初始化第一楼数据 */ - private void initFirst(ForumContent forumContent) { + private void initFirst(ForumContent forumContent, Forum forum) { setData(firstLayout, forumContent); + + if (forum != null) { + View childView = null; + switch (forum.getForumType()) { + case active: { + Active active = forum.getActiveDto(); + childView = View.inflate(getApplicationContext(), R.layout.forum_data_active_content, null); + TextView deadline = childView.findViewById(R.id.registration_deadline); + deadline.setText(getString(R.string.forum_show_registration_deadline, active.getRegistrationDeadline())); + TextView startTime = childView.findViewById(R.id.active_start_time); + startTime.setText(getString(R.string.forum_show_start_time, active.getActiveStartTime())); + TextView endTime = childView.findViewById(R.id.active_end_time); + endTime.setText(getString(R.string.forum_show_end_time, active.getActiveEndTime())); + TextView activeScore = childView.findViewById(R.id.active_score); + activeScore.setText(getString(R.string.forum_show_active_score, active.getActiveScore())); + } + break; + case score: { + Score score = forum.getScore(); + childView = View.inflate(getApplicationContext(), R.layout.forum_data_score_content, null); + TextView activeScore = childView.findViewById(R.id.active_score); + activeScore.setText(getString(R.string.forum_show_active_score, score.getActiveScore())); + } + break; + case complan: { + Complain complain = forum.getComplainDto(); + childView = View.inflate(getApplicationContext(), R.layout.forum_data_complain_content, null); + TextView $complain = childView.findViewById(R.id.complain); + $complain.setText(getString(R.string.forum_show_complain, complain.getComplain())); + } + break; + } + if (childView != null) { + otherContent.removeAllViews(); + otherContent.addView(childView); + } + } } /** @@ -211,7 +261,7 @@ public class ForumDataActivity extends BaseActivity { * 创建楼层数据 */ private void createReply(List forumContentList) { - replyLayout.removeAllViews(); + replyLayout.removeViews(1, replyLayout.getChildCount() - 1); 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); @@ -230,7 +280,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.getMyInfo().getCreditScore())); + score.setText(getString(R.string.credit_score, forumContent.getInfo().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 b1f56e8..af52dc7 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 @@ -3,6 +3,7 @@ package com.community.pocket.ui.main.ui.forum.data; import androidx.annotation.StringRes; import com.community.pocket.R; +import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.ForumContent; import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.util.CustomMessage; @@ -18,6 +19,8 @@ import java.util.List; public class ForumDataResponse extends Response { private List forumContentList; + private Forum forum; + List getForumContentList() { return forumContentList; } @@ -26,6 +29,14 @@ public class ForumDataResponse extends Response { this.forumContentList = forumContentList; } + public Forum getForum() { + return forum; + } + + public void setForum(Forum forum) { + this.forum = forum; + } + enum Msg implements CustomMessage { ok(R.string.forum_data_ok), fail(R.string.forum_data_fail), diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java index 2f8f406..a639249 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java @@ -40,6 +40,10 @@ public class ForumPostActiveFragment extends ForumPostContent { @ViewInject(R.id.active_score) private EditText activeScore; + //报名截止日期 + @ViewInject(R.id.registration_deadline) + private EditText registrationDeadline; + private ForumPostActiveViewModel viewModel; //日期格式提示 @@ -68,6 +72,9 @@ public class ForumPostActiveFragment extends ForumPostContent { if (forumPostFormState.getContentError() != null) { postContent.setError(getString(forumPostFormState.getContentError())); } + if (forumPostFormState.getRegistrationDeadlineError() != null) { + registrationDeadline.setError(getString(forumPostFormState.getRegistrationDeadlineError())); + } if (forumPostFormState.getActiveStartTimeError() != null) { activeStartTime.setError(getString(forumPostFormState.getActiveStartTimeError())); } @@ -88,11 +95,12 @@ public class ForumPostActiveFragment extends ForumPostContent { TextWatcher textWatcher = new MyTextChange() { @Override public void afterTextChanged(Editable s) { - viewModel.postDataForumChanged(postTitle.getText().toString(), postContent.getText().toString(), activeStartTime.getText().toString(), activeEndTime.getText().toString(), activeScore.getText().toString()); + viewModel.postDataForumChanged(postTitle.getText().toString(), postContent.getText().toString(), activeStartTime.getText().toString(), activeEndTime.getText().toString(), activeScore.getText().toString(), registrationDeadline.getText().toString()); } }; postTitle.addTextChangedListener(textWatcher); postContent.addTextChangedListener(textWatcher); + registrationDeadline.addTextChangedListener(textWatcher); activeStartTime.addTextChangedListener(textWatcher); activeEndTime.addTextChangedListener(textWatcher); activeScore.addTextChangedListener(textWatcher); @@ -101,7 +109,7 @@ public class ForumPostActiveFragment extends ForumPostContent { postButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - viewModel.sendPost(postTitle.getText().toString(), postContent.getText().toString(), activeStartTime.getText().toString(), activeEndTime.getText().toString(), activeScore.getText().toString()); + viewModel.sendPost(postTitle.getText().toString(), postContent.getText().toString(), activeStartTime.getText().toString(), activeEndTime.getText().toString(), activeScore.getText().toString(), registrationDeadline.getText().toString()); } }); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java index bcbe9f3..8656a33 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java @@ -15,26 +15,30 @@ public class ForumPostActiveViewModel extends ForumPostViewModel { } //校验表单状态 - void postDataForumChanged(String title, String content, String activeStartTime, String activeEndTime, String activeScore) { + void postDataForumChanged(String title, String content, String activeStartTime, String activeEndTime, String activeScore, String registrationDeadline) { if (!ValidUtil.titleValid(title)) { - forumPostFormState.setValue(new ForumPostFormState.Active(R.string.invalid_title, null, null, null, null)); + forumPostFormState.setValue(new ForumPostFormState.Active(R.string.invalid_title, null, null, null, null, null)); } else if (!ValidUtil.notesValid(content)) { - forumPostFormState.setValue(new ForumPostFormState.Active(null, R.string.invalid_post, null, null, null)); + forumPostFormState.setValue(new ForumPostFormState.Active(null, R.string.invalid_post, null, null, null, null)); + } else if (!ValidUtil.dateValid(registrationDeadline)) { + forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, null, null, R.string.invalid_date)); } else if (!ValidUtil.dateValid(activeStartTime)) { - forumPostFormState.setValue(new ForumPostFormState.Active(null, null, R.string.invalid_date, null, null)); + forumPostFormState.setValue(new ForumPostFormState.Active(null, null, R.string.invalid_date, null, null, null)); + } else if (!ValidUtil.before(registrationDeadline, activeStartTime)) { + forumPostFormState.setValue(new ForumPostFormState.Active(null, null, R.string.invalid_active_date_before, null, null, null)); } else if (!ValidUtil.dateValid(activeEndTime)) { - forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, R.string.invalid_date, null)); - } else if (!ValidUtil.before(activeStartTime, activeEndTime)) { - forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, R.string.invalid_date_before, null)); + forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, R.string.invalid_date, null, null)); + } else if (!activeStartTime.equals(activeEndTime) && !ValidUtil.before(activeStartTime, activeEndTime)) { + forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, R.string.invalid_date_before, null, null)); } else if (!ValidUtil.scoreValid(activeScore)) { - forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, null, R.string.invalid_score)); + forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, null, R.string.invalid_score, null)); } else { forumPostFormState.setValue(new ForumPostFormState.Active(true)); } } //发帖请求状态 - void sendPost(String title, String content, String activeStartTime, String activeEndTime, String activeScore) { - getRequest().sendActive(forumPostResponse, title, content, activeStartTime, activeEndTime, activeScore); + void sendPost(String title, String content, String activeStartTime, String activeEndTime, String activeScore, String registrationDeadline) { + getRequest().sendActive(forumPostResponse, title, content, activeStartTime, activeEndTime, activeScore, registrationDeadline); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java index 9257f06..1894f22 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java @@ -89,7 +89,9 @@ public class ForumPostComplainFragment extends ForumPostContent { queryUserResponse.toast(getContext()); if (queryUserResponse.getResult() == Response.Result.OK) { - initSearch(queryUserResponse.getPeopleList()); + if (!queryUserResponse.getPeopleList().isEmpty()) { + initSearch(queryUserResponse.getPeopleList()); + } } } }); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFormState.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFormState.java index febc662..a05c9b2 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFormState.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFormState.java @@ -36,6 +36,7 @@ class ForumPostFormState { return isDataValid; } + //活动表单 static class Active extends ForumPostFormState { @Nullable private Integer activeStartTimeError; @@ -43,16 +44,19 @@ class ForumPostFormState { private Integer activeEndTimeError; @Nullable private Integer activeScore; + @Nullable + private Integer registrationDeadlineError; Active(boolean isDataValid) { super(isDataValid); } - Active(@Nullable Integer titleError, @Nullable Integer contentError, @Nullable Integer activeStartTimeError, @Nullable Integer activeEndTimeError, @Nullable Integer activeScore) { + Active(@Nullable Integer titleError, @Nullable Integer contentError, @Nullable Integer activeStartTimeError, @Nullable Integer activeEndTimeError, @Nullable Integer activeScore, @Nullable Integer registrationDeadlineError) { super(titleError, contentError); this.activeStartTimeError = activeStartTimeError; this.activeEndTimeError = activeEndTimeError; this.activeScore = activeScore; + this.registrationDeadlineError = registrationDeadlineError; } @Nullable @@ -69,8 +73,14 @@ class ForumPostFormState { Integer getActiveScore() { return activeScore; } + + @Nullable + Integer getRegistrationDeadlineError() { + return registrationDeadlineError; + } } + //投诉表单 static class Complain extends ForumPostFormState { @Nullable private Integer complainError; @@ -89,4 +99,25 @@ class ForumPostFormState { return complainError; } } + + //结算表单 + static class Score extends ForumPostFormState { + + @Nullable + private Integer scoreError; + + Score(@Nullable Integer titleError, @Nullable Integer contentError, @Nullable Integer scoreError) { + super(titleError, contentError); + this.scoreError = scoreError; + } + + Score(boolean isDataValid) { + super(isDataValid); + } + + @Nullable + Integer getScoreError() { + return scoreError; + } + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java index 3f66a06..483ee6d 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java @@ -4,7 +4,6 @@ import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; -import android.widget.EditText; import android.widget.Spinner; import androidx.annotation.NonNull; @@ -26,13 +25,6 @@ import java.util.Objects; */ @ContentView(R.layout.forum_post_fragment) public class ForumPostFragment extends BaseFragment { - - /** - * 发送标题 - */ - @ViewInject(R.id.post_title) - private EditText postTitle; - /** * 帖子类型 */ @@ -69,11 +61,14 @@ public class ForumPostFragment extends BaseFragment { nav.navigate(R.id.forumPostActiveFragment); break; case 1: - nav.navigate(R.id.forumPostTopicFragment); + nav.navigate(R.id.forumPostScore); break; case 2: - nav.navigate(R.id.forumPostComplainFragment); + nav.navigate(R.id.forumPostTopicFragment); break; + case 3: + nav.navigate(R.id.forumPostComplainFragment); + } } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostScore.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostScore.java new file mode 100644 index 0000000..9db233c --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostScore.java @@ -0,0 +1,84 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.EditText; + +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import com.community.pocket.R; +import com.community.pocket.ui.listener.MyTextChange; +import com.community.pocket.util.PropertiesUtil; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.ViewInject; + +/** + * 悬赏贴布局 + */ +@ContentView(R.layout.forum_post_score_fragment) +public class ForumPostScore extends ForumPostContent { + + private ForumPostScoreViewModel viewModel; + + @ViewInject(R.id.active_score) + private EditText activeScore; + + public static ForumPostScore newInstance() { + return new ForumPostScore(); + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + viewModel = new ViewModelProvider.NewInstanceFactory().create(ForumPostScoreViewModel.class); + + //监听表单校验状态 + viewModel.getForumPostFormState().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(ForumPostFormState.Score forumPostFormState) { + if (forumPostFormState == null) { + return; + } + + if (forumPostFormState.getTitleError() != null) { + postTitle.setError(getString(forumPostFormState.getTitleError())); + } + if (forumPostFormState.getContentError() != null) { + postContent.setError(getString(forumPostFormState.getContentError())); + } + if (forumPostFormState.getScoreError() != null) { + activeScore.setError(getString(forumPostFormState.getScoreError(), PropertiesUtil.getIntValue("score.max"))); + } + + postButton.setEnabled(forumPostFormState.isDataValid()); + } + }); + + //监听发帖状态 + sendPost(viewModel); + + TextWatcher textWatcher = new MyTextChange() { + @Override + public void afterTextChanged(Editable s) { + viewModel.scoreFormChanged(postTitle.getText().toString(), postContent.getText().toString(), activeScore.getText().toString()); + } + }; + postTitle.addTextChangedListener(textWatcher); + postContent.addTextChangedListener(textWatcher); + activeScore.addTextChangedListener(textWatcher); + + //发帖操作 + postButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + viewModel.sendScore(postTitle.getText().toString(), postContent.getText().toString(), activeScore.getText().toString()); + } + }); + } + +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostScoreViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostScoreViewModel.java new file mode 100644 index 0000000..f2461d6 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostScoreViewModel.java @@ -0,0 +1,32 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import androidx.lifecycle.MutableLiveData; + +import com.community.pocket.R; +import com.community.pocket.util.ValidUtil; + +public class ForumPostScoreViewModel extends ForumPostViewModel { + private MutableLiveData forumPostFormState = new MutableLiveData<>(); + + MutableLiveData getForumPostFormState() { + return forumPostFormState; + } + + //结算表单校验 + void scoreFormChanged(String title, String content, String activeScore) { + if (!ValidUtil.titleValid(title)) { + forumPostFormState.setValue(new ForumPostFormState.Score(R.string.invalid_title, null, null)); + } else if (!ValidUtil.notesValid(content)) { + forumPostFormState.setValue(new ForumPostFormState.Score(null, R.string.invalid_post, null)); + } else if (!ValidUtil.scoreValid(activeScore)) { + forumPostFormState.setValue(new ForumPostFormState.Score(null, null, R.string.invalid_score)); + } else { + forumPostFormState.setValue(new ForumPostFormState.Score(true)); + } + } + + //发送结算贴贴 + void sendScore(String title, String content, String activeScore) { + getRequest().sendScore(forumPostResponse, title, content, activeScore); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/QueryUserResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/QueryUserResponse.java index afc1697..fd4631d 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/QueryUserResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/QueryUserResponse.java @@ -28,6 +28,7 @@ public class QueryUserResponse extends Response { enum Msg implements CustomMessage { ok(R.string.forum_search_people_ok), + ok_empty(R.string.not_match_people), fail(R.string.forum_search_people_fail); private Integer msg; diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java index 527b3f7..959e89a 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java @@ -148,7 +148,9 @@ public class VisitorAppointmentFragment extends BaseFragment { visitorResponse.toast(getContext()); if (visitorResponse.getResult() == Response.Result.OK) { - initSearch(visitorResponse.getVisitorPeopleList()); + if (!visitorResponse.getVisitorPeopleList().isEmpty()) { + initSearch(visitorResponse.getVisitorPeopleList()); + } } } }); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorPeopleResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorPeopleResponse.java index d1d71b5..776a0f4 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorPeopleResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorPeopleResponse.java @@ -25,7 +25,8 @@ public class VisitorPeopleResponse extends Response { enum Msg implements CustomMessage { ok(R.string.visitor_appointment_people_ok), - fail(R.string.visitor_appointment_people_fail); + fail(R.string.visitor_appointment_people_fail), + ok_empty(R.string.not_match_people); private Integer msg; diff --git a/app/src/main/java/com/community/pocket/util/BuildType.java b/app/src/main/java/com/community/pocket/util/BuildType.java new file mode 100644 index 0000000..0af37cb --- /dev/null +++ b/app/src/main/java/com/community/pocket/util/BuildType.java @@ -0,0 +1,16 @@ +package com.community.pocket.util; + +public enum BuildType { + rap2debug("rap2"), + serverdebug("springboot"); + + private String name; + + BuildType(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/app/src/main/java/com/community/pocket/util/HttpUtil.java b/app/src/main/java/com/community/pocket/util/HttpUtil.java index d05cca0..d85345c 100644 --- a/app/src/main/java/com/community/pocket/util/HttpUtil.java +++ b/app/src/main/java/com/community/pocket/util/HttpUtil.java @@ -1,10 +1,21 @@ package com.community.pocket.util; +import android.app.Activity; import android.content.Context; +import android.content.Intent; +import android.net.Uri; import android.os.Looper; +import android.util.Patterns; +import android.util.TypedValue; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; +import androidx.constraintlayout.widget.ConstraintLayout; import com.community.pocket.BuildConfig; import com.community.pocket.R; @@ -12,6 +23,8 @@ import com.community.pocket.R; import org.jetbrains.annotations.NotNull; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -66,13 +79,96 @@ public class HttpUtil { public void onFailure(@NotNull Call call, @NotNull IOException e) { if (BuildConfig.DEBUG) { Looper.prepare(); - if (BuildConfig.API_HOST.contains("http")) { - new AlertDialog.Builder(context) - .setMessage(context.getString(R.string.check_server_fail, BuildConfig.API_HOST)).show(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + View view = View.inflate(context, R.layout.debug_title, null); + ImageView imageView = view.findViewById(R.id.close); + imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + View confirm = View.inflate(context, R.layout.debug_alert, null); + AlertDialog.Builder dialog = new AlertDialog.Builder(context); + dialog.setView(confirm); + final AlertDialog alertDialog = dialog.create(); + confirm.findViewById(R.id.yes).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + System.exit(0); + } + }); + confirm.findViewById(R.id.no).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + alertDialog.dismiss(); + } + }); + alertDialog.show(); + } + }); + builder.setCustomTitle(view); + if (Patterns.WEB_URL.matcher(BuildConfig.API_HOST).matches()) { + ConstraintLayout constraintLayout = (ConstraintLayout) View.inflate(context, R.layout.debug, null); + TextView buildType = constraintLayout.findViewById(R.id.build_type); + buildType.setText(context.getString(R.string.build_type, BuildConfig.BUILD_TYPE)); + TextView url = constraintLayout.findViewById(R.id.url); + url.setText(context.getString(R.string.server_host, BuildConfig.API_HOST)); + TextView detailError = constraintLayout.findViewById(R.id.detailError); + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + e.printStackTrace(printWriter); + detailError.setText(stringWriter.toString()); + Button openUrl = constraintLayout.findViewById(R.id.open_url); + TextView error = constraintLayout.findViewById(R.id.error); + LinearLayout linearLayout = constraintLayout.findViewById(R.id.my_layout); + int index = linearLayout.indexOfChild(error); + + TextView testPort = new TextView(context); + TextView mode = constraintLayout.findViewById(R.id.mode); + switch (BuildType.valueOf(BuildConfig.BUILD_TYPE)) { + case rap2debug: + testPort.setText(R.string.rap2_error); + mode.setText(context.getString(R.string.debug_mode, BuildType.rap2debug.getName())); + break; + case serverdebug: + testPort.setText(R.string.server_error); + mode.setText(context.getString(R.string.debug_mode, BuildType.serverdebug.getName())); + break; + } + testPort.setSingleLine(false); + testPort.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); + testPort.setGravity(error.getGravity()); + linearLayout.addView(testPort, index + 1); + + openUrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //从其他浏览器打开 + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + Uri content_url = Uri.parse(BuildConfig.API_HOST); + intent.setData(content_url); + Activity activity = (Activity) context; + activity.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_browser))); + + } + }); + +// int[] buttonId=new int[]{R.id.button,R.id.button2}; +// View.OnClickListener onClickListener=new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// System.exit(0); +// } +// }; +// for(int id:buttonId){ +// view.findViewById(id).setOnClickListener(onClickListener); +// } + + + builder.setView(constraintLayout); } else { - new AlertDialog.Builder(context) - .setMessage(context.getString(R.string.error_api_host, BuildConfig.API_HOST)).show(); + builder.setMessage(context.getString(R.string.error_api_host, BuildConfig.API_HOST)); } + builder.show(); Looper.loop(); } } diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml new file mode 100644 index 0000000..3b9daf9 --- /dev/null +++ b/app/src/main/res/drawable/ic_close.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 73ac745..e595ea5 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -22,8 +22,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/titlebar" - tools:layout_constraintStart_toStartOf="parent"> + app:layout_constraintTop_toBottomOf="@id/titlebar"> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@id/titlebar"> + + + + + + + + + + + + + + +