Beispiel #1
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var model = value as ModelPropertyBase;

            if (model != null)
            {
                if (model.playInfo.Count > 1)
                {
                    var p = from m in model.playInfo
                            where m.name == (AppEnvironment.IsWlanOrInternet ? "高清" : "标清")
                            select m;
                    var playInfo = p.FirstOrDefault() as Playinfo;
                    if (playInfo != null)
                    {
                        DicStore.AddOrUpdateValue <int>(AppCommonConst.CURRENT_VIDEO_SOLUTION_SELECTED_INDEX, model.playInfo.IndexOf(playInfo));
                        return(playInfo.url);
                    }
                    else
                    {
                        return(model.playUrl);
                    }
                }
                else
                {
                    return(model.playUrl);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            //及时将当前PastCategoryDetail的请求链接置为null,以便下次访问的时候能够正确设置好请求链接
            DicStore.AddOrUpdateValue <string>(AppCommonConst.PAST_CATEGORY_DETAIL_NEXT_PAGE_URL, null);
        }
Beispiel #3
0
        private async void grid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (AppEnvironment.IsInternetAccess)
            {
                var control = sender as FrameworkElement;
                if (control != null)
                {
                    var model = control.DataContext as AuthorData;
                    if (model != null)
                    {
                        //如果解析出错
                        if (model.actionId == (int)CategoryErrorType.ERROR)
                        {
                            await new MessageDialog(AppNetworkMessageConst.DATA_PRE_COMBINE_IS_ERROR, "提示").ShowAsyncQueue();
                        }
                        //如果暂不支持此类型的跳转
                        else if (model.actionId == (int)CategoryErrorType.UNSUPPORT)
                        {
                            await new MessageDialog(AppNetworkMessageConst.DATA_UNSUPPORT, "提示").ShowAsyncQueue();
                        }
                        else
                        {
                            var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                            if (animationGrid != null)
                            {
                                if (AppEnvironment.IsPhone)
                                {
                                    await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                                    {
                                        Duration = 0.25, Distance = 400
                                    });
                                }
                                else
                                {
                                    await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                                    {
                                        Duration = 0.13, Distance = 600
                                    });
                                }
                            }

                            //名称的记录和暂存暂时用CURRENT_PAST_CATEGORY_DETAIL_NAME字段来替代
                            DicStore.AddOrUpdateValue <string>(AppCommonConst.CURRENT_PAST_CATEGORY_DETAIL_NAME, AppEnvironment.IsPhone ? "" : model.title);
                            DicStore.AddOrUpdateValue <int>(AppCommonConst.CURRENT_AUTHOR_DETAIL_ACTION_ID, model.actionId);

                            CommonHelper.Instance.NavigateWithOverride(typeof(AuthorDetailPage));

                            if (animationGrid != null)
                            {
                                await animationGrid.AnimateAsync(new ResetAnimation());
                            }
                        }
                    }
                }
            }
            else
            {
                await new MessageDialog(AppNetworkMessageConst.NETWORK_IS_OFFLINEL, "提示").ShowAsyncQueue();
            }
        }
Beispiel #4
0
 private void solutionListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (this.solutionListView.SelectedIndex != -1)
     {
         DicStore.AddOrUpdateValue <int>(AppCommonConst.CURRENT_VIDEO_SOLUTION_SELECTED_INDEX, this.solutionListView.SelectedIndex);
     }
 }
Beispiel #5
0
        protected override async void OnUIControlBaseNeedNavigate(object sender, PointerRoutedEventArgs e)
        {
            base.OnUIControlBaseNeedNavigate(sender, e);

            var szListPC = CommonHelper.Instance.GetCurrentSemanticZoom("szListPC");

            if (szListPC != null)
            {
                if (szListPC.IsZoomedInViewActive == true)
                {
                    var control = sender as FrameworkElement;
                    if (control != null)
                    {
                        var model = control.DataContext as ModelPropertyBase;
                        if (model != null)
                        {
                            DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);

                            szListPC.IsZoomedInViewActive = false;

                            ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;

                            await this.coverGrid.AnimateAsync(new ResetAnimation());
                        }
                    }
                }
            }

            ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;
        }
        private async void Grid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var grid = sender as Grid;

            if (grid != null)
            {
                var model = grid.DataContext as NewsModelPropertyBase;
                if (model != null)
                {
                    var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                    if (animationGrid != null)
                    {
                        //if (AppEnvironment.IsPhone)
                        //{
                        //    await animationGrid.AnimateAsync(new FadeOutLeftAnimation() { Distance = 300 });
                        //}
                        //else
                        //{
                        await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                        {
                            Duration = 0.3, Distance = 400
                        });

                        //}
                    }

                    //记录当前的模型Model以便在网页成功加载后能够更改条目的标题颜色
                    DicStore.AddOrUpdateValue <NewsModelPropertyBase>(AppCommonConst.CURRENT_NEWS_MODEL, model);

                    CommonHelper.Instance.NavigateWithOverride(typeof(NewsDetailPage));

                    await animationGrid.AnimateAsync(new ResetAnimation());
                }
            }
        }
Beispiel #7
0
        private void GridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var gridView = sender as GridView;

            if (gridView != null)
            {
                DicStore.AddOrUpdateValue <int>(AppCommonConst.CUR_PIVOT_SELECTED_INDEX, gridView.SelectedIndex);
            }
        }
        private async void OnMyUIControlBaseNeedNavigate(object sender, PointerRoutedEventArgs e)
        {
            var control = sender as FrameworkElement;

            if (control != null)
            {
                var model = control.DataContext as ModelPropertyBase;
                if (model != null)
                {
                    var szPC = CommonHelper.Instance.GetCurrentSemanticZoom("szPC");
                    if (szPC != null)
                    {
                        if (model.isAleadyDownload)
                        {
                            DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);
                            szPC.IsZoomedInViewActive = false;
                        }
                        else if (AppEnvironment.IsInternetAccess)
                        {
                            if (AppEnvironment.IsWlanOrInternet)
                            {
                                DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);
                                szPC.IsZoomedInViewActive = false;
                            }
                            else
                            {
                                bool isPlayAccepted = false;

                                var messageDialog = new MessageDialog(AppNetworkMessageConst.NETWORK_IS_NOT_WIFI_OR_LAN_TO_PLAY, "播放提示");

                                messageDialog.Commands.Add(new UICommand("继续", new UICommandInvokedHandler(uc =>
                                {
                                    isPlayAccepted = true;
                                })));

                                messageDialog.Commands.Add(new UICommand("取消"));

                                messageDialog.DefaultCommandIndex = 1;

                                await messageDialog.ShowAsyncQueue();

                                if (isPlayAccepted)
                                {
                                    DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);
                                    szPC.IsZoomedInViewActive = false;
                                }
                            }
                        }
                        else
                        {
                            await new MessageDialog(AppNetworkMessageConst.NETWORK_IS_OFFLINEL, "提示").ShowAsyncQueue();
                        }
                    }
                }
            }
        }
        private void rankListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.rankListView.SelectedIndex != -1)
            {
                DicStore.AddOrUpdateValue <int>(AppCommonConst.CURRENT_RANK_LIST_SELECTED_INDEX, this.rankListView.SelectedIndex);

                Messenger.Default.Send <int>(this.rankListView.SelectedIndex, AppMessengerTokenConst.IS_RANK_LIST_SELECTED);

                Debug.WriteLine("我被触发2");
            }
        }
Beispiel #10
0
        public async void ShowRetry(string msg, Type fromType, string method, object[] parameters)
        {
            await DispatcherHelper.RunAsync(async() =>
            {
                try
                {
                    //HideRetry();

                    RetryUIControl ruc = new RetryUIControl();
                    ruc.msg            = msg;
                    ruc.fromType       = fromType;
                    ruc.method         = method;
                    ruc.parameters     = parameters;


                    if (popup == null)
                    {
                        popup = new Popup();
                    }

                    if (!popup.IsOpen)
                    {
                        popup.Child = ruc;

                        popup.IsLightDismissEnabled = false;
                        //应当占据NavigationRootPage的rootFrame区域,此区域距离左和上的距离都为48,在加上Pivot的Header头高度为45(已取消)
                        //popup.VerticalOffset = 48;
                        //if (!AppEnvironment.IsPhone)
                        //{
                        //    popup.HorizontalOffset = 48;
                        //}


                        if (DicStore.GetValueOrDefault <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, false))
                        {
                            //如果是第一次显示,并且加载出错要显示RetryBox的时候,判断欢迎屏幕是否还在,如果欢迎屏幕还在则等待2300毫秒,如果不在的话,则立即显示RetryBox。
                            //情况举例:1、立刻显示的情况:比如网络比较慢,当欢迎屏幕消失后还在加载数据,结果加载失败了,(网络和本地都加在失败,本地加载失败有两种情况,一种是本地无缓存,二是本地缓存文件结构损坏了,就是页面上没数据),此时应该立刻显示RetryBox,不应等待2300毫秒。2、等待2300毫秒显示的情况:当网络无连接,数据加载失败,本地和网络都没能正确获取到数据,此时IsBusy已经为false,Progress已经消失,但此时的欢迎屏幕还在,此时就应高等待2300毫秒,让欢迎屏幕消失之后再显示RetryBox。这次是正确的处理逻辑
                            if (WelcomeBox.Instance.IsWelcomeShow)
                            {
                                await Task.Delay(2000);
                            }
                        }

                        popup.IsOpen = true;

                        DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, false);
                    }
                }
                catch { }
            });
        }
Beispiel #11
0
        private void OpenEdit()
        {
            var trans = this.guestureGrid.GetHorizontalOffset().Transform;

            trans.AnimateX(trans.X, -95, 300, 0, new CubicEase
            {
                EasingMode = EasingMode.EaseOut
            });

            isEditOpen = true;

            ViewModelLocator.Instance.FavoriteOrDownloadListViewScrollHandler += CancelEditding;

            DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_HAS_DOWNLOAD_EDITING, true);
        }
Beispiel #12
0
        private async void appBarRefreshBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!SimpleIoc.Default.IsRegistered <DailyViewModel>())
            {
                SimpleIoc.Default.Register <DailyViewModel>();
            }

            var dailyViewModel = SimpleIoc.Default.GetInstance <DailyViewModel>();

            if (dailyViewModel != null && !dailyViewModel.IsBusy && DicStore.GetValueOrDefault <bool>(AppCommonConst.DAILY_HAS_NEXT_PAGE, false))
            {
                if (AppEnvironment.IsInternetAccess)
                {
                    //及时将当前的nextPageUrl置为null
                    DicStore.AddOrUpdateValue <string>(AppCommonConst.DAILY_NEXT_PAGE_URL, null);
                    dailyViewModel.GetDaily(dailyViewModel.DailyCollection, dailyViewModel.DailyFlipViewCollection, ApiDailyRoot.Instance.DailyUrl, AppCacheNewsFileNameConst.CACHE_DAILY_FILENAME, true);
                }
                else
                {
                    await new MessageDialog(AppNetworkMessageConst.NETWORK_IS_OFFLINEL, "提示").ShowAsyncQueue();
                }
            }


            //try
            //{
            //    var rp = DicStore.GetValueOrDefault<RetryParameter>(AppCommonConst.RETRY_PARAMETER, null);
            //    if (rp != null)
            //    {
            //        Type fromType = rp.fromType;

            //        string method = rp.method;

            //        object[] parameters = rp.parameters;

            //        parameters[parameters.Count() - 1] = true;

            //        object o = Activator.CreateInstance(fromType);

            //        object obj2 = fromType.GetMethod(method).Invoke(o, parameters);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    string s = ex.Message;
            //}
        }
        private async void grid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var grid = sender as Grid;

            if (grid != null)
            {
                var model = grid.DataContext as MapModel;
                if (model != null)
                {
                    var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                    if (animationGrid != null)
                    {
                        if (AppEnvironment.IsPhone)
                        {
                            await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                            {
                                Duration = 0.3, Distance = 400
                            });
                        }
                        else
                        {
                            await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                            {
                                Duration = 0.13, Distance = 600
                            });
                        }
                    }

                    DicStore.AddOrUpdateValue <int>(AppCommonConst.CURRENT_MAP_ID, Convert.ToInt32(model.id));

                    CommonHelper.Instance.NavigateWithOverride(typeof(MapDetailPage));

                    if (!AppEnvironment.IsPhone)
                    {
                        var tb = CommonHelper.Instance.GetRootPageSubTitle();
                        if (tb != null)
                        {
                            tb.Text = " / " + model.map_name;
                        }
                    }

                    await animationGrid.AnimateAsync(new ResetAnimation());
                }
            }
        }
Beispiel #14
0
        protected override async void OnUIControlBaseNeedNavigate(object sender, PointerRoutedEventArgs e)
        {
            base.OnUIControlBaseNeedNavigate(sender, e);

            if (this.guestureGrid.GetHorizontalOffset().Value == 0 && !isAlreadyTryManipulation)
            {
                var isAlreadyCollectionEditing = DicStore.GetValueOrDefault <bool>(AppCommonConst.IS_HAS_DOWNLOAD_EDITING, false);
                if (isAlreadyCollectionEditing == true)
                {
                    ViewModelLocator.Instance.FavoriteOrDownloadListViewScroll();
                    return;
                }

                var ctrl = sender as FrameworkElement;
                if (ctrl != null)
                {
                    var model = ctrl.DataContext as ModelPropertyBase;
                    if (model != null)
                    {
                        if (!model.isEditing)
                        {
                            var szListPC = CommonHelper.Instance.GetCurrentSemanticZoom("szListPC");
                            if (szListPC != null)
                            {
                                if (szListPC.IsZoomedInViewActive == true)
                                {
                                    DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);

                                    szListPC.IsZoomedInViewActive = false;

                                    ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;

                                    await this.coverGrid.AnimateAsync(new ResetAnimation());
                                }
                            }
                        }
                    }
                }
            }

            ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;

            isAlreadyTryManipulation = false;
        }
Beispiel #15
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedFrom(e);

            if (e.NavigationMode == NavigationMode.Back)
            {
                //及时将当前PastCategoryDetail的请求链接置为null,以便下次访问的时候能够正确设置好请求链接
                DicStore.AddOrUpdateValue <string>(AppCommonConst.AUTHOR_DETAIL_NEXT_PAGE_URL, null);
                //及时将当前要请求的类别名称设为""
                DicStore.AddOrUpdateValue <string>(AppCommonConst.CURRENT_PAST_CATEGORY_DETAIL_NAME, "");

                if (authorDetailViewModel != null)
                {
                    authorDetailViewModel.Cleanup();

                    SimpleIoc.Default.Unregister <AuthorDetailViewModel>();
                }
            }
        }
Beispiel #16
0
        private void CloseEdit()
        {
            ViewModelLocator.Instance.FavoriteOrDownloadListViewScrollHandler -= CancelEditding;
            DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_HAS_DOWNLOAD_EDITING, false);

            var trans = this.guestureGrid.GetHorizontalOffset().Transform;

            trans.AnimateX(trans.X, 0, 300, 0, new CubicEase
            {
                EasingMode = EasingMode.EaseOut
            }, async() =>
            {
                await DispatcherHelper.RunAsync(() =>
                {
                    this.editGrid.Opacity = 0.0;
                });
            });
            isAlreadyTryManipulation = false;
            isEditOpen = false;
        }
        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            ViewModelLocator.Instance.FavoriteOrDownloadListViewScrollHandler -= CancelEditding;
            DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_HAS_COLLECTION_EDITING, false);

            var trans = this.guestureGrid.GetHorizontalOffset().Transform;

            trans.AnimateX(trans.X, 0, 300, 0, new CubicEase
            {
                EasingMode = EasingMode.EaseOut
            }, async() =>
            {
                await DispatcherHelper.RunAsync(() =>
                {
                    this.editGrid.Opacity = 0.0;
                    gridEdit_Tapped(sender, null);
                });
            });
            isAlreadyTryManipulation = false;
            isEditOpen = false;
        }
        private async void grid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var grid = sender as Grid;

            if (grid != null)
            {
                var videoNewsModel = grid.DataContext as NewsModel;
                if (videoNewsModel != null && videoNewsModel.IsVideo)
                {
                    var videoInfo = videoNewsModel.backup3;
                    if (videoInfo != null)
                    {
                        VideoPlayBox.Instance.ShowVideo(videoInfo.vid, videoNewsModel.title, null);
                    }
                }
                else
                {
                    var model = grid.DataContext as NewsModelPropertyBase;

                    if (model != null)
                    {
                        var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                        if (animationGrid != null)
                        {
                            await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                            {
                                Duration = 0.13, Distance = 600
                            });
                        }

                        //记录当前的模型Model以便在网页成功加载后能够更改条目的标题颜色
                        DicStore.AddOrUpdateValue <NewsModelPropertyBase>(AppCommonConst.CURRENT_NEWS_MODEL, model);

                        CommonHelper.Instance.NavigateWithOverride(typeof(NewsDetailPage));

                        await animationGrid.AnimateAsync(new ResetAnimation());
                    }
                }
            }
        }
Beispiel #19
0
        public async void GetDaily(ObservableCollection <Videolist> collection, ObservableCollection <Videolist> flipViewCollection, string url, string cacheFileName = null, bool isRefresh = false)
        {
            //这里是为了异步,在无网络加载读取本地缓存文本的时候不会卡界面
            DispatcherHelper.RunAsync(async() =>
            {
                IsBusy = true;

                bool is_Campaign_Available = SettingsStore.GetValueOrDefault <bool>(AppCommonConst.IS_CAMPAIGN_AVAILABLE, false);
                string campaign_Image_Url  = SettingsStore.GetValueOrDefault <string>(AppCommonConst.CAMPAIGN_IMAGE_URL, null);
                string campaign_Action_Url = SettingsStore.GetValueOrDefault <string>(AppCommonConst.CAMPAIGN_ACTION_URL, null);

                var backJson = await WebDataHelper.Instance.GetFromUrlWithAuthReturnString(url, null, 20);
                if (backJson != null)
                {
                    var result = JsonConvertHelper.Instance.DeserializeObject <DailyRootModel>(backJson);
                    if (result != null)
                    {
                        if (result.dailyList.Count != 0)
                        {
                            //如果是第一次加载数据或者刷新,则记录当前的刷新时间
                            if (collection.Count == 0 || isRefresh)
                            {
                                SettingsStore.AddOrUpdateValue <string>(AppCommonConst.LAST_UPDATE_TIME, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            }

                            if (isRefresh)
                            {
                                collection.Clear();
                                flipViewCollection.Clear();

                                List <Videolist> myCollection         = new List <Videolist>();
                                List <Videolist> myFlipViewCollection = new List <Videolist>();

                                if (!AppEnvironment.IsPhone)
                                {
                                    result.dailyList[0].videoList.ForEach(B =>
                                    {
                                        myFlipViewCollection.Add(B);
                                    });
                                }
                                else
                                {
                                    result.dailyList.ForEach(A =>
                                    {
                                        if (myCollection.Count != 0)
                                        {
                                            Videolist vl = new Videolist();
                                            vl.today     = A.today;
                                            myCollection.Add(vl);
                                        }
                                        else
                                        {
                                            if (is_Campaign_Available && campaign_Image_Url != null && campaign_Action_Url != null)
                                            {
                                                Videolist vlCam = new Videolist();
                                                //vlCam.is_Campaign_Available = is_Campaign_Available;
                                                vlCam.coverForDetail = campaign_Image_Url;
                                                vlCam.webUrl.raw     = campaign_Action_Url;
                                                myCollection.Add(vlCam);
                                            }
                                        }

                                        A.videoList.ForEach(B =>
                                        {
                                            myCollection.Add(B);
                                            myFlipViewCollection.Add(B);
                                        });
                                    });
                                }

                                #region 处理 收藏 和 下载
                                if (!SimpleIoc.Default.IsRegistered <CollectionViewModel>())
                                {
                                    SimpleIoc.Default.Register <CollectionViewModel>(false);
                                }
                                var cvm = SimpleIoc.Default.GetInstance <CollectionViewModel>();

                                if (cvm != null)
                                {
                                    myFlipViewCollection.ForEach(A =>
                                    {
                                        var model = from m in cvm.FavoriteCollection
                                                    where A.id == m.id
                                                    select A;
                                        if (model.Count() != 0)
                                        {
                                            A.isFavorite = true;
                                        }
                                    });
                                }

                                if (!SimpleIoc.Default.IsRegistered <DownloadViewModel>())
                                {
                                    SimpleIoc.Default.Register <DownloadViewModel>(false);
                                }
                                var dlvm = SimpleIoc.Default.GetInstance <DownloadViewModel>();

                                if (dlvm != null)
                                {
                                    myFlipViewCollection.ForEach(A =>
                                    {
                                        //先去检查下载队列里面有没有
                                        var downloadingModels = from m in dlvm.DownloadingList
                                                                where m.DownloadId == A.id
                                                                select m;
                                        //这里说明有正在下载的,那么应该把当前的Model添加到下载队列里面的DownloadModelList
                                        if (downloadingModels.Count() != 0)
                                        {
                                            var downloadModel = downloadingModels.FirstOrDefault() as DownloadingModel;
                                            if (downloadModel != null)
                                            {
                                                downloadModel.DownloadModelList.Add(A);
                                            }
                                        }
                                        else
                                        {
                                            //然后检查已下载集合里面有没有
                                            var hasDownloadModels = from m in dlvm.DownloadCollection
                                                                    where A.id == m.id
                                                                    select A;
                                            if (hasDownloadModels.Count() != 0)
                                            {
                                                A.isAleadyDownload = true;
                                            }
                                        }
                                    });
                                }

                                #endregion

                                DailyCollection         = new ObservableCollection <Videolist>(myCollection);
                                DailyFlipViewCollection = new ObservableCollection <Videolist>(myFlipViewCollection);

                                myCollection         = null;
                                myFlipViewCollection = null;
                            }
                            else
                            {
                                if (!AppEnvironment.IsPhone)
                                {
                                    result.dailyList[0].videoList.ForEach(B =>
                                    {
                                        flipViewCollection.Add(B);
                                    });
                                }
                                else
                                {
                                    result.dailyList.ForEach(A =>
                                    {
                                        //这个地方是当collection.Count == 0 的时候不添加日期头的处理
                                        if (collection.Count != 0)
                                        {
                                            Videolist vl = new Videolist();
                                            vl.today     = A.today;
                                            collection.Add(vl);
                                        }
                                        else
                                        {
                                            if (is_Campaign_Available && campaign_Image_Url != null && campaign_Action_Url != null)
                                            {
                                                Videolist vlCam = new Videolist();
                                                //vlCam.is_Campaign_Available = is_Campaign_Available;
                                                vlCam.coverForDetail = campaign_Image_Url;
                                                vlCam.webUrl.raw     = campaign_Action_Url;
                                                collection.Add(vlCam);
                                            }
                                        }

                                        A.videoList.ForEach(B =>
                                        {
                                            collection.Add(B);
                                            flipViewCollection.Add(B);
                                        });
                                    });
                                }

                                #region 处理收藏和下载
                                if (!SimpleIoc.Default.IsRegistered <CollectionViewModel>())
                                {
                                    SimpleIoc.Default.Register <CollectionViewModel>(false);
                                }
                                var cvm = SimpleIoc.Default.GetInstance <CollectionViewModel>();

                                if (cvm != null)
                                {
                                    flipViewCollection.ForEach(A =>
                                    {
                                        var model = from m in cvm.FavoriteCollection
                                                    where A.id == m.id
                                                    select A;
                                        if (model.Count() != 0)
                                        {
                                            A.isFavorite = true;
                                        }
                                    });
                                }

                                if (!SimpleIoc.Default.IsRegistered <DownloadViewModel>())
                                {
                                    SimpleIoc.Default.Register <DownloadViewModel>(false);
                                }
                                var dlvm = SimpleIoc.Default.GetInstance <DownloadViewModel>();

                                if (dlvm != null)
                                {
                                    flipViewCollection.ForEach(A =>
                                    {
                                        //先去检查下载队列里面有没有
                                        var downloadingModels = from m in dlvm.DownloadingList
                                                                where m.DownloadId == A.id
                                                                select m;
                                        //这里说明有正在下载的,那么应该把当前的Model添加到下载队列里面的DownloadModelList
                                        if (downloadingModels.Count() != 0)
                                        {
                                            var downloadModel = downloadingModels.FirstOrDefault() as DownloadingModel;
                                            if (downloadModel != null)
                                            {
                                                downloadModel.DownloadModelList.Add(A);
                                            }
                                        }
                                        else
                                        {
                                            //然后检查已下载集合里面有没有
                                            var hasDownloadModels = from m in dlvm.DownloadCollection
                                                                    where A.id == m.id
                                                                    select A;
                                            if (hasDownloadModels.Count() != 0)
                                            {
                                                A.isAleadyDownload = true;
                                            }
                                        }
                                    });
                                }
                                #endregion

                                #region 首屏和磁贴
                                Task.Run(async() =>
                                {
                                    #region 存储每日精选的最新一天的图片。因为加入了动态磁贴,所以无论是手机还是pc都要去下载pc端今日的图片
                                    //if (!AppEnvironment.IsPhone)
                                    //{
                                    if (AppEnvironment.IsNeedToUpdateSplashImage)
                                    {
                                        var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CacheConfig.Instance.PCSplashScreenImageCacheRelativePath, CreationCollisionOption.OpenIfExists);
                                        foreach (var file in await folder.GetFilesAsync())
                                        {
                                            await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                                        }

                                        List <Task> taskList = new List <Task>();

                                        flipViewCollection.Take(8).ForEach(async A =>
                                        {
                                            try
                                            {
                                                var name = EyeSight.Encrypt.MD5Core.Instance.ComputeMD5(A.coverForDetail);

                                                Task task = Task.Run(async() =>
                                                {
                                                    await WebDownFileHelper.Instance.SaveAsyncWithHttp(A.coverForDetail, name, folder);
                                                });

                                                taskList.Add(task);
                                            }
                                            catch { }
                                        });

                                        Task.WhenAll(taskList).ContinueWith(o =>
                                        {
                                            Debug.WriteLine("我刚加载完首屏");

                                            #region 处理磁贴
                                            DicStore.AddOrUpdateValue <object>(AppCommonConst.CURRENT_TILE_COLLECTION, flipViewCollection.Take(5).ToList());
                                            if (SettingsStore.GetValueOrDefault <bool>(AppCommonConst.IS_TILE_ACTIVE, true) == true)
                                            {
                                                TileHelper.Instance.UpdateTiles(flipViewCollection.Take(5).ToList());
                                            }
                                            else
                                            {
                                                TileHelper.Instance.CloseTiles();
                                            }
                                            #endregion

                                            Debug.WriteLine("我加载完磁贴了");
                                        });
                                    }

                                    //}
                                    #endregion
                                });

                                #region 处理磁贴
                                DicStore.AddOrUpdateValue <object>(AppCommonConst.CURRENT_TILE_COLLECTION, flipViewCollection.Take(5).ToList());
                                if (SettingsStore.GetValueOrDefault <bool>(AppCommonConst.IS_TILE_ACTIVE, true) == true)
                                {
                                    TileHelper.Instance.UpdateTiles(flipViewCollection.Take(5).ToList());
                                }
                                else
                                {
                                    TileHelper.Instance.CloseTiles();
                                }
                                #endregion

                                #endregion
                            }

                            Debug.WriteLine("我的数据加载完了");

                            DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, false);

                            //只存第一页的数据
                            if (cacheFileName != null)
                            {
                                //将第一页数据缓存到本地
                                FileHelper.Instance.SaveTextToFile(CacheConfig.Instance.ListFileCacheRelativePath, cacheFileName, backJson);
                            }
                        }
                        else
                        {
                            //判断是不是分页索引第一页,如果是第一页并且获取到的条目个数为0个,则此时要求再次获取。此时提示“没有获取到数据,请重试”
                            if (collection.Count == 0 && !isRefresh)
                            {
                                //这里使用反射
                                RetryBox.Instance.ShowRetry(AppNetworkMessageConst.COLLECTION_ITEM_IS_ZERO, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                            }
                            //如果不是第一页,就不用去管
                            else
                            {
                            }
                        }
                    }
                    else
                    {
                        //判断是不是分页索引第一页,如果是第一页的话则会弹出提示,重新加载。因为第一页没有加载成功,本条目下就没数据,此时就要弹出一个东西让其重新加载数据。如果不是第一页就不用去管了
                        if (collection.Count == 0)
                        {
                            //加载本地数据
                            var localJson = await FileHelper.Instance.ReadTextFromFile(CacheConfig.Instance.ListFileCacheRelativePath, cacheFileName);
                            if (localJson != null)
                            {
                                var localResult = JsonConvertHelper.Instance.DeserializeObject <DailyRootModel>(localJson);
                                if (localResult != null)
                                {
                                    //因为如果第一页获取到的数据为0条时不会写到本地的,所以,从本地获取到的数据条目数一定不为0
                                    if (localResult.dailyList.Count != 0)
                                    {
                                        //不是刷新说明是第一次加载。如果是刷新的话,此处无动作。因为如果数据加载成功的话前面会正确处理,如果数据加载失败了刷新还到这一步的话添加也无用。
                                        if (!isRefresh)
                                        {
                                            if (!AppEnvironment.IsPhone)
                                            {
                                                localResult.dailyList[0].videoList.ForEach(B =>
                                                {
                                                    flipViewCollection.Add(B);
                                                });
                                            }
                                            else
                                            {
                                                localResult.dailyList.ForEach(A =>
                                                {
                                                    if (collection.Count != 0)
                                                    {
                                                        Videolist vl = new Videolist();
                                                        vl.today     = A.today;
                                                        collection.Add(vl);
                                                    }
                                                    else
                                                    {
                                                        if (is_Campaign_Available && campaign_Image_Url != null && campaign_Action_Url != null)
                                                        {
                                                            Videolist vlCam = new Videolist();
                                                            //vlCam.is_Campaign_Available = is_Campaign_Available;
                                                            vlCam.coverForDetail = campaign_Image_Url;
                                                            vlCam.webUrl.raw     = campaign_Action_Url;
                                                            collection.Add(vlCam);
                                                        }
                                                    }

                                                    A.videoList.ForEach(B =>
                                                    {
                                                        collection.Add(B);
                                                        flipViewCollection.Add(B);
                                                    });
                                                });
                                            }

                                            #region 处理收藏和下载
                                            if (!SimpleIoc.Default.IsRegistered <CollectionViewModel>())
                                            {
                                                SimpleIoc.Default.Register <CollectionViewModel>(false);
                                            }
                                            var cvm = SimpleIoc.Default.GetInstance <CollectionViewModel>();

                                            if (cvm != null)
                                            {
                                                flipViewCollection.ForEach(A =>
                                                {
                                                    var model = from m in cvm.FavoriteCollection
                                                                where A.id == m.id
                                                                select A;
                                                    if (model.Count() != 0)
                                                    {
                                                        A.isFavorite = true;
                                                    }
                                                });
                                            }

                                            if (!SimpleIoc.Default.IsRegistered <DownloadViewModel>())
                                            {
                                                SimpleIoc.Default.Register <DownloadViewModel>(false);
                                            }
                                            var dlvm = SimpleIoc.Default.GetInstance <DownloadViewModel>();

                                            if (dlvm != null)
                                            {
                                                flipViewCollection.ForEach(A =>
                                                {
                                                    //先去检查下载队列里面有没有
                                                    var downloadingModels = from m in dlvm.DownloadingList
                                                                            where m.DownloadId == A.id
                                                                            select m;
                                                    //这里说明有正在下载的,那么应该把当前的Model添加到下载队列里面的DownloadModelList
                                                    if (downloadingModels.Count() != 0)
                                                    {
                                                        var downloadModel = downloadingModels.FirstOrDefault() as DownloadingModel;
                                                        if (downloadModel != null)
                                                        {
                                                            downloadModel.DownloadModelList.Add(A);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //然后检查已下载集合里面有没有
                                                        var hasDownloadModels = from m in dlvm.DownloadCollection
                                                                                where A.id == m.id
                                                                                select A;
                                                        if (hasDownloadModels.Count() != 0)
                                                        {
                                                            A.isAleadyDownload = true;
                                                        }
                                                    }
                                                });
                                            }
                                            #endregion

                                            #region 处理磁贴
                                            DicStore.AddOrUpdateValue <object>(AppCommonConst.CURRENT_TILE_COLLECTION, flipViewCollection.Take(5).ToList());
                                            if (SettingsStore.GetValueOrDefault <bool>(AppCommonConst.IS_TILE_ACTIVE, true) == true)
                                            {
                                                TileHelper.Instance.UpdateTiles(flipViewCollection.Take(5).ToList());
                                            }
                                            else
                                            {
                                                TileHelper.Instance.CloseTiles();
                                            }
                                            #endregion
                                        }

                                        DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, false);
                                    }
                                }
                                //虽然错误的数据是不会写到本地的,但如果反序列化失败一样会出错
                                else
                                {
                                    if (!isRefresh)
                                    {
                                        //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                                        if (AppEnvironment.IsInternetAccess)
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                        }
                                        //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                                        else
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_ERROR, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (!isRefresh)
                                {
                                    //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                                    if (AppEnvironment.IsInternetAccess)
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                    }
                                    //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                                    else
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    //判断是不是分页索引第一页,如果是第一页的话则会弹出提示,重新加载。因为第一页没有加载成功,本条目下就没数据,此时就要弹出一个东西让其重新加载数据。如果不是第一页就不用去管了
                    if (collection.Count == 0)
                    {
                        //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                        if (AppEnvironment.IsInternetAccess && !isRefresh)
                        {
                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                        }
                        //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                        else
                        {
                            //加载本地数据
                            var localJson = await FileHelper.Instance.ReadTextFromFile(CacheConfig.Instance.ListFileCacheRelativePath, cacheFileName);
                            if (localJson != null)
                            {
                                var localResult = JsonConvertHelper.Instance.DeserializeObject <DailyRootModel>(localJson);
                                if (localResult != null)
                                {
                                    //因为如果第一页获取到的数据为0条时不会写到本地的,所以,从本地获取到的数据条目数一定不为0
                                    if (localResult.dailyList.Count != 0)
                                    {
                                        //不是刷新说明是第一次加载。如果是刷新的话,此处无动作。因为如果数据加载成功的话前面会正确处理,如果数据加载失败了刷新还到这一步的话添加也无用。
                                        if (!isRefresh)
                                        {
                                            if (!AppEnvironment.IsPhone)
                                            {
                                                localResult.dailyList[0].videoList.ForEach(B =>
                                                {
                                                    flipViewCollection.Add(B);
                                                });
                                            }
                                            else
                                            {
                                                localResult.dailyList.ForEach(A =>
                                                {
                                                    if (collection.Count != 0)
                                                    {
                                                        Videolist vl = new Videolist();
                                                        vl.today     = A.today;
                                                        collection.Add(vl);
                                                    }
                                                    else
                                                    {
                                                        if (is_Campaign_Available && campaign_Image_Url != null && campaign_Action_Url != null)
                                                        {
                                                            Videolist vlCam = new Videolist();
                                                            //vlCam.is_Campaign_Available = is_Campaign_Available;
                                                            vlCam.coverForDetail = campaign_Image_Url;
                                                            vlCam.webUrl.raw     = campaign_Action_Url;
                                                            collection.Add(vlCam);
                                                        }
                                                    }

                                                    A.videoList.ForEach(B =>
                                                    {
                                                        collection.Add(B);
                                                        flipViewCollection.Add(B);
                                                    });
                                                });
                                            }

                                            #region 处理收藏和下载
                                            if (!SimpleIoc.Default.IsRegistered <CollectionViewModel>())
                                            {
                                                SimpleIoc.Default.Register <CollectionViewModel>(false);
                                            }
                                            var cvm = SimpleIoc.Default.GetInstance <CollectionViewModel>();

                                            if (cvm != null)
                                            {
                                                flipViewCollection.ForEach(A =>
                                                {
                                                    var model = from m in cvm.FavoriteCollection
                                                                where A.id == m.id
                                                                select A;
                                                    if (model.Count() != 0)
                                                    {
                                                        A.isFavorite = true;
                                                    }
                                                });
                                            }

                                            if (!SimpleIoc.Default.IsRegistered <DownloadViewModel>())
                                            {
                                                SimpleIoc.Default.Register <DownloadViewModel>(false);
                                            }
                                            var dlvm = SimpleIoc.Default.GetInstance <DownloadViewModel>();

                                            if (dlvm != null)
                                            {
                                                flipViewCollection.ForEach(A =>
                                                {
                                                    //先去检查下载队列里面有没有
                                                    var downloadingModels = from m in dlvm.DownloadingList
                                                                            where m.DownloadId == A.id
                                                                            select m;
                                                    //这里说明有正在下载的,那么应该把当前的Model添加到下载队列里面的DownloadModelList
                                                    if (downloadingModels.Count() != 0)
                                                    {
                                                        var downloadModel = downloadingModels.FirstOrDefault() as DownloadingModel;
                                                        if (downloadModel != null)
                                                        {
                                                            downloadModel.DownloadModelList.Add(A);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //然后检查已下载集合里面有没有
                                                        var hasDownloadModels = from m in dlvm.DownloadCollection
                                                                                where A.id == m.id
                                                                                select A;
                                                        if (hasDownloadModels.Count() != 0)
                                                        {
                                                            A.isAleadyDownload = true;
                                                        }
                                                    }
                                                });
                                            }
                                            #endregion

                                            #region 处理磁贴
                                            DicStore.AddOrUpdateValue <object>(AppCommonConst.CURRENT_TILE_COLLECTION, flipViewCollection.Take(5).ToList());
                                            if (SettingsStore.GetValueOrDefault <bool>(AppCommonConst.IS_TILE_ACTIVE, true) == true)
                                            {
                                                TileHelper.Instance.UpdateTiles(flipViewCollection.Take(5).ToList());
                                            }
                                            else
                                            {
                                                TileHelper.Instance.CloseTiles();
                                            }
                                            #endregion
                                        }

                                        DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, false);
                                    }
                                    else
                                    {
                                        if (!isRefresh)
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                        }
                                    }
                                }
                                //虽然错误的数据是不会写到本地的,但如果反序列化失败一样会出错,又没有网络
                                else
                                {
                                    if (!isRefresh)
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_ERROR, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                    }
                                }
                            }
                            else
                            {
                                if (!isRefresh)
                                {
                                    RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(EyeSight.ViewModel.Daily.DailyViewModel), "GetDaily", new object[] { collection, flipViewCollection, url, cacheFileName, isRefresh });
                                }
                            }
                        }
                    }
                    //如果不是第一页就不用管了
                    else
                    {
                    }
                }

                IsBusy = false;
            });
        }
Beispiel #20
0
        public async void GetCommonNews(ObservableCollection <NewsModel> collection, string newsUrl, string pageIndexConst, string cacheFileName = null, ObservableCollection <NewsModel> adCollection = null, bool isRefresh = false)
        {
            //取出当前的分页索引记录
            int currentPageIndex = DicStore.GetValueOrDefault <int>(pageIndexConst, 1);

            Debug.WriteLine(currentPageIndex);
            if (currentPageIndex <= AppCommonConst.PAGE_LOAD_DATA_MAX_INDEX)
            {
                IsBusy = true;

                var backJson = await WebDataHelper.Instance.GetFromUrlWithAuthReturnString(newsUrl, null, 3);

                if (backJson != null)
                {
                    var result = JsonConvertHelper.Instance.DeserializeObject <NewsCommonModel>(backJson);
                    if (result != null)
                    {
                        if (result.news.Count != 0)
                        {
                            if (isRefresh)
                            {
                                collection.Clear();
                                if (adCollection != null)
                                {
                                    adCollection.Clear();
                                }

                                var pivotSelectedIndex = DicStore.GetValueOrDefault <int>(AppCommonConst.CUR_PIVOT_SELECTED_INDEX, 0);
                                switch (pivotSelectedIndex)
                                {
                                case 0:
                                    FirstNewsCollection   = new ObservableCollection <NewsModel>(result.news);
                                    FirstNewsAdCollection = new ObservableCollection <NewsModel>(result.ads);
                                    break;

                                case 1:
                                    ChampionCollection = new ObservableCollection <NewsModel>(result.news);
                                    break;

                                case 3:
                                    StrategyCollection = new ObservableCollection <NewsModel>(result.news);
                                    break;
                                }

                                //重要:一个集合绑定到xaml界面上不显示数据有两种情况:1、原有集合地址被再次更改 2、拿着集合的别名到处跑。下面这种写法就是拿着集合的别名到处跑的情况,原有的集合无法被更改。如果要正确处理那就是直接拿着集合去更改。那如果就要拿着集合别名到处跑也要有数据显示的话,就得一个一个去add
                            }
                            else
                            {
                                result.news.ForEach(A =>
                                {
                                    collection.Add(A);
                                });

                                //只有adCollection有数据并且是手机才会展示顶部banner幻灯
                                if (adCollection != null)
                                {
                                    result.ads.ForEach(B =>
                                    {
                                        adCollection.Add(B);
                                    });
                                }
                            }

                            //及时更改类别的分页索引记录,如果没有加载成功就不会被自增记录
                            DicStore.AddOrUpdateValue <int>(pageIndexConst, ++currentPageIndex);

                            //只存第一页的数据,只有加载第一页数据才会记录当前的刷新时间
                            if (cacheFileName != null)
                            {
                                //记录当前的刷新时间 - 已取消
                                //SettingsStore.AddOrUpdateValue<string>(AppCommonConst.LAST_UPDATE_TIME, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                                //将第一页数据缓存到本地
                                FileHelper.Instance.SaveTextToFile(CacheConfig.Instance.NewsListFileCacheRelativePath, cacheFileName, backJson);
                            }
                        }
                        else
                        {
                            //判断是不是分页索引第一页,如果是第一页并且获取到的条目个数为0个,则此时要求再次获取。此时提示“没有获取到数据,请重试”
                            if (currentPageIndex == 1 && !isRefresh)
                            {
                                //这里使用反射
                                RetryBox.Instance.ShowRetry(AppNetworkMessageConst.COLLECTION_ITEM_IS_ZERO, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                            }
                            //如果不是第一页,就不用去管
                            else
                            {
                            }
                        }
                    }
                    else
                    {
                        //判断是不是分页索引第一页,且不是刷新,说明是第一次启动程序加载失败了,如果是第一页且加载失败了,则会加载本地的数据。以保证有数据显示
                        if (currentPageIndex == 1)
                        {
                            //加载本地数据
                            var localJson = await FileHelper.Instance.ReadTextFromFile(CacheConfig.Instance.NewsListFileCacheRelativePath, cacheFileName);

                            if (localJson != null)
                            {
                                var localResult = JsonConvertHelper.Instance.DeserializeObject <NewsCommonModel>(localJson);
                                if (localResult != null)
                                {
                                    //因为如果第一页获取到的数据为0条时不会写到本地的,所以,从本地获取到的数据条目数一定不为0
                                    if (localResult.news.Count != 0)
                                    {
                                        if (!isRefresh)
                                        {
                                            localResult.news.ForEach(A =>
                                            {
                                                collection.Add(A);
                                            });

                                            //只有adCollection有数据并且是手机才会展示顶部banner幻灯
                                            if (adCollection != null)
                                            {
                                                localResult.ads.ForEach(B =>
                                                {
                                                    adCollection.Add(B);
                                                });
                                            }
                                        }

                                        //及时更改类别的分页索引记录,如果没有加载成功就不会被自增记录。加载成功则为第二页做准备
                                        DicStore.AddOrUpdateValue <int>(pageIndexConst, ++currentPageIndex);
                                    }
                                }
                                //虽然错误的数据是不会写到本地的,但如果反序列化失败一样会出错
                                else
                                {
                                    //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                                    if (!isRefresh)
                                    {
                                        if (AppEnvironment.IsInternetAccess)
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                        }
                                        //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                                        else
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                                if (!isRefresh)
                                {
                                    if (AppEnvironment.IsInternetAccess)
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                    }
                                    //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                                    else
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    //判断是不是分页索引第一页,如果是第一页的话则会弹出提示,重新加载。因为第一页没有加载成功,本条目下就没数据,此时就要弹出一个东西让其重新加载数据。如果不是第一页就不用去管了
                    if (currentPageIndex == 1)
                    {
                        //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                        if (AppEnvironment.IsInternetAccess && !isRefresh)
                        {
                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                        }
                        //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                        else
                        {
                            //加载本地数据
                            var localJson = await FileHelper.Instance.ReadTextFromFile(CacheConfig.Instance.NewsListFileCacheRelativePath, cacheFileName);

                            if (localJson != null)
                            {
                                var localResult = JsonConvertHelper.Instance.DeserializeObject <NewsCommonModel>(localJson);
                                if (localResult != null)
                                {
                                    //因为如果第一页获取到的数据为0条时不会写到本地的,所以,从本地获取到的数据条目数一定不为0
                                    if (localResult.news.Count != 0)
                                    {
                                        if (!isRefresh)
                                        {
                                            localResult.news.ForEach(A =>
                                            {
                                                collection.Add(A);
                                            });

                                            //只有adCollection有数据并且是手机才会展示顶部banner幻灯
                                            if (adCollection != null)
                                            {
                                                localResult.ads.ForEach(B =>
                                                {
                                                    adCollection.Add(B);
                                                });
                                            }
                                        }

                                        //及时更改类别的分页索引记录,如果没有加载成功就不会被自增记录。加载成功则为第二页做准备
                                        DicStore.AddOrUpdateValue <int>(pageIndexConst, ++currentPageIndex);
                                    }
                                    else
                                    {
                                        if (!isRefresh)
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                        }
                                    }
                                }
                                //虽然错误的数据是不会写到本地的,但如果反序列化失败一样会出错,又没有网络
                                else
                                {
                                    if (!isRefresh)
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                    }
                                }
                            }
                            else
                            {
                                if (!isRefresh)
                                {
                                    RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(MyCF.ViewModel.News.NewsViewModel), "GetCommonNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                }
                            }
                        }
                    }
                    //如果不是第一页就不用管了
                    else
                    {
                    }
                }

                IsBusy = false;
            }
        }
Beispiel #21
0
        public async void GetActivityNews(ObservableCollection <ActivityModel> collection, string newsUrl, string pageIndexConst, string cacheFileName = null, ObservableCollection <NewsModel> adCollection = null, bool isRefresh = false)
        {
            //取出当前的分页索引记录
            int currentPageIndex = DicStore.GetValueOrDefault <int>(pageIndexConst, 1);

            Debug.WriteLine(currentPageIndex);
            if (currentPageIndex <= AppCommonConst.PAGE_LOAD_DATA_MAX_INDEX)
            {
                IsBusy = true;

                var backJson = await WebDataHelper.Instance.GetFromUrlWithAuthReturnString(newsUrl, null, 3);

                if (backJson != null)
                {
                    var result = JsonConvertHelper.Instance.DeserializeObject <NewsActivityModel>(backJson);
                    if (result != null)
                    {
                        if (result.news.Count != 0)
                        {
                            if (isRefresh)
                            {
                                collection.Clear();

                                ActivityCollection = new ObservableCollection <ActivityModel>(result.news);
                            }
                            else
                            {
                                result.news.ForEach(A =>
                                {
                                    collection.Add(A);
                                });
                            }

                            //及时更改类别的分页索引记录,如果没有加载成功就不会被自增记录
                            DicStore.AddOrUpdateValue <int>(pageIndexConst, ++currentPageIndex);

                            //只存第一页的数据
                            if (cacheFileName != null)
                            {
                                //将第一页数据缓存到本地
                                FileHelper.Instance.SaveTextToFile(CacheConfig.Instance.NewsListFileCacheRelativePath, cacheFileName, backJson);
                            }
                        }
                        else
                        {
                            //判断是不是分页索引第一页,如果是第一页并且获取到的条目个数为0个,则此时要求再次获取。此时提示“没有获取到数据,请重试”
                            if (currentPageIndex == 1 && !isRefresh)
                            {
                                //这里使用反射
                                RetryBox.Instance.ShowRetry(AppNetworkMessageConst.COLLECTION_ITEM_IS_ZERO, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                            }
                            //如果不是第一页,就不用去管
                            else
                            {
                            }
                        }
                    }
                    else
                    {
                        //判断是不是分页索引第一页,如果是第一页的话则会弹出提示,重新加载。因为第一页没有加载成功,本条目下就没数据,此时就要弹出一个东西让其重新加载数据。如果不是第一页就不用去管了
                        if (currentPageIndex == 1)
                        {
                            //加载本地数据
                            var localJson = await FileHelper.Instance.ReadTextFromFile(CacheConfig.Instance.NewsListFileCacheRelativePath, cacheFileName);

                            if (localJson != null)
                            {
                                var localResult = JsonConvertHelper.Instance.DeserializeObject <NewsActivityModel>(localJson);
                                if (localResult != null)
                                {
                                    //因为如果第一页获取到的数据为0条时不会写到本地的,所以,从本地获取到的数据条目数一定不为0
                                    if (localResult.news.Count != 0)
                                    {
                                        if (!isRefresh)
                                        {
                                            localResult.news.ForEach(A =>
                                            {
                                                collection.Add(A);
                                            });
                                        }

                                        //及时更改类别的分页索引记录,如果没有加载成功就不会被自增记录。加载成功则为第二页做准备
                                        DicStore.AddOrUpdateValue <int>(pageIndexConst, ++currentPageIndex);
                                    }
                                }
                                //虽然错误的数据是不会写到本地的,但如果反序列化失败一样会出错
                                else
                                {
                                    if (!isRefresh)
                                    {
                                        //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                                        if (AppEnvironment.IsInternetAccess)
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                        }
                                        //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                                        else
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (!isRefresh)
                                {
                                    //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                                    if (AppEnvironment.IsInternetAccess)
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                    }
                                    //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                                    else
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    //判断是不是分页索引第一页,如果是第一页的话则会弹出提示,重新加载。因为第一页没有加载成功,本条目下就没数据,此时就要弹出一个东西让其重新加载数据。如果不是第一页就不用去管了
                    if (currentPageIndex == 1)
                    {
                        //如果此时还有网络,说明加载过程出错,提示信息为“加载数据出错,请重试。”
                        if (AppEnvironment.IsInternetAccess && !isRefresh)
                        {
                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWOTK_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                        }
                        //如果没有网络,说明数据加载失败是因为没有网络造成的。提示信息为“没有网络,请确认网络连接。”
                        else
                        {
                            //加载本地数据
                            var localJson = await FileHelper.Instance.ReadTextFromFile(CacheConfig.Instance.NewsListFileCacheRelativePath, cacheFileName);

                            if (localJson != null)
                            {
                                var localResult = JsonConvertHelper.Instance.DeserializeObject <NewsActivityModel>(localJson);
                                if (localResult != null)
                                {
                                    //因为如果第一页获取到的数据为0条时不会写到本地的,所以,从本地获取到的数据条目数一定不为0
                                    if (localResult.news.Count != 0)
                                    {
                                        if (!isRefresh)
                                        {
                                            localResult.news.ForEach(A =>
                                            {
                                                collection.Add(A);
                                            });
                                        }

                                        //及时更改类别的分页索引记录,如果没有加载成功就不会被自增记录。加载成功则为第二页做准备
                                        DicStore.AddOrUpdateValue <int>(pageIndexConst, ++currentPageIndex);
                                    }
                                    else
                                    {
                                        if (!isRefresh)
                                        {
                                            RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                        }
                                    }
                                }
                                //虽然错误的数据是不会写到本地的,但如果反序列化失败一样会出错,又没有网络
                                else
                                {
                                    if (!isRefresh)
                                    {
                                        RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_ERROR, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                    }
                                }
                            }
                            else
                            {
                                if (!isRefresh)
                                {
                                    RetryBox.Instance.ShowRetry(AppNetworkMessageConst.NETWORK_IS_OFFLINE_LOCAL_CACHE_IS_NULL, typeof(MyCF.ViewModel.News.NewsViewModel), "GetActivityNews", new object[] { collection, newsUrl, pageIndexConst, cacheFileName, adCollection, isRefresh });
                                }
                            }
                        }
                    }
                    //如果不是第一页就不用管了
                    else
                    {
                    }
                }

                IsBusy = false;
            }
        }
Beispiel #22
0
        private async Task ShowWindow(LaunchActivatedEventArgs e)
        {
            //获取并记录屏幕宽度,一定要在程序启动的时候记录,这样记录到的数据才是竖屏下的屏幕高度。屏幕旋转Window.Current.Bounds.With宽高会互换
            AppEnvironment.ScreenPortraitWith = Window.Current.Bounds.Width;
            //初始化MvvmLight线程
            GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize();

            NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage;

            Frame rootFrame = null;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootPage == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootPage = new NavigationRootPage();

                rootFrame = (Frame)rootPage.FindName("rootFrame");

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                //如果是手机,则默认全屏模式
                if (AppEnvironment.IsPhone)
                {
                    ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
                    //ApplicationView.GetForCurrentView().TitleBar
                }
                else
                {
                    // DisplayProperties.CurrentOrientation 发生变化时触发的事件

                    //设置平板窗口的最小宽高
                    ApplicationView.GetForCurrentView().SetPreferredMinSize(AppEnvironment.DesktopSize);
                }

                //初始化数据库
                await InitDatabase();

                //获取数据库数据
                await GetDatabaseCollection();

                //处理自定义SplashScreenImage
                var isLoadSplashImageSuccess = await InitSplashScreenImage();

                //如果SplashScreenI加载失败,则不显示欢迎屏幕,直接进入主界面
                if (isLoadSplashImageSuccess)
                {
                    //存储第一次启动的表示,是为了防止DailyPage第一页加载数据的时候把ProgressUIControl或者RetryUIControl显示出来,达到正确显示的逻辑处理
                    DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, true);

                    //这句话放在Activate()之前是为了保证在系统的初始屏幕SplashScreen.png消失之后能够显示ShowWelcome的内容。这是正确的处理逻辑
                    WelcomeBox.Instance.ShowWelcome();
                }

                //这句话调用以后,在Package.appxmanifest文件配置的初始屏幕SplashScreen.png就会消失。不写这句话的话,会一直停留显示在初始屏幕SplashScreen.png处。因此,自定义SplashScreenImage的处理逻辑应该放在这句话之前
                //确保当前窗口处于活动状态
                Window.Current.Activate();

                //这个放在Activate()方法下面是为了防止在ShowWelcome没显示之前Window.Current.Content就显示出来的问题。因为只要写了这句话,rootPage就会立刻被激活显示,此时的ShowWelcome可能还没显示出来,造成闪一下的问题。放在ShowWelcome()和Activate()之后才是正确的处理逻辑。
                // 将框架放在当前窗口中
                Window.Current.Content = rootPage;
            }

            if (rootFrame != null && rootFrame.Content == null)
            {
                // 当导航堆栈尚未还原时,导航到第一页,
                // 并通过将所需信息作为导航参数传入来配置
                // 参数
                rootFrame.Navigate(typeof(DailyPage), "每日精选");
            }

            Window.Current.Activate();
        }
Beispiel #23
0
        private async Task <bool> InitSplashScreenImage()
        {
            string splashScreenScreenUrl = AppEnvironment.IsPhone ? "ms-appx:///Assets/SplashDefault/Mobile/1.jpg" : "ms-appx:///Assets/SplashDefault/PC/2.jpg";

            if (AppEnvironment.IsPhone)
            {
                var phoneFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CacheConfig.Instance.PhoneSplashScreenImageCacheRelativePath, CreationCollisionOption.OpenIfExists);

                var phoneFile = await phoneFolder.TryGetItemAsync("phone.jpg");

                if (phoneFile != null)
                {
                    //因为手机端始终都是一张图片名称永远都是phone.jpg,所以直接指定路径就可以了
                    splashScreenScreenUrl = "ms-appdata:///local/" + CacheConfig.Instance.PhoneSplashScreenImageCacheRelativePath + "/phone.jpg";
                }

                //都要转换成东八区北京时间来计算
                var saveDate = SettingsStore.GetValueOrDefault <long>(AppCommonConst.DATE_HAS_SAVE, DateTime.Now.ToChinaStandardTime().AddDays(-1).ToUnixTime());
                if ((DateTime.Now.ToChinaStandardTime().Date - saveDate.ToDateTime().Date).Days >= 1)
                {
                    await Task.Run(async() =>
                    {
                        var backJson = await WebDataHelper.Instance.GetFromUrlWithAuthReturnString(ApiSplashScreenRoot.Instance.SplashScreenUrl, null, 20);
                        if (backJson != null)
                        {
                            var model = JsonConvertHelper.Instance.DeserializeObject <PhoneSplashScreenModel>(backJson);
                            if (model != null)
                            {
                                //专题数据处理
                                if (model.campaignInFeed != null && AppEnvironment.IsMemoryLimitMoreThan185)
                                {
                                    SettingsStore.AddOrUpdateValue <bool>(AppCommonConst.IS_CAMPAIGN_AVAILABLE, model.campaignInFeed.available);
                                    SettingsStore.AddOrUpdateValue <string>(AppCommonConst.CAMPAIGN_IMAGE_URL, model.campaignInFeed.imageUrl);
                                    SettingsStore.AddOrUpdateValue <string>(AppCommonConst.CAMPAIGN_ACTION_URL, model.campaignInFeed.actionUrl);
                                }

                                WebDownFileHelper.Instance.SaveAsyncWithHttp(model.startPage.imageUrl, "phone.jpg", phoneFolder);
                            }
                        }
                    });
                }
            }
            else
            {
                var pcFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CacheConfig.Instance.PCSplashScreenImageCacheRelativePath, CreationCollisionOption.OpenIfExists);

                var pcFiles = await pcFolder.GetAllFilesAsync();

                if (pcFiles.Count != 0)
                {
                    var randomIndex = new Random().Next(0, pcFiles.Count);
                    splashScreenScreenUrl = "ms-appdata:///local/" + CacheConfig.Instance.PCSplashScreenImageCacheRelativePath + "/" + pcFiles[randomIndex].Name;
                }
            }

            var bitmapImage = await CommonHelper.Instance.LoadImageSource(splashScreenScreenUrl);

            if (bitmapImage != null)
            {
                DicStore.AddOrUpdateValue <BitmapImage>(AppCommonConst.SPLASH_BITMAPIMAGE, bitmapImage);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #24
0
        private async Task InitDatabase()
        {
            #region 我的收藏数据库
            SQLiteAsyncConnection dbConnection;
            //使用漫游目录来存储
            var dbFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CacheConfig.Instance.EyeSightFavoriteDatabaseCacheRelativePath, CreationCollisionOption.OpenIfExists);

            var file = await dbFolder.CreateFileAsync(AppCommonConst.EYESIGHT_FAVORITE_DATABASE_NAME, CreationCollisionOption.OpenIfExists);

            //读取数据库文件的长度
            //var fileLength = (await file.OpenStreamForReadAsync()).Length;
            //如果长度为0的话,说明这个数据库文件里面啥也没有,连表都没有,及应用的初始化状态
            //if (fileLength == 0)
            //{
            //开始创建数据库表
            dbConnection = new SQLiteAsyncConnection(file.Path);
            Type[] favouriteTables = new Type[5];
            favouriteTables[0] = typeof(ModelPropertyBase);
            favouriteTables[1] = typeof(Provider);
            favouriteTables[2] = typeof(Consumption);
            favouriteTables[3] = typeof(Playinfo);
            favouriteTables[4] = typeof(VideoTag);

            //数据库一下创建多个表
            await dbConnection.CreateTablesAsync(favouriteTables);

            //}
            //根据数据库路径返回SQlite数据库实例,以便能够存储方便应用程序全局访问
            dbConnection = new SQLiteAsyncConnection(file.Path);

            if (dbConnection != null)
            {
                DicStore.AddOrUpdateValue <SQLiteAsyncConnection>(AppCommonConst.EYESIGHT_FAVORITE_DATABASE, dbConnection);
            }
            else
            {
            }
            #endregion

            #region 我的下载
            SQLiteAsyncConnection dbDownloadConnection;
            //使用漫游目录来存储
            var dbDownloadFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CacheConfig.Instance.EyeSightFavoriteDatabaseCacheRelativePath, CreationCollisionOption.OpenIfExists);

            var downloadFile = await dbDownloadFolder.CreateFileAsync(AppCommonConst.EYESIGHT_DOWNLOAD_DATABASE_NAME, CreationCollisionOption.OpenIfExists);

            //读取数据库文件的长度
            //var downloadFileLength = (await downloadFile.OpenStreamForReadAsync()).Length;
            //如果长度为0的话,说明这个数据库文件里面啥也没有,连表都没有,及应用的初始化状态
            //if (downloadFileLength == 0)
            //{
            //开始创建数据库表
            dbDownloadConnection = new SQLiteAsyncConnection(downloadFile.Path);
            Type[] downloadTables = new Type[5];
            downloadTables[0] = typeof(ModelPropertyBase);
            downloadTables[1] = typeof(Provider);
            downloadTables[2] = typeof(Consumption);
            downloadTables[3] = typeof(Playinfo);
            downloadTables[4] = typeof(VideoTag);

            //数据库一下创建多个表
            await dbDownloadConnection.CreateTablesAsync(downloadTables);

            //}
            //根据数据库路径返回SQlite数据库实例,以便能够存储方便应用程序全局访问
            dbDownloadConnection = new SQLiteAsyncConnection(downloadFile.Path);

            if (dbDownloadConnection != null)
            {
                DicStore.AddOrUpdateValue <SQLiteAsyncConnection>(AppCommonConst.EYESIGHT_DOWNLOAD_DATABASE, dbDownloadConnection);
            }
            else
            {
            }
            #endregion
        }
Beispiel #25
0
        private async void lv_ItemClick(object sender, ItemClickEventArgs e)
        {
            DicStore.AddOrUpdateValue <string>(AppCommonConst.CURRENT_PAST_CATEGORY_DETAIL_NAME, "");

            var model = e.ClickedItem as NavigationRootModel;

            if (model != null)
            {
                isItemClicked = true;
                //取消上下栏ListView的选择
                var listview = sender as ListView;
                if (listview != null)
                {
                    switch (listview.Tag.ToString())
                    {
                    case "lvCommon":
                        lvBottomCategory.SelectedIndex = -1;
                        break;

                    case "lvBottom":
                        lvCommonCategory.SelectedIndex = -1;
                        break;
                    }
                }

                //及时关闭SpliteView
                if (rootSplitView.IsPaneOpen)
                {
                    rootSplitView.IsPaneOpen = false;
                }

                if (rootFrame.BackStack.Count == 0)
                {
                    if (rootFrame.SourcePageType == model.ClassType)
                    {
                        isItemClicked = false;
                        Debug.WriteLine("0我不导");
                        return;
                    }
                }
                else if (rootFrame.BackStack.Count > 0)
                {
                    if (rootFrame.BackStack[0].SourcePageType == model.ClassType)
                    {
                        isItemClicked = false;
                        Debug.WriteLine("非0我也不导");
                        return;
                    }
                }

                //页面一旦发生导航跳转都要隐藏重试提示
                RetryBox.Instance.HideRetry();

                var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                if (animationGrid != null)
                {
                    var page = rootFrame.Content as Page;
                    if (page != null)
                    {
                        if (page.GetType() == typeof(SettingPage) || page.GetType() == typeof(AboutPage))
                        {
                            await animationGrid.AnimateAsync(new FadeOutAnimation()
                            {
                                Duration = 0.13
                            });
                        }
                        else
                        {
                            if (AppEnvironment.IsPhone)
                            {
                                await animationGrid.AnimateAsync(new FadeOutRightAnimation()
                                {
                                    Duration = 0.25, Distance = 400
                                });
                            }
                            else
                            {
                                await animationGrid.AnimateAsync(new FadeOutRightAnimation()
                                {
                                    Duration = 0.13, Distance = 600
                                });
                            }
                        }
                    }
                }

                //这里要清空非一级顶级页面的数据。例如:修复 精彩发现 当PastDetailPage 以new的方式离开时,其所包含的集合数据为清空导致的数据不正确的问题
                if (!SimpleIoc.Default.IsRegistered <PastDetailViewModel>())
                {
                    SimpleIoc.Default.Register <PastDetailViewModel>();
                }
                var pastDetailViewModel = SimpleIoc.Default.GetInstance <PastDetailViewModel>();
                if (pastDetailViewModel != null)
                {
                    pastDetailViewModel.Cleanup();
                }

                //作者这里处理

                if (!SimpleIoc.Default.IsRegistered <AuthorDetailViewModel>())
                {
                    SimpleIoc.Default.Register <AuthorDetailViewModel>();
                }
                var authorDetailViewModel = SimpleIoc.Default.GetInstance <AuthorDetailViewModel>();
                if (authorDetailViewModel != null)
                {
                    authorDetailViewModel.Cleanup();
                }

                rootFrame.Navigate(model.ClassType, model.Title);

                isItemClicked = false;

                if (this.appBarFavoriteBtn.IsChecked.Value)
                {
                    this.appBarFavoriteBtn.IsChecked = false;
                }

                if (this.appBarDownloadBtn.IsChecked.Value)
                {
                    this.appBarDownloadBtn.IsChecked = false;
                }

                if (animationGrid != null)
                {
                    await animationGrid.AnimateAsync(new ResetAnimation());
                }
            }
        }
        protected override async void OnUIControlBaseNeedNavigate(object sender, PointerRoutedEventArgs e)
        {
            base.OnUIControlBaseNeedNavigate(sender, e);

            //throw new NullReferenceException();

            var control = sender as FrameworkElement;

            if (control != null)
            {
                var model = control.DataContext as ModelPropertyBase;
                if (model != null)
                {
                    //说明此处是专题
                    if (model.duration == 0 && string.IsNullOrEmpty(model.category))
                    {
                        if (AppEnvironment.IsInternetAccess)
                        {
                            var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                            if (animationGrid != null)
                            {
                                if (AppEnvironment.IsPhone)
                                {
                                    await animationGrid.AnimateAsync(new BounceOutDownAnimation());
                                }
                            }

                            DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);

                            CommonHelper.Instance.NavigateWithOverride(typeof(CampaignWebPage));

                            await this.coverGrid.AnimateAsync(new ResetAnimation());

                            if (animationGrid != null)
                            {
                                await animationGrid.AnimateAsync(new ResetAnimation());
                            }
                        }
                        else
                        {
                            await new MessageDialog(AppNetworkMessageConst.NETWORK_IS_OFFLINEL, "提示").ShowAsyncQueue();
                        }
                    }
                    else
                    {
                        var szPhone = CommonHelper.Instance.GetCurrentSemanticZoom("szPhone");
                        if (szPhone != null)
                        {
                            if (szPhone.IsZoomedInViewActive == true)
                            {
                                DicStore.AddOrUpdateValue <ModelPropertyBase>(AppCommonConst.CURRENT_SELECTED_ITEM, model);

                                szPhone.IsZoomedInViewActive = false;

                                ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;

                                await this.coverGrid.AnimateAsync(new ResetAnimation());
                            }
                        }
                    }
                }
            }
            ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;
        }
Beispiel #27
0
        protected override async void OnUIControlBaseNeedNavigate(object sender, PointerRoutedEventArgs e)
        {
            base.OnUIControlBaseNeedNavigate(sender, e);

            if (AppEnvironment.IsInternetAccess)
            {
                var control = sender as FrameworkElement;
                if (control != null)
                {
                    if (model != null)
                    {
                        //如果解析出错
                        if (model.actionId == (int)CategoryErrorType.ERROR)
                        {
                            await new MessageDialog(AppNetworkMessageConst.DATA_PRE_COMBINE_IS_ERROR, "提示").ShowAsyncQueue();
                        }
                        //如果暂不支持此类型的跳转
                        else if (model.actionId == (int)CategoryErrorType.UNSUPPORT)
                        {
                            await new MessageDialog(AppNetworkMessageConst.DATA_UNSUPPORT, "提示").ShowAsyncQueue();
                        }
                        else
                        {
                            var animationGrid = CommonHelper.Instance.GetCurrentAnimationGrid();
                            if (animationGrid != null)
                            {
                                if (AppEnvironment.IsPhone)
                                {
                                    await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                                    {
                                        Duration = 0.25, Distance = 400
                                    });
                                }
                                else
                                {
                                    await animationGrid.AnimateAsync(new FadeOutLeftAnimation()
                                    {
                                        Duration = 0.13, Distance = 600
                                    });
                                }
                            }

                            DicStore.AddOrUpdateValue <string>(AppCommonConst.CURRENT_PAST_CATEGORY_DETAIL_NAME, model.convertName);
                            DicStore.AddOrUpdateValue <int>(AppCommonConst.CURRENT_PAST_CATEGORY_DETAIL_ACTION_ID, model.actionId);
                            DicStore.AddOrUpdateValue <CategorySubType>(AppCommonConst.CURRENT_PAST_CATEGORY_DETAIL_ACTION_TYPE, model.categorySubType);

                            CommonHelper.Instance.NavigateWithOverride(typeof(PastDetailPage));

                            ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;

                            await this.coverGrid.AnimateAsync(new ResetAnimation());

                            if (animationGrid != null)
                            {
                                await animationGrid.AnimateAsync(new ResetAnimation());
                            }
                        }
                    }
                }
            }
            else
            {
                await new MessageDialog(AppNetworkMessageConst.NETWORK_IS_OFFLINEL, "提示").ShowAsyncQueue();
            }

            ViewModelLocator.Instance.ListViewScrollHandler -= resetCoverGridState;
        }