136 lines
4.9 KiB
C#
136 lines
4.9 KiB
C#
using Sarand.Net.Mobile.Maui.App;
|
|
using Sarand.Net.Mobile.Maui.Controls;
|
|
using Sarand.Net.Mobile.Maui.Layouts;
|
|
using Sarand.Net.Mobile.Maui.Utils;
|
|
using Sarand.Net.Mobile.Maui.Views;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sarand.Net.Mobile.Maui.Panels
|
|
{
|
|
//=======================================================================
|
|
public class SamPanel_Page_Footer : SamPanel
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
// Layout.
|
|
private VerticalStackLayout panelFooter = new VerticalStackLayout() { BackgroundColor = Sam.Visuals.Page.Footer.BackgroundColor };
|
|
private SamBoxView panelBorderTop = new SamBoxView() { BackgroundColor = Sam.Visuals.Page.Footer.BorderColor, HeightRequest = Sam.Visuals.Page.Footer.BorderStrokeWidthTop };
|
|
private SamBoxView panelBorderBottom = new SamBoxView() { BackgroundColor = Sam.Visuals.Page.Footer.BorderColor, HeightRequest = Sam.Visuals.Page.Footer.BorderStrokeWidthBottom };
|
|
// Grid.
|
|
private SamGrid gridFooter = new SamGrid() { Padding = Sam.Visuals.Page.Footer.Padding };
|
|
private ColumnDefinition colLeft = new ColumnDefinition(GridLength.Star);
|
|
private ColumnDefinition colMiddle = new ColumnDefinition(GridLength.Auto);
|
|
private ColumnDefinition colRight = new ColumnDefinition(GridLength.Star);
|
|
// Panels.
|
|
private VerticalStackLayout panelLeft = new VerticalStackLayout() { HorizontalOptions = LayoutOptions.Start };
|
|
private VerticalStackLayout panelMiddle = new VerticalStackLayout() { HorizontalOptions = LayoutOptions.Center };
|
|
private VerticalStackLayout panelRight = new VerticalStackLayout() { HorizontalOptions = LayoutOptions.End };
|
|
// Date-time display.
|
|
private String dateTimeFormat = "ddd d-MMM-yyyy HH:mm:ss";
|
|
private IDispatcherTimer? timerDateTime;
|
|
private Sam.DisplayPosition dateTimeDisplay = Sam.Visuals.Page.Footer.DateTimeDisplay;
|
|
private SamLabel labelDateTime = new SamLabel() { FontSize = 12.0, HorizontalTextAlignment = TextAlignment.Center };
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SamPanel_Page_Footer()
|
|
{
|
|
// Footer panel.
|
|
Content = panelFooter;
|
|
|
|
// Footer border top.
|
|
panelFooter.Children.Add(panelBorderTop);
|
|
|
|
// Footer grid.
|
|
gridFooter.ColumnDefinitions.Add(colLeft);
|
|
gridFooter.ColumnDefinitions.Add(colMiddle);
|
|
gridFooter.ColumnDefinitions.Add(colRight);
|
|
gridFooter.Add(panelLeft, 0, 0);
|
|
gridFooter.Add(panelMiddle, 1, 0);
|
|
gridFooter.Add(panelRight, 2, 0);
|
|
panelFooter.Children.Add(gridFooter);
|
|
|
|
// Footer border bottom.
|
|
panelFooter.Children.Add(panelBorderBottom);
|
|
|
|
RefreshComponents();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public Sam.DisplayPosition DateTimeDisplay
|
|
{
|
|
get { return dateTimeDisplay; }
|
|
set { dateTimeDisplay = value; RefreshComponents(); }
|
|
}
|
|
public String DateTimeFormat
|
|
{
|
|
get { return dateTimeFormat; }
|
|
set { dateTimeFormat = value; RefreshComponents(); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Events.
|
|
protected override void OnParentChanged()
|
|
{
|
|
base.OnParentChanged();
|
|
if (Parent == null)
|
|
ClearDateTimeTimer();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// DateTime display.
|
|
private void ClearDateTimeTimer()
|
|
{
|
|
if (timerDateTime != null && timerDateTime.IsRunning)
|
|
timerDateTime.Stop();
|
|
}
|
|
|
|
private void TimerDateTime_Tick(object? sender, EventArgs e)
|
|
{
|
|
String dateTimeValue = DateTime.Now.ToString(dateTimeFormat);
|
|
if (!labelDateTime.Text.Equals(dateTimeValue))
|
|
labelDateTime.Text = dateTimeValue;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
private void RefreshComponents()
|
|
{
|
|
bool contentDisplayed = false;
|
|
|
|
// Date time.
|
|
ClearDateTimeTimer();
|
|
panelLeft.Children.Remove(labelDateTime);
|
|
panelMiddle.Children.Remove(labelDateTime);
|
|
panelRight.Children.Remove(labelDateTime);
|
|
if (dateTimeDisplay == Sam.DisplayPosition.Left)
|
|
panelLeft.Children.Add(labelDateTime);
|
|
else if (dateTimeDisplay == Sam.DisplayPosition.Middle)
|
|
panelMiddle.Children.Add(labelDateTime);
|
|
else if (dateTimeDisplay == Sam.DisplayPosition.Right)
|
|
panelRight.Children.Add(labelDateTime);
|
|
if (dateTimeDisplay != Sam.DisplayPosition.None)
|
|
{
|
|
contentDisplayed = true;
|
|
timerDateTime = SamTimerUtil.DoTimer(this, TimeSpan.FromMilliseconds(250), true, TimerDateTime_Tick);
|
|
timerDateTime.Start();
|
|
}
|
|
|
|
// Hide panel if nothing displayed.
|
|
if (contentDisplayed)
|
|
IsVisible = true;
|
|
else IsVisible = false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|