Пример #1
0
        public async Task <SearchPhotoObjects> SearchPhotoaaa()
        {
            Uri searchPhotoaaaUri = new Uri(RequestParameters.photoSearchUri);

            HttpClient httpClient = new HttpClient();

            string responseJson = await httpClient.GetStringAsync(searchPhotoaaaUri);

            SearchPhotoObjects searchPhotoObjects = JsonConvert.DeserializeObject <SearchPhotoObjects>(responseJson, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(searchPhotoObjects);
        }
Пример #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            //AutoSuggestBox item = (AutoSuggestBox)e.Parameter;
            try
            {
                AutoSuggestBox AutosgBoxitem = (AutoSuggestBox)e.Parameter;

                ViewModel.RequestParameters.photoSearchUri += AutosgBoxitem.Text;

                tbNameSearch.Text = AutosgBoxitem.Text;
            }
            catch (Exception)
            {
                TrendSourch Trenditem = (TrendSourch)e.Parameter;

                ViewModel.RequestParameters.photoSearchUri += Trenditem.Title;

                tbNameSearch.Text = Trenditem.Title;
            }


            publicAuthorization = new PublicAuthorization();

            try
            {
                listPhotoSearch = await publicAuthorization.SearchPhotoaaa();
            }
            catch (Exception ex)
            {
                Noreult.Visibility = Visibility.Visible;
            }

            if (listPhotoSearch.results != null)
            {
                if (listPhotoSearch.results.Count == 0)
                {
                    Noreult.Visibility = Visibility.Visible;
                }
                else
                {
                    while (listPhotoSearch.total == 0)
                    {
                        await Task.Delay(10);

                        listPhotoSearch = await publicAuthorization.SearchPhotoaaa();
                    }

                    for (int i = 0; i < 30; i++)
                    {
                        MySearchRes.Add(new ResultModel
                        {
                            id                       = listPhotoSearch.results[i].id,
                            created_at               = listPhotoSearch.results[i].created_at,
                            updated_at               = listPhotoSearch.results[i].updated_at,
                            width                    = listPhotoSearch.results[i].width,
                            height                   = listPhotoSearch.results[i].height,
                            color                    = listPhotoSearch.results[i].color,
                            description              = listPhotoSearch.results[i].description,
                            urlsfull                 = listPhotoSearch.results[i].urls.full,
                            urlsmedium               = listPhotoSearch.results[i].urls.small,
                            links                    = listPhotoSearch.results[i].links.download,
                            categories               = listPhotoSearch.results[i].categories,
                            sponsored                = listPhotoSearch.results[i].sponsored,
                            likes                    = listPhotoSearch.results[i].likes,
                            liked_by_user            = listPhotoSearch.results[i].liked_by_user,
                            current_user_collections = listPhotoSearch.results[i].current_user_collections,
                            slug                     = listPhotoSearch.results[i].slug,
                            username                 = listPhotoSearch.results[i].user.username,
                            name                     = listPhotoSearch.results[i].user.name,
                            ImgmediumPro5            = listPhotoSearch.results[i].user.profile_image.medium,
                            likebyuser               = listPhotoSearch.results[i].urls.raw
                        });
                    }
                }
            }
            else
            {
                Noreult.Visibility = Visibility.Visible;
            }


            this.ListPhotoSearchModel = new SearchViewModel();

            double totalWidth = 0;
            int    start      = 0;

            while (grvSearch.ActualWidth == 0)
            {
                await Task.Delay(10);
            }

            for (int i = 0; i < ListPhotoSearchModel.ListImageRes.Count; i++)
            {
                var width = ListPhotoSearchModel.ListImageRes[i].width * 310 / ListPhotoSearchModel.ListImageRes[i].height;
                totalWidth += width;

                if (totalWidth > grvSearch.ActualWidth)
                {
                    for (int j = start; j < i; j++)
                    {
                        ListPhotoSearchModel.ListImageRes[j].Scale = grvSearch.ActualWidth / (totalWidth - width);
                    }
                    start      = i;
                    totalWidth = width;
                }
            }

            for (int j = start; j < ListPhotoSearchModel.ListImageRes.Count; j++)
            {
                ListPhotoSearchModel.ListImageRes[j].Scale = grvSearch.ActualWidth / (totalWidth);
            }

            grvSearch.ItemsSource = ListPhotoSearchModel.ListImageRes;

            griNewLoading.Visibility = Visibility.Collapsed;

            ViewModel.RequestParameters.photoSearchUri = "https://api.unsplash.com/search/photos/?client_id=" + RequestParameters.client_id + "&per_page=30&query=";

            RequestParameters.collectionSearchUri = "https://api.unsplash.com/search/collections/?client_id=" + RequestParameters.client_id + "&per_page=30&query=";
        }