Пример #1
0
        public MessagesPage(int dialogId, MessagesManager messagesManager, DialogsManager dialogsManager)
        {
            this.dialogId        = dialogId;
            this.messagesManager = messagesManager;
            this.dialogsManager  = dialogsManager;

            NavigationPage.SetHasNavigationBar(this, false);
            SetBinding(RotaryFocusObjectProperty, new Binding {
                Source = messagesListView
            });
            messagesListView.ItemsSource = messagesManager.GetMessages(dialogId);
            absoluteLayout.Children.Add(messagesListView);
            absoluteLayout.Children.Add(popupEntryView);
            absoluteLayout.Children.Add(activityIndicator);
            Content = absoluteLayout;

            swipeLeftRecognizer.Command  = new Command(OpenKeyboard);
            swipeRightRecognizer.Command = new Command(OnOpenRecorder);
            messagesListView.GestureRecognizers.Add(swipeLeftRecognizer);
            messagesListView.GestureRecognizers.Add(swipeRightRecognizer);

            messagesListView.ItemTapped      += OnItemTapped;
            messagesListView.ItemLongPressed += OnItemLongPressed;
            messagesListView.ItemAppearing   += OnLoadMoreMessages;
            popupEntryView.Completed         += OnTextCompleted;

            if (dialogsManager.GetIsInitRequired(this.dialogId))
            {
                Appearing += OnConstructor;
            }
        }
Пример #2
0
        /// <summary>
        /// Load more messages when scroll reached the end of the page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnLoadMoreMessages(object sender, ItemVisibilityEventArgs e)
        {
            if (dialogsManager.GetIsInitRequired(dialogId))
            {
                return;
            }

            var message       = (Message)e.Item;
            var messagesCount = messagesManager.GetMessagesCount(dialogId);

            if (messagesCount >= Consts.BatchSize && messagesManager.IsMessageOlderThanAll(dialogId, message.Id))
            {
                activityIndicator.IsVisible = true;
                await NetExceptionCatchHelpers.CatchNetException(
                    async() =>
                {
                    await messagesManager.UpdateMessagesFromApi(dialogId, messagesCount);
                    messagesListView.ScrollIfExist(message, ScrollToPosition.Center);
                },
                    () =>
                {
                    OnLoadMoreMessages(sender, e);
                    return(Task.CompletedTask);
                },
                    LocalizedStrings.MessagesNoInternetError);

                activityIndicator.IsVisible = false;
            }
        }