Ejemplo n.º 1
0
        public static DetailViewModel CreateNew <TSchema, TRelatedSchema>(SectionConfigBase <TSchema, TRelatedSchema> sectionConfig) where TSchema : SchemaBase where TRelatedSchema : SchemaBase
        {
            var vm = new DetailViewModel
            {
                Title       = sectionConfig.DetailPage.Title,
                SectionName = sectionConfig.Name
            };

            vm.RelatedContentTitle = sectionConfig.RelatedContent?.ListPage?.Title;

            var settings = new CacheSettings
            {
                Key          = sectionConfig.Name,
                Expiration   = vm.CacheExpiration,
                NeedsNetwork = sectionConfig.NeedsNetwork,
                UseStorage   = sectionConfig.NeedsNetwork,
            };

            //we save a reference to the load delegate in order to avoid export TSchema outside the view model
            vm.LoadDataInternal = async(selectedItem) =>
            {
                TSchema sourceSelected = null;

                await AppCache.LoadItemsAsync <TSchema>(settings, sectionConfig.LoadDataAsyncFunc, (content) => vm.ParseDetailItems(sectionConfig.DetailPage, content, selectedItem, out sourceSelected));

                if (sectionConfig.RelatedContent != null)
                {
                    var settingsRelated = new CacheSettings
                    {
                        Key          = $"{sectionConfig.Name}_related_{selectedItem.Id}",
                        Expiration   = vm.CacheExpiration,
                        NeedsNetwork = sectionConfig.RelatedContent.NeedsNetwork
                    };

                    vm.RelatedContentStatus = ResourceLoader.GetString("LoadingRelatedContent");
                    await AppCache.LoadItemsAsync <TRelatedSchema>(settingsRelated, () => sectionConfig.RelatedContent.LoadDataAsync(sourceSelected), (content) => vm.ParseRelatedItems(sectionConfig.RelatedContent.ListPage, content));

                    if (vm.RelatedItems == null || vm.RelatedItems.Count == 0)
                    {
                        vm.RelatedContentStatus = ResourceLoader.GetString("ThereIsNotRelatedContent");
                    }
                    else
                    {
                        vm.RelatedContentStatus = string.Empty;
                    }
                }
            };

            return(vm);
        }
Ejemplo n.º 2
0
        public static DetailViewModel CreateNew <TSchema>(SectionConfigBase <TSchema> sectionConfig) where TSchema : SchemaBase
        {
            var vm = new DetailViewModel
            {
                Title = sectionConfig.DetailPage.Title
            };

            var settings = new CacheSettings
            {
                Key          = sectionConfig.Name,
                Expiration   = vm.CacheExpiration,
                NeedsNetwork = sectionConfig.NeedsNetwork,
                UseStorage   = sectionConfig.NeedsNetwork,
            };

            //we save a reference to the load delegate in order to avoid export TSchema outside the view model
            vm.LoadDataInternal = async(selectedItem) =>
            {
                await AppCache.LoadItemsAsync <TSchema>(settings, sectionConfig.LoadDataAsyncFunc, (content) => vm.ParseDetailItems(sectionConfig.DetailPage, content, selectedItem));
            };

            return(vm);
        }