Begin CaptorsPage

This commit is contained in:
2019-04-17 13:44:24 +02:00
parent bc4615761c
commit 198a6ddebc
14 changed files with 148 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
using PlantBox.Shared.Communication.Commands; using PlantBox.Client.Models;
using PlantBox.Shared.Communication.Commands;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@@ -9,24 +10,53 @@ namespace PlantBox.Client.Converters
{ {
class CaptorValueToDoubleConverter : IValueConverter class CaptorValueToDoubleConverter : IValueConverter
{ {
const double HUMIDITY_UPPER_BOUND = 100.0;
const double HUMIDITY_LOWER_BOUND = 0.0;
const double LUMINOSITY_UPPER_BOUND = 1200.0;
const double LUMINOSITY_LOWER_BOUND = 0.0;
const double TEMPERATURE_UPPER_BOUND = 50.0;
const double TEMPERATURE_LOWER_BOUND = -20.0;
const double TANK_UPPER_BOUND = 100.0;
const double TANK_LOWER_BOUND = 0.0;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
if (value is CaptorValue captor) if (value is double d && parameter is CaptorType type)
{ {
return (captor.Value - captor.Min) / (captor.Max - captor.Min); double upperBound;
double lowerBound;
switch (type)
{
case CaptorType.Humidity:
upperBound = HUMIDITY_UPPER_BOUND;
lowerBound = HUMIDITY_LOWER_BOUND;
break;
case CaptorType.Luminosity:
upperBound = LUMINOSITY_UPPER_BOUND;
lowerBound = LUMINOSITY_LOWER_BOUND;
break;
case CaptorType.Temperature:
upperBound = TEMPERATURE_UPPER_BOUND;
lowerBound = TEMPERATURE_LOWER_BOUND;
break;
case CaptorType.Tank:
upperBound = TANK_UPPER_BOUND;
lowerBound = TANK_LOWER_BOUND;
break;
default:
throw new InvalidOperationException("How did you just got here?");
} }
throw new ArgumentException($"Invalid source: excepted 'CaptorValue' and got '${value.GetType().Name}'", nameof(value)); return (d - lowerBound) / (upperBound - lowerBound);
}
throw new ArgumentException("Invalid source or argument");
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
if (value is double step && parameter is CaptorValue captor) throw new NotImplementedException();
{
return new CaptorValue(captor.Min, captor.Max, (captor.Max - captor.Min) * step - captor.Max);
}
throw new ArgumentException();
} }
} }
} }

View File

@@ -29,9 +29,8 @@ namespace PlantBox.Client.Forms
// Prepare view model // Prepare view model
var viewModel = new PlantViewModel(plant); var viewModel = new PlantViewModel(plant);
await Navigation.PushAsync(new PlantPage() await Navigation.PushAsync(new PlantPage(viewModel)
{ {
BindingContext = viewModel,
Title = plant.Name Title = plant.Name
}); });
} }

View File

@@ -1,12 +1,63 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:converters="clr-namespace:PlantBox.Client.Converters"
xmlns:statusbar="clr-namespace:PlantBox.Client.Forms.Controls.StatusBar"
xmlns:models="clr-namespace:PlantBox.Client.Models"
xmlns:viewmodels="clr-namespace:PlantBox.Client.ViewModels"
xmlns:extensions="clr-namespace:PlantBox.Client.Extensions"
x:Class="PlantBox.Client.Forms.Plant.CaptorsPage"> x:Class="PlantBox.Client.Forms.Plant.CaptorsPage">
<ContentPage.Resources>
<FlexBasis x:Key="BarWidth">17%</FlexBasis>
<converters:CaptorValueToDoubleConverter x:Key="CaptorConverter" />
</ContentPage.Resources>
<ContentPage.Content> <ContentPage.Content>
<StackLayout> <FlexLayout Direction="Row"
<Label Text="Welcome to Xamarin.Forms!" JustifyContent="SpaceAround"
VerticalOptions="CenterAndExpand" VerticalOptions="FillAndExpand"
HorizontalOptions="CenterAndExpand" /> HorizontalOptions="FillAndExpand"
</StackLayout> Margin="20">
<statusbar:StatusBar Progress="{Binding HumidityCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Humidity}}"
Label="{Binding HumidityCaptor.Value, StringFormat='\{0:F1} %'}"
ForegroundColor="DeepSkyBlue"
HintColor="SkyBlue"
BoundColor="DarkSlateGray"
BoundHeight="2"
LowerBound="{Binding HumidityCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Humidity}}"
UpperBound="{Binding HumidityCaptor.Max, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Humidity}}"
Image="{extensions:ImageResource Humidity_Icon.png}"
FlexLayout.Basis="{StaticResource BarWidth}" />
<statusbar:StatusBar Progress="{Binding LuminosityCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}"
Label="{Binding LuminosityCaptor.Value, StringFormat='\{0:F0} lux'}"
ForegroundColor="Bisque"
HintColor="AntiqueWhite"
BoundColor="DarkSlateGray"
BoundHeight="2"
LowerBound="{Binding LuminosityCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}"
UpperBound="-1"
Image="{extensions:ImageResource Luminosity_Icon.png}"
FlexLayout.Basis="{StaticResource BarWidth}" />
<statusbar:StatusBar Progress="{Binding TemperatureCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
Label="{Binding TemperatureCaptor.Value, StringFormat='\{0:F1} °C'}"
ForegroundColor="Crimson"
HintColor="IndianRed"
BoundColor="DarkSlateGray"
BoundHeight="2"
LowerBound="{Binding TemperatureCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
UpperBound="{Binding TemperatureCaptor.Max, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
Image="{extensions:ImageResource Temperature_Icon.png}"
FlexLayout.Basis="{StaticResource BarWidth}" />
<statusbar:StatusBar Progress="{Binding TankValue, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Tank}}"
Label="{Binding TankValue, StringFormat='\{0:F0} %'}"
ForegroundColor="DeepSkyBlue"
HintColor="SkyBlue"
BoundColor="DarkSlateGray"
BoundHeight="2"
LowerBound="-1"
UpperBound="-1"
Image="{extensions:ImageResource Tank_Icon.png}"
FlexLayout.Basis="{StaticResource BarWidth}" />
</FlexLayout>
</ContentPage.Content> </ContentPage.Content>
</ContentPage> </ContentPage>

View File

@@ -1,5 +1,6 @@
using PlantBox.Client.Models; using PlantBox.Client.Models;
using PlantBox.Client.Resources; using PlantBox.Client.Resources;
using PlantBox.Client.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -14,18 +15,18 @@ namespace PlantBox.Client.Forms.Plant
[XamlCompilation(XamlCompilationOptions.Compile)] [XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PlantPage : TabbedPage public partial class PlantPage : TabbedPage
{ {
public PlantPage() public PlantPage(PlantViewModel viewModel)
{ {
InitializeComponent(); InitializeComponent();
Children.Add(new CaptorsPage() Children.Add(new CaptorsPage()
{ {
BindingContext = BindingContext, BindingContext = viewModel,
Title = Locale.Informations Title = Locale.Informations
}); });
Children.Add(new HistoricPage() Children.Add(new HistoricPage()
{ {
BindingContext = BindingContext, BindingContext = viewModel,
Title = Locale.Historic Title = Locale.Historic
}); });
} }

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace PlantBox.Client.Models
{
enum CaptorType
{
Humidity,
Luminosity,
Tank,
Temperature
}
}

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace PlantBox.Client.Models namespace PlantBox.Client.Models
{ {
class Historic public class Historic
{ {
public HistoricEntry MinutelyHistoric { get; } public HistoricEntry MinutelyHistoric { get; }
public HistoricEntry HourlyHistoric { get; } public HistoricEntry HourlyHistoric { get; }

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace PlantBox.Client.Models namespace PlantBox.Client.Models
{ {
class HistoricEntry public class HistoricEntry
{ {
public DateTime LastTime { get; } public DateTime LastTime { get; }
public TimeSpan TimeInterval { get; } public TimeSpan TimeInterval { get; }

View File

@@ -15,18 +15,26 @@
<None Remove="Resources\Images\Banner.png" /> <None Remove="Resources\Images\Banner.png" />
<None Remove="Resources\Images\Help.png" /> <None Remove="Resources\Images\Help.png" />
<None Remove="Resources\Images\Home.png" /> <None Remove="Resources\Images\Home.png" />
<None Remove="Resources\Images\Humidity_Icon.png" />
<None Remove="Resources\Images\Info.png" /> <None Remove="Resources\Images\Info.png" />
<None Remove="Resources\Images\Logo_Gray.png" /> <None Remove="Resources\Images\Logo_Gray.png" />
<None Remove="Resources\Images\Luminosity_Icon.png" />
<None Remove="Resources\Images\Settings.png" /> <None Remove="Resources\Images\Settings.png" />
<None Remove="Resources\Images\Tank_Icon.png" />
<None Remove="Resources\Images\Temperature_Icon.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\Images\Banner.png" /> <EmbeddedResource Include="Resources\Images\Banner.png" />
<EmbeddedResource Include="Resources\Images\Help.png" /> <EmbeddedResource Include="Resources\Images\Help.png" />
<EmbeddedResource Include="Resources\Images\Home.png" /> <EmbeddedResource Include="Resources\Images\Home.png" />
<EmbeddedResource Include="Resources\Images\Humidity_Icon.png" />
<EmbeddedResource Include="Resources\Images\Info.png" /> <EmbeddedResource Include="Resources\Images\Info.png" />
<EmbeddedResource Include="Resources\Images\Logo_Gray.png" /> <EmbeddedResource Include="Resources\Images\Logo_Gray.png" />
<EmbeddedResource Include="Resources\Images\Luminosity_Icon.png" />
<EmbeddedResource Include="Resources\Images\Settings.png" /> <EmbeddedResource Include="Resources\Images\Settings.png" />
<EmbeddedResource Include="Resources\Images\Tank_Icon.png" />
<EmbeddedResource Include="Resources\Images\Temperature_Icon.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -8,7 +8,7 @@ using System.Text;
namespace PlantBox.Client.ViewModels namespace PlantBox.Client.ViewModels
{ {
class PlantViewModel : INotifyPropertyChanged public class PlantViewModel : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
@@ -89,10 +89,30 @@ namespace PlantBox.Client.ViewModels
} }
} }
private double _tankValue;
public double TankValue
{
get => _tankValue;
set
{
if (value != _tankValue)
{
_tankValue = value;
OnPropertyChanged();
}
}
}
private void LoadValues() private void LoadValues()
{ {
// TODO // TODO
//throw new NotImplementedException(); //throw new NotImplementedException();
// Temp
HumidityCaptor = new CaptorValue(20, 80, 21);
LuminosityCaptor = new CaptorValue(50, 1000, 375.6);
TemperatureCaptor = new CaptorValue(20, 35, 27);
TankValue = 78.45;
} }
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) protected void OnPropertyChanged([CallerMemberName] string propertyName = null)