Skip to content

Commit

Permalink
Final view model transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Aug 5, 2019
1 parent c3f7ea0 commit 456911d
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 161 deletions.
1 change: 1 addition & 0 deletions Chat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<DependentUpon>Shell.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\AboutViewModel.cs" />
<Compile Include="ViewModels\ComposeViewModel.cs" />
<Compile Include="ViewModels\ConversationViewModel.cs" />
<Compile Include="ViewModels\ShellViewModel.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="LumiaWOA.Chat"
Publisher="CN=LumiaWOA"
Version="0.0.42.0" />
Version="0.0.43.0" />

<mp:PhoneIdentity PhoneProductId="d8719107-e9ed-450f-be3e-88003464d950" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
120 changes: 61 additions & 59 deletions Pages/ComposePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="CellularLineComboBox" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,4,0,8" SelectionChanged="CellularLineComboBox_SelectionChanged" Style="{ThemeResource FluentComboBoxStyle}" SelectedIndex="0" BorderBrush="Transparent" Background="Transparent" PlaceholderText="No cellular device" BorderThickness="0"/>
<ComboBox x:Name="CellularLineComboBox" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,4,0,8" SelectionChanged="CellularLineComboBox_SelectionChanged" Style="{ThemeResource FluentComboBoxStyle}" ItemsSource="{x:Bind ViewModel.CellularLines, Mode=OneWay}" SelectedIndex="0" BorderBrush="Transparent" Background="Transparent" PlaceholderText="No cellular device" BorderThickness="0"/>
<Grid Grid.Row="1" VerticalAlignment="Center" Margin="0,0,16,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand All @@ -415,63 +415,65 @@
</Grid>

<!-- Compose panel -->
<toolkit:DropShadowPanel Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="12" ShadowOpacity="0.7" Height="48">
<Grid Grid.Row="2" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" CornerRadius="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button x:Name="AttachmentButton" Grid.Column="1" Height="48" Width="48" VerticalAlignment="Bottom" FontFamily="Segoe MDL2 Assets" Content="&#xE723;" BorderBrush="Transparent" BorderThickness="0" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" Style="{ThemeResource FluentDialogButtonBackStyle}" Click="AttachmentButton_Click">
<FlyoutBase.AttachedFlyout>
<MenuFlyout Placement="Top">
<!-- Camera -->
<MenuFlyoutItem Text="Camera">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE114;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Photo / Video -->
<MenuFlyoutItem Text="Photo or video">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xEB9F;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Location -->
<MenuFlyoutItem Text="Location">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE139;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Contact -->
<MenuFlyoutItem Text="Contact">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE13D;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Voice -->
<MenuFlyoutItem Text="Voice message">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE1D6;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Ringtone -->
<MenuFlyoutItem Text="Ringtone">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8D6;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
</Button>
<TextBox x:Name="ComposeTextBox" MaxHeight="200" Grid.Column="0" PlaceholderText="Type a message" AcceptsReturn="True" BorderThickness="0" Padding="14" BorderBrush="Transparent" Style="{ThemeResource TextBoxNoBackground}" TextChanged="ComposeTextBox_TextChanged"/>
<Button x:Name="SendButton" Grid.Column="2" Height="38" Width="38" Foreground="{ThemeResource SystemControlForegroundAccentBrush}" Style="{ThemeResource FluentDialogButtonBackStyle}" VerticalAlignment="Center" Margin="0,0,4,0" Click="SendButton_Click" FontFamily="Segoe MDL2 Assets" Content="&#xE724;" BorderBrush="Transparent" BorderThickness="0" Windows10version1809:CornerRadius="45" IsEnabled="False"/>
</Grid>
</toolkit:DropShadowPanel>
<Grid Grid.Row="2" VerticalAlignment="Bottom" Background="{ThemeResource SystemControlAcrylicElementBrush}">
<toolkit:DropShadowPanel HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="12" ShadowOpacity="0.7">
<Grid Grid.Row="2" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" CornerRadius="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button x:Name="AttachmentButton" Grid.Column="1" Height="48" Width="48" VerticalAlignment="Bottom" FontFamily="Segoe MDL2 Assets" Content="&#xE723;" BorderBrush="Transparent" BorderThickness="0" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" Style="{ThemeResource FluentDialogButtonBackStyle}" Command="{x:Bind ShowAttachments}">
<FlyoutBase.AttachedFlyout>
<MenuFlyout Placement="Top">
<!-- Camera -->
<MenuFlyoutItem Text="Camera">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE114;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Photo / Video -->
<MenuFlyoutItem Text="Photo or video">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xEB9F;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Location -->
<MenuFlyoutItem Text="Location">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE139;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Contact -->
<MenuFlyoutItem Text="Contact">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE13D;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Voice -->
<MenuFlyoutItem Text="Voice message">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE1D6;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<!-- Ringtone -->
<MenuFlyoutItem Text="Ringtone">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8D6;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
</Button>
<TextBox x:Name="ComposeTextBox" MaxHeight="200" Grid.Column="0" PlaceholderText="Type a message" AcceptsReturn="True" BorderThickness="0" Padding="14" BorderBrush="Transparent" Style="{ThemeResource TextBoxNoBackground}" TextChanged="ComposeTextBox_TextChanged"/>
<Button x:Name="SendButton" Grid.Column="2" Height="38" Width="38" Foreground="{ThemeResource SystemControlForegroundAccentBrush}" Style="{ThemeResource FluentDialogButtonBackStyle}" VerticalAlignment="Bottom" Margin="0,0,4,5" Command="{x:Bind SendReply}" FontFamily="Segoe MDL2 Assets" Content="&#xE724;" BorderBrush="Transparent" BorderThickness="0" Windows10version1809:CornerRadius="45" IsEnabled="False"/>
</Grid>
</toolkit:DropShadowPanel>
</Grid>
</Grid>
</Page>
90 changes: 48 additions & 42 deletions Pages/ComposePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Chat.Common;
using Chat.Controls;
using Chat.ViewModels;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Windows.ApplicationModel.Contacts;
using Windows.Devices.Enumeration;
using Windows.Devices.Sms;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -16,10 +17,11 @@ namespace Chat.Pages
{
public sealed partial class ComposePage : Page
{
public ComposeViewModel ViewModel { get; } = new ComposeViewModel();

public ComposePage()
{
this.InitializeComponent();
Load();
Loaded += ComposePage_Loaded;
}

Expand All @@ -39,27 +41,6 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
}
}

private List<CellularLineControl> cellularlineControls = new List<CellularLineControl>();

private async void Load()
{
var smsDevices = await DeviceInformation.FindAllAsync(SmsDevice2.GetDeviceSelector(), null);
foreach (var smsDevice in smsDevices)
{
try
{
SmsDevice2 dev = SmsDevice2.FromId(smsDevice.Id);
CellularLineControl control = new CellularLineControl(dev);
cellularlineControls.Add(control);
CellularLineComboBox.Items.Add(new ComboBoxItem() { Content = control });
}
catch
{

}
}
}

private async void ContactPickerBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
var store = await ContactManager.RequestStoreAsync();
Expand Down Expand Up @@ -138,30 +119,55 @@ private void ComposeTextBox_TextChanged(object sender, TextChangedEventArgs e)
}
}

private async void SendButton_Click(object sender, RoutedEventArgs e)
private ICommand _showAttachments;
public ICommand ShowAttachments
{
try
{
SendButton.IsEnabled = false;
var smsDevice = cellularlineControls[CellularLineComboBox.SelectedIndex].device;

var result = await SmsUtils.SendTextMessageAsync(smsDevice, ContactPickerBox.Text.Split(';'), ComposeTextBox.Text);
if (!result)
await new MessageDialog("We could not send one or some messages.", "Something went wrong").ShowAsync();

SendButton.IsEnabled = true;
ComposeTextBox.Text = "";
}
catch (Exception ex)
get
{
SendButton.IsEnabled = true;
await new MessageDialog(ex.Message + " - " + ex.StackTrace).ShowAsync();
if (_showAttachments == null)
{
_showAttachments = new RelayCommand(
() =>
{
FlyoutBase.ShowAttachedFlyout((FrameworkElement)AttachmentButton);
});
}
return _showAttachments;
}
}

private void AttachmentButton_Click(object sender, RoutedEventArgs e)

private ICommand _sendReply;
public ICommand SendReply
{
FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
get
{
if (_sendReply == null)
{
_sendReply = new RelayCommand(
async () =>
{
try
{
SendButton.IsEnabled = false;
var smsDevice = ViewModel.CellularLines[CellularLineComboBox.SelectedIndex].device;

var result = await SmsUtils.SendTextMessageAsync(smsDevice, ContactPickerBox.Text.Split(';'), ComposeTextBox.Text);
if (!result)
await new MessageDialog("We could not send one or some messages.", "Something went wrong").ShowAsync();

SendButton.IsEnabled = true;
ComposeTextBox.Text = "";
}
catch (Exception ex)
{
SendButton.IsEnabled = true;
await new MessageDialog(ex.Message + " - " + ex.StackTrace).ShowAsync();
}
});
}
return _sendReply;
}
}
}
}
Loading

0 comments on commit 456911d

Please sign in to comment.