Add PlantPage logic
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
using PlantBox.Shared.Communication.Commands;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace PlantBox.Client.Converters
|
||||||
|
{
|
||||||
|
class CaptorValueToDoubleConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is CaptorValue captor)
|
||||||
|
{
|
||||||
|
return (captor.Value - captor.Min) / (captor.Max - captor.Min);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentException($"Invalid source: excepted 'CaptorValue' and got '${value.GetType().Name}'", nameof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is double step && parameter is CaptorValue captor)
|
||||||
|
{
|
||||||
|
return new CaptorValue(captor.Min, captor.Max, (captor.Max - captor.Min) * step - captor.Max);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using PlantBox.Client.Forms.Plant;
|
using PlantBox.Client.Forms.Plant;
|
||||||
using PlantBox.Client.Models;
|
using PlantBox.Client.Models;
|
||||||
|
using PlantBox.Client.ViewModels;
|
||||||
using PlantBox.Shared.Communication.Commands;
|
using PlantBox.Shared.Communication.Commands;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -25,8 +26,12 @@ namespace PlantBox.Client.Forms
|
|||||||
{
|
{
|
||||||
var plant = (PlantInfo)e.Item;
|
var plant = (PlantInfo)e.Item;
|
||||||
|
|
||||||
await Navigation.PushAsync(new PlantPage(plant)
|
// Prepare view model
|
||||||
|
var viewModel = new PlantViewModel(plant);
|
||||||
|
|
||||||
|
await Navigation.PushAsync(new PlantPage()
|
||||||
{
|
{
|
||||||
|
BindingContext = viewModel,
|
||||||
Title = plant.Name
|
Title = plant.Name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,18 @@ namespace PlantBox.Client.Forms.Plant
|
|||||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
public partial class PlantPage : TabbedPage
|
public partial class PlantPage : TabbedPage
|
||||||
{
|
{
|
||||||
public PlantPage(PlantInfo plant)
|
public PlantPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Children.Add(new CaptorsPage()
|
Children.Add(new CaptorsPage()
|
||||||
{
|
{
|
||||||
|
BindingContext = BindingContext,
|
||||||
Title = Locale.Informations
|
Title = Locale.Informations
|
||||||
});
|
});
|
||||||
Children.Add(new HistoricPage()
|
Children.Add(new HistoricPage()
|
||||||
{
|
{
|
||||||
|
BindingContext = BindingContext,
|
||||||
Title = Locale.Historic
|
Title = Locale.Historic
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
28
PlantBox.Client/PlantBox.Client/Models/Historic.cs
Normal file
28
PlantBox.Client/PlantBox.Client/Models/Historic.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Client.Models
|
||||||
|
{
|
||||||
|
class Historic
|
||||||
|
{
|
||||||
|
public HistoricEntry MinutelyHistoric { get; }
|
||||||
|
public HistoricEntry HourlyHistoric { get; }
|
||||||
|
public HistoricEntry DailyHistoric { get; }
|
||||||
|
public HistoricEntry WeeklyHistoric { get; }
|
||||||
|
public HistoricEntry MonthlyHistoric { get; }
|
||||||
|
|
||||||
|
public Historic
|
||||||
|
(
|
||||||
|
HistoricEntry minutelyHistoric, HistoricEntry hourlyHistoric, HistoricEntry dailyHistoric,
|
||||||
|
HistoricEntry weeklyHistoric, HistoricEntry monthlyHistoric
|
||||||
|
)
|
||||||
|
{
|
||||||
|
MinutelyHistoric = minutelyHistoric;
|
||||||
|
HourlyHistoric = hourlyHistoric;
|
||||||
|
DailyHistoric = dailyHistoric;
|
||||||
|
WeeklyHistoric = weeklyHistoric;
|
||||||
|
MonthlyHistoric = monthlyHistoric;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
PlantBox.Client/PlantBox.Client/Models/HistoricEntry.cs
Normal file
28
PlantBox.Client/PlantBox.Client/Models/HistoricEntry.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Client.Models
|
||||||
|
{
|
||||||
|
class HistoricEntry
|
||||||
|
{
|
||||||
|
public DateTime LastTime { get; }
|
||||||
|
public TimeSpan TimeInterval { get; }
|
||||||
|
|
||||||
|
public double[] Humidities { get; }
|
||||||
|
public double[] Luminosities { get; }
|
||||||
|
public double[] Temperatures { get; }
|
||||||
|
|
||||||
|
public DateTime EndTime => LastTime - new TimeSpan(TimeInterval.Ticks * Count);
|
||||||
|
public int Count => Humidities.Length;
|
||||||
|
|
||||||
|
public HistoricEntry(DateTime lastTime, TimeSpan timeInterval, double[] humidities, double[] luminosities, double[] temperatures)
|
||||||
|
{
|
||||||
|
LastTime = lastTime;
|
||||||
|
TimeInterval = timeInterval;
|
||||||
|
Humidities = humidities;
|
||||||
|
Luminosities = luminosities;
|
||||||
|
Temperatures = temperatures;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
103
PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs
Normal file
103
PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
using PlantBox.Client.Models;
|
||||||
|
using PlantBox.Shared.Communication.Commands;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Client.ViewModels
|
||||||
|
{
|
||||||
|
class PlantViewModel : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
public PlantViewModel(PlantInfo plant)
|
||||||
|
{
|
||||||
|
PlantInfo = plant;
|
||||||
|
|
||||||
|
LoadValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Historic _historic;
|
||||||
|
public Historic Historic
|
||||||
|
{
|
||||||
|
get => _historic;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _historic)
|
||||||
|
{
|
||||||
|
_historic = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlantInfo _plantInfo;
|
||||||
|
public PlantInfo PlantInfo
|
||||||
|
{
|
||||||
|
get => _plantInfo;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _plantInfo)
|
||||||
|
{
|
||||||
|
_plantInfo = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CaptorValue _humidityCaptor;
|
||||||
|
public CaptorValue HumidityCaptor
|
||||||
|
{
|
||||||
|
get => _humidityCaptor;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _humidityCaptor)
|
||||||
|
{
|
||||||
|
_humidityCaptor = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CaptorValue _luminosityCaptor;
|
||||||
|
public CaptorValue LuminosityCaptor
|
||||||
|
{
|
||||||
|
get => _luminosityCaptor;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _luminosityCaptor)
|
||||||
|
{
|
||||||
|
_luminosityCaptor = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CaptorValue _temperatureCaptor;
|
||||||
|
public CaptorValue TemperatureCaptor
|
||||||
|
{
|
||||||
|
get => _temperatureCaptor;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _temperatureCaptor)
|
||||||
|
{
|
||||||
|
_temperatureCaptor = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadValues()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
//throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||||
|
{
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user