Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Download
Browse files Browse the repository at this point in the history
  • Loading branch information
Seng-Jik committed Feb 5, 2021
1 parent bd2ae41 commit 1373b77
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
16 changes: 16 additions & 0 deletions KoKoViewer/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ static ToastNotification ToastProgress(KoKo.Post post)
return toast;
}

public static StorageFile GetDownloaded(KoKo.Post post)
{
StorageFolder applicationFolder = KnownFolders.PicturesLibrary;
StorageFolder folder = applicationFolder.CreateFolderAsync("KoKo Images", CreationCollisionOption.OpenIfExists).AsTask().Result;
var image = post.images.First().First();

try
{
return folder.GetFileAsync(KoKo.Utils.normalizeFileName(image.fileName)).AsTask().Result;
}
catch(Exception)
{
return null;
}
}

public static async void Download(KoKo.Post post)
{
StorageFolder applicationFolder = KnownFolders.PicturesLibrary;
Expand Down
1 change: 0 additions & 1 deletion KoKoViewer/Viewer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<Image.Source>
<BitmapImage
x:Name="ImageSource"
UriSource="{x:Bind imageUrl}"
AutoPlay="True"
ImageOpened="BitmapImage_ImageOpened"
ImageFailed="ImageSource_ImageFailed"
Expand Down
25 changes: 20 additions & 5 deletions KoKoViewer/Viewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
Expand All @@ -24,7 +25,6 @@ namespace KoKoViewer
/// </summary>
public sealed partial class Viewer : Page
{
string imageUrl;
KoKo.Post post;
SearchOption searchOption;

Expand All @@ -40,9 +40,17 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
post = p.Item1;
searchOption = p.Item2;

imageUrl = post.images.First().Last().imageUrl;

Flyout_ViewLarger.IsEnabled = post.images.First().Count() > 1;
var cache = DownloadHelper.GetDownloaded(post);
if (cache != null)
{
Flyout_ViewLarger.IsEnabled = false;
ImageSource.SetSource(cache.OpenAsync(FileAccessMode.Read).AsTask().Result);
}
else
{
ImageSource.UriSource = new Uri(post.images.First().Last().imageUrl);
Flyout_ViewLarger.IsEnabled = post.images.First().Count() > 1;
}
}

private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
Expand Down Expand Up @@ -80,7 +88,7 @@ private async void FlyoutSourceList_ItemClick(object sender, ItemClickEventArgs
private void Flyout_ViewLarger_Click(object sender, RoutedEventArgs e)
{
(sender as AppBarButton).IsEnabled = false;
imageUrl = post.images.First().First().imageUrl;
var imageUrl = post.images.First().First().imageUrl;
ImageSource.UriSource = new Uri(imageUrl);

Flyout.Hide();
Expand Down Expand Up @@ -110,6 +118,13 @@ private void Flyout_Opening(object sender, object e)
DisplayScore.Text = $" Score:{post.score.Value}";
}

if(DownloadHelper.GetDownloaded(post) != null)
{
Flyout_Download.IsEnabled = false;
Flyout_ViewLarger.IsEnabled = false;
Flyout_Download.Label = "Downloaded";
}

if (FavoritesData.Get().Has(post.fromSpider.Name, post.id))
{
Flyout_Star.Icon = new SymbolIcon() { Symbol = Symbol.UnFavorite };
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ KoKoViewer是KoKo的使用UWP的GUI实现,提供了基本的浏览功能。

### 后续工作
- [x] 收藏夹
- [ ] 下载图片
- [x] 下载图片
- [ ] 支持播放视频

### 如何安装
Expand Down

0 comments on commit 1373b77

Please sign in to comment.