protected override void OnCreate (Bundle bundle) { db = new DataBaseWrapper (this.Resources); if ((setting = db.Table<Setting> ().FirstOrDefault ()) == null) { db.Insert(setting = new Setting ()); } StartupTheme = setting.Theme; SetTheme (setting.Theme); base.OnCreate (bundle); SetContentView (Resource.Layout.ChatActivity); conversation = Intent.GetStringExtra ("conversation"); chat = db.Get<Chat> (conversation); visibleMessages = chat.VisibleMessages; if (visibleMessages <= 0) { visibleMessages = setting.VisibleMessages; } if (visibleMessages <= 0) { visibleMessages = 30; } Title = chat.name; ActionBar.SetDisplayHomeAsUpEnabled(true); ActionBar.SetIcon (Resource.Drawable.Icon); user = db.Table<User>().FirstOrDefault (); Button send = FindViewById<Button> (Resource.Id.send); send.Click += delegate { TextView message = FindViewById<TextView> (Resource.Id.message); var msg = message.Text; message.Text = ""; if (msg.Equals("")) return; LinearLayout messageList = FindViewById<LinearLayout> (Resource.Id.messageLayout); AddMessage(messageList, new Message() {time = "sending", author = "Du", nick = user.user, text = msg, conversation = this.conversation}); ScrollView scrollView = FindViewById<ScrollView> (Resource.Id.messageScrollView); scrollView.FullScroll (FocusSearchDirection.Down); scrollView.Post (() => scrollView.FullScroll (FocusSearchDirection.Down)); OnBind(); new Thread(async () => { while(!await network.SendMessage (db, user, chat, msg)) { await network.Authenticate(db, user); } }).Start(); }; }
protected override void OnCreate (Bundle bundle) { db = new DataBaseWrapper (this.Resources); if ((setting = db.Table<Setting> ().FirstOrDefault ()) == null) { db.Insert(setting = new Setting ()); } SetTheme (setting.Theme); base.OnCreate (bundle); network = new AsyncNetwork (); db = new DataBaseWrapper (this.Resources); user = db.Table<User>().FirstOrDefault (); if (setting.FontSize == Setting.Size.large) { SetContentView (Resource.Layout.ChatSettingsLarge); } else { SetContentView (Resource.Layout.ChatSettings); } var conversation = Intent.GetStringExtra ("conversation"); chat = db.Get<Chat> (conversation); InitializeView(); }
public Task<bool> UpdateHistory(DataBaseWrapper db, User user, Chat chat, int count) { string request = String.Format ("\"getHistory\":{{\"conversation\":\"{0}\", \"count\":\"{1}\"}}", chat.conversation, count); return CommonNetworkOperations (db, request, user, "onGetHistory", arr => { var msgs = arr ["messages"]; string conversation = arr ["conversation"]; foreach (JsonValue x in msgs) { try { var msg = new Message (); msg.conversation = conversation; msg.author = x ["author"]; msg.nick = x ["nick"]; msg.text = x ["text"]; msg.time = x ["time"]; db.InsertIfNotContains<Message>(msg); } catch (Exception e) { Log.Error ("BlaChat", e.StackTrace); } } }); }
public async Task<bool> SetGroupImage(DataBaseWrapper db, User user, Chat chat, object image) { return true; }
public async Task<bool> Data(DataBaseWrapper db, User user, Chat chat, object data) { return true; }
public async Task<bool> RenameChat(DataBaseWrapper db, User user, Chat chat, string name) { return true; }
public async Task<bool> SendImage (DataBaseWrapper db, User user, Chat chat, Bitmap bitmap) { string encodedJson = escape (String.Format ("{{\"id\":\"{0}\", \"data\":{{\"conversation\":\"{1}\"}}}}", user.id, chat.conversation)); var success = false; NameValueCollection nvc = new NameValueCollection(); nvc.Add("msg", encodedJson); string tmp = null; while (tmp == null) { tmp = HttpUploadFile (user.server + "/xjcp.php", bitmap, "uploadedfile", "image/png", nvc); } var result = JsonValue.Parse (tmp); try { success = 0 == await EventHandling (db, result); if (!result.ContainsKey ("onData")) { success = false; } } catch (Exception ex) { Log.Error ("BlaChat", ex.StackTrace); } return success; }
public Task<bool> SendMessage(DataBaseWrapper db, User user, Chat chat, string message) { message = message.Replace ("\\", "\\\\"); message = message.Replace ("\"", "\\\""); string request = String.Format ("\"message\":{{\"conversation\":\"{0}\", \"message\":\"{1}\"}}", chat.conversation, message); return CommonNetworkOperations (db, request, user, "onMessage", x => { return; }); }
public Task<bool> UpdateChats(DataBaseWrapper db, User user) { string request = String.Format ("\"getChats\":{{}}"); return CommonNetworkOperations(db, request, user, "onGetChats", x => { JsonArray arr = (JsonArray)x; foreach (JsonValue v in arr) { string conv = v ["conversation"]; var chat = db.Get<Chat> (conv); if (chat == null) { chat = new Chat () { conversation = conv }; db.Insert (chat); } chat.name = v ["name"]; chat.time = v ["time"]; db.Update (chat); } }); }
protected override void OnCreate(Bundle bundle) { db = new DataBaseWrapper(this.Resources); if ((setting = db.Table <Setting> ().FirstOrDefault()) == null) { db.Insert(setting = new Setting()); } StartupTheme = setting.Theme; SetTheme(setting.Theme); base.OnCreate(bundle); SetContentView(Resource.Layout.ChatActivity); conversation = Intent.GetStringExtra("conversation"); chat = db.Get <Chat> (conversation); visibleMessages = chat.VisibleMessages; if (visibleMessages <= 0) { visibleMessages = setting.VisibleMessages; } if (visibleMessages <= 0) { visibleMessages = 30; } Title = chat.name; ActionBar.SetDisplayHomeAsUpEnabled(true); ActionBar.SetIcon(Resource.Drawable.Icon); user = db.Table <User>().FirstOrDefault(); Button send = FindViewById <Button> (Resource.Id.send); send.Click += delegate { TextView message = FindViewById <TextView> (Resource.Id.message); var msg = message.Text; message.Text = ""; if (msg.Equals("")) { return; } LinearLayout messageList = FindViewById <LinearLayout> (Resource.Id.messageLayout); AddMessage(messageList, new Message() { time = "sending", author = "Du", nick = user.user, text = msg, conversation = this.conversation }); ScrollView scrollView = FindViewById <ScrollView> (Resource.Id.messageScrollView); scrollView.FullScroll(FocusSearchDirection.Down); scrollView.Post(() => scrollView.FullScroll(FocusSearchDirection.Down)); OnBind(); new Thread(async() => { while (!await network.SendMessage(db, user, chat, msg)) { await network.Authenticate(db, user); } }).Start(); }; }