Search in sources :

Example 11 with IChatSessionManager

use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.

the class MainActivity method startGroupChat.

public void startGroupChat(String room, String server, String nickname, final ArrayList<String> invitees, IImConnection conn) {
    mLastConnGroup = conn;
    new AsyncTask<String, Long, String>() {

        private ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            dialog = new ProgressDialog(MainActivity.this);
            dialog.setMessage(getString(R.string.connecting_to_group_chat_));
            dialog.setCancelable(true);
            dialog.show();
        }

        @Override
        protected String doInBackground(String... params) {
            String subject = params[0];
            String chatRoom = "group" + UUID.randomUUID().toString().substring(0, 8);
            String server = params[1];
            try {
                IChatSessionManager manager = mLastConnGroup.getChatSessionManager();
                String roomAddress = (chatRoom + '@' + server).toLowerCase(Locale.US);
                String nickname = params[2];
                IChatSession session = manager.getChatSession(roomAddress);
                if (session == null) {
                    session = manager.createMultiUserChatSession(roomAddress, subject, nickname, true);
                    if (session != null) {
                        mRequestedChatId = session.getId();
                        publishProgress(mRequestedChatId);
                    } else {
                        return getString(R.string.unable_to_create_or_join_group_chat);
                    }
                } else {
                    mRequestedChatId = session.getId();
                    publishProgress(mRequestedChatId);
                }
                if (invitees != null && invitees.size() > 0) {
                    // wait a second for the server to sort itself out
                    try {
                        Thread.sleep(100);
                    } catch (Exception e) {
                    }
                    for (String invitee : invitees) session.inviteContact(invitee);
                }
                return null;
            } catch (RemoteException e) {
                return e.toString();
            }
        }

        @Override
        protected void onProgressUpdate(Long... showChatId) {
            showChat(showChatId[0]);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
            if (result != null) {
            // mHandler.showServiceErrorAlert(result);
            }
        }
    }.executeOnExecutor(ImApp.sThreadPoolExecutor, room, server, nickname);
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) ProgressDialog(android.app.ProgressDialog) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Aggregations

RemoteException (android.os.RemoteException)11 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)11 IChatSession (org.awesomeapp.messenger.service.IChatSession)10 IOException (java.io.IOException)4 Intent (android.content.Intent)3 CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)2 DecoderException (org.apache.commons.codec.DecoderException)2 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)2 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)2 IImConnection (org.awesomeapp.messenger.service.IImConnection)2 ProgressDialog (android.app.ProgressDialog)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 KeyPair (java.security.KeyPair)1 ImApp (org.awesomeapp.messenger.ImApp)1 IOtrChatSession (org.awesomeapp.messenger.crypto.IOtrChatSession)1 OtrAndroidKeyManagerImpl (org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl)1 Contact (org.awesomeapp.messenger.model.Contact)1