Skip to content

Commit

Permalink
EmbeddedResource test + missing null check
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Mar 1, 2018
1 parent 1ab2b92 commit b22d83a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion glidex.forms.sample/Forms/Images.cs
Expand Up @@ -10,7 +10,7 @@ public static class Images
static readonly Random random = new Random ();
static readonly string tempDir = Path.Combine (Path.GetTempPath (), "glide.forms.sample");
static readonly string tempPath = Path.Combine (tempDir, "temp.jpg");
const int MaxImages = 9;
const int MaxImages = 10;

public static IEnumerable<ImageSource> RandomSources ()
{
Expand Down Expand Up @@ -50,6 +50,9 @@ public static ImageSource RandomSource ()
//Stream
case 8:
return ImageSource.FromStream (() => Android.App.Application.Context.Assets.Open ("assetpatch2.jpg"));
//Embedded Resource
case 9:
return ImageSource.FromResource ("Android.Glide.Sample.embeddedpatch1.jpg", typeof (App));
default:
throw new NotImplementedException ($"Whoops {x} not implemented!");
}
Expand Down
Binary file added glidex.forms.sample/embeddedpatch1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions glidex.forms.sample/glidex.forms.sample.csproj
Expand Up @@ -124,5 +124,8 @@
<ItemGroup>
<AndroidAsset Include="Assets\assetpatch2.jpg" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="embeddedpatch1.jpg" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion glidex.forms/ImageRenderer.cs
Expand Up @@ -168,7 +168,7 @@ async void UpdateSource ()
var token = new CancellationToken ();
using (var memoryStream = new MemoryStream ())
using (var stream = await streamSource.Stream (token)) {
if (token.IsCancellationRequested || source != _element.Source)
if (token.IsCancellationRequested || stream == null || source != _element.Source)
return;
stream.CopyTo (memoryStream);
builder = request.Load (memoryStream.ToArray ());
Expand Down

0 comments on commit b22d83a

Please sign in to comment.