Skip to content

Commit b265ac4

Browse files
committed
Create conversation settings page
1 parent 9ca8e32 commit b265ac4

9 files changed

+511
-38
lines changed

Signal-Windows/Controls/Conversation.xaml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@
3030
<RowDefinition Height="Auto" />
3131
</Grid.RowDefinitions>
3232
<Border Grid.Row="0" Background="{x:Bind HeaderBackground, Mode=OneWay}">
33-
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
34-
<TextBlock Name="Displayname" IsTextSelectionEnabled="True" HorizontalAlignment="Center" Text="{x:Bind ThreadDisplayName, Mode=OneWay}" />
35-
<TextBlock Name="Separator" xml:space="preserve" Visibility="{x:Bind SeparatorVisibility, Mode=OneWay}">&#160;&#160;&#x2022;&#160;&#160;</TextBlock>
36-
<TextBlock Name="Username" IsTextSelectionEnabled="True" HorizontalAlignment="Center" Text="{x:Bind ThreadUsername, Mode=OneWay}" Visibility="{x:Bind ThreadUsernameVisibility, Mode=OneWay}" />
37-
</StackPanel>
33+
<Grid>
34+
<Grid.ColumnDefinitions>
35+
<ColumnDefinition/>
36+
<ColumnDefinition Width="50"/>
37+
</Grid.ColumnDefinitions>
38+
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
39+
<TextBlock Name="Displayname" IsTextSelectionEnabled="True" HorizontalAlignment="Center" Text="{x:Bind ThreadDisplayName, Mode=OneWay}" />
40+
<TextBlock Name="Separator" xml:space="preserve" Visibility="{x:Bind SeparatorVisibility, Mode=OneWay}">&#160;&#160;&#x2022;&#160;&#160;</TextBlock>
41+
<TextBlock Name="Username" IsTextSelectionEnabled="True" HorizontalAlignment="Center" Text="{x:Bind ThreadUsername, Mode=OneWay}" Visibility="{x:Bind ThreadUsernameVisibility, Mode=OneWay}" />
42+
</StackPanel>
43+
<Button Grid.Column="1" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{x:Bind HeaderBackground, Mode=OneWay}">
44+
<SymbolIcon Symbol="More"/>
45+
<Button.Flyout>
46+
<MenuFlyout>
47+
<MenuFlyoutItem x:Name="ConversationSettingsButton" Text="Conversation settings" Click="ConversationSettingsButton_Click"/>
48+
<MenuFlyoutItem Text="Disappearing messages" IsEnabled="False"/>
49+
<MenuFlyoutItem Text="All media" IsEnabled="False"/>
50+
<ToggleMenuFlyoutItem Text="Mute conversation" IsEnabled="False"/>
51+
<MenuFlyoutItem Text="Reset secure session" IsEnabled="False"/>
52+
</MenuFlyout>
53+
</Button.Flyout>
54+
</Button>
55+
</Grid>
3856
</Border>
3957
<ListView Grid.Row="1" Name="ConversationItemsControl" VirtualizingStackPanel.VirtualizationMode="Recycling" Background="White" ScrollViewer.VerticalScrollBarVisibility="Visible" Padding="0 0 15 0" ItemTemplateSelector="{StaticResource MessageDataTemplateSelector}" SelectionMode="None">
4058
<ListView.ItemContainerStyle>

Signal-Windows/Controls/Conversation.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Signal_Windows.Models;
33
using Signal_Windows.Storage;
44
using Signal_Windows.ViewModels;
5+
using Signal_Windows.Views;
56
using System;
67
using System.Collections.Generic;
78
using System.ComponentModel;
@@ -260,6 +261,15 @@ private void ScrollToUnread()
260261
}
261262
}
262263
}
264+
265+
private void ConversationSettingsButton_Click(object sender, RoutedEventArgs e)
266+
{
267+
if (SignalConversation is SignalContact)
268+
{
269+
App.ViewModels.ConversationSettingsPageInstance.Contact = (SignalContact)SignalConversation;
270+
GetMainPageVm().View.Frame.Navigate(typeof(ConversationSettingsPage));
271+
}
272+
}
263273
}
264274

265275
public class MessageTemplateSelector : DataTemplateSelector

Signal-Windows/Controls/ConversationListElement.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private void ThreadListItem_DataContextChanged(FrameworkElement sender, DataCont
121121
ConversationDisplayName.Text = Model.ThreadDisplayName;
122122
UnreadCount = Model.UnreadCount;
123123
LastMessage = Model.LastMessage?.Content.Content;
124-
Initials = Model.ThreadDisplayName.Length == 0 ? "#" : Model.ThreadDisplayName.Substring(0, 1);
124+
Initials = Utils.GetInitials(Model.ThreadDisplayName);
125125
FillBrush = Model is SignalContact ? Utils.GetBrushFromColor(((SignalContact)Model).Color) : Utils.Blue;
126126
LastMessageTimestamp = Utils.GetTimestamp(Model.LastActiveTimestamp);
127127
}

Signal-Windows/Signal-Windows.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
<Compile Include="Storage\Store.cs" />
203203
<Compile Include="Utils.cs" />
204204
<Compile Include="ViewModels\AddContactPageViewModel.cs" />
205+
<Compile Include="ViewModels\ConversationSettingsPageViewModel.cs" />
205206
<Compile Include="ViewModels\FinishRegistrationPageViewModel.cs" />
206207
<Compile Include="ViewModels\LinkPageViewModel.cs" />
207208
<Compile Include="ViewModels\MainPageViewModel.cs" />
@@ -212,6 +213,9 @@
212213
<Compile Include="Views\AddContactPage.xaml.cs">
213214
<DependentUpon>AddContactPage.xaml</DependentUpon>
214215
</Compile>
216+
<Compile Include="Views\ConversationSettingsPage.xaml.cs">
217+
<DependentUpon>ConversationSettingsPage.xaml</DependentUpon>
218+
</Compile>
215219
<Compile Include="Views\FinishRegistrationPage.xaml.cs">
216220
<DependentUpon>FinishRegistrationPage.xaml</DependentUpon>
217221
</Compile>
@@ -285,6 +289,10 @@
285289
<SubType>Designer</SubType>
286290
<Generator>MSBuild:Compile</Generator>
287291
</Page>
292+
<Page Include="Views\ConversationSettingsPage.xaml">
293+
<SubType>Designer</SubType>
294+
<Generator>MSBuild:Compile</Generator>
295+
</Page>
288296
<Page Include="Views\FinishRegistrationPage.xaml">
289297
<SubType>Designer</SubType>
290298
<Generator>MSBuild:Compile</Generator>
@@ -364,4 +372,4 @@
364372
<Target Name="AfterBuild">
365373
</Target>
366374
-->
367-
</Project>
375+
</Project>

Signal-Windows/Utils.cs

Lines changed: 77 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using Windows.Foundation;
88
using Windows.Foundation.Metadata;
9+
using Windows.UI;
910
using Windows.UI.Core;
1011
using Windows.UI.Xaml;
1112
using Windows.UI.Xaml.Controls;
@@ -15,22 +16,39 @@ namespace Signal_Windows
1516
{
1617
public static class Utils
1718
{
19+
public const string RED = "red";
20+
public const string PINK = "pink";
21+
public const string PURPLE = "purple";
22+
public const string DEEP_PURPLE = "deep_purple";
23+
public const string INDIGO = "indigo";
24+
public const string BLUE = "blue";
25+
public const string LIGHT_BLUE = "light_blue";
26+
public const string CYAN = "cyan";
27+
public const string TEAL = "teal";
28+
public const string GREEN = "green";
29+
public const string LIGHT_GREEN = "light_green";
30+
public const string ORANGE = "orange";
31+
public const string DEEP_ORANGE = "deep_orange";
32+
public const string AMBER = "amber";
33+
public const string BLUE_GREY = "blue_grey";
34+
public const string GREY = "grey";
35+
1836
public static string[] Colors = {
19-
"red",
20-
"pink",
21-
"purple",
22-
"deep_purple",
23-
"indigo",
24-
"blue",
25-
"light_blue",
26-
"cyan",
27-
"teal",
28-
"green",
29-
"light_green",
30-
"orange",
31-
"deep_orange",
32-
"amber",
33-
"blue_grey"};
37+
RED,
38+
PINK,
39+
PURPLE,
40+
DEEP_PURPLE,
41+
INDIGO,
42+
BLUE,
43+
LIGHT_BLUE,
44+
CYAN,
45+
TEAL,
46+
GREEN,
47+
LIGHT_GREEN,
48+
ORANGE,
49+
DEEP_ORANGE,
50+
AMBER,
51+
BLUE_GREY};
3452

3553
public static SolidColorBrush Red = GetSolidColorBrush(255, "#EF5350");
3654
public static SolidColorBrush Pink = GetSolidColorBrush(255, "#EC407A");
@@ -67,26 +85,49 @@ public static SolidColorBrush GetBrushFromColor(string signalcolor)
6785
{
6886
switch (signalcolor)
6987
{
70-
case "red": return Red;
71-
case "pink": return Pink;
72-
case "purple": return Purple;
73-
case "deep_purple": return Deep_Purple;
74-
case "indigo": return Indigo;
75-
case "blue": return Blue;
76-
case "light_blue": return Light_Blue;
77-
case "cyan": return Cyan;
78-
case "teal": return Teal;
79-
case "green": return Green;
80-
case "light_green": return Light_Green;
81-
case "orange": return Orange;
82-
case "deep_orange": return Deep_Orange;
83-
case "amber": return Amber;
84-
case "blue_grey": return Blue_Grey;
85-
case "grey": return Grey;
88+
case RED: return Red;
89+
case PINK: return Pink;
90+
case PURPLE: return Purple;
91+
case DEEP_PURPLE: return Deep_Purple;
92+
case INDIGO: return Indigo;
93+
case BLUE: return Blue;
94+
case LIGHT_BLUE: return Light_Blue;
95+
case CYAN: return Cyan;
96+
case TEAL: return Teal;
97+
case GREEN: return Green;
98+
case LIGHT_GREEN: return Light_Green;
99+
case ORANGE: return Orange;
100+
case DEEP_ORANGE: return Deep_Orange;
101+
case AMBER: return Amber;
102+
case BLUE_GREY: return Blue_Grey;
103+
case GREY: return Grey;
104+
case "system": return new SolidColorBrush((Color)App.Current.Resources["SystemAccentColor"]);
86105
default: return Default;
87106
}
88107
}
89108

109+
public static string GetColorFromBrush(SolidColorBrush brush)
110+
{
111+
Color color = brush.Color;
112+
if (color == Red.Color) { return RED; }
113+
else if (color == Pink.Color) { return PINK; }
114+
else if (color == Purple.Color) { return PURPLE; }
115+
else if (color == Deep_Purple.Color) { return DEEP_PURPLE; }
116+
else if (color == Indigo.Color) { return INDIGO; }
117+
else if (color == Blue.Color) { return BLUE; }
118+
else if (color == Light_Blue.Color) { return LIGHT_BLUE; }
119+
else if (color == Cyan.Color) { return CYAN; }
120+
else if (color == Teal.Color) { return TEAL; }
121+
else if (color == Green.Color) { return GREEN; }
122+
else if (color == Light_Green.Color) { return LIGHT_GREEN; }
123+
else if (color == Orange.Color) { return ORANGE; }
124+
else if (color == Deep_Orange.Color) { return DEEP_ORANGE; }
125+
else if (color == Amber.Color) { return AMBER; }
126+
else if (color == Blue_Grey.Color) { return BLUE_GREY; }
127+
else if (color == Grey.Color) { return GREY; }
128+
else { return GREY; }
129+
}
130+
90131
public static void AddRange<T>(this ObservableCollection<T> observableCollection, IEnumerable<T> collection)
91132
{
92133
foreach (var item in collection)
@@ -140,6 +181,11 @@ public static void DisableBackButton(EventHandler<BackRequestedEventArgs> handle
140181
SystemNavigationManager.GetForCurrentView().BackRequested -= handler;
141182
}
142183

184+
public static string GetInitials(string name)
185+
{
186+
return name.Length == 0 ? "#" : name.Substring(0, 1);
187+
}
188+
143189
public static PageStyle GetViewStyle(Size s)
144190
{
145191
if (s.Width <= 640)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using GalaSoft.MvvmLight;
2+
using Signal_Windows.Models;
3+
using Signal_Windows.Views;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.ObjectModel;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Windows.UI;
11+
using Windows.UI.Xaml.Media;
12+
using Signal_Windows.Storage;
13+
using Windows.UI.Core;
14+
15+
namespace Signal_Windows.ViewModels
16+
{
17+
public class ConversationSettingsPageViewModel : ViewModelBase
18+
{
19+
public ConversationSettingsPage View;
20+
21+
private string _Initials = string.Empty;
22+
public string Initials
23+
{
24+
get { return _Initials; }
25+
set { _Initials = value; RaisePropertyChanged(nameof(Initials)); }
26+
}
27+
28+
private SolidColorBrush _FillBrush;
29+
public SolidColorBrush FillBrush
30+
{
31+
get { return _FillBrush; }
32+
set { _FillBrush = value; RaisePropertyChanged(nameof(FillBrush)); }
33+
}
34+
35+
private SolidColorBrush _AccentColor;
36+
public SolidColorBrush AccentColor
37+
{
38+
get { return _AccentColor; }
39+
set { _AccentColor = value; RaisePropertyChanged(nameof(AccentColor)); }
40+
}
41+
42+
private string _DisplayName;
43+
public string DisplayName
44+
{
45+
get { return _DisplayName; }
46+
set { _DisplayName = value; RaisePropertyChanged(nameof(DisplayName)); }
47+
}
48+
private string oldDisplayName;
49+
50+
public ObservableCollection<SolidColorBrush> Colors { get; set; }
51+
public SignalContact Contact { get; set; }
52+
53+
public ConversationSettingsPageViewModel()
54+
{
55+
Colors = new ObservableCollection<SolidColorBrush>();
56+
foreach (var color in Utils.Colors)
57+
{
58+
Colors.Add(Utils.GetBrushFromColor(color));
59+
}
60+
Colors.Add(Utils.Grey);
61+
62+
AccentColor = new SolidColorBrush((Color)App.Current.Resources["SystemAccentColor"]);
63+
}
64+
65+
public void OnNavigatedTo()
66+
{
67+
FillBrush = Utils.GetBrushFromColor(Contact.Color);
68+
Initials = Utils.GetInitials(Contact.ThreadDisplayName);
69+
DisplayName = Contact.ThreadDisplayName;
70+
oldDisplayName = DisplayName;
71+
}
72+
73+
internal async Task OnNavigatingFrom()
74+
{
75+
if (DisplayName.Trim() != oldDisplayName.Trim())
76+
{
77+
Contact.ThreadDisplayName = DisplayName.Trim();
78+
await Task.Run(() =>
79+
{
80+
SignalDBContext.InsertOrUpdateContactLocked(Contact, App.ViewModels.MainPageInstance);
81+
});
82+
}
83+
}
84+
85+
internal void UpdateDisplayName(string newDisplayName)
86+
{
87+
DisplayName = newDisplayName.Trim();
88+
Initials = Utils.GetInitials(DisplayName);
89+
}
90+
91+
internal async Task SetContactColor(SolidColorBrush brush)
92+
{
93+
await SetContactColor(Utils.GetColorFromBrush(brush));
94+
}
95+
96+
internal async Task SetContactColor(string color)
97+
{
98+
Contact.Color = color;
99+
await Task.Run(() =>
100+
{
101+
SignalDBContext.InsertOrUpdateContactLocked(Contact, App.ViewModels.MainPageInstance);
102+
});
103+
FillBrush = Utils.GetBrushFromColor(Contact.Color);
104+
}
105+
106+
internal async Task ResetContactColor()
107+
{
108+
await SetContactColor(Utils.GetDefaultColor(DisplayName));
109+
}
110+
111+
internal void BackButton_Click(object sender, BackRequestedEventArgs e)
112+
{
113+
View.Frame.GoBack();
114+
e.Handled = true;
115+
}
116+
}
117+
}

Signal-Windows/ViewModels/ViewModelLocator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public ViewModelLocator()
3434
SimpleIoc.Default.Register<RegisterFinalizationPageViewModel>();
3535
SimpleIoc.Default.Register<LinkPageViewModel>();
3636
SimpleIoc.Default.Register<FinishRegistrationPageViewModel>();
37+
SimpleIoc.Default.Register<ConversationSettingsPageViewModel>();
3738
}
3839

3940
// <summary>
@@ -95,6 +96,11 @@ public FinishRegistrationPageViewModel FinishRegistrationPageInstance
9596
get { return ServiceLocator.Current.GetInstance<FinishRegistrationPageViewModel>(); }
9697
}
9798

99+
public ConversationSettingsPageViewModel ConversationSettingsPageInstance
100+
{
101+
get { return ServiceLocator.Current.GetInstance<ConversationSettingsPageViewModel>(); }
102+
}
103+
98104
// <summary>
99105
// The cleanup.
100106
// </summary>

0 commit comments

Comments
 (0)