Beispiel #1
0
        public RoomsViewModel(Page page)
        {
            this.page       = page;
            twilioMessenger = DependencyService.Get <ITwilioMessenger>();

            ConnectCommand = new Command(async() =>
            {
                var success    = false;
                string message = string.Empty;
                try
                {
                    IsBusy  = true;
                    success = await twilioMessenger.InitializeAsync();
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
                finally
                {
                    IsBusy = false;
                }

                if (success)
                {
                    await page.DisplayAlert("Success", "Now joining #general.", "OK");
                    await page.Navigation.PushAsync(new MainChatPage());
                }
                else
                {
                    await page.DisplayAlert("Sad Monkeys", $"Unable to join #general: {message}", "OK");
                }
            });
        }
Beispiel #2
0
        public MessagesViewModel()
        {
            twilioMessenger  = DependencyService.Get <ITwilioMessenger>();
            this.Messages    = new ObservableCollection <object>();
            this.CurrentUser = new Author()
            {
                Name = App.MyIdentity, Avatar = "name.png"
            };
            this.GenerateMessages();

            if (!string.IsNullOrEmpty(App.TypingMessage))
            {
                this.TypingIndicator = new ChatTypingIndicator();
                this.TypingIndicator.Authors.Add(new Author()
                {
                    Name = App.ChatMessages.Count > 0 ?
                           App.ChatMessages[0].Identity : "", Avatar = "name.png"
                });
                this.TypingIndicator.AvatarViewType = AvatarViewType.Image;
                this.TypingIndicator.Text           = App.TypingMessage;
                this.ShowTypingIndicator            = true;
            }
            else
            {
                this.ShowTypingIndicator = false;
            }

            this.BackCommand        = new Command(this.BackButtonClicked);
            this.SendMessageCommand = new Command(this.SendButtonClicked);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RecentChatViewModel" /> class.
        /// </summary>
        public RecentChatViewModel()
        {
            twilioMessenger = DependencyService.Get <ITwilioMessenger>();

            var success = twilioMessenger.GetAllPublicChannels();

            this.ChatItems = App.ChannelDetails;

            this.MakeVoiceCallCommand = new Command(this.VoiceCallClicked);
            this.MakeVideoCallCommand = new Command(this.VideoCallClicked);
            this.ShowSettingsCommand  = new Command(this.SettingsClicked);
            this.MenuCommand          = new Command(this.MenuClicked);
            this.ProfileImageCommand  = new Command(this.ProfileImageClicked);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatMessageViewModel" /> class.
        /// </summary>
        public ChatMessageViewModel()
        {
            twilioMessenger = DependencyService.Get <ITwilioMessenger>();

            //this.MakeVoiceCall = new Command(this.VoiceCallClicked);
            //this.MakeVideoCall = new Command(this.VideoCallClicked);
            //this.MenuCommand = new Command(this.MenuClicked);
            //this.ShowCamera = new Command(this.CameraClicked);
            //this.SendAttachment = new Command(this.AttachmentClicked);
            //this.SendCommand = new Command(this.SendClicked);
            //this.BackCommand = new Command(this.BackButtonClicked);
            //this.ProfileCommand = new Command(this.ProfileClicked);

            this.GenerateMessageInfo();
        }
        public MainChatViewModel()
        {
            // Initialize with default values
            twilioMessenger = DependencyService.Get <ITwilioMessenger>();


            Messages = new ObservableRangeCollection <Message>();

            SendCommand = new Command(() =>
            {
                var message = new Message
                {
                    Text            = OutGoingText,
                    IsIncoming      = false,
                    MessageDateTime = DateTime.Now
                };



                Messages.Add(message);

                currentUser = TwilioHelper.Identity;

                twilioMessenger?.SendMessage(message.Text);

                OutGoingText = string.Empty;
            });


            LocationCommand = new Command(async() =>
            {
                try
                {
                    var local = await CrossGeolocator.Current.GetPositionAsync(10000);
                    var map   = $"https://maps.googleapis.com/maps/api/staticmap?center={local.Latitude.ToString(CultureInfo.InvariantCulture)},{local.Longitude.ToString(CultureInfo.InvariantCulture)}&zoom=17&size=400x400&maptype=street&markers=color:red%7Clabel:%7C{local.Latitude.ToString(CultureInfo.InvariantCulture)},{local.Longitude.ToString(CultureInfo.InvariantCulture)}&key=";

                    var message = new Message
                    {
                        Text            = "I am here",
                        AttachementUrl  = map,
                        IsIncoming      = false,
                        MessageDateTime = DateTime.Now
                    };

                    Messages.Add(message);
                    twilioMessenger?.SendMessage("attach:" + message.AttachementUrl);
                }
                catch (Exception)
                {
                }
            });


            if (twilioMessenger == null)
            {
                return;
            }

            twilioMessenger.MessageAdded = (message) =>
            {
                Messages.Add(message);
            };
        }