Skip to content

Commit

Permalink
Fix slide bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yashihei committed May 21, 2015
1 parent b5452c9 commit 69e1618
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
1 change: 0 additions & 1 deletion README.md
@@ -1,4 +1,3 @@
#TumblrViewer

WPFアプリケーションで、TumblrAPIを使って、指定したユーザーのアーカイブを眺められるようにするっぽい
![](ss.JPG)
2 changes: 1 addition & 1 deletion tumblrAppWPF/MainWindow.xaml
Expand Up @@ -5,7 +5,7 @@
Title="TumblrViewer" Height="450" Width="680" KeyDown="Window_KeyDown">
<Grid>
<Image Name="image1" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Top" UseLayoutRounding="False" />
<Button Content="Save" HorizontalAlignment="Center" Margin="1,0,0,10" VerticalAlignment="Bottom" Width="75" RenderTransformOrigin="0.253,0.559" Click="Button_Click" Opacity="0.705"/>
<Button Content="Save" HorizontalAlignment="Center" Margin="0,0,0,10" VerticalAlignment="Bottom" Width="75" RenderTransformOrigin="0.253,0.559" Click="Button_Click" Opacity="0.705"/>
<Button Content="&gt;" HorizontalAlignment="Center" Margin="120,0,0,10" VerticalAlignment="Bottom" Width="30" MinWidth="0" Click="Button_Click_2" Opacity="0.7"/>
<Button Content="&lt;" HorizontalAlignment="Center" Margin="0,0,120,10" VerticalAlignment="Bottom" Width="30" MinWidth="0" Click="Button_Click_1" Opacity="0.7"/>
</Grid>
Expand Down
27 changes: 10 additions & 17 deletions tumblrAppWPF/MainWindow.xaml.cs
Expand Up @@ -16,7 +16,6 @@
using System.IO;

using Newtonsoft.Json;
using WpfAnimatedGif;

namespace tumblrAppWPF
{
Expand All @@ -31,6 +30,7 @@ public partial class MainWindow : Elysium.Controls.Window

List<BitmapImage> images = new List<BitmapImage>();
int index = 0;
int forward_index = 0;

public MainWindow()
{
Expand All @@ -43,62 +43,55 @@ public MainWindow()

private void Button_Click(object sender, RoutedEventArgs e)
{
//images[index]
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
index--;
if (index < 0) index = 0;
SlideImage();
}

private void Button_Click_2(object sender, RoutedEventArgs e)
{
index++;
if (index > forward_index) index = forward_index;
SlideImage();
}

private void SlideImage()
{
if (index < 0) index = 0;
else if (index % 10 == 0) RequestNewImages();//FIXME:10枚毎に読み込む

if (images[index].UriSource.ToString().IndexOf(".gif") > 0)
{
image1.SetValue(ImageBehavior.AnimatedSourceProperty, images[index]);
}
else
if (forward_index - index < 5)
{
image1.ClearValue(ImageBehavior.AnimatedSourceProperty);
image1.Source = images[index];
RequestNewImages();
}

image1.Source = images[index];
}

private void RequestNewImages()
{
//if (images.Count() < index + 1) return;

var req = WebRequest.Create(url + domain + "/posts/photo?api_key=" + api_key + "&offset=" + index + "&limit=10");
var req = WebRequest.Create(url + domain + "/posts/photo?api_key=" + api_key + "&offset=" + forward_index + "&limit=10");
var stream = req.GetResponse().GetResponseStream();

//JSON
using (var sr = new StreamReader(stream))
{
String json = sr.ReadToEnd();
//Console.Write(json);

var result = JsonConvert.DeserializeObject<TumblrPost>(json);//jsonをパース

foreach (var post in result.response.posts)
{
String imgUrl = post.photos[0].original_size.url;
Console.WriteLine(imgUrl);

var image = new BitmapImage(new Uri(imgUrl));

images.Add(image);
}
}

forward_index += 10;
}

private void Window_KeyDown(object sender, KeyEventArgs e)
Expand Down
3 changes: 0 additions & 3 deletions tumblrAppWPF/tumblrAppWPF.csproj
Expand Up @@ -57,9 +57,6 @@
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsFormsIntegration" />
<Reference Include="WpfAnimatedGif">
<HintPath>..\packages\WpfAnimatedGif.1.4.4\lib\net\WpfAnimatedGif.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down

0 comments on commit 69e1618

Please sign in to comment.