Example #1
0
        private static async Task <StorageFile> PrepareImageFileAsync(StorageFile resultFile)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                ToastService.SendToast("Your device can't set wallpaper.");
                return(null);
            }
            if (resultFile != null)
            {
                StorageFile file = null;

                //WTF, the file should be copy to LocalFolder to make the setting wallpaer api work.
                var folder  = ApplicationData.Current.LocalFolder;
                var oldFile = await folder.TryGetItemAsync(resultFile.Name) as StorageFile;

                if (oldFile != null)
                {
                    await resultFile.CopyAndReplaceAsync(oldFile);

                    file = oldFile;
                }
                else
                {
                    file = await resultFile.CopyAsync(folder);
                }
                return(file);
            }
            return(null);
        }
Example #2
0
        private static async Task <StorageFile> PrepareImageFileAsync(StorageFile resultFile)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                ToastService.SendToast(ResourcesHelper.GetResString("SettingWallpaperNotSupported"));
                return(null);
            }

            try
            {
                if (resultFile != null)
                {
                    //WTF, the file should be copy to LocalFolder to make the setting wallpaer api work.
                    var         folder = ApplicationData.Current.LocalFolder;
                    StorageFile file;
                    if (await folder.TryGetItemAsync(resultFile.Name) is StorageFile oldFile)
                    {
                        await resultFile.CopyAndReplaceAsync(oldFile);

                        file = oldFile;
                    }
                    else
                    {
                        file = await resultFile.CopyAsync(folder);
                    }
                    return(file);
                }
            }
            catch (FileNotFoundException)
            {
                ShowFailedToast();
            }

            return(null);
        }
Example #3
0
 public void OnLoaded()
 {
     if (ConfigHelper.IsLogin)
     {
         ToastService.SendToast("欢迎回来:-)", TimeSpan.FromMilliseconds(2000));
     }
 }
Example #4
0
        public async Task GetUserPlan()
        {
            CurrentUserPlans = new ObservableCollection <UserPlan>();

            var getResult = await CloudService.GetAllPlans(CTSFactory.MakeCTS().Token);

            getResult.ParseAPIResult();
            if (!getResult.IsSuccessful)
            {
                ToastService.SendToast("获得培养计划失败");
                return;
            }
            var json = getResult.JsonSrc;


            SelectedIndex = 0;

            if (CurrentUserPlans.Count == 0)
            {
                NoItemVisibility = Visibility.Visible;
            }
            else
            {
                NoItemVisibility = Visibility.Collapsed;
            }
        }
Example #5
0
        public static async Task SetBothAsync(StorageFile savedFile)
        {
            var uc = new LoadingTextControl()
            {
                LoadingText = "Setting background and lockscreen..."
            };
            await PopupService.Instance.ShowAsync(uc);

            var file = await PrepareImageFileAsync(savedFile);

            if (file != null)
            {
                var result1 = await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(file);

                var result2 = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(file);

                //var task = file.DeleteAsync(StorageDeleteOption.PermanentDelete);

                if (result1 && result2)
                {
                    ToastService.SendToast("Set as background and lock screen successfully.");
                }
                else
                {
                    ToastService.SendToast("Fail to set both. #API ERROR.");
                }
            }

            PopupService.Instance.TryHide(500);
        }
Example #6
0
        private async Task SaveMainListDataAsync()
        {
            if (this.DataVM.DataList?.Count > 0)
            {
                var list = new List <UnsplashImage>();
                foreach (var item in DataVM.DataList)
                {
                    if (item is UnsplashImage)
                    {
                        list.Add(item as UnsplashImage);
                    }
                }
                if (list.Count > 0)
                {
                    ToastService.SendToast("Fetched :D");

                    var str = JsonConvert.SerializeObject(list, new JsonSerializerSettings()
                    {
                        TypeNameHandling = TypeNameHandling.All
                    });
                    var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(CachedFileNames.MainListFileName, CreationCollisionOption.OpenIfExists);

                    await FileIO.WriteTextAsync(file, str);
                }
            }
        }
Example #7
0
        /// <summary>
        /// 收藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void Favorite(object sender, RoutedEventArgs e)
        {
            if (DocumentExtra != null)
            {
                if (DocumentExtra.Favorited)
                {
                    var res = await ApiService.Instance.UnFavoriteAsync(DocumentExtra.DocumentId);

                    if (res != null)
                    {
                        if (!string.IsNullOrEmpty(res.Count))
                        {
                            DocumentExtra.Favorited = false;
                            ToastService.SendToast("取消收藏成功");
                        }
                    }
                }
                else
                {
                    var res = await ApiService.Instance.FavoriteAsync(DocumentExtra.DocumentId);

                    if (res != null)
                    {
                        if (res.Status.Equals("1000"))
                        {
                            DocumentExtra.Favorited = true;
                            ToastService.SendToast("收藏成功");
                        }
                    }
                }
            }
        }
        public async Task DownloadFullImageAsync(CancellationToken token)
        {
            var url = GetSaveImageUrlFromSettings();

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            ToastService.SendToast("Downloading in background...", 2000);

            StorageFolder folder = await AppSettings.Instance.GetSavingFolderAsync();

            var fileName = $"{Owner.Name}  {CreateTimeString}";
            var newFile  = await folder.CreateFileAsync($"{fileName}.jpg", CreationCollisionOption.GenerateUniqueName);

            _backgroundDownloader.SuccessToastNotification = ToastHelper.CreateToastNotification("Saved:D",
                                                                                                 $"Tap to open {folder.Path}.");

            var downloadOperation = _backgroundDownloader.CreateDownload(new Uri(url), newFile);

            var progress = new Progress <DownloadOperation>();

            try
            {
                await downloadOperation.StartAsync().AsTask(token, progress);
            }
            catch (TaskCanceledException)
            {
                await downloadOperation.ResultFile.DeleteAsync();

                downloadOperation = null;
                throw;
            }
        }
Example #9
0
 private bool IsInputDataValid()
 {
     if (string.IsNullOrEmpty(Email))
     {
         ToastService.SendToast("请输入邮箱");
         return(false);
     }
     if (!Functions.IsValidEmail(Email))
     {
         ToastService.SendToast("邮箱格式不对");
         return(false);
     }
     if (string.IsNullOrEmpty(Password))
     {
         ToastService.SendToast("请输入密码");
         return(false);
     }
     if (LoginMode == LoginMode.Register && string.IsNullOrEmpty(PasswordToBeConfirmed))
     {
         ToastService.SendToast("请再次输入密码");
         return(false);
     }
     if (LoginMode == LoginMode.Register && Password != PasswordToBeConfirmed)
     {
         ToastService.SendToast("两次输入的密码不匹配");
         return(false);
     }
     return(true);
 }
        private async void DownloadBtn_Click(object sender, RoutedEventArgs e)
        {
            ToggleDownloadBtnAnimation(false);
            ToggleDownloadingBtnAnimation(true);

            try
            {
                _cts = new CancellationTokenSource();
                await this.CurrentImage.DownloadFullImageAsync(_cts.Token);

                ToggleDownloadingBtnAnimation(false);

                //Still in this page
                if (IsShown)
                {
                    ToggleOkBtnAnimation(true);
                    ToastService.SendToast("Saved :D", TimeSpan.FromMilliseconds(1000));
                }
            }
            catch (OperationCanceledException)
            {
                ToggleDownloadBtnAnimation(true);
                ToggleDownloadingBtnAnimation(false);
                ToggleOkBtnAnimation(false);
                ToastService.SendToast("Cancelled", TimeSpan.FromMilliseconds(1000));
            }
            catch (Exception ex)
            {
                var task = Logger.LogAsync(ex);
                ToggleDownloadBtnAnimation(true);
                ToggleDownloadingBtnAnimation(false);
                ToggleOkBtnAnimation(false);
                ToastService.SendToast($"Exception throws.{ex.Message}", TimeSpan.FromMilliseconds(1000));
            }
        }
        private void CopyURLBtn_Click(object sender, RoutedEventArgs e)
        {
            DataPackage dataPackage = new DataPackage();

            dataPackage.SetText(CurrentImage.GetSaveImageUrlFromSettings());
            Clipboard.SetContent(dataPackage);
            ToastService.SendToast("Copied.");
        }
Example #12
0
 public void RemoveVol(VolItem item)
 {
     if (IsHeartedVol(item))
     {
         HeartVols.Remove(item);
         ToastService.SendToast("已取消收藏");
     }
 }
Example #13
0
 public void AddVol(VolItem item)
 {
     if (!IsHeartedVol(item))
     {
         HeartVols.Add(item);
         ToastService.SendToast("期刊已收藏");
     }
 }
Example #14
0
        private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            DataPackage dataPackage = new DataPackage();

            dataPackage.SetText("473967668");
            Clipboard.SetContent(dataPackage);
            ToastService.SendToast("已复制到剪切板");
        }
Example #15
0
        /// <summary>
        /// 复制链接
        /// </summary>
        public static void CopyLink(string content)
        {
            DataPackage dataPackage = new DataPackage();

            dataPackage.SetText(content);
            Clipboard.SetContent(dataPackage);

            ToastService.SendToast("链接已复制到剪切板");
        }
Example #16
0
        private async Task ClearCacheAsync()
        {
            ClearCacheCommandEnabled = false;
            CacheHint = ResourceLoader.GetForCurrentView().GetString("Cleaning");
            await _cacheSupplier.ClearAsync();

            ToastService.SendToast(ResourcesHelper.GetResString("TempFilesCleaned"), TimeSpan.FromMilliseconds(1000));
            await UpdateCacheSizeUIAsync();
        }
Example #17
0
        public async void QQLogin()
        {
            bool result = await ApiService.Instance.TecentLoginAsync();

            if (result)
            {
                ToastService.SendToast("登录成功");
            }
        }
Example #18
0
        /// <summary>
        /// 点赞 视频
        /// </summary>
        /// <param name="videoId"></param>
        public async Task VoteVideoAsync(string videoId)
        {
            var result = await ApiService.Instance.VoteAsync(videoId);

            if (result != null)
            {
                ToastService.SendToast(result.Description);
            }
        }
Example #19
0
        /// <summary>
        /// 复制链接
        /// </summary>
        public void CopyLink()
        {
            DataPackage dataPackage = new DataPackage();

            dataPackage.SetText(Document.ShareUrl);
            Clipboard.SetContent(dataPackage);

            ToastService.SendToast("链接已复制到剪切板");
        }
Example #20
0
        private async Task Login()
        {
            try
            {
                var saltResult = await CloudService.GetSalt(Email, CTSFactory.MakeCTS(100000).Token);

                saltResult.ParseAPIResult();
                if (!saltResult.IsSuccessful)
                {
                    throw new APIException(saltResult.ErrorMsg);
                }
                var saltObj = JsonObject.Parse(saltResult.JsonSrc);
                var salt    = JsonParser.GetStringFromJsonObj(saltObj, "Salt");
                if (string.IsNullOrEmpty(salt))
                {
                    throw new APIException("User does not exist.");
                }

                var newPwd       = MD5.GetMd5String(Password);
                var newPwdInSalt = MD5.GetMd5String(newPwd + salt);
                var loginResult  = await CloudService.Login(Email, newPwdInSalt, CTSFactory.MakeCTS(100000).Token);

                loginResult.ParseAPIResult();
                if (!loginResult.IsSuccessful)
                {
                    throw new APIException(loginResult.ErrorMsg);
                }
                var loginObj    = JsonObject.Parse(loginResult.JsonSrc);
                var userObj     = loginObj["UserInfo"];
                var uid         = JsonParser.GetStringFromJsonObj(userObj, "uid");
                var accessToken = JsonParser.GetStringFromJsonObj(userObj, "access_token");
                if (uid.IsNotNullOrEmpty() && accessToken.IsNotNullOrEmpty())
                {
                    LocalSettingHelper.AddValue("uid", uid);
                    LocalSettingHelper.AddValue("access_token", accessToken);
                    NavigationService.NavigateViaRootFrame(typeof(MainPage));
                }
            }
            catch (TaskCanceledException)
            {
                ToastService.SendToast("Connection time out");
            }
            catch (APIException e)
            {
                ToastService.SendToast(e.ErrorMessage.IsNotNullOrEmpty() ? e.Message : "Fail to login");
            }
            catch (Exception e)
            {
                ToastService.SendToast("Fail to login");
                var task = ExceptionHelper.WriteRecordAsync(e, nameof(LoginViewModel), nameof(Login));
            }
            finally
            {
                ShowLoading = Visibility.Collapsed;
            }
        }
Example #21
0
        public async void ClearHistories()
        {
            var result = await ApiService.Instance.ClearReadHistoryAsync();

            if (result != null && result.Status.Equals("1000"))
            {
                ToastService.SendToast(result.AlertDesc);
                ReadHistories.Clear();
            }
        }
        private void AlipayBtn_Click(object sender, RoutedEventArgs e)
        {
            PopupService.Instance.TryHide();

            DataPackage dataPackage = new DataPackage();

            dataPackage.SetText("18520944923");
            Clipboard.SetContent(dataPackage);
            ToastService.SendToast("Alipay account is copied in Clipboard", 2000);
        }
        public async void Logout()
        {
            bool result = await ApiService.Instance.LogoutAsync();

            if (result)
            {
                IsLogoutEnable = false;
                ToastService.SendToast("已注销登录");
            }
        }
        private async void InAppClick_Click(object sender, RoutedEventArgs e)
        {
            PopupService.Instance.TryHide();

            try
            {
                var licenseInformation = CurrentApp.LicenseInformation;
                var license            = licenseInformation.ProductLicenses["MyerSplashIAP"];
                if (license.IsActive)
                {
                    // the customer can access this feature
                    ToastService.SendToast("Thanks for your drink. I will do better. :P", 2000);
                }
                else
                {
                    var uc = new LoadingTextControl()
                    {
                        LoadingText = "Grabing infomation..."
                    };
                    await PopupService.Instance.ShowAsync(uc);

                    // the customer can' t access this feature
                    var result = await CurrentApp.RequestProductPurchaseAsync("MyerSplashIAP");

                    PopupService.Instance.TryHide(500);

                    switch (result.Status)
                    {
                    case ProductPurchaseStatus.AlreadyPurchased:
                    {
                        ToastService.SendToast("Thanks. I will do better :P", 4000);
                    }; break;

                    case ProductPurchaseStatus.NotPurchased:
                    {
                    }; break;

                    case ProductPurchaseStatus.Succeeded:
                    {
                        ToastService.SendToast("Thanks. I will do better. :P", 2000);
                    }; break;
                    }
                }
            }
            catch (Exception ex)
            {
                await Logger.LogAsync(ex);
            }
            finally
            {
                PopupService.Instance.TryHide();
            }
        }
Example #25
0
        private async Task <bool> RegisterAsync()
        {
            try
            {
                //注册
                IsLoading = true;

                var loader = new ResourceLoader();

                var check = await CloudService.CheckEmailExistAsync(TempEmail);

                if (check)
                {
                    throw new MyerListException()
                          {
                              ErrorCode = "202"
                          };
                }
                string salt = await CloudService.RegisterAsync(TempEmail, InputPassword);

                if (!string.IsNullOrEmpty(salt))
                {
                    LocalSettingHelper.AddValue("email", TempEmail);
                    LocalSettingHelper.AddValue("password", InputPassword);
                    return(true);
                }
                else
                {
                    throw new MyerListException()
                          {
                              ErrorCode = ""
                          };
                }
            }
            catch (MyerListException e)
            {
                ToastService.SendToast(ErrorUtils.GetUserMsgFromErrorCode(int.Parse(e.ErrorCode)));
                IsLoading = false;
                return(false);
            }
            catch (TaskCanceledException)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                IsLoading = false;
                return(false);
            }
            catch (COMException)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                IsLoading = false;
                return(false);
            }
        }
        /// <summary>
        /// 投稿
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void Contribute(object sender, RoutedEventArgs e)
        {
            var result = await ApiService.Instance.UserContributeAsync(ShareUri, Title);

            if (result != null)
            {
                if (result.Status.Equals("1000"))
                {
                    ToastService.SendToast("投稿成功");
                }
            }
        }
Example #27
0
        /// <summary>
        /// 举报评论
        /// </summary>
        /// <param name="commentId"></param>
        public async void ReportAsync(string commentId)
        {
            var result = await ApiService.Instance.ReportCommentAsync(commentId);

            if (result != null)
            {
                if (result.Status == "1000")
                {
                    ToastService.SendToast(result.AlertDesc);
                }
            }
        }
Example #28
0
        public async Task DownloadFullImageAsync(CancellationToken token)
        {
            var url = GetSaveImageUrlFromSettings();

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            ToastService.SendToast("Downloading in background...", 2000);

            StorageFolder folder = null;

            if (LocalSettingHelper.HasValue(SettingsViewModel.SAVING_POSITION))
            {
                var path = LocalSettingHelper.GetValue(SettingsViewModel.SAVING_POSITION);
                if (path == SettingsViewModel.DEFAULT_SAVING_POSITION)
                {
                    folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MyerSplash", CreationCollisionOption.OpenIfExists);
                }
                else
                {
                    folder = await StorageFolder.GetFolderFromPathAsync(path);
                }
            }
            if (folder == null)
            {
                folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MyerSplash", CreationCollisionOption.OpenIfExists);
            }
            var fileName = $"{Owner.Name}  {CreateTimeString}";
            var newFile  = await folder.CreateFileAsync($"{fileName}.jpg", CreationCollisionOption.GenerateUniqueName);

            //backgroundDownloader.FailureToastNotification = ToastHelper.CreateToastNotification("Failed to download :-(", "You may cancel it. Otherwise please check your network.");
            _backgroundDownloader.SuccessToastNotification = ToastHelper.CreateToastNotification("Saved:D",
                                                                                                 $"You can find it in {folder.Path}.");

            var downloadOperation = _backgroundDownloader.CreateDownload(new Uri(url), newFile);

            var progress = new Progress <DownloadOperation>();

            try
            {
                await downloadOperation.StartAsync().AsTask(token, progress);
            }
            catch (TaskCanceledException)
            {
                await downloadOperation.ResultFile.DeleteAsync();

                downloadOperation = null;
                throw;
            }
        }
Example #29
0
        /// <summary>
        /// 新浪微博授权登录
        /// </summary>
        public async void SinaLogin()
        {
            User user = await ApiService.Instance.SinaWeiboLoginAsync();

            if (user != null)
            {
                DataShareManager.Current.UpdateUser(user);
                ToastService.SendToast("登录成功");
            }
            else
            {
                ToastService.SendToast("登录失败");
            }
        }
Example #30
0
        /// <summary>
        /// 点赞此评论
        /// </summary>
        public async void Vote()
        {
            var result = await ApiService.Instance.VoteAsync(DocumentId);

            if (result != null)
            {
                if (result.Status == "1000")
                {
                    Voted = true;
                    VoteCount++;
                }
                ToastService.SendToast(result.AlertDesc);
            }
        }