コード例 #1
0
ファイル: FlickrTools.cs プロジェクト: jrlambs/FlickrPicker
        public static async Task<List<FlickrPhoto>> getImages(String searchTerm, int pageNum, int numPerPage)
        {
            var app = App.Current as App;
            List<FlickrPhoto> photosToReturn = new List<FlickrPhoto>();
            Flickr flickr = getFlickrObject();
            var options = new PhotoSearchOptions { MediaType = MediaType.Photos, Tags = searchTerm, PerPage = numPerPage, Page = pageNum, UserId = app.accountId, Extras = (PhotoSearchExtras.DateTaken | PhotoSearchExtras.OriginalUrl | PhotoSearchExtras.Tags), SortOrder = PhotoSearchSortOrder.DatePostedDescending };
            PhotoCollection photos = await flickr.PhotosSearchAsync(options);
            foreach (Photo photo in photos)
            {
                FlickrPhoto p = new FlickrPhoto();
                p.Title = photo.Title;
                p.Url = photo.WebUrl;
                p.keywords = photo.Tags.ToList();
                p.Farm = Convert.ToInt32(photo.Farm);
                p.Id = Convert.ToInt64(photo.PhotoId);
                p.Secret = photo.Secret;
                p.Server = Convert.ToInt32(photo.Server);
                
                if (p.keywords.Contains(app.tagToAddString.ToLower()))
                {
                    p.tagImage = App.FAVORITE_ICON;
                }
                else{
                    p.tagImage = App.NOT_FAVORITE_ICON;
                }
                photosToReturn.Add(p);

            }
            return photosToReturn;
        }
コード例 #2
0
ファイル: FlickrTools.cs プロジェクト: jrlambs/FlickrPicker
/*        private static List<DateTime> getPhotoCountDatesFromMonths(List<DateNavigationItem> months)
        {
            List<DateTime> photCountDates = new List<DateTime>();
            try
            {
                for (int i = months.Count() - 1; i >= 0; i--)
                {
                    DateNavigationItem item = months.ElementAt(i);
                    string month = getMonthIntString(item.month);
                    string nextMonth = Convert.ToString(Convert.ToUInt32(month) + 1).PadLeft(2, '0');
                    DateTime d = Convert.ToDateTime(month + "/01/" + item.year);
                    photCountDates.Add(d);
                    if (!month.Equals("12"))
                    {
                        d = Convert.ToDateTime(nextMonth + "/01/" + (item.year));
                        photCountDates.Add(d);
                    }
                    else
                    {
                        d = Convert.ToDateTime("01/01/" + (item.year + 1));
                        photCountDates.Add(d);
                    }
                    
                }
            }
            catch (Exception e)
            {
                String s = e.StackTrace;
                s.ToString();
            }
            photCountDates.Sort((a, b) => a.CompareTo(b));
            return photCountDates;
        }

        private static void addNavigationItemToList(List<DateNavigationItem> items, DateNavigationItem it)
        {
            foreach(DateNavigationItem dn in items)
            {
                if(it.month.Equals(dn.month) && it.year == dn.year)
                {
                    return;
                }
            }
            items.Add(it);
        }*/


        public static async Task<List<FlickrPhoto>> getPhotosForMonth(int perPage, int pageNum, string searchTerm, string year, string month)
        {
            var app = App.Current as App;
            string monthIntString = getMonthIntString(month);
            DateTime startDate = Convert.ToDateTime(monthIntString + "/01/" + year);
            DateTime endDate;
            if (!"12".Equals(monthIntString))
            {
                string endMonthString = Convert.ToString(Convert.ToInt32(monthIntString) + 1).PadLeft(2, '0');
                endDate = Convert.ToDateTime(endMonthString+"/01/"+year);
            }else
            {
                string endMonthString = "01";
                string endYear = (Convert.ToInt32(year) + 1).ToString();
                endDate = Convert.ToDateTime(endMonthString + "/01/" + endYear);
            }
            List<FlickrPhoto> photosToReturn = new List<FlickrPhoto>();
            Flickr flickr = getFlickrObject();
            var options = new PhotoSearchOptions { MediaType = MediaType.Photos, PerPage = perPage, Page = pageNum, UserId = app.accountId, Extras = (PhotoSearchExtras.DateTaken | PhotoSearchExtras.OriginalUrl | PhotoSearchExtras.Tags), SortOrder = PhotoSearchSortOrder.DateTakenDescending, MinTakenDate= startDate,MaxTakenDate=endDate };
            if (!"*".Equals(searchTerm))
            {
                options.Tags = searchTerm;
            }
            PhotoCollection photos = await flickr.PhotosSearchAsync(options);
            foreach (Photo photo in photos)
            {
                FlickrPhoto p = new FlickrPhoto();
                p.Title = photo.Title;
                p.Url = photo.WebUrl;
                p.keywords = photo.Tags.ToList();
                p.Farm = Convert.ToInt32(photo.Farm);
                p.Id = Convert.ToInt64(photo.PhotoId);
                p.Secret = photo.Secret;
                p.Server = Convert.ToInt32(photo.Server);
                if (p.keywords.Contains(app.tagToAddString.ToLower()))
                {
                    p.tagImage = App.FAVORITE_ICON;
                }
                else
                {
                    p.tagImage = App.NOT_FAVORITE_ICON;
                }
                photosToReturn.Add(p);


            }
            return photosToReturn;
        }