Commit 74affc6a210998e584aeb946b958edb249946be7

Authored by 谷俊
1 parent 22283030

添加上传进度功能

app/src/main/java/com/cnlive/im/adapter/ChatRoomAdpter.java
... ... @@ -202,12 +202,14 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
202 202 private TextView ima_user_name;
203 203 private ImageView img_content;
204 204 private TextView status;
  205 + private TextView uploadProgress;
205 206  
206 207 public ImaMessageHolder(View itemView) {
207 208 super(itemView);
208 209 ima_user_name = (TextView) itemView.findViewById(R.id.img_user_name);
209 210 img_content = (ImageView) itemView.findViewById(R.id.img_content);
210 211 status = (TextView) itemView.findViewById(R.id.status);
  212 + uploadProgress = (TextView) itemView.findViewById(R.id.uploadProgress);
211 213 }
212 214  
213 215 public void showMessage(final ImagMessage imagMessage) {
... ... @@ -219,16 +221,24 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
219 221 case IChat.CN_MSG_STATUS_SENDING:
220 222 if (status != null)
221 223 status.setText("发送中");
  224 + if (uploadProgress != null) {
  225 + uploadProgress.setVisibility(View.VISIBLE);
  226 + uploadProgress.setText("上传进度:" + imagMessage.getProgress() + "%");
  227 + }
222 228 Glide.with(mContext).load(imagMessage.getCnImgMessage().getImagePath()).into(img_content);
223 229 break;
224 230 case IChat.CN_MSG_STATUS_SEND_FAIL:
225 231 if (status != null)
226 232 status.setText("发送失败");
  233 + if (uploadProgress != null)
  234 + uploadProgress.setVisibility(View.GONE);
227 235 Glide.with(mContext).load(imagMessage.getCnImgMessage().getImagePath()).into(img_content);
228 236 break;
229 237 case IChat.CN_MSG_STATUS_SEND_SUCCESS:
230 238 if (status != null)
231 239 status.setText("发送成功");
  240 + if (uploadProgress != null)
  241 + uploadProgress.setVisibility(View.GONE);
232 242 sendSuccess(imagMessage);
233 243 break;
234 244 }
... ... @@ -280,6 +290,7 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
280 290 private TextView voice_duration;
281 291 private View voice_none_read;
282 292 private TextView status;
  293 + private TextView uploadProgress;
283 294  
284 295 public VoiceMessageHolder(View itemView) {
285 296 super(itemView);
... ... @@ -288,6 +299,7 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
288 299 voice_duration = (TextView) itemView.findViewById(R.id.voice_duration);
289 300 voice_none_read = itemView.findViewById(R.id.noneRead);
290 301 status = (TextView) itemView.findViewById(R.id.status);
  302 + uploadProgress = (TextView) itemView.findViewById(R.id.uploadProgress);
291 303 }
292 304  
293 305 public void showMessage(final VoiceMessage voiceMessage) {
... ... @@ -298,14 +310,22 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
298 310 case IChat.CN_MSG_STATUS_SENDING:
299 311 if (status != null)
300 312 status.setText("发送中");
  313 + if (uploadProgress != null) {
  314 + uploadProgress.setVisibility(View.VISIBLE);
  315 + uploadProgress.setText("上传进度:" + voiceMessage.getProgress() + "%");
  316 + }
301 317 break;
302 318 case IChat.CN_MSG_STATUS_SEND_FAIL:
303 319 if (status != null)
304 320 status.setText("发送失败");
  321 + if (uploadProgress != null)
  322 + uploadProgress.setVisibility(View.GONE);
305 323 break;
306 324 case IChat.CN_MSG_STATUS_SEND_SUCCESS:
307 325 if (status != null)
308 326 status.setText("发送成功");
  327 + if (uploadProgress != null)
  328 + uploadProgress.setVisibility(View.GONE);
309 329 sendSuccess(voiceMessage);
310 330 break;
311 331 }
... ... @@ -332,6 +352,7 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
332 352 private ImageView video_snapshot;
333 353 private View videoLayout;
334 354 private TextView status;
  355 + private TextView uploadProgress;
335 356  
336 357 public VideoMessageHolder(View itemView) {
337 358 super(itemView);
... ... @@ -339,6 +360,7 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
339 360 video_snapshot = (ImageView) itemView.findViewById(R.id.img_content);
340 361 videoLayout = itemView.findViewById(R.id.videoLayout);
341 362 status = (TextView) itemView.findViewById(R.id.status);
  363 + uploadProgress = (TextView) itemView.findViewById(R.id.uploadProgress);
342 364 }
343 365  
344 366 public void showMessage(final VideoMessage videoMessage) {
... ... @@ -347,16 +369,24 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
347 369 case IChat.CN_MSG_STATUS_SENDING:
348 370 if (status != null)
349 371 status.setText("发送中");
  372 + if (uploadProgress != null) {
  373 + uploadProgress.setVisibility(View.VISIBLE);
  374 + uploadProgress.setText("上传进度:" + videoMessage.getProgress() + "%");
  375 + }
350 376 Glide.with(mContext).load(videoMessage.getCnVideoMessage().getSnapshotPath()).into(video_snapshot);
351 377 break;
352 378 case IChat.CN_MSG_STATUS_SEND_FAIL:
353 379 if (status != null)
354 380 status.setText("发送失败");
  381 + if (uploadProgress != null)
  382 + uploadProgress.setVisibility(View.GONE);
355 383 Glide.with(mContext).load(videoMessage.getCnVideoMessage().getSnapshotPath()).into(video_snapshot);
356 384 break;
357 385 case IChat.CN_MSG_STATUS_SEND_SUCCESS:
358 386 if (status != null)
359 387 status.setText("发送成功");
  388 + if (uploadProgress != null)
  389 + uploadProgress.setVisibility(View.GONE);
360 390 sendSuccess(videoMessage);
361 391 break;
362 392 }
... ... @@ -406,6 +436,7 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
406 436 private ImageView video_cover;
407 437 private View videoLayout;
408 438 private TextView status;
  439 + private TextView uploadProgress;
409 440  
410 441 public UgcVideoMessageHolder(View itemView) {
411 442 super(itemView);
... ... @@ -413,6 +444,7 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
413 444 video_cover = (ImageView) itemView.findViewById(R.id.img_content);
414 445 videoLayout = itemView.findViewById(R.id.videoLayout);
415 446 status = (TextView) itemView.findViewById(R.id.status);
  447 + uploadProgress = (TextView) itemView.findViewById(R.id.uploadProgress);
416 448 }
417 449  
418 450 public void showMessage(final UgcVideoMessage videoMessage) {
... ... @@ -421,16 +453,24 @@ public class ChatRoomAdpter extends BaseRecyclerAdapter {
421 453 case IChat.CN_MSG_STATUS_SENDING:
422 454 if (status != null)
423 455 status.setText("发送中");
  456 + if (uploadProgress != null) {
  457 + uploadProgress.setVisibility(View.VISIBLE);
  458 + uploadProgress.setText("上传进度:" + videoMessage.getProgress() + "%");
  459 + }
424 460 Glide.with(mContext).load(videoMessage.getCnUgcMessage().getCoverPath()).into(video_cover);
425 461 break;
426 462 case IChat.CN_MSG_STATUS_SEND_FAIL:
427 463 if (status != null)
428 464 status.setText("发送失败");
  465 + if (uploadProgress != null)
  466 + uploadProgress.setVisibility(View.GONE);
429 467 Glide.with(mContext).load(videoMessage.getCnUgcMessage().getCoverPath()).into(video_cover);
430 468 break;
431 469 case IChat.CN_MSG_STATUS_SEND_SUCCESS:
432 470 if (status != null)
433 471 status.setText("发送成功");
  472 + if (uploadProgress != null)
  473 + uploadProgress.setVisibility(View.GONE);
434 474 sendSuccess(videoMessage);
435 475 break;
436 476 }
... ...
app/src/main/java/com/cnlive/im/mode/ImagMessage.java
... ... @@ -13,6 +13,7 @@ public class ImagMessage {
13 13 boolean isUserSend;
14 14  
15 15 private boolean isDownloading = false;
  16 + private int progress = 0;
16 17  
17 18  
18 19 public String getType() {
... ... @@ -52,4 +53,19 @@ public class ImagMessage {
52 53 this.cnImgMessage = cnImgMessage;
53 54 this.isUserSend = isUserSend;
54 55 }
  56 +
  57 + public ImagMessage(String type, CNImgMessage cnImgMessage, boolean isUserSend, int progress) {
  58 + this.type = type;
  59 + this.cnImgMessage = cnImgMessage;
  60 + this.isUserSend = isUserSend;
  61 + this.progress = progress;
  62 + }
  63 +
  64 + public int getProgress() {
  65 + return progress;
  66 + }
  67 +
  68 + public void setProgress(int progress) {
  69 + this.progress = progress;
  70 + }
55 71 }
... ...
app/src/main/java/com/cnlive/im/mode/UgcVideoMessage.java
... ... @@ -12,6 +12,7 @@ public class UgcVideoMessage {
12 12 boolean isUserSend;
13 13  
14 14 private boolean isDownloading = false;
  15 + private int progress = 0;
15 16  
16 17 public UgcVideoMessage(String type, CNUgcMessage cnUgcMessage, boolean isUserSend) {
17 18 this.type = type;
... ... @@ -19,6 +20,14 @@ public class UgcVideoMessage {
19 20 this.isUserSend = isUserSend;
20 21 }
21 22  
  23 + public UgcVideoMessage(String type, CNUgcMessage cnUgcMessage, boolean isUserSend, int progress) {
  24 + this.type = type;
  25 + this.cnUgcMessage = cnUgcMessage;
  26 + this.isUserSend = isUserSend;
  27 + this.progress = progress;
  28 + }
  29 +
  30 +
22 31 public String getType() {
23 32 return type;
24 33 }
... ... @@ -50,5 +59,13 @@ public class UgcVideoMessage {
50 59 public void setDownloading(boolean downloading) {
51 60 isDownloading = downloading;
52 61 }
  62 +
  63 + public int getProgress() {
  64 + return progress;
  65 + }
  66 +
  67 + public void setProgress(int progress) {
  68 + this.progress = progress;
  69 + }
53 70 }
54 71  
... ...
app/src/main/java/com/cnlive/im/mode/VideoMessage.java
... ... @@ -13,6 +13,7 @@ public class VideoMessage {
13 13 boolean isUserSend;
14 14  
15 15 private boolean isDownloading = false;
  16 + private int progress;
16 17  
17 18 public VideoMessage(String type, CNVideoMessage cnVideoMessage, boolean isUserSend) {
18 19 this.type = type;
... ... @@ -20,6 +21,14 @@ public class VideoMessage {
20 21 this.isUserSend = isUserSend;
21 22 }
22 23  
  24 +
  25 + public VideoMessage(String type, CNVideoMessage cnVideoMessage, boolean isUserSend, int progress) {
  26 + this.type = type;
  27 + this.cnVideoMessage = cnVideoMessage;
  28 + this.isUserSend = isUserSend;
  29 + this.progress = progress;
  30 + }
  31 +
23 32 public String getType() {
24 33 return type;
25 34 }
... ... @@ -51,4 +60,12 @@ public class VideoMessage {
51 60 public void setDownloading(boolean downloading) {
52 61 isDownloading = downloading;
53 62 }
  63 +
  64 + public int getProgress() {
  65 + return progress;
  66 + }
  67 +
  68 + public void setProgress(int progress) {
  69 + this.progress = progress;
  70 + }
54 71 }
... ...
app/src/main/java/com/cnlive/im/mode/VoiceMessage.java
... ... @@ -12,12 +12,21 @@ public class VoiceMessage {
12 12 private CNVoiceMessage cnVoiceMessage;
13 13 boolean isUserSend;
14 14  
  15 + private int progress;
  16 +
15 17 public VoiceMessage(String type, CNVoiceMessage cnVoiceMessage, boolean isUserSend) {
16 18 this.type = type;
17 19 this.cnVoiceMessage = cnVoiceMessage;
18 20 this.isUserSend = isUserSend;
19 21 }
20 22  
  23 + public VoiceMessage(String type, CNVoiceMessage cnVoiceMessage, boolean isUserSend, int progress) {
  24 + this.type = type;
  25 + this.cnVoiceMessage = cnVoiceMessage;
  26 + this.isUserSend = isUserSend;
  27 + this.progress = progress;
  28 + }
  29 +
21 30 public String getType() {
22 31 return type;
23 32 }
... ... @@ -41,4 +50,12 @@ public class VoiceMessage {
41 50 public void setUserSend(boolean userSend) {
42 51 isUserSend = userSend;
43 52 }
  53 +
  54 + public int getProgress() {
  55 + return progress;
  56 + }
  57 +
  58 + public void setProgress(int progress) {
  59 + this.progress = progress;
  60 + }
44 61 }
... ...
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
... ... @@ -74,7 +74,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
74 74  
75 75 private final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 0x2001;
76 76  
77   - private ArrayList<String> groupChatOneListMy;
  77 + private ArrayList<String> msgIds = new ArrayList<>();
78 78 private String roomIdOne = "ChatRoom10";
79 79 private EditText editText;
80 80 private Button send_messageOneBtn;
... ... @@ -132,7 +132,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
132 132 mHandler = new Handler();
133 133 ChatUtil.setOnConnectStatusListener(connectStatusListener);
134 134 ChatUtil.setOnChatRoomActionListener(chatRoomActionListener);
135   - ChatUtil.setOnReceiveMessageListener(receiveMessageListener);
  135 + ChatUtil.setOnReceiveChatroomMessageListener(receiveMessageListener);
  136 + ChatUtil.setUploadProgressListener(uploadProgressListener);
136 137 ChatUtil.setKickedOfflineListener(onKickedOfflineListener);
137 138 Intent intent = getIntent();
138 139 user_name_string = intent.getStringExtra("user_name_string");
... ... @@ -168,7 +169,6 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
168 169 exit_chat1.setOnClickListener(this);
169 170 foundChatBtn.setOnClickListener(this);
170 171 send_messageOneBtn.setOnClickListener(this);
171   - groupChatOneListMy = new ArrayList<>();
172 172 chatListAdapterOne = new ChatRoomAdpter(ChatRoomActivity.this, false);
173 173 chatListAdapterOne.setonVoiceItemClickListener(this);
174 174 listViewOne.setLayoutManager(new LinearLayoutManager(ChatRoomActivity.this));
... ... @@ -200,12 +200,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
200 200  
201 201 @Override
202 202 public void onSuccess(final CNBaseMessage o) {
203   - updateItem(o);
  203 + updateItem(o, -1);
204 204 }
205 205  
206 206 @Override
207 207 public void onError(CNBaseMessage o, int i, String s) {
208   - updateItem(o);
  208 + updateItem(o, -1);
209 209 }
210 210 };
211 211  
... ... @@ -221,15 +221,25 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
221 221 private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
222 222 @Override
223 223 public void processMessage(final CNBaseMessage o) {
  224 + if (!o.getTargetId().equals(roomIdOne)) return;
224 225 showMessage(o);
225 226 }
226 227 };
227 228  
  229 + private IChat.OnUploadProgressListener uploadProgressListener = new IChat.OnUploadProgressListener() {
  230 + @Override
  231 + public void onMessagesUpdate(CNBaseMessage message, int elemIdx, int taskId, int progress) {
  232 + if (!message.getTargetId().equals(roomIdOne)) return;
  233 + updateItem(message, progress);
  234 + }
  235 + };
  236 +
  237 +
228 238 /**
229 239 * 更新消息
230 240 */
231   - public void updateItem(CNBaseMessage o) {
232   - int updateIndex = groupChatOneListMy.indexOf(o.getMessageId());
  241 + public void updateItem(CNBaseMessage o, int progress) {
  242 + int updateIndex = msgIds.indexOf(o.getMessageId());
233 243 if (updateIndex < 0 || chatListAdapterOne.getItemCount() <= 0 || updateIndex > chatListAdapterOne.getItemCount() - 1)
234 244 return;
235 245 if (o.getMsgType() == IChat.CN_MSG_TYPE_TEXT) {
... ... @@ -237,18 +247,18 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
237 247 chatListAdapterOne.updateItem(new StringMessage(MessageType.stringMessage, o1, o1.isSelf()), updateIndex);
238 248 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_IMAGE) {
239 249 CNImgMessage o1 = (CNImgMessage) o;
240   - chatListAdapterOne.updateItem(new ImagMessage(MessageType.imaMessage, o1, o1.isSelf()), updateIndex);
  250 + chatListAdapterOne.updateItem(new ImagMessage(MessageType.imaMessage, o1, o1.isSelf(), progress < 0 ? 0 : progress), updateIndex);
241 251 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VOICE) {
242 252 CNVoiceMessage o1 = (CNVoiceMessage) o;
243   - VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, o1.isSelf());
  253 + VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, o1.isSelf(), progress < 0 ? 0 : progress);
244 254 chatListAdapterOne.updateItem(voiceMessage, updateIndex);
245 255 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VIDEO) {
246 256 CNVideoMessage ol = (CNVideoMessage) o;
247   - VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, ol, ol.isSelf());
  257 + VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, ol, ol.isSelf(), progress < 0 ? 0 : progress);
248 258 chatListAdapterOne.updateItem(videoMessage, updateIndex);
249 259 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_UGC) {
250 260 CNUgcMessage ol = (CNUgcMessage) o;
251   - UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, ol, ol.isSelf());
  261 + UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, ol, ol.isSelf(), progress < 0 ? 0 : progress);
252 262 chatListAdapterOne.updateItem(ugcVideoMessage, updateIndex);
253 263 }
254 264 }
... ... @@ -259,7 +269,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
259 269 * @param o
260 270 */
261 271 private void showMessage(CNBaseMessage o) {
262   - groupChatOneListMy.add(o.getMessageId());
  272 + msgIds.add(o.getMessageId());
263 273 if (o.getMsgType() == IChat.CN_MSG_TYPE_TEXT) {
264 274 CNMessage o1 = (CNMessage) o;
265 275 chatListAdapterOne.addItem(new StringMessage(MessageType.stringMessage, o1, o1.isSelf()));
... ... @@ -271,12 +281,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
271 281 VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, o1.isSelf());
272 282 chatListAdapterOne.addItem(voiceMessage);
273 283 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VIDEO) {
274   - CNVideoMessage ol = (CNVideoMessage) o;
275   - VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, ol, ol.isSelf());
  284 + CNVideoMessage o1 = (CNVideoMessage) o;
  285 + VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, o1, o1.isSelf());
276 286 chatListAdapterOne.addItem(videoMessage);
277 287 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_UGC) {
278   - CNUgcMessage ol = (CNUgcMessage) o;
279   - UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, ol, ol.isSelf());
  288 + CNUgcMessage o1 = (CNUgcMessage) o;
  289 + UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, o1, o1.isSelf());
280 290 chatListAdapterOne.addItem(ugcVideoMessage);
281 291 }
282 292 if (chatListAdapterOne.getItemCount() > 0)
... ... @@ -817,7 +827,10 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
817 827 @Override
818 828 protected void onDestroy() {
819 829 super.onDestroy();
  830 + ChatUtil.removeUploadProgressListener(uploadProgressListener);
820 831 ChatUtil.removeReceiveMessageListener(receiveMessageListener);
821 832 ChatUtil.removeConnectListener(connectListener);
  833 + ChatUtil.removeConnectStatusListener(connectStatusListener);
822 834 }
  835 +
823 836 }
... ...
app/src/main/java/com/cnlive/im/ui/PrivateActivity.java
... ... @@ -99,7 +99,7 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
99 99 private EditText messageContent;
100 100 private Button sendMessageBtn;
101 101 private ChatRoomAdpter chatListAdapter;
102   - private ArrayList<String> messageList = new ArrayList<>();
  102 + private ArrayList<String> msgIds = new ArrayList<>();
103 103 // private CNMessage cnMessage;
104 104 private LinearLayout linearLayoutUseID;
105 105 private EditText user_id_edit;
... ... @@ -144,6 +144,7 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
144 144 mHandler = new Handler();
145 145 ChatUtil.setOnConnectStatusListener(connectStatusListener);
146 146 ChatUtil.setOnReceivePrivateMessageListener(receiveMessageListener);
  147 + ChatUtil.setUploadProgressListener(uploadProgressListener);
147 148 requestPermission();
148 149 }
149 150  
... ... @@ -414,12 +415,12 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
414 415  
415 416 @Override
416 417 public void onSuccess(final CNBaseMessage o) {
417   - updateItem(o);
  418 + updateItem(o, -1);
418 419 }
419 420  
420 421 @Override
421 422 public void onError(CNBaseMessage o, int i, String s) {
422   - updateItem(o);
  423 + updateItem(o, -1);
423 424 }
424 425 };
425 426  
... ... @@ -436,15 +437,24 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
436 437 private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
437 438 @Override
438 439 public void processMessage(final CNBaseMessage o) {
  440 + if (!o.getTargetId().equals(oppositeID)) return;
439 441 showMessage(o, true);
440 442 }
441 443 };
442 444  
  445 + private IChat.OnUploadProgressListener uploadProgressListener = new IChat.OnUploadProgressListener() {
  446 + @Override
  447 + public void onMessagesUpdate(CNBaseMessage message, int elemIdx, int taskId, int progress) {
  448 + if (!message.getTargetId().equals(oppositeID)) return;
  449 + updateItem(message, progress);
  450 + }
  451 + };
  452 +
443 453 /**
444 454 * 更新消息
445 455 */
446   - public void updateItem(CNBaseMessage o) {
447   - int updateIndex = messageList.indexOf(o.getMessageId());
  456 + public void updateItem(CNBaseMessage o, int progress) {
  457 + int updateIndex = msgIds.indexOf(o.getMessageId());
448 458 if (updateIndex < 0 || chatListAdapter.getItemCount() <= 0 || updateIndex > chatListAdapter.getItemCount() - 1)
449 459 return;
450 460 if (o.getMsgType() == IChat.CN_MSG_TYPE_TEXT) {
... ... @@ -452,18 +462,18 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
452 462 chatListAdapter.updateItem(new StringMessage(MessageType.stringMessage, o1, o1.isSelf()), updateIndex);
453 463 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_IMAGE) {
454 464 CNImgMessage o1 = (CNImgMessage) o;
455   - chatListAdapter.updateItem(new ImagMessage(MessageType.imaMessage, o1, o1.isSelf()), updateIndex);
  465 + chatListAdapter.updateItem(new ImagMessage(MessageType.imaMessage, o1, o1.isSelf(), progress < 0 ? 0 : progress), updateIndex);
456 466 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VOICE) {
457 467 CNVoiceMessage o1 = (CNVoiceMessage) o;
458   - VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, o1.isSelf());
  468 + VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, o1.isSelf(), progress < 0 ? 0 : progress);
459 469 chatListAdapter.updateItem(voiceMessage, updateIndex);
460 470 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VIDEO) {
461 471 CNVideoMessage ol = (CNVideoMessage) o;
462   - VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, ol, ol.isSelf());
  472 + VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, ol, ol.isSelf(), progress < 0 ? 0 : progress);
463 473 chatListAdapter.updateItem(videoMessage, updateIndex);
464 474 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_UGC) {
465 475 CNUgcMessage ol = (CNUgcMessage) o;
466   - UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, ol, ol.isSelf());
  476 + UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, ol, ol.isSelf(), progress < 0 ? 0 : progress);
467 477 chatListAdapter.updateItem(ugcVideoMessage, updateIndex);
468 478 }
469 479 }
... ... @@ -490,7 +500,7 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
490 500 sendInfo = 4;
491 501 } else if ("4".equals(type)) {
492 502 Log.v(TAG, o1.getContent().toString());
493   - messageList.add(o.getMessageId());
  503 + msgIds.add(o.getMessageId());
494 504 chatListAdapter.addItem(new StringMessage(MessageType.stringMessage, o1, false));
495 505 }
496 506 } catch (JSONException e) {
... ... @@ -512,28 +522,28 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
512 522 } else if ("3".equals(type) && message.equals("同意")) {
513 523 sendInfo = 1;
514 524 } else if ("4".equals(type)) {
515   - messageList.add(o.getMessageId());
  525 + msgIds.add(o.getMessageId());
516 526 chatListAdapter.addItem(new StringMessage(MessageType.stringMessage, o1, true));
517 527 }
518 528 } catch (JSONException e) {
519 529 }
520 530 }
521 531 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_IMAGE) {
522   - messageList.add(o.getMessageId());
  532 + msgIds.add(o.getMessageId());
523 533 CNImgMessage o1 = (CNImgMessage) o;
524 534 chatListAdapter.addItem(new ImagMessage(MessageType.imaMessage, o1, o1.isSelf()));
525 535 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VOICE) {
526   - messageList.add(o.getMessageId());
  536 + msgIds.add(o.getMessageId());
527 537 CNVoiceMessage o1 = (CNVoiceMessage) o;
528 538 VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, o1.isSelf());
529 539 chatListAdapter.addItem(voiceMessage);
530 540 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_VIDEO) {
531   - messageList.add(o.getMessageId());
  541 + msgIds.add(o.getMessageId());
532 542 CNVideoMessage ol = (CNVideoMessage) o;
533 543 VideoMessage videoMessage = new VideoMessage(MessageType.videoMessage, ol, ol.isSelf());
534 544 chatListAdapter.addItem(videoMessage);
535 545 } else if (o.getMsgType() == IChat.CN_MSG_TYPE_UGC) {
536   - messageList.add(o.getMessageId());
  546 + msgIds.add(o.getMessageId());
537 547 CNUgcMessage ol = (CNUgcMessage) o;
538 548 UgcVideoMessage ugcVideoMessage = new UgcVideoMessage(MessageType.ugcVideoMessage, ol, ol.isSelf());
539 549 chatListAdapter.addItem(ugcVideoMessage);
... ... @@ -874,7 +884,9 @@ public class PrivateActivity extends AppCompatActivity implements View.OnClickLi
874 884 @Override
875 885 protected void onDestroy() {
876 886 super.onDestroy();
  887 + ChatUtil.removeUploadProgressListener(uploadProgressListener);
877 888 ChatUtil.removeReceiveMessageListener(receiveMessageListener);
878 889 ChatUtil.removeConnectListener(connectListener);
  890 + ChatUtil.removeConnectStatusListener(connectStatusListener);
879 891 }
880 892 }
... ...
app/src/main/res/layout/imag_layout_item_user.xml
... ... @@ -13,6 +13,15 @@
13 13 android:orientation="horizontal">
14 14  
15 15 <TextView
  16 + android:id="@+id/uploadProgress"
  17 + android:layout_width="wrap_content"
  18 + android:layout_height="wrap_content"
  19 + android:layout_gravity="center_vertical"
  20 + android:layout_marginRight="5dp"
  21 + android:gravity="center"
  22 + android:textColor="@android:color/black" />
  23 +
  24 + <TextView
16 25 android:id="@+id/status"
17 26 android:layout_width="wrap_content"
18 27 android:layout_height="wrap_content"
... ...
app/src/main/res/layout/video_layout_item_user.xml
... ... @@ -13,6 +13,15 @@
13 13 android:layout_alignParentRight="true">
14 14  
15 15 <TextView
  16 + android:id="@+id/uploadProgress"
  17 + android:layout_width="wrap_content"
  18 + android:layout_height="wrap_content"
  19 + android:layout_gravity="center_vertical"
  20 + android:layout_marginRight="5dp"
  21 + android:gravity="center"
  22 + android:textColor="@android:color/black" />
  23 +
  24 + <TextView
16 25 android:id="@+id/status"
17 26 android:layout_width="wrap_content"
18 27 android:layout_height="wrap_content"
... ...
app/src/main/res/layout/voice_layout_item_user.xml
... ... @@ -11,6 +11,15 @@
11 11 android:layout_alignParentRight="true">
12 12  
13 13 <TextView
  14 + android:id="@+id/uploadProgress"
  15 + android:layout_width="wrap_content"
  16 + android:layout_height="wrap_content"
  17 + android:layout_gravity="center_vertical"
  18 + android:layout_marginRight="5dp"
  19 + android:gravity="center"
  20 + android:textColor="@android:color/black" />
  21 +
  22 + <TextView
14 23 android:id="@+id/status"
15 24 android:layout_width="wrap_content"
16 25 android:layout_height="wrap_content"
... ...