Updating Testproject

- adding example for NavigationController
- readability improvement in Menu
This commit is contained in:
FlorianDahn 2021-07-25 16:34:29 +02:00
parent 6f005114bc
commit 9eae63dae6
4 changed files with 240 additions and 23 deletions

View File

@ -41,7 +41,9 @@ namespace TelegramBotBaseTest.Tests
if (call == null)
return;
switch(call.Value)
message.Handled = true;
switch (call.Value)
{
case "text":
@ -93,8 +95,6 @@ namespace TelegramBotBaseTest.Tests
case "data":
message.Handled = true;
var data = new DataForm();
await this.NavigateTo(data);
@ -103,8 +103,6 @@ namespace TelegramBotBaseTest.Tests
case "calendar":
message.Handled = true;
var calendar = new Controls.CalendarPickerForm();
await this.NavigateTo(calendar);
@ -113,8 +111,6 @@ namespace TelegramBotBaseTest.Tests
case "month":
message.Handled = true;
var month = new Controls.MonthPickerForm();
await this.NavigateTo(month);
@ -123,8 +119,6 @@ namespace TelegramBotBaseTest.Tests
case "treeview":
message.Handled = true;
var tree = new Controls.TreeViewForms();
await this.NavigateTo(tree);
@ -133,8 +127,6 @@ namespace TelegramBotBaseTest.Tests
case "togglebuttons":
message.Handled = true;
var tb = new Controls.ToggleButtons();
await this.NavigateTo(tb);
@ -143,8 +135,6 @@ namespace TelegramBotBaseTest.Tests
case "multitogglebuttons":
message.Handled = true;
var mtb = new Controls.MultiToggleButtons();
await this.NavigateTo(mtb);
@ -153,8 +143,6 @@ namespace TelegramBotBaseTest.Tests
case "buttongrid":
message.Handled = true;
var bg = new Controls.ButtonGridForm();
await this.NavigateTo(bg);
@ -163,8 +151,6 @@ namespace TelegramBotBaseTest.Tests
case "buttongridfilter":
message.Handled = true;
var bg2 = new Controls.ButtonGridPagingForm();
await this.NavigateTo(bg2);
@ -173,8 +159,6 @@ namespace TelegramBotBaseTest.Tests
case "buttongridtags":
message.Handled = true;
var bg3 = new Controls.ButtonGridTagForm();
await this.NavigateTo(bg3);
@ -183,8 +167,6 @@ namespace TelegramBotBaseTest.Tests
case "multiview":
message.Handled = true;
var mvf = new MultiViewForm();
await NavigateTo(mvf);
@ -194,13 +176,26 @@ namespace TelegramBotBaseTest.Tests
case "checkedbuttonlist":
message.Handled = true;
var cbl = new CheckedButtonListForm();
await NavigateTo(cbl);
break;
case "navigationcontroller":
var nc = new Navigation.Start();
await NavigateTo(nc);
break;
default:
message.Handled = false;
break;
}
@ -240,6 +235,8 @@ namespace TelegramBotBaseTest.Tests
btn.AddButtonRow(new ButtonBase("#16 CheckedButtonList", new CallbackData("a", "checkedbuttonlist").Serialize()));
btn.AddButtonRow(new ButtonBase("#17 NavigationController (Push/Pop)", new CallbackData("a", "navigationcontroller").Serialize()));
await this.Device.Send("Choose your test:", btn);
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using TelegramBotBase.Form;
using TelegramBotBase.Form.Navigation;
namespace TelegramBotBaseTest.Tests.Navigation
{
class CustomController : NavigationController
{
public CustomController(FormBase form) : base(form)
{
}
public override Task PushAsync(FormBase form, params object[] args)
{
Console.WriteLine($"Pushes form (Count on stack {this.Index + 1})");
//Device.Send($"Pushes form (Count on stack {this.Index + 1})");
return base.PushAsync(form, args);
}
public override Task PopAsync()
{
Console.WriteLine($"Pops one form (Count on stack {this.Index + 1})");
//Device.Send($"Pops one form (Count on stack {this.Index + 1})");
return base.PopAsync();
}
public override Task PopToRootAsync()
{
Console.WriteLine($"Moved back to root (Count on stack {this.Index + 1})");
//Device.Send($"Moved back to root (Count on stack {this.Index + 1})");
return base.PopToRootAsync();
}
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
namespace TelegramBotBaseTest.Tests.Navigation
{
public class Form1 : FormBase
{
Message msg = null;
public Form1()
{
this.Closed += Form1_Closed;
}
private async Task Form1_Closed(object sender, EventArgs e)
{
if (msg == null)
return;
await Device.DeleteMessage(msg);
}
public override async Task Action(MessageResult message)
{
if (message.Handled)
return;
await message.ConfirmAction();
switch (message.RawData)
{
case "next":
message.Handled = true;
var f1 = new Form1();
await NavigationController.PushAsync(f1);
break;
case "previous":
message.Handled = true;
//Pop's the current form and move the previous one. The root form will be the Start class.
await NavigationController.PopAsync();
break;
case "root":
message.Handled = true;
await NavigationController.PopToRootAsync();
break;
}
}
public override async Task Render(MessageResult message)
{
if (msg != null)
return;
var bf = new ButtonForm();
bf.AddButtonRow("Next page", "next");
bf.AddButtonRow("Previous page", "previous");
bf.AddButtonRow("Back to root", "root");
msg = await Device.Send($"Choose your options (Count on stack {NavigationController.Index + 1})", bf);
}
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
using TelegramBotBase.Form.Navigation;
namespace TelegramBotBaseTest.Tests.Navigation
{
public class Start : FormBase
{
Message msg = null;
public Start()
{
this.Closed += Start_Closed;
}
private async Task Start_Closed(object sender, EventArgs e)
{
if (msg == null)
return;
await Device.DeleteMessage(msg);
}
public override async Task Load(MessageResult message)
{
}
public override async Task Action(MessageResult message)
{
if (message.Handled)
return;
await message.ConfirmAction();
switch (message.RawData)
{
case "yes":
message.Handled = true;
//Create navigation controller and navigate to it, keep the current form as root form so we can get back to here later
var nc = new CustomController(this);
var f1 = new Form1();
await NavigateTo(nc);
await nc.PushAsync(f1);
break;
case "no":
message.Handled = true;
var mn = new Menu();
await NavigateTo(mn);
break;
}
}
public override async Task Render(MessageResult message)
{
var bf = new ButtonForm();
bf.AddButtonRow("Yes", "yes");
bf.AddButtonRow("No", "no");
msg = await Device.Send("Open controller?", bf);
}
}
}