[ ] Red Architecture |
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Common
{
public enum k {OnMessageEdit, MessageEdit, MessageReply, Unused, MessageSendProgress, OnMessageSendProgress, OnIsTyping, IsTyping, MessageSend, JoinRoom, OnMessageReceived, OnlineStatus, OnUpdateUserOnlineStatus }
public class v : ObservableCollection >
{
static v i;
static v sharedInstance()
{
if (i == null)
i = new v();
return i;
}
public static void h(System.Collections.Specialized.NotifyCollectionChangedEventHandler handler)
{
i.CollectionChanged += handler;
}
public static void m(System.Collections.Specialized.NotifyCollectionChangedEventHandler handler)
{
i.CollectionChanged -= handler;
}
public static void Add(k key, object o)
{
i.OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Add,
new List>(new KeyValuePair[] { new KeyValuePair(key, o) })));
}
protected v()
{
}
}
}
void OnEvent(object sener, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var newItem = (KeyValuePair)e.NewItems[0];
if (newItem.Key == k.OnMessageSendProgress)
{
var d = (Dictionary)newItem.Value;
if ((string)d["guid"] == _guid && (ChatMessage.Status)d["status"] == ChatMessage.Status.Deleted)
{
Device.BeginInvokeOnMainThread(() =>
{
FindViewById(Resource.Id.message).Text = "";
});
}
}
else if (newItem.Key == k.OnMessageEdit)
{
var d = (Dictionary)newItem.Value;
if ((string)d["guid"] == _guid)
{
Device.BeginInvokeOnMainThread(() =>
{
FindViewById(Resource.Id.message).Text = (string)d["message"];
});
}
}
}
}
var newItem = (KeyValuePair)e.NewItems[0];
if (newItem.Key == k.OnMessageSendProgress)
Device.BeginInvokeOnMainThread(() =>
{
FindViewById(Resource.Id.message).Text = "";
});
FindViewById(Resource.Id.message).Text = "";
.
string s = Response.ResponseObject["success"].ToString();
success = Convert.ToBoolean(s);
if (success)
{
var r = Response.ResponseObject["data"].ToString();
if(r.Contains("status")) // response not empty
{
Dictionary retVal = JsonConvert.DeserializeObject>(r);
// convert status from web to internal type
retVal["status"] = (ChatMessage.Status)Enum.ToObject(typeof(ChatMessage.Status), retVal["status"]);
await PersistanceService.GetCacheMessagePersistance().UpdateItemAsync(retVal);
v.Add(k.OnMessageSendProgress, retVal);
}
}