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.
71 lines
1.9 KiB
71 lines
1.9 KiB
package com.community.pocket.ui.main.ui.forum.data;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.data.main.forum.ForumDataRequest;
|
|
import com.community.pocket.ui.main.ui.share.BaseViewModel;
|
|
import com.community.pocket.util.ValidUtil;
|
|
|
|
/**
|
|
* 帖子详情数据管理
|
|
*/
|
|
public class ForumDataViewModel extends BaseViewModel<ForumDataRequest> {
|
|
//表单校验状态
|
|
private MutableLiveData<ForumReplyState> forumReplyState = new MutableLiveData<>();
|
|
|
|
//回帖请求状态
|
|
private MutableLiveData<ForumDataResponse> replayResponse = new MutableLiveData<>();
|
|
|
|
//帖子详情数据状态
|
|
private MutableLiveData<ForumDataResponse> forumContentResponse = new MutableLiveData<>();
|
|
|
|
MutableLiveData<ForumReplyState> getForumReplyState() {
|
|
return forumReplyState;
|
|
}
|
|
|
|
MutableLiveData<ForumDataResponse> getReplayResponse() {
|
|
return replayResponse;
|
|
}
|
|
|
|
MutableLiveData<ForumDataResponse> getForumContentResponse() {
|
|
return forumContentResponse;
|
|
}
|
|
|
|
/**
|
|
* 校验回帖表单
|
|
*
|
|
* @param content 内容
|
|
*/
|
|
void replayFormChanged(String content) {
|
|
if (!ValidUtil.notesValid(content)) {
|
|
forumReplyState.setValue(new ForumReplyState(R.string.invalid_post));
|
|
} else {
|
|
forumReplyState.setValue(new ForumReplyState(true));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 回帖状态
|
|
* @param forumId 帖子id
|
|
* @param content 内容
|
|
*/
|
|
void sendReply(String forumId, String content) {
|
|
getRequest().sendReply(replayResponse, forumId, content);
|
|
}
|
|
|
|
/**
|
|
* 加载帖子数据
|
|
*
|
|
* @param forumId 帖子id
|
|
*/
|
|
void loadData(String forumId) {
|
|
getRequest().loadData(forumContentResponse, forumId);
|
|
}
|
|
|
|
|
|
@Override
|
|
protected ForumDataRequest getRequest() {
|
|
return ForumDataRequest.getInstance();
|
|
}
|
|
}
|
|
|