From 1171424f1919eabe8961eca18be8743651cdf2db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E4=B9=85?= <1484288157@qq.com>
Date: Tue, 26 May 2020 11:53:53 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E8=AE=AF=E6=96=87?=
=?UTF-8?q?=E7=AB=A0=E8=AF=84=E8=AE=BA=E8=AF=A6=E6=83=85=E8=AF=84=E8=AE=BA?=
=?UTF-8?q?=E6=A1=86UI?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/src/main/AndroidManifest.xml | 1 +
.../gh/gamecenter/MessageDetailActivity.java | 23 ++
.../gamedetail/rating/RatingReplyActivity.kt | 5 -
.../message/MessageDetailFragment.java | 282 +++++++++++-------
.../qa/comment/NewCommentFragment.kt | 8 -
.../res/layout/activity_message_detail.xml | 37 +++
.../main/res/layout/activity_rating_reply.xml | 13 -
.../res/layout/fragment_message_detail.xml | 63 +---
.../layout/piece_comment_typing_container.xml | 3 +-
9 files changed, 251 insertions(+), 184 deletions(-)
create mode 100644 app/src/main/res/layout/activity_message_detail.xml
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 309505b810..7894adde32 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -175,6 +175,7 @@
android:screenOrientation="portrait" />
diff --git a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java
index 1da8efd44e..23db3b184f 100644
--- a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java
+++ b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java
@@ -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);
diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyActivity.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyActivity.kt
index 0f91786573..50a5f24e52 100644
--- a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyActivity.kt
+++ b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/RatingReplyActivity.kt
@@ -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 {
+ 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
diff --git a/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt
index 6694beeafd..e01ace0005 100644
--- a/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt
+++ b/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt
@@ -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
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() {
diff --git a/app/src/main/res/layout/activity_message_detail.xml b/app/src/main/res/layout/activity_message_detail.xml
new file mode 100644
index 0000000000..7d7078ee59
--- /dev/null
+++ b/app/src/main/res/layout/activity_message_detail.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_rating_reply.xml b/app/src/main/res/layout/activity_rating_reply.xml
index e5afb22424..0bb3f45b58 100644
--- a/app/src/main/res/layout/activity_rating_reply.xml
+++ b/app/src/main/res/layout/activity_rating_reply.xml
@@ -36,19 +36,6 @@
android:layout_height="wrap_content" />
-
-
-
-
-
-
-
+ android:layout_height = "match_parent" />
+
+ android:id="@+id/shadowView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/black_alpha_30"
+ android:visibility="gone" />
-
+
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/piece_comment_typing_container.xml b/app/src/main/res/layout/piece_comment_typing_container.xml
index 367fdb8b32..aebe96e747 100644
--- a/app/src/main/res/layout/piece_comment_typing_container.xml
+++ b/app/src/main/res/layout/piece_comment_typing_container.xml
@@ -33,8 +33,7 @@
android:layout_weight="1"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:layout_toLeftOf="@+id/answer_comment_send_btn">
+ android:layout_marginRight="20dp">