Esempio n. 1
0
 /** 下载 */
 @Override
 public void onDownloadMessageComplete(ECError e, ECMessage message) {
   if (e.errorCode == SdkErrorCode.REQUEST_SUCCESS) {
     if (message == null) return;
     // 处理发送文件IM消息的时候进度回调
     LogUtil.d(TAG, "[onDownloadMessageComplete] msgId:" + message.getMsgId());
     postDowloadMessageResult(message);
   } else {
     // 重试下载3次
     SyncMsgEntry remove = syncMessage.remove(message.getMsgId());
     if (remove == null) {
       return;
     }
     LogUtil.d(TAG, "[onDownloadMessageComplete] download fail , retry :" + remove.retryCount);
     retryDownload(remove);
   }
 }
Esempio n. 2
0
 /** 收到新的IM文本和附件消息 */
 @Override
 public void OnReceivedMessage(ECMessage msg) {
   LogUtil.d(TAG, "[OnReceivedMessage] show notice true");
   if (msg == null) {
     return;
   }
   postReceiveMessage(msg, true);
 }
Esempio n. 3
0
 @Override
 public void onProgress(String msgId, int totalByte, int progressByte) {
   // 处理发送文件IM消息的时候进度回调
   LogUtil.d(
       TAG,
       "[IMChattingHelper - onProgress] msgId: "
           + msgId
           + " , totalByte: "
           + totalByte
           + " , progressByte:"
           + progressByte);
 }
Esempio n. 4
0
 @Override
 public void onReceiveOfflineMessage(List<ECMessage> msgs) {
   // 离线消息的处理可以参考 void OnReceivedMessage(ECMessage msg)方法
   // 处理逻辑完全一样
   // 参考 IMChattingHelper.java
   LogUtil.d(TAG, "[onReceiveOfflineMessage] show notice false");
   if (msgs != null && !msgs.isEmpty() && !isFirstSync) isFirstSync = true;
   for (ECMessage msg : msgs) {
     mOfflineMsg = msg;
     postReceiveMessage(msg, false);
   }
 }
Esempio n. 5
0
 @Override
 public void onProgress(String msgId, int total, int progress) {
   // 处理发送文件IM消息的时候进度回调
   LogUtil.d(
       TAG,
       "[IMChattingHelper - onProgress] msgId:"
           + msgId
           + " ,total:"
           + total
           + " ,progress:"
           + progress);
 }
Esempio n. 6
0
 public void getPersonInfo() {
   LogUtil.d(TAG, "[getPersonInfo] currentVersion :");
   final ClientUser clientUser = CCPAppManager.getClientUser();
   if (clientUser == null) {
     return;
   }
   LogUtil.d(
       TAG,
       "[getPersonInfo] currentVersion :"
           + clientUser.getpVersion()
           + " ,ServerVersion: "
           + mServicePersonVersion);
   if (clientUser.getpVersion() < mServicePersonVersion) {
     SDKCoreHelper.getECChatManager()
         .getPersonInfo(
             new ECChatManager.OnGetPersonInfoListener() {
               @Override
               public void onGetPersonInfoComplete(ECError e, PersonInfo p) {
                 clientUser.setpVersion(p.getVersion());
                 clientUser.setSex(p.getSex());
                 clientUser.setUserName(p.getNickName());
                 if (!TextUtils.isEmpty(p.getBirth())) {
                   clientUser.setBirth(DateUtil.getActiveTimelong(p.getBirth()));
                 }
                 String newVersion = clientUser.toString();
                 LogUtil.d(TAG, "[getPersonInfo -result] ClientUser :" + newVersion);
                 try {
                   ECPreferences.savePreference(
                       ECPreferenceSettings.SETTINGS_REGIST_AUTO, newVersion, true);
                 } catch (InvalidClassException e1) {
                   e1.printStackTrace();
                 }
               }
             });
   }
 }
Esempio n. 7
0
  /**
   * 处理接收消息
   *
   * @param msg
   * @param showNotice
   */
  private synchronized void postReceiveMessage(ECMessage msg, boolean showNotice) {
    // 接收到的IM消息,根据IM消息类型做不同的处理
    // IM消息类型:ECMessage.Type
    if (msg.getType() != ECMessage.Type.TXT) {
      ECFileMessageBody body = (ECFileMessageBody) msg.getBody();
      FileAccessor.initFileAccess();
      if (!TextUtils.isEmpty(body.getRemoteUrl())) {
        boolean thumbnail = false;
        String fileExt = DemoUtils.getExtensionName(body.getRemoteUrl());
        if (msg.getType() == ECMessage.Type.VOICE) {
          body.setLocalUrl(
              new File(
                      FileAccessor.getVoicePathName(),
                      DemoUtils.md5(String.valueOf(System.currentTimeMillis())) + ".amr")
                  .getAbsolutePath());
        } else if (msg.getType() == ECMessage.Type.IMAGE) {
          ECImageMessageBody imageBody = (ECImageMessageBody) body;
          thumbnail = !TextUtils.isEmpty(imageBody.getThumbnailFileUrl());
          imageBody.setLocalUrl(
              new File(
                      FileAccessor.getImagePathName(),
                      DemoUtils.md5(
                              thumbnail
                                  ? imageBody.getThumbnailFileUrl()
                                  : imageBody.getRemoteUrl())
                          + "."
                          + fileExt)
                  .getAbsolutePath());
        } else {
          body.setLocalUrl(
              new File(
                      FileAccessor.getFilePathName(),
                      DemoUtils.md5(String.valueOf(System.currentTimeMillis())) + "." + fileExt)
                  .getAbsolutePath());
        }
        if (syncMessage != null) {
          syncMessage.put(msg.getMsgId(), new SyncMsgEntry(showNotice, thumbnail, msg));
        }
        if (mChatManager != null) {
          if (thumbnail) {
            mChatManager.downloadThumbnailMessage(msg, this);
          } else {
            mChatManager.downloadMediaMessage(msg, this);
          }
        }
        if (TextUtils.isEmpty(body.getFileName()) && !TextUtils.isEmpty(body.getRemoteUrl())) {
          body.setFileName(FileAccessor.getFileName(body.getRemoteUrl()));
        }
        msg.setUserData("fileName=" + body.getFileName());
        if (IMessageSqlManager.insertIMessage(msg, msg.getDirection().ordinal()) > 0) {
          return;
        }
      } else {
        LogUtil.e(TAG, "ECMessage fileUrl: null");
      }
    }
    if (IMessageSqlManager.insertIMessage(msg, msg.getDirection().ordinal()) <= 0) {
      return;
    }

    if (mOnMessageReportCallback != null) {
      ArrayList<ECMessage> msgs = new ArrayList<ECMessage>();
      msgs.add(msg);
      mOnMessageReportCallback.onPushMessage(msg.getSessionId(), msgs);
    }

    // 是否状态栏提示
    if (showNotice) showNotification(msg);
  }