Updates and improvements
- refactoring of ButtonGrid control for more readability - refactoring of TaggedButtonGrid control for more readability - adding Index parameter to ButtenClickedEventArgs - adding FindRowByButton method to ButtonForm to get the row index -
This commit is contained in:
@@ -167,67 +167,68 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
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);
|
||||
|
||||
if (button == null)
|
||||
var index = ButtonsForm.FindRowByButton(button);
|
||||
|
||||
if (button != null)
|
||||
{
|
||||
if (result.MessageText == null)
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
||||
|
||||
//Remove button click message
|
||||
if (this.DeletePreviousMessage)
|
||||
await Device.DeleteMessage(result.MessageId);
|
||||
|
||||
result.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Remove button click message
|
||||
if (this.DeletePreviousMessage)
|
||||
await Device.DeleteMessage(result.MessageId);
|
||||
|
||||
result.Handled = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -250,9 +251,11 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
?? 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));
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
||||
|
||||
result.Handled = true;
|
||||
return;
|
||||
|
||||
@@ -178,12 +178,18 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
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);
|
||||
|
||||
if (result.MessageText == null)
|
||||
return;
|
||||
var index = HeadLayoutButtonRow?.IndexOf(button)
|
||||
?? SubHeadLayoutButtonRow?.IndexOf(button)
|
||||
?? ButtonsForm.ToList().IndexOf(button);
|
||||
|
||||
|
||||
|
||||
switch (this.SelectedViewIndex)
|
||||
{
|
||||
@@ -191,7 +197,7 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
|
||||
if (button != null)
|
||||
{
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
||||
|
||||
//Remove button click message
|
||||
if (this.DeletePreviousMessage)
|
||||
@@ -304,6 +310,10 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
|
||||
public async override Task Action(MessageResult result, string value = null)
|
||||
{
|
||||
//Find clicked button depending on Text or Value (depending on markup type)
|
||||
if (this.KeyboardType != eKeyboardType.InlineKeyBoard)
|
||||
return;
|
||||
|
||||
if (result.Handled)
|
||||
return;
|
||||
|
||||
@@ -312,18 +322,17 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
|
||||
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 = HeadLayoutButtonRow?.IndexOf(button)
|
||||
?? SubHeadLayoutButtonRow?.IndexOf(button)
|
||||
?? ButtonsForm.ToList().IndexOf(button);
|
||||
|
||||
if (button != null)
|
||||
{
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
||||
|
||||
result.Handled = true;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user