Beispiel #1
0
        private void SendLiveLocation(TLMessageMediaGeoLive mediaGeoLive)
        {
            var message = GetMessage(TLString.Empty, mediaGeoLive);

            mediaGeoLive.Date = message.Date;
            mediaGeoLive.From = message.From;

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && (_messages == null || _messages.Count == 0) && LazyItems.Count == 0;

                LiveLocationBadge = new LiveLocationBadgeViewModel(IoC.Get <ILiveLocationService>(), IoC.Get <ICacheService>(), false)
                {
                    Message = message
                };
                LiveLocationBadge.OpenMessage += OpenLiveLocationBadge;
                LiveLocationBadge.Closed      += CloseLiveLocationBadge;

                NotifyOfPropertyChange(() => LiveLocationBadge);

                UpdateLiveLocations(
                    result =>
                {
                },
                    error =>
                {
                });

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      SendLiveLocationInternal));
            });
        }
Beispiel #2
0
        public Task <bool> SendGeoAsync(TLMessageMediaGeoLive media)
        {
            var tsc  = new TaskCompletionSource <bool>();
            var date = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now);

            var message = TLUtils.GetMessage(SettingsHelper.UserId, Peer.ToPeer(), TLMessageState.Sending, true, true, date, string.Empty, media, TLLong.Random(), null);

            if (Reply != null)
            {
                message.HasReplyToMsgId = true;
                message.ReplyToMsgId    = Reply.Id;
                message.Reply           = Reply;
                Reply = null;
            }

            var previousMessage = InsertSendingMessage(message);

            CacheService.SyncSendingMessage(message, previousMessage, async(m) =>
            {
                var inputMedia = media.ToInputMedia();

                var result = await ProtoService.SendMediaAsync(Peer, inputMedia, message);
                if (result.IsSucceeded)
                {
                    tsc.SetResult(true);
                    await _liveLocationService.TrackAsync(message);
                }
                else
                {
                    tsc.SetResult(false);
                }
            });

            return(tsc.Task);
        }
        private void UpdateAnimation(TLMessageMediaGeoLive mediaGeoLive)
        {
            if (mediaGeoLive == null || mediaGeoLive.Date == null)
            {
                Label.Text     = "0";
                Progress.Angle = 0.0;
                if (_storyboard.GetCurrentState() == ClockState.Active)
                {
                    _storyboard.SkipToFill(); // will invoke storyboard.Completed
                }
                return;
            }

            var date = TLUtils.DateToUniversalTimeTLInt(IoC.Get <IMTProtoService>().ClientTicksDelta, DateTime.Now);

            var lastPartSeconds = (double)mediaGeoLive.Date.Value + mediaGeoLive.Period.Value - date.Value;

            if (lastPartSeconds <= 0)
            {
                Label.Text     = "0";
                Progress.Angle = 0.0;
                if (_storyboard.GetCurrentState() == ClockState.Active)
                {
                    _storyboard.SkipToFill(); // will invoke storyboard.Completed
                }
                return;
            }
            if (lastPartSeconds > mediaGeoLive.Period.Value)
            {
                lastPartSeconds = mediaGeoLive.Period.Value - 1.0;
            }

            Label.Text = GetLabelText(lastPartSeconds);

            var percent = lastPartSeconds / mediaGeoLive.Period.Value;
            var angle   = 359.0 * percent;

            _progressAnimation.From     = angle;
            _progressAnimation.Duration = TimeSpan.FromSeconds(lastPartSeconds);

            Progress.Angle = angle;
            _storyboard.Begin();

            SetNextTimer(lastPartSeconds);
        }
Beispiel #4
0
        public void AttachGeoLive(GeoCoordinate location, TimerSpan timer)
        {
            if (location == null)
            {
                return;
            }
            if (location.Latitude == 0.0 && location.Longitude == 0.0)
            {
                return;
            }

            var mediaGeoLive = new TLMessageMediaGeoLive
            {
                Geo = new TLGeoPoint {
                    Lat = new TLDouble(location.Latitude), Long = new TLDouble(location.Longitude)
                },
                Period = new TLInt(timer.Seconds)
            };

            CloseEditor();
            ContinueAction.SafeInvoke(mediaGeoLive);
        }
Beispiel #5
0
        private async void LiveLocation_Click(object sender, RoutedEventArgs e)
        {
            if (LiveLocation == true)
            {
                var dialog  = new SelectLivePeriodView();
                var confirm = await dialog.ShowQueuedAsync();

                if (confirm == ContentDialogResult.Primary && _lastPosition != null)
                {
                    Media = new TLMessageMediaGeoLive {
                        Geo = new TLGeoPoint {
                            Lat = _lastPosition.Coordinate.Point.Position.Latitude, Long = _lastPosition.Coordinate.Point.Position.Longitude
                        }, Period = dialog.Period
                    };
                    Dialog.Hide(ContentDialogBaseResult.OK);
                }
            }
            else if (LiveLocation == false)
            {
                Media = new TLMessageMediaGeoLive();
                Dialog.Hide(ContentDialogBaseResult.OK);
            }
        }