コード例 #1
0
        public async Task ReadRecipeData()
        {
            await _dataSvc.SyncOfflineCache();

            var recipes = await _dataSvc.GetAllRecipes();

            // iOS doesn't like things to be added on anything but the main thread
            Device.BeginInvokeOnMainThread(() =>
            {
                var easyGrouping = AllRecipes.First((arg) => arg.Title == Difficulty.Easy);
                var medGrouping  = AllRecipes.First((arg) => arg.Title == Difficulty.Medium);
                var hardGrouping = AllRecipes.First((arg) => arg.Title == Difficulty.Hard);

                // This goes through and does a wholesale clean of the groupings
                easyGrouping.Clear();
                medGrouping.Clear();
                hardGrouping.Clear();

                // Then adds everything back in
                foreach (var item in recipes)
                {
                    if (item.Difficulty == Difficulty.Easy)
                    {
                        easyGrouping.Add(item);
                    }
                    else if (item.Difficulty == Difficulty.Medium)
                    {
                        medGrouping.Add(item);
                    }
                    else if (item.Difficulty == Difficulty.Hard)
                    {
                        hardGrouping.Add(item);
                    }
                }
            });
        }