private async void LoadVideo()
        {
            LoadingIndicator.IsBusy = true;

            try
            {
                var response = await ServiceLocator.Vkontakte.Video.Get(new[] { $"{_videoAttachment.OwnerId}_{_videoAttachment.Id}_{_videoAttachment.AccessKey}" });

                if (response != null && !response.Items.IsNullOrEmpty())
                {
                    var video = response.Items.First();
                    WebView.Navigate(new Uri(video.Player));
                }
                else
                {
                    LoadingIndicator.Error  = Localizator.String("Error/ChatVideoAttachmentLoadCommonError");
                    LoadingIndicator.IsBusy = false;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"Unable to load video {_videoAttachment.OwnerId}_{_videoAttachment.Id}_{_videoAttachment.AccessKey} info");

                LoadingIndicator.Error  = Localizator.String("Error/ChatVideoAttachmentLoadCommonError");
                LoadingIndicator.IsBusy = false;
            }
        }
Esempio n. 2
0
        private async void Load()
        {
            var friends = new List <VkProfile>();

            //try
            //{
            //    var response = await ServiceLocator.Vkontakte.Friends.Get(0, "first_name,last_name,photo,online,last_seen", null, 7, 0, FriendsOrder.ByRating);
            //    if (response != null)
            //        friends.AddRange(response.Items);
            //}
            //catch (Exception ex)
            //{
            //    Logger.Error(ex, "Unable to load friends");
            //}

            var t = TaskStarted("users");

            try
            {
                var response = await ServiceLocator.Vkontakte.Friends.Get(0, "first_name,last_name,photo,online,last_seen", null, 0, 0, _selectedSortTypeIndex != 0?FriendsOrder.ByName : FriendsOrder.ByRating);

                if (response != null && !response.Items.IsNullOrEmpty())
                {
                    friends.AddRange(response.Items);
                }
                else
                {
                    t.Error = Localizator.String("NewDialogFriendsEmptyError");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to load friends");

                t.Error = Localizator.String("NewDialogFriendsCommonError");
            }

            Friends = friends;

            if (_selectedSortTypeIndex != 0)
            {
                FriendsCollection = new CollectionViewSource()
                {
                    Source          = _friends.ToAlphaGroups(f => _selectedSortTypeIndex == 1 ? f.FirstName : f.LastName),
                    ItemsPath       = new PropertyPath("Value"),
                    IsSourceGrouped = true
                };
            }
            else
            {
                FriendsCollection = new CollectionViewSource()
                {
                    Source          = _friends,
                    IsSourceGrouped = false
                };
            }

            t.Finish();
        }
        private void UpdateCountTitle()
        {
            var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

            MessagesCountTitle.Text = StringHelper.LocalizeNumerals(Attachment.Messages.Count,
                                                                    Localizator.String("MessagesSingular"), Localizator.String("MessagesDual"),
                                                                    Localizator.String("MessagesPlural"), locale).ToLower();
        }
Esempio n. 4
0
        private async void Load()
        {
            var t = TaskStarted("dialogs");

            try
            {
                var vkDialogs = await ServiceLocator.Vkontakte.Messages.GetDialogs();

                if (!vkDialogs.Items.IsNullOrEmpty())
                {
                    var dialogs = await ProcessDialogs(vkDialogs.Items);

                    _totalCount = vkDialogs.TotalCount;

                    Dialogs = new IncrementalLoadingCollection <Dialog>(dialogs);
                    Dialogs.HasMoreItemsRequested = () => _totalCount > Dialogs.Count;
                    Dialogs.OnMoreItemsRequested  = LoadMoreDialogs;

                    if (((App)Application.Current).LaunchArgs != null)
                    {
                        var args = ((App)Application.Current).LaunchArgs;
                        if (args != null && args.ContainsKey("uid"))
                        {
                            long uid = long.Parse(args["uid"]);

                            var activeDialog = Dialogs.FirstOrDefault(d => d.User.Profile.Id == uid);
                            SelectedDialog = activeDialog;
                        }
                    }
                }
                else
                {
                    t.Error = Localizator.String("Errors/DialogsEmptyError");
                }
            }
            catch (VkInvalidTokenException)
            {
                Messenger.Default.Send(new LoginStateChangedMessage()
                {
                    IsLoggedIn = false
                });

                Navigator.Main.Navigate(typeof(LoginView), clearHistory: true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to load dialogs");

                t.Error = Localizator.String("Errors/DialogsCommonError");
            }

            t.Finish();
        }
Esempio n. 5
0
        private async void ChatTextBoxGrid_OnDragEnter(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.Bitmap))
            {
                e.AcceptedOperation = DataPackageOperation.Copy;
                if (e.DragUIOverride != null)
                {
                    e.DragUIOverride.Caption = Localizator.String("DragDropAttachImage");
                }
                e.Handled = true;
            }
            else if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var deferral = e.GetDeferral();
                e.AcceptedOperation = DataPackageOperation.None;

                var items = await e.DataView.GetStorageItemsAsync();

                int filesCount = 0;

                foreach (var item in items)
                {
                    try
                    {
                        var file = item as StorageFile;
                        if (file != null)
                        {
                            //if (file.ContentType.StartsWith("image/"))
                            //    filesCount++;
                            //else
                            filesCount++;
                        }
                    }
                    catch { }
                }

                if (filesCount > 0)
                {
                    e.AcceptedOperation = DataPackageOperation.Copy;
                    if (e.DragUIOverride != null)
                    {
                        e.DragUIOverride.Caption = filesCount == 1 ? Localizator.String("DragDropAttachFile") : Localizator.String("DragDropAttachFiles");
                    }
                }

                e.Handled = true;
                deferral.Complete();
            }
        }
        private async void SaveButton_OnClick(object sender, RoutedEventArgs e)
        {
            //TODO
            string currentPhoto = null;

            if (_photos.IsNullOrEmpty() || _photos.Count == 1)
            {
                currentPhoto = _currentPhoto;
            }
            else
            {
                currentPhoto = _photos[FlipView.SelectedIndex]; //(string)FlipView.SelectedItem;
            }
            var picker = new FileSavePicker();

            picker.FileTypeChoices.Add("Image", new List <string>()
            {
                Path.GetExtension(currentPhoto)
            });
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

            var file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                try
                {
                    var httpClient  = new HttpClient();
                    var imageStream = await httpClient.GetInputStreamAsync(new Uri(currentPhoto));

                    var fileStream = await file.OpenStreamForWriteAsync();

                    await imageStream.AsStreamForRead().CopyToAsync(fileStream);

                    await fileStream.FlushAsync();

                    fileStream.Dispose();
                    imageStream.Dispose();

                    await new MessageDialog(Localizator.String("Errors/SaveImageDialogCommonSuccess"), Localizator.String("Errors/SaveImageDialogTitleDone")).ShowAsync();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Unable to save image");

                    await new MessageDialog(Localizator.String("Errors/SaveImageDialogCommonError"), Localizator.String("Errors/SaveImageDialogTitleError")).ShowAsync();
                }
            }
        }
        public MessageWallPostControl(VkWallPostAttachment wallPost)
        {
            WallPost = wallPost;

            this.InitializeComponent();

            if (string.IsNullOrEmpty(wallPost.Text))
            {
                TitleTextBlock.Text = Localizator.String("ChatMessageWallPostTitle");
                DateTextBlock.Text  = wallPost.Date.ToString(Localizator.String("MessageWallPostTimeFormat"));
            }
            else
            {
                TitleTextBlock.Text = WallPost.Text;
                DateTextBlock.Text  = Localizator.String("ChatMessageWallPostTitle") + ", " + wallPost.Date.ToString(Localizator.String("MessageWallPostTimeFormat"));
            }
        }
Esempio n. 8
0
        public object Convert(object value, Type targetType, object parameter, string culture)
        {
            var date  = (DateTime)value;
            var hours = (DateTime.Now.ToUniversalTime() - date).TotalHours;

            if (date.Date == DateTime.Today)
            {
                return(date.ToString("t"));
            }

            if (DateTime.Today - date.Date == TimeSpan.FromDays(1))
            {
                return(Localizator.String("Yesterday").ToLower());
            }

            return(date.ToString(Localizator.String("MessageTimeFormat")));
        }
Esempio n. 9
0
        public string GetActionText()
        {
            if (string.IsNullOrEmpty(MessageContent.Action))
            {
                return(null);
            }

            switch (MessageContent.Action)
            {
            case "chat_create":
                return(string.Format(Localizator.String("ChatServiceMessageChatCreated"), Sender?.Name, MessageContent.ActionText));

            case "chat_photo_update":
                return(string.Format(Localizator.String("ChatServiceMessagePhotoUpdated"), Sender?.Name));

            case "chat_photo_remove":
                return(string.Format(Localizator.String("ChatServiceMessagePhotoRemoved"), Sender?.Name));

            case "chat_kick_user":
                return(string.Format(Localizator.String("ChatServiceMessageKickUser"), Sender?.Name));
            }

            return(null);
        }
Esempio n. 10
0
 private void WebView_OnNavigationFailed(object sender, WebViewNavigationFailedEventArgs e)
 {
     LoadingIndicator.Error = Localizator.String("Error/ChatVideoAttachmentLoadCommonError");
 }
Esempio n. 11
0
        public async void DoLogin()
        {
            if (Operations["login"].IsWorking)
            {
                return;
            }

            var t = TaskStarted("login");

            CanInput = false;

            try
            {
                var token = await ServiceLocator.Vkontakte.Auth.Login(Login, Password, VkScopeSettings.CanAccessFriends |
                                                                      VkScopeSettings.CanAccessGroups |
                                                                      VkScopeSettings.CanAccessMessages |
                                                                      VkScopeSettings.CanAccessWall |
                                                                      VkScopeSettings.CanAccessVideos |
                                                                      VkScopeSettings.CanAccessPhotos |
                                                                      VkScopeSettings.CanAccessDocs |
                                                                      VkScopeSettings.CanAccessAudios,
                                                                      _captchaSid, _captchaKey);

                if (token != null)
                {
                    AppSettings.AccessToken = token;
                }

                Navigator.Main.Navigate(typeof(MainPage), clearHistory: true);
                Messenger.Default.Send(new LoginStateChangedMessage()
                {
                    IsLoggedIn = true
                });
            }
            catch (VkCaptchaNeededException ex)
            {
                Logger.Error(ex, "Unable to login. Captcha needed.");

                IsCaptchaVisible = true;
                _captchaSid      = ex.CaptchaSid;
                CaptchaImg       = ex.CaptchaImg;
            }
            catch (VkInvalidClientException ex)
            {
                Logger.Error(ex, "Unable to login. Invalid client.");

                t.Error = Localizator.String("Errors/LoginInvalidClientError");
            }
            catch (VkNeedValidationException ex)
            {
                Logger.Error(ex, "Validation requred");

                ValidateUser(ex.RedirectUri);

                UpdateCanLogin();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to login.");

                t.Error = Localizator.String("Errors/LoginCommonError");
            }

            t.Finish();

            CanInput = true;
        }
Esempio n. 12
0
        private async void Load()
        {
            var t = TaskStarted("history");

            try
            {
                bool isChat = Dialog.Message.ChatId != 0;
                if (isChat)
                {
                    var users = await ServiceLocator.UserService.GetChatUsers(Dialog.Message.ChatId);

                    Dialog.Users = users;

                    if (Dialog.Users == null)
                    {
                        Dialog.Users = new List <VkProfile>();
                    }

                    if (!Dialog.Users.Contains(ViewModelLocator.Main.CurrentUser))
                    {
                        Dialog.Users.Add(ViewModelLocator.Main.CurrentUser);
                    }
                }

                var vkMessages = await ServiceLocator.Vkontakte.Execute.GetChatHistoryAndMarkAsRead(!isChat?Dialog.User.Profile.Id : 0, chatId : isChat?Dialog.Message.ChatId : 0, count : DeviceHelper.IsMobile()? 20 : 50, markAsRead : !AppSettings.DontMarkMessagesAsRead);

                if (!vkMessages.Items.IsNullOrEmpty())
                {
                    if (isChat)
                    {
                        var userIds = vkMessages.Items.Where(m => !Dialog.Users.Any(u => m.UserId == u.Id)).Select(m => m.UserId).ToList();

                        var users = await ServiceLocator.UserService.GetById(userIds);

                        if (!users.IsNullOrEmpty())
                        {
                            Dialog.Users.AddRange(users);
                        }
                    }

                    Messages.AddRange(vkMessages.Items.Select(m =>
                    {
                        VkProfile sender = null;
                        if (!isChat)
                        {
                            sender = !m.IsOut ? Dialog.User.Profile : null;
                        }
                        else
                        {
                            sender = Dialog.Users?.FirstOrDefault(u => u.Id == m.UserId);
                        }
                        return(new Message(m, sender));
                    }).Reverse().ToList());
                    _totalCount = vkMessages.TotalCount;
                    //Messages.OnMoreItemsRequested = LoadMoreMessages;
                    //Messages.HasMoreItemsRequested = () => _totalCount > Messages.Count;
                }
            }
            catch (VkInvalidTokenException)
            {
                Messenger.Default.Send(new LoginStateChangedMessage()
                {
                    IsLoggedIn = false
                });

                Navigator.Main.Navigate(typeof(LoginView), clearHistory: true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to load messages in coversation");

                t.Error = Localizator.String("Errors/ChatHistoryCommonError");
            }

            t.IsWorking = false;
        }
Esempio n. 13
0
        private string GetPreview()
        {
            if (Message == null)
            {
                return(string.Empty);
            }

            string result = string.Empty;
            var    locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

            if (!string.IsNullOrEmpty(Message.Body))
            {
                result = Message.Body;
            }
            else if (Message.Action != null)
            {
                result = new Message(Message, User.Profile).GetActionText();
            }
            else if (!Message.Attachments.IsNullOrEmpty())
            {
                var first = Message.Attachments[0];
                var count = Message.Attachments.Count;

                if (count > 1 && Message.Attachments.Any(a => a.Type != first.Type))
                {
                    result = count + " " + StringHelper.LocalizeNumerals(count, Localizator.String("AttachmentsSingular"), Localizator.String("AttachmentsDual"), Localizator.String("AttachmentsPlural"), locale);
                }
                else
                {
                    switch (first.Type)
                    {
                    case "audio":
                        result = count + " " + StringHelper.LocalizeNumerals(count, Localizator.String("AudiosSingular"), Localizator.String("AudiosDual"), Localizator.String("AudiosPlural"), locale);
                        break;

                    case "photo":
                        result = count + " " + StringHelper.LocalizeNumerals(count, Localizator.String("PhotosSingular"), Localizator.String("PhotosDual"), Localizator.String("PhotosPlural"), locale);
                        break;

                    case "sticker":
                        result = Localizator.String("DialogSticker");
                        break;

                    case "gift":
                        result = Localizator.String("DialogGift");
                        break;

                    case "link":
                        result = Localizator.String("DialogLink");
                        break;

                    case "doc":
                        result = count + " " + StringHelper.LocalizeNumerals(count, Localizator.String("DocumentsSingular"), Localizator.String("DocumentsDual"), Localizator.String("DocumentsPlural"), locale);
                        break;

                    case "video":
                        result = count + " " + StringHelper.LocalizeNumerals(count, Localizator.String("VideosSingular"), Localizator.String("VideosDual"), Localizator.String("VideosPlural"), locale);
                        break;

                    case "wall":
                        result = Localizator.String("DialogWallPost");
                        break;

                    default:
                        result = count + " " + StringHelper.LocalizeNumerals(count, Localizator.String("AttachmentsSingular"), Localizator.String("AttachmentsDual"), Localizator.String("AttachmentsPlural"), locale);
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(result) && Message.Geo != null)
            {
                result = Localizator.String("DialogLocation");
            }

            if (!Message.ForwardMessages.IsNullOrEmpty())
            {
                result = Message.ForwardMessages.Count + " " + StringHelper.LocalizeNumerals(Message.ForwardMessages.Count, Localizator.String("DialogForwardedMessagesSingular"), Localizator.String("DialogForwardedMessagesDual"), Localizator.String("DialogForwardedMessagesPlural"), locale);
            }

            return(result);
        }