예제 #1
0
 public async Task<List<NavigationItem>> GetNavigationItems(string path)
 {
     List<NavigationItem> navigItems = new List<NavigationItem>();
     try
     {
         using (WebClient client = new WebClient())
         {
             client.DownloadString("http://google.com");
         }
     }
     catch (WebException ex)
     {
         MessageBox.Show("Ошибка подключения. Пожалуйста, проверьте подключение к интернету.",
         "Ошибка подключения", MessageBoxButton.OK, MessageBoxImage.Error);
         navigItems.Add(new NavigationItem("Вход", null, itemHeight, true, false, null, fontHeight, Cursors.Hand));
         return navigItems;
     }
     if (path == null && !userLogged)
     {
         browserWin = new BrowserWindow(vkAudio);
         browserWin.Navigate(vkAudio.AuthUrl);
         bool? result = browserWin.Show();
         if (vkAudio.HasAccessData)
         {
             userLogged = true;
             navigItems = await GetNavigationItems(null);
         }
         else
             navigItems = await GetNavigationItems(loginPath);
     }
     else if (path == loginPath)
     {
         navigItems.Add(new NavigationItem("Вход", null, itemHeight, true, false, null, fontHeight, Cursors.Hand));
     }
     else if (path == null && userLogged)
     {
         if (!isCacheDownloaded)
         {
             if (FavoriteItems.Count > 0 && FavoriteItems[0].Name != "Мои аудиозаписи" || FavoriteItems.Count == 0)
                 FavoriteItems.Add(new NavigationItem("Мои аудиозаписи", vkAudio.UserID, itemHeight, false, false, null, fontHeight, Cursors.Hand));
             await vkAudio.GetFriendsList();
             await vkAudio.GetGroupsList();
             isCacheDownloaded = true;
         }
         navigItems.Add(new NavigationItem("Мои аудиозаписи", vkAudio.UserID, itemHeight, false, false, null, fontHeight, Cursors.Hand));
         navigItems.Add(new NavigationItem("Мои друзья", friendsPath, itemHeight, true, false, null, fontHeight, Cursors.Hand));
         navigItems.Add(new NavigationItem("Мои группы", groupsPath, itemHeight, true, false, null, fontHeight, Cursors.Hand));
         navigItems.Add(new NavigationItem("Мои плейлисты", playlistsPath, itemHeight, true, false, null, fontHeight, Cursors.Hand));
         navigItems.Add(new NavigationItem("Выход", logoutPath, itemHeight, true, false, null, fontHeight, Cursors.Hand, true, "Вы уверены что хотите выйти из своего аккаунта?"));
     }
     else if (path == logoutPath)
     {
         vkAudio.LogOut();
         var cleanedFavorites = new List<NavigationItem>();
         cleanedFavorites.Add(FavoriteItems[0]);
         FavoriteItems = cleanedFavorites;
         userLogged = false;
         navigItems = await GetNavigationItems(loginPath);
     }
     else
     {
         navigItems.Add(new NavigationItem("[Назад]", null, 50, true, false, null, 16, Cursors.Hand));
         var resultList = new List<NavigationItem>();
         if (path == friendsPath)
             resultList = await vkAudio.GetFriendsList();
         else if (path == groupsPath)
             resultList = await vkAudio.GetGroupsList();
         else if (path == playlistsPath)
             resultList = await vkAudio.GetPlaylistsList();
         if (resultList == null)
             return null;
         navigItems.AddRange(resultList);
     }
     return navigItems;
 }