private async void loadRecipe(int id)
        {
            string              page     = Config.URL_JSON_ID + id;
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(page);

            HttpContent content = response.Content;

            string output = await content.ReadAsStringAsync();

            if (output != null)
            {
                recipe = JsonConvert.DeserializeObject <Recipe>(output);
            }

            fillRectanglesWithColors(recipe.getCategoryInteger());
            fillXamlElements(recipe);

            bool fileExists = await storageManager.createFile();

            if (fileExists)
            {
                isFav = await storageManager.isFavorite(id);

                img_star.Source = (isFav) ? new BitmapImage()
                {
                    UriSource = new Uri("ms-appx:///Assets/star_full.png", UriKind.Absolute)
                } : new BitmapImage()
                {
                    UriSource = new Uri("ms-appx:///Assets/star_empty.png", UriKind.Absolute)
                };
            }

            if (recipe.getImageString().Length != 0)
            {
                try
                {
                    page = Config.URL_GALLERY + recipe.getImageString();
                    Stream st = await client.GetStreamAsync(page);

                    var memoryStream = new MemoryStream();
                    await st.CopyToAsync(memoryStream);

                    memoryStream.Position = 0;
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(memoryStream.AsRandomAccessStream());

                    img_main.Source = bitmap;
                }
                catch (Exception e)
                {
                }
            }
            prog_recipe.IsActive = false;
        }
        public async Task <List <MainListboxModel> > getFavorites()
        {
            List <MainListboxModel> list           = new List <MainListboxModel>();
            StorageManager          storageManager = new StorageManager();

            for (int x = 0; x < listboxItems.Count; x++)
            {
                bool fav = await storageManager.isFavorite(listboxItems[x].id);

                if (fav)
                {
                    list.Add(listboxItems[x]);
                }
            }
            return(list);
        }
Пример #3
0
 public async Task<List<MainListboxModel>> getFavorites()
 {
     List<MainListboxModel> list = new List<MainListboxModel>();
     StorageManager storageManager = new StorageManager();
     
     for (int x = 0; x < listboxItems.Count; x++)
     {
         bool fav = await storageManager.isFavorite(listboxItems[x].id);
         if (fav)                
             list.Add(listboxItems[x]);                
     }
     return list;
 }