Commit a1cbcbee authored by Margaux Clerc's avatar Margaux Clerc

Add file tranfer message

parent 6dadd72a
......@@ -24,7 +24,6 @@ using BelledonneCommunications.Linphone.Native;
using Linphone.Model;
using System.Diagnostics;
using Windows.UI.Core;
using Windows.UI.Popups;
namespace Linphone
{
......@@ -53,7 +52,6 @@ namespace Linphone
private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
e.Handled = true;
Debug.WriteLine(e.Message);
}
private void Back_requested(object sender, BackRequestedEventArgs e)
......@@ -179,13 +177,9 @@ namespace Linphone
}
else
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(Views.Dialer), args);
}
}
// Ensure the current window is active
Window.Current.Activate();
}
......
......@@ -60,13 +60,22 @@
Margin="5"
Stretch="UniformToFill"
Visibility="Collapsed"
Tapped="Image_Tap"
x:Name="Image" />
<TextBlock
Grid.Row="2"
x:Name="Timestamp"
Style="{StaticResource TimestampStyle}"
TextAlignment="Right"/>
<TextBlock
Grid.Row="2"
x:Name="Timestamp"
Style="{StaticResource TimestampStyle}"
TextAlignment="Right"/>
<Grid.Resources>
<MenuFlyout x:Name="FlyoutMenu" x:Key="FlyoutBase">
<MenuFlyoutItem x:Name="DeleteButton" Text="Delete" x:Uid="DeleteChat" Click="Delete_Click"/>
</MenuFlyout>
</Grid.Resources>
<FlyoutBase.AttachedFlyout>
<StaticResource ResourceKey="FlyoutBase"/>
</FlyoutBase.AttachedFlyout>
</Grid>
</UserControl>
\ No newline at end of file
......@@ -20,12 +20,16 @@ using BelledonneCommunications.Linphone.Native;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Input;
namespace Linphone.Controls
{
public partial class IncomingChatBubble : UserControl
{
public delegate void ImageTappedEventHandler(object sender, String appData);
public event ImageTappedEventHandler ImageTapped;
private ChatMessage _message;
public ChatMessage ChatMessage
......@@ -46,6 +50,7 @@ namespace Linphone.Controls
ChatMessage = message;
Timestamp.Text = HumanFriendlyTimeStamp;
this.Holding += Bubble_Holding;
string fileName = message.FileTransferName;
string filePath = message.AppData;
bool isImageMessage = fileName != null && fileName.Length > 0;
......@@ -57,10 +62,10 @@ namespace Linphone.Controls
{
// Image already downloaded
Image.Visibility = Visibility.Visible;
// Save.Visibility = Visibility.Visible;
// Save.Visibility = Visibility.Visible;
BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
Image.Source = image;
SetImage(filePath);
}
else
{
......@@ -76,14 +81,26 @@ namespace Linphone.Controls
}
}
private async void SetImage(string name)
{
BitmapImage image = await Utils.ReadImageFromTempStorage(name);
Image.Source = image;
}
private void Delete_Click(object sender, RoutedEventArgs e)
{
if (MessageDeleted != null)
{
// MessageDeleted(this, ChatMessage);
MessageDeleted(this, ChatMessage);
}
}
private void Bubble_Holding(object sender, HoldingRoutedEventArgs e)
{
FrameworkElement senderElement = sender as FrameworkElement;
FlyoutMenu.ShowAt(senderElement);
}
private void Copy_Click(object sender, RoutedEventArgs e)
{
// Clipboard.SetText(ChatMessage.Text);
......@@ -91,8 +108,8 @@ namespace Linphone.Controls
private void Save_Click(object sender, RoutedEventArgs e)
{
//bool result = Utils.SavePictureInMediaLibrary(ChatMessage.AppData);
// MessageBox.Show(result ? AppResources.FileSavingSuccess : AppResources.FileSavingFailure, AppResources.FileSaving, MessageBoxButton.OK);
// bool result = await Utils.SavePictureInMediaLibrary(ChatMessage.AppData);
// MessageBox.Show(result ? AppResources.FileSavingSuccess : AppResources.FileSavingFailure, AppResources.FileSaving, MessageBoxButton.OK);
}
/// <summary>
......@@ -147,28 +164,28 @@ namespace Linphone.Controls
/// <summary>
/// Displays the image in the bubble
/// </summary>
public void RefreshImage()
public async void RefreshImage()
{
//string filePath = ChatMessage.AppData;
/* ProgressBar.Visibility = Visibility.Collapsed;
string filePath = ChatMessage.AppData;
ProgressBar.Visibility = Visibility.Collapsed;
if (filePath != null && filePath.Length > 0)
{
Download.Visibility = Visibility.Collapsed;
Image.Visibility = Visibility.Visible;
// Save.Visibility = Visibility.Visible;
BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
BitmapImage image = await Utils.ReadImageFromTempStorage(filePath);
Image.Source = image;
}
else
{
Download.Visibility = Visibility.Visible;
}*/
}
}
/* private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
private void Image_Tap(object sender, TappedRoutedEventArgs e)
{
BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/FullScreenPicture.xaml?uri=" + ChatMessage.AppData, UriKind.RelativeOrAbsolute));
}*/
ImageTapped(this, ChatMessage.AppData);
}
}
}
......@@ -54,12 +54,19 @@
</StackPanel>
<Path
x:Name="Path"
Grid.Row="2"
Data="m 0,0 l 8,0 l 0,16 l -16,-16"
Fill="{ThemeResource SystemControlBackgroundAccentBrush}"
Margin="0,-1,10,0"
HorizontalAlignment="Right"/>
x:Name="Path"
Grid.Row="2"
Data="m 0,0 l 8,0 l 0,16 l -16,-16"
Fill="{ThemeResource SystemControlBackgroundAccentBrush}"
Margin="0,-1,10,0"
HorizontalAlignment="Right"/>
<Grid.Resources>
<MenuFlyout x:Name="FlyoutMenu" x:Key="FlyoutBase">
<MenuFlyoutItem x:Name="DeleteButton" Text="Delete" x:Uid="DeleteChat" Click="Delete_Click"/>
</MenuFlyout>
</Grid.Resources>
<FlyoutBase.AttachedFlyout>
<StaticResource ResourceKey="FlyoutBase"/>
</FlyoutBase.AttachedFlyout>
</Grid>
</UserControl>
\ No newline at end of file
......@@ -19,6 +19,7 @@ using BelledonneCommunications.Linphone.Native;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace Linphone.Controls
{
......@@ -43,28 +44,33 @@ namespace Linphone.Controls
InitializeComponent();
ChatMessage = message;
this.Holding += Bubble_Holding;
string filePath = message.AppData;
bool isImageMessage = filePath != null && filePath.Length > 0;
if (isImageMessage)
{
// Message.Visibility = Visibility.Collapsed;
// Copy.Visibility = Visibility.Collapsed;
// Image.Visibility = Visibility.Visible;
// Save.Visibility = Visibility.Visible;
BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
//Image.Source = image;
Message.Visibility = Visibility.Collapsed;
//Copy.Visibility = Visibility.Collapsed;
Image.Visibility = Visibility.Visible;
//Save.Visibility = Visibility.Visible;
SetImage(filePath);
}
else
{
Message.Visibility = Visibility.Visible;
Message.Blocks.Add(Utils.FormatText(message.Text));
//Image.Visibility = Visibility.Collapsed;
Image.Visibility = Visibility.Collapsed;
}
Timestamp.Text = HumanFriendlyTimeStamp;
}
private async void SetImage(string name)
{
BitmapImage image = await Utils.ReadImageFromTempStorage(name);
Image.Source = image;
}
public string HumanFriendlyTimeStamp
{
get
......@@ -88,11 +94,17 @@ namespace Linphone.Controls
}
}
private void Bubble_Holding(object sender, HoldingRoutedEventArgs e)
{
FrameworkElement senderElement = sender as FrameworkElement;
FlyoutMenu.ShowAt(senderElement);
}
private void Delete_Click(object sender, RoutedEventArgs e)
{
if (MessageDeleted != null)
{
//MessageDeleted(this, ChatMessage);
MessageDeleted(this, ChatMessage);
}
}
......
......@@ -15,10 +15,11 @@
</Grid.ColumnDefinitions>
<Image
Grid.Row="1"
Grid.Column="1"
x:Name="Image"
Stretch="Uniform"
Margin="10"
MaxHeight="100"
Visibility="Collapsed">
</Image>
......@@ -27,7 +28,6 @@
BorderThickness="0"
Style="{StaticResource ButtonStyle}"
Click="SendFile_Click"
Visibility="Collapsed"
Background="Transparent">
<Button.ContentTemplate>
<DataTemplate>
......
......@@ -13,7 +13,6 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using Linphone.Model;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
......@@ -54,7 +53,7 @@ namespace Linphone.Controls
private void Message_TextChanged(object sender, TextChangedEventArgs e)
{
Text = Message.Text;
SendMessage.IsEnabled = Text.Length > 0 ? true : false;
SendMessage.IsEnabled = (Text.Length > 0 ? true : false || Image.Visibility == Visibility.Visible);
if (TextChanged != null)
{
TextChanged(this, Message.Text);
......@@ -63,10 +62,11 @@ namespace Linphone.Controls
public void SetImage(BitmapImage image)
{
// Image.SourceProperty = image;
// Image.Visibility = Visibility.Visible;
// Message.Visibility = Visibility.Collapsed;
// Message.Text = "";
Image.Source = image;
Image.Visibility = Visibility.Visible;
Message.Visibility = Visibility.Collapsed;
Message.Text = "";
SendMessage.IsEnabled = true;
}
private void Delete_Click(object sender, RoutedEventArgs e)
......
......@@ -19,6 +19,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Windows.ApplicationModel.Resources;
using Windows.UI.Xaml;
namespace Linphone.Model
{
......@@ -45,9 +46,9 @@ namespace Linphone.Model
get
{
string lastText = Messages.Last().Text;
if (lastText == null || lastText.Length <= 0)
if (lastText == null || lastText.Length <= 0 || Messages.Last().AppData != "")
{
return ResourceLoader.GetForCurrentView().GetString("ImageMessageReceived");
return null;
}
return lastText;
}
......@@ -75,6 +76,21 @@ namespace Linphone.Model
}
}
public Visibility IsLastMessageImage
{
get
{
if (Messages.Last().FileTransferFilepath != "" || Messages.Last().AppData != "")
{
return Visibility.Visible;
} else
{
return Visibility.Collapsed;
}
}
}
/// <summary>
/// List of messages sent and received.
/// </summary>
......
......@@ -16,8 +16,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
using BelledonneCommunications.Linphone.Native;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Media;
......@@ -85,22 +88,19 @@ namespace Linphone.Model
/// </summary>
/// <param name="fileName">File's name in the isolated storage</param>
/// <returns>true if the operation succeeds</returns>
public static bool SavePictureInMediaLibrary(string fileName)
public static async System.Threading.Tasks.Task<bool> SavePictureInMediaLibrary(string fileName)
{
// MediaLibrary library = new MediaLibrary();
byte[] data;
FolderPicker picker = new FolderPicker();
try
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
picker.FileTypeFilter.Add("*");
StorageFolder folder = await picker.PickSingleFolderAsync();
if(folder != null)
{
using (IsolatedStorageFileStream file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read))
{
data = new byte[file.Length];
file.Read(data, 0, data.Length);
}
}
// library.SavePicture(fileName, data);
var tempFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await tempFolder.GetFileAsync(fileName);
await file.CopyAsync(folder);
}
return true;
}
catch { }
......@@ -162,7 +162,7 @@ namespace Linphone.Model
/// <param name="image">The bitmap image to save</param>
/// <param name="fileName">The file's name to use</param>
/// <returns>true if the operation succeeds</returns>
public static string SaveImageInLocalFolder(BitmapImage image, string fileName)
public static string SaveImageInIsolatedFolder(BitmapImage image, string fileName)
{
try
{
......@@ -180,8 +180,8 @@ namespace Linphone.Model
using (IsolatedStorageFileStream file = store.CreateFile(filePath))
{
WriteableBitmap bitmap = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
/* Extensions.SaveJpeg(bitmap, file, bitmap.PixelWidth, bitmap.PixelHeight, 0, LOCAL_IMAGES_QUALITY);
/* WriteableBitmap bitmap = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
bitmap.Save(bitmap, file, bitmap.PixelWidth, bitmap.PixelHeight, 0, LOCAL_IMAGES_QUALITY);
file.Flush();
string hash = GetRandomHash();
file.Close();
......@@ -192,7 +192,7 @@ namespace Linphone.Model
fileName = newFile.Name;
newFile.Close();*/
// return fileName;
return "";
//return "";
}
}
}
......@@ -200,13 +200,57 @@ namespace Linphone.Model
return null;
}
public static async System.Threading.Tasks.Task<string> SaveImageInLocalFolder(StorageFile image)
{
try
{
var tempFolder = ApplicationData.Current.LocalFolder;
StorageFile tempFile = await image.CopyAsync(tempFolder, GetFileName());
return tempFile.Name;
} catch (Exception e)
{
Debug.WriteLine(e);
return null;
}
}
public static async System.Threading.Tasks.Task<string> GetImageTempFileName()
{
var tempFolder = ApplicationData.Current.LocalFolder;
String fileName = GetFileName() + ".jpg";
var tempFile = await tempFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);
return tempFile.Name;
}
public static async System.Threading.Tasks.Task<BitmapImage> ReadImageFromTempStorage(String name)
{
var tempFolder = ApplicationData.Current.LocalFolder;
try
{
var tempFile = await tempFolder.GetFileAsync(name);
Windows.Storage.Streams.IRandomAccessStream fileStream = await tempFile.OpenAsync(FileAccessMode.Read);
try
{
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);
return bitmapImage;
}
catch (Exception e)
{
}
} catch (Exception e)
{
}
return null;
}
public static string GetImageRandomFileName()
{
try
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
string hash = GetRandomHash();
string hash = GetFileName();
string filePath = Path.Combine(LOCAL_IMAGES_PATH, hash + ".jpg");
if (!store.DirectoryExists(LOCAL_IMAGES_PATH))
{
......@@ -221,15 +265,12 @@ namespace Linphone.Model
return null;
}
private static string GetRandomHash()
private static string GetFileName()
{
byte[] bytes = new byte[1024];
/* RNGCryptoServiceProvider cryptProv = new RNGCryptoServiceProvider();
cryptProv.GetBytes(bytes);
SHA1Managed s = new SHA1Managed();*/
// byte[] hashBytes = s.ComputeHash(bytes);
// return BitConverter.ToString(hashBytes).Replace("-", "");
return "";
long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
ticks /= 10000000; //Convert windows ticks to seconds
String timestamp = ticks.ToString();
return timestamp;
}
public static string ReplacePlusInUri(string uri)
......
......@@ -33,6 +33,8 @@
<Capability Name="internetClient" />
<uap:Capability Name="contacts" />
<uap:Capability Name="voipCall" />
<uap:Capability Name="picturesLibrary" />
<uap:Capability Name="removableStorage" />
<DeviceCapability Name="microphone" />
<DeviceCapability Name="webcam" />
</Capabilities>
......
......@@ -742,4 +742,7 @@ To enjoy the best experience with Linphone WP8, we recommend that you use the SI
<data name="EmptyContactsList.Text" xml:space="preserve">
<value>No contact in your address book</value>
</data>
<data name="DeleteChat.Text" xml:space="preserve">
<value>Delete</value>
</data>
</root>
\ No newline at end of file
......@@ -63,9 +63,10 @@
<ScrollViewer x:Name="MessagesScroll">
<StackPanel
x:Name="MessagesList"
Orientation="Vertical"
VerticalAlignment="Bottom"/>
x:Name="MessagesList"
Orientation="Vertical"
VerticalAlignment="Bottom">
</StackPanel>
</ScrollViewer>
<TextBlock x:Name="RemoteComposing" Grid.Row="1" Visibility="Collapsed"/>
......@@ -92,6 +93,7 @@
</Grid>
<CommandBar Grid.Row="4" VerticalAlignment="Bottom">
<AppBarButton Icon="Phone" Label="Call" x:Uid="Call" Click="Call_Click"/>
<AppBarButton Visibility="Collapsed" x:Name="CancelUpload" Icon="Cancel" Label="Cancel" x:Uid="Cancel" Click="Cancel_Upload"/>
</CommandBar>
</Grid>
......
This diff is collapsed.
......@@ -57,6 +57,11 @@
VerticalAlignment="Bottom"
Text="{Binding LatestMessageDate}"
Style="{StaticResource DateStyle}"/>
<FontIcon Grid.Row="1"
FontFamily="Segoe MDL2 Assets"
Glyph="&#xE723;"
HorizontalAlignment="Left"
Visibility="{Binding IsLastMessageImage}"/>
<TextBlock Grid.Row="1" Text="{Binding LatestMessage}"
HorizontalAlignment="Left"
Style="{StaticResource ListItemStyle}"
......
......@@ -20,8 +20,6 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
......
<Page
x:Class="Linphone.Views.FullScreenPicture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Margin="12,0,12,0">
<Image
x:Name="Image"
Stretch="Uniform" />
</Grid>
<CommandBar Grid.Row="1" VerticalAlignment="Bottom">
<AppBarButton Icon="Save" Label="Save" x:Uid="SaveSettings" Click="Save_Click"/>
</CommandBar>
</Grid>
</Page>
\ No newline at end of file
/*
FullScreenPicture.xaml.cs
Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using Linphone.Model;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Controls;
namespace Linphone.Views
{
/// <summary>
/// Displays on full screen received or sent pictures
/// </summary>
public partial class FullScreenPicture : Page
{
private String _fileName;
public FullScreenPicture()
{
InitializeComponent();
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter is String)
{
_fileName = (e.Parameter as String);
BitmapImage image = await Utils.ReadImageFromTempStorage(_fileName);
if (image != null)
{
Image.Source = image;
}
else
{
//TODO ?
}
}
}
private async void Save_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
bool result = await Utils.SavePictureInMediaLibrary(_fileName);
//MessageBox.Show(result ? AppResources.FileSavingSuccess : AppResources.FileSavingFailure, AppResources.FileSaving, MessageBoxButton.OK); bool result = Utils.SavePictureInMediaLibrary(_fileName);
}
}
}
\ No newline at end of file
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