Ejemplo n.º 1
0
        public MainViewModel(int visibleItems) : base()
        {
            PageTitle                 = "Windows 10 News";
            WhatsGoingOn              = new ListViewModel <RssDataConfig, RssSchema>(new WhatsGoingOnConfig(), visibleItems);
            RecentNews                = new ListViewModel <RssDataConfig, RssSchema>(new RecentNewsConfig(), visibleItems);
            Apps                      = new ListViewModel <RssDataConfig, RssSchema>(new AppsConfig(), visibleItems);
            InsiderProgram            = new ListViewModel <RssDataConfig, RssSchema>(new InsiderProgramConfig(), visibleItems);
            WhatArePeopleTalkingAbout = new ListViewModel <TwitterDataConfig, TwitterSchema>(new WhatArePeopleTalkingAboutConfig(), visibleItems);
            DoMore                    = new ListViewModel <InstagramDataConfig, InstagramSchema>(new DoMoreConfig(), visibleItems);
            Actions                   = new List <ActionInfo>();

            if (GetViewModels().Any(vm => !vm.HasLocalData))
            {
                Actions.Add(new ActionInfo
                {
                    Command    = new RelayCommand(Refresh),
                    Style      = ActionKnownStyles.Refresh,
                    Name       = "RefreshButton",
                    ActionType = ActionType.Primary
                });
            }
        }
Ejemplo n.º 2
0
        public static ListViewModel CreateNew <TSchema>(SectionConfigBase <TSchema> sectionConfig, int visibleItems = 0) where TSchema : SchemaBase
        {
            var vm = new ListViewModel
            {
                SectionName    = sectionConfig.Name,
                Title          = sectionConfig.ListPage.Title,
                NavigationInfo = sectionConfig.ListPage.ListNavigationInfo,
                PageTitle      = sectionConfig.ListPage.PageTitle,
                _visibleItems  = visibleItems,
                HasLocalData   = !sectionConfig.NeedsNetwork
            };

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

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

            return(vm);
        }