public static GroupedListViewModel CreateNew <TSchema>(SectionConfigBase <TSchema> sectionConfig) where TSchema : SchemaBase
        {
            var vm = new GroupedListViewModel
            {
                SectionName  = sectionConfig.Name,
                Title        = sectionConfig.ListPage.Title,
                PageTitle    = sectionConfig.ListPage.PageTitle,
                HasLocalData = !sectionConfig.NeedsNetwork,
                _orderType   = sectionConfig.ListPage.OrderType
            };

            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 = (refresh) => AppCache.LoadItemsAsync <TSchema>(settings, sectionConfig.LoadDataAsyncFunc, (content) => vm.ParseItems(sectionConfig.ListPage, content), refresh);

            if (sectionConfig.NeedsNetwork)
            {
                vm.Actions.Add(new ActionInfo
                {
                    Command    = vm.Refresh,
                    Style      = ActionKnownStyles.Refresh,
                    Name       = "RefreshButton",
                    ActionType = ActionType.Primary
                });
            }

            return(vm);
        }
Ejemplo n.º 2
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.º 3
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);
        }