<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hamza Oban on Medium]]></title>
        <description><![CDATA[Stories by Hamza Oban on Medium]]></description>
        <link>https://medium.com/@HamzaObann?source=rss-1cdd9130c2b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LJHicGhhNODU6LBjyYTAsQ.jpeg</url>
            <title>Stories by Hamza Oban on Medium</title>
            <link>https://medium.com/@HamzaObann?source=rss-1cdd9130c2b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:50:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@HamzaObann/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Google Gemini: a largest and most capable AI model]]></title>
            <link>https://medium.com/@HamzaObann/google-gemini-a-largest-and-most-capable-ai-model-2a872fd8dad0?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a872fd8dad0</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Tue, 09 Jan 2024 10:57:28 GMT</pubDate>
            <atom:updated>2024-01-09T10:57:28.886Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38Vc_DrA9RakZxrDGXRaSw.png" /></figure><h4>What is Gemini?</h4><p>In this article, I will talk about Gemini, which claims to be stronger than ChatGPT.</p><p>Google and Google DeepMind introduced the long-awaited AI model Gemini.</p><p>Gemini models are trained to accommodate textual input interleaved with a wide variety of audio and visual inputs, such as natural images, charts, screenshots, PDFs, and videos, and they can produce text and image outputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnHGkLEir4XijgPz8INnlQ.png" /><figcaption>Source: <a href="https://storage.googleapis.com/deepmind-media/gemini/gemini_1_report.pdf">Google DeepMind</a></figcaption></figure><p>There’s still no word on how well it works, but the reported performance is very good, even better than ChatGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_U2fFLyZHy8fVp_jcEjDdw.png" /><figcaption>Performance data reported by Google</figcaption></figure><h3>Gemini comes in three sizes</h3><blockquote>Ultra — Pro — Nano</blockquote><ul><li><strong>Ultra</strong> : Our most capable and largest model for highly-complex tasks.</li><li><strong>Pro</strong> : Our best model for scaling across a wide range of tasks.*</li><li><strong>Nano</strong> : Our most efficient model for on-device tasks.</li></ul><blockquote>The most important feature that Gemini offers us is that we can include it in our Android Applications.</blockquote><h3>Using Gemini API in Android Application</h3><blockquote>There are two ways to implement gemini</blockquote><h4>1. Select Gemini Starter Template with the <a href="https://developer.android.com/studio/preview?hl=en">latest preview version</a> of Android Studio</h4><h4>Step 1 — Build on the New Project template for AI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*Q6OAQRrCrmYSk8TjgVOV7w.png" /></figure><h4>Step 2 — Generate the <a href="https://makersuite.google.com/">API</a> key</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*B48TurnJBg-n6NxB1LQN8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*a6GtyXVah4I2wwdeZ9MmdA.png" /></figure><h3>Step 3 — Start prototyping</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7wSZ346Cf_r4ohYC629MQ.png" /></figure><h4>2. Add the SDK dependency to your project</h4><h4><strong>Step: 1 — Add the dependency</strong></h4><p>In your <strong>module (app-level)</strong> Gradle configuration file, add the dependency for the Google AI SDK for Android:</p><pre>dependencies {<br>  // add the dependency for the Google AI client SDK for Android<br>  implementation(&quot;com.google.ai.client.generativeai:generativeai:0.1.1&quot;)<br>}</pre><h4>Step: 2 — Initialize the Generative Model</h4><p>Initialize the GenerativeModelobject:</p><pre>val generativeModel = GenerativeModel(<br>    //Gemini offers two models. The first one is gemini-pro, the second one is gemini-pro-vision<br>    modelName = &quot;MODEL_NAME&quot;,<br>    // Access your API key as a Build Configuration variable (see &quot;Set up your API key&quot; above)<br>    apiKey = BuildConfig.apiKey<br>)</pre><h4>Step: 3 — Generate text from text-only input</h4><pre>val prompt = &quot;What is Jetpack Compose?&quot;<br>val response = generativeModel.generateContent(prompt)</pre><p>Gemini provides a multimodal model (gemini-pro-vision), so you can input both text and images. Make sure to review the <a href="https://ai.google.dev/docs/gemini_api_overview#image_requirements">image requirements for prompts</a>.</p><h3>Conclusion</h3><p>We created your first Generative AI app in Android Studio</p><p>In both methods, we implemented Gemini in our Android Application.</p><p>I hope it was a useful article for you! See you in my other articles!</p><blockquote><em>Don’t forget to clap 👏</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a872fd8dad0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WorkManager Guide | Periodic and One-time | Android]]></title>
            <link>https://medium.com/orion-innovation-techclub/workmanager-guide-periodic-and-one-time-android-e8e2a638ed67?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8e2a638ed67</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <category><![CDATA[workmanager]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 05:53:12 GMT</pubDate>
            <atom:updated>2024-01-11T17:44:24.693Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DEEMaLEshujUbRlBWbLmWQ.png" /></figure><h3>Contents</h3><ul><li>What is WorkManager?</li><li>When is WorkManager used?</li><li>Implementing the WorkManager</li><li>How to define Periodic and One-time request?</li><li>What is a work chaining?</li><li>Observing the works.</li></ul><h3>What is WorkManager?</h3><p>WorkManager is one of the Android <strong>Jetpack</strong> components and is used to manage the <strong>scheduling of jobs</strong>. It allows you to manage your work when your app is <strong>running in the background</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*be1bDV-EsC7-4sfgmmOmJw.png" /><figcaption>Types of persistent work</figcaption></figure><p>The following table summarizes the various types of work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2cLhOGKjrPFxVnwBq9TfFw.png" /></figure><h3>When is WorkManager used?</h3><ul><li>If you want to manage your work when your app is running in the background</li><li>If you want it to work compatible with different Android versions</li><li>If you want to manage your business according to different priority levels</li><li>If you want to trigger your jobs at a certain time or periodically</li></ul><h3>Implementing the WorkManager</h3><p>To use WorkManager, you must first create a project in Android Studio. Next, the WorkManager library needs to be added to your app <strong>build.gradle</strong> file.</p><blockquote>It doesn’t matter if you use Kotlin or Java.</blockquote><pre>dependencies {<br>   def work_version = &quot;2.5.0&quot;<br><br>   // Java<br>   implementation &quot;androidx.work:work-runtime:$work_version&quot;<br><br>   // Kotlin + coroutines<br>   implementation &quot;androidx.work:work-runtime-ktx:$work_version&quot;<br>}</pre><p>That is all. Now we can use <strong>WorkManager</strong>.</p><p>We will make an application that updates an Int value we created with SharedPreferences using WorkManager.</p><p>We include the Worker abstract class and implement the “<strong>doWork</strong>” function.</p><p>We create the SharedPreferences object and create an Int value and increase the value we created (with the value passed to us from MainActivity)</p><p>We can get the value sent here from MainActivity with <strong>input Data</strong>.</p><p>Input Data structure works with <strong>key-values pairs</strong>. Just like sharedPreferences or intent.</p><p>We call the refreshDatabase function we created in doWork.</p><pre>class RefreshDatabase(val context: Context, workerParams: WorkerParameters) : Worker(context,<br>    workerParams<br>) {<br><br>    override fun doWork(): Result {<br>        val data = inputData<br>        val myNumber = data.getInt(&quot;intKey&quot;,0)<br>        refreshDatabase(myNumber)<br>        return Result.success()<br>    }<br><br>    private fun refreshDatabase(myNumber : Int){<br>        val sharedPreferences = context.getSharedPreferences(&quot;com.example.workmanager&quot;,Context.MODE_PRIVATE)<br>        var mySavedNumber = sharedPreferences.getInt(&quot;myNumber&quot;,0)<br>        mySavedNumber += myNumber<br>        println(mySavedNumber)<br>        sharedPreferences.edit().putInt(&quot;myNumber&quot;,mySavedNumber).apply()<br><br>    }<br>}</pre><p>If you don’t know SharedPreferences, you can read <a href="https://blog.devgenius.io/using-sharedpreferences-with-android-3a8a953cae4f">my article</a>.</p><p>Let’s see what we did in MainActivity.</p><p>We are sending the value to RefreshDatabase using the <strong>Data</strong> Class.</p><h4>Work constraints</h4><p>Declaratively define the optimal conditions for your work to run using <a href="https://developer.android.com/topic/libraries/architecture/workmanager/how-to/define-work#work-constraints">work constraints</a>. For example, run only when the device is on an unmetered network, when the device is idle, or when it has sufficient battery.</p><h4>WorkRequest</h4><p>WorkManager allows you to <a href="https://developer.android.com/topic/libraries/architecture/workmanager/how-to/define-work">schedule work</a> to run <a href="https://developer.android.com/reference/androidx/work/OneTimeWorkRequest">one-time</a> or <a href="https://developer.android.com/reference/androidx/work/PeriodicWorkRequest">repeatedly</a> using flexible scheduling windows. Work can be tagged and named as well, allowing you to schedule unique, replaceable work and monitor or cancel groups of work together.</p><p>Let’s see how we do it when we want to do a <strong>one-time</strong> job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZKaoezDSKTrUGfjZYWkSCg.png" /><figcaption>One-time.</figcaption></figure><p>While creating the <strong>WorkRequest</strong>, it asks us for a type and we created the RefreshDatabase.</p><p>We used <strong>WorkManager</strong> to initialize WorkRequest.</p><p>Let’s see how we do it when we want to do a <strong>periodic</strong> job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CUWqyY8LQrXQZxSVKTyHqw.png" /></figure><p>Unlike one-time, it asks us for two parameters. We say that we will update our database every 15 minutes in line with the parameters we have given.</p><h3>Work chaining</h3><p>For complex related work, chain individual work tasks together using an intuitive interface that allows you to control which pieces run sequentially and which run in parallel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sK7CA-SaqhykeIW9Kmo9gQ.png" /></figure><p>We specify which job to start with with the “<strong>beginWith</strong>” function. We determine the next jobs with the “<strong>then</strong>” function.</p><p>If you want to finish all work, you should call <strong>cancelAllWork</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAj4ydEqAulCvWBw8Pf-Gg.png" /><figcaption>cancelAllWork</figcaption></figure><h4>Observing the works</h4><p>Finally, you can observe all jobs according to their <strong>id</strong> or <strong>tags</strong>, with <strong>LiveData</strong> support.</p><p>In our example, you can observe the status of jobs with <strong>WorkInfo</strong>.</p><p>Let’s see our example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hE0ypuhPC75BjQiA8jfPEA.png" /></figure><h3>Conclusion</h3><p>The WorkManager API is the recommended replacement for all previous Android background scheduling APIs, including <strong>FirebaseJobDispatcher</strong>, <strong>GcmNetworkManager</strong>, and <strong>Job Scheduler</strong>.</p><p>I hope it was a useful article for you! See you in my other articles.</p><blockquote><em>Don’t forget to clap 👏</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8e2a638ed67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orion-innovation-techclub/workmanager-guide-periodic-and-one-time-android-e8e2a638ed67">WorkManager Guide | Periodic and One-time | Android</a> was originally published in <a href="https://medium.com/orion-innovation-techclub">Orion Innovation techClub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Enum Class]]></title>
            <link>https://medium.com/orion-innovation-techclub/kotlin-enum-class-8ee611eb942f?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ee611eb942f</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 06:27:43 GMT</pubDate>
            <atom:updated>2024-01-11T17:42:58.273Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xF1C2XjsRmngLGM1qyZX-w.png" /></figure><h4>What are Enums and how to use them with Kotlin.</h4><p>An enum class is used to create types with a limited set of possible values.</p><p>We can create enum classes with this syntax.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*gro_3nbO0olcwn0bUDdf_Q.png" /><figcaption>The syntax</figcaption></figure><p>We can use this enum class we created as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*bA2LzO0JrtyBsqUHTRCu4w.png" /><figcaption>Usage</figcaption></figure><p>In the real world, for example, the game levels— <em>BEGINNER</em>, <em>EASY</em>, <em>MEDIUM</em>, <em>HARD and IMPOSSIBLE </em>— could be represented by an enum class</p><pre>enum class Level {<br>    BEGINNER,EASY,MEDIUM,HARD,IMPOSSIBLE<br>}</pre><p>Each enum constant is an object. Enum constants are separated by commas.</p><p>Enum class can take parameters. It is mandatory to give this parameter to every enum constant when it takes a parameter.</p><p>For example:</p><pre>enum class Country(val capital: String) {<br>    Turkey(&quot;Ankara&quot;),<br>    Germany(&quot;Berlin&quot;),<br>    England(&quot;London&quot;)<br>}</pre><blockquote>Objects of <strong>Enum classes cannot be created.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fC7h5h3utDevB1Qbqmc-JQ.png" /></figure><h3>Implementing interfaces in enum classes</h3><blockquote>Enum classes<strong> cannot inherit any class</strong>. But <strong>they can implement any interface.</strong></blockquote><p>Let’s create our interface</p><pre>interface Attribute{<br>    fun numberOfDoors(): Int<br>    fun color(): String<br>    fun brand(): String<br>    fun maxSpeed(): Int<br>}</pre><p>Let’s implement our interface in our car enum class.</p><pre>enum class Car : Attribute {<br>    FordFocus {<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Gray&quot;<br><br>        override fun brand(): String = &quot;Ford&quot;<br><br>        override fun maxSpeed(): Int = 240<br><br>    },<br>    JeepWrangler {<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Black&quot;<br><br>        override fun brand(): String = &quot;Jeep&quot;<br><br>        override fun maxSpeed(): Int = 280<br><br>    },<br>    NissanMicra {<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Red&quot;<br><br>        override fun brand(): String = &quot;Nissan&quot;<br><br>        override fun maxSpeed(): Int = 200<br>    };<br>}</pre><p>Let’s look at the results in the main func.</p><pre>fun main() {<br>    Car.FordFocus.let {<br>        println(&quot;${it.brand()} ${it.color()} ${it.numberOfDoors()} ${it.maxSpeed()}&quot;)<br>    }<br>    Car.JeepWrangler.let {<br>        println(&quot;${it.brand()} ${it.color()} ${it.numberOfDoors()} ${it.maxSpeed()}&quot;)<br>    }<br>    Car.NissanMicra.let {<br>        println(&quot;${it.brand()} ${it.color()} ${it.numberOfDoors()} ${it.maxSpeed()}&quot;)<br>    }<br><br>}</pre><h3>Implementing abstract values and functions in enum classes</h3><blockquote>All enum constants must override these abstract structures.</blockquote><pre>enum class Car {<br>    FordFocus{<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Gray&quot;<br><br>        override fun brand(): String = &quot;Ford&quot;<br><br>        override fun maxSpeed(): Int = 240<br><br>    },<br>    JeepWrangler {<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Black&quot;<br><br>        override fun brand(): String = &quot;Jeep&quot;<br><br>        override fun maxSpeed(): Int = 280<br><br>    },<br>    NissanMicra{<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Red&quot;<br><br>        override fun brand(): String = &quot;Nissan&quot;<br><br>        override fun maxSpeed(): Int = 200<br>    };<br>    abstract fun numberOfDoors(): Int<br>    abstract fun color(): String<br>    abstract fun brand(): String<br>    abstract fun maxSpeed(): Int<br>}</pre><p>Additionally, open functions can be written inside enum classes.</p><pre>enum class Car2 {<br>    FordFocus{<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Gray&quot;<br><br>        override fun brand(): String = &quot;Ford&quot;<br><br>        override fun maxSpeed(): Int = 240<br><br>    },<br>    JeepWrangler {<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Black&quot;<br><br>        override fun brand(): String = &quot;Jeep&quot;<br><br>        override fun maxSpeed(): Int = 280<br><br>    },<br>    NissanMicra{<br>        override fun numberOfDoors(): Int = 4<br><br>        override fun color(): String = &quot;Red&quot;<br><br>        override fun brand(): String = &quot;Nissan&quot;<br><br>        override fun maxSpeed(): Int = 200<br><br>        override fun modify() {<br>            super.modify()<br>            println(&quot;Change color&quot;)<br>        }<br>    };<br>    abstract fun numberOfDoors(): Int<br>    abstract fun color(): String<br>    abstract fun brand(): String<br>    abstract fun maxSpeed(): Int<br><br>    open fun modify(){<br>        println(&quot;Modify&quot;)<br>    }<br>}</pre><p>Overriding these explicit functions in enum constants is entirely optional.</p><h3>Conclusion</h3><p>As a result, Enum classes allow the grouping of the same datasets for their intended use, giving us convenience. Thus, we can easily see the available options with the data sets we have grouped. Enum classes are frequently used because they make our work very easy. That’s why I took care to mention all the properties of enum classes. I hope it was a useful article for you! See you in my other articles!</p><p>As a result, Enum classes provide us convenience by allowing the same datasets to be grouped according to their intended use. Thus, we can easily see the available options with the data sets we have grouped. Enum classes are often used because they make our job so much easier. That’s why I took care to mention all the properties of enum classes. I hope it was a useful article for you! See you in my other articles!</p><blockquote>Don’t forget to clap 👏</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ee611eb942f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orion-innovation-techclub/kotlin-enum-class-8ee611eb942f">Kotlin Enum Class</a> was originally published in <a href="https://medium.com/orion-innovation-techclub">Orion Innovation techClub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[companion objects and object in Kotlin]]></title>
            <link>https://blog.devgenius.io/companion-objects-and-object-in-kotlin-4c0a6d101bbc?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c0a6d101bbc</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[companion-object]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 19:07:03 GMT</pubDate>
            <atom:updated>2024-01-11T17:44:58.755Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QswwSyCEP_pBqGuXgbKt-A.png" /></figure><h3>What are the companion objects?</h3><p>In some languages like Java and C#, we use <strong>static</strong> keywords to declare the members of the class and use them without making any object i.e. just call them with the help of the class name.</p><p>The static keyword is also used to create <a href="https://en.wikipedia.org/wiki/Singleton_pattern">Singletons</a>, one of the most widely used design patterns.</p><blockquote>In Kotlin we don’t use static keywords, instead, we use <strong>companion objects</strong>.</blockquote><h4><strong>For example</strong></h4><p>Let’s create the <strong>Player</strong> class and get a <strong>value</strong> in the <strong>primary constructor</strong>.</p><p>Let’s define the <strong>companion object</strong> inside this class.</p><p>Let the companion object have a <strong>score</strong> value.</p><p>Finally, let’s write a function that increases the <strong>Score</strong> value.</p><pre>class Player(private val value : Int){<br>    fun increaseScore(){<br>        score += value<br>    }<br>    companion object{<br>        var score : Int = 0<br>    }<br>}</pre><p>Let’s see how we call it in the main function.</p><pre>fun main() {<br>    val player1 = Player(10)<br>    val player2 = Player(20)<br>    player1.increaseScore()<br>    player2.increaseScore()<br><br>    println(Player.score)<br>}</pre><p>We will see the value <strong>30</strong> as the output.</p><h4>Conclusion</h4><p>We access the <strong>score</strong> value directly with the name of the class</p><h3>What is the object?</h3><p>Kotlin has a more elegant way to deal with this. You can use a single keyword: object, to implement the Singleton pattern.</p><h4>For example</h4><p>This way we can set up a singleton structure in kotlin.</p><p>We can access it directly by saying <strong>Singleton.name</strong> and <strong>Singleton.reverseName()</strong>.</p><pre>object Singleton{<br>    var name = &quot;&quot;<br>    fun reverseName(){<br>        name = name.reversed()<br>    }<br>}</pre><p>Let’s see what we call it in the main function.</p><pre>fun main() {<br>    Singleton.name = &quot;Hamza&quot;<br>    Singleton.reverseName()<br>    println(Singleton.name)<br>}</pre><h4>Conclusion</h4><p>This structure allows us to access everything using the Class name without creating an object.</p><p>Here you can now use companion objects and object.</p><blockquote>If my spelling is helpful, don’t forget to clap! :)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c0a6d101bbc" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/companion-objects-and-object-in-kotlin-4c0a6d101bbc">companion objects and object in Kotlin</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using SharedPreferences with Android]]></title>
            <link>https://blog.devgenius.io/using-sharedpreferences-with-android-3a8a953cae4f?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a8a953cae4f</guid>
            <category><![CDATA[sharedpreferences]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 19:06:39 GMT</pubDate>
            <atom:updated>2024-01-11T17:45:51.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2H9J2y7s2Ho-JMRRs0NKw.png" /></figure><h3>What are the SharedPreferences?</h3><p>SharedPreferences is a structure where we save our small data to ram. It saves the structure as <strong>key-value</strong> pairs in the XML file. The key we create can only hold one value. We can change the value at any time using this key. The data we save is not deleted unless the application is deleted.</p><h4>What type of data can we save?</h4><p>We can save 7 different types.</p><p>They are <strong>String</strong>, <strong>Int</strong>, <strong>Float</strong>, <strong>Double</strong>, <strong>Long</strong>, <strong>Boolean</strong>, <strong>and StringSet.</strong></p><p>To use it, we need to create the <strong>SharedPreferences</strong> object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5HSglvQ-MLcpT47yNn47hQ.png" /><figcaption>Create the SharedPreferences object</figcaption></figure><p>It asks for a name for the XML it created while creating the object, and secondly, it asks whether this XML can be accessed by someone else.</p><p>To write to SharedPreferences, call <strong>edit()</strong> on your SharedPreferences.</p><p>And call it “<strong>put</strong>” according to the type you want to write.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ShW0Vr4piVlwHYxzZ4hMOg.png" /><figcaption>Write to shared preferences</figcaption></figure><h3>Let’s do a little project now</h3><p>We will make an application where we save and delete some of our information using SharedPreferences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtDEnknN4ZyxS_MAZ9j3rQ.gif" /></figure><p>We can create Shared Preferences object</p><pre>private lateinit var sharedPref: SharedPreferences</pre><p>Now let’s initialize our Shared Preferences object</p><pre>sharedPref = getSharedPreferences(&quot;SharedPreference&quot;, MODE_PRIVATE)</pre><p>Now we can easily write and delete using our sharedPref object.</p><p>Let’s write the <strong>save</strong> function.</p><pre>private fun save(){<br>    //Let&#39;s check if it&#39;s empty <br>    if(binding.nameTextField.editText?.text.isNullOrEmpty() ||<br>        binding.ageTextField.editText?.text.isNullOrEmpty() ||<br>        binding.jobTextField.editText?.text.isNullOrEmpty())<br>    {<br>        Toast.makeText(this,&quot;Boş Bırakılamaz&quot;,Toast.LENGTH_LONG).show()<br>        return<br>    }<br>    //Let&#39;s check that we entered our age as an Int type.<br>    if (!isNumeric(binding.ageTextField.editText?.text.toString())){<br>        Toast.makeText(this,&quot;Sayı Giriniz&quot;,Toast.LENGTH_LONG).show()<br>        return<br>    }<br>    //Let&#39;s get the editText values entered with viewBinding.<br>    val name = binding.nameTextField.editText?.text.toString()<br>    val age = binding.ageTextField.editText?.text.toString().toIntOrNull()<br>    val job = binding.jobTextField.editText?.text.toString()<br>    <br>    //Let&#39;s assign our values to our TextViews<br>    binding.prefNameTextView.text = name<br>    binding.prefJobTextView.text = job<br>    binding.prefAgeTextView.text = age.toString()<br>   <br>    //Here we are writing with the SharedPref object.<br><br>    sharedPref.apply {<br>        edit().putString(&quot;name&quot;,name).apply()<br>        if (age != null) {<br>            edit().putInt(&quot;age&quot;,age).apply()<br>        }<br>        edit().putString(&quot;job&quot;,job).apply()<br>    }<br>}</pre><p>Let’s write the <strong>delete</strong> function</p><p>We perform the writing operation with put and the deletion operation with remove.</p><pre>private fun delete(){<br>        sharedPref.apply {<br>            edit().remove(&quot;name&quot;).apply()<br>            edit().remove(&quot;age&quot;).apply()<br>            edit().remove(&quot;job&quot;).apply()<br>            val age = sharedPref.getInt(&quot;age&quot;,-1)<br>            if (age == -1){<br>                binding.prefJobTextView.text = &quot;Yaşınız&quot;<br>            }<br>            binding.prefNameTextView.text = sharedPref.getString(&quot;name&quot;,&quot;Adınız&quot;)<br><br>            binding.prefAgeTextView.text = sharedPref.getString(&quot;job&quot;,&quot;Mesleğiniz&quot;)<br>        }<br><br><br>    }</pre><p>When the application starts, we get the values we saved in <strong>onCreate</strong>.</p><pre>binding.prefNameTextView.text = sharedPref.getString(&quot;name&quot;,&quot;Adınız&quot;)<br>binding.prefJobTextView.text = sharedPref.getInt(&quot;age&quot;,0).toString()<br>binding.prefAgeTextView.text = sharedPref.getString(&quot;job&quot;,&quot;Mesleğiniz&quot;)</pre><p>We call the <strong>save</strong> and <strong>delete</strong> functions we created when clicking the Save and Delete buttons.</p><pre>binding.saveButton.setOnClickListener {<br>    save()<br>}<br>binding.deleteButton.setOnClickListener {<br>    delete()<br>}</pre><h3>Persistent Data</h3><p>SharedPreferences retains data as long as the application is running. However, the data is lost when the user closes and reopens the app. If you need persistent data, you may need to consider using other mechanisms such as <strong>SQLite </strong>database or <strong>Room </strong>database, which is one of the Jetpack elements.</p><h3>Conclusion</h3><p>Android SharedPreferences provides a convenient mechanism for simple data storage and management. By using key-value pairs, you can store and retrieve data easily. While SharedPreferences is ideal for simple scenarios, complex data structures and scenarios that require persistent data may necessitate the use of other methods.</p><p>Here you can now use SharedPreferences.</p><p>If my spelling is helpful, don’t forget to clap :)</p><h3>Reference</h3><p><a href="https://developer.android.com/training/data-storage/shared-preferences">Android Developer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a8a953cae4f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/using-sharedpreferences-with-android-3a8a953cae4f">Using SharedPreferences with Android</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coroutines on Android]]></title>
            <link>https://medium.com/orion-innovation-techclub/coroutines-on-android-da210315a248?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/da210315a248</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 07:29:05 GMT</pubDate>
            <atom:updated>2023-03-21T07:29:05.120Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9je1JnV4eF4P2tN_7au_uQ.png" /><figcaption>Coroutines</figcaption></figure><h3>What are the coroutines?</h3><p>A coroutine is a concurrency design pattern that you can use on Android to simplify code that executes asynchronously.</p><p>On Android, coroutines help to manage long-running tasks that might otherwise block the main thread and cause your app to become unresponsive.</p><h3><strong>Implementation</strong></h3><pre>dependencies {<br>    implementation(&quot;org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9&quot;)<br>}</pre><h3>Features</h3><p>Features that will help us understand are:</p><p><strong>Lightweight:</strong> You can run many coroutines on a single thread due to support for suspension, which doesn’t block the thread where the coroutine is running.</p><pre> runBlocking {<br>        repeat(10000){//lots of coroutines<br>            launch {<br>                delay(1000)<br>                println(&quot;Android&quot;)<br>            }<br>        }<br>    }</pre><p><strong>Fewer memory leaks:</strong> Use structured concurrency to run operations within a scope.</p><p><strong>Built-in cancellation support</strong>: Cancellation is propagated automatically through the running coroutine hierarchy.</p><pre>suspend fun main() {<br><br>    val job = CoroutineScope(Dispatchers.IO).launch {<br>        repeat(1000) { i -&gt;<br>            println(&quot;job: $i ...&quot;)<br>            delay(500L)<br>        }<br>    }<br>    delay(1300L) // delay a bit<br>    job.cancel() // cancels the job<br>    job.join() // waits for job&#39;s completion<br>    println(&quot;End&quot;)<br>}</pre><p>Output :</p><p>job: 0 …<br>job: 1 …<br>job: 2 …<br>End</p><p>When ” job.cancel” is called, we do not see any output from the other coroutine as it is canceled. To use coroutine scope we should use suspend fun.</p><p><strong>Jetpack integration</strong>: Many Jetpack libraries are coroutine compatible and include extensions that provide full coroutine support.</p><blockquote><a href="https://developer.android.com/kotlin/ktx">Android KTX</a></blockquote><p>Some libraries even have their coroutines.</p><p>For examples: ViewModelScope, LifecycleScope, LiveData</p><p><strong>GlobalScope</strong>: GlobalScope is alive as long as your app is alive if you do some counting for instance in this scope and rotate your device it will continue the task/process. We don’t need to write it in Suspend fun.</p><pre>class MainActivity : AppCompatActivity() {<br>    private val TAG = &quot;GLOBAL&quot;<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br>        GlobalScope.launch {<br>            repeat(100000){<br>                launch {<br>                    Log.d(TAG,&quot;GlobalScope&quot;)<br>                }<br>            }<br>        }<br>    }<br>}</pre><p><strong>Launch: </strong>is a coroutine builder. It launches a new coroutine concurrently with the rest of the code, which continues to work independently</p><p><strong>runBLocking: </strong>It stops the execution of the next code block, it blocks.</p><pre>fun main() {<br>    runBlocking{<br>        this.launch{<br>            repeat(10){<br>                println(&quot;Android + $it&quot;)<br>            }<br><br>        }<br>    }<br>    println(&quot;End&quot;)<br>}</pre><p>Output:</p><p><em>Android + 0<br>Android + 1<br>Android + 2<br>Android + 3<br>Android + 4<br>Android + 5<br>Android + 6<br>Android + 7<br>Android + 8<br>Android + 9<br>End</em></p><h3>CoroutineContext</h3><p>CoroutineContext is an indexed set of elements that define the behavior of a Coroutine.</p><p>Items related to CoroutineContext are:</p><ol><li><strong><em>CoroutineDispatcher: </em></strong>Dispatches the job to the appropriate thread.</li></ol><p><strong>Dispatchers.IO</strong>: Networking or reading and writing from files (any input and output)</p><p><strong>Dispatchers.Default:</strong> For CPU-intensive tasks such as sorting large lists and performing complex calculations.</p><p><strong>Dispatchers.Main:</strong> For everything else, new UI or non-blocking code.</p><p><em>2.</em><strong><em> CoroutineExceptionHandler</em></strong>: It’s better to use CoroutineExceptionHandler inside CoroutineScope instead of try-catch.</p><pre>lifecycleScope.launch {<br>            <br>            try {<br>                launch {<br>                    throw Exception(&quot;error&quot;)<br>                }<br>            } catch (e: Exception) {<br>                print(e.stackTrace)<br>            }<br>        }</pre><p>This won’t work. Exceptions propagate in coroutines and we need CorutineExceptionHandler</p><pre>        val handler = CoroutineExceptionHandler {context, throwable -&gt;<br>            println(&quot;exception: &quot; + throwable)<br>        }<br>        <br>        /* this will cancel the other coroutine without executing it. <br>        so if we are doing many launches, we can use SupervisorScope.<br>        */ <br><br>//an error will cancel all initializations within the scope of this coroutine<br>        lifecycleScope.launch(handler) {<br>            launch {<br>                throw Exception(&quot;error&quot;)<br>            }<br>            launch {<br>                delay(500L)<br>                println(&quot;this is executed&quot;)<br>            }<br>        }<br><br><br>/* All initializations within the scope of the other <br>coroutine will continue even if there is an error */<br>        lifecycleScope.launch(handler) { <br>            supervisorScope {<br>                launch {<br>                    throw Exception(&quot;error&quot;)<br>                }<br>                launch {<br>                    delay(500L)<br>                    println(&quot;this is executed&quot;)<br>                }<br>            }<br>        }<br><br>//we can use the handler in other cases as well such as<br>        CoroutineScope(Dispatchers.Main + handler).launch {<br>            launch {<br>                throw Exception(&quot;error in a coroutine scope&quot;)<br>            }<br>        }</pre><h3>Applying Retrofit with Coroutines</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*950f3Af3pZ2O4KLdggj3Ow.png" /></figure><p>First, we need a model.</p><p>You need to add the properties from your API to your model.</p><pre>data class CryptoModel(<br>    val currency: String,<br>    val price: String<br>)</pre><p>Launch the coroutine and make the Retrofit network call in the background. In CryptoAPI, make getData() a suspend function. So that you can call this method from within a coroutine.</p><pre>interface CryptoAPI {<br>    @GET(&quot;Your-Api-Key-Or-Json-Url&quot;)<br>    suspend fun getData(): Response&lt;List&lt;CryptoModel&gt;&gt;<br>}</pre><p>We created the Retrofit object in Activity. In the RecyclerView we showed the data asynchronously with the coroutine.</p><pre>private fun loadData() {<br>        val retrofit = Retrofit.Builder()<br>            .baseUrl(BASE_URL)<br>            .addConverterFactory(GsonConverterFactory.create())<br>            .build()<br>            .create(CryptoAPI::class.java)<br><br>        job = CoroutineScope(Dispatchers.IO).launch {<br>            val response = retrofit.getData()<br>            withContext(Dispatchers.Main){<br>                if (response.isSuccessful){<br>                    response.body()?.let {<br>                        cryptoModels = ArrayList(it)<br>                        cryptoModels.let { list -&gt;<br>                            recyclerViewAdapter = list?.let { it1 -&gt; RecyclerViewAdapter(it1,this@MainActivity) }<br>                        }<br>                    }<br>                }<br>            }<br>        }<br>    }</pre><p>When an activity is destroyed, we end the job with the job object we created.</p><pre>override fun onDestroy() {<br>        super.onDestroy()<br>        job?.cancel()<br>    }</pre><p>Thanks for reading and if you like the article, remember to <strong>clap</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da210315a248" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orion-innovation-techclub/coroutines-on-android-da210315a248">Coroutines on Android</a> was originally published in <a href="https://medium.com/orion-innovation-techclub">Orion Innovation techClub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope Functions | Kotlin]]></title>
            <link>https://medium.com/orion-innovation-techclub/scope-functions-kotlin-a1bdfaf7e4a6?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1bdfaf7e4a6</guid>
            <category><![CDATA[kotlin-scope-functions]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 18:57:51 GMT</pubDate>
            <atom:updated>2023-03-10T08:09:40.704Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ewx2pduUVDpc1PfiEnRLaQ.png" /><figcaption>Kotlin Scope Functions</figcaption></figure><p>The Kotlin standard library contains several functions whose sole purpose is to execute a block of code within the context of an object. When you call such a function on an object with a lambda expression provided, it forms a temporary scope. In this scope, you can access the object without its name.</p><p>As you can see in the table above, there are 5 scope functions.</p><p>These functions do the same: execute a block of code on an object. What’s different is how this object becomes available inside the block and what is the result of the whole expression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IIy9oqSJxhzE4aRvQnmSFQ.png" /></figure><h3>Function selection</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*dUF_cnnuesnwoY-jr-E-_Q.png" /><figcaption>Table showing the differences</figcaption></figure><h3>Object References</h3><p>Inside a lambda of a scope function, <strong><em>this</em> </strong>(lambda receiver) is used to access the context object. The same object can be accessed by using <strong><em>it</em> </strong>(lambda argument). In general, both can perform similar things.</p><h4>This</h4><p>Inside a scope function, you will be able to reference the context object by a short word (<strong><em>this</em></strong>), instead of the name itself.</p><p><strong>run</strong>, <strong>apply</strong>, <strong>with </strong>use ‘<strong><em>this</em></strong>’ to access the context object.</p><h4>It</h4><p>‘<strong>let</strong>’ and ‘<strong>also</strong>’ functions refer to the object’s context as a lambda argument.</p><h3>Let</h3><blockquote>Executing a lambda on non-null objects: let</blockquote><blockquote>Introducing an expression as a variable in local scope: <em>let</em></blockquote><pre>Person(&quot;Alice&quot;, 20, &quot;Amsterdam&quot;).let {<br>    println(it)<br>    it.moveTo(&quot;London&quot;)<br>    it.incrementAge()<br>    println(it)<br>}</pre><p>If we write it without “<strong>let” </strong>it should look like this:</p><p>We create a new variable and make changes using that variable.</p><pre>val alice = Person(&quot;Alice&quot;, 20, &quot;Amsterdam&quot;)<br>println(alice)<br>alice.moveTo(&quot;London&quot;)<br>alice.incrementAge()<br>println(alice)</pre><p><strong>“Let” </strong>is usually used for a null check.</p><pre>private val text : String ?= null<br><br>fun main() {<br>    //null check<br>    if(text!=null){<br>        print(text)<br>    }<br>    <br>    //We have done the null check using let.<br>    text?.let{<br>        print(it)<br>    }<br>}</pre><h3>Run</h3><blockquote>Object configuration and computing the result: run</blockquote><blockquote>Running statements where an expression is required: non-extension run</blockquote><pre>val service = MultiportService(&quot;https://example.kotlinlang.org&quot;, 80)<br><br>val result = service.run {<br>    port = 8080<br>    query(prepareRequest() + &quot; to port $port&quot;)<br>}<br><br>// the same code written with let() function:<br>val letResult = service.let {<br>    it.port = 8080<br>    it.query(it.prepareRequest() + &quot; to port ${it.port}&quot;)<br>}</pre><p>run which is an extension to the Template class is similar to let but the only difference is in let we get a reference as it whereas, in the run, the reference is this.</p><p>The best use case of this run function is to avoid the null check. the run function used with<strong> ? .</strong> ensures the execution only if the expression is non-null.</p><h3>Apply</h3><blockquote>Object configuration: apply</blockquote><pre>class Employee {<br>    var firstName: String = &quot;&quot;<br>    var age: Int = 0<br>}<br><br>val employee = Employee().apply{<br>        firstName = &quot;Suneet Agrawal&quot;<br>        age = 27<br>    }</pre><p>apply is recommended for lambdas that mainly operate on the object members or call its functions or assign properties. In short, it is mostly used for object configurations.</p><h3>With</h3><blockquote>The grouping function calls on an object: with</blockquote><pre>class Game() {<br>    lateinit var name: String<br>    lateinit var type: String<br>    lateinit var company: String<br>}<br>  <br>fun main() {<br>    val lol = Game().apply {<br>        name = &quot;League of Legends&quot;<br>        type = &quot;MOBA&quot;<br>        company = &quot;RIOT GAMES&quot;<br>    }<br>  <br>    // with function<br>    with(lol) {<br>        // similar to println( &quot;${this.name} ${this.type} ${this.company}&quot; )<br>        println(&quot; $name $type $company &quot;)<br>    }<br>}</pre><p>The with function has a return type as the lambda result, and the context object is this keyword, which refers to the object itself.</p><h3>Also</h3><blockquote>Additional effects: also</blockquote><p>also is good for performing some actions that take the context object as an argument. Use also for actions that need a reference to the object rather than its properties and functions, or when you don’t want to shadow this reference from an outer scope.</p><pre>fun main() {<br>    // initialized<br>    val list = mutableListOf&lt;Int&gt;(1, 2, 3)<br>  <br>    // later if we want to perform <br>    // multiple operations on this list<br>    list.also {<br>        it.add(4)<br>        it.remove(2)<br>        // more operations if needed<br>    }<br>    println(list)<br>}</pre><p>When you see also in the code, you can read it as &quot;<em>and also do the following with the object.</em>&quot;</p><blockquote>Thanks for reading, I hope it was helpful.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1bdfaf7e4a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orion-innovation-techclub/scope-functions-kotlin-a1bdfaf7e4a6">Scope Functions | Kotlin</a> was originally published in <a href="https://medium.com/orion-innovation-techclub">Orion Innovation techClub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose 101— Episode I]]></title>
            <link>https://medium.com/orion-innovation-techclub/jetpack-compose-101-episode-i-b913af3b858c?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b913af3b858c</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 07:41:42 GMT</pubDate>
            <atom:updated>2023-01-17T07:41:42.827Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEvF-1Ov91ZcMudIxJYIlw.png" /><figcaption>Jetpack Compose Logo</figcaption></figure><h3>Why should we use Jetpack Compose?</h3><p>Jetpack Compose is Android’s recommended modern toolset for creating native UI.</p><h4>Less Code</h4><blockquote>Why is it good for us to write less code?</blockquote><p>Writing less code affects every stage of development.</p><p>As a developer, you focus on the problem at hand with less testing, debugging, and less chance of errors, and you have less code to read, understand, review, and maintain.</p><p>It allows us to develop only on the Kotlin side without any division between Kotlin and XML.</p><h4>Intuitive</h4><p>Jetpack Compose uses a declarative API, which means that all you need to do is describe your UI. The APIs are intuitive</p><h4>Accelerate development</h4><p>The very commonly used libraries of Jetpack work well with Compose.</p><p>Speed up your development without switching between XML and Kotlin. With live previews as you write the code, you can test it quickly and save time. It allows us to control the states and properties of UI components.</p><h4>Powerful</h4><p>Compose enables you to create apps with direct access to the Android platform APIs and built-in support for Material Design, Dark theme, animations, and more…</p><p>Compose gives you the flexibility to apply the design you want</p><h3>Jetpack Compose Starter Tutorial</h3><p>Choose Empty Compose Activity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2XvYPOhZ7TPlcwlNXD-_XA.png" /></figure><p>It only supports Kotlin as a language. Let’s click Finish and create the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxfJeH06KVTmMAtYlqoKnQ.png" /></figure><p>In Android, the visual design was stored in XML files and each Activity was associated with a design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i8HwuMgwFxM2rxHvfEnCjw.png" /></figure><p>To create a composable function, just add the @Composable annotation to the function name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PolEktBl1_RIVp8SrwykYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IL6n_FYj2tGfle-QrE-fmQ.png" /></figure><p>Preview your function in Android Studio. The @Preview annotation lets you preview your composable functions within Android Studio without having to build and install the app to an Android device or emulator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_85GcZub2bzVnsFdWdCyNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*dc2cZcY5w-ucuOA_bSR-ag.png" /></figure><h3>Use Layout</h3><p>If you don’t use a layout it will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgHbf1WqSdTQLYxbdpqTVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJfY_cHlDfZCKKCt0eCKOw.png" /></figure><p>The Column function lets you arrange elements vertically. Add Column to function. You can use Row to arrange items horizontally and Box to stack elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHYBPq-N0bz81cyJpn3WKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VSNqMbAL68RM19EVxnCaA.png" /></figure><h3>Use Material Design</h3><p>Compose is built to support Material Design principles. Many of its UI elements implement Material Design out of the box.</p><p>Material Design is built around three pillars: <strong>Color</strong>, <strong>Typography</strong>, and <strong>Shape</strong>. You will add them one by one.</p><h4>Color</h4><p>Use MaterialTheme.colors to style with colors from the wrapped theme. You can use these values from the theme anywhere a color is needed.</p><h4>Typography</h4><p>Material Typography styles are available in the MaterialTheme.typography, just add them to the Text composable.</p><h4>Shape</h4><p>With Shape, you can add the final touches. First, wrap the message body text around a Surface composable. Doing so allows customizing the message body’s shape and elevation. Padding is also added to the message for a better layout.</p><h4>Enable dark theme</h4><p>Thanks to Material Design support, Jetpack Compose can handle dark themes by default. Having used Material Design colors, text and backgrounds will automatically adapt to the dark background.</p><p>You can create multiple previews in your file as separate functions, or add multiple annotations to the same function.</p><p>Add a new preview annotation and enable night mode.</p><blockquote>Now let’s see what we can do with examples.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G4Yz15q0rZIRcfJje1psLg.png" /></figure><p>Let’s see how it looks on the emulator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*SjGuMl8ES31rH3QRslDdzw.png" /></figure><p>Let’s see how it looks in the preview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwcHWXmHsZxbUXKo5Rb6Kw.png" /></figure><h3>Result</h3><p>We learned how to create projects with Jetpack Compose and what to do simply.</p><p>I hope this article will be useful for those who are just starting with Jetpack compose.</p><p>Thanks.</p><h3>Reference</h3><p><a href="https://developer.android.com/jetpack/compose/tutorial?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fjetpack-compose-for-android-developers-1%23article-https%3A%2F%2Fdeveloper.android.com%2Fjetpack%2Fcompose%2Ftutorial">Android Developer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b913af3b858c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orion-innovation-techclub/jetpack-compose-101-episode-i-b913af3b858c">Jetpack Compose 101— Episode I</a> was originally published in <a href="https://medium.com/orion-innovation-techclub">Orion Innovation techClub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVVM architecture, ViewModel and LiveData]]></title>
            <link>https://blog.devgenius.io/mvvm-architecture-viewmodel-and-livedata-d6c74ef45728?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6c74ef45728</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[viewmodel]]></category>
            <category><![CDATA[livedata]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 21:35:20 GMT</pubDate>
            <atom:updated>2024-01-11T17:46:55.285Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is MVVM?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*x_gukitZvSTd7eQebvMAAw.png" /></figure><p>Model-View-ViewModel (MVVM) is a software design pattern that is structured to separate program logic and user interface controls.</p><p>MVVM is basically composed of three layers :</p><ul><li>Model : This holds the data of the application. It cannot directly talk to the View. Generally, it’s recommended to expose the data to the ViewModel through Observables.</li><li>View : It represents the UI of the application devoid of any Application Logic. It observes the ViewModel.</li><li>ViewModel : It acts as a link between Model and View. It is responsible for transforming the data from the model. Prepares observable(s) observable by View.. It also uses hooks or callbacks to update the View. It will request data from the model.</li></ul><p>We can easily see what kind of interactions exist between these three components on the following simple graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*2YMOIUxRlJ6Tl1KOKIV62Q.png" /><figcaption>MVVM</figcaption></figure><h3>LiveData</h3><p><a href="https://developer.android.com/reference/androidx/lifecycle/LiveData">LiveData</a> is an observable data holder class. Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. This awareness ensures LiveData only updates app component observers that are in an active lifecycle state.</p><blockquote>The advantages of using LiveData</blockquote><ol><li><strong>Ensures your UI matches your data state</strong></li><li><strong>No memory leaks</strong></li><li><strong>No crashes due to stopped activities</strong></li><li><strong>No more manual lifecycle handling</strong></li><li><strong>Always up to date data</strong></li><li><strong>Proper configuration changes</strong></li><li><strong>Sharing resources</strong></li></ol><p>Now let’s see how I used it in my messaging app.</p><h3>Using LiveData with Domain Layer or Repository Layer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*kSt-3Fh3V8rPuRioxjwmTg.png" /></figure><p>We have to use a different layer to get the data.</p><p>Repository can have instances of :</p><ol><li>Remote i.e. network</li><li>Database</li><li>Cache or Shared Preferences.</li></ol><h3>Repository</h3><p>There is an interface where tasks are defined for messaging and a class where we use this interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*EMOzIsbfyAa0zlF0DcPNyw.png" /></figure><p>an example repository interface</p><pre>interface UserRepositoryI {<br>    fun showListOfUser(userList : ArrayList&lt;Users&gt;)<br>}</pre><p>I used firebase for storage.</p><pre>class UserRepository(UserRepositoryI: UserRepositoryI) {<br><br>    private var userRepositoryI : UserRepositoryI ?= UserRepositoryI<br>    private  var userList = ArrayList&lt;Users&gt;()<br><br>    fun getUserFirebase(){<br>        val ref = FirebaseDatabase.getInstance().getReference(&quot;/users&quot;)<br>        ref.addListenerForSingleValueEvent(object : ValueEventListener {<br>            override fun onDataChange(snapshot: DataSnapshot) {<br>                userList.clear()<br>                snapshot.children.forEach{<br>                    val user = it.getValue(Users::class.java)<br><br>                    if (user!=null &amp;&amp; user.uid != FirebaseAuth.getInstance().uid){<br>                        userList.add(user)<br>                        userRepositoryI?.showListOfUser(userList)<br><br>                    }<br>                }<br><br>            }<br>            override fun onCancelled(error: DatabaseError) {<br>                Log.d(&quot;ViewModel&quot;,error.message)<br>            }<br>        })<br>    }<br>}</pre><h3>Model</h3><p>Lets create a data model class</p><pre>@Entity<br>@Parcelize<br>class Users(<br>    @PrimaryKey(autoGenerate = false)<br>    var uid : String ,<br>    @ColumnInfo(name = &quot;username&quot;)<br>    var username:String,<br>    @ColumnInfo(name = &quot;profileImageURL&quot;)<br>    var profileImageURL:String,<br>    @ColumnInfo(name = &quot;status&quot;)<br>    var status : String,<br>    @ColumnInfo(name = &quot;Email&quot;)<br>    var Email : String,<br>    @ColumnInfo(name = &quot;activeState&quot;)<br>    var activeState : String ,<br>    @ColumnInfo(name = &quot;token&quot;)<br>    var token : String?) : Parcelable{<br><br>    constructor() : this(&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;offline&quot;,&quot;&quot;)<br><br>    companion object{<br>        private val addition = Addition()<br>        @JvmStatic<br>        @BindingAdapter(&quot;imageUrl&quot;)<br>        fun loadImage(view : CircleImageView , imageUrl : String?){<br>            imageUrl?.let {<br>                addition.picassoUseIt(imageUrl,view)<br>            }<br>        }<br>    }<br>}</pre><ul><li><strong>Room </strong>— It is an ORM provided by Google, which provides an abstraction layer between the SQLite database and our data in the form of objects. It gives us errors in compile-time, which is much better than run-time error which difficult to track and debug. <br>In order to use the room, it’s very important to define our schema. We do that by creating a data model class and add an <a href="http://twitter.com/entity">@entity</a> annotation. We also must add a <a href="http://twitter.com/PrimaryKey">@PrimaryKey</a> annotation to our entity’s id.</li></ul><h3>ViewModel</h3><p>ViewModel object acts as an intermediate between View and the Model, meaning it provides data for the UI components like fragments or activities. It also includes an observable data holder called LiveData that allows ViewModel to inform or update the View whenever the data get updated. It is very crucial, mainly to keep our app from reloading on orientation changes. Which ultimately provides a great user experience.<br>Here’s an example,</p><pre>class UserListViewModel(application: Application) : BaseViewModel(application), UserRepositoryI {<br>    private var userRepository = UserRepository(this)<br>    val users = MutableLiveData&lt;List&lt;Users&gt;&gt;()<br>    val userLoading = MutableLiveData&lt;Boolean&gt;()<br>    val informationMessage = MutableLiveData&lt;Boolean&gt;()<br><br>    private val specialSharedPreferences = SpecialSharedPreferences(getApplication())<br>    private var updateTimeValue = 0.1 * 60 * 1000 * 1000 * 1000L<br>    fun getAllUsers() : LiveData&lt;List&lt;Users&gt;&gt;{<br>        return users<br>    }<br>    fun getUser(){<br>        val getTime = specialSharedPreferences.getTime()<br>        if (getTime !=null &amp;&amp; getTime!=0L &amp;&amp; System.nanoTime()-getTime&lt;updateTimeValue){<br>            //get SqLite<br>            getDataSQlite()<br>        }<br>        else{<br>            //get Firebase<br>            userRepository.getUserFirebase()<br>            getAllUsers().value?.let { saveSQLite(it) }<br><br>        }<br><br>    }<br>    private fun getDataSQlite(){<br>        launch {<br>            val userList = UsersDatabase(getApplication()).usersDao().getAllUser()<br>            if (userList.isEmpty()){<br>                userRepository.getUserFirebase()<br>                getAllUsers().value?.let { saveSQLite(it) }<br>            }<br>            users.value = userList<br>            informationMessage.value = userList.isEmpty()<br>            userLoading.value = false<br>        }<br>    }<br>    override fun showListOfUser(userList: ArrayList&lt;Users&gt;) {<br>        users.value = userList<br>        informationMessage.value = userList.size==0<br>        userLoading.value = false<br>    }<br>    private fun saveSQLite(userList : List&lt;Users&gt;) {<br>        launch {<br>            val dao = UsersDatabase(getApplication()).usersDao()<br>            dao.deleteAllUser()<br>            dao.insertAllUser(*userList.toTypedArray())<br>        }<br>        specialSharedPreferences.saveTime(System.nanoTime())<br>    }<br>}</pre><h3>View</h3><p>We observe the observable live data coming through the viewmodel on the view side.</p><pre> private fun observeLiveData(){<br>        viewModel.users.observe(viewLifecycleOwner, Observer {<br>            it?.let {<br>                binding.newInformationTV.visibility = View.GONE<br>                binding.recyclerView4.visibility = View.VISIBLE<br><br>                adapter.UsersListUpdate(it)<br>            }<br><br>        })<br>        viewModel.informationMessage.observe(viewLifecycleOwner, Observer {<br>            it?.let {<br>                if (it){<br>                    binding.newInformationTV.text = &quot;Kullanıcı Listen Boş&quot;<br>                }<br>                else{<br>                    binding.newInformationTV.text = &quot;&quot;<br>                }<br>            }<br>        })<br>        viewModel.userLoading.observe(viewLifecycleOwner, Observer {<br>            it?.let {<br>                if (it){<br>                    binding.newLoadingBar.visibility = View.VISIBLE<br>                }<br>                else<br>                {<br>                    binding.newLoadingBar.visibility = View.GONE<br>                }<br>            }<br>        })<br>    }</pre><h3>Recycler View Adapter</h3><p>We show the live data we observe on the view side with adapter.</p><pre>class NewMessagesRVAdapter(private val userList: ArrayList&lt;Users&gt;) : RecyclerView.Adapter&lt;NewMessagesRVAdapter.NewMessageViewHolder&gt;(),Filterable{<br>    var userFilterList = ArrayList&lt;Users&gt;()<br>    lateinit var mContext: Context<br><br><br>    init {<br>        userFilterList = userList<br>    }<br>    private val addition = Addition()<br>    class NewMessageViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){<br>        var itemImage : ImageView = itemView.findViewById(R.id.message_imageView)<br>        var itemTitle : TextView = itemView.findViewById(R.id.message_TV)<br>        var itemStatus: TextView = itemView.findViewById(R.id.status_TV)<br>        var itemProgressBar : ProgressBar = itemView.findViewById(R.id.new_messages_progressBar)<br>    }<br>    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewMessageViewHolder {<br>        val view = LayoutInflater.from(parent.context).inflate(R.layout.user_row_new_message,parent,false)<br>        return NewMessageViewHolder(view)<br>    }<br>    override fun getItemCount(): Int {<br>        return userFilterList.size<br>    }<br>    override fun onBindViewHolder(holder: NewMessageViewHolder, position: Int){<br>        holder.itemTitle.text = userFilterList[position].username<br>        holder.itemStatus.text = userFilterList[position].status<br>        addition.picassoUseIt(userFilterList[position].profileImageURL,holder.itemImage,holder.itemProgressBar)<br>        holder.itemProgressBar.visibility = View.GONE<br>        holder.itemView.setOnClickListener {<br>            val action = NewMessagesFragmentDirections.actionNewMessagesFragmentToChatLogFragment(<br>                position,<br>                userFilterList[position].uid,<br>                userFilterList[position].username,<br>                userFilterList[position].profileImageURL,<br>                userFilterList[position].status,<br>                userFilterList[position].activeState,<br>                userFilterList[position].Email,<br>                userFilterList[position].token!!<br>            )<br>            Navigation.findNavController(it).navigate(action)<br>        }<br><br>    }<br><br><br>    @SuppressLint(&quot;NotifyDataSetChanged&quot;)<br>    fun UsersListUpdate(NewUserList : List&lt;Users&gt;){<br>        userList.clear()<br>        userList.addAll(NewUserList)<br><br>        notifyDataSetChanged()<br>    }<br><br>    override fun getFilter(): Filter {<br>        return object : Filter() {<br>            override fun performFiltering(constraint: CharSequence?): FilterResults {<br>                val charSearch = constraint.toString()<br>                if (charSearch.isEmpty()) {<br>                    userFilterList = userList<br>                } else {<br>                    val resultList = ArrayList&lt;Users&gt;()<br>                    for (row in userList) {<br>                        if (row.username.lowercase(Locale.ROOT).contains(charSearch.lowercase(Locale.ROOT))) {<br>                            resultList.add(row)<br>                        }<br>                    }<br>                    userFilterList = resultList<br>                }<br>                val filterResults = FilterResults()<br>                filterResults.values = userFilterList<br>                return filterResults<br>            }<br><br>            @SuppressLint(&quot;NotifyDataSetChanged&quot;)<br>            @Suppress(&quot;UNCHECKED_CAST&quot;)<br>            override fun publishResults(constraint: CharSequence?, results: FilterResults?) {<br>                userFilterList = results?.values as ArrayList&lt;Users&gt;<br>                notifyDataSetChanged()<br>            }<br><br>        }<br>    }<br>}</pre><h3>Result</h3><p>One an easily make android apps without following this architecture, but if we want to make apps that are robust, testable, maintainable and easy to read, then we must use this to our advantage.</p><p>Thanks for reading and if you like the article, remember to <strong>clap</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6c74ef45728" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/mvvm-architecture-viewmodel-and-livedata-d6c74ef45728">MVVM architecture, ViewModel and LiveData</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide To MultiPlatform Mobile Development]]></title>
            <link>https://blog.devgenius.io/guide-to-multiplatform-mobile-development-1cfa7e9576ac?source=rss-1cdd9130c2b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cfa7e9576ac</guid>
            <category><![CDATA[kmm]]></category>
            <category><![CDATA[multiplatform]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Hamza Oban]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 18:19:11 GMT</pubDate>
            <atom:updated>2024-01-11T17:47:53.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBHfJVFI4-EhVUqvhSSY6A.png" /></figure><h3>What is Kotlin Multiplatform Mobile?</h3><p>Kotlin Multiplatform Mobile (KMM) is a framework that allows you to build an application that targets Android and iOS. Unlike other Multiplatform frameworks, though, it does not attempt to make all the code of the application reusable across both platforms. Instead, the UI layer, in Clean Architecture terms, is the only layer that needs to be developed natively, while allowing most of the rest of the architectural layers to be shared.</p><p>The shared architecture is provided to each native app as a compiled package. This package is then accessed within the native app code. KMM has the potential to be the foundation for a number of platforms, including Android, JavaScript, Java, Kotlin and Swift iOS codebases.</p><h3>Tools necessary for KMM</h3><p><strong>Android Studio : </strong><a href="https://developer.android.com/studio">Download Android Studio &amp; App Tools</a></p><p><strong>Xcode</strong> : <a href="https://apps.apple.com/us/app/xcode/id497799835">Xcode on the Mac App Store</a></p><p><strong>Brew : </strong><a href="https://brew.sh/">Install Brew</a></p><p><strong>MacOS computer/laptop</strong></p><h3>Initial Setup</h3><blockquote>To make sure everything works as expected, install and run the KDoctor tool:</blockquote><p>In the Android Studio terminal or your command-line tool, run the following command to install the tool using Homebrew:</p><ul><li>[!] symbol indicates warnings.</li></ul><p>After the installation is completed, call KDoctor in the console:</p><p>2.</p><p>After running the KDoctor command it scans the system for all the. required tools for KMM development. The report will be shown in the terminal.</p><p>In the report:</p><ul><li>[x] symbol indicates the missing tools</li><li>[v] symbol indicates the successfully installed tools</li><li>[!] symbol indicates warnings.</li></ul><blockquote>Kotlin Multiplatform Mobile Plugin</blockquote><p>This plugin makes creating a KMM project super easy in Android Studio. It provides options to create Kotlin Multiplatform App and Kotlin Multiplatform Library options, with the help of which one can easily create a basic KMM app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*3drxq7nPuL7DSJy65Yhp3A.png" /></figure><p>Initial setup is completed. We are ready to create a KMM project.</p><blockquote>Create a new project, select new “Kotlin Multiplatform App”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*5sFgZBpHy_NhC6HPnWr3vA.png" /></figure><blockquote>Select the project name, package name and project location as usual.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*TgNXQUPsftuNpvCFsqPPVQ.png" /></figure><blockquote>you can add the names for the Android and iOS apps. You can also add the name for the shared module. You can choose to add sample unit tests for the shared module where your business logic will be saved.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*w9RLMZCHAQPQvCFbSAX18w.png" /></figure><p><em>You can using the regular framework for your first project, as this option doesn’t require third-party tools and has less installation issues.<br>For more complex projects, you might need the CocoaPods dependency manager that helps handle library dependencies. To learn more about CocoaPods and how to set up an environment for them, see </em><a href="https://cocoapods.org/"><em>CocoaPods overview and setup</em></a><em>.</em></p><blockquote>Click on finish and Android Studio will create a KMM project for you.</blockquote><h3>Examine the project structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*P_pyQYvuC1HLnl_YzAbpDA.png" /></figure><p>Each Kotlin Multiplatform Mobile project includes three modules:</p><ul><li><em>shared</em> is a Kotlin module that contains the logic common for both Android and iOS applications — the code you share between platforms. It uses <a href="https://kotlinlang.org/docs/gradle.html">Gradle</a> as the build system that helps you automate your build process. The <em>shared</em> module builds into an Android library and an iOS framework.</li><li><em>androidApp</em> is a Kotlin module that builds into an Android application. It uses Gradle as the build system. The <em>androidApp</em> module depends on and uses the shared module as a regular Android library.</li><li><em>iOSApp</em> is an Xcode project that builds into an iOS application. It depends on and uses the shared module as an iOS framework. The shared module can be used as a regular framework or as a <a href="https://kotlinlang.org/docs/native-cocoapods.html">CocoaPods dependency</a>, based on what you’ve chosen in the previous step in <strong>iOS framework distribution</strong>. In this tutorial, it’s a regular framework dependency.</li></ul><h3>Reference</h3><ol><li><a href="https://kotlinlang.org/docs/multiplatform-mobile-getting-started.html#0">Kotlin Multiplatform for iOS and Android</a></li><li><a href="https://www.youtube.com/c/PhilippLackner">Philipp Lackner</a></li><li><a href="https://www.youtube.com/watch?v=ri6XfKmnC8w&amp;t=171s">Keep On Coding</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cfa7e9576ac" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/guide-to-multiplatform-mobile-development-1cfa7e9576ac">Guide To MultiPlatform Mobile Development</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>