Skip to content

Commit

Permalink
Merge pull request #19 from c1rus/null-check
Browse files Browse the repository at this point in the history
Allow empty path
  • Loading branch information
molinch committed May 8, 2015
2 parents dbea6f2 + 74d0279 commit a1708ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 0 additions & 5 deletions FFImageLoading.Common/Work/WorkScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ public async void LoadImage(IImageLoaderTask task)
if (task == null || task.IsCancelled)
return;

if (string.IsNullOrWhiteSpace(task.GetKey()))
{
throw new Exception("Image loading key can not be null, empty or a whitespace");
}

bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);
if (loadedFromCache)
{
Expand Down
14 changes: 12 additions & 2 deletions FFImageLoading.Droid/Work/ImageLoaderTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,16 @@ private async Task<CacheResult> TryLoadingFromCacheAsync(ImageView imageView)
if (imageView == null)
return CacheResult.NotFound; // weird situation, dunno what to do

var value = ImageCache.Instance.Get(GetKey());
var key = GetKey();

if (string.IsNullOrWhiteSpace(key))
return CacheResult.NotFound;

var value = ImageCache.Instance.Get(key);
if (value == null)
return CacheResult.NotFound; // not available in the cache

Logger.Debug(string.Format("Image from cache: {0}", GetKey()));
Logger.Debug(string.Format("Image from cache: {0}", key));
await MainThreadDispatcher.PostAsync(() =>
{
imageView.SetImageDrawable(value);
Expand Down Expand Up @@ -396,6 +401,9 @@ await MainThreadDispatcher.PostAsync(() =>
private async Task<Stream> GetStreamAsync(string path, ImageSource source)
{
Stream stream = null;

if (string.IsNullOrWhiteSpace(path)) return null;

try
{
switch (source)
Expand Down Expand Up @@ -425,6 +433,8 @@ private async Task<Stream> GetStreamAsync(string path, ImageSource source)
// having a width and height equal to or larger than the requested width and height.
private async Task<BitmapDrawable> RetrieveDrawableAsync(string sourcePath, ImageSource source, bool isLoadingPlaceHolder)
{
if (string.IsNullOrWhiteSpace(sourcePath)) return null;

// If the image cache is available and this task has not been cancelled by another
// thread and the ImageView that was originally bound to this task is still bound back
// to this task and our "exit early" flag is not set then try and fetch the bitmap from
Expand Down

0 comments on commit a1708ab

Please sign in to comment.