<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Erselan Khan</title>
    <description>The latest articles on DEV Community by Erselan Khan (@erselankhan).</description>
    <link>https://dev.to/erselankhan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1013790%2Ffe34f120-8741-418b-a1e3-21b94e5d8e1e.jpeg</url>
      <title>DEV Community: Erselan Khan</title>
      <link>https://dev.to/erselankhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/erselankhan"/>
    <language>en</language>
    <item>
      <title>Image URL to Bitmap using Coil in Jetpack Compose | Erselan Khan</title>
      <dc:creator>Erselan Khan</dc:creator>
      <pubDate>Tue, 14 Feb 2023 20:12:27 +0000</pubDate>
      <link>https://dev.to/erselankhan/image-url-to-bitmap-using-coil-in-jetpack-compose-erselan-khan-1dc5</link>
      <guid>https://dev.to/erselankhan/image-url-to-bitmap-using-coil-in-jetpack-compose-erselan-khan-1dc5</guid>
      <description>&lt;p&gt;Today we will show you how we can convert the Image URL to Bitmap using Coil in Jetpack Compose. But before moving forward, I would like to ask you to please follow my account to get the latest updates about Android and other tech-related topics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8zhn052qkvvx839hrwh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8zhn052qkvvx839hrwh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Coil?
&lt;/h2&gt;

&lt;p&gt;An image loading library for Android backed by Kotlin Coroutines. Coil is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;- &lt;strong&gt;Fast&lt;/strong&gt;: Coil performs a number of optimizations including memory and disk caching, downsampling the image in memory, automatically pausing/cancelling requests, and more.&lt;/li&gt;
&lt;li&gt;- &lt;strong&gt;Lightweight&lt;/strong&gt;: Coil adds ~2000 methods to your APK (for apps that already use OkHttp and Coroutines), which is comparable to Picasso and significantly less than Glide and Fresco.&lt;/li&gt;
&lt;li&gt;- &lt;strong&gt;Easy to use&lt;/strong&gt;: Coil’s API leverages Kotlin’s language features for simplicity and minimal boilerplate.&lt;/li&gt;
&lt;li&gt;- &lt;strong&gt;Modern&lt;/strong&gt;: Coil is Kotlin-first and uses modern libraries including Coroutines, OkHttp, Okio, and AndroidX Lifecycles.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation:
&lt;/h2&gt;

&lt;p&gt;I have made this example in Jetpack Compose, but we can also do this without Jetpack Compose. Let’s create an Activity:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            JetpackComposeUtilsTheme {
                val scope = rememberCoroutineScope()
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    urlToBitmap(
                        scope = scope,
                        imageURL = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg",
                        context = LocalContext.current,
                        onSuccess = {
                            it
                        },
                        onError = {
                            it
                        }
                    )
                }
            }
        }
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We have created a method i.e: urlToBitmap, which takes some parameters like coroutine scope, image URL, and context. It also gives the callback in case of Success and Error.&lt;/p&gt;

&lt;p&gt;We are using rememberCoroutineScope() for getting the CoroutineScope instance to pass in our function to load the image data using Dispatchers.IO.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

fun urlToBitmap(
    scope: CoroutineScope,
    imageURL: String,
    context: Context,
    onSuccess: (bitmap: Bitmap) -&amp;gt; Unit,
    onError: (error: Throwable) -&amp;gt; Unit
) {
    var bitmap: Bitmap? = null
    val loadBitmap = scope.launch(Dispatchers.IO) {
        val loader = ImageLoader(context)
        val request = ImageRequest.Builder(context)
            .data(imageURL)
            .allowHardware(false)
            .build()
        val result = loader.execute(request)
        if (result is SuccessResult) {
            bitmap = (result.drawable as BitmapDrawable).bitmap
        } else if (result is ErrorResult) {
            cancel(result.throwable.localizedMessage ?: "ErrorResult", result.throwable)
        }
    }
    loadBitmap.invokeOnCompletion { throwable -&amp;gt;
        bitmap?.let {
            onSuccess(it)
        } ?: throwable?.let {
            onError(it)
        } ?: onError(Throwable("Undefined Error"))
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We load the image inside the coroutine scope and give a callback on its completion. We cancel the coroutine job in case of ErrorResult and pass the error message and throwable to the coroutine cancel() function.&lt;/p&gt;

&lt;p&gt;After the coroutine job is completed, we got the callback on invokeOnCompletion. We checked whether the bitmap object is null or not, if it is not null, we call the onSuccess otherwise we call the onError.&lt;/p&gt;

&lt;p&gt;Project Github Link: &lt;a href="https://github.com/arsalankhan994/jetpack-compose-utils" rel="noopener noreferrer"&gt;https://github.com/arsalankhan994/jetpack-compose-utils&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it for now. I will cover more topics on Android, Java, Kotlin, and Springboot in my upcoming articles. If you like this article then Clap as much as you can 🤐&lt;/p&gt;

&lt;h2&gt;
  
  
  In case you missed: 🤐
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://towardsdev.com/parallel-multiple-api-calls-or-network-calls-using-kotlin-coroutines-40cb5f313171" rel="noopener noreferrer"&gt;https://towardsdev.com/parallel-multiple-api-calls-or-network-calls-using-kotlin-coroutines-40cb5f313171&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://erselankhan.medium.com/communication-between-modules-in-android-erselan-khan-2c2ae5684024" rel="noopener noreferrer"&gt;https://erselankhan.medium.com/communication-between-modules-in-android-erselan-khan-2c2ae5684024&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/bazaar-tech/dynamically-update-refresh-reload-viewpager2-fragments-588fcbd6f859" rel="noopener noreferrer"&gt;https://medium.com/bazaar-tech/dynamically-update-refresh-reload-viewpager2-fragments-588fcbd6f859&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Show your love ❤️ by sharing this article with your fellow developers 😅 and also following my Medium account ✈️&lt;/p&gt;

&lt;p&gt;(Follow me for more content about Android, Kotlin, and other technologies. If you have any questions, go ahead and ask me here or email me at &lt;a href="mailto:arsalankhan994@gmail.com"&gt;arsalankhan994@gmail.com&lt;/a&gt; and I’ll do my best to respond.)&lt;/p&gt;

</description>
      <category>android</category>
      <category>coil</category>
      <category>compose</category>
      <category>jetpack</category>
    </item>
    <item>
      <title>The story behind Spelling Checker App | Erselan Khan</title>
      <dc:creator>Erselan Khan</dc:creator>
      <pubDate>Tue, 14 Feb 2023 13:31:55 +0000</pubDate>
      <link>https://dev.to/erselankhan/the-story-behind-spelling-checker-app-erselan-khan-469h</link>
      <guid>https://dev.to/erselankhan/the-story-behind-spelling-checker-app-erselan-khan-469h</guid>
      <description>&lt;p&gt;Hey guys! before moving forward to the article, I would like to request you all kindly download the &lt;strong&gt;Spelling Checker&lt;/strong&gt; app and give your reviews and feedback on the &lt;strong&gt;Google Play Store&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Download now: [&lt;a href="https://play.google.com/store/apps/details?id=com.apphut.spellingchecker" rel="noopener noreferrer"&gt;https://play.google.com/store/apps/details?id=com.apphut.spellingchecker&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9d4wm4aahen25d0pswlu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9d4wm4aahen25d0pswlu.gif" alt="Image description" width="480" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Story:
&lt;/h2&gt;

&lt;p&gt;So the story is that, when I was scrolling my Facebook feeds, I saw a post on the Soul Brothers Pakistan group. One of our soul brothers had shared his story. He applied for immigration to Canada, but his process took some time and finally, one day his immigration process got approved by the Canadian embassy. When his process got approved, he also got married at this time. So he shared his marriage certificate with the Canadian embassy for her wife’s immigration process. But this time, the Canadian embassy rejected his wife’s immigration process because of a very small spelling mistake.&lt;/p&gt;

&lt;p&gt;So the mistake on his marriage certificate was that the title of the marriage certificate should be “&lt;strong&gt;Govt of Pakistan&lt;/strong&gt;”, but It was mistaken as “&lt;strong&gt;Govt of Pkistan&lt;/strong&gt;”. The Canadian embassy considered that the marriage certificate is fake and that’s why they rejected the whole immigration process for his wife.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea for Spelling Checker App:
&lt;/h2&gt;

&lt;p&gt;So after I read the post and thought about the solution to how I can help people get rid of these kinds of mistakes. So I built an app the Spelling Checker app. The Spelling checker app helps you to find out the spelling mistakes in your document in very few seconds. There are a few steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;- Take a picture from your phone camera.&lt;/li&gt;
&lt;li&gt;- or Select a picture from your phone gallery.&lt;/li&gt;
&lt;li&gt;- You can crop the picture if you want to.&lt;/li&gt;
&lt;li&gt;- Boom! the app will highlight all the mistakes in yellow colour.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb2ve2p6mntw0skk2sz4m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb2ve2p6mntw0skk2sz4m.png" alt="Image description" width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you all take benefit from this app. I am signing off for now and waiting for the feedback and reviews from all of you!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>snippet</category>
      <category>resources</category>
    </item>
  </channel>
</rss>
