增加发送活动帖UI数据管理

0515
panqihua 5 years ago
parent f91edffd33
commit 9851032a64
  1. 8
      app/src/main/assets/config.properties
  2. 26
      app/src/main/java/com/community/pocket/data/main/forum/ForumRequest.java
  3. 20
      app/src/main/java/com/community/pocket/ui/BaseFragment.java
  4. 25
      app/src/main/java/com/community/pocket/ui/listener/MyTextChange.java
  5. 13
      app/src/main/java/com/community/pocket/ui/login/LoginActivity.java
  6. 15
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java
  7. 132
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java
  8. 49
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java
  9. 10
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java
  10. 42
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java
  11. 73
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFormState.java
  12. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java
  13. 30
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostResponse.java
  14. 8
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java
  15. 24
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModel.java
  16. 25
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModelFactory.java
  17. 24
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java
  18. 13
      app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java
  19. 13
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java
  20. 13
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java
  21. 13
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java
  22. 2
      app/src/main/java/com/community/pocket/util/PropertiesUtil.java
  23. 56
      app/src/main/java/com/community/pocket/util/ValidUtil.java
  24. 26
      app/src/main/res/layout/main/layout/forum/layout/forum_post_active_fragment.xml
  25. 9
      app/src/main/res/layout/main/layout/forum/layout/forum_post_complain_fragment.xml
  26. 7
      app/src/main/res/layout/main/layout/forum/layout/forum_post_fragment.xml
  27. 8
      app/src/main/res/layout/main/layout/forum/layout/forum_post_topic_fragment.xml
  28. 7
      app/src/main/res/values-en-rUS/strings.xml
  29. 7
      app/src/main/res/values-zh-rCN/strings.xml
  30. 7
      app/src/main/res/values/strings.xml

@ -3,4 +3,10 @@ password.length=5
#注册账号大于长度 #注册账号大于长度
username.length=5 username.length=5
#多行文本最大长度 #多行文本最大长度
textMultiLine.length=200 textMultiLine.length=200
#帖子标题最大长度
title.length=15
#帖子信用分最大值
score.max=20
#日期格式
date.pattern=yyyy/MM/dd

@ -0,0 +1,26 @@
package com.community.pocket.data.main.forum;
import com.community.pocket.util.Valid;
/**
* 发表帖子请求接口
* TODO 完善逻辑
*/
public class ForumRequest {
private static volatile ForumRequest instance;
private ForumRequest() {
}
public static ForumRequest getInstance() {
if (instance == null) {
instance = new ForumRequest();
}
return instance;
}
public Valid sendPost(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
return Valid.ok;
}
}

@ -20,4 +20,24 @@ public abstract class BaseFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return x.view().inject(this, inflater, container);//fragment注解 return x.view().inject(this, inflater, container);//fragment注解
} }
//获取父级Fragment
protected <T extends Fragment> T getParentFragment(int level) {
return getParentFragment(level, null);
}
//获取父级Fragment
@SuppressWarnings("unchecked")
private <T extends Fragment> T getParentFragment(int level, Fragment fragment) {
if (level-- > 0) {
if (fragment == null) {
fragment = getParentFragment();
} else {
fragment = fragment.getParentFragment();
}
return getParentFragment(level, fragment);
} else {
return (T) fragment;
}
}
} }

@ -0,0 +1,25 @@
package com.community.pocket.ui.listener;
import android.text.Editable;
import android.text.TextWatcher;
/**
* 监听输入文本框内容改变
*/
public abstract class MyTextChange implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
}

@ -20,6 +20,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.BaseActivity; import com.community.pocket.ui.BaseActivity;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.MainMenu; import com.community.pocket.ui.main.MainMenu;
import com.community.pocket.ui.register.RegisterActivity; import com.community.pocket.ui.register.RegisterActivity;
import com.community.pocket.ui.resetpwd.ResetPwdActivity; import com.community.pocket.ui.resetpwd.ResetPwdActivity;
@ -101,17 +102,7 @@ public class LoginActivity extends BaseActivity {
// 监听用户密码文本输入框内容改变 // 监听用户密码文本输入框内容改变
TextWatcher afterTextChangedListener = new TextWatcher() { TextWatcher afterTextChangedListener = new MyTextChange() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// ignore
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// ignore
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
loginViewModel.loginDataChanged(usernameEditText.getText().toString(), loginViewModel.loginDataChanged(usernameEditText.getText().toString(),

@ -1,8 +1,6 @@
package com.community.pocket.ui.main.ui.forum; package com.community.pocket.ui.main.ui.forum;
import android.text.Editable;
import android.text.Html; import android.text.Html;
import android.text.TextWatcher;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -10,6 +8,7 @@ import android.widget.TextView;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
/** /**
@ -52,21 +51,11 @@ public class ShowWordCount {
setCount(); setCount();
postContent.addTextChangedListener(new TextWatcher() { postContent.addTextChangedListener(new MyTextChange() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
setCount(); setCount();
} }
@Override
public void afterTextChanged(Editable s) {
}
}); });
} }
} }

@ -1,35 +1,153 @@
package com.community.pocket.ui.main.ui.forum.post; package com.community.pocket.ui.main.ui.forum.post;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.format.DateFormat;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.forum.ForumFragment;
import com.community.pocket.util.PropertiesUtil;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject; import org.xutils.view.annotation.ViewInject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
/** /**
* 活动贴 * 活动贴
*/ */
@ContentView(R.layout.forum_post_active_fragment) @ContentView(R.layout.forum_post_active_fragment)
public class ForumPostActiveFragment extends ForumPostContent { public class ForumPostActiveFragment extends ForumPostContent {
//活动开始时间
@ViewInject(R.id.active_start_time) @ViewInject(R.id.active_start_time)
private EditText activeStartTime; private EditText activeStartTime;
//活动结束时间
@ViewInject(R.id.active_end_time) @ViewInject(R.id.active_end_time)
private EditText activeEndTime; private EditText activeEndTime;
//活动信用分
@ViewInject(R.id.active_score) @ViewInject(R.id.active_score)
private EditText activeScore; private EditText activeScore;
/** private ForumPostActiveViewModel viewModel;
* 发帖操作
*/ //日期格式提示
@Event(value = R.id.post_button) @ViewInject(R.id.tip)
private void onButtonClick(View v) { private TextView tip;
Toast.makeText(getContext(), R.string.post, Toast.LENGTH_SHORT).show();
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewModel = new ViewModelProvider(this, new ForumPostViewModelFactory()).get(ForumPostActiveViewModel.class);
//监控表单校验状态
viewModel.getForumPostFormState().observe(getViewLifecycleOwner(), new Observer<ForumPostFormState.Active>() {
@Override
public void onChanged(ForumPostFormState.Active 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.getActiveStartTimeError() != null) {
activeStartTime.setError(getString(forumPostFormState.getActiveStartTimeError()));
}
if (forumPostFormState.getActiveEndTimeError() != null) {
activeEndTime.setError(getString(forumPostFormState.getActiveEndTimeError()));
}
if (forumPostFormState.getActiveScore() != null) {
activeScore.setError(getString(forumPostFormState.getActiveScore(), PropertiesUtil.getIntValue("score.max")));
}
postButton.setEnabled(forumPostFormState.isDataValid());
}
});
//监控发帖状态
viewModel.getForumPostResponse().observe(getViewLifecycleOwner(), new Observer<ForumPostResponse>() {
@Override
public void onChanged(ForumPostResponse forumPostResponse) {
if (forumPostResponse == null) {
return;
}
if (forumPostResponse.getSuccess() != null) {
Toast.makeText(getContext(), forumPostResponse.getSuccess(), Toast.LENGTH_LONG).show();
ForumFragment forumFragment = getParentFragment(4);
Button button = Objects.requireNonNull(forumFragment.getView()).findViewById(R.id.forum_new);
try {
Method method = ForumFragment.class.getDeclaredMethod("_new", View.class);
method.setAccessible(true);
method.invoke(forumFragment, button);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
if (forumPostResponse.getError() != null) {
Toast.makeText(getContext(), forumPostResponse.getError(), Toast.LENGTH_LONG).show();
}
}
});
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());
}
};
postTitle.addTextChangedListener(textWatcher);
postContent.addTextChangedListener(textWatcher);
activeStartTime.addTextChangedListener(textWatcher);
activeEndTime.addTextChangedListener(textWatcher);
activeScore.addTextChangedListener(textWatcher);
//发帖操作
postButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewModel.sendPost(postType.getSelectedItem().toString(), postTitle.getText().toString(), postContent.getText().toString(), activeStartTime.getText().toString(), activeEndTime.getText().toString(), activeScore.getText().toString());
}
});
initTip();
}
//初始化日期提示
private void initTip() {
String format = PropertiesUtil.getValue("date.pattern");
tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis())));
} }
} }

@ -1,7 +1,50 @@
package com.community.pocket.ui.main.ui.forum.post; package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.MutableLiveData;
public class ForumPostActiveViewModel extends ViewModel { import com.community.pocket.R;
// TODO: Implement the ViewModel import com.community.pocket.data.main.forum.ForumRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
class ForumPostActiveViewModel extends ForumPostViewModel {
//表单校验状态
private MutableLiveData<ForumPostFormState.Active> forumPostFormState = new MutableLiveData<>();
ForumPostActiveViewModel(ForumRequest forumRequest) {
super(forumRequest);
}
MutableLiveData<ForumPostFormState.Active> getForumPostFormState() {
return forumPostFormState;
}
//校验表单状态
void postDataForumChanged(String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
if (!ValidUtil.titleValid(title)) {
forumPostFormState.setValue(new ForumPostFormState.Active(R.string.invalid_title, null, null, null, null));
} else if (!ValidUtil.notesValid(content)) {
forumPostFormState.setValue(new ForumPostFormState.Active(null, R.string.invalid_post, null, null, null));
} else if (!ValidUtil.dateValid(activeStartTime)) {
forumPostFormState.setValue(new ForumPostFormState.Active(null, null, R.string.invalid_date, null, null));
} else if (!ValidUtil.dateValid(activeEndTime)) {
forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, R.string.invalid_date, null));
} else if (!ValidUtil.scoreValid(activeScore)) {
forumPostFormState.setValue(new ForumPostFormState.Active(null, null, null, null, R.string.invalid_score));
} else {
forumPostFormState.setValue(new ForumPostFormState.Active(true));
}
}
//发帖请求状态
void sendPost(String type, String title, String content, String activeStartTime, String activeEndTime, String activeScore) {
Valid valid = forumRequest.sendPost(type, title, content, activeStartTime, activeEndTime, activeScore);
if (valid == Valid.ok) {
forumPostResponse.setValue(new ForumPostResponse().setSuccess(R.string.forum_post_ok));
} else {
forumPostResponse.setValue(new ForumPostResponse().setError(R.string.forum_post_fail));
}
}
} }

@ -1,7 +1,11 @@
package com.community.pocket.ui.main.ui.forum.post; package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.ViewModel; import com.community.pocket.data.main.forum.ForumRequest;
class ForumPostComplainViewModel extends ForumPostViewModel {
ForumPostComplainViewModel(ForumRequest forumRequest) {
super(forumRequest);
}
public class ForumPostComplainViewModel extends ViewModel {
// TODO: Implement the ViewModel
} }

@ -3,27 +3,69 @@ package com.community.pocket.ui.main.ui.forum.post;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.main.ui.forum.ShowWordCount; import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import org.xutils.view.annotation.ViewInject;
import java.util.Objects;
/** /**
* 发送正文界面 * 发送正文界面
*/ */
abstract class ForumPostContent extends BaseFragment { abstract class ForumPostContent extends BaseFragment {
/**
* 发送标题
*/
EditText postTitle;
/**
* 帖子类型
*/
Spinner postType;
/**
* 发帖按钮
*/
Button postButton;
@ViewInject(R.id.post_content_layout)
private ConstraintLayout contentLayout;
//发送正文
EditText postContent;
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
@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);
ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_count, R.id.show_count_top}, R.id.post_content, view); ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_count, R.id.show_count_top}, R.id.post_content, view);
showWordCount.showCount(); showWordCount.showCount();
initParentView();
} }
//初始化父级布局组件
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initParentView() {
ForumPostFragment forumPostFragment = getParentFragment(2);
View parentView = Objects.requireNonNull(Objects.requireNonNull(forumPostFragment).getView());
postTitle = parentView.findViewById(R.id.post_title);
postType = parentView.findViewById(R.id.post_type);
postButton = parentView.findViewById(R.id.post_button);
postContent = contentLayout.findViewById(R.id.post_content);
}
} }

@ -0,0 +1,73 @@
package com.community.pocket.ui.main.ui.forum.post;
import androidx.annotation.Nullable;
/**
* 发送帖子表单状态
*/
class ForumPostFormState {
@Nullable
private Integer titleError;
@Nullable
private Integer contentError;
private boolean isDataValid;
ForumPostFormState(@Nullable Integer titleError, @Nullable Integer contentError) {
this.titleError = titleError;
this.contentError = contentError;
}
ForumPostFormState(boolean isDataValid) {
this.isDataValid = isDataValid;
}
@Nullable
Integer getTitleError() {
return titleError;
}
@Nullable
Integer getContentError() {
return contentError;
}
boolean isDataValid() {
return isDataValid;
}
static class Active extends ForumPostFormState {
@Nullable
private Integer activeStartTimeError;
@Nullable
private Integer activeEndTimeError;
@Nullable
private Integer activeScore;
Active(boolean isDataValid) {
super(isDataValid);
}
Active(@Nullable Integer titleError, @Nullable Integer contentError, @Nullable Integer activeStartTimeError, @Nullable Integer activeEndTimeError, @Nullable Integer activeScore) {
super(titleError, contentError);
this.activeStartTimeError = activeStartTimeError;
this.activeEndTimeError = activeEndTimeError;
this.activeScore = activeScore;
}
@Nullable
Integer getActiveStartTimeError() {
return activeStartTimeError;
}
@Nullable
Integer getActiveEndTimeError() {
return activeEndTimeError;
}
@Nullable
Integer getActiveScore() {
return activeScore;
}
}
}

@ -39,12 +39,16 @@ public class ForumPostFragment extends BaseFragment {
@ViewInject(R.id.post_type) @ViewInject(R.id.post_type)
private Spinner postType; private Spinner postType;
/**
* 帖子类型布局导航控制器
*/
private NavController nav; private NavController nav;
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
@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);
onPostTypeChange(); onPostTypeChange();
} }

@ -0,0 +1,30 @@
package com.community.pocket.ui.main.ui.forum.post;
import androidx.annotation.Nullable;
public class ForumPostResponse {
@Nullable
private Integer success;
@Nullable
private Integer error;
@Nullable
public Integer getSuccess() {
return success;
}
public ForumPostResponse setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
@Nullable
public Integer getError() {
return error;
}
public ForumPostResponse setError(@Nullable Integer error) {
this.error = error;
return this;
}
}

@ -1,7 +1,9 @@
package com.community.pocket.ui.main.ui.forum.post; package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.ViewModel; import com.community.pocket.data.main.forum.ForumRequest;
public class ForumPostTopicViewModel extends ViewModel { class ForumPostTopicViewModel extends ForumPostViewModel {
// TODO: Implement the ViewModel ForumPostTopicViewModel(ForumRequest forumRequest) {
super(forumRequest);
}
} }

@ -1,7 +1,27 @@
package com.community.pocket.ui.main.ui.forum.post; package com.community.pocket.ui.main.ui.forum.post;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
public class ForumPostViewModel extends ViewModel { import com.community.pocket.data.main.forum.ForumRequest;
// TODO: Implement the ViewModel
//发送帖子UI数据管理
abstract class ForumPostViewModel extends ViewModel {
//请求接口状态
MutableLiveData<ForumPostResponse> forumPostResponse = new MutableLiveData<>();
//请求接口处理
ForumRequest forumRequest;
MutableLiveData<ForumPostResponse> getForumPostResponse() {
return forumPostResponse;
}
ForumPostViewModel(ForumRequest forumRequest) {
this.forumRequest = forumRequest;
}
} }

@ -0,0 +1,25 @@
package com.community.pocket.ui.main.ui.forum.post;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.data.main.forum.ForumRequest;
public class ForumPostViewModelFactory implements ViewModelProvider.Factory {
@NonNull
@Override
@SuppressWarnings("unchecked")
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (modelClass.isAssignableFrom(ForumPostActiveViewModel.class)) {
return (T) new ForumPostActiveViewModel(ForumRequest.getInstance());
} else if (modelClass.isAssignableFrom(ForumPostTopicViewModel.class)) {
return (T) new ForumPostTopicViewModel(ForumRequest.getInstance());
} else if (modelClass.isAssignableFrom(ForumPostComplainViewModel.class)) {
return (T) new ForumPostComplainViewModel(ForumRequest.getInstance());
} else {
throw new IllegalArgumentException("Unknown ViewModel class");
}
}
}

@ -7,7 +7,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -26,6 +25,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.adapter.VisitorAdpter; import com.community.pocket.data.adapter.VisitorAdpter;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.forum.ShowWordCount; import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
@ -112,8 +112,8 @@ public class VisitorAppointmentFragment extends BaseFragment {
if (visitorResponse.getSuccess() != null) { if (visitorResponse.getSuccess() != null) {
Toast.makeText(getContext(), visitorResponse.getSuccess(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), visitorResponse.getSuccess(), Toast.LENGTH_LONG).show();
VisitorFragment visitorFragment = ((VisitorFragment) Objects.requireNonNull(getParentFragment()).getParentFragment()); VisitorFragment visitorFragment = getParentFragment(2);
Button button = Objects.requireNonNull(Objects.requireNonNull(visitorFragment).getView()).findViewById(R.id.visitor_reservation); Button button = Objects.requireNonNull(visitorFragment.getView()).findViewById(R.id.visitor_reservation);
try { try {
Method method = VisitorFragment.class.getDeclaredMethod("my", View.class); Method method = VisitorFragment.class.getDeclaredMethod("my", View.class);
method.setAccessible(true); method.setAccessible(true);
@ -260,22 +260,4 @@ public class VisitorAppointmentFragment extends BaseFragment {
appointmentViewModel.appointment(appointment.getText().toString(), chooseTime.getSelectedItem().toString(), notes.getText().toString()); appointmentViewModel.appointment(appointment.getText().toString(), chooseTime.getSelectedItem().toString(), notes.getText().toString());
} }
abstract static class MyTextChange implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
}
} }

@ -16,6 +16,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.BaseActivity; import com.community.pocket.ui.BaseActivity;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.login.LoginActivity; import com.community.pocket.ui.login.LoginActivity;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
@ -91,17 +92,7 @@ public class RegisterActivity extends BaseActivity {
} }
}); });
TextWatcher afterTextChangedListener = new TextWatcher() { TextWatcher afterTextChangedListener = new MyTextChange() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// ignore
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// ignore
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
registerViewModel.registerDataChanged(username.getText().toString(), registerViewModel.registerDataChanged(username.getText().toString(),

@ -20,6 +20,7 @@ import androidx.navigation.fragment.NavHostFragment;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.login.LoginActivity; import com.community.pocket.ui.login.LoginActivity;
import com.community.pocket.util.Param; import com.community.pocket.util.Param;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
@ -72,17 +73,7 @@ public class ResetPwdStep1 extends BaseFragment {
}); });
//监听输入框文本 //监听输入框文本
TextWatcher afterTextChangedListener = new TextWatcher() { TextWatcher afterTextChangedListener = new MyTextChange() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
resetPwdViewModel.resetpwdStep1Changed(username.getText().toString(), email.getText().toString()); resetPwdViewModel.resetpwdStep1Changed(username.getText().toString(), email.getText().toString());

@ -18,6 +18,7 @@ import androidx.navigation.fragment.NavHostFragment;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.util.Param; import com.community.pocket.util.Param;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
@ -89,17 +90,7 @@ public class ResetPwdStep2 extends BaseFragment {
}); });
//监听输入框文本 //监听输入框文本
TextWatcher afterTextChangedListener = new TextWatcher() { TextWatcher afterTextChangedListener = new MyTextChange() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
resetPwdViewModel.resetpwdStep2Changed(code.getText().toString()); resetPwdViewModel.resetpwdStep2Changed(code.getText().toString());

@ -18,6 +18,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.login.LoginActivity; import com.community.pocket.ui.login.LoginActivity;
import com.community.pocket.util.Param; import com.community.pocket.util.Param;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
@ -76,17 +77,7 @@ public class ResetPwdStep3 extends BaseFragment {
} }
}); });
TextWatcher textWatcher = new TextWatcher() { TextWatcher textWatcher = new MyTextChange() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
resetPwdViewModel.resetpwdStep3Changed(password.getText().toString(), confirmPassword.getText().toString()); resetPwdViewModel.resetpwdStep3Changed(password.getText().toString(), confirmPassword.getText().toString());

@ -26,7 +26,7 @@ public class PropertiesUtil {
} }
//获取字符串配置 //获取字符串配置
private static String getValue(String key) { public static String getValue(String key) {
if (values.containsKey(key)) { if (values.containsKey(key)) {
return values.get(key); return values.get(key);
} else { } else {

@ -2,6 +2,9 @@ package com.community.pocket.util;
import android.util.Patterns; import android.util.Patterns;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -57,4 +60,57 @@ public class ValidUtil {
public static boolean notesValid(String notes) { public static boolean notesValid(String notes) {
return notes != null && !notes.isEmpty() && notes.length() <= PropertiesUtil.getIntValue("textMultiLine.length"); return notes != null && !notes.isEmpty() && notes.length() <= PropertiesUtil.getIntValue("textMultiLine.length");
} }
/**
* 校验标题信息
*/
public static boolean titleValid(String title) {
return title != null && !title.isEmpty() && title.length() <= PropertiesUtil.getIntValue("title.length");
}
/**
* 校验日期
*/
public static boolean dateValid(String str) {
boolean convertSuccess = true;
// 指定日期格式为四位年/两位月份/两位日期,注意yyyy/MM/dd区分大小写;
SimpleDateFormat format = new SimpleDateFormat(PropertiesUtil.getValue("date.pattern"), Locale.getDefault());
try {
// 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期,比如2007/02/29会被接受,并转换成2007/03/01
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
// e.printStackTrace();
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
convertSuccess = false;
}
return convertSuccess;
}
/**
* 校验信用分
*/
public static boolean scoreValid(String score) {
if (score != null && Pattern.compile("^\\d+$").matcher(score).matches()) {
int value = Integer.parseInt(score);
return value > 0 && value <= PropertiesUtil.getIntValue("score.max");
} else {
return false;
}
}
} }

@ -24,16 +24,28 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/post_content_layout"> app:layout_constraintTop_toBottomOf="@id/post_content_layout">
<TextView
android:id="@+id/tip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText <EditText
android:id="@+id/active_start_time" android:id="@+id/active_start_time"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/prompt_active_start_time" android:hint="@string/prompt_active_start_time"
android:importantForAutofill="no" android:importantForAutofill="no"
android:inputType="none|text" android:inputType="date"
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/tip"
tools:layout_constraintTop_toBottomOf="@id/post_content" /> tools:layout_constraintTop_toBottomOf="@id/post_content" />
<EditText <EditText
@ -43,7 +55,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:hint="@string/prompt_active_end_time" android:hint="@string/prompt_active_end_time"
android:importantForAutofill="no" android:importantForAutofill="no"
android:inputType="none|text" android:inputType="date"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/active_start_time" app:layout_constraintTop_toBottomOf="@id/active_start_time"
@ -64,14 +76,6 @@
tools:layout_constraintStart_toStartOf="parent" /> tools:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/post_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/post"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/body_layout" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

@ -28,14 +28,5 @@
app:layout_constraintTop_toBottomOf="@id/search_name" app:layout_constraintTop_toBottomOf="@id/search_name"
tools:layout_constraintStart_toStartOf="parent" /> tools:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/post_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/post"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/post_content_layout" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

@ -45,6 +45,13 @@
app:defaultNavHost="true" app:defaultNavHost="true"
app:navGraph="@navigation/nav_forum_post_type" /> app:navGraph="@navigation/nav_forum_post_type" />
<Button
android:id="@+id/post_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/forum_post" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -16,12 +15,5 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<Button
android:id="@+id/post_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/post"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/post_content_layout" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

@ -118,4 +118,11 @@
<string name="visitor_appointment_time_fail">search time fail</string> <string name="visitor_appointment_time_fail">search time fail</string>
<string name="load_data_err">load data error</string> <string name="load_data_err">load data error</string>
<string name="visitor_tag">visitor_tag</string> <string name="visitor_tag">visitor_tag</string>
<string name="invalid_title">title error</string>
<string name="invalid_post">content error</string>
<string name="forum_post_ok">post OK</string>
<string name="forum_post_fail">post fail</string>
<string name="invalid_date">date error</string>
<string name="invalid_score">score error</string>
<string name="dateformat_tip">date format must be %1s,such as %2s</string>
</resources> </resources>

@ -118,4 +118,11 @@
<string name="visitor_appointment_time_fail">预约时间检索失败</string> <string name="visitor_appointment_time_fail">预约时间检索失败</string>
<string name="load_data_err">数据加载失败!!!</string> <string name="load_data_err">数据加载失败!!!</string>
<string name="visitor_tag">visitor_tag</string> <string name="visitor_tag">visitor_tag</string>
<string name="invalid_title">标题不合法</string>
<string name="invalid_post">帖子内容不合法</string>
<string name="forum_post_ok">帖子发表成功</string>
<string name="forum_post_fail">帖子发表失败</string>
<string name="invalid_date">日期不合法</string>
<string name="invalid_score">信用分必须大于0小于等于%1d</string>
<string name="dateformat_tip">日期格式必须是:%1s,例如:%2s</string>
</resources> </resources>

@ -119,6 +119,13 @@
<string name="visitor_appointment_time_fail">search time fail</string> <string name="visitor_appointment_time_fail">search time fail</string>
<string name="load_data_err">load data error</string> <string name="load_data_err">load data error</string>
<string name="visitor_tag">visitor_tag</string> <string name="visitor_tag">visitor_tag</string>
<string name="invalid_title">title error</string>
<string name="invalid_post">content error</string>
<string name="forum_post_ok">post OK</string>
<string name="forum_post_fail">post fail</string>
<string name="invalid_date">date error</string>
<string name="invalid_score">score error</string>
<string name="dateformat_tip">date format must be %1s,such as %2s</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