Commit eafec331 authored by Sylvain Berfini's avatar Sylvain Berfini

Display selected image before sending it

parent fac3e176
......@@ -21,6 +21,11 @@ namespace Linphone.Controls
/// </summary>
public string Text { get; set; }
/// <summary>
/// Sets the filename associated with the image to send
/// </summary>
public string ImageName { get; set; }
/// <summary>
/// Public constructor.
/// </summary>
......@@ -35,6 +40,7 @@ namespace Linphone.Controls
public void Reset()
{
Message.Text = "";
ImageName = null;
Message.Visibility = Visibility.Visible;
Image.Visibility = Visibility.Collapsed;
}
......
......@@ -187,6 +187,7 @@
<ItemGroup>
<Content Include="Assets\AppBar\appbar.connection.bluetooth.png" />
<Content Include="Assets\AppBar\appbar.message.send.png" />
<Content Include="Assets\AppBar\appbar.paperclip.png" />
<Content Include="Assets\AppBar\chat.png" />
<Content Include="Assets\AppBar\clear.png" />
<Content Include="Assets\AppBar\empty.png" />
......
......@@ -116,8 +116,6 @@ namespace Linphone.Views
displayedSipAddress = displayedSipAddress.Split( new string[] { "@" }, StringSplitOptions.RemoveEmptyEntries)[0];
}
EnableAppBarSendMessageButton(false);
ContactName.Text = displayedSipAddress;
cm.FindContact(sipAddress);
......@@ -276,25 +274,40 @@ namespace Linphone.Views
return response;
}
private void SendImageMessage(string localFileName, string url, BitmapImage image)
private async void SendImageMessage(string localFileName, BitmapImage image)
{
if (url == null || url.Length == 0)
try
{
return;
}
ProgressPopup.Visibility = Visibility.Visible;
MessageBox.Visibility = Visibility.Collapsed;
AddCancelUploadButtonInAppBar();
if (chatRoom != null)
{
LinphoneChatMessage chatMessage = chatRoom.CreateLinphoneChatMessage("");
chatMessage.SetExternalBodyUrl(url);
long time = chatMessage.GetTime();
chatRoom.SendMessage(chatMessage, this);
string url = await UploadImageMessage(image, localFileName);
if (url == null || url.Length == 0)
{
return;
}
DateTime date = new DateTime(chatMessage.GetTime() * TimeSpan.TicksPerSecond).AddYears(1969);
OutgoingChatBubble bubble = new OutgoingChatBubble(chatMessage, image, FormatDate(date));
bubble.MessageDeleted += bubble_MessageDeleted;
MessagesList.Children.Add(bubble);
scrollToBottom();
if (chatRoom != null)
{
LinphoneChatMessage chatMessage = chatRoom.CreateLinphoneChatMessage("");
chatMessage.SetExternalBodyUrl(url);
long time = chatMessage.GetTime();
chatRoom.SendMessage(chatMessage, this);
DateTime date = new DateTime(chatMessage.GetTime() * TimeSpan.TicksPerSecond).AddYears(1969);
OutgoingChatBubble bubble = new OutgoingChatBubble(chatMessage, image, FormatDate(date));
bubble.MessageDeleted += bubble_MessageDeleted;
MessagesList.Children.Add(bubble);
scrollToBottom();
}
}
catch { }
finally
{
ProgressPopup.Visibility = Visibility.Collapsed;
MessageBox.Visibility = Visibility.Visible;
AddSendButtonsToAppBar();
}
}
......@@ -382,6 +395,10 @@ namespace Linphone.Views
{
SendMessage(MessageBox.Text);
}
else if (MessageBox.ImageName != null)
{
SendImageMessage(MessageBox.ImageName, (BitmapImage)MessageBox.Image.Source);
}
MessageBox.Reset();
}
else
......@@ -399,7 +416,7 @@ namespace Linphone.Views
task.Show();
}
private async void task_Completed(object sender, PhotoResult e)
private void task_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
......@@ -428,25 +445,10 @@ namespace Linphone.Views
bm.SaveJpeg(ms, w, h, 0, 100);
image.SetSource(ms);
}
try
{
ProgressPopup.Visibility = Visibility.Visible;
MessageBox.Visibility = Visibility.Collapsed;
AddCancelUploadButtonInAppBar();
string url = await UploadImageMessage(image, e.OriginalFileName);
string fileName = e.OriginalFileName.Substring(e.OriginalFileName.LastIndexOf("\\") + 1);
SendImageMessage(fileName, url, image);
}
catch { }
finally
{
ProgressPopup.Visibility = Visibility.Collapsed;
MessageBox.Visibility = Visibility.Visible;
AddSendButtonsToAppBar();
}
MessageBox.SetImage(image);
string fileName = e.OriginalFileName.Substring(e.OriginalFileName.LastIndexOf("\\") + 1);
MessageBox.ImageName = fileName;
EnableAppBarSendMessageButton(true);
}
}
......@@ -502,9 +504,9 @@ namespace Linphone.Views
appBarSend.Text = AppResources.SendMessage;
ApplicationBar.Buttons.Add(appBarSend);
appBarSend.Click += send_Click_1;
appBarSend.IsEnabled = MessageBox.Text != null && MessageBox.Text.Length > 0;
appBarSend.IsEnabled = ((MessageBox.Text != null && MessageBox.Text.Length > 0) || (MessageBox.ImageName != null && MessageBox.ImageName.Length > 0));
ApplicationBarIconButton appBarSendImage = new ApplicationBarIconButton(new Uri("/Assets/AppBar/feature.camera.png", UriKind.Relative));
ApplicationBarIconButton appBarSendImage = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.paperclip.png", UriKind.Relative));
appBarSendImage.Text = AppResources.SendPicture;
ApplicationBar.Buttons.Add(appBarSendImage);
appBarSendImage.Click += attach_image_Click_1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment