You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
package com.community.pocket.ui.main.ui.forum.post;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.ui.main.ui.share.SearchViewModel;
|
|
import com.community.pocket.util.ValidUtil;
|
|
|
|
/**
|
|
* 投诉贴数据管理
|
|
*/
|
|
public class ForumPostComplainViewModel extends ForumPostViewModel implements SearchViewModel {
|
|
|
|
//投诉帖表单状态
|
|
private MutableLiveData<ForumPostFormState.Complain> forumPostFormState = new MutableLiveData<>();
|
|
|
|
//检索投诉人
|
|
private MutableLiveData<QueryUserResponse> searchPeople = new MutableLiveData<>();
|
|
|
|
MutableLiveData<ForumPostFormState.Complain> getForumPostFormState() {
|
|
return forumPostFormState;
|
|
}
|
|
|
|
MutableLiveData<QueryUserResponse> getSearchPeople() {
|
|
return searchPeople;
|
|
}
|
|
|
|
/**
|
|
* 投诉贴表单校验
|
|
*/
|
|
void complainDataChanged(String title, String complain, String content) {
|
|
if (!ValidUtil.titleValid(title)) {
|
|
forumPostFormState.setValue(new ForumPostFormState.Complain(R.string.invalid_title, null, null));
|
|
} else if (!ValidUtil.usernamevalid(complain)) {
|
|
forumPostFormState.setValue(new ForumPostFormState.Complain(null, null, R.string.invalid_username));
|
|
} else if (!ValidUtil.notesValid(content)) {
|
|
forumPostFormState.setValue(new ForumPostFormState.Complain(null, R.string.invalid_post, null));
|
|
} else {
|
|
forumPostFormState.setValue(new ForumPostFormState.Complain(true));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 发表投诉贴
|
|
*
|
|
* @param title 标题
|
|
* @param content 正文
|
|
* @param complain 投诉人
|
|
*/
|
|
void sendComplain(String title, String content, String complain) {
|
|
getRequest().sendComplain(forumPostResponse, title, content, complain);
|
|
}
|
|
|
|
/**
|
|
* 模糊检索投诉人列表
|
|
*
|
|
* @param name 投诉人
|
|
*/
|
|
private void searchPeople(String name) {
|
|
getRequest().searchPeople(searchPeople, name);
|
|
}
|
|
|
|
@Override
|
|
public void search(String content, Bundle data) {
|
|
searchPeople(content);
|
|
}
|
|
}
|
|
|