コード例 #1
0
ファイル: ChatFragment.java プロジェクト: hrsyah1970/SIPTKI
  public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
    this.sipUri = newSipUri;
    this.displayName = displayName;
    this.pictureUri = pictureUri;

    if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) {
      ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage();
      if (chatStorage.getDraft(sipUri) == null) {
        chatStorage.saveDraft(sipUri, message.getText().toString());
      } else {
        chatStorage.updateDraft(sipUri, message.getText().toString());
      }
    } else if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
    }

    if (LinphoneActivity.isInstanciated()) {
      String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
      if (draft == null) draft = "";
      message.setText(draft);
    }

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    displayChatHeader(displayName, pictureUri);
    dispayMessageList();
  }
コード例 #2
0
  private boolean importAndroidStoredMessagedIntoLibLinphoneStorage() {
    Log.w("Importing previous messages into new database...");
    try {
      ChatStorage db = LinphoneActivity.instance().getChatStorage();
      List<String> conversations = db.getChatList();
      for (int j = conversations.size() - 1; j >= 0; j--) {
        String correspondent = conversations.get(j);
        LinphoneChatRoom room = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);
        for (ChatMessage message : db.getMessages(correspondent)) {
          LinphoneChatMessage msg =
              room.createLinphoneChatMessage(
                  message.getMessage(),
                  message.getUrl(),
                  message.getStatus(),
                  Long.parseLong(message.getTimestamp()),
                  true,
                  message.isIncoming());
          if (message.getImage() != null) {
            String path = saveImageAsFile(message.getId(), message.getImage());
            if (path != null) msg.setExternalBodyUrl(path);
          }
          msg.store();
        }
        db.removeDiscussion(correspondent);
      }
      return true;
    } catch (Exception e) {
      e.printStackTrace();
    }

    return false;
  }
コード例 #3
0
  public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
    if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) {
      ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage();
      if (chatStorage.getDraft(sipUri) == null) {
        chatStorage.saveDraft(sipUri, message.getText().toString());
      } else {
        chatStorage.updateDraft(sipUri, message.getText().toString());
      }
    } else if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
    }

    sipUri = newSipUri;
    if (LinphoneActivity.isInstanciated()) {
      String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
      if (draft == null) draft = "";
      message.setText(draft);
    }

    displayChatHeader(displayName, pictureUri);
    displayMessages();
  }
コード例 #4
0
 public ChatStorage getChatStorage() {
   return ChatStorage.getInstance();
 }