public async void NewRepost() { var sit = new SitbackAndRelaxDialog(); sit.ShowAsync(); try { var text = Item.Result.RetweetedStatus == null ? $"{SendText}" : $"{SendText}//@{Item.Result.User.Name}:{Item.Result.Text}"; await Core.Api.Statuses.PostWeibo.Repost(Item.Result.ID, text.Length > 140?text.Remove(139) : text); } catch { Notification.Show("发送失败"); } sit.Hide(); SendText = ""; }
public async void NewComment() { if (string.IsNullOrEmpty(SendText)) { return; } var sit = new SitbackAndRelaxDialog(); sit.ShowAsync(); try { await Core.Api.Comments.PostComment(Item.Result.ID, SendText.Length > 140?SendText.Remove(139) : SendText); } catch { Notification.Show("发送失败"); } sit.Hide(); SendText = ""; }
public async void DownloadEmotion() { var dialog = new SitbackAndRelaxDialog() { DialogText = "正在获取表情列表...", IsIndeterminate = true }; dialog.ShowAsync(); var list = (await Core.Api.Statuses.Emotions.GetEmotions()).ToList(); dialog.DialogText = "正在下载表情图片..."; dialog.IsIndeterminate = false; dialog.ProgressMaximum = list.Count; var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("emotion", CreationCollisionOption.OpenIfExists); using (var client = new HttpClient()) for (int i = 0; i < list.Count; i++) { var item = list[i]; if (string.IsNullOrEmpty(item.Category)) { item.Category = "表情"; } var catfolder = await folder.CreateFolderAsync(item.Category, CreationCollisionOption.OpenIfExists); var fileName = $"{item.Value.Replace("[", "").Replace("]","")}.jpg"; if (await catfolder.TryGetItemAsync(fileName) == null) { var file = await catfolder.CreateFileAsync(fileName); using (var fileStream = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStreamForWrite()) using (var iconStream = (await client.GetStreamAsync(item.Url))) await iconStream.CopyToAsync(fileStream); } //can not load the image from localcache list[i].Url = $"ms-appdata:///local/emotion/{item.Category}/{fileName}"; dialog.ProgressValue++; } StaticResource.Emotions = list; var jsonFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("emotion.json", CreationCollisionOption.ReplaceExisting); File.WriteAllText(jsonFile.Path, JsonHelper.ToJson(list), Encoding.UTF8); dialog.Hide(); Notification.Show("下载完毕"); }
public async void PostWeibo() { if (_isSending || Text?.Length < 0) { return; } if (TextCount < 0) { var dialog = new MessageDialog("超出140字限制", "错误"); dialog.Commands.Add(new UICommand("删除超出部分并发送", (command) => { Text = Text.Remove(139); PostWeibo(); })); dialog.Commands.Add(new UICommand("取消")); await dialog.ShowAsync(); return; } _isSending = true; var sardialog = new SitbackAndRelaxDialog(); sardialog.ShowAsync(); var(isSuccess, message) = (false, ""); switch (_data.Type) { case PostWeiboType.NewPost: (isSuccess, message) = await NewPost(); break; case PostWeiboType.RePost: (isSuccess, message) = await RePost(); break; case PostWeiboType.Comment: (isSuccess, message) = await Comment(); break; default: break; } sardialog.Hide(); if (isSuccess) { if (_data is SharedPostWeibo) { (_data as SharedPostWeibo).Operation.ReportCompleted(); } else { Frame.GoBack(); } } else { Notification.Show(message); } _isSending = false; }