Пример #1
0
        private async Task ClearCacheAsync()
        {
            var files1 = await CacheUtil.GetCachedFileFolder().GetItemsAsync();

            foreach (var file in files1)
            {
                await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }
            var files2 = await CacheUtil.GetTempFolder().GetItemsAsync();

            foreach (var file in files2)
            {
                await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }

            ToastService.SendToast("All clear.", TimeSpan.FromMilliseconds(1000));
        }
Пример #2
0
        private Task DoCleanUpAsync()
        {
            return(Task.Run(async() =>
            {
                var localFiles = await CacheUtil.GetCachedFileFolder().GetItemsAsync();
                foreach (var file in localFiles)
                {
                    await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }

                var tempFiles = await CacheUtil.GetTempFolder().GetItemsAsync();
                foreach (var file in tempFiles)
                {
                    await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }
            }));
        }
Пример #3
0
        private async Task ClearCacheAsync()
        {
            CacheHint = $"Clean up cache (0 MB)";
            ToastService.SendToast("All clear.", TimeSpan.FromMilliseconds(1000));

            var localFiles = await CacheUtil.GetCachedFileFolder().GetItemsAsync();

            foreach (var file in localFiles)
            {
                await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }

            var tempFiles = await CacheUtil.GetTempFolder().GetItemsAsync();

            foreach (var file in tempFiles)
            {
                await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }
        }
Пример #4
0
        private async Task RestoreMainListDataAsync()
        {
            var file = await CacheUtil.GetCachedFileFolder().TryGetFileAsync(CachedFileNames.MainListFileName);

            if (file != null)
            {
                var list = await SerializerHelper.DeserializeFromJsonByFile <IncrementalLoadingCollection <UnsplashImage> >(CachedFileNames.MainListFileName, CacheUtil.GetCachedFileFolder());

                if (list != null)
                {
                    this.MainDataVM = new ImageDataViewModel(this, UrlHelper.GetFeaturedImages);
                    list.ToList().ForEach(s => MainDataVM.DataList.Add(s));

                    for (int i = 0; i < MainDataVM.DataList.Count; i++)
                    {
                        var item = MainDataVM.DataList[i];
                        if (i % 2 == 0)
                        {
                            item.BackColor = new SolidColorBrush(ColorConverter.HexToColor("#FF2E2E2E").Value);
                        }
                        else
                        {
                            item.BackColor = new SolidColorBrush(ColorConverter.HexToColor("#FF383838").Value);
                        }
                        var task = item.RestoreAsync();
                    }
                    await UpdateLiveTileAsync();
                }
                else
                {
                    MainDataVM = new ImageDataViewModel(this, UrlHelper.GetFeaturedImages);
                }
            }
            else
            {
                MainDataVM = new ImageDataViewModel(this, UrlHelper.GetFeaturedImages);
            }
        }
Пример #5
0
        private async Task RestoreMainListDataAsync()
        {
            var file = await CacheUtil.GetCachedFileFolder().TryGetFileAsync(CachedFileNames.MainListFileName);

            if (file != null)
            {
                var list = await SerializerHelper.DeserializeFromJsonByFile <IncrementalLoadingCollection <UnsplashImageBase> >(CachedFileNames.MainListFileName, CacheUtil.GetCachedFileFolder());

                if (list != null)
                {
                    this.MainDataVM = new ImageDataViewModel(this, UrlHelper.GetNewImages, true);
                    list.ToList().ForEach(s => MainDataVM.DataList.Add(s));

                    for (int i = 0; i < MainDataVM.DataList.Count; i++)
                    {
                        var item = MainDataVM.DataList[i];
                        if (i % 2 == 0)
                        {
                            item.BackColor = App.Current.Resources["ImageBackBrush1"] as SolidColorBrush;
                        }
                        else
                        {
                            item.BackColor = App.Current.Resources["ImageBackBrush2"] as SolidColorBrush;
                        }
                        var task = item.RestoreDataAsync();
                    }
                }
                else
                {
                    MainDataVM = new ImageDataViewModel(this, UrlHelper.GetNewImages, true);
                }
            }
            else
            {
                MainDataVM = new ImageDataViewModel(this, UrlHelper.GetNewImages, true);
            }
        }
Пример #6
0
        private async Task RestoreMainListDataAsync()
        {
            DataVM = new ImageDataViewModel(UrlHelper.GetNewImages, false);

            if (AppSettings.Instance.DefaultCategory == 0)
            {
                return;
            }
            var file = await CacheUtil.GetCachedFileFolder().TryGetFileAsync(CachedFileNames.MainListFileName);

            if (file != null)
            {
                var str = await FileIO.ReadTextAsync(file);

                var list = JsonConvert.DeserializeObject <List <UnsplashImage> >(str);
                if (list != null)
                {
                    list.ForEach(s => DataVM.DataList.Add(s));

                    for (int i = 0; i < DataVM.DataList.Count; i++)
                    {
                        var item = DataVM.DataList[i];
                        if (i % 2 == 0)
                        {
                            item.BackColor = Application.Current.Resources["ImageBackBrush1"] as SolidColorBrush;
                        }
                        else
                        {
                            item.BackColor = Application.Current.Resources["ImageBackBrush2"] as SolidColorBrush;
                        }
                        var task = item.RestoreDataAsync();
                    }

                    return;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            CacheUtilInstance = new CacheUtil();
            await CacheUtilInstance.LoadAsync();

            GlobalLocaleHelper.SetupLang(null);

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame            = new Frame();
                rootFrame.Background = App.Current.Resources["MyerSplashDarkColor"] as SolidColorBrush;

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter

                if (!LocalSettingHelper.HasValue("UPDATED_TO_1.1"))
                {
                    var files1 = await CacheUtil.GetCachedFileFolder().GetItemsAsync();

                    foreach (var file in files1)
                    {
                        await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                    var files2 = await CacheUtil.GetTempFolder().GetItemsAsync();

                    foreach (var file in files2)
                    {
                        await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                    LocalSettingHelper.AddValue("UPDATED_TO_1.1", true);
                }

                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();

            TitleBarHelper.SetUpThemeTitleBar();
            if (DeviceHelper.IsMobile)
            {
                StatusBarHelper.SetUpStatusBar();
            }

            SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
            if (APIInfoHelper.HasHardwareButton)
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }
        }
Пример #8
0
 private async Task SaveMainListDataAsync()
 {
     if (this.MainDataVM.DataList?.Count > 0)
     {
         await SerializerHelper.SerializerToJson <IncrementalLoadingCollection <UnsplashImageBase> >(this.MainDataVM.DataList, CachedFileNames.MainListFileName, CacheUtil.GetCachedFileFolder());
     }
 }
Пример #9
0
        private async Task SaveMainListDataAsync()
        {
            if (this.MainDataVM.DataList?.Count > 0)
            {
                await SerializerHelper.SerializerToJson <IncrementalLoadingCollection <UnsplashImage> >(this.MainDataVM.DataList, CachedFileNames.MainListFileName, CacheUtil.GetCachedFileFolder());

                //if (MainList?.ToList().FirstOrDefault()?.ID != MainDataVM?.DataList?.FirstOrDefault()?.ID && SelectedIndex == 0)
                //{
                //    MainList = MainDataVM.DataList;
                //}
            }
        }
Пример #10
0
        private async Task GetCategoriesAsync()
        {
            if (Categories?.Count > 0)
            {
                return;
            }

            var result = await CloudService.GetCategories(CTSFactory.MakeCTS(20000).Token);

            if (result.IsRequestSuccessful)
            {
                var list = UnsplashCategory.GenerateListFromJson(result.JsonSrc);
                this.Categories = list;
                this.Categories.Insert(0, new UnsplashCategory()
                {
                    Title = "Featured",
                });
                this.Categories.Insert(0, new UnsplashCategory()
                {
                    Title = "New",
                });
                this.Categories.Insert(0, new UnsplashCategory()
                {
                    Title = "Random",
                });
                SelectedIndex = NEW_INDEX;
                await SerializerHelper.SerializerToJson <ObservableCollection <UnsplashCategory> >(list, CachedFileNames.CateListFileName, CacheUtil.GetCachedFileFolder());
            }
        }