diff --git a/PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml b/PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml new file mode 100644 index 0000000..d81b451 --- /dev/null +++ b/PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml.cs new file mode 100644 index 0000000..853e717 --- /dev/null +++ b/PlantBox.Client/PlantBox.Client/Forms/HomeItem.xaml.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml b/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml index a08ce6c..4639185 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml +++ b/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml @@ -2,10 +2,28 @@ + + + - - - + + + + + + + + + \ No newline at end of file diff --git a/PlantBox.Client/PlantBox.Client/Forms/Settings/SettingsPage.xaml b/PlantBox.Client/PlantBox.Client/Forms/Settings/SettingsPage.xaml index 8f8df19..fc2bfea 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/Settings/SettingsPage.xaml +++ b/PlantBox.Client/PlantBox.Client/Forms/Settings/SettingsPage.xaml @@ -23,6 +23,12 @@ + + + diff --git a/PlantBox.Client/PlantBox.Client/Models/Settings.cs b/PlantBox.Client/PlantBox.Client/Models/Settings.cs index 22c25ea..cad1b07 100644 --- a/PlantBox.Client/PlantBox.Client/Models/Settings.cs +++ b/PlantBox.Client/PlantBox.Client/Models/Settings.cs @@ -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 IDs { get; set; } = new List(); } } diff --git a/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj b/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj index f088fc3..d584124 100644 --- a/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj +++ b/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj @@ -50,6 +50,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml diff --git a/PlantBox.Client/PlantBox.Client/Resources/Locale.Designer.cs b/PlantBox.Client/PlantBox.Client/Resources/Locale.Designer.cs index ec415a7..577ea5f 100644 --- a/PlantBox.Client/PlantBox.Client/Resources/Locale.Designer.cs +++ b/PlantBox.Client/PlantBox.Client/Resources/Locale.Designer.cs @@ -186,6 +186,15 @@ namespace PlantBox.Client.Resources { } } + /// + /// Recherche une chaîne localisée semblable à Server. + /// + internal static string Server { + get { + return ResourceManager.GetString("Server", resourceCulture); + } + } + /// /// Recherche une chaîne localisée semblable à Settings. /// diff --git a/PlantBox.Client/PlantBox.Client/Resources/Locale.fr.resx b/PlantBox.Client/PlantBox.Client/Resources/Locale.fr.resx index 4cedf84..5f5ece7 100644 --- a/PlantBox.Client/PlantBox.Client/Resources/Locale.fr.resx +++ b/PlantBox.Client/PlantBox.Client/Resources/Locale.fr.resx @@ -159,6 +159,9 @@ Rendre muet les notifications + + Serveur + Préférences diff --git a/PlantBox.Client/PlantBox.Client/Resources/Locale.resx b/PlantBox.Client/PlantBox.Client/Resources/Locale.resx index da0c427..0d952dc 100644 --- a/PlantBox.Client/PlantBox.Client/Resources/Locale.resx +++ b/PlantBox.Client/PlantBox.Client/Resources/Locale.resx @@ -159,6 +159,9 @@ Mute notifications + + Server + Settings diff --git a/PlantBox.Client/PlantBox.Client/ViewModels/HomeViewModel.cs b/PlantBox.Client/PlantBox.Client/ViewModels/HomeViewModel.cs new file mode 100644 index 0000000..d600c16 --- /dev/null +++ b/PlantBox.Client/PlantBox.Client/ViewModels/HomeViewModel.cs @@ -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 Plants { get; set; } + + public HomeViewModel() + { + Plants = LoadPlants(App.Settings.IDs); + } + + public ObservableCollection LoadPlants(IEnumerable ids) + { + // Mock + return new ObservableCollection() + { + 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)); + } + } +} diff --git a/PlantBox.Client/PlantBox.Client/ViewModels/SettingsViewModel.cs b/PlantBox.Client/PlantBox.Client/ViewModels/SettingsViewModel.cs index 2b9e90d..4a73dd1 100644 --- a/PlantBox.Client/PlantBox.Client/ViewModels/SettingsViewModel.cs +++ b/PlantBox.Client/PlantBox.Client/ViewModels/SettingsViewModel.cs @@ -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 IDs + { + get => _settings.IDs; + set + { + if (value != _settings.IDs) + { + _settings.IDs = value; + OnPropertyChanged(); + } + } + } + public SettingsViewModel() { if (File.Exists(FilePath)) diff --git a/PlantBox.Shared/Communication/Commands/InfoResponse.cs b/PlantBox.Shared/Communication/Commands/InfoResponse.cs index 19d1ed2..e486a46 100644 --- a/PlantBox.Shared/Communication/Commands/InfoResponse.cs +++ b/PlantBox.Shared/Communication/Commands/InfoResponse.cs @@ -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) diff --git a/PlantBox.Shared/Communication/Commands/PlantState.cs b/PlantBox.Shared/Communication/Commands/PlantState.cs index d7ba36a..ba8469a 100644 --- a/PlantBox.Shared/Communication/Commands/PlantState.cs +++ b/PlantBox.Shared/Communication/Commands/PlantState.cs @@ -6,6 +6,7 @@ namespace PlantBox.Shared.Communication.Commands { public enum PlantState { + Default, Bad, Warning, Good diff --git a/PlantBox.Shared/Communication/Commands/PlantType.cs b/PlantBox.Shared/Communication/Commands/PlantType.cs index 36dae3d..a72ad52 100644 --- a/PlantBox.Shared/Communication/Commands/PlantType.cs +++ b/PlantBox.Shared/Communication/Commands/PlantType.cs @@ -6,9 +6,10 @@ namespace PlantBox.Shared.Communication.Commands { public enum PlantType { + Default, Bamboo, Bonsai, Cactus, - Ficus, + Ficus } }