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.
87 lines
2.8 KiB
87 lines
2.8 KiB
package com.community.pocket.ui.main.ui.forum.post;
|
|
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
import androidx.lifecycle.Observer;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.ui.BaseFragment;
|
|
import com.community.pocket.ui.main.ui.forum.main.ForumFragment;
|
|
import com.community.pocket.ui.main.ui.share.Response;
|
|
import com.community.pocket.ui.main.ui.share.ShowWordCount;
|
|
|
|
import org.xutils.view.annotation.ViewInject;
|
|
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 发送正文界面
|
|
*/
|
|
abstract class ForumPostContent extends BaseFragment {
|
|
|
|
/**
|
|
* 发送标题
|
|
*/
|
|
EditText postTitle;
|
|
|
|
/**
|
|
* 发帖按钮
|
|
*/
|
|
Button postButton;
|
|
|
|
|
|
@ViewInject(R.id.post_content_layout)
|
|
private ConstraintLayout contentLayout;
|
|
|
|
//发送正文
|
|
EditText postContent;
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_count_bottom, R.id.show_count_top}, R.id.post_content, view);
|
|
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);
|
|
postButton = parentView.findViewById(R.id.post_button);
|
|
postContent = contentLayout.findViewById(R.id.post_content);
|
|
}
|
|
|
|
//监听发帖状态
|
|
void sendPost(ForumPostViewModel viewModel) {
|
|
viewModel.getForumPostResponse().observe(getViewLifecycleOwner(), new Observer<ForumPostResponse>() {
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Override
|
|
public void onChanged(ForumPostResponse forumPostResponse) {
|
|
if (forumPostResponse == null) {
|
|
return;
|
|
}
|
|
|
|
forumPostResponse.toast(getContext());
|
|
if (forumPostResponse.getResult() == Response.Result.OK) {
|
|
ForumFragment forumFragment = getParentFragment(4);
|
|
Button button = Objects.requireNonNull(forumFragment.getView()).findViewById(R.id.forum_new);
|
|
forumFragment._new(button);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|