Skip to content

Commit 091e015

Browse files
committed
fix transfer ,add deleteMessage
1 parent 70b5e6a commit 091e015

File tree

7 files changed

+65
-14
lines changed

7 files changed

+65
-14
lines changed

android/messagelist/src/main/java/cn/jiguang/imui/messages/viewholder/BankTransferViewHolder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import android.support.v7.widget.RecyclerView;
44
import android.text.TextUtils;
5+
import android.util.Log;
56
import android.view.View;
67
import android.widget.TextView;
78

89
import java.text.DecimalFormat;
910

11+
import cn.jiguang.imui.BuildConfig;
1012
import cn.jiguang.imui.R;
1113
import cn.jiguang.imui.commons.models.IBankTransfer;
1214
import cn.jiguang.imui.commons.models.IMessage;
@@ -49,6 +51,19 @@ public void onClick(View v) {
4951
}
5052
}
5153
});
54+
layoutTop.setOnLongClickListener(new View.OnLongClickListener() {
55+
@Override
56+
public boolean onLongClick(View v) {
57+
if (mMsgLongClickListener != null) {
58+
mMsgLongClickListener.onMessageLongClick(message);
59+
} else {
60+
if (BuildConfig.DEBUG) {
61+
Log.w("MsgListAdapter", "Didn't set long click listener! Drop event.");
62+
}
63+
}
64+
return true;
65+
}
66+
});
5267
}
5368

5469
final DecimalFormat format = new DecimalFormat("#.00");

android/messagelist/src/main/java/cn/jiguang/imui/messages/viewholder/RedPacketViewHolder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package cn.jiguang.imui.messages.viewholder;
22

33
import android.support.v7.widget.RecyclerView;
4+
import android.util.Log;
45
import android.view.View;
56
import android.widget.TextView;
67

8+
import cn.jiguang.imui.BuildConfig;
79
import cn.jiguang.imui.R;
810
import cn.jiguang.imui.commons.models.IMessage;
911
import cn.jiguang.imui.commons.models.IRedPacket;
@@ -40,6 +42,19 @@ public void onClick(View v) {
4042
}
4143
}
4244
});
45+
layoutTop.setOnLongClickListener(new View.OnLongClickListener() {
46+
@Override
47+
public boolean onLongClick(View v) {
48+
if (mMsgLongClickListener != null) {
49+
mMsgLongClickListener.onMessageLongClick(message);
50+
} else {
51+
if (BuildConfig.DEBUG) {
52+
Log.w("MsgListAdapter", "Didn't set long click listener! Drop event.");
53+
}
54+
}
55+
return true;
56+
}
57+
});
4358
}
4459

4560
@Override

android/messagelist/src/main/res/layout/item_receive_bank_transfer.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
android:background="@drawable/red_packet_top">
4141

4242
<ImageView
43+
android:padding="3dp"
4344
android:id="@+id/icon"
4445
android:layout_margin="@dimen/red_packet_image_margin"
4546
android:src="@drawable/transfer"

android/messagelist/src/main/res/layout/item_send_bank_transfer.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,31 @@
5656
android:background="@drawable/red_packet_top">
5757

5858
<ImageView
59+
android:padding="3dp"
5960
android:id="@+id/icon"
6061
android:layout_width="wrap_content"
6162
android:layout_height="wrap_content"
6263
android:layout_margin="@dimen/red_packet_image_margin"
6364
android:src="@drawable/transfer" />
6465

6566
<TextView
66-
android:id="@+id/bank_transfer_value"
67+
android:id="@+id/bank_transfer_comments"
6768
android:layout_width="match_parent"
6869
android:layout_height="wrap_content"
6970
android:layout_marginTop="@dimen/red_packet_top"
7071
android:layout_toRightOf="@+id/icon"
7172
android:ellipsize="end"
7273
android:lines="1"
73-
android:text="100.00¥"
7474
android:textColor="@color/red_packet_comments"
7575
android:textSize="@dimen/red_packet_comments_size" />
7676

7777
<TextView
78-
android:id="@+id/bank_transfer_comments"
78+
android:id="@+id/bank_transfer_value"
7979
android:layout_width="match_parent"
8080
android:layout_height="wrap_content"
81-
android:layout_below="@+id/bank_transfer_value"
81+
android:layout_below="@+id/bank_transfer_comments"
8282
android:layout_marginTop="6dp"
8383
android:layout_toRightOf="@+id/icon"
84-
android:text="备注"
8584
android:textColor="@color/red_packet_text"
8685
android:textSize="@dimen/red_packet_text_size" />
8786
</RelativeLayout>

android/src/main/java/cn/jiguang/imui/messagelist/AuroraIMUIModule.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ public void insertMessage(ReadableMap message) {
7777
}
7878

7979
@ReactMethod
80-
public void deleteMessage(ReadableMap message) {
80+
public void deleteMessage(ReadableArray messages) {
81+
String[] rctMessages = new String[messages.size()];
82+
for (int i = 0; i < messages.size(); i++) {
83+
RCTMessage rctMessage = configMessage(messages.getMap(i));
84+
rctMessages[i] = rctMessage.toString();
85+
}
86+
Intent intent = new Intent();
87+
intent.setAction(ReactMsgListManager.RCT_DELETE_MESSAGES_ACTION);
88+
intent.putExtra("messages", rctMessages);
89+
getReactApplicationContext().sendBroadcast(intent);
8190
}
8291

8392

android/src/main/java/cn/jiguang/imui/messagelist/ReactMsgListManager.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public class ReactMsgListManager extends ViewGroupManager<MessageList> {
7373
public static final String RCT_APPEND_MESSAGES_ACTION = "cn.jiguang.imui.messagelist.intent.appendMessages";
7474
public static final String RCT_UPDATE_MESSAGE_ACTION = "cn.jiguang.imui.messagelist.intent.updateMessage";
7575
public static final String RCT_INSERT_MESSAGES_ACTION = "cn.jiguang.imui.messagelist.intent.insertMessages";
76+
public static final String RCT_DELETE_MESSAGES_ACTION = "cn.jiguang.imui.messagelist.intent.deleteMessages";
77+
7678
public static final String RCT_SCROLL_TO_BOTTOM_ACTION = "cn.jiguang.imui.messagelist.intent.scrollToBottom";
7779

7880
private MsgListAdapter mAdapter;
@@ -93,6 +95,7 @@ protected MessageList createViewInstance(final ThemedReactContext reactContext)
9395
intentFilter.addAction(RCT_APPEND_MESSAGES_ACTION);
9496
intentFilter.addAction(RCT_UPDATE_MESSAGE_ACTION);
9597
intentFilter.addAction(RCT_INSERT_MESSAGES_ACTION);
98+
intentFilter.addAction(RCT_DELETE_MESSAGES_ACTION);
9699
intentFilter.addAction(RCT_SCROLL_TO_BOTTOM_ACTION);
97100

98101
mContext = reactContext;
@@ -224,7 +227,7 @@ public void onLoadMore(int i, int i1) {
224227

225228
void showMenu(final ReactContext reactContext, final RCTMessage message) {
226229
CustomAlertDialog dialog = new CustomAlertDialog(reactContext.getCurrentActivity());
227-
if(message.getType()== IMessage.MessageType.RECEIVE_TEXT||message.getType()== IMessage.MessageType.SEND_TEXT) {
230+
if (message.getType() == IMessage.MessageType.RECEIVE_TEXT || message.getType() == IMessage.MessageType.SEND_TEXT) {
228231
dialog.addItem("复制", new CustomAlertDialog.onSeparateItemClickListener() {
229232
@Override
230233
public void onClick() {
@@ -248,9 +251,9 @@ public void onClick() {
248251
ON_STATUS_VIEW_CLICK_EVENT, event);
249252
}
250253
});
251-
if(message.isOutgoing()
252-
&&(message.getType()!= IMessage.MessageType.SEND_RED_PACKET
253-
||message.getType()!= IMessage.MessageType.SEND_BANK_TRANSFER)) {
254+
if (message.isOutgoing()
255+
&& (message.getType() != IMessage.MessageType.SEND_RED_PACKET
256+
|| message.getType() != IMessage.MessageType.SEND_BANK_TRANSFER)) {
254257
dialog.addItem("撤回", new CustomAlertDialog.onSeparateItemClickListener() {
255258
@Override
256259
public void onClick() {
@@ -302,16 +305,17 @@ private static List<PopupMenuItem> getMoreMenuItems(Context context, String sess
302305
}
303306

304307
@ReactProp(name = "initList")
305-
public void setInitList(MessageList messageList, ReadableArray messages){
306-
if(messages!=null&&messages.size()>0) {
308+
public void setInitList(MessageList messageList, ReadableArray messages) {
309+
if (messages != null && messages.size() > 0) {
307310
final List<RCTMessage> list = new ArrayList<>();
308311
for (int i = 0; i < messages.size(); i++) {
309312
RCTMessage rctMessage = configMessage(messages.getMap(i));
310313
list.add(rctMessage);
311314
}
312-
mAdapter.addToStart(list,true);
315+
mAdapter.addToStart(list, true);
313316
}
314317
}
318+
315319
@ReactProp(name = "sendBubble")
316320
public void setSendBubble(MessageList messageList, ReadableMap map) {
317321
int resId = mContext.getResources().getIdentifier(map.getString("imageName"), "drawable", mContext.getPackageName());
@@ -453,6 +457,12 @@ public void run() {
453457
Log.i("RCTMessageListManager", "Scroll to bottom");
454458
mAdapter.getLayoutManager().scrollToPosition(0);
455459
mAdapter.getLayoutManager().requestLayout();
460+
} else if (intent.getAction().equals(RCT_DELETE_MESSAGES_ACTION)) {
461+
String[] messages = intent.getStringArrayExtra("messages");
462+
for (int i = 0; i < messages.length; i++) {
463+
final RCTMessage rctMessage = gson.fromJson(messages[i], RCTMessage.class);
464+
mAdapter.delete(rctMessage);
465+
}
456466
}
457467
}
458468
};

android/src/main/java/cn/jiguang/imui/messagelist/module/RCTMessage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public JsonElement toJSON() {
227227
if (msgType != null) {
228228
json.addProperty(MessageConstant.Message.MSG_TYPE, msgTypeStr);
229229
}
230-
json.addProperty(MessageConstant.Message.IS_OUTGOING, isOutgoing);
230+
json.addProperty(MessageConstant.Message.IS_OUTGOING, isOutgoing );
231231
if (timeString != null) {
232232
json.addProperty(MessageConstant.Message.TIME_STRING, timeString);
233233
}
@@ -253,6 +253,8 @@ public WritableMap toWritableMap() {
253253
writableMap.putString(MessageConstant.Message.MSG_ID, msgId);
254254
writableMap.putString(MessageConstant.Message.STATUS, statusStr);
255255
writableMap.putString(MessageConstant.Message.MSG_TYPE, msgTypeStr);
256+
writableMap.putString(MessageConstant.Message.MSG_TEXT, text);
257+
writableMap.putString(MessageConstant.Message.IS_OUTGOING, isOutgoing? "0" : "1");
256258
// writableMap.putString(MessageConstant.Message.STATUS, progress);
257259
if (rctUser != null) {
258260
writableMap.putMap(MessageConstant.Message.FROM_USER, rctUser.toWritableMap());

0 commit comments

Comments
 (0)