Ejemplo n.º 1
0
        public async Task Refresh()
        {
            BT_Refresh.IsEnabled = false;
            PR_Loading.IsActive  = true;
            TB_RefreshBT.Text    = "갱신중..";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.ProgressClock;
            var mails = await KakaoRequestClass.GetMails();

            SP_Main.Children.Clear();
            foreach (var mail in mails)
            {
                var mc = new MailControl();
                mc.TB_Name.Text    = mail.sender.display_name;
                mc.TB_Content.Text = mail.summary;
                mc.TB_Date.Text    = PostWindow.GetTimeString(mail.created_at);

                string imgUri = mail.sender.profile_thumbnail_url;
                if (Properties.Settings.Default.GIFProfile && mail.sender.profile_video_url_square_small != null)
                {
                    imgUri = mail.sender.profile_video_url_square_small;
                }
                GlobalHelper.AssignImage(mc.IMG_Profile, imgUri);
                MainWindow.SetClickObject(mc.IMG_Profile);
                mc.IMG_Profile.PreviewMouseLeftButtonDown += (s, e) =>
                {
                    e.Handled = true;
                    try
                    {
                        TimeLineWindow tlw = new TimeLineWindow(mail.sender.id);
                        tlw.Show();
                        tlw.Activate();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("접근이 불가능한 스토리입니다.");
                    }
                };

                if (mail.read_at == null || mail.read_at.Value.Year < 1)
                {
                    mc.RA_BG.Fill = Brushes.Teal;
                }

                mc.Grid.MouseLeftButtonDown += (s, e) =>
                {
                    e.Handled     = true;
                    mc.RA_BG.Fill = Brushes.Transparent;
                    var window = new MailReadWindow(mail.id);
                    window.Show();
                };

                mc.IC_Reply.PreviewMouseLeftButtonDown += (s, e) =>
                {
                    e.Handled     = true;
                    mc.RA_BG.Fill = Brushes.Transparent;
                    var window = new MailWriteWindow(mail.sender.id, mail.sender.display_name);
                    window.Show();
                };

                MainWindow.SetClickObject(mc.Grid);

                SP_Main.Children.Add(mc);
                var sep = new Separator
                {
                    Foreground = new SolidColorBrush(Color.FromRgb(221, 221, 221))
                };
                SP_Main.Children.Add(sep);
            }
            PR_Loading.IsActive  = false;
            BT_Refresh.IsEnabled = true;
            TB_RefreshBT.Text    = "새로고침";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.Refresh;
        }