Skip to content

Commit bcda48b

Browse files
golf1052Trolldemorted
authored andcommitted
Beginnings of displaying attachment
1 parent 021e2e2 commit bcda48b

File tree

6 files changed

+128
-1
lines changed

6 files changed

+128
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<UserControl
2+
x:Class="Signal_Windows.Controls.Attachment"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Signal_Windows.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
d:DesignHeight="200"
10+
d:DesignWidth="200">
11+
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="*"/>
15+
<ColumnDefinition Width="*"/>
16+
</Grid.ColumnDefinitions>
17+
<Ellipse Fill="#FF9B9B9B" Width="50" Height="50"/>
18+
<SymbolIcon Symbol="Page2"/>
19+
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8,0,0,0">
20+
<TextBlock Text="{x:Bind FileName, Mode=OneWay}" Style="{StaticResource BodyTextBlockStyle}"/>
21+
<TextBlock Text="{x:Bind FileSize, Mode=OneWay}" Style="{StaticResource CaptionTextBlockStyle}"/>
22+
</StackPanel>
23+
</Grid>
24+
</UserControl>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.InteropServices.WindowsRuntime;
7+
using Signal_Windows.Models;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
19+
20+
namespace Signal_Windows.Controls
21+
{
22+
public sealed partial class Attachment : UserControl, INotifyPropertyChanged
23+
{
24+
public event PropertyChangedEventHandler PropertyChanged;
25+
26+
private string fileName;
27+
public string FileName
28+
{
29+
get { return fileName; }
30+
set { fileName = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FileName))); }
31+
}
32+
33+
private string fileSize;
34+
public string FileSize
35+
{
36+
get { return fileSize; }
37+
set { fileSize = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FileSize))); }
38+
}
39+
40+
public SignalAttachment Model
41+
{
42+
get { return DataContext as SignalAttachment; }
43+
set { DataContext = value; }
44+
}
45+
46+
public Attachment()
47+
{
48+
this.InitializeComponent();
49+
DataContextChanged += Attachment_DataContextChanged;
50+
}
51+
52+
private void Attachment_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
53+
{
54+
if (Model != null)
55+
{
56+
FileName = Model.FileName;
57+
FileSize = Utils.BytesToString(Model.Size);
58+
}
59+
}
60+
}
61+
}

Signal-Windows/Controls/Message.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</UserControl.Resources>
1717
<Border Name="MessageBoxBorder" BorderBrush="#00000000" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4" Padding="10 5 10 5" Margin="4">
1818
<ItemsControl>
19+
<local:Attachment DataContext="{x:Bind Attachment, Mode=OneWay}" Visibility="{x:Bind HasAttachment, Mode=OneWay}"/>
1920
<TextBlock Name="MessageAuthor" FontWeight="Bold" />
2021
<TextBlock Name="MessageContentTextBlock" TextWrapping="Wrap" MaxWidth="300" IsTextSelectionEnabled="True" FontSize="14" Foreground="Black" />
2122
<Grid Name="FooterPanel" MaxWidth="300">

Signal-Windows/Controls/Message.xaml.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace Signal_Windows.Controls
1515
{
16-
public sealed partial class Message : UserControl
16+
public sealed partial class Message : UserControl, INotifyPropertyChanged
1717
{
18+
public event PropertyChangedEventHandler PropertyChanged;
19+
1820
public SignalMessageContainer Model
1921
{
2022
get
@@ -27,6 +29,20 @@ public SignalMessageContainer Model
2729
}
2830
}
2931

32+
private bool hasAttachment;
33+
public bool HasAttachment
34+
{
35+
get { return hasAttachment; }
36+
set { hasAttachment = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HasAttachment))); }
37+
}
38+
39+
private SignalAttachment attachment;
40+
public SignalAttachment Attachment
41+
{
42+
get { return attachment; }
43+
set { attachment = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Attachment))); }
44+
}
45+
3046
public Message()
3147
{
3248
this.InitializeComponent();
@@ -93,6 +109,13 @@ private void UpdateUI()
93109
FooterPanel.HorizontalAlignment = HorizontalAlignment.Left;
94110
}
95111
FancyTimestampBlock.Text = Utils.GetTimestamp(Model.Message.ComposedTimestamp);
112+
113+
HasAttachment = false;
114+
if (Model.Message.Attachments?.Count > 0)
115+
{
116+
HasAttachment = true;
117+
Attachment = Model.Message.Attachments[0];
118+
}
96119
}
97120
}
98121

Signal-Windows/Signal-Windows.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
<Compile Include="Controls\AddContactListElement.xaml.cs">
146146
<DependentUpon>AddContactListElement.xaml</DependentUpon>
147147
</Compile>
148+
<Compile Include="Controls\Attachment.xaml.cs">
149+
<DependentUpon>Attachment.xaml</DependentUpon>
150+
</Compile>
148151
<Compile Include="Controls\IdentityKeyChangeMessage.xaml.cs">
149152
<DependentUpon>IdentityKeyChangeMessage.xaml</DependentUpon>
150153
</Compile>
@@ -226,6 +229,10 @@
226229
<SubType>Designer</SubType>
227230
<Generator>MSBuild:Compile</Generator>
228231
</Page>
232+
<Page Include="Controls\Attachment.xaml">
233+
<SubType>Designer</SubType>
234+
<Generator>MSBuild:Compile</Generator>
235+
</Page>
229236
<Page Include="Controls\IdentityKeyChangeMessage.xaml">
230237
<SubType>Designer</SubType>
231238
<Generator>MSBuild:Compile</Generator>

Signal-Windows/Utils.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ public static bool ContainsCaseInsensitive(this string str, string value)
252252
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(str, value, CompareOptions.IgnoreCase) >= 0;
253253
}
254254

255+
public static String BytesToString(long byteCount) //https://stackoverflow.com/a/4975942/1569755
256+
{
257+
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB
258+
if (byteCount == 0)
259+
return "0" + suf[0];
260+
long bytes = Math.Abs(byteCount);
261+
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
262+
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
263+
return (Math.Sign(byteCount) * num).ToString() + suf[place];
264+
}
265+
255266
public static string GetCountryCode(string ISO3166) //https://stackoverflow.com/questions/34837436/uwp-get-country-phone-number-prefix
256267
{
257268
var dictionary = new Dictionary<string, string>();

0 commit comments

Comments
 (0)