Ejemplo n.º 1
0
        private ButtonForm GeneratePagingView(ButtonForm dataForm)
        {
            ButtonForm bf = new ButtonForm();

            bf = PrepareCheckableLayout(dataForm);

            //No Items
            if (this.ButtonsForm.Count == 0)
            {
                bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
            }

            if (this.IsNavigationBarVisible)
            {
                //🔍
                List <ButtonBase> lst = new List <ButtonBase>();
                lst.Add(new ButtonBase(PreviousPageLabel, "$previous$"));
                lst.Add(new ButtonBase(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"));
                lst.Add(new ButtonBase(NextPageLabel, "$next$"));

                //if (this.EnableSearch)
                //{
                //    lst.Insert(2, new ButtonBase("🔍 " + (this.SearchQuery ?? ""), "$search$"));
                //}

                bf.InsertButtonRow(0, lst);

                bf.AddButtonRow(lst);
            }

            return(bf);
        }
        private ButtonForm GeneratePagingView(ButtonForm dataForm)
        {
            ButtonForm bf = new ButtonForm();


            for (int i = 0; i < this.MaximumRow - LayoutRows; i++)
            {
                int it = (this.CurrentPageIndex * (this.MaximumRow - LayoutRows)) + i;

                if (it > dataForm.Rows - 1)
                {
                    break;
                }

                bf.AddButtonRow(dataForm[it]);
            }

            //No Items
            if (this.ButtonsForm.Count == 0)
            {
                bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
            }

            if (this.IsNavigationBarVisible)
            {
                //🔍
                List <ButtonBase> lst = new List <ButtonBase>();
                lst.Add(new ButtonBase(PreviousPageLabel, "$previous$"));
                lst.Add(new ButtonBase(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"));

                if (this.Tags != null && this.Tags.Count > 0)
                {
                    lst.Add(new ButtonBase("📁", "$filter$"));
                }

                lst.Add(new ButtonBase(NextPageLabel, "$next$"));

                if (this.EnableSearch)
                {
                    lst.Insert(2, new ButtonBase("🔍 " + (this.SearchQuery ?? ""), "$search$"));
                }

                bf.InsertButtonRow(0, lst);

                bf.AddButtonRow(lst);
            }

            return(bf);
        }
Ejemplo n.º 3
0
        public async override Task Render(MessageResult result)
        {
            if (!this.RenderNecessary)
            {
                return;
            }

            //Check for rows and column limits
            CheckGrid();

            this.RenderNecessary = false;

            Message m = null;

            ButtonForm form = this.ButtonsForm;

            if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
            {
                form = form.FilterDuplicate(this.SearchQuery, true);
            }
            else
            {
                form = form.Duplicate();
            }

            if (this.EnablePaging)
            {
                form = GeneratePagingView(form);
            }

            if (this.HeadLayoutButtonRow != null && HeadLayoutButtonRow.Count > 0)
            {
                form.InsertButtonRow(0, this.HeadLayoutButtonRow);
            }

            if (this.SubHeadLayoutButtonRow != null && SubHeadLayoutButtonRow.Count > 0)
            {
                if (this.IsNavigationBarVisible)
                {
                    form.InsertButtonRow(2, this.SubHeadLayoutButtonRow);
                }
                else
                {
                    form.InsertButtonRow(1, this.SubHeadLayoutButtonRow);
                }
            }

            switch (this.KeyboardType)
            {
            //Reply Keyboard could only be updated with a new keyboard.
            case eKeyboardType.ReplyKeyboard:

                if (this.MessageId != null)
                {
                    if (form.Count == 0)
                    {
                        await this.Device.HideReplyKeyboard();

                        this.MessageId = null;
                        return;
                    }

                    if (this.DeletePreviousMessage)
                    {
                        await this.Device.DeleteMessage(this.MessageId.Value);
                    }
                }

                if (form.Count == 0)
                {
                    return;
                }


                var rkm = (ReplyKeyboardMarkup)form;
                rkm.ResizeKeyboard  = this.ResizeKeyboard;
                rkm.OneTimeKeyboard = this.OneTimeKeyboard;
                m = await this.Device.Send(this.Title, rkm, disableNotification : true, parseMode : MessageParseMode, MarkdownV2AutoEscape : false);

                break;

            case eKeyboardType.InlineKeyBoard:

                //Try to edit message if message id is available
                //When the returned message is null then the message has been already deleted, resend it
                if (this.MessageId != null)
                {
                    m = await this.Device.Edit(this.MessageId.Value, this.Title, (InlineKeyboardMarkup)form);

                    if (m != null)
                    {
                        this.MessageId = m.MessageId;
                        return;
                    }
                }

                //When no message id is available or it has been deleted due the use of AutoCleanForm re-render automatically
                m = await this.Device.Send(this.Title, (InlineKeyboardMarkup)form, disableNotification : true, parseMode : MessageParseMode, MarkdownV2AutoEscape : false);

                break;
            }

            if (m != null)
            {
                this.MessageId = m.MessageId;
            }
        }
        private async Task RenderDataView()
        {
            Message m = null;

            ButtonForm form = this.ButtonsForm;

            if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
            {
                form = form.FilterDuplicate(this.SearchQuery, true);
            }
            else
            {
                form = form.Duplicate();
            }

            if (this.Tags != null && this.SelectedTags != null)
            {
                form = form.TagDuplicate(this.SelectedTags);
            }

            if (this.EnablePaging)
            {
                form = GeneratePagingView(form);
            }

            if (this.HeadLayoutButtonRow != null && HeadLayoutButtonRow.Count > 0)
            {
                form.InsertButtonRow(0, this.HeadLayoutButtonRow);
            }

            if (this.SubHeadLayoutButtonRow != null && SubHeadLayoutButtonRow.Count > 0)
            {
                if (this.IsNavigationBarVisible)
                {
                    form.InsertButtonRow(2, this.SubHeadLayoutButtonRow);
                }
                else
                {
                    form.InsertButtonRow(1, this.SubHeadLayoutButtonRow);
                }
            }

            switch (this.KeyboardType)
            {
            //Reply Keyboard could only be updated with a new keyboard.
            case eKeyboardType.ReplyKeyboard:

                if (this.MessageId != null)
                {
                    if (form.Count == 0)
                    {
                        await this.Device.HideReplyKeyboard();

                        this.MessageId = null;
                        return;
                    }

                    if (this.DeletePreviousMessage)
                    {
                        await this.Device.DeleteMessage(this.MessageId.Value);
                    }
                }

                if (form.Count == 0)
                {
                    return;
                }


                var rkm = (ReplyKeyboardMarkup)form;
                rkm.ResizeKeyboard  = this.ResizeKeyboard;
                rkm.OneTimeKeyboard = this.OneTimeKeyboard;
                m = await this.Device.Send(this.Title, rkm, disableNotification : true, parseMode : MessageParseMode, MarkdownV2AutoEscape : false);

                break;

            case eKeyboardType.InlineKeyBoard:

                if (this.MessageId != null)
                {
                    m = await this.Device.Edit(this.MessageId.Value, this.Title, (InlineKeyboardMarkup)form);
                }
                else
                {
                    m = await this.Device.Send(this.Title, (InlineKeyboardMarkup)form, disableNotification : true, parseMode : MessageParseMode, MarkdownV2AutoEscape : false);
                }

                break;
            }

            if (m != null)
            {
                this.MessageId = m.MessageId;
            }
        }