Ejemplo n.º 1
0
        public async override Task Action(MessageResult result, string value = null)
        {
            if (result.Handled)
            {
                return;
            }

            if (!result.IsFirstHandler)
            {
                return;
            }

            await result.ConfirmAction(this.ConfirmationText ?? "");

            //Find clicked button depending on Text or Value (depending on markup type)
            if (this.KeyboardType != eKeyboardType.InlineKeyBoard)
            {
                return;
            }


            var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
                         ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
                         ?? ButtonsForm.ToList().FirstOrDefault(a => a.Value == result.RawData);

            var index = ButtonsForm.FindRowByButton(button);

            if (button != null)
            {
                await OnButtonClicked(new ButtonClickedEventArgs(button, index));

                result.Handled = true;
                return;
            }

            switch (result.RawData)
            {
            case "$previous$":

                if (this.CurrentPageIndex > 0)
                {
                    this.CurrentPageIndex--;
                }

                this.Updated();

                break;

            case "$next$":

                if (this.CurrentPageIndex < this.PageCount - 1)
                {
                    this.CurrentPageIndex++;
                }

                this.Updated();

                break;
            }
        }
Ejemplo n.º 2
0
        public async override Task Load(MessageResult result)
        {
            if (this.KeyboardType != eKeyboardType.ReplyKeyboard)
            {
                return;
            }

            if (!result.IsFirstHandler)
            {
                return;
            }

            if (result.MessageText == null)
            {
                return;
            }

            var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
                         ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
                         ?? ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);

            var index = ButtonsForm.FindRowByButton(button);

            if (button != null)
            {
                await OnButtonClicked(new ButtonClickedEventArgs(button, index));

                //Remove button click message
                if (this.DeletePreviousMessage)
                {
                    await Device.DeleteMessage(result.MessageId);
                }

                result.Handled = true;
                return;
            }


            if (result.MessageText == PreviousPageLabel)
            {
                if (this.CurrentPageIndex > 0)
                {
                    this.CurrentPageIndex--;
                }

                this.Updated();
            }
            else if (result.MessageText == NextPageLabel)
            {
                if (this.CurrentPageIndex < this.PageCount - 1)
                {
                    this.CurrentPageIndex++;
                }

                this.Updated();
            }
            else if (this.EnableSearch)
            {
                if (result.MessageText.StartsWith("🔍"))
                {
                    //Sent note about searching
                    if (this.SearchQuery == null)
                    {
                        await this.Device.Send(this.SearchLabel);
                    }

                    this.SearchQuery = null;
                    this.Updated();
                    return;
                }

                this.SearchQuery = result.MessageText;

                if (this.SearchQuery != null && this.SearchQuery != "")
                {
                    this.CurrentPageIndex = 0;
                    this.Updated();
                }
            }
        }
Ejemplo n.º 3
0
        public async override Task Action(MessageResult result, string value = null)
        {
            if (result.Handled)
            {
                return;
            }

            if (!result.IsFirstHandler)
            {
                return;
            }

            //Find clicked button depending on Text or Value (depending on markup type)
            if (this.KeyboardType != eKeyboardType.InlineKeyBoard)
            {
                return;
            }

            await result.ConfirmAction(this.ConfirmationText ?? "");

            var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
                         ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
                         ?? ButtonsForm.ToList().FirstOrDefault(a => a.Value == result.RawData);

            var index = ButtonsForm.FindRowByButton(button);

            if (button != null)
            {
                await OnButtonClicked(new ButtonClickedEventArgs(button, index));

                result.Handled = true;
                return;
            }

            switch (result.RawData)
            {
            case "$previous$":

                if (this.CurrentPageIndex > 0)
                {
                    this.CurrentPageIndex--;
                }

                this.Updated();

                break;

            case "$next$":

                if (this.CurrentPageIndex < this.PageCount - 1)
                {
                    this.CurrentPageIndex++;
                }

                this.Updated();

                break;

            default:

                var s = result.RawData.Split('$');


                switch (s[0])
                {
                case "check":

                    index = int.Parse(s[1]);

                    if (!this.CheckedRows.Contains(index))
                    {
                        this.CheckedRows.Add(index);

                        this.Updated();

                        await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, true));
                    }

                    break;

                case "uncheck":

                    index = int.Parse(s[1]);

                    if (this.CheckedRows.Contains(index))
                    {
                        this.CheckedRows.Remove(index);

                        this.Updated();

                        await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, false));
                    }

                    break;
                }


                break;
            }
        }
        public async override Task Load(MessageResult result)
        {
            if (this.KeyboardType != eKeyboardType.ReplyKeyboard)
            {
                return;
            }

            if (!result.IsFirstHandler)
            {
                return;
            }

            if (result.MessageText == null)
            {
                return;
            }

            var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
                         ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
                         ?? ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);

            var index = ButtonsForm.FindRowByButton(button);


            switch (this.SelectedViewIndex)
            {
            case 0:

                if (button != null)
                {
                    await OnButtonClicked(new ButtonClickedEventArgs(button, index));

                    //Remove button click message
                    if (this.DeletePreviousMessage)
                    {
                        await Device.DeleteMessage(result.MessageId);
                    }

                    result.Handled = true;

                    return;
                }

                if (result.MessageText == PreviousPageLabel)
                {
                    if (this.CurrentPageIndex > 0)
                    {
                        this.CurrentPageIndex--;
                    }

                    this.Updated();
                    result.Handled = true;
                }
                else if (result.MessageText == NextPageLabel)
                {
                    if (this.CurrentPageIndex < this.PageCount - 1)
                    {
                        this.CurrentPageIndex++;
                    }

                    this.Updated();
                    result.Handled = true;
                }
                else if (this.EnableSearch)
                {
                    if (result.MessageText.StartsWith("🔍"))
                    {
                        //Sent note about searching
                        if (this.SearchQuery == null)
                        {
                            await this.Device.Send(this.SearchLabel);
                        }

                        this.SearchQuery = null;
                        this.Updated();
                        result.Handled = true;
                        return;
                    }

                    this.SearchQuery = result.MessageText;

                    if (this.SearchQuery != null && this.SearchQuery != "")
                    {
                        this.CurrentPageIndex = 0;
                        this.Updated();
                        result.Handled = true;
                        return;
                    }
                }
                else if (this.Tags != null)
                {
                    if (result.MessageText == "📁")
                    {
                        //Remove button click message
                        if (this.DeletePreviousMessage)
                        {
                            await Device.DeleteMessage(result.MessageId);
                        }

                        this.SelectedViewIndex = 1;
                        this.Updated();
                        result.Handled = true;
                        return;
                    }
                }

                break;

            case 1:

                if (result.MessageText == this.BackLabel)
                {
                    //Remove button click message
                    if (this.DeletePreviousMessage)
                    {
                        await Device.DeleteMessage(result.MessageId);
                    }

                    this.SelectedViewIndex = 0;
                    this.Updated();
                    result.Handled = true;
                    return;
                }

                var i = result.MessageText.LastIndexOf(" ");
                if (i == -1)
                {
                    i = result.MessageText.Length;
                }

                var t = result.MessageText.Substring(0, i);

                if (this.SelectedTags.Contains(t))
                {
                    this.SelectedTags.Remove(t);
                }
                else
                {
                    this.SelectedTags.Add(t);
                }

                this.Updated();
                result.Handled = true;


                break;
            }
        }
Ejemplo n.º 5
0
        public async override Task Load(MessageResult result)
        {
            if (this.KeyboardType != eKeyboardType.ReplyKeyboard)
            {
                return;
            }

            if (!result.IsFirstHandler)
            {
                return;
            }

            if (result.MessageText == null)
            {
                return;
            }

            var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
                         ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
                         ?? ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);

            var index = ButtonsForm.FindRowByButton(button);

            if (button == null)
            {
                if (result.MessageText == PreviousPageLabel)
                {
                    if (this.CurrentPageIndex > 0)
                    {
                        this.CurrentPageIndex--;
                    }

                    this.Updated();
                }
                else if (result.MessageText == NextPageLabel)
                {
                    if (this.CurrentPageIndex < this.PageCount - 1)
                    {
                        this.CurrentPageIndex++;
                    }

                    this.Updated();
                }
                else if (result.MessageText.EndsWith(CheckedIconLabel))
                {
                    var s = result.MessageText.Split(' ', '.');
                    index = int.Parse(s[0]);

                    if (!this.CheckedRows.Contains(index))
                    {
                        return;
                    }

                    this.CheckedRows.Remove(index);

                    this.Updated();

                    await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, false));
                }
                else if (result.MessageText.EndsWith(UncheckedIconLabel))
                {
                    var s = result.MessageText.Split(' ', '.');
                    index = int.Parse(s[0]);

                    if (this.CheckedRows.Contains(index))
                    {
                        return;
                    }


                    this.CheckedRows.Add(index);

                    this.Updated();

                    await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, true));
                }
                //else if (this.EnableSearch)
                //{
                //    if (result.MessageText.StartsWith("🔍"))
                //    {
                //        //Sent note about searching
                //        if (this.SearchQuery == null)
                //        {
                //            await this.Device.Send(this.SearchLabel);
                //        }

                //        this.SearchQuery = null;
                //        this.Updated();
                //        return;
                //    }

                //    this.SearchQuery = result.MessageText;

                //    if (this.SearchQuery != null && this.SearchQuery != "")
                //    {
                //        this.CurrentPageIndex = 0;
                //        this.Updated();
                //    }

                //}



                return;
            }


            await OnButtonClicked(new ButtonClickedEventArgs(button, index));

            //Remove button click message
            if (this.DeletePreviousMessage)
            {
                await Device.DeleteMessage(result.MessageId);
            }

            result.Handled = true;
        }