Merge branch 'dev' of gitlab.ghzs.com:halo/assistant-android into dev
This commit is contained in:
@ -2,13 +2,19 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.gh.gamecenter.message.MessageDetailFragment;
|
||||
import com.halo.assistant.HaloApp;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
* 消息详情界面(评论详情)
|
||||
@ -16,6 +22,23 @@ import com.halo.assistant.HaloApp;
|
||||
@Deprecated
|
||||
public class MessageDetailActivity extends NormalActivity {
|
||||
|
||||
@BindView(R.id.shadowView)
|
||||
public View shadowView;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_message_detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams();
|
||||
layoutParams.height = DisplayUtils.dip2px(50f) + DisplayUtils.getStatusBarHeight(getResources());
|
||||
shadowView.setLayoutParams(layoutParams);
|
||||
DisplayUtils.setStatusBarColor(this, R.color.transparent, false);
|
||||
}
|
||||
|
||||
// 评论回复
|
||||
public static Intent getMessageDetailIntent(Context context, CommentEntity entity, String newsId) {
|
||||
Intent intent = new Intent(context, MessageDetailActivity.class);
|
||||
|
||||
@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -272,10 +271,6 @@ class RatingReplyActivity : ListActivity<RatingReplyEntity, RatingReplyViewModel
|
||||
mLayoutParams.height = if (isPopup) DisplayUtils.dip2px(130f) else LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
mLayoutParams.bottomMargin = if (isPopup) height + mOffset - DisplayUtils.dip2px(12f) else 0
|
||||
mReplyEditorContainer.layoutParams = mLayoutParams
|
||||
|
||||
val mReplyContentParams = mReplyContent.layoutParams as FrameLayout.LayoutParams
|
||||
mReplyContentParams.gravity = if (isPopup) Gravity.NO_GRAVITY else Gravity.CENTER_VERTICAL
|
||||
mReplyContent.layoutParams = mReplyContentParams
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@ -11,23 +11,25 @@ import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ErrorHelper;
|
||||
import com.gh.common.util.GsonUtils;
|
||||
import com.gh.common.util.KeyboardHeightObserver;
|
||||
import com.gh.common.util.KeyboardHeightProvider;
|
||||
import com.gh.common.util.PermissionHelper;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.common.util.TextHelper;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.UrlFilterUtils;
|
||||
import com.gh.gamecenter.MessageDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.MessageDetailAdapter;
|
||||
import com.gh.gamecenter.adapter.OnCommentCallBackListener;
|
||||
@ -57,6 +59,9 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
@ -69,18 +74,28 @@ import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG;
|
||||
* Created by CsHeng on 18/12/2017.
|
||||
* 消息详情界面--评论详情--对话详情
|
||||
*/
|
||||
public class MessageDetailFragment extends NormalFragment implements OnCommentCallBackListener, OnBackPressedListener {
|
||||
public class MessageDetailFragment extends NormalFragment implements OnCommentCallBackListener, OnBackPressedListener, KeyboardHeightObserver {
|
||||
|
||||
public static final int REQUEST_UPDATE_COMMENT = 9; // 刷新文章web页面评论数
|
||||
|
||||
@BindView(R.id.message_detail_rv)
|
||||
RecyclerView mMessageDetailRv;
|
||||
@BindView(R.id.comment_send_btn)
|
||||
@BindView(R.id.answer_comment_send_btn)
|
||||
TextView mMessageDetailCommentSend;
|
||||
@BindView(R.id.comment_et)
|
||||
@BindView(R.id.answer_comment_et)
|
||||
EditText mMessageDetailEt;
|
||||
@BindView(R.id.reuse_no_connection)
|
||||
LinearLayout mNoConnection;
|
||||
@BindView(R.id.comment_line)
|
||||
View mCommentLine;
|
||||
@BindView(R.id.shadowView)
|
||||
View mShadowView;
|
||||
@BindView(R.id.answer_content)
|
||||
LinearLayout mCommentContainer;
|
||||
@BindView(R.id.scrollView)
|
||||
ScrollView mScrollView;
|
||||
@BindView(R.id.answer_comment_content_container)
|
||||
View mReplyEditorContainer;
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
@ -96,6 +111,10 @@ public class MessageDetailFragment extends NormalFragment implements OnCommentCa
|
||||
private String newsId;
|
||||
|
||||
private int commentNum = -1; //区分来源 -1:资讯关注列表 !=-1 :新闻详情
|
||||
|
||||
private KeyboardHeightProvider mKeyboardHeightProvider = null;
|
||||
private int mOffset = 0;
|
||||
|
||||
private TextWatcher watcher = new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
@ -156,6 +175,10 @@ public class MessageDetailFragment extends NormalFragment implements OnCommentCa
|
||||
mMessageDetailEt.setFilters(new InputFilter[]{TextHelper.getFilter(140, "评论不能多于140字")});
|
||||
mMessageDetailCommentSend.setEnabled(false);
|
||||
mMessageDetailCommentSend.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_gray_style));
|
||||
mKeyboardHeightProvider = new KeyboardHeightProvider(requireActivity());
|
||||
mMessageDetailRv.post(() -> {
|
||||
mKeyboardHeightProvider.start();
|
||||
});
|
||||
mMessageDetailEt.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (hasFocus) {
|
||||
mMessageDetailEt.setHintTextColor(ContextCompat.getColor(getContext(), R.color.hint));
|
||||
@ -297,113 +320,120 @@ public class MessageDetailFragment extends NormalFragment implements OnCommentCa
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.comment_send_btn)
|
||||
public void OnSendCommentListener() {
|
||||
PermissionHelper.checkReadPhoneStatePermissionBeforeAction(requireContext(), () -> {
|
||||
final String content = mMessageDetailEt.getText().toString();
|
||||
@OnClick({R.id.answer_comment_send_btn,R.id.shadowView})
|
||||
public void OnSendCommentListener(View view) {
|
||||
switch (view.getId()){
|
||||
case R.id.answer_comment_send_btn:
|
||||
PermissionHelper.checkReadPhoneStatePermissionBeforeAction(requireContext(), () -> {
|
||||
final String content = mMessageDetailEt.getText().toString();
|
||||
|
||||
if (content.length() == 0) {
|
||||
Utils.toast(getContext(), "评论内容不能为空!");
|
||||
return;
|
||||
}
|
||||
if (content.length() == 0) {
|
||||
Utils.toast(getContext(), "评论内容不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
CheckLoginUtils.checkLogin(requireContext(), "资讯文章详情-评论详情-写评论", () -> {
|
||||
mSendingDialog = DialogUtils.showWaitDialog(getActivity(), getString(R.string.post_dialog_hint));
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("content", content);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (newsId == null && mConcernEntity == null || newsId == null && mConcernEntity.getId() == null) {
|
||||
Utils.toast(getContext(), "评论异常 id null");
|
||||
mSendingDialog.cancel();
|
||||
return;
|
||||
} else if (newsId == null) {
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
|
||||
PostCommentUtils.addCommentData(getContext(), newsId, jsonObject, mCommentEntity, new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
toast("发表成功");
|
||||
mMessageDetailEt.setText("");
|
||||
CheckLoginUtils.checkLogin(requireContext(), "资讯文章详情-评论详情-写评论", () -> {
|
||||
mSendingDialog = DialogUtils.showWaitDialog(getActivity(), getString(R.string.post_dialog_hint));
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
JSONObject cacheObject = new JSONObject();
|
||||
JSONObject cacheUser = new JSONObject();
|
||||
JSONObject userData = new JSONObject();
|
||||
JSONObject badgeData = new JSONObject();
|
||||
cacheUser.put("_id", mUserInfo.getUserId());
|
||||
cacheUser.put("icon", mUserInfo.getIcon());
|
||||
cacheUser.put("name", mUserInfo.getName());
|
||||
|
||||
if (mUserInfo.getBadge() != null) {
|
||||
badgeData.put("name", mUserInfo.getBadge().getName());
|
||||
badgeData.put("icon", mUserInfo.getBadge().getIcon());
|
||||
cacheUser.put("badge", badgeData);
|
||||
}
|
||||
|
||||
userData.put("is_comment_own", true);
|
||||
cacheObject.put("_id", response.getString("_id"));
|
||||
cacheObject.put("content", content);
|
||||
cacheObject.put("time", System.currentTimeMillis() / 1000);
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
cacheObject.put("me", userData);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
JSONObject cacheParent = new JSONObject();
|
||||
cacheParent.put("user", new JSONObject(GsonUtils.toJson(mCommentEntity.getUser())));
|
||||
cacheParent.put("comment", mCommentEntity.getContent());
|
||||
cacheObject.put("parent", cacheParent);
|
||||
}
|
||||
|
||||
CommentEntity commentEntity = new Gson().fromJson(cacheObject.toString(), CommentEntity.class);
|
||||
if (mConcernEntity != null) {
|
||||
adapter.addNormalComment(commentEntity);
|
||||
}
|
||||
|
||||
modifyNewsCommentOkhttpCache(adapter.findTheLastPriorComment(), cacheObject, newsId);
|
||||
jsonObject.put("content", content);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (mConcernEntity != null) {
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(getContext(), newsId);
|
||||
CommentManager.updateOkhttpCache(getContext(), newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
} else {
|
||||
showNoConnection(false);
|
||||
if (newsId == null && mConcernEntity == null || newsId == null && mConcernEntity.getId() == null) {
|
||||
Utils.toast(getContext(), "评论异常 id null");
|
||||
mSendingDialog.cancel();
|
||||
return;
|
||||
} else if (newsId == null) {
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
|
||||
setSoftInput(false);
|
||||
PostCommentUtils.addCommentData(getContext(), newsId, jsonObject, mCommentEntity, new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
toast("发表成功");
|
||||
mMessageDetailEt.setText("");
|
||||
|
||||
}
|
||||
try {
|
||||
JSONObject cacheObject = new JSONObject();
|
||||
JSONObject cacheUser = new JSONObject();
|
||||
JSONObject userData = new JSONObject();
|
||||
JSONObject badgeData = new JSONObject();
|
||||
cacheUser.put("_id", mUserInfo.getUserId());
|
||||
cacheUser.put("icon", mUserInfo.getIcon());
|
||||
cacheUser.put("name", mUserInfo.getName());
|
||||
|
||||
if (mUserInfo.getBadge() != null) {
|
||||
badgeData.put("name", mUserInfo.getBadge().getName());
|
||||
badgeData.put("icon", mUserInfo.getBadge().getIcon());
|
||||
cacheUser.put("badge", badgeData);
|
||||
}
|
||||
|
||||
userData.put("is_comment_own", true);
|
||||
cacheObject.put("_id", response.getString("_id"));
|
||||
cacheObject.put("content", content);
|
||||
cacheObject.put("time", System.currentTimeMillis() / 1000);
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
cacheObject.put("me", userData);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
JSONObject cacheParent = new JSONObject();
|
||||
cacheParent.put("user", new JSONObject(GsonUtils.toJson(mCommentEntity.getUser())));
|
||||
cacheParent.put("comment", mCommentEntity.getContent());
|
||||
cacheObject.put("parent", cacheParent);
|
||||
}
|
||||
|
||||
CommentEntity commentEntity = new Gson().fromJson(cacheObject.toString(), CommentEntity.class);
|
||||
if (mConcernEntity != null) {
|
||||
adapter.addNormalComment(commentEntity);
|
||||
}
|
||||
|
||||
modifyNewsCommentOkhttpCache(adapter.findTheLastPriorComment(), cacheObject, newsId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (mConcernEntity != null) {
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(getContext(), newsId);
|
||||
CommentManager.updateOkhttpCache(getContext(), newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
} else {
|
||||
showNoConnection(false);
|
||||
}
|
||||
|
||||
setSoftInput(false);
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable e) {
|
||||
mSendingDialog.dismiss();
|
||||
String errorString = null;
|
||||
if (e instanceof HttpException) {
|
||||
try {
|
||||
errorString = ((HttpException) e).response().errorBody().string();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
ErrorHelper.handleError(requireContext(), errorString, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@Override
|
||||
public void postFailed(Throwable e) {
|
||||
mSendingDialog.dismiss();
|
||||
String errorString = null;
|
||||
if (e instanceof HttpException) {
|
||||
try {
|
||||
errorString = ((HttpException) e).response().errorBody().string();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
ErrorHelper.handleError(requireContext(), errorString, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
break;
|
||||
case R.id.shadowView:
|
||||
setSoftInput(false);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -456,6 +486,56 @@ public class MessageDetailFragment extends NormalFragment implements OnCommentCa
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mKeyboardHeightProvider.setKeyboardHeightObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mKeyboardHeightProvider.setKeyboardHeightObserver(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mKeyboardHeightProvider.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyboardHeightChanged(int height, int orientation) {
|
||||
popInputLayout(height > 0, height);
|
||||
}
|
||||
|
||||
private void popInputLayout(boolean isPopup, int height) {
|
||||
if(requireActivity() instanceof MessageDetailActivity){
|
||||
View shadowView = ((MessageDetailActivity) requireActivity()).shadowView;
|
||||
shadowView.setVisibility(isPopup ? View.VISIBLE : View.GONE);
|
||||
shadowView.setOnClickListener(v -> {setSoftInput(false);});
|
||||
}
|
||||
mCommentLine.setVisibility(isPopup ? View.GONE : View.VISIBLE);
|
||||
mShadowView.setVisibility(isPopup ? View.VISIBLE : View.GONE);
|
||||
mCommentContainer.setOrientation(isPopup ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
|
||||
if (isPopup) {
|
||||
mCommentContainer.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.bg_shape_white_radius_10_top_only));
|
||||
} else {
|
||||
mCommentContainer.setBackgroundColor(ContextCompat.getColor(requireActivity(), R.color.white));
|
||||
mOffset = Math.abs(height);
|
||||
}
|
||||
DisplayUtils.setLightStatusBar(requireActivity(), !isPopup);
|
||||
LinearLayout.LayoutParams mScrollViewParams = (LinearLayout.LayoutParams) mScrollView.getLayoutParams();
|
||||
mScrollViewParams.width = isPopup ? LinearLayout.LayoutParams.MATCH_PARENT : 0;
|
||||
mScrollViewParams.height = isPopup ? DisplayUtils.dip2px(64f) : DisplayUtils.dip2px(28f);
|
||||
mScrollView.setLayoutParams(mScrollViewParams);
|
||||
|
||||
RelativeLayout.LayoutParams mLayoutParams = (RelativeLayout.LayoutParams) mReplyEditorContainer.getLayoutParams();
|
||||
mLayoutParams.height = isPopup ? DisplayUtils.dip2px(130f) : LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
mLayoutParams.bottomMargin = isPopup? height + mOffset - DisplayUtils.dip2px(12f) : 0;
|
||||
mReplyEditorContainer.setLayoutParams(mLayoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHandleBackPressed() {
|
||||
if (commentNum != -1 && adapter.getConcernEntity() != null
|
||||
|
||||
@ -6,7 +6,6 @@ import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.*
|
||||
@ -27,12 +26,9 @@ import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.OnCommentCallBackListener
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.baselist.ListFragment
|
||||
import com.gh.gamecenter.entity.CommentDraft
|
||||
import com.gh.gamecenter.entity.CommentEntity
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailFragment
|
||||
import com.gh.gamecenter.room.AppDatabase
|
||||
import com.gh.gamecenter.room.dao.CommentDraftDao
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Util_System_Keyboard
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
@ -417,10 +413,6 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
|
||||
mLayoutParams.height = if (isPopup)DisplayUtils.dip2px(130f)else LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
mLayoutParams.bottomMargin = if (isPopup)height + mOffset - DisplayUtils.dip2px(12F) else 0
|
||||
commentInputContainer.layoutParams = mLayoutParams
|
||||
|
||||
val mReplyContentParams = commentEt.layoutParams as FrameLayout.LayoutParams
|
||||
mReplyContentParams.gravity = if (isPopup)Gravity.NO_GRAVITY else Gravity.CENTER_VERTICAL
|
||||
commentEt.layoutParams = mReplyContentParams
|
||||
}
|
||||
|
||||
override fun onLoadEmpty() {
|
||||
|
||||
Reference in New Issue
Block a user