Quellcode durchsuchen

Added Company Logo to HomeScreen Layouts
Added Proper Android Geolocation

Frank van den Bos vor 1 Monat
Ursprung
Commit
fca972ee8e

+ 1 - 2
PRS.Avalonia/PRS.Avalonia.Android/MainActivity.cs

@@ -35,8 +35,7 @@ public class MainActivity : AvaloniaMainActivity<App>
         PlatformTools.Register<IBluetooth, Android_Bluetooth>();
         PlatformTools.Register<ICameraViewControl, Android_CameraViewControl>();
         PlatformTools.Register<IPermissions, Android_Permissions>();
-        
-        
+        PlatformTools.Register<IGeolocation, Android_Geolocation>();
         
         return base.CustomizeAppBuilder(builder)
             .WithInterFont();

+ 103 - 48
PRS.Avalonia/PRS.Avalonia/HomePage/HomePageView.axaml

@@ -12,7 +12,9 @@
     <UserControl.Resources>
         <converters:BooleanToColorConverter x:Key="BooleanToColorConverter" True="{StaticResource PrsButtonBackground}" False="{StaticResource PrsAlertBackground}" />
         <converters:BooleanToStringConverter x:Key="BooleanToStringConverter" True="CLOCK OFF" False="CLOCK ON" />
-        <converters:BooleanMatcher x:Key="BooleanMatcher" Comparison="EqualTo" Type="All" />
+        <converters:ByteArrayToImageSourceConverter x:Key="ImageSourceConverter" />
+        <converters:ByteArrayToBooleanConverter x:Key="ByteArrayHasBytes" />
+        <converters:ByteArrayToBooleanConverter x:Key="ByteArrayIsEmpty" Inverted="True" />
     </UserControl.Resources>
     <Grid 
         RowDefinitions="200 Auto Auto *" 
@@ -37,59 +39,82 @@
             
             <Grid 
                 ColumnDefinitions="* Auto" 
-                RowDefinitions="* Auto"
+                RowDefinitions="*"
                 HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch">
                 
-                <StackPanel 
-                    Orientation="Vertical"
-                    HorizontalAlignment="Center"
-                    VerticalAlignment="Center"
+                <StackPanel
                     Grid.Row="0"
                     Grid.Column="0"
-                    Grid.RowSpan="2"
-                    Grid.ColumnSpan="2">
+                    Orientation="Horizontal"
+                    HorizontalAlignment="Center"
+                    VerticalAlignment="Center">
                     
-                    <Label 
-                        FontSize="{StaticResource PrsFontSizeExtraLarge}"
-                        FontWeight="Bold"
-                        Content="{Binding IsClockedOn, Converter={StaticResource BooleanToStringConverter}}"
-                        HorizontalAlignment="Center"/>
+                    <Border
+                        Classes="Standard"
+                        IsVisible="{Binding CompanyLogo, Converter={StaticResource ByteArrayHasBytes}}"
+                        Height="120"
+                        Width="120"
+                        CornerRadius="60"
+                        Margin="0 0 10 0">
+                        <Border.Background>
+                            <SolidColorBrush Color="WhiteSmoke" Opacity="0.6" />
+                        </Border.Background>
+                        <Image 
+                            Source="{Binding CompanyLogo, Converter={StaticResource ImageSourceConverter}}" 
+                            Stretch="Uniform"
+                            VerticalAlignment="Stretch"
+                            HorizontalAlignment="Stretch"
+                        />
+                    </Border>
                     
-                    <Label 
-                        FontSize="{StaticResource PrsFontSizeNormal}"
-                        FontWeight="DemiBold"
-                        Content="{Binding ClockOnLocation}"
-                        HorizontalAlignment="Center">
-                        <Label.IsVisible>
-                            <MultiBinding Converter = "{x:Static BoolConverters.And}">
-                                <Binding Path="IsClockedOn" Converter="{x:Static BoolConverters.Not}" />
-                                <Binding Path="ClockOnLocation" Converter="{x:Static StringConverters.IsNotNullOrEmpty}" />
-                            </MultiBinding>
-                        </Label.IsVisible>
-                    </Label>
+                    <StackPanel 
+                        Orientation="Vertical"
+                        HorizontalAlignment="Center"
+                        VerticalAlignment="Center"
+                        MinWidth="200">
                     
-                    <Label 
-                        FontSize="{StaticResource PrsFontSizeNormal}"
-                        FontWeight="DemiBold"
-                        Content="No Job Site Found"
-                        HorizontalAlignment="Center">
-                        <Label.IsVisible>
-                            <MultiBinding Converter="{x:Static BoolConverters.And}">
-                                <Binding Path="IsClockedOn" Converter="{x:Static BoolConverters.Not}" />
-                                <Binding Path="ClockOnLocation" Converter="{x:Static ObjectConverters.IsNull}" />
-                                <Binding Path="CurrentLocation" Converter="{x:Static ObjectConverters.IsNotNull}" />
-                            </MultiBinding>
-                        </Label.IsVisible>
-                    </Label>
+                        <Label 
+                            FontSize="{StaticResource PrsFontSizeSuperLarge}"
+                            FontWeight="Bold"
+                            Content="{Binding IsClockedOn, Converter={StaticResource BooleanToStringConverter}}"
+                            HorizontalAlignment="Center"/>
                     
-                    <Label 
-                        FontSize="{StaticResource PrsFontSizeNormal}"
-                        FontWeight="DemiBold"
-                        Content="Missing/Invalid GPS Signal"
-                        IsVisible="{Binding CurrentLocation, Converter={x:Static ObjectConverters.IsNull}}"
-                        HorizontalAlignment="Center"/>
+                        <Label 
+                            FontSize="{StaticResource PrsFontSizeNormal}"
+                            FontWeight="DemiBold"
+                            Content="{Binding ClockOnLocation}"
+                            HorizontalAlignment="Center">
+                            <Label.IsVisible>
+                                <MultiBinding Converter = "{x:Static BoolConverters.And}">
+                                    <Binding Path="IsClockedOn" Converter="{x:Static BoolConverters.Not}" />
+                                    <Binding Path="ClockOnLocation" Converter="{x:Static StringConverters.IsNotNullOrEmpty}" />
+                                </MultiBinding>
+                            </Label.IsVisible>
+                        </Label>
+                    
+                        <Label 
+                            FontSize="{StaticResource PrsFontSizeNormal}"
+                            FontWeight="DemiBold"
+                            Content="No Job Site Found"
+                            HorizontalAlignment="Center">
+                            <Label.IsVisible>
+                                <MultiBinding Converter="{x:Static BoolConverters.And}">
+                                    <Binding Path="IsClockedOn" Converter="{x:Static BoolConverters.Not}" />
+                                    <Binding Path="ClockOnLocation" Converter="{x:Static ObjectConverters.IsNull}" />
+                                    <Binding Path="CurrentLocation" Converter="{x:Static ObjectConverters.IsNotNull}" />
+                                </MultiBinding>
+                            </Label.IsVisible>
+                        </Label>
                     
+                        <Label 
+                            FontSize="{StaticResource PrsFontSizeNormal}"
+                            FontWeight="DemiBold"
+                            Content="Missing/Invalid GPS Signal"
+                            IsVisible="{Binding CurrentLocation, Converter={x:Static ObjectConverters.IsNull}}"
+                            HorizontalAlignment="Center"/>
+                    
+                    </StackPanel>
                 </StackPanel>
                 
                 <ProgressBar
@@ -109,15 +134,45 @@
 				Grid.Row="0"
 				Grid.Column="0"
 				Grid.ColumnSpan="2"
-				Padding="10"
+				Padding="20"
 				IsVisible="{Binding SplashVisible}">
-            <Image Source="{SvgImage ../Images/badge.svg}" />
+                <StackPanel
+                    Orientation="Vertical"
+                    HorizontalAlignment="Center"
+                    VerticalAlignment="Center">
+                    
+                    <Image 
+                        Classes.HasLogo="{Binding CompanyLogo, Converter={StaticResource ByteArrayHasBytes}}"
+                        Classes.NoLogo="{Binding CompanyLogo, Converter={StaticResource ByteArrayIsEmpty}}"
+                        Stretch="Uniform"
+                        Height="120"
+                        Width="120">
+                        <Image.Styles>
+                            <Style Selector="Image.HasLogo">
+                                <Setter Property="Source" Value="{Binding CompanyLogo, Converter={StaticResource ByteArrayToImageSourceConverter}}" />
+                            </Style>
+                            <Style Selector="Image.NoLogo">
+                                <Setter Property="Source" Value="{SvgImage ../Images/badge.svg}" />
+                            </Style>
+                        </Image.Styles>
+                    </Image>
+                    
+                    <Label 
+                        FontSize="{StaticResource PrsFontSizeExtraLarge}"
+                        FontWeight="Bold"
+                        Margin="0 20 0 0"
+                        Content="{Binding CompanyName}"
+                        IsVisible="{Binding CompanyName, Converter={StaticResource StringToBooleanConverter}}"
+                        HorizontalAlignment="Center"/>
+                    
+                </StackPanel>
+
         </Border>
         
         <Button Classes="Standard"
             Grid.Row="1"
             Grid.Column="0"
-            Content="{Binding Repositories.CurrentAssignment?.JobDisplay, TargetNullValue='Select Job'}"
+            Content="{Binding Repositories.CurrentAssignment.JobDisplay, FallbackValue='Select Job'}"
             IsVisible="{Binding ClockOnVisible}"
             Background="{Binding IsClockedOn, Converter={StaticResource BooleanToColorConverter}}"
             Command="{Binding SelectJobCommand}">
@@ -133,7 +188,7 @@
         <Button Classes="Standard"
             Grid.Row="2"
             Grid.Column="0"
-            Content="{Binding Repositories.CurrentAssignment?.TaskDisplay, TargetNullValue='Select Task'}"
+            Content="{Binding Repositories.CurrentAssignment.TaskDisplay, FallbackValue='Select Task'}"
             IsVisible="{Binding ClockOnVisible}"
             Background="{Binding IsClockedOn, Converter={StaticResource BooleanToColorConverter}}"
             Command="{Binding SelectTaskCommand}">

+ 4 - 0
PRS.Avalonia/PRS.Avalonia/HomePage/HomePageViewModel.cs

@@ -120,6 +120,7 @@ public partial class HomePageViewModel : ViewModelBase
     {
         foreach (var setting in DatabaseSettings)
             setting.Value.IsDefault = string.Equals(setting.Key, key);
+        SaveDatabaseSettings();
         Navigation.Reset<LoginViewModel>();
         return Task.FromResult(true);
     }
@@ -157,6 +158,9 @@ public partial class HomePageViewModel : ViewModelBase
     [ObservableProperty] 
     private double _gpsRemaining;
     
+    public byte[]? CompanyLogo => Repositories.CompanyInformation.Items.FirstOrDefault()?.Logo;
+    public string? CompanyName => Repositories.CompanyInformation.Items.FirstOrDefault()?.CompanyName;
+    
     private void LocationChanged(object? sender, GeoLocationChangedArgs e)
     {
         DoLocationChanged();

+ 3 - 0
PRS.Avalonia/PRS.Avalonia/Repositories/CompanyInformation/CompanyInformationModel.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Linq.Expressions;
 using Comal.Classes;
 using InABox.Avalonia;
 using InABox.Core;
@@ -10,4 +11,6 @@ public class CompanyInformationModel : CoreRepository<CompanyInformationModel, C
     public CompanyInformationModel(IModelHost host, Func<Filter<CompanyInformation>> filter, Func<string>? filename = null) : base(host, filter, filename)
     {
     }
+    
+    protected override Expression<Func<CompanyInformation, Guid>> ImageColumn => x => x.Logo.ID;
 }

+ 6 - 1
PRS.Avalonia/PRS.Avalonia/Repositories/CompanyInformation/CompanyInformationShell.cs

@@ -14,6 +14,10 @@ public class CompanyInformationShell : Shell<CompanyInformationModel, CompanyInf
         set => Set(value);
     }
     
+    public Guid LogoID => Get<Guid>();
+
+    public byte[] Logo => Parent.GetImageSource(LogoID);
+    
     private GeoFenceDefinition? _geofence;
     public GeoFenceDefinition? Geofence {
         get
@@ -30,6 +34,7 @@ public class CompanyInformationShell : Shell<CompanyInformationModel, CompanyInf
     {
         columns
             .Map(nameof(Geofence), x => x.DeliveryAddress.Geofence)
-            .Map(nameof(CompanyName), x => x.CompanyName);
+            .Map(nameof(CompanyName), x => x.CompanyName)
+            .Map(nameof(LogoID), x=>x.Logo.ID);
     }
 }