Пример #1
0
        public virtual void Xmpp_OnMessage(object sender, MessageEventArgs e)
        {
            if (userLastContacts == null || userLastContacts.Count == 0)
            {
                return;
            }

            if (myActivity.GetType() == typeof(ChatActivity))
            {
            }
            //RunOnUiThread(() =>
            setUserRecentChat(e.From, e.Body);
            msgFriend(sender, e);
            //	);
            //}

            //save ready msg to count
            string lastMsg      = appPreferences.getValueKey("LAST_MSG" + e.From);
            bool   isSaveRecMsg = true;

            if (lastMsg != null)
            {
                if (lastMsg.Equals(e.Body))
                {
                    isSaveRecMsg = false;
                }
            }
            if (LegionUtils.GetUserNameClear(e.From) != null && isSaveRecMsg == true)
            {
                appPreferences.saveKey("LAST_MSG" + e.From, e.Body);
                int countMsg = appPreferences.getValueKeyMSGCount(LegionUtils.GetUserNameClear(e.From));
                appPreferences.saveKeyMSGCount(LegionUtils.GetUserNameClear(e.From), countMsg + 1);
            }
        }
Пример #2
0
 public void CountMessage(object sender, MessageEventArgs e)
 {
     if (LegionUtils.GetUserNameClear(e.From) != null)
     {
         appPreferences.saveKey("LAST_MSG" + e.From, e.Body);
         int countMsg = appPreferences.getValueKeyMSGCount(LegionUtils.GetUserNameClear(e.From));
         appPreferences.saveKeyMSGCount(LegionUtils.GetUserNameClear(e.From), countMsg + 1);
     }
 }
Пример #3
0
        public void msgFriend(object sender, MessageEventArgs e)
        {
            string userNameFriend = LegionUtils.GetUserNameClear(e.From);

            AppCore.Message m   = null;
            Bitmap          bit = null;

            //byte[] bytes = LegionUtils.base64ToByte(e.Body);
            //if (bytes != null)
            //{
            //	bit = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
            //}
            if (bit == null)
            {
                if (e.From.Contains(AppCore.Utils._MUS_SERVER))
                {
                    m = new AppCore.Message(e.From, e.Body, DateTime.Now, false, true);
                }
                else
                {
                    m = new AppCore.Message(e.From, e.Body, DateTime.Now, false);
                }
            }
            else
            {
                string fileName = LegionUtils.SaveBitmapGalerry(bit);
                if (e.From.Contains(AppCore.Utils._MUS_SERVER))
                {
                    m = new AppCore.Message(e.From, e.Body, DateTime.Now, false, true, fileName, true);
                }
                else
                {
                    m = new AppCore.Message(e.From, e.Body, DateTime.Now, false, fileName, true);
                }
            }

            this.message = m;
            if (this.msgs == null)
            {
                msgs = getMsgs(e.From);
            }
            this.msgs.Add(m);
            saveMsg(userNameFriend);

            if (friend != null)
            {
                if (friend.Jid.Split('@')[0].Equals(e.From))
                {
                    RefrashRecycleView(friend);
                }
                else
                {
                    CountMessage(sender, e);
                }
            }
        }
Пример #4
0
        void clearUnreadMessage()
        {
            string jidUser = "";

            inChatJid = null;
            if (isGroupChat)
            {
                jidUser = groupFromGson.Jid;
            }
            else
            {
                jidUser = friend.Jid;
            }
            appPreferences.saveKeyMSGCount(LegionUtils.GetUserNameClear(jidUser.Split('@')[0]), 0);
        }
Пример #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            this.callType = this.Intent.GetStringExtra("callType");
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);
            SetContentView(Resource.Layout.Video);
            Layout          = (RelativeLayout)FindViewById(Resource.Id.layout);
            ActivityService = ActivityService.GetInstance;
            if (friend == null)
            {
                if (this.callType.Equals("incoming"))
                {
                    friend          = new AppCore.User();
                    friend.Jid      = this.Intent.GetStringExtra("userChat");
                    friend.username = LegionUtils.GetUserNameClear(friend.Jid);
                }
                else
                {
                    friend = LegionUtils.getUserson(Intent.GetStringExtra("userChat"));
                }
            }

            //ActivityService.GetInstance.App.Xmpp.OnReceiveSessionAccept += (sender, e) => {
            //	Log.Info("Success connection");

            //	//RunOnUiThread(() =>
            //	//		showConnectionVideo(true)
            //	//		 );

            //};



            //Bgconnection = (ImageView)FindViewById(Resource.Id.
            //                                       bgconnection);
            //avatar = (ImageView)FindViewById(Resource.Id.avatarFriend);
            if (friend.Photo != null)
            {
                //Bitmap bitmap = xmppFace.Base64ToBitmap(friend.Photo);
                //var d = new CircleDrawable(bitmap);
                //avatar.SetBackgroundDrawable(d);
            }
            //TxUserName = (TextView)FindViewById(Resource.Id.userNameFriend);
            //TxUserName.Text = friend.username;
            //TxConnection = (TextView)FindViewById(Resource.Id.connect);

            LeaveButton = (ImageButton)FindViewById(Resource.Id.leaveButton);

            // Load native libraries.
            if (!Build.CpuAbi.ToLower().Contains("x86") && !Build.CpuAbi.ToLower().Contains("arm64"))
            {
                Java.Lang.JavaSystem.LoadLibrary("audioprocessing");
                Java.Lang.JavaSystem.LoadLibrary("audioprocessingJNI");
            }
            Java.Lang.JavaSystem.LoadLibrary("opus");
            Java.Lang.JavaSystem.LoadLibrary("opusJNI");
            Java.Lang.JavaSystem.LoadLibrary("vpx");
            Java.Lang.JavaSystem.LoadLibrary("vpxJNI");

            LeaveButton.Click += new EventHandler(LeaveButton_Click);

            Messaging.Log.Debug("VideoActivity adding event handler Xmpp_OnReceiveSessionTerminate");
            //oadXmppConnect(this);
            ActivityService.GetInstance.App.Xmpp.OnReceiveSessionTerminate += Xmpp_OnReceiveSessionTerminate;
            //ActivityService.GetInstance.App.Xmpp.OnReceiveSessionInitiate += Xmpp_OnReceiveSessionInitiate;

            // For demonstration purposes, use the double-tap gesture
            // to switch between the front and rear camera.
            GestureDetector = new GestureDetector(this, new OnGestureListener(ActivityService.GetInstance.App));

            // Preserve a static container across
            // activity destruction/recreation.
            var c = (RelativeLayout)FindViewById(Resource.Id.container);

            if (Container == null)
            {
                Container = c;

                Toast.MakeText(this, "Double tap to switch camera.", ToastLength.Short).Show();
            }
            Layout.RemoveView(c);

            if (!LocalMediaStarted)
            {
                StartLocalMedia();
            }
        }
Пример #6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.VoiceCall);
            this.callType = this.Intent.GetStringExtra("callType");
            if (friend == null)
            {
                if (this.callType.Equals("incoming"))
                {
                    friend          = new AppCore.User();
                    friend.Jid      = this.Intent.GetStringExtra("userChat");
                    friend.username = LegionUtils.GetUserNameClear(friend.Jid);
                }
                else
                {
                    friend = LegionUtils.getUserson(Intent.GetStringExtra("userChat"));
                }
            }
            App      = App.Instance;
            xmppFace = new XmppFacade();
            App.Xmpp.OnReceiveSessionAccept += (sender, e) =>
            {
                Log.Info("Success connection");
                timer.Interval = 1000;
                timer.Elapsed += OnTimedEvent;
                timer.Enabled  = true;
            };

            Layout       = (RelativeLayout)FindViewById(Resource.Id.layout);
            Bgconnection = (ImageView)FindViewById(Resource.Id.
                                                   bgconnection);
            avatar = (ImageView)FindViewById(Resource.Id.avatarFriend);
            if (friend.Photo != null)
            {
                Bitmap bitmap = xmppFace.Base64ToBitmap(friend.Photo);
                var    d      = new CircleDrawable(bitmap);
                avatar.SetBackgroundDrawable(d);
            }
            TxUserName      = (TextView)FindViewById(Resource.Id.userNameFriend);
            TxUserName.Text = friend.username;
            TxConnection    = (TextView)FindViewById(Resource.Id.time);

            LeaveButton = (ImageButton)FindViewById(Resource.Id.leaveButton);

            // Load native libraries.
            if (!Build.CpuAbi.ToLower().Contains("x86") && !Build.CpuAbi.ToLower().Contains("arm64"))
            {
                Java.Lang.JavaSystem.LoadLibrary("audioprocessing");
                Java.Lang.JavaSystem.LoadLibrary("audioprocessingJNI");
            }
            Java.Lang.JavaSystem.LoadLibrary("opus");
            Java.Lang.JavaSystem.LoadLibrary("opusJNI");
            Java.Lang.JavaSystem.LoadLibrary("vpx");
            Java.Lang.JavaSystem.LoadLibrary("vpxJNI");

            LeaveButton.Click += new EventHandler(LeaveButton_Click);

            Messaging.Log.Debug("VoiceCallActivity adding event handler Xmpp_OnReceiveSessionTerminate");
            //loadXmppConnect(this);
            //App.Instance.Xmpp.OnReceiveSessionTerminate += Xmpp_OnReceiveSessionTerminate;
            //App.Instance.Xmpp.OnReceiveSessionInitiate += Xmpp_OnReceiveSessionInitiate;


            if (!SignallingStarted)
            {
                StartSignalling();
            }

            if (!LocalMediaStarted)
            {
                StartLocalMedia();
            }
        }
Пример #7
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            vh = holder as UserViewHolder;
            if (user.users[position].Photo != null)
            {
                byte[] imageAsBytes = Android.Util.Base64.Decode(user.users[position].Photo, Android.Util.Base64Flags.Default);
                activity.RunOnUiThread(() =>
                {
                    Bitmap bMap = BitmapFactory.DecodeByteArray(imageAsBytes, 0, imageAsBytes.Length);
                    var d       = new CircleDrawable(bMap);
                    vh.Image.SetBackgroundDrawable(d);
                });
            }
            else
            {
                vh.Image.SetBackgroundResource(Resource.Drawable.avatar_upload);
                vh.Image.SetImageResource(Resource.Drawable.circle);
            }

            if (vh.Phone != null)
            {
                vh.Phone.Text = user.users[position].Phone;
            }

            //teste for online user
            if (user.users[position].isGroup)
            {
                vh.IconVideo.Visibility = ViewStates.Gone;
                vh.IconPhone.Visibility = ViewStates.Gone;
                //vh.IconStatusOn.Visibility = ViewStates.Gone;
            }
            else
            {
                vh.IconVideo.Visibility = ViewStates.Visible;
                vh.IconPhone.Visibility = ViewStates.Visible;
            }

            //teste for online user
            if (user.users[position].username != null)
            {
                vh.Name.Text = user.users[position].username.Replace("_", " ");
                if (vh.Name.Text.Contains('@'))
                {
                    vh.Name.Text = vh.Name.Text.Split('@')[0];
                }
            }
            else if (user.users[position].Nick != null)
            {
                vh.Name.Text = user.users[position].Nick.Replace("_", " ");
                if (vh.Name.Text.Contains('@'))
                {
                    vh.Name.Text = vh.Name.Text.Split('@')[0];
                }
            }

            //is msg no ready
            if (user.users[position].username != null || user.users[position].Nick != null)
            {
                int msgCount = appPreferences.getValueKeyMSGCount(LegionUtils.GetUserNameClear(user.users[position].username));
                if (msgCount > 0)
                {
                    vh.fragmentMsg.Visibility = ViewStates.Visible;
                    vh.countMsg.Text          = msgCount.ToString();
                }
                else
                {
                    vh.fragmentMsg.Visibility = ViewStates.Gone;
                }
                vh.fragmentMsg.RefreshDrawableState();
            }

            vh.IconVideo.RefreshDrawableState();
            vh.IconPhone.RefreshDrawableState();
            vh.Name.RefreshDrawableState();
            vh.fragmentMsg.RefreshDrawableState();
            vh.Image.RefreshDrawableState();
        }
Пример #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ChatActivity);
            layout         = FindViewById(Resource.Id.rootRelative);
            mKeyboard      = new Keyboard(this, Resource.Layout.keyboard2);
            smileyKeyBoard = (ImageView)FindViewById(Resource.Id.btn_key_board);

            smileyKeyBoard.Touch += (sender, e) =>
            {
                ShowKeyboardWithAnimation();
            };

            Rect r    = new Rect();
            View view = Window.DecorView;

            view.GetWindowVisibleDisplayFrame(r);
            iHeightDefault = r.Bottom;

            rootView     = (RelativeLayout)FindViewById(Resource.Id.rootRelative);
            relative2    = (RelativeLayout)FindViewById(Resource.Id.relative2);
            usersRecents = getGroupsTempToList(AppPreferences.GROUPS_TEMP);

            rootView.ViewTreeObserver.GlobalLayout += (sender, e) =>
            {
                r    = new Rect();
                view = Window.DecorView;
                view.GetWindowVisibleDisplayFrame(r);

                if (iHeightDefault > r.Bottom)
                {
                    // Keyboard is Show
                    if (relative2.Visibility == ViewStates.Visible)
                    {
                        relative2.Visibility = ViewStates.Gone;
                    }
                }
            };

            var toolbar = loadToolBar(Resource.Id.toolbar);

            toolbar.SetNavigationIcon(Resource.Drawable.back);

            TextView tvToo = (TextView)toolbar.FindViewById(Resource.Id.toolbar_title);

            mLayoutManager = new LinearLayoutManager(this);

            rvList     = (RecyclerView)FindViewById(Resource.Id.rvLista);
            btnSendMsg = (ImageView)FindViewById(Resource.Id.btnEnviar);
            edtMsg     = (EmojiconEditText)FindViewById(Resource.Id.edtMessage);

            EmojiconsFragment.EmojiClicked += (e) =>
            {
                EmojiconsFragment.Input(edtMsg, e);
            };
            EmojiconsFragment.EmojiconBackspaceClicked += (v) =>
            {
                EmojiconsFragment.Backspace(edtMsg);
            };


            this.isGroupChat = Intent.GetBooleanExtra("chatGroup", false);
            jsonUser         = Intent.GetStringExtra("userChat");
            if (jsonUser != null)
            {
                friend = LegionUtils.getUserson(jsonUser);
                appPreferences.saveKeyMSGCount(LegionUtils.GetUserNameClear(friend.Jid), 0);
                inChatJid = LegionUtils.GetUserNameClear(friend.Jid);
            }
            if (this.isGroupChat)
            {
                string gson = Intent.GetStringExtra("groupJson");
                isFromGroup = Intent.GetBooleanExtra("isFromGroup", false);

                if (gson == null || gson.Equals(""))
                {
                    gson = appPreferences.getValueKey(AppPreferences.GROUP_JSON);
                }
                groupFromGson = LegionUtils.getUserson(gson);
                GroupName     = groupFromGson.username;
                inChatJid     = GroupName;

                tvToo.Text = (GroupName.Replace("_", " "));
                tvToo.Text = tvToo.Text.Split('@')[0];
                msgs       = getMsgs(groupFromGson.Jid);
                appPreferences.saveKeyMSGCount(LegionUtils.GetUserNameClear(groupFromGson.Jid), 0);
            }
            else
            {
                friend.Jid = friend.username + "@" + GetString(Resource.String.jid);
                tvToo.Text = (friend.username);
                msgs       = getMsgs(friend.username);
            }


            btnSendMsg.Click += BtnSendMsg_Click;


            RefrashRecycleView();

            //loadXmppConnect(this);
            // ActivityService = new ActivityService(this);


            if (!SignallingStarted)
            {
                StartSignalling();
            }

            var isDirect = Intent.GetBooleanExtra("isDirectCall", false);
            var typeCall = Intent.GetStringExtra("callType");

            if (isDirect)
            {
                if (typeCall.Equals("callPhone"))
                {
                    startCall(PHONE_CALL);
                }
                else
                {
                    startCall(VIDEO_CALL);
                }
            }

            recentConversationsUserName = userService.getRecentUsers(appPreferences);
            clearUnreadMessage();
        }