Exemple #1
0
        public async override void HandleWatchKitExtensionRequest(UIApplication application, NSDictionary userInfo, Action <NSDictionary> reply)
        {
            if (userInfo ["Profile"] != null && userInfo ["Profile"].ToString() == "Profile")
            {
                var conversationsViewModel = App.ConversationsViewModel;
                await conversationsViewModel.ExecuteLoadConversationsCommand();

                var conversationsList = conversationsViewModel.Conversations.ToList();
                ConversationsStore.Save(conversationsList);

                foreach (var conversation in conversationsList)
                {
                    var conversationViewModel = new ConversationViewModel(conversation.Sender);
                    await conversationViewModel.ExecuteLoadMessagesCommand();

                    ConversationsStore.Save(conversationViewModel.Messages.Select(i => i.UnderlyingMessage).ToList(), string.Format("conversation-{0}.xml", conversation.Sender));
                }

                var    viewModel   = App.ProfileViewModel;
                NSData avatarImage = !string.IsNullOrEmpty(viewModel.AvatarUrl) ? ImageUtils.GetImage(viewModel.AvatarUrl, url => url == viewModel.AvatarUrl).AsPNG() : new NSData();

                reply(new NSDictionary("Username", viewModel.NickName, "Avatar", avatarImage));
            }

            if (userInfo ["TextInput"] != null && userInfo ["TextInput"].ToString() != string.Empty)
            {
                var number = userInfo ["SenderID"] as NSNumber;
                var conversationViewModel = new ConversationViewModel(number.Int32Value);
                await conversationViewModel.ExecuteLoadMessagesCommand();

                await conversationViewModel.SendMessage(userInfo ["TextInput"].ToString());

                reply(new NSDictionary("Confirmation", "Text was received"));
            }
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            viewModel.PropertyChanged            += OnPropertyChanged;
            viewModel.Messages.CollectionChanged += OnMessagesCollectionChanged;
            viewModel.ExecuteLoadMessagesCommand();
        }
        private async void LoadMessages()
        {
            await viewModel.ExecuteLoadMessagesCommand();

            foreach (MessageViewModel message in viewModel.Messages)
            {
                if (!message.IsIncoming)
                {
                    message.PropertyChanged += (object s, PropertyChangedEventArgs propertyChangedEventArgs) => {
                        DispatchQueue.MainQueue.DispatchAsync(() => {
                            CollectionView.ReloadData();
                        });
                    };
                }
            }
        }
Exemple #4
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            willShowToken     = UIKeyboard.Notifications.ObserveWillShow(KeyboardWillShowHandler);
            willHideToken     = UIKeyboard.Notifications.ObserveWillHide(KeyboardWillHideHandler);
            willHideMenuToken = UIMenuController.Notifications.ObserveWillHideMenu(MenuWillHide);

            UpdateTableInsets();
            UpdateButtonState();

            viewModel.PropertyChanged            += OnPropertyChanged;
            viewModel.Messages.CollectionChanged += OnMessagesCollectionChanged;
            viewModel.ExecuteLoadMessagesCommand();

            ScrollToBottom(false);
        }
		public async override void HandleWatchKitExtensionRequest (UIApplication application, NSDictionary userInfo, Action<NSDictionary> reply)
		{
			if (userInfo ["Profile"] != null && userInfo ["Profile"].ToString () == "Profile") {
				var conversationsViewModel = App.ConversationsViewModel;
				await conversationsViewModel.ExecuteLoadConversationsCommand ();
				var conversationsList = conversationsViewModel.Conversations.ToList ();
				ConversationsStore.Save (conversationsList);

				foreach (var conversation in conversationsList) {
					var conversationViewModel = new ConversationViewModel (conversation.Sender);
					await conversationViewModel.ExecuteLoadMessagesCommand ();
					ConversationsStore.Save (conversationViewModel.Messages.Select(i => i.UnderlyingMessage).ToList (), string.Format ("conversation-{0}.xml", conversation.Sender));
				}

				var viewModel = App.ProfileViewModel;
				NSData avatarImage = !string.IsNullOrEmpty (viewModel.AvatarUrl) ? ImageUtils.GetImage (viewModel.AvatarUrl, url => url == viewModel.AvatarUrl).AsPNG () : new NSData ();

				reply (new NSDictionary ("Username", viewModel.NickName, "Avatar", avatarImage));
			}

			if (userInfo ["TextInput"] != null && userInfo ["TextInput"].ToString () != string.Empty) {
				var number = userInfo ["SenderID"] as NSNumber;
				var conversationViewModel = new ConversationViewModel (number.Int32Value);
				await conversationViewModel.ExecuteLoadMessagesCommand ();
				await conversationViewModel.SendMessage (userInfo ["TextInput"].ToString ());

				reply (new NSDictionary ("Confirmation", "Text was received"));
			}
		}