Exemplo n.º 1
0
        private async void UpdateDataFromHabitica()
        {
            DoubleAnimation rotateAnimation = new DoubleAnimation()
            {
                From           = 360,
                To             = 0,
                Duration       = new Duration(TimeSpan.FromSeconds(.8)),
                RepeatBehavior = RepeatBehavior.Forever,
            };
            RotateTransform rotateTransform = new RotateTransform(0);

            RefreshButton.RenderTransform = rotateTransform;
            rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation);
            try
            {
                HttpApi = new HttpApi(AppSetting);
                // 获取 Habitica 数据
                Tasks = await HttpApi.GetAllTasks();

                Tags = await HttpApi.GetAllTags();

                // 获取今日目标标签
                TodayTargetTag = HttpApi.TodayTargetTagFilter(Tags);
                if (TodayTargetTag == null)
                {
                    TodayTargetTag = HttpApi.CreateTag("TodayTarget").Result;
                }
                // 清理目标列表
                ClearShouldGetFromHabiticaTask();
                // 初始化目标列表
                InitTodayTargetList();
                InitDailyTargetList();
                InitPlanTargetList();
                ShowMessage("更新数据成功");
                rotateTransform.BeginAnimation(RotateTransform.AngleProperty, null);
            }
            catch (Exception exception)
            {
                ShowMessage(exception.Message, false);
                rotateTransform.BeginAnimation(RotateTransform.AngleProperty, null);
            }
        }