Add HomePage
This commit is contained in:
41
PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml
Normal file
41
PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:extensions="clr-namespace:PlantBox.Client.Extensions"
|
||||
x:Class="PlantBox.Client.Forms.HomeItem">
|
||||
<ContentView.Content>
|
||||
<Frame CornerRadius="5"
|
||||
Padding="5"
|
||||
BorderColor="Gray"
|
||||
BackgroundColor="{OnPlatform UWP='#F0F0F0'}">
|
||||
<StackLayout HorizontalOptions="Fill"
|
||||
VerticalOptions="Fill"
|
||||
Orientation="Horizontal">
|
||||
<Image x:Name="imageType"
|
||||
Source="{extensions:ImageResource Logo_Gray.png}"
|
||||
WidthRequest="50"
|
||||
Margin="2, 0, 0, 0"/>
|
||||
<BoxView VerticalOptions="Fill"
|
||||
WidthRequest="3"
|
||||
Margin="0, 2"
|
||||
CornerRadius="5"
|
||||
BackgroundColor="Gray" />
|
||||
<StackLayout Orientation="Vertical">
|
||||
<Label x:Name="labelName"
|
||||
VerticalOptions="StartAndExpand"
|
||||
TextColor="#666666"
|
||||
Style="{DynamicResource TitleStyle}" />
|
||||
<Label x:Name="labelType"
|
||||
VerticalOptions="StartAndExpand"
|
||||
TextColor="Gray"
|
||||
Style="{DynamicResource SubtitleStyle}" />
|
||||
</StackLayout>
|
||||
<BoxView x:Name="boxState"
|
||||
VerticalOptions="Fill"
|
||||
HorizontalOptions="EndAndExpand"
|
||||
WidthRequest="5"
|
||||
CornerRadius="5" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
||||
82
PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml.cs
Normal file
82
PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using PlantBox.Shared.Communication.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace PlantBox.Client.Forms
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class HomeItem : ContentView
|
||||
{
|
||||
// Name
|
||||
public static readonly BindableProperty PlantNameProperty = BindableProperty.Create(nameof(PlantName), typeof(string), typeof(HomeItem));
|
||||
public string PlantName
|
||||
{
|
||||
get => (string)GetValue(PlantNameProperty);
|
||||
set => SetValue(PlantNameProperty, value);
|
||||
}
|
||||
|
||||
// PlantType
|
||||
public static readonly BindableProperty PlantTypeProperty = BindableProperty.Create(nameof(PlantType), typeof(PlantType), typeof(HomeItem));
|
||||
public PlantType PlantType
|
||||
{
|
||||
get => (PlantType)GetValue(PlantTypeProperty);
|
||||
set => SetValue(PlantTypeProperty, value);
|
||||
}
|
||||
|
||||
// PlantState
|
||||
public static readonly BindableProperty PlantStateProperty = BindableProperty.Create(nameof(PlantState), typeof(PlantState), typeof(HomeItem));
|
||||
public PlantState PlantState
|
||||
{
|
||||
get => (PlantState)GetValue(PlantStateProperty);
|
||||
set => SetValue(PlantStateProperty, value);
|
||||
}
|
||||
|
||||
public HomeItem()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
base.OnPropertyChanged(propertyName);
|
||||
|
||||
if (propertyName == PlantNameProperty.PropertyName)
|
||||
{
|
||||
labelName.Text = PlantName;
|
||||
}
|
||||
if (propertyName == PlantTypeProperty.PropertyName)
|
||||
{
|
||||
labelType.Text = PlantType.ToString();
|
||||
|
||||
// Icon
|
||||
|
||||
}
|
||||
if (propertyName == PlantStateProperty.PropertyName)
|
||||
{
|
||||
Color color;
|
||||
|
||||
switch(PlantState)
|
||||
{
|
||||
case PlantState.Bad:
|
||||
color = Color.Red;
|
||||
break;
|
||||
case PlantState.Warning:
|
||||
color = Color.Yellow;
|
||||
break;
|
||||
default:
|
||||
color = Color.Lime;
|
||||
break;
|
||||
}
|
||||
|
||||
boxState.BackgroundColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,28 @@
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:extensions="clr-namespace:PlantBox.Client.Extensions"
|
||||
xmlns:forms="clr-namespace:PlantBox.Client.Forms"
|
||||
xmlns:viewmodels="clr-namespace:PlantBox.Client.ViewModels"
|
||||
x:Class="PlantBox.Client.Forms.HomePage">
|
||||
<ContentPage.BindingContext>
|
||||
<viewmodels:HomeViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
|
||||
</StackLayout>
|
||||
<ListView ItemsSource="{Binding Plants}"
|
||||
SelectionMode="None"
|
||||
IsPullToRefreshEnabled="True"
|
||||
RowHeight="85"
|
||||
SeparatorVisibility="None">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<forms:HomeItem Margin="5"
|
||||
PlantName="{Binding Name}"
|
||||
PlantType="{Binding Type}"
|
||||
PlantState="{Binding State}" />
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
@@ -23,6 +23,12 @@
|
||||
<SwitchCell Text="{extensions:Locale NotificationsMuted}"
|
||||
On="{Binding NotificationsMuted}" />
|
||||
</TableSection>
|
||||
<TableSection Title="{extensions:Locale Server}">
|
||||
<EntryCell Label="IP: "
|
||||
LabelColor="Accent"
|
||||
Placeholder="ip"
|
||||
Text="{Binding BrokerIP}"/>
|
||||
</TableSection>
|
||||
</TableRoot>
|
||||
</TableView>
|
||||
</ContentPage.Content>
|
||||
|
||||
@@ -14,5 +14,9 @@ namespace PlantBox.Client.Models
|
||||
|
||||
public bool NotificationsDisabled { get; set; } = false;
|
||||
public bool NotificationsMuted { get; set; } = false;
|
||||
|
||||
public string BrokerIP { get; set; } = "";
|
||||
|
||||
public List<ulong> IDs { get; set; } = new List<ulong>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
<EmbeddedResource Update="Forms\MenuPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Forms\HomeItem.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Forms\Settings\LanguageSelectorPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -186,6 +186,15 @@ namespace PlantBox.Client.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recherche une chaîne localisée semblable à Server.
|
||||
/// </summary>
|
||||
internal static string Server {
|
||||
get {
|
||||
return ResourceManager.GetString("Server", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recherche une chaîne localisée semblable à Settings.
|
||||
/// </summary>
|
||||
|
||||
@@ -159,6 +159,9 @@
|
||||
<data name="NotificationsMuted" xml:space="preserve">
|
||||
<value>Rendre muet les notifications</value>
|
||||
</data>
|
||||
<data name="Server" xml:space="preserve">
|
||||
<value>Serveur</value>
|
||||
</data>
|
||||
<data name="Settings" xml:space="preserve">
|
||||
<value>Préférences</value>
|
||||
</data>
|
||||
|
||||
@@ -159,6 +159,9 @@
|
||||
<data name="NotificationsMuted" xml:space="preserve">
|
||||
<value>Mute notifications</value>
|
||||
</data>
|
||||
<data name="Server" xml:space="preserve">
|
||||
<value>Server</value>
|
||||
</data>
|
||||
<data name="Settings" xml:space="preserve">
|
||||
<value>Settings</value>
|
||||
</data>
|
||||
|
||||
41
PlantBox.Client/PlantBox.Client/ViewModels/HomeViewModel.cs
Normal file
41
PlantBox.Client/PlantBox.Client/ViewModels/HomeViewModel.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using PlantBox.Client.Models;
|
||||
using PlantBox.Shared.Communication.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PlantBox.Client.ViewModels
|
||||
{
|
||||
class HomeViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public ObservableCollection<InfoResponse> Plants { get; set; }
|
||||
|
||||
public HomeViewModel()
|
||||
{
|
||||
Plants = LoadPlants(App.Settings.IDs);
|
||||
}
|
||||
|
||||
public ObservableCollection<InfoResponse> LoadPlants(IEnumerable<ulong> ids)
|
||||
{
|
||||
// Mock
|
||||
return new ObservableCollection<InfoResponse>()
|
||||
{
|
||||
new InfoResponse("Salon", PlantType.Ficus, PlantState.Good, 75.2),
|
||||
new InfoResponse("Chambre", PlantType.Bamboo, PlantState.Warning, 11.2),
|
||||
new InfoResponse("Hello", PlantType.Cactus, PlantState.Bad, 45.2),
|
||||
new InfoResponse("Hello", PlantType.Cactus, PlantState.Bad, 45.2)
|
||||
};
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,32 @@ namespace PlantBox.Client.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public string BrokerIP
|
||||
{
|
||||
get => _settings.BrokerIP;
|
||||
set
|
||||
{
|
||||
if (value != _settings.BrokerIP)
|
||||
{
|
||||
_settings.BrokerIP = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ulong> IDs
|
||||
{
|
||||
get => _settings.IDs;
|
||||
set
|
||||
{
|
||||
if (value != _settings.IDs)
|
||||
{
|
||||
_settings.IDs = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsViewModel()
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
|
||||
@@ -15,6 +15,18 @@ namespace PlantBox.Shared.Communication.Commands
|
||||
public PlantState State { get; set; }
|
||||
public double Water { get; set; }
|
||||
|
||||
public InfoResponse()
|
||||
{
|
||||
|
||||
}
|
||||
public InfoResponse(string name, PlantType type, PlantState state, double water)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
State = state;
|
||||
Water = water;
|
||||
}
|
||||
|
||||
public override InfoResponse Deserialize(string[] arguments)
|
||||
{
|
||||
if (arguments == null)
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace PlantBox.Shared.Communication.Commands
|
||||
{
|
||||
public enum PlantState
|
||||
{
|
||||
Default,
|
||||
Bad,
|
||||
Warning,
|
||||
Good
|
||||
|
||||
@@ -6,9 +6,10 @@ namespace PlantBox.Shared.Communication.Commands
|
||||
{
|
||||
public enum PlantType
|
||||
{
|
||||
Default,
|
||||
Bamboo,
|
||||
Bonsai,
|
||||
Cactus,
|
||||
Ficus,
|
||||
Ficus
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user