- added IsDisposed to form

- removed FormSwitched from FormBase and added to DeviceSession (more logical message loop)
- added PreviousForm to DeviceSession, contains last opened form (at initial form is null)
-BotBase message loop update
- now navigation is possible from every form, not just the latest ones as before
This commit is contained in:
FlorianDahn 2019-06-22 15:15:29 +02:00
parent 022eee4b57
commit fe1aafc9a5
3 changed files with 28 additions and 10 deletions

View File

@ -20,9 +20,9 @@ namespace TelegramBotBase.Form
public bool CustomEventManagement { get; set; } = false; public bool CustomEventManagement { get; set; } = false;
/// <summary> /// <summary>
/// contains if the form has been switched (navigated) /// has this formular already been disposed ?
/// </summary> /// </summary>
public bool FormSwitched { get; set; } = false; public bool IsDisposed { get; set; } = false;
public List<ControlBase> Controls { get; set; } public List<ControlBase> Controls { get; set; }
@ -117,12 +117,14 @@ namespace TelegramBotBase.Form
if (ds == null) if (ds == null)
return; return;
this.FormSwitched = true; ds.FormSwitched = true;
ds.ActiveForm = newForm; ds.ActiveForm = newForm;
newForm.Client = this.Client; newForm.Client = this.Client;
newForm.Device = ds; newForm.Device = ds;
ds.PreviousForm = this;
await newForm.Init(args); await newForm.Init(args);
await this.Closed(); await this.Closed();
@ -137,7 +139,7 @@ namespace TelegramBotBase.Form
{ {
this.Client = null; this.Client = null;
this.Device = null; this.Device = null;
this.FormSwitched = false; this.IsDisposed = true;
} }
} }
} }

View File

@ -258,6 +258,9 @@ namespace TelegramBotBase
do do
{ {
i++; i++;
//Reset navigation
ds.FormSwitched = false;
activeForm = ds.ActiveForm; activeForm = ds.ActiveForm;
@ -279,10 +282,10 @@ namespace TelegramBotBase
} }
//Render Event //Render Event
if (!activeForm.FormSwitched) if (!ds.FormSwitched)
await activeForm.Render(e); await activeForm.Render(e);
} while (activeForm.FormSwitched && i < NavigationMaximum); } while (ds.FormSwitched && i < NavigationMaximum);
} }
@ -329,6 +332,9 @@ namespace TelegramBotBase
{ {
i++; i++;
//Reset navigation
ds.FormSwitched = false;
activeForm = ds.ActiveForm; activeForm = ds.ActiveForm;
//If the form manages the events by itselfs, skip here //If the form manages the events by itselfs, skip here
@ -342,7 +348,7 @@ namespace TelegramBotBase
await activeForm.Load(e); await activeForm.Load(e);
//Action Event //Action Event
if (!activeForm.FormSwitched) if (!ds.FormSwitched)
{ {
await activeForm.Action(e); await activeForm.Action(e);
@ -353,7 +359,7 @@ namespace TelegramBotBase
if (uhc.Handled) if (uhc.Handled)
{ {
if (activeForm.FormSwitched) if (ds.FormSwitched)
{ {
continue; continue;
} }
@ -367,10 +373,10 @@ namespace TelegramBotBase
} }
//Render Event //Render Event
if (!activeForm.FormSwitched) if (!ds.FormSwitched)
await activeForm.Render(e); await activeForm.Render(e);
} while (activeForm.FormSwitched && i < NavigationMaximum); } while (ds.FormSwitched && i < NavigationMaximum);
} }

View File

@ -37,6 +37,16 @@ namespace TelegramBotBase.Sessions
/// </summary> /// </summary>
public FormBase ActiveForm { get; set; } public FormBase ActiveForm { get; set; }
/// <summary>
/// Returns the previous shown form
/// </summary>
public FormBase PreviousForm { get; set; }
/// <summary>
/// contains if the form has been switched (navigated)
/// </summary>
public bool FormSwitched { get; set; } = false;
/// <summary> /// <summary>
/// Returns the ID of the last received message. /// Returns the ID of the last received message.
/// </summary> /// </summary>