Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions ChatApp/ChatApp/Common/BindableBase.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using GalaSoft.MvvmLight;

namespace ChatApp.Common
{
/// <summary>
/// Provides a standard change-notification implementation.
/// </summary>
public abstract class BindableBase : INotifyPropertyChanged
public abstract class BindableBase : ViewModelBase
{
public event PropertyChangedEventHandler PropertyChanged;

public void OnPropertyChanged([CallerMemberName] string propertyName = null) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

protected bool SetProperty<T>(ref T storage, T value,
[CallerMemberName] String propertyName = null)
{
if (object.Equals(storage, value)) return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
}
}
27 changes: 11 additions & 16 deletions ChatApp/ChatApp/ViewModels/ChatPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@

using ChatApp.Commands;
using ChatApp.Commands;
using ChatApp.Common;
using ChatApp.Facades;
using ChatApp.Models.Csharp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ChatApp.ViewModels
Expand All @@ -28,14 +22,17 @@ public class ChatPageViewModel : BindableBase
public string Text
{
get { return _text; }
set { SetProperty(ref _text, value); }
set { base.Set(ref _text, value); }
}

public ObservableCollection<Message> MessageThread
{
get { return _messageThread; }
private set { SetProperty(ref _messageThread, value); }
private set { base.Set(ref _messageThread, value); }
}

public ICommand SendMessage { get; set; }

/// <summary>
/// The chat correspondent.
/// </summary>
Expand All @@ -44,11 +41,9 @@ public Profile ChatCorrespondent
get { return _chatCorrespondent; }
set
{
if(_chatCorrespondent == null || value.User.Id != _chatCorrespondent.User.Id)
{
SetProperty(ref _chatCorrespondent, value);
MessageThread = MessageFacade.GetMessages();
}
if (_chatCorrespondent != null && value.User.Id == _chatCorrespondent.User.Id) return;
base.Set(ref _chatCorrespondent, value);
MessageThread = MessageFacade.GetMessages();
}
}

Expand All @@ -59,12 +54,12 @@ public ChatPageViewModel()
}

/// <summary>
/// Sets the message to text from the textbox.
/// Sets the message to text from the text box.
/// </summary>
/// <param name="text"></param>
internal void SetText(string text)
{
Text = text;
}
}
}
}
18 changes: 6 additions & 12 deletions ChatApp/ChatApp/ViewModels/ContactsPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using ChatApp.Common;
using ChatApp.Facades;
using ChatApp.Models.Csharp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChatApp.ViewModels
{
Expand All @@ -16,20 +11,19 @@ namespace ChatApp.ViewModels
/// </summary>
public class ContactsPageViewModel : BindableBase
{
private string error;
private readonly string error;
public static ObservableCollection<User> _allFriends;
public static ObservableCollection<RecentConversation> _recentConversations;
private ObservableCollection<Profile> _friends;

public ObservableCollection<User> AllFriends { get { return _allFriends; } }
public ObservableCollection<RecentConversation> RecentConversations { get { return _recentConversations; } }
public ObservableCollection<Profile> Friends { get { return _friends; } }
public ObservableCollection<User> AllFriends => _allFriends;
public ObservableCollection<RecentConversation> RecentConversations => _recentConversations;
public ObservableCollection<Profile> Friends { get; }

public ContactsPageViewModel()
{
_allFriends = ContactFacade.GetAllFriends(out error);
_recentConversations = ContactFacade.GetRecentConversations(out error);
_friends = ContactFacade.GetFriendProfiles();
Friends = ContactFacade.GetFriendProfiles();
}
}
}
3 changes: 2 additions & 1 deletion ChatApp/ChatApp/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.3",
"MvvmLightLibs": "5.3.0"
},
"frameworks": {
"uap10.0": {}
Expand Down