Add text to contact icon OUT-587
authorThomas
Fri, 09 Aug 2019 16:02:29 +0200
branchOUT-587
changeset 2701727366b902e3
parent 2700 b17a58d4461a
child 2702 4ebc6523e502
Add text to contact icon
UI/FormControlPreviewMessage.xaml
UI/FormControlPreviewMessage.xaml.cs
     1.1 --- a/UI/FormControlPreviewMessage.xaml	Fri Aug 09 14:06:19 2019 +0200
     1.2 +++ b/UI/FormControlPreviewMessage.xaml	Fri Aug 09 16:02:29 2019 +0200
     1.3 @@ -26,6 +26,11 @@
     1.4                  <local:IsListEmptyConverter />
     1.5                  <local:InvertBoolConverter />
     1.6              </local:ValueConverterGroup>
     1.7 +            <local:ValueConverterGroup x:Key="IsListEmptyToInvertVisibility">
     1.8 +                <local:IsListEmptyConverter />
     1.9 +                <local:InvertBoolConverter />
    1.10 +                <BooleanToVisibilityConverter />
    1.11 +            </local:ValueConverterGroup>
    1.12              <local:ValueConverterGroup x:Key="IsStringEmptyToVisibility">
    1.13                  <local:IsStringEmptyConverter />
    1.14                  <BooleanToVisibilityConverter />
    1.15 @@ -86,7 +91,8 @@
    1.16              </Grid.RowDefinitions>
    1.17  
    1.18              <!--Contact image-->
    1.19 -            <Canvas Grid.Row="0"
    1.20 +            <Canvas x:Name="CanvasContactName"
    1.21 +                    Grid.Row="0"
    1.22                      Grid.RowSpan="3"
    1.23                      Grid.Column="0"
    1.24                      Height="60"
    1.25 @@ -97,7 +103,18 @@
    1.26                           Height="48"
    1.27                           Fill="{Binding ContactIconBackground}"
    1.28                           Canvas.Left="6"
    1.29 -                         Canvas.Top="6"/>
    1.30 +                         Canvas.Top="6"
    1.31 +                         Panel.ZIndex="0"/>
    1.32 +                <Grid Width="{Binding ActualWidth, ElementName=CanvasContactName}"
    1.33 +                      Height="{Binding ActualHeight, ElementName=CanvasContactName}">
    1.34 +                    <TextBlock Text="{Binding ContactIconText}"                           
    1.35 +                           Foreground="White"
    1.36 +                           FontFamily="Segoe UI Light"
    1.37 +                           FontSize="20"
    1.38 +                           Panel.ZIndex="1"
    1.39 +                           HorizontalAlignment="Center"
    1.40 +                           VerticalAlignment="Center"/>
    1.41 +                </Grid>
    1.42              </Canvas>
    1.43  
    1.44              <!-- From recipient -->
    1.45 @@ -221,7 +238,7 @@
    1.46              <StackPanel Grid.Row="2" 
    1.47                          Grid.Column="1"
    1.48                          Orientation="Horizontal"
    1.49 -                        Visibility="{Binding Message.Cc, Converter={StaticResource IsListEmptyToInvertBool}}">
    1.50 +                        Visibility="{Binding Message.Cc, Converter={StaticResource IsListEmptyToInvertVisibility}}">
    1.51  
    1.52                  <!--Recipients "Cc" text-->
    1.53                  <TextBlock Margin="0,0,10,0"
     2.1 --- a/UI/FormControlPreviewMessage.xaml.cs	Fri Aug 09 14:06:19 2019 +0200
     2.2 +++ b/UI/FormControlPreviewMessage.xaml.cs	Fri Aug 09 16:02:29 2019 +0200
     2.3 @@ -4,6 +4,7 @@
     2.4  using System.Diagnostics;
     2.5  using System.IO;
     2.6  using System.Net;
     2.7 +using System.Runtime.CompilerServices;
     2.8  using System.Text.RegularExpressions;
     2.9  using System.Windows;
    2.10  using System.Windows.Controls;
    2.11 @@ -571,9 +572,6 @@
    2.12              /// </summary>
    2.13              public event PropertyChangedEventHandler PropertyChanged;
    2.14  
    2.15 -            private SolidColorBrush _ContactIconBackground;
    2.16 -            private string _Date;
    2.17 -            private string _FromRecipient;
    2.18              private bool _IsNoteModeEnabled;
    2.19              private PEPMessage _Message;
    2.20  
    2.21 @@ -600,30 +598,23 @@
    2.22              /// <summary>
    2.23              /// Gets the background color of the Contact icon.
    2.24              /// </summary>
    2.25 -            public SolidColorBrush ContactIconBackground
    2.26 -            {
    2.27 -                get { return this._ContactIconBackground; }
    2.28 -            }
    2.29 +            public SolidColorBrush ContactIconBackground { get; private set; }
    2.30 +
    2.31 +            /// <summary>
    2.32 +            /// Gets the text to show in the Contact icon.
    2.33 +            /// </summary>
    2.34 +            public string ContactIconText { get; private set; }
    2.35  
    2.36              /// <summary>
    2.37              /// Gets the formatted date string of the message.
    2.38              /// This is a dependent property set through Message.
    2.39              /// </summary>
    2.40 -            public string Date
    2.41 -            {
    2.42 -                get { return this._Date; }
    2.43 -            }
    2.44 +            public string Date { get; private set; }
    2.45  
    2.46              /// <summary>
    2.47              /// Gets the To recipient
    2.48              /// </summary>
    2.49 -            public string FromRecipient
    2.50 -            {
    2.51 -                get
    2.52 -                {
    2.53 -                    return (this._FromRecipient);
    2.54 -                }
    2.55 -            }
    2.56 +            public string FromRecipient { get; private set; }
    2.57  
    2.58              /// <summary>
    2.59              /// Gets or sets whether note mode is enabled.
    2.60 @@ -631,11 +622,11 @@
    2.61              /// </summary>
    2.62              public bool IsNoteModeEnabled
    2.63              {
    2.64 -                get { return (this._IsNoteModeEnabled); }
    2.65 +                get => this._IsNoteModeEnabled;
    2.66                  set
    2.67                  {
    2.68                      this._IsNoteModeEnabled = value;
    2.69 -                    this.RaisePropertyChangedEvent(nameof(this.IsNoteModeEnabled));
    2.70 +                    this.OnPropertyChanged();
    2.71  
    2.72                      this.CalcDependentProperties();
    2.73                  }
    2.74 @@ -646,11 +637,11 @@
    2.75              /// </summary>
    2.76              public PEPMessage Message
    2.77              {
    2.78 -                get { return (this._Message); }
    2.79 +                get => this._Message;
    2.80                  set
    2.81                  {
    2.82                      this._Message = value;
    2.83 -                    this.RaisePropertyChangedEvent(nameof(this.Message));
    2.84 +                    this.OnPropertyChanged();
    2.85  
    2.86                      this.CalcDependentProperties();
    2.87                  }
    2.88 @@ -671,7 +662,7 @@
    2.89              /// Raises the property changed event, if possible, with the given arguments.
    2.90              /// </summary>
    2.91              /// <param name="propertyName">The name of the property that changed.</param>
    2.92 -            private void RaisePropertyChangedEvent(string propertyName)
    2.93 +            protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    2.94              {
    2.95                  this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    2.96              }
    2.97 @@ -682,11 +673,8 @@
    2.98              public void Reset()
    2.99              {
   2.100                  // Set independent properties
   2.101 -                this._IsNoteModeEnabled = true;
   2.102 -                this._Message = null;
   2.103 -
   2.104 -                this.RaisePropertyChangedEvent(nameof(this.IsNoteModeEnabled));
   2.105 -                this.RaisePropertyChangedEvent(nameof(this.Message));
   2.106 +                this.IsNoteModeEnabled = true;
   2.107 +                this.Message = null;
   2.108  
   2.109                  // Set dependent properties -- raises own events
   2.110                  this.CalcDependentProperties();
   2.111 @@ -699,16 +687,36 @@
   2.112              private void CalcDependentProperties()
   2.113              {
   2.114                  // Date
   2.115 -                this._Date = this._Message?.SentOn?.ToString("g", Globals.ThisAddIn.GetActiveUICulture());
   2.116 -                this.RaisePropertyChangedEvent(nameof(this.Date));
   2.117 +                this.Date = this._Message?.SentOn?.ToString("g", Globals.ThisAddIn.GetActiveUICulture());
   2.118 +                this.OnPropertyChanged(nameof(this.Date));
   2.119  
   2.120                  // From recipient
   2.121 -                this._FromRecipient = this._Message?.From?.UserName ?? this.Message?.From?.Address;
   2.122 -                this.RaisePropertyChangedEvent(nameof(this.FromRecipient));
   2.123 +                this.FromRecipient = this._Message?.From?.UserName ?? this.Message?.From?.Address;
   2.124 +                this.OnPropertyChanged(nameof(this.FromRecipient));
   2.125  
   2.126 -                // Contact Image color
   2.127 -                this._ContactIconBackground = (SolidColorBrush)new BrushConverter().ConvertFromString("#03AA4B");
   2.128 -                this.RaisePropertyChangedEvent(nameof(this.ContactIconBackground));
   2.129 +                // Contact Icon color
   2.130 +                this.ContactIconBackground = (SolidColorBrush)new BrushConverter().ConvertFromString("#03AA4B");
   2.131 +                this.OnPropertyChanged(nameof(this.ContactIconBackground));
   2.132 +
   2.133 +                // Contact Icon text
   2.134 +                string contactIconText = null;
   2.135 +                try
   2.136 +                {
   2.137 +                    string[] initials = this.FromRecipient?.ToUpperInvariant()?.Split(' ');
   2.138 +                    if (initials?.Length > 0)
   2.139 +                    {
   2.140 +                        for (int i = 0; i < initials?.Length; i++)
   2.141 +                        {
   2.142 +                            contactIconText += initials[i][0];
   2.143 +                        }
   2.144 +                    }
   2.145 +                }
   2.146 +                catch (Exception ex)
   2.147 +                {
   2.148 +                    Log.Error("FormControlPreviewMessage.CalcDependentProperties: Error getting initials. " + ex.ToString());
   2.149 +                }
   2.150 +                this.ContactIconText = contactIconText;
   2.151 +                this.OnPropertyChanged(nameof(this.ContactIconText));
   2.152              }
   2.153  
   2.154              /// <summary>
   2.155 @@ -717,15 +725,10 @@
   2.156              /// </summary>
   2.157              public void SetNote(string note = null)
   2.158              {
   2.159 -                this._Date = null;
   2.160 -                this._IsNoteModeEnabled = true;
   2.161 -                this._Message = null;
   2.162 -                this._FromRecipient = note;
   2.163 -
   2.164 -                this.RaisePropertyChangedEvent(nameof(this.Date));
   2.165 -                this.RaisePropertyChangedEvent(nameof(this.FromRecipient));
   2.166 -                this.RaisePropertyChangedEvent(nameof(this.IsNoteModeEnabled));
   2.167 -                this.RaisePropertyChangedEvent(nameof(this.Message));
   2.168 +                this.Date = null;
   2.169 +                this.IsNoteModeEnabled = true;
   2.170 +                this.Message = null;
   2.171 +                this.FromRecipient = note;
   2.172              }
   2.173  
   2.174              /// <summary>
   2.175 @@ -735,11 +738,8 @@
   2.176              /// <param name="message">The message to set to the UI.</param>
   2.177              public void SetMessage(PEPMessage message)
   2.178              {
   2.179 -                this._IsNoteModeEnabled = false;
   2.180 -                this._Message = message;
   2.181 -
   2.182 -                this.RaisePropertyChangedEvent(nameof(this.IsNoteModeEnabled));
   2.183 -                this.RaisePropertyChangedEvent(nameof(this.Message));
   2.184 +                this.IsNoteModeEnabled = false;
   2.185 +                this.Message = message;
   2.186  
   2.187                  this.CalcDependentProperties();
   2.188              }