コード例 #1
0
ファイル: BackgroundService.cs プロジェクト: Bla-Chat/Android
        private async Task <int> HandleEvent(DataBaseWrapper db, AsyncNetwork network, User user, Event e)
        {
            if (e.type != "onMessage")
            {
                return(0);
            }
            var chat = db.Get <Chat> (e.msg);

            if (chat == null)
            {
                while (!await network.UpdateChats(db, user))
                {
                    await network.Authenticate(db, user);
                }
                chat = db.Get <Chat> (e.msg);
            }
            chat.time = e.time;
            db.Update(chat);

            var msg = new Message();

            msg.conversation = chat.conversation;
            msg.author       = e.author;
            msg.nick         = e.nick;
            msg.text         = e.text;
            msg.time         = e.time;
            db.InsertIfNotContains <Message> (msg);

            ResetUpdateInterval();
            if (e.msg != ActiveConversation && user.user != e.nick)
            {
                chat.Marked = true;
                db.Update(chat);
                if (chat.Notifications)
                {
                    await Notify(network, e.nick, e.text);
                }
            }
            if (ChatActivity != null)
            {
                ChatActivity.OnUpdateRequested();
            }
            else if (MainActivity != null)
            {
                MainActivity.OnUpdateRequested();
            }
            return(0);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: BackgroundService.cs プロジェクト: Bla-Chat/Android
        public async Task <int> CancelNotify(string conversation)
        {
            var chat = db.Get <Chat> (conversation);

            chat.Marked = false;
            db.Update(chat);
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;
            const int notificationId = 0;

            notificationManager.Cancel(notificationId);
            return(notificationId);
        }
コード例 #4
0
        public Task <bool> UpdateContacts(DataBaseWrapper db, User user)
        {
            string request = String.Format("\"getContacts\":{{}}");

            return(CommonNetworkOperations(db, request, user, "onGetContacts", x => {
                JsonArray arr = (JsonArray)x;
                foreach (JsonValue v in arr)
                {
                    var contact = db.Get <Contact> (v ["nick"]);
                    if (contact == null)
                    {
                        contact = new Contact()
                        {
                            nick = v ["nick"]
                        };
                        db.Insert(contact);
                    }
                    contact.name = v ["name"];
                    contact.status = v ["status"];
                    db.Update(contact);
                }
            }));
        }
コード例 #5
0
        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);
                }
            }));
        }
コード例 #6
0
ファイル: ShareActivity.cs プロジェクト: Bla-Chat/Android
        private void ShowChats(User user)
        {
            TextView placeholder = FindViewById <TextView> (Resource.Id.placeholder);
            var      x           = db.Table <Chat> ();

            if (x.Count() > 0)
            {
                placeholder.Visibility = ViewStates.Gone;
            }
            else
            {
                placeholder.Visibility = ViewStates.Visible;
                placeholder.Text       = "No chats found.";
            }
            LinearLayout chatList = FindViewById <LinearLayout> (Resource.Id.chatList);

            chatList.RemoveAllViews();
            foreach (var elem in x.OrderByDescending(e => e.time))
            {
                View v;
                if (setting.FontSize == Setting.Size.large)
                {
                    v = LayoutInflater.Inflate(Resource.Layout.ChatLarge, null);
                }
                else
                {
                    v = LayoutInflater.Inflate(Resource.Layout.Chat, null);
                }
                TextView  name    = v.FindViewById <TextView>(Resource.Id.chatName);
                TextView  message = v.FindViewById <TextView>(Resource.Id.chatMessage);
                TextView  time    = v.FindViewById <TextView>(Resource.Id.chatTime);
                ImageView image   = v.FindViewById <ImageView> (Resource.Id.chatImage);

                new Thread(async() => {
                    try {
                        string conv = elem.conversation;
                        if (conv.Split(',').Length == 2)
                        {
                            if (conv.Split(',')[0] == user.user)
                            {
                                conv = conv.Split(',')[1];
                            }
                            else
                            {
                                conv = conv.Split(',')[0];
                            }
                        }
                        var imageBitmap = await network.GetImageBitmapFromUrl(Resources.GetString(Resource.String.profileUrl) + conv + ".png", AsyncNetwork.MINI_PROFILE_SIZE, AsyncNetwork.MINI_PROFILE_SIZE);
                        RunOnUiThread(() => image.SetImageBitmap(imageBitmap));
                    } catch (Exception e) {
                        Log.Error("BlaChat", e.StackTrace);
                    }
                }).Start();

                name.Text = elem.name;
                var tmp     = db.Table <Message> ().Where(q => q.conversation == elem.conversation).OrderByDescending(q => q.time);
                var lastMsg = tmp.FirstOrDefault();
                if (lastMsg != null)
                {
                    var escape = lastMsg.text.Replace("&quot;", "\"");
                    escape = escape.Replace("&lt;", "<");
                    escape = escape.Replace("&gt;", ">");
                    escape = escape.Replace("&amp;", "&");
                    if (lastMsg.nick == user.user)
                    {
                        message.Text = "Du: " + escape;
                    }
                    else
                    {
                        if (elem.conversation.Split(',').Length == 2 && lastMsg.nick != "watchdog")
                        {
                            message.Text = escape;
                        }
                        else
                        {
                            message.Text = lastMsg.author + ": " + escape;
                        }
                    }
                    time.Text = TimeConverter.AutoConvert(lastMsg.time);
                }
                else
                {
                    time.Text    = "";
                    message.Text = "No message";
                }

                v.Clickable = true;
                v.Click    += delegate {
                    Finish();
                    var intent = new Intent(this, typeof(ChatActivity));
                    intent.PutExtra("conversation", elem.conversation);
                    StartActivity(intent);
                    var chat = db.Get <Chat> (elem.conversation);
                    new Thread(async() => {
                        if (textShare != null)
                        {
                            while (!await network.SendMessage(db, user, chat, "(Shared Text) " + textShare))
                            {
                                await network.Authenticate(db, user);
                            }
                        }
                        foreach (var file in fileset)
                        {
                            Bitmap img = MediaStore.Images.Media.GetBitmap(ContentResolver, file);
                            while (!await network.SendImage(db, user, chat, img))
                            {
                                await network.Authenticate(db, user);
                            }
                        }
                    }).Start();
                };
                chatList.AddView(v);
            }
            chatList.Post(() => chatList.RequestLayout());
        }
コード例 #7
0
        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 = SmileyTools.GetSmiledTextUTF(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();
            };
            Button smiley = FindViewById <Button>(Resource.Id.smile);

            smiley.Click += delegate {
                // TODO implement smiley stuff...
            };
        }