Exemplo n.º 1
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            if (args.Item is DateTime dateHeader)
            {
                var border = args.ItemContainer.ContentTemplateRoot as Border;
                var label  = border.Child as TextBlock;

                label.Text = BindConvert.DayGrouping(dateHeader);

                return;
            }

            var item    = args.Item as RawTransaction;
            var root    = args.ItemContainer.ContentTemplateRoot as Grid;
            var content = root.Children[0] as Grid;

            var headline  = content.Children[0] as TextBlock;
            var address   = content.Children[1] as TextBlock;
            var message   = content.Children[2] as TextBlock;
            var timestamp = content.Children[3] as TextBlock;

            headline.Inlines.Clear();

            long         amount;
            IList <byte> comment;

            if (item.InMsg != null)
            {
                amount  = item.InMsg.Value;
                comment = item.InMsg.Message;
            }
            else
            {
                amount  = 0;
                comment = null;
            }

            foreach (var msg in item.OutMsgs)
            {
                amount -= msg.Value;

                if (comment == null || comment.IsEmpty())
                {
                    comment = msg.Message;
                }
            }

            amount -= item.Fee;

            if (amount > 0)
            {
                headline.Inlines.Add(new Run {
                    Text = ConvertAmount(amount), Foreground = new SolidColorBrush(Windows.UI.Colors.Green), FontWeight = FontWeights.SemiBold
                });
                headline.Inlines.Add(new Run {
                    Text = $" {Strings.Resources.WalletFrom}"
                });
                address.Text = ConvertAddress(item.InMsg.Source);
            }
            else
            {
                headline.Inlines.Add(new Run {
                    Text = ConvertAmount(amount), Foreground = new SolidColorBrush(Windows.UI.Colors.Red), FontWeight = FontWeights.SemiBold
                });

                if (item.OutMsgs.IsEmpty())
                {
                    address.Text = Strings.Resources.WalletTransactionFee;
                }
                else
                {
                    headline.Inlines.Add(new Run {
                        Text = $" {Strings.Resources.WalletTo}"
                    });
                    address.Text = ConvertAddress(item.OutMsgs[0].Destination);
                }
            }

            if (comment != null && comment.Count > 0)
            {
                message.Text       = Encoding.UTF8.GetString(comment.ToArray());
                message.Visibility = Visibility.Visible;
            }
            else
            {
                message.Visibility = Visibility.Collapsed;
            }

            timestamp.Text = BindConvert.Current.Date((int)item.Utime);
        }
Exemplo n.º 2
0
        private void UpdateHeaderDate(bool intermediate)
        {
            var panel = Messages.ItemsPanelRoot as ItemsStackPanel;

            if (panel == null || panel.FirstVisibleIndex < 0)
            {
                return;
            }

            var firstVisibleId = 0L;
            var lastVisibleId  = 0L;

            var minItem      = true;
            var minDate      = true;
            var minDateIndex = panel.FirstVisibleIndex;

            for (int i = panel.FirstVisibleIndex; i <= panel.LastVisibleIndex; i++)
            {
                var container = Messages.ContainerFromIndex(i) as SelectorItem;
                if (container == null)
                {
                    continue;
                }

                var message = Messages.ItemFromContainer(container) as MessageViewModel;
                if (message == null)
                {
                    continue;
                }

                if (firstVisibleId == 0)
                {
                    firstVisibleId = message.Id;
                }
                else if (message.Id != 0)
                {
                    lastVisibleId = message.Id;
                }

                if (minItem && i >= panel.FirstVisibleIndex)
                {
                    var transform = container.TransformToVisual(DateHeaderRelative);
                    var point     = transform.TransformPoint(new Point());

                    if (point.Y + container.ActualHeight >= 0)
                    {
                        minItem = false;

                        if (message.SchedulingState is MessageSchedulingStateSendAtDate sendAtDate)
                        {
                            DateHeader.CommandParameter = null;
                            DateHeaderLabel.Text        = string.Format(Strings.Resources.MessageScheduledOn, BindConvert.DayGrouping(Utils.UnixTimestampToDateTime(sendAtDate.SendDate)));
                        }
                        else if (message.SchedulingState is MessageSchedulingStateSendWhenOnline)
                        {
                            DateHeader.CommandParameter = null;
                            DateHeaderLabel.Text        = Strings.Resources.MessageScheduledUntilOnline;
                        }
                        else
                        {
                            DateHeader.CommandParameter = message.Date;
                            DateHeaderLabel.Text        = BindConvert.DayGrouping(Utils.UnixTimestampToDateTime(message.Date));
                        }
                    }
                }

                if (message.Content is MessageHeaderDate && minDate && i >= panel.FirstVisibleIndex)
                {
                    var transform = container.TransformToVisual(DateHeaderRelative);
                    var point     = transform.TransformPoint(new Point());
                    var height    = (float)DateHeader.ActualHeight;
                    var offset    = (float)point.Y + height;

                    minDate = false;

                    if (/*offset >= 0 &&*/ offset < height)
                    {
                        container.Opacity = 0;
                        minDateIndex      = int.MaxValue; // Force show
                    }
                    else
                    {
                        container.Opacity = 1;
                        minDateIndex      = i;
                    }

                    if (offset >= height && offset < height * 2)
                    {
                        _dateHeader.Offset = new Vector3(0, -height * 2 + offset, 0);
                    }
                    else
                    {
                        _dateHeader.Offset = Vector3.Zero;
                    }
                }
                else
                {
                    container.Opacity = 1;
                }
            }

            _dateHeaderTimer.Stop();
            _dateHeaderTimer.Start();
            ShowHideDateHeader(minDateIndex > 0, minDateIndex > 0 && minDateIndex < int.MaxValue);

            // Read and play messages logic:
            //TODO:
            //if (messages.Count > 0 && _windowContext.ActivationMode == CoreWindowActivationMode.ActivatedInForeground)
            //{
            //    ViewModel.ProtoService.Send(new ViewMessages(chat.Id, ViewModel.ThreadId, messages, false));
            //}

            //if (animations.Count > 0 && !intermediate)
            //{
            //    Play(animations, ViewModel.Settings.IsAutoPlayAnimationsEnabled, false);
            //}

            // Pinned banner
            if (firstVisibleId == 0 || lastVisibleId == 0)
            {
                return;
            }

            if (ViewModel.LockedPinnedMessageId < firstVisibleId)
            {
                ViewModel.LockedPinnedMessageId = 0;
            }

            var thread = ViewModel.Thread;

            if (thread != null)
            {
                var message = thread.Messages.LastOrDefault();
                if (message == null || (firstVisibleId <= message.Id && lastVisibleId >= message.Id))
                {
                    PinnedMessage.UpdateMessage(ViewModel.Chat, null, false, 0, 1, false);
                }
                else
                {
                    PinnedMessage.UpdateMessage(ViewModel.Chat, ViewModel.CreateMessage(message), false, 0, 1, false);
                }
            }
            else if (ViewModel.PinnedMessages.Count > 0)
            {
                var currentPinned = ViewModel.LockedPinnedMessageId != 0
                    ? ViewModel.PinnedMessages.LastOrDefault(x => x.Id < firstVisibleId) ?? ViewModel.PinnedMessages.LastOrDefault()
                    : ViewModel.PinnedMessages.LastOrDefault(x => x.Id <= lastVisibleId) ?? ViewModel.PinnedMessages.FirstOrDefault();
                if (currentPinned != null)
                {
                    //PinnedMessage.UpdateIndex(ViewModel.PinnedMessages.IndexOf(currentPinned), ViewModel.PinnedMessages.Count, intermediate);
                    PinnedMessage.UpdateMessage(ViewModel.Chat, currentPinned, false,
                                                ViewModel.PinnedMessages.IndexOf(currentPinned), ViewModel.PinnedMessages.Count, intermediate);
                }
                else
                {
                    PinnedMessage.UpdateMessage(ViewModel.Chat, null, false, 0, 1, false);
                }
            }
        }