82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using ChatController.Annotations;
|
|
|
|
namespace ChatController.Utilities
|
|
{
|
|
public class ChatMessageFileWrapper : INotifyPropertyChanged
|
|
{
|
|
public string FileName => !string.IsNullOrWhiteSpace(OriginalFilePath) ? Path.GetFileName(OriginalFilePath) : null;
|
|
|
|
private string _OriginalFilePath;
|
|
public string OriginalFilePath
|
|
{
|
|
get => _OriginalFilePath;
|
|
set
|
|
{
|
|
_OriginalFilePath = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(FileName));
|
|
}
|
|
}
|
|
|
|
private string _ScaledFilePath;
|
|
public string ScaledFilePath
|
|
{
|
|
get => _ScaledFilePath;
|
|
set
|
|
{
|
|
_ScaledFilePath = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
private ImageSource _ChatMessageImageSource;
|
|
|
|
public ImageSource ChatMessageImageSource
|
|
{
|
|
get => _ChatMessageImageSource;
|
|
private set
|
|
{
|
|
_ChatMessageImageSource = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public ChatMessageFileWrapper(string originalFilePath, string scaledFilePath, string thumbnailUrl)
|
|
{
|
|
OriginalFilePath = originalFilePath;
|
|
ScaledFilePath = scaledFilePath;
|
|
|
|
var uri = new Uri(scaledFilePath);
|
|
|
|
if(Constants.ImageFileExtensions.Contains(Path.GetExtension(scaledFilePath).ToUpperInvariant()) && uri.IsFile)
|
|
{
|
|
var bitmap = new BitmapImage(uri);
|
|
bitmap.Freeze();
|
|
|
|
ChatMessageImageSource = bitmap;
|
|
}
|
|
else
|
|
{
|
|
Utils.DownloadDocumentThumbnail(thumbnailUrl, imageSource =>
|
|
{
|
|
ChatMessageImageSource = imageSource;
|
|
});
|
|
}
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
[NotifyPropertyChangedInvocator]
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
}
|