33using System . Threading ;
44using System . Threading . Tasks ;
55using Android . Content ;
6+ using Android . Graphics ;
67using Android . Graphics . Drawables ;
78using Android . Widget ;
89using Bumptech . Glide ;
1112using Microsoft . Extensions . Logging ;
1213using Microsoft . Maui . Controls . PlatformConfiguration ;
1314using Microsoft . Maui . Platform ;
15+ using Path = System . IO . Path ;
1416
1517namespace AuroraControls ;
1618
1719internal partial class NoCacheFileImageSourceService
1820{
19- public override Task < IImageSourceServiceResult ? > LoadDrawableAsync ( IImageSource imageSource , ImageView imageView ,
21+ public override async Task < IImageSourceServiceResult ? > LoadDrawableAsync ( IImageSource imageSource , ImageView imageView ,
2022 CancellationToken cancellationToken = default )
2123 {
2224 var fileImageSource = ( INoCacheFileImageSource ) imageSource ;
@@ -33,14 +35,15 @@ internal partial class NoCacheFileImageSourceService
3335 if ( id > 0 )
3436 {
3537 imageView . SetImageResource ( id ) ;
36- return Task . FromResult < IImageSourceServiceResult ? > ( new ImageSourceServiceLoadResult ( ) ) ;
38+ return new ImageSourceServiceLoadResult ( ) ;
3739 }
3840 }
3941
40- using var pathDrawable = Drawable . CreateFromPath ( file ) ;
42+ using var pathBitmap = await BitmapFactory . DecodeFileAsync ( file ) ;
43+ using var pathDrawable = new BitmapDrawable ( Platform . AppContext . Resources , pathBitmap ) ;
4144 imageView . SetImageDrawable ( pathDrawable ) ;
4245
43- return Task . FromResult < IImageSourceServiceResult ? > ( new ImageSourceServiceLoadResult ( ) ) ;
46+ return new ImageSourceServiceLoadResult ( ) ;
4447 }
4548 catch ( Exception ex )
4649 {
@@ -49,10 +52,10 @@ internal partial class NoCacheFileImageSourceService
4952 }
5053 }
5154
52- return Task . FromResult < IImageSourceServiceResult ? > ( null ) ;
55+ return null ;
5356 }
5457
55- public override Task < IImageSourceServiceResult < Drawable > ? > GetDrawableAsync ( IImageSource imageSource , Context context ,
58+ public override async Task < IImageSourceServiceResult < Drawable > ? > GetDrawableAsync ( IImageSource imageSource , Context context ,
5659 CancellationToken cancellationToken = default )
5760 {
5861 var fileImageSource = ( INoCacheFileImageSource ) imageSource ;
@@ -70,13 +73,14 @@ internal partial class NoCacheFileImageSourceService
7073 var d = context ? . GetDrawable ( id ) ;
7174 if ( d is not null )
7275 {
73- return Task . FromResult < IImageSourceServiceResult < Drawable > ? > ( new ImageSourceServiceResult ( d ) ) ;
76+ return new ImageSourceServiceResult ( d ) ;
7477 }
7578 }
7679 }
7780
78- var pathDrawable = Drawable . CreateFromPath ( file ) ;
79- return Task . FromResult < IImageSourceServiceResult < Drawable > ? > ( new ImageSourceServiceResult ( pathDrawable ) ) ;
81+ var pathBitmap = await BitmapFactory . DecodeFileAsync ( file ) ;
82+ var pathDrawable = new BitmapDrawable ( Platform . AppContext . Resources , pathBitmap ) ;
83+ return new ImageSourceServiceResult ( pathDrawable ) ;
8084 }
8185 catch ( Exception ex )
8286 {
@@ -85,7 +89,7 @@ internal partial class NoCacheFileImageSourceService
8589 }
8690 }
8791
88- return Task . FromResult < IImageSourceServiceResult < Drawable > ? > ( null ) ;
92+ return null ;
8993 }
9094}
9195
0 commit comments