This commit is contained in:
Paul Schneider 2016-12-12 14:30:23 +01:00
commit 61701e21e9
26 changed files with 382 additions and 210 deletions

View file

@ -136,18 +136,20 @@ namespace BookAStar.ViewModels.EstimateAndBilling
{
get
{
/*
OnPlatform<Font> lfs = (OnPlatform<Font>)App.Current.Resources["MediumFontSize"];
*/
OnPlatform<double> mfs = (OnPlatform < double > ) App.Current.Resources["MediumFontSize"];
Color etc = (Color) App.Current.Resources["EmphasisTextColor"];
return new FormattedString
{
Spans = {
new Span { Text = "Total TTC: " },
new Span { Text = Data.Total.ToString(),
ForegroundColor = etc,
FontSize = (double) lfs.Android.FontSize },
new Span { Text = "€", FontSize = (double) lfs.Android.FontSize }
FontSize = mfs },
new Span { Text = "€", FontSize = mfs }
}
};
}

View file

@ -7,7 +7,6 @@ using XLabs.Forms.Mvvm;
namespace BookAStar.ViewModels.Messaging
{
using Data;
using Model;
using Model.Social.Messaging;
class ChatViewModel: ViewModel
@ -15,19 +14,8 @@ namespace BookAStar.ViewModels.Messaging
public ObservableCollection<ChatMessage> Messages { get; set; }
public ObservableCollection<ChatMessage> Notifs { get; set; }
public ObservableCollection<ChatMessage> PVs { get; set; }
public ObservableCollection<ClientProviderInfo> Contacts { get; set; }
private string chatUser;
public string ChatUser
{
get
{
return chatUser;
}
set
{
SetProperty<string>(ref chatUser, value);
}
}
public ObservableCollection<UserViewModel> Contacts { get; set; }
private ConnectionState state;
public ConnectionState State
{
@ -41,7 +29,9 @@ namespace BookAStar.ViewModels.Messaging
Messages = new ObservableCollection<ChatMessage>();
Notifs = new ObservableCollection<ChatMessage>();
PVs = DataManager.Current.PrivateMessages;
Contacts = DataManager.Current.Contacts;
Contacts =
new ObservableCollection<UserViewModel>(
DataManager.Current.Contacts.Select(c=>new UserViewModel { Data = c }));
App.ChatHubProxy.On<string, string>("addMessage", (n, m) =>
{
Messages.Add(new ChatMessage
@ -54,45 +44,44 @@ namespace BookAStar.ViewModels.Messaging
App.ChatHubProxy.On<string, string, string>("notify", (eventId, cxId, userName) =>
{
var msg = new ChatMessage
{
Message = eventId,
SenderId = userName,
Date = DateTime.Now
};
// TODO make admin possible
// by assigning a server side username to anonymous.
// From now, don't log anonymous
if (!string.IsNullOrEmpty(userName))
if (string.IsNullOrEmpty(userName))
{
Notifs.Add(new ChatMessage
{
Message = eventId,
SenderId = userName,
Date = DateTime.Now
});
if (eventId == "connected")
OnUserConnected(cxId, userName);
else if (eventId == "disconnected")
OnUserDisconnected(userName);
msg.SenderId = $"({cxId})";
}
Notifs.Add(msg);
if (eventId == "connected")
OnUserConnected(cxId, userName);
else if (eventId == "disconnected")
OnUserDisconnected(userName);
});
ChatUser = MainSettings.UserName;
}
private void OnUserConnected(string cxId, string userName)
{
var user = Contacts.SingleOrDefault(
c => c.UserName == userName);
c => c.Data.UserName == userName);
if (user != null)
user.ChatHubConnectionId = cxId;
user.ConnexionId = cxId;
}
private void OnUserDisconnected (string userName)
{
var user = Contacts.SingleOrDefault(
c => c.UserName == userName);
c => c.Data.UserName == userName);
if (user != null)
user.ChatHubConnectionId = null;
user.ConnexionId = null;
}
private void MainSettings_UserChanged(object sender, EventArgs e)
{
ChatUser = MainSettings.UserName;
}
private void ChatHubConnection_StateChanged(StateChange obj)

View file

@ -0,0 +1,57 @@
using BookAStar.Helpers;
using BookAStar.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using XLabs.Forms.Mvvm;
namespace BookAStar.ViewModels.Messaging
{
class UserViewModel : ViewModel
{
private ClientProviderInfo data;
public ClientProviderInfo Data {
get
{
return data;
}
set
{
SetProperty(ref data, value);
NotifyPropertyChanged("Avatar");
}
}
private string connexionId;
public string ConnexionId
{
get
{
return connexionId;
}
set
{
SetProperty(ref connexionId, value);
NotifyPropertyChanged("Connected");
}
}
public bool Connected
{
get { return connexionId != null; }
}
[JsonIgnore]
public ImageSource Avatar
{
get
{
return UserHelpers.Avatar(Data.Avatar);
}
}
}
}

View file

@ -13,6 +13,7 @@ namespace BookAStar.ViewModels.UserProfile
using Helpers;
using Model.Auth.Account;
using Pages.UserProfile;
using System.Threading.Tasks;
internal class DashboardViewModel : ViewModel
{
@ -97,7 +98,6 @@ namespace BookAStar.ViewModels.UserProfile
if (user!=null)
{
user.PropertyChanged += User_PropertyChanged;
}
UpdateUserMeta();
@ -173,39 +173,53 @@ namespace BookAStar.ViewModels.UserProfile
private void UpdateUserMeta ()
{
string newStatusString;
long newQueryCount;
bool newUserIsPro;
ImageSource newAvatar;
string newQueriesButtonText;
bool newHaveAnUser = user == null;
if (newHaveAnUser) {
newQueryCount = 0;
newUserIsPro = false;
newStatusString = null;
newAvatar = null;
newQueriesButtonText = null;
}
else
{
newUserIsPro = UserIsPro;
Task.Run( ()=> {
string newStatusString;
long newQueryCount;
bool newUserIsPro;
ImageSource newAvatar;
string newQueriesButtonText;
bool newHaveAnUser = user == null;
if (newHaveAnUser)
{
newQueryCount = 0;
newUserIsPro = false;
newStatusString = null;
newAvatar = null;
newQueriesButtonText = null;
}
else
{
newUserIsPro = UserIsPro;
newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0;
newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0;
newStatusString = newUserIsPro ?
$"Profile professionel renseigné" :
"Profile professionel non renseigné";
newQueriesButtonText = newUserIsPro ?
$"{newQueryCount} demandes valides en cours" :
"Profile professionel non renseigné";
newAvatar = UserHelpers.Avatar(user.Avatar);
}
SetProperty<bool>(ref haveAnUser, newHaveAnUser, "HaveAnUser");
SetProperty<bool>(ref userIsPro, newUserIsPro, "UserIsPro");
SetProperty<string>(ref performerStatus, newStatusString, "PerformerStatus");
SetProperty<string>(ref userQueries, newQueriesButtonText, "UserQueries");
SetProperty<long>(ref queryCount, newQueryCount, "QueryCount");
SetProperty<ImageSource>(ref avatar, newAvatar, "Avatar");
newStatusString = newUserIsPro ?
$"Profile professionel renseigné" :
"Profile professionel non renseigné";
newQueriesButtonText = newUserIsPro ?
$"{newQueryCount} demandes valides en cours" :
"Profile professionel non renseigné";
newAvatar = UserHelpers.Avatar(user.Avatar);
}
SetProperty<bool>(ref haveAnUser, newHaveAnUser, "HaveAnUser");
SetProperty<bool>(ref userIsPro, newUserIsPro, "UserIsPro");
SetProperty<string>(ref performerStatus, newStatusString, "PerformerStatus");
SetProperty<string>(ref userQueries, newQueriesButtonText, "UserQueries");
SetProperty<long>(ref queryCount, newQueryCount, "QueryCount");
try
{
SetProperty<ImageSource>(ref avatar, newAvatar, "Avatar");
}
catch (TaskCanceledException)
{ }
NotifyPropertyChanged("UserName");
NotifyPropertyChanged("UserId");
NotifyPropertyChanged("HaveAnUser");
NotifyPropertyChanged("UserIsPro");
});
}
private void User_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
@ -214,6 +228,12 @@ namespace BookAStar.ViewModels.UserProfile
}
public RelayGesture UserNameGesture { get; set; }
public string UserFilesText
{
get
{
return Strings.YourFiles;
}
}
}
}