diff --git a/common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java b/common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java index 1562414a3..1361f1b6c 100644 --- a/common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java +++ b/common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java @@ -1,21 +1,27 @@ package com.yunbao.common.dialog; import android.app.Activity; +import android.graphics.drawable.BitmapDrawable; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.PopupWindow; import com.yunbao.common.R; +import io.rong.imlib.model.Message; + /** * 消息長按彈窗 */ -public class MessageLongClickPopuwindow { +public class MessageLongClickPopuwindow implements View.OnClickListener { private Activity mContext; private View popupView; private PopupWindow popupWindow; private LinearLayout copyLinear; + private Message message; public MessageLongClickPopuwindow(Activity context) { this.mContext = context; @@ -23,6 +29,48 @@ public class MessageLongClickPopuwindow { initView(); } + public MessageLongClickPopuwindow setMessage(Message message) { + this.message = message; + return this; + } + + /** + * 展示弹窗 + * + * @param view 显示在什么组件的上面 + * @return + */ + public void show(View view) { + popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); + int[] location = new int[2]; + view.getLocationOnScreen(location); + popupWindow.setBackgroundDrawable(new BitmapDrawable()); + popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + + int popupWidth = popupView.getMeasuredWidth(); + int popupHeight = popupView.getMeasuredHeight(); + + popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, (location[0] + view.getWidth() / 2) - popupWidth / 2, + location[1] - popupHeight); + } + private void initView() { + popupView.findViewById(R.id.copy_linear).setOnClickListener(this); + popupView.findViewById(R.id.withdraw_linear).setOnClickListener(this); + popupView.findViewById(R.id.quote_linear).setOnClickListener(this); + long sentTime = message.getSentTime(); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + //复制 + if (id == R.id.copy_linear) { + + } else if (id == R.id.withdraw_linear) {//撤回 + + } else if (id == R.id.quote_linear) {//引用 + } + } } diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java index 378c4d185..51e411c57 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java @@ -1,5 +1,6 @@ package com.yunbao.common.manager.imrongcloud; +import android.app.Activity; import android.content.Context; import android.os.Handler; import android.text.TextUtils; @@ -9,6 +10,7 @@ import com.alibaba.fastjson.JSON; import com.google.gson.Gson; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.ImUserInfoModel; +import com.yunbao.common.dialog.MessageLongClickPopuwindow; import com.yunbao.common.event.MessageIMEvent; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; @@ -209,13 +211,16 @@ public class MessageIMManager { private ConversationClickListener listener = new ConversationClickListener() { @Override public boolean onUserPortraitClick(Context context, Conversation.ConversationType conversationType, UserInfo userInfo, String targetId) { - IMLoginModel model = new Gson().fromJson(userInfo.getExtra(), IMLoginModel.class); - long userId = IMLoginManager.get(context).getUserInfo().getId(); - if (!TextUtils.equals(model.getIsAdmin(), "1") && userId != model.getId()) { - RouteUtil.forwardUserHome(mContext, userInfo.getUserId(), 0); - } else if (userId == model.getId()) { - RouteUtil.forwardUserHome(mContext, userInfo.getUserId(), 2); + if (!TextUtils.isEmpty(userInfo.getExtra())){ + IMLoginModel model = new Gson().fromJson(userInfo.getExtra(), IMLoginModel.class); + long userId = IMLoginManager.get(context).getUserInfo().getId(); + if (!TextUtils.equals(model.getIsAdmin(), "1") && userId != model.getId()) { + RouteUtil.forwardUserHome(mContext, userInfo.getUserId(), 0); + } else if (userId == model.getId()) { + RouteUtil.forwardUserHome(mContext, userInfo.getUserId(), 2); + } } + return true; } @@ -234,7 +239,9 @@ public class MessageIMManager { */ @Override public boolean onMessageLongClick(Context context, View view, Message message) { - ToastUtil.show(message.getContent().toString()); + new MessageLongClickPopuwindow((Activity) context) + .setMessage(message) + .show(view); return true; } diff --git a/common/src/main/res/layout/view_message_long_click.xml b/common/src/main/res/layout/view_message_long_click.xml index 32f2e9f1a..7b2caea00 100644 --- a/common/src/main/res/layout/view_message_long_click.xml +++ b/common/src/main/res/layout/view_message_long_click.xml @@ -47,7 +47,7 @@