Files
Chat/ChatController/ChatKlassen/Contact.cs

160 lines
5.0 KiB
C#
Raw Normal View History

2017-09-12 14:32:34 +02:00
using System;
using System.Collections.Generic;
2017-09-12 14:32:34 +02:00
using System.ComponentModel;
using System.Drawing;
2017-09-12 14:32:34 +02:00
using System.Windows.Media;
using ChatController.LoginKlassen;
using Brush = System.Windows.Media.Brush;
2017-09-12 14:32:34 +02:00
namespace ChatController.ChatKlassen
{
public class Contact : INotifyPropertyChanged
2017-09-12 14:32:34 +02:00
{
2019-04-04 13:00:10 +02:00
public string Name { get; }
2017-09-12 14:32:34 +02:00
private GroupLatestMessage _ReceivedMessage;
public GroupLatestMessage ReceivedMessage
2017-09-12 14:32:34 +02:00
{
get => _ReceivedMessage;
2017-09-12 14:32:34 +02:00
set
{
2019-04-04 13:00:10 +02:00
_ReceivedMessage = value;
OnPropertyChanged(nameof(ReceivedMessage));
2017-09-12 14:32:34 +02:00
}
}
public bool IsNewMessage { get; set; }
private Brush _Color;
2017-09-12 14:32:34 +02:00
public Brush Color
{
get => _Color;
2019-04-04 13:00:10 +02:00
2017-09-12 14:32:34 +02:00
set
{
_Color = value;
2019-04-04 13:00:10 +02:00
OnPropertyChanged(nameof(Color));
2017-09-12 14:32:34 +02:00
}
}
private bool _HasUnreadMessages;
public bool HasUnreadMessages
2017-09-12 14:32:34 +02:00
{
get => _HasUnreadMessages;
2017-09-12 14:32:34 +02:00
set
{
_HasUnreadMessages = value;
2017-09-12 14:32:34 +02:00
if (_HasUnreadMessages)
2017-09-12 14:32:34 +02:00
{
_Color = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
2017-09-12 14:32:34 +02:00
}
else
2017-09-12 14:32:34 +02:00
{
_Color = new SolidColorBrush(Colors.Gray);
2017-09-12 14:32:34 +02:00
}
OnPropertyChanged(nameof(HasUnreadMessages));
2019-04-04 13:00:10 +02:00
OnPropertyChanged(nameof(Color));
2017-09-12 14:32:34 +02:00
}
}
2019-04-04 13:00:10 +02:00
public ImageSource Image { get; }
2017-09-12 14:32:34 +02:00
public DateTime TimeStamp { get; set; }
public int GroupId { get; set; }
public int UserOid { get; set; }
public string UserIdManage { get; set; }
2017-09-12 14:32:34 +02:00
public bool IsChatMessageInputGridVisible { get; }
public Bitmap ProfilePicture { get; }
public Contact(string pName, GroupLatestMessage pLatestMessage, DateTime pTimeStamp, int pGroupId, string pUserIdManage, bool pOnlyEmployees, int pUserCount, bool isChatMessageInputGridVisible, string accentColorBrushString, Bitmap profilePicture, ImageSource image)
2017-09-12 14:32:34 +02:00
{
Name = pName;
ReceivedMessage = pLatestMessage;
TimeStamp = pTimeStamp;
GroupId = pGroupId;
UserIdManage = pUserIdManage;
HasUnreadMessages = false;
ProfilePicture = profilePicture;
IsChatMessageInputGridVisible = isChatMessageInputGridVisible;
AccentColorBrush = new BrushConverter().ConvertFromString($"#{accentColorBrushString}") as SolidColorBrush ?? new SolidColorBrush(Colors.Black);
Image = image;
}
private sealed class ContactEqualityComparer : IEqualityComparer<Contact>
{
public bool Equals(Contact x, Contact y)
2017-11-16 15:38:30 +01:00
{
if(ReferenceEquals(x, y))
{
return true;
}
if(x is null)
{
return false;
}
if(y is null)
{
return false;
}
if(x.GetType() != y.GetType())
{
return false;
}
return x.Name == y.Name &&
x.IsNewMessage == y.IsNewMessage &&
Equals(x.ProfilePicture, y.ProfilePicture) &&
x.TimeStamp.Equals(y.TimeStamp) &&
x.GroupId == y.GroupId &&
x.UserOid == y.UserOid &&
x.UserIdManage == y.UserIdManage &&
x.IsChatMessageInputGridVisible == y.IsChatMessageInputGridVisible;
2017-11-16 15:38:30 +01:00
}
public int GetHashCode(Contact obj)
2017-11-16 15:38:30 +01:00
{
unchecked
{
var hashCode = obj.Name != null ? obj.Name.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ obj.IsNewMessage.GetHashCode();
hashCode = (hashCode * 397) ^ (obj.ProfilePicture != null ? obj.ProfilePicture.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ obj.TimeStamp.GetHashCode();
hashCode = (hashCode * 397) ^ obj.GroupId;
hashCode = (hashCode * 397) ^ obj.UserOid;
hashCode = (hashCode * 397) ^ (obj.UserIdManage != null ? obj.UserIdManage.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ obj.IsChatMessageInputGridVisible.GetHashCode();
return hashCode;
}
2017-11-16 15:38:30 +01:00
}
2017-09-12 14:32:34 +02:00
}
public SolidColorBrush AccentColorBrush { get; }
2017-09-12 14:32:34 +02:00
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
2019-04-04 13:00:10 +02:00
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2017-09-12 14:32:34 +02:00
}
}
}