Beispiel #1
0
        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);

                if (elem.Marked)
                {
                    message.SetTextColor(Color.Green);
                }

                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");
                        RunOnUiThread(() => image.SetImageBitmap(imageBitmap));
                    } catch (Exception e) {
                        Log.Error("BlaChat", e.StackTrace);
                    }
                }).Start();

                name.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString(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 (escape.StartsWith("#image"))
                    {
                        escape = "(image)";
                    }
                    else if (escape.StartsWith("#video"))
                    {
                        escape = "(video)";
                    }
                    if (lastMsg.nick == user.user)
                    {
                        message.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString("Du: " + escape));
                    }
                    else
                    {
                        if (elem.conversation.Split(',').Length == 2 && lastMsg.nick != "watchdog")
                        {
                            message.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString(escape));
                        }
                        else
                        {
                            message.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString(lastMsg.author + ": " + escape));
                        }
                    }
                    time.Text = TimeConverter.AutoConvert(lastMsg.time);
                }
                else
                {
                    time.Text    = "";
                    message.Text = "No message";
                }

                v.Clickable = true;
                v.Click    += delegate {
                    var intent = new Intent(this, typeof(ChatActivity));
                    intent.PutExtra("conversation", elem.conversation);
                    StartActivity(intent);
                };
                chatList.AddView(v);
            }
            chatList.Post(() => chatList.RequestLayout());
        }
Beispiel #2
0
        void InitializeView()
        {
            var smallFont  = FindViewById <RadioButton> (Resource.Id.smallfont);
            var mediumFont = FindViewById <RadioButton> (Resource.Id.mediumfont);
            var largeFont  = FindViewById <RadioButton> (Resource.Id.largefont);

            smallFont.Checked  = setting.FontSize == Setting.Size.small;
            mediumFont.Checked = setting.FontSize == Setting.Size.medium;
            largeFont.Checked  = setting.FontSize == Setting.Size.large;

            largeFont.CheckedChange += delegate { if (largeFont.Checked)
                                                  {
                                                      setting.FontSize = Setting.Size.large; db.Update(setting); Refresh();
                                                  }
            };
            mediumFont.CheckedChange += delegate { if (mediumFont.Checked)
                                                   {
                                                       setting.FontSize = Setting.Size.medium; db.Update(setting); Refresh();
                                                   }
            };
            smallFont.CheckedChange += delegate { if (smallFont.Checked)
                                                  {
                                                      setting.FontSize = Setting.Size.small; db.Update(setting); Refresh();
                                                  }
            };

            var lightTheme             = FindViewById <RadioButton> (Resource.Id.lighttheme);
            var darkTheme              = FindViewById <RadioButton> (Resource.Id.darktheme);
            var materialTheme          = FindViewById <RadioButton> (Resource.Id.materialtheme);
            var materialThemeDark      = FindViewById <RadioButton> (Resource.Id.materialthemeDark);
            var materialThemeBlue      = FindViewById <RadioButton> (Resource.Id.materialthemeBlue);
            var materialThemeDarkBlue  = FindViewById <RadioButton> (Resource.Id.materialthemeDarkBlue);
            var materialThemeGreen     = FindViewById <RadioButton> (Resource.Id.materialthemeGreen);
            var materialThemeDarkGreen = FindViewById <RadioButton> (Resource.Id.materialthemeDarkGreen);

            lightTheme.Checked        = setting.Theme == Resource.Style.LightHolo;
            darkTheme.Checked         = setting.Theme == Resource.Style.DarkHolo;
            lightTheme.CheckedChange += delegate { if (lightTheme.Checked)
                                                   {
                                                       setting.Theme = Resource.Style.LightHolo; db.Update(setting);  Refresh();
                                                   }
            };
            darkTheme.CheckedChange += delegate { if (darkTheme.Checked)
                                                  {
                                                      setting.Theme = Resource.Style.DarkHolo; db.Update(setting);  Refresh();
                                                  }
            };

            if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
            {
                materialTheme.Checked        = setting.Theme == Resource.Style.LightMaterial;
                materialThemeDark.Checked    = setting.Theme == Resource.Style.DarkMaterial;
                materialTheme.CheckedChange += delegate { if (materialTheme.Checked)
                                                          {
                                                              setting.Theme = Resource.Style.LightMaterial; db.Update(setting);  Refresh();
                                                          }
                };
                materialThemeDark.CheckedChange += delegate { if (materialThemeDark.Checked)
                                                              {
                                                                  setting.Theme = Resource.Style.DarkMaterial; db.Update(setting);  Refresh();
                                                              }
                };

                materialThemeBlue.Checked        = setting.Theme == Resource.Style.LightBlueMaterial;
                materialThemeDarkBlue.Checked    = setting.Theme == Resource.Style.DarkBlueMaterial;
                materialThemeBlue.CheckedChange += delegate { if (materialThemeBlue.Checked)
                                                              {
                                                                  setting.Theme = Resource.Style.LightBlueMaterial; db.Update(setting);  Refresh();
                                                              }
                };
                materialThemeDarkBlue.CheckedChange += delegate { if (materialThemeDarkBlue.Checked)
                                                                  {
                                                                      setting.Theme = Resource.Style.DarkBlueMaterial; db.Update(setting);  Refresh();
                                                                  }
                };

                materialThemeGreen.Checked        = setting.Theme == Resource.Style.LightGreenMaterial;
                materialThemeDarkGreen.Checked    = setting.Theme == Resource.Style.DarkGreenMaterial;
                materialThemeGreen.CheckedChange += delegate { if (materialThemeGreen.Checked)
                                                               {
                                                                   setting.Theme = Resource.Style.LightGreenMaterial; db.Update(setting);  Refresh();
                                                               }
                };
                materialThemeDarkGreen.CheckedChange += delegate { if (materialThemeDarkGreen.Checked)
                                                                   {
                                                                       setting.Theme = Resource.Style.DarkGreenMaterial; db.Update(setting);  Refresh();
                                                                   }
                };
            }
            else
            {
                materialTheme.Visibility     = ViewStates.Gone;
                materialThemeDark.Visibility = ViewStates.Gone;

                materialThemeBlue.Visibility     = ViewStates.Gone;
                materialThemeDarkBlue.Visibility = ViewStates.Gone;

                materialThemeGreen.Visibility     = ViewStates.Gone;
                materialThemeDarkGreen.Visibility = ViewStates.Gone;
            }

            var readMessages = FindViewById <CheckBox> (Resource.Id.readMessages);

            readMessages.Checked        = setting.ReadMessagesEnabled;
            readMessages.CheckedChange += delegate { setting.ReadMessagesEnabled = readMessages.Checked; db.Update(setting); };
            var visibleMessages = FindViewById <EditText> (Resource.Id.visibleMessages);

            visibleMessages.Text         = setting.VisibleMessages.ToString();
            visibleMessages.TextChanged += delegate { try { setting.VisibleMessages = int.Parse(visibleMessages.Text); db.Update(setting); } catch (Exception) { setting.VisibleMessages = 0; db.Update(setting); } };

            var notifications = FindViewById <CheckBox> (Resource.Id.notifications);
            var vibrate       = FindViewById <CheckBox> (Resource.Id.vibrate);
            var sound         = FindViewById <CheckBox> (Resource.Id.sound);
            var led           = FindViewById <CheckBox> (Resource.Id.led);

            notifications.Checked = setting.Notifications;
            vibrate.Checked       = setting.Vibrate;
            sound.Checked         = setting.Sound;
            led.Checked           = setting.Led;

            notifications.CheckedChange += delegate { setting.Notifications = notifications.Checked; db.Update(setting); };
            vibrate.CheckedChange       += delegate { setting.Vibrate = vibrate.Checked; db.Update(setting); };
            sound.CheckedChange         += delegate { setting.Sound = sound.Checked; db.Update(setting); };
            led.CheckedChange           += delegate { setting.Led = led.Checked; db.Update(setting); };

            var highSync   = FindViewById <RadioButton> (Resource.Id.highsync);
            var normalSync = FindViewById <RadioButton> (Resource.Id.normalsync);
            var lowSync    = FindViewById <RadioButton> (Resource.Id.lowsync);
            var wlanSync   = FindViewById <RadioButton> (Resource.Id.wlansync);

            highSync.Checked   = setting.Synchronisation == Setting.Frequency.often;
            normalSync.Checked = setting.Synchronisation == Setting.Frequency.normal;
            lowSync.Checked    = setting.Synchronisation == Setting.Frequency.rare;
            wlanSync.Checked   = setting.Synchronisation == Setting.Frequency.wlan;

            highSync.CheckedChange += delegate { if (highSync.Checked)
                                                 {
                                                     setting.Synchronisation = Setting.Frequency.often; db.Update(setting);
                                                 }
            };
            normalSync.CheckedChange += delegate { if (normalSync.Checked)
                                                   {
                                                       setting.Synchronisation = Setting.Frequency.normal; db.Update(setting);
                                                   }
            };
            lowSync.CheckedChange += delegate { if (lowSync.Checked)
                                                {
                                                    setting.Synchronisation = Setting.Frequency.rare; db.Update(setting);
                                                }
            };
            wlanSync.CheckedChange += delegate { if (wlanSync.Checked)
                                                 {
                                                     setting.Synchronisation = Setting.Frequency.wlan; db.Update(setting);
                                                 }
            };

            var server        = FindViewById <TextView> (Resource.Id.server);
            var nickname      = FindViewById <TextView> (Resource.Id.nickname);
            var changeProfile = FindViewById <ImageButton> (Resource.Id.changeProfile);
            var savechanges   = FindViewById <Button> (Resource.Id.save);
            var logout        = FindViewById <Button> (Resource.Id.logout);
            var name          = FindViewById <EditText> (Resource.Id.name);

            if (user != null)
            {
                server.Text   = user.server;
                nickname.Text = user.user;
                name.Text     = user.name;
                logout.Click += delegate {
                    db.DropUserSpecificData();
                    var intent = new Intent(this, typeof(MainActivity));
                    intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                    Finish();
                    StartActivity(intent);
                };
                savechanges.Click += delegate {
                    Toast.MakeText(this, "Not implemented yet.", ToastLength.Long).Show();
                };
                changeProfile.Click += delegate {
                    Toast.MakeText(this, "Not implemented yet.", ToastLength.Long).Show();
                };
                new Thread(async() => {
                    try {
                        var imageBitmap = await network.GetImageBitmapFromUrl(Resources.GetString(Resource.String.profileUrl) + user.user + ".png");
                        RunOnUiThread(() => changeProfile.SetImageBitmap(imageBitmap));
                    } catch (Exception e) {
                        Log.Error("BlaChat", e.StackTrace);
                    }
                }).Start();
            }
            else
            {
                server.Text              = "none";
                nickname.Text            = "none";
                name.Enabled             = false;
                changeProfile.Visibility = ViewStates.Gone;
                savechanges.Visibility   = ViewStates.Gone;
                logout.Visibility        = ViewStates.Gone;
            }

            var currentVersion = FindViewById <TextView> (Resource.Id.version);
            var newestVersion  = FindViewById <TextView> (Resource.Id.newestVersion);


            currentVersion.Text = Setting.CurrentVersion;
            if (setting.NewestVersion != null && !setting.NewestVersion.StartsWith(Setting.CurrentVersion))
            {
                newestVersion.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString(setting.NewestVersion));
            }
            else
            {
                newestVersion.Text = Setting.CurrentVersion;
            }
        }
        private void AddMessage(LinearLayout messageList, Message elem)
        {
            View v = null;

            if (elem.text.StartsWith("#image"))
            {
                if (elem.nick == user.user)
                {
                    if (setting.FontSize == Setting.Size.large)
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.ImageRightLarge, null);
                    }
                    else
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.ImageRight, null);
                    }
                }
                else
                {
                    if (setting.FontSize == Setting.Size.large)
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.ImageLeftLarge, null);
                    }
                    else
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.ImageLeft, null);
                    }
                    ImageView image = v.FindViewById <ImageView> (Resource.Id.messageImage);
                    new Thread(async() => {
                        try {
                            var imageBitmap = await network.GetImageBitmapFromUrl(Resources.GetString(Resource.String.profileUrl) + elem.nick + ".png");
                            RunOnUiThread(() => image.SetImageBitmap(imageBitmap));
                        } catch (Exception e) {
                            Log.Error("BlaChat", e.StackTrace);
                        }
                    }).Start();
                }
                ImageView contentImage = v.FindViewById <ImageView> (Resource.Id.contentImage);
                contentImage.Click += delegate {
                    string images   = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Pictures/BlaChat");
                    var    filename = elem.text.Substring("#image ".Length);
                    filename = filename.Substring(filename.LastIndexOf("/") + 1);
                    filename = System.IO.Path.Combine(images, filename);
                    Intent intent = new Intent(Intent.ActionView);
                    intent.SetDataAndType(Android.Net.Uri.Parse("file://" + filename), "image/*");
                    StartActivity(intent);
                };
                //contentImage.SetOnTouchListener (new TouchListener(this, elem.text.Substring ("#image ".Length)));

                new Thread(async() => {
                    try {
                        var uri         = elem.text.Substring("#image ".Length);
                        var imageBitmap = await network.GetImageBitmapFromUrl(uri);
                        RunOnUiThread(() => contentImage.SetImageBitmap(imageBitmap));
                    } catch (Exception e) {
                        Log.Error("BlaChat", e.StackTrace);
                    }
                }).Start();
            }
            else
            {
                if (elem.nick == user.user)
                {
                    if (setting.FontSize == Setting.Size.large)
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.MessageRightLarge, null);
                    }
                    else
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.MessageRight, null);
                    }
                }
                else
                {
                    if (setting.FontSize == Setting.Size.large)
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.MessageLeftLarge, null);
                    }
                    else
                    {
                        v = LayoutInflater.Inflate(Resource.Layout.MessageLeft, null);
                    }
                    ImageView image = v.FindViewById <ImageView> (Resource.Id.messageImage);
                    new Thread(async() => {
                        try {
                            var imageBitmap = await network.GetImageBitmapFromUrl(Resources.GetString(Resource.String.profileUrl) + elem.nick + ".png");
                            RunOnUiThread(() => image.SetImageBitmap(imageBitmap));
                        } catch (Exception e) {
                            Log.Error("BlaChat", e.StackTrace);
                        }
                    }).Start();
                }
                TextView text   = v.FindViewById <TextView> (Resource.Id.messageText);
                var      escape = elem.text.Replace("&quot;", "\"");
                escape             = escape.Replace("&lt;", "<");
                escape             = escape.Replace("&gt;", ">");
                escape             = escape.Replace("&amp;", "&");
                text.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString(escape));
            }

            TextView caption = v.FindViewById <TextView> (Resource.Id.messageCaption);

            if (elem.nick != user.user)
            {
                caption.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString(elem.author + " (" + elem.time.Substring(11, 5) + ")"));
            }
            else
            {
                if (elem.time == "sending")
                {
                    caption.TextFormatted = SpannableTools.GetSmiledText(this, new SpannableString("Du (" + elem.time + ")"));
                }
                else
                {
                    caption.Text = "Du (" + elem.time.Substring(11, 5) + ")";
                }
            }
            messageList.AddView(v);
        }