コード例 #1
0
  public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.cht_alert_btn_yes) {
      dismiss();
      if (AlertType == 1) {
        try {
          // appSession.setData(ChatSession.CONNECTION_DATA, contactConn);
          // Contact conn = chatSession.getSelectedConnection();
          if (chatManager.getContactByLocalPublicKey(contactConn.getRemoteActorPublicKey())
              == null) {
            ContactImpl newContact = new ContactImpl();
            newContact.setAlias(contactConn.getAlias());
            newContact.setRemoteActorType(contactConn.getRemoteActorType());
            newContact.setRemoteActorPublicKey(contactConn.getRemoteActorPublicKey());
            newContact.setRemoteName(contactConn.getRemoteName());
            newContact.setContactId(UUID.randomUUID());
            newContact.setCreationDate(System.currentTimeMillis());
            newContact.setContactStatus(contactConn.getContactStatus());
            newContact.setProfileImage(contactConn.getProfileImage());
            chatManager.saveContact(newContact);
            addcontact = true;
            Toast.makeText(getActivity(), "Contact added", Toast.LENGTH_SHORT).show();
            // changeActivity(Activities.CHT_CHAT_OPEN_CONTACTLIST, appSession.getAppPublicKey());
            // dismiss();
          } else {
            Toast.makeText(getActivity(), "Contact already exist", Toast.LENGTH_SHORT).show();

            // changeActivity(Activities.CHT_CHAT_OPEN_CONTACTLIST, appSession.getAppPublicKey());
            // dismiss();
          }
          dismiss();
          mAdapterCallback.onMethodCallbackContacts(); // solution to access to update contacts. j

        } catch (CantSaveContactException e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        } catch (Exception e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        }
        // changeActivity(Activities.CHT_CHAT_OPEN_CHATLIST, appSession.getAppPublicKey());
      } else if (AlertType == 2) {
        try {
          Contact con = chatSession.getSelectedContact();
          chatManager.deleteContact(con);
          List<Contact> cont = chatManager.getContacts();
          if (cont.size() > 0) {
            for (int i = 0; i < cont.size(); i++) {
              contactname.add(cont.get(i).getAlias());
              contactid.add(cont.get(i).getContactId());
              ByteArrayInputStream bytes = new ByteArrayInputStream(cont.get(i).getProfileImage());
              BitmapDrawable bmd = new BitmapDrawable(bytes);
              contacticon.add(bmd.getBitmap());
            }
            final ContactListAdapter adaptador =
                new ContactListAdapter(
                    getActivity(),
                    contactname,
                    contacticon,
                    contactid,
                    chatManager,
                    moduleManager,
                    errorManager,
                    chatSession,
                    getSession(),
                    null);
            adaptador.refreshEvents(contactname, contacticon, contactid);
          }
        } catch (CantGetContactException e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        } catch (Exception e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        }
        delete_contact = true;
      }
    }

    if (id == R.id.cht_alert_btn_no) {
      dismiss();
    }
  }