parent
9851032a64
commit
bc6a97dce4
@ -0,0 +1,29 @@ |
||||
package com.community.pocket.data.adapter; |
||||
|
||||
import android.content.Context; |
||||
import android.widget.ArrayAdapter; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ForumSearchAdapter extends ArrayAdapter<String> { |
||||
|
||||
private List<String> data; |
||||
|
||||
public ForumSearchAdapter(@NonNull Context context, List<String> data) { |
||||
super(context, android.R.layout.simple_list_item_1); |
||||
addAll(data); |
||||
} |
||||
|
||||
|
||||
public void addAll(List<String> data) { |
||||
this.data = data; |
||||
clear(); |
||||
super.addAll(data); |
||||
} |
||||
|
||||
public boolean containsKey(String name) { |
||||
return this.data.contains(name); |
||||
} |
||||
} |
@ -1,11 +1,75 @@ |
||||
package com.community.pocket.ui.main.ui.forum.post; |
||||
|
||||
import androidx.lifecycle.MutableLiveData; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.data.main.forum.ForumRequest; |
||||
import com.community.pocket.util.Valid; |
||||
import com.community.pocket.util.ValidUtil; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 投诉贴数据管理 |
||||
*/ |
||||
class ForumPostComplainViewModel extends ForumPostViewModel { |
||||
|
||||
//投诉帖表单状态
|
||||
private MutableLiveData<ForumPostFormState.Complain> forumPostFormState = new MutableLiveData<>(); |
||||
|
||||
//检索投诉人
|
||||
private MutableLiveData<ForumPostResponse<List<String>>> searchPeople = new MutableLiveData<>(); |
||||
|
||||
ForumPostComplainViewModel(ForumRequest forumRequest) { |
||||
super(forumRequest); |
||||
} |
||||
|
||||
MutableLiveData<ForumPostFormState.Complain> getForumPostFormState() { |
||||
return forumPostFormState; |
||||
} |
||||
|
||||
MutableLiveData<ForumPostResponse<List<String>>> getSearchPeople() { |
||||
return searchPeople; |
||||
} |
||||
|
||||
/** |
||||
* 投诉贴表单校验 |
||||
*/ |
||||
void complainDataChanged(String title, String content, String complain) { |
||||
if (!ValidUtil.titleValid(title)) { |
||||
forumPostFormState.setValue(new ForumPostFormState.Complain(R.string.invalid_title, null, null)); |
||||
} else if (!ValidUtil.notesValid(content)) { |
||||
forumPostFormState.setValue(new ForumPostFormState.Complain(null, R.string.invalid_post, null)); |
||||
} else if (!ValidUtil.usernamevalid(complain)) { |
||||
forumPostFormState.setValue(new ForumPostFormState.Complain(null, null, R.string.invalid_username)); |
||||
} else { |
||||
forumPostFormState.setValue(new ForumPostFormState.Complain(true)); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 发表投诉贴 |
||||
* |
||||
* @param title 标题 |
||||
* @param content 正文 |
||||
* @param complain 投诉人 |
||||
*/ |
||||
void sendComplain(String title, String content, String complain) { |
||||
Valid valid = forumRequest.sendComplain(title, content, complain); |
||||
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)); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 模糊检索投诉人列表 |
||||
* |
||||
* @param name 投诉人 |
||||
*/ |
||||
void searchPeople(String name) { |
||||
ForumPostResponse<List<String>> forumPostResponse = forumRequest.searchPeople(name); |
||||
searchPeople.setValue(forumPostResponse); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue