<?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 Abhiraj Khare on Medium]]></title>
        <description><![CDATA[Stories by Abhiraj Khare on Medium]]></description>
        <link>https://medium.com/@abhirajkhare?source=rss-25737b8c0d44------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Z2wKVp7b89vKWDqJ4t5Z7A.jpeg</url>
            <title>Stories by Abhiraj Khare on Medium</title>
            <link>https://medium.com/@abhirajkhare?source=rss-25737b8c0d44------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 19:01:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhirajkhare/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[Animated Speed Dial FAB in Compose Multiplatform (Android & iOS)]]></title>
            <link>https://medium.com/@abhirajkhare/animated-speed-dial-fab-in-compose-multiplatform-android-ios-b91554bc4b96?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/b91554bc4b96</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Mon, 14 Sep 2026 00:14:13 GMT</pubDate>
            <atom:updated>2026-09-14T00:14:13.164Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faJX6ikytpaIiBlverr4CQ.jpeg" /></figure><p>When building modern mobile applications, screen real estate is at a premium. Users expect a clean interface, yet you still need quick access to high-frequency secondary actions — like sharing, liking, bookmarking, or posting content.</p><p>The Material Design specification popularised the <strong>Speed Dial FAB</strong> (Expandable Floating Action Button) for this exact pattern. When tapped, the primary button pivots and reveals a vertical stack of smaller action buttons.</p><p>While classic Android views had third-party libraries for this, <strong>Compose Multiplatform (CMP)</strong> currently lacks an official, out-of-the-box animated Speed Dial component.</p><p>In this tutorial, we will build a modular, high-performance <strong>SpeedDialFab</strong> from scratch that works identically across <strong>Android and iOS</strong>.</p><h3>🏗️ Architecture &amp; Component Design</h3><p>Our component is divided into three distinct responsibilities:</p><ol><li><strong>State Management (</strong><strong>SpeedDialState)</strong>: Controls whether the speed dial is expanded or collapsed, allowing both internal toggles and external state hoisting.</li><li><strong>Data &amp; Styling Models (</strong><strong>SpeedDialItem, </strong><strong>SpeedDialTrigger, </strong><strong>SpeedDialStyle)</strong>: Holds icon vectors, labels, tap handlers, and color tokens.</li><li><strong>Composables (</strong><strong>SpeedDialFab &amp; </strong><strong>SpeedDialActionRow)</strong>: Handles the animations (animateFloatAsState, AnimatedVisibility) and layout rendering.</li></ol><h3>Step 1: Modeling State and Contracts</h3><p>Let’s begin by defining how our Speed Dial behaves and represents its items.</p><h4>1. The State Machine (SpeedDialState.kt)</h4><pre>package com.example.speeddial<br><br>import androidx.compose.runtime.Composable<br>import androidx.compose.runtime.mutableStateOf<br>import androidx.compose.runtime.remember<br><br>sealed interface SpeedDialState {<br>    data object Collapsed : SpeedDialState<br>    data object Expanded : SpeedDialState<br><br>    val isExpanded: Boolean<br>        get() = this is Expanded<br><br>    fun toggle(): SpeedDialState = if (isExpanded) Collapsed else Expanded<br>}<br><br>@Composable<br>fun rememberSpeedDialState(<br>    initialState: SpeedDialState = SpeedDialState.Collapsed<br>) = remember { mutableStateOf(initialState) }</pre><h4>2. Action Items &amp; Styling Configuration (SpeedDialModels.kt)</h4><p>We annotate these classes with @Immutable so the Compose compiler can skip recompositions whenever the menu is idle.</p><pre>package com.example.speeddial<br><br>import androidx.compose.material3.MaterialTheme<br>import androidx.compose.runtime.Composable<br>import androidx.compose.runtime.Immutable<br>import androidx.compose.runtime.Stable<br>import androidx.compose.ui.graphics.Color<br>import androidx.compose.ui.graphics.vector.ImageVector<br><br>/**<br> * Represents an individual sub-action in the expanded stack.<br> */<br>@Immutable<br>data class SpeedDialItem(<br>    val id: String,<br>    val icon: ImageVector,<br>    val label: String? = null,<br>    val onClick: (SpeedDialItem) -&gt; Unit<br>)<br><br>/**<br> * Configures the primary anchor FAB.<br> */<br>@Immutable<br>data class SpeedDialTrigger(<br>    val icon: ImageVector,<br>    val rotationAngle: Float = 45f // Rotates + into an X, or turns a menu icon<br>)<br><br>/**<br> * Visual styling configuration for sub-actions.<br> */<br>@Immutable<br>data class SpeedDialStyle(<br>    val containerColor: Color,<br>    val contentColor: Color,<br>    val showLabels: Boolean = true,<br>    val labelBackgroundColor: Color? = null,<br>    val labelTextColor: Color? = null<br>)<br><br>@Composable<br>fun defaultSpeedDialStyle(<br>    containerColor: Color = MaterialTheme.colorScheme.secondaryContainer,<br>    contentColor: Color = MaterialTheme.colorScheme.onSecondaryContainer,<br>    showLabels: Boolean = true<br>): SpeedDialStyle = SpeedDialStyle(<br>    containerColor = containerColor,<br>    contentColor = contentColor,<br>    showLabels = showLabels,<br>    labelBackgroundColor = MaterialTheme.colorScheme.surfaceVariant,<br>    labelTextColor = MaterialTheme.colorScheme.onSurfaceVariant<br>)  </pre><h3>Step 2: The Sub-Action Row (SpeedDialActionRow.kt)</h3><p>Each child button is rendered in a horizontal row containing an optional pill label and a compact mini-FAB:</p><pre>package com.example.speeddial<br><br>import androidx.compose.foundation.background<br>import androidx.compose.foundation.layout.*<br>import androidx.compose.foundation.shape.CircleShape<br>import androidx.compose.foundation.shape.RoundedCornerShape<br>import androidx.compose.material3.*<br>import androidx.compose.runtime.Composable<br>import androidx.compose.ui.Alignment<br>import androidx.compose.ui.Modifier<br>import androidx.compose.ui.draw.clip<br>import androidx.compose.ui.unit.dp<br><br>@Composable<br>fun SpeedDialActionRow(<br>    item: SpeedDialItem,<br>    style: SpeedDialStyle,<br>    modifier: Modifier = Modifier<br>) {<br>    Row(<br>        modifier = modifier.wrapContentSize(),<br>        horizontalArrangement = Arrangement.spacedBy(12.dp),<br>        verticalAlignment = Alignment.CenterVertically<br>    ) {<br>        // Optional text label<br>        if (style.showLabels &amp;&amp; !item.label.isNullOrBlank()) {<br>            Surface(<br>                shape = RoundedCornerShape(8.dp),<br>                color = style.labelBackgroundColor ?: MaterialTheme.colorScheme.surfaceVariant,<br>                tonalElevation = 2.dp,<br>                shadowElevation = 4.dp<br>            ) {<br>                Text(<br>                    text = item.label,<br>                    style = MaterialTheme.typography.labelMedium,<br>                    color = style.labelTextColor ?: MaterialTheme.colorScheme.onSurfaceVariant,<br>                    modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp)<br>                )<br>            }<br>        }<br><br>        // Mini Action Button (40dp diameter)<br>        SmallFloatingActionButton(<br>            onClick = { item.onClick(item) },<br>            shape = CircleShape,<br>            containerColor = style.containerColor,<br>            contentColor = style.contentColor,<br>            modifier = Modifier.size(40.dp)<br>        ) {<br>            Icon(<br>                imageVector = item.icon,<br>                contentDescription = item.label ?: &quot;Speed dial action&quot;,<br>                modifier = Modifier.size(20.dp)<br>            )<br>        }<br>    }<br>}</pre><h3>Step 3: The Complete SpeedDialFab Component</h3><p>Now we orchestrate the parent layout. Notice the two key animations:</p><ol><li>animateFloatAsState: Animates the primary icon&#39;s rotation when toggling between Collapsed and Expanded.</li><li>AnimatedVisibility: Expands the vertical stack with a synchronized fadeIn() + expandVertically().</li></ol><pre>package com.example.speeddial<br><br>import androidx.compose.animation.*<br>import androidx.compose.animation.core.Spring<br>import androidx.compose.animation.core.animateFloatAsState<br>import androidx.compose.animation.core.spring<br>import androidx.compose.foundation.layout.*<br>import androidx.compose.foundation.shape.CircleShape<br>import androidx.compose.material3.FloatingActionButton<br>import androidx.compose.material3.Icon<br>import androidx.compose.material3.MaterialTheme<br>import androidx.compose.runtime.Composable<br>import androidx.compose.runtime.MutableState<br>import androidx.compose.runtime.getValue<br>import androidx.compose.ui.Alignment<br>import androidx.compose.ui.Modifier<br>import androidx.compose.ui.draw.rotate<br>import androidx.compose.ui.unit.dp<br><br>@Composable<br>fun SpeedDialFab(<br>    items: List&lt;SpeedDialItem&gt;,<br>    trigger: SpeedDialTrigger,<br>    modifier: Modifier = Modifier,<br>    state: MutableState&lt;SpeedDialState&gt; = rememberSpeedDialState(),<br>    style: SpeedDialStyle = defaultSpeedDialStyle(),<br>    onStateChanged: ((SpeedDialState) -&gt; Unit)? = null<br>) {<br>    // 1. Pivot rotation animation for the main FAB icon<br>    val rotationAngle by animateFloatAsState(<br>        targetValue = if (state.value.isExpanded) trigger.rotationAngle else 0f,<br>        animationSpec = spring(<br>            dampingRatio = Spring.DampingRatioMediumBouncy,<br>            stiffness = Spring.StiffnessMedium<br>        ),<br>        label = &quot;SpeedDialRotation&quot;<br>    )<br><br>    Column(<br>        modifier = modifier.wrapContentSize(),<br>        horizontalAlignment = Alignment.End,<br>        verticalArrangement = Arrangement.spacedBy(16.dp)<br>    ) {<br>        // 2. Animated Stack of Sub-Actions<br>        AnimatedVisibility(<br>            visible = state.value.isExpanded,<br>            enter = fadeIn() + expandVertically(expandFrom = Alignment.Bottom),<br>            exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Bottom)<br>        ) {<br>            Column(<br>                modifier = Modifier.wrapContentSize(),<br>                horizontalAlignment = Alignment.End,<br>                verticalArrangement = Arrangement.spacedBy(12.dp)<br>            ) {<br>                items.forEach { item -&gt;<br>                    SpeedDialActionRow(<br>                        item = item.copy(<br>                            onClick = { clickedItem -&gt;<br>                                // Auto-collapse when an option is selected<br>                                state.value = SpeedDialState.Collapsed<br>                                onStateChanged?.invoke(SpeedDialState.Collapsed)<br>                                clickedItem.onClick(clickedItem)<br>                            }<br>                        ),<br>                        style = style<br>                    )<br>                }<br>            }<br>        }<br><br>        // 3. Primary Trigger FAB<br>        FloatingActionButton(<br>            onClick = {<br>                val newState = state.value.toggle()<br>                state.value = newState<br>                onStateChanged?.invoke(newState)<br>            },<br>            shape = CircleShape,<br>            containerColor = MaterialTheme.colorScheme.primary,<br>            contentColor = MaterialTheme.colorScheme.onPrimary,<br>            modifier = Modifier.size(56.dp)<br>        ) {<br>            Icon(<br>                imageVector = trigger.icon,<br>                contentDescription = if (state.value.isExpanded) &quot;Close actions&quot; else &quot;Show actions&quot;,<br>                modifier = Modifier.rotate(rotationAngle)<br>            )<br>        }<br>    }<br>}</pre><h3>Step 4: Putting It into Action</h3><p>Here is an example of embedding SpeedDialFab inside any Scaffold or full-screen feed:</p><pre>package com.example.speeddial<br><br>import androidx.compose.foundation.layout.Box<br>import androidx.compose.foundation.layout.fillMaxSize<br>import androidx.compose.foundation.layout.padding<br>import androidx.compose.material.icons.Icons<br>import androidx.compose.material.icons.filled.Add<br>import androidx.compose.material.icons.filled.Edit<br>import androidx.compose.material.icons.filled.Favorite<br>import androidx.compose.material.icons.filled.Share<br>import androidx.compose.material3.Scaffold<br>import androidx.compose.runtime.Composable<br>import androidx.compose.ui.Alignment<br>import androidx.compose.ui.Modifier<br>import androidx.compose.ui.unit.dp<br><br>@Composable<br>fun MainFeedScreen() {<br>    val speedDialState = rememberSpeedDialState()<br><br>    Scaffold { innerPadding -&gt;<br>        Box(<br>            modifier = Modifier<br>                .fillMaxSize()<br>                .padding(innerPadding)<br>        ) {<br>            // Your screen content (Feed, Video Player, or Lists) goes here...<br><br>            // Anchor SpeedDialFab to Bottom-End<br>            SpeedDialFab(<br>                modifier = Modifier<br>                    .align(Alignment.BottomEnd)<br>                    .padding(end = 20.dp, bottom = 24.dp),<br>                state = speedDialState,<br>                trigger = SpeedDialTrigger(<br>                    icon = Icons.Default.Add,<br>                    rotationAngle = 45f // Rotates &#39;+&#39; into an &#39;x&#39; on expansion<br>                ),<br>                style = defaultSpeedDialStyle(showLabels = true),<br>                items = listOf(<br>                    SpeedDialItem(<br>                        id = &quot;like&quot;,<br>                        icon = Icons.Default.Favorite,<br>                        label = &quot;Like Post&quot;,<br>                        onClick = { println(&quot;Liked!&quot;) }<br>                    ),<br>                    SpeedDialItem(<br>                        id = &quot;share&quot;,<br>                        icon = Icons.Default.Share,<br>                        label = &quot;Share&quot;,<br>                        onClick = { println(&quot;Shared!&quot;) }<br>                    ),<br>                    SpeedDialItem(<br>                        id = &quot;draft&quot;,<br>                        icon = Icons.Default.Edit,<br>                        label = &quot;New Story&quot;,<br>                        onClick = { println(&quot;Compose Draft!&quot;) }<br>                    )<br>                )<br>            )<br>        }<br>    }<br>}</pre><p>We used spring(dampingRatio = Spring.DampingRatioMediumBouncy) for the rotation. This subtle bounce feels tactile and native on both iOS and Android screens.</p><p>With just three compact files, you now have an expandable, animated Speed Dial action menu ready for any Compose Multiplatform project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*3ntKqHy_AFzqBv_uMFiblA.gif" /></figure><p><a href="https://github.com/abkhare/speed-dial-fab">GitHub - abkhare/speed-dial-fab</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b91554bc4b96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating GraphQL in Compose Multiplatform project]]></title>
            <link>https://proandroiddev.com/integrating-graphql-in-compose-multiplatform-project-f232cf824721?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/f232cf824721</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[multiplatform]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[cross-platform]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Sat, 22 Mar 2025 11:42:41 GMT</pubDate>
            <atom:updated>2025-05-15T16:18:11.013Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Created by Abhiraj Khare" src="https://cdn-images-1.medium.com/max/1024/1*f6LBbSc4iA74wwmFvmZpwg.png" /></figure><p>GraphQL is a data query and manipulation language. It is server-side runtime for application programming interfaces (APIs) that allows specifying what data is to be retrieved or modified. GraphQL is neither frontend nor backend, it is a language spoken between two to exchange information.</p><p>GraphQL is not SQL as it uses resolver to retrieve or manipulate the data. GraphQL offers more flexible and efficient way of API development. Unlike REST, it has only 1 endpoint and data is handled by defining “query” and “mutation” in its schema. For more information you can refer : <a href="https://graphql.org/">https://graphql.org/</a></p><p>For this sample app, we will use Apollo GraphQL open API: <a href="https://studio.apollographql.com/public/countries/variant/current/schema/reference">https://studio.apollographql.com/public/countries/variant/current/schema/reference</a></p><p>This page shows schema which will give us idea what kind of data we can get from this API.</p><p>For example, if want to get continents details. Query will be:</p><pre>query ExampleQuery {<br>  continents {<br>    code<br>    name<br>    countries {<br>      name<br>    }<br>  }<br>}</pre><p>Here query can be modified to get any one of the attribute, for example.</p><pre>query ExampleQuery {<br>  continents {<br>    name<br>  }<br>}</pre><p>Similarly if we want to fetch all details of countries, query will be:</p><pre>query Countries {<br>  countries {<br>    code<br>    name<br>    native<br>    phone<br>    continent {<br>      code<br>      name<br>    }<br>    currency<br>    languages {<br>      rtl<br>      native<br>      name<br>      code<br>    }<br>    emoji<br>    emojiU<br>    states {<br>      code<br>      name<br>    }<br>  }<br>}</pre><p>We can even try to execute this query in explorer to see results. <a href="https://studio.apollographql.com/public/countries/variant/current/explorer">https://studio.apollographql.com/public/countries/variant/current/explorer</a></p><p>Let’s open build.gradle.kts of shared module to add plugin.</p><pre>// Add in libs.versions.toml<br>graphql = &quot;4.0.1&quot;<br>apolloGraphQl = { id = &quot;com.apollographql.apollo&quot;, version.ref = &quot;graphql&quot; }<br>// Add <br>plugins {<br>    ....<br>    alias(libs.plugins.apolloGraphQl)<br>}<br>apollo {<br>    service(&quot;service&quot;) {<br>        packageName.set(&quot;com.your.package.name&quot;)<br>    }<br>}</pre><p>Now we have to download graphql schema by following command. Don’t forget to change the correct package.</p><pre>./gradlew shared:downloadApolloSchema --endpoint=&#39;https://countries.trevorblades.com/graphql&#39; --schema=&quot;shared/src/commonMain/graphql/com/khareab/cmp/graphql&quot;</pre><p>Once executed we will get schema file “graphql.graphqls” under mentioned package. Now sync the project</p><p>Inside same package we will create 2 queries file. One for fetching Country list and another country details.</p><pre>// For country list<br>query Countries {<br>    countries {<br>        name<br>        capital<br>        code<br>        emoji<br>    }<br>}<br><br>// For country details<br>query Country($country_code: ID!) {<br>    country(code: $country_code) {<br>        name<br>        capital<br>        code<br>        emoji<br>        currency<br>        languages {<br>            name<br>        }<br>        continent {<br>            name<br>        }<br>    }<br>}</pre><p>Create Apollo client.</p><pre>val apolloClient = ApolloClient<br>    .Builder()<br>    .serverUrl(&quot;https://countries.trevorblades.com/graphql&quot;)<br>    .build()</pre><p>Now we can access data using client and query created in previous steps.</p><pre>apolloClient<br>      .query(CountriesQuery())<br>      .execute()<br>      .data<br>      ?.countries<br>      ?: emptyList()</pre><p>Once this is configured, we can use the fetched data to show on UI. We can create simple UI in composeApp-&gt;commonMain/</p><pre>    Box(modifier = Modifier.fillMaxSize()) {<br>        if (state.isLoading) {<br>            // Loading indicator<br>            CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))<br>        } else {<br>            // List of countries<br>            LazyColumn(<br>                modifier = Modifier.fillMaxSize()<br>            ) {<br>                items(state.countries.size) { index -&gt;<br>                    // Country Item<br>                    CountryItem(<br>                        country = state.countries[index],<br>                        index = index<br>                    ) {<br>                        onSelectedCountry(state.countries[index].code)<br>                    }<br>                }<br>            }<br>            GetScrollBars()<br>        }<br>    }</pre><p>Now use View Model to call GraphQL api client which we created in previous steps.</p><p>You can also follow the sample project I uploaded on Github. This uses clean architecture where it is divided in data, domain and UI layer.</p><p>Apollo client resides in data layer which gives fetched data to usecases in domain layer. Domain layer converts the data into domain model as well as apply sort operation (business logic). Response is then delivered to ViewModel in UI layer through which data is displayed on UI using compose state. You can find repository like at:</p><p><a href="https://github.com/abkhare/CMPGraphQL">GitHub - abkhare/CMPGraphQL: Compose Multiplatform project template with GraphQL client integration. Can create app for Android, iOS, Desktop and Web.</a></p><p>Clone the project and then sync it. And then try to run it on different platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*6skJZDvCaM6N39UgMciR_g.png" /></figure><p>That’s all, happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f232cf824721" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/integrating-graphql-in-compose-multiplatform-project-f232cf824721">Integrating GraphQL in Compose Multiplatform project</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate your Android Project to Compose Multiplatform Project]]></title>
            <link>https://proandroiddev.com/migrate-your-android-project-to-compose-multiplatform-project-0708897caea3?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/0708897caea3</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Thu, 02 Jan 2025 09:43:47 GMT</pubDate>
            <atom:updated>2025-01-04T19:49:33.816Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*xxXBV-5F7Fk_mGYyNinErg.png" /></figure><p>Hi all, I have been working on a Compose Multiplatform project for last few months and this learning journey was remarkable. In same project I got chance to migrate android application codebase to Compose Multiplatform which was able to build apps for iOS, Android and Desktop.</p><p>Prerequisite for such migration is that your project should have</p><ul><li>Single activity and compose navigation for all composable screens.</li><li>No fragments and no XML views</li><li>Ktor as network api client</li><li>Room or SqlDelight for local storage</li><li>Use of expect/actual to write platform specific code</li></ul><p>Here I will be sharing step by step process to migrate sample multi-modular android code into Compose Multiplatform.</p><p>Clone below repository to get android sample implementation. We will be converting this sample into Compose Multiplatform. (Branch: <a href="https://github.com/abkhare/ComposeMultiplatformMigration/tree/android_sample">android_sample</a>)</p><p><a href="https://github.com/abkhare/ComposeMultiplatformMigration.git">GitHub - abkhare/ComposeMultiplatformMigration: Migartion to Compose Multiplatform</a></p><p>Add blow plugins in project and all module level build.gradle.</p><pre>// Add these plugins in project build.gradle<br>alias(libs.plugins.kotlinMultiplatform) apply false<br>alias(libs.plugins.composeMultiplatform) apply false<br><br>// Add these plugins in each module build.gradle<br>alias(libs.plugins.kotlinMultiplatform)<br>alias(libs.plugins.composeMultiplatform)<br>// Remove if present in each module build.gradle<br>alias(libs.plugins.kotlin.android)<br><br>// Version Catalog:<br>kotlin = &quot;2.0.0&quot;<br>compose-multiplatform = &quot;1.7.0&quot;<br>kotlin-android = { id = &quot;org.jetbrains.kotlin.android&quot;, version.ref = &quot;kotlin&quot; }<br>composeMultiplatform = { id = &quot;org.jetbrains.compose&quot;, version.ref = &quot;compose-multiplatform&quot; }<br>kotlinMultiplatform = { id = &quot;org.jetbrains.kotlin.multiplatform&quot;, version.ref = &quot;kotlin&quot; }</pre><p>Remove “compileOptions” and “<em>kotlinOptions</em>” if present in all module level build.gradle.</p><p>All all targets if you want to support your application on Web, iOS, Android and Desktop.</p><ul><li>wasm: Browser application</li><li>androidTarget: Android application</li><li>iosXXX: iOS application</li><li>jvm: MacOs and Windows Desktop application running JVM</li></ul><pre>kotlin {<br>    @OptIn(ExperimentalWasmDsl::class)<br>    wasmJs {<br>        browser {<br>            val projectDirPath = project.projectDir.path<br>            commonWebpackConfig {<br>                devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {<br>                    static = (static ?: mutableListOf()).apply {<br>                        // Serve sources to debug inside browser<br>                        add(projectDirPath)<br>                    }<br>                }<br>            }<br>        }<br>    }<br><br>    androidTarget {<br>        @OptIn(ExperimentalKotlinGradlePluginApi::class)<br>        compilerOptions {<br>            jvmTarget.set(JvmTarget.JVM_11)<br>        }<br>    }<br><br>    iosX64()<br>    iosArm64()<br>    iosSimulatorArm64()<br><br>    jvm(&quot;desktop&quot;)<br><br>    sourceSets {<br>        val desktopMain by getting<br>        commonMain.dependencies {<br><br>        }<br>        androidMain.dependencies {<br><br>        }<br>        iosMain.dependencies {<br><br>        }<br>        desktopMain.dependencies {<br><br>        }<br>        wasmJsMain.dependencies {<br><br>        }<br>    }<br>}</pre><pre>// Add this in app module<br>listOf(<br>    iosX64(),<br>    iosArm64(),<br>    iosSimulatorArm64()<br>).forEach { iosTarget -&gt;<br>    iosTarget.binaries.framework {<br>        // This will &quot;app&quot; fromework<br>        baseName = &quot;app&quot;<br>        isStatic = true<br>    }<br>}<br>// Instead of this for ios target<br>iosX64()<br>iosArm64()<br>iosSimulatorArm64()</pre><p>With sourSets, we can define all platform specific dependencies.</p><p><strong>commonMain</strong>: It will have all multiplatform dependencies which is work on all declared platform. <em>Before adding any dependencies here check whether that library has support on all platform you defined in gradle</em><strong>.</strong></p><p><strong>androidMain</strong>: dependencies which are supported on Android platform.</p><p><strong>iosMain</strong>: dependencies which are supported on iOS platform.</p><p><strong>desktopMain</strong>: dependencies which are supported on Desktop platform.</p><p><strong>wasmJsMain</strong>: dependencies which are supported on Browser platform.</p><blockquote>Note: Browser application are not advised to develop with Compose Multiplatform as it is alpha stage.</blockquote><blockquote>Message from google: “New ‘wasm’ target is Work-in-Progress and is subject to change without notice. Please report encountered issues to https://kotl.in/issue”</blockquote><p>Add compose and module dependencies in commonMain. And sync the project. For navigation, make sure to use JetBrains navigation.</p><pre>implementation(project(&quot;:FeatureOne&quot;))<br>implementation(project(&quot;:FeatureTwo&quot;))<br>implementation(project(&quot;:FeatureThree&quot;))<br>implementation(compose.materialIconsExtended)<br>implementation(compose.ui)<br>implementation(compose.animationGraphics)<br>implementation(compose.material3)<br>implementation(compose.components.resources)<br>implementation(compose.components.uiToolingPreview)<br>implementation(compose.runtime)<br>implementation(compose.foundation)<br>implementation(compose.animation)<br>implementation(libs.navigation)<br><br>// Version Catalog<br>navigation = &quot;2.8.0-alpha08&quot;<br>navigation = { group = &quot;org.jetbrains.androidx.navigation&quot;, name = &quot;navigation-compose&quot;, version.ref = &quot;navigation&quot; }</pre><p>Now add four directories in each module -&gt; src</p><pre>commonMain/kotlin<br>androidMain/kotlin<br>iosMain/kotlin<br>desktopMain/kotlin<br>wasmJsMain/kotlin</pre><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/428/1*PF0yNzWtDFKPhD-jajOuQA.png" /></figure><p>Copy all code of compose, viewModel or business logic written with any multiplatform library into <strong>commonMain</strong>.</p><p>In our case for app module, we will move MainActivity, res/ and AndroidManifest.xml in <strong>androidMain/kotlin</strong> and rest all files in <strong>commonMain/kotlin </strong>in app module. if any resource/assets belongs to compose UI is present, then we will move them to commonMain/composeResources.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/722/1*Dr8_JgyR3v6sCxIOsgfi5Q.png" /></figure><p>Similarly we will move files for other modules. And then build the project and try running on Android devices.</p><p>Current setup will only work for Android target so, we need to enable other platform target as well. So we will build other targets with the help of “<a href="https://kmp.jetbrains.com/?_gl=1*1plq0i0*_gcl_au*MTc2MjcxMDk3OC4xNzM1Mzg4Mjg3*FPAU*MTc2MjcxMDk3OC4xNzM1Mzg4Mjg3*_ga*Nzg1MDc1MjMuMTcyNzQ1OTIyNg..*_ga_9J976DJZ68*MTczNTc5MDYxMi40OC4xLjE3MzU3OTA2ODcuNjAuMC4w">Kotlin Multiplatform Wizard</a>”.</p><p>Using Kotlin Multiplatform sample, let’s create sample with all required targets. Select Android, iOS, Desktop and Web download sample.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*psJaDY9H14IsrcusEPlndQ.png" /></figure><p>Try running all targets:</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/748/1*6skJZDvCaM6N39UgMciR_g.png" /></figure><p>Output will be something like this:</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*xxXBV-5F7Fk_mGYyNinErg.png" /></figure><p>Now let’s enable iOS target first, copy “iosApp” folder and paste it into our project.</p><p>Create MainViewController.kt in: app-&gt; src/iosMain/kotlin</p><pre>package com.abkhare.multiplatformmigration<br><br>import androidx.compose.ui.window.ComposeUIViewController<br><br>fun MainViewController() = ComposeUIViewController { AppNavigation() }</pre><p>Now open “iosApp” in Xcode.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*DHiO0b84x0elbpjwABUQtg.png" /></figure><p>Modify build script to create compose framework in Xcode. Since our root module is app module so we need to specify “app:embedAndSignAppleFrameworkForXcode”.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*q4GcODBb87qtca6YILzyaA.png" /></figure><p>Now point to correct framework in “ContentView.swift”.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*7oMyCAKGFpbj3ls0NkbaxQ.png" /></figure><blockquote><strong>You may have to resolve some errors using:</strong> <a href="https://github.com/abkhare/ComposeMultiplatformMigration/commit/97205c6d9a96a73cbdf7583cee4a6865a2ecf9bd">https://github.com/abkhare/ComposeMultiplatformMigration/commit/97205c6d9a96a73cbdf7583cee4a6865a2ecf9bd</a></blockquote><p>And run the project in Xcode. And that’s it you will be able to build the application on iPhone device.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/283/1*00rRFVOzvuUD9QVf8AtoLA.png" /></figure><p>Now to Enable “DeskTop” target, create “main.kt” in app-&gt; src/desktopMain/kotlin.</p><pre>fun main() = application {<br>    Window(<br>        onCloseRequest = ::exitApplication,<br>        title = &quot;MultiplatformSample&quot;,<br>    ) {<br>        AppNavigation()<br>    }<br>}</pre><p>Now run the application by play icon beside main function.</p><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/463/1*fr-yzSQYscNEkQliYqtnDQ.png" /></figure><figure><img alt="source: author" src="https://cdn-images-1.medium.com/max/1024/1*JrpZN9Iy7geoQ2hIOcy8JQ.png" /></figure><p>You can find full working source code in below repository (branch: main)</p><p><a href="https://github.com/abkhare/ComposeMultiplatformMigration">GitHub - abkhare/ComposeMultiplatformMigration: Migration to Compose Multiplatform</a></p><p>Stay tuned, I will be sharing more such in-depth articles on Compose Multiplatform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0708897caea3" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/migrate-your-android-project-to-compose-multiplatform-project-0708897caea3">Migrate your Android Project to Compose Multiplatform Project</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Convert callback API into suspend or Flow]]></title>
            <link>https://medium.com/iot-android-things/convert-callback-api-into-suspend-or-flow-c10fe7ca810c?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/c10fe7ca810c</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[suspend]]></category>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Thu, 03 Jun 2021 16:15:53 GMT</pubDate>
            <atom:updated>2021-06-03T16:15:53.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKQFevXW9ilKYoQhuzE1uA.png" /></figure><p>If you had started using coroutine in your project but any third party library which you are using does not support suspend function, then we can convert such callback based API into suspend using “suspendCancellableCoroutine”.</p><p>Similarly we have “<em>callbackFlow</em>” to convert callbacks into flow. Let’s understand this with the help of example.</p><pre>interface MyCallback {<br>    fun onSuccess(value: String)<br>    fun onFailure(error: Throwable)<br>}</pre><pre>suspend fun testSuspend(): String = suspendCancellableCoroutine <strong>{  </strong>continuation <strong>-&gt;<br>    </strong>val callback = object : MyCallback {<br>        override fun onSuccess(value: String) {<br>            continuation.resume(value, onCancellation = <strong>{}</strong>)<br>        }<br><br>        override fun onFailure(error: Throwable) {<br>            continuation.<em>resumeWithException</em>(error)<br>        }<br>    }<br>    <em>// register callback<br></em><strong>}</strong></pre><p>Here let’s say some third party library has exposed “MyCallback” interface. We will use this interface instance to register and it will give us response in “onSuccess” callback or in “onFailure” callback in case of failure.</p><p>“suspendCancellableCoroutine” will suspend the coroutine in which it is called and allow any third party library like RX to perform background operation.</p><p>Once it returns the response in “onSuccess”, coroutine can be resumed either by “continuation.resume” or by “continuation.<em>resumeWithException</em>”.</p><pre>interface MyCallback {<br>    fun onSuccess(value: String)<br>    fun onFailure(error: Throwable)<br>    fun onComplete()<br>}<br><br> fun testFlow(): Flow&lt;String&gt; = <em>callbackFlow </em><strong>{<br>    </strong>val callback = object : MyCallback {<br>        override fun onSuccess(value: String) {<br>            offer(value)<br>        }<br><br>        override fun onFailure(error: Throwable) {<br>            close(error)<br>        }<br><br>        override fun onComplete() {<br>            close()<br>        }<br>    }<br>    <em>// register callback<br>    </em>awaitClose <strong>{</strong><em><br>        // unregister callback<br>    </em><strong>}<br>}</strong></pre><p>Similarly if same library response, we want to pass through coroutine flow then we can use “<em>callbackFlow</em>”.</p><p>Here also on “onSuccess” callback, we call “offer” to send data through flow and close to close the flow.</p><p>awaitClose provides a way to cleanup the resources when flow is closed in case when callback base API invokes close.</p><p>Thanks for reading…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c10fe7ca810c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/convert-callback-api-into-suspend-or-flow-c10fe7ca810c">Convert callback API into suspend or Flow</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[enum versus sealed classes]]></title>
            <link>https://medium.com/iot-android-things/enum-versus-sealed-classes-526f05479f0d?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/526f05479f0d</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[versus]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[sealed-classes]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Tue, 01 Jun 2021 17:40:48 GMT</pubDate>
            <atom:updated>2021-06-01T17:40:48.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*HoXsVI8ysrcmQhPM6BtXlQ.jpeg" /></figure><p>enum classes are used to define set of constants while sealed classes are abstract class with set of subclasses in same file.</p><p>Enum example:</p><pre>enum class Constants {<br>    <em>ONE</em>,<br>    <em>TWO</em>,<br>    <em>THREE<br></em>}</pre><p>Alternatively in kotlin, we can have same behaviour using sealed class.</p><p>But now question arises, if enum was already there then why was sealed class introduced.</p><p>One reason is that we can have only one instance of each item in enum.</p><pre>val v1 = Constants.<em>ONE<br></em>val v2 = Constants.<em>ONE<br></em>v1 === v2   <em>// true, as reference is same.</em></pre><p>If we want to write possible clone of enum in sealed class. It will be like:</p><pre>sealed class Constants {<br>    object ONE : Constants()<br>    object TWO : Constants()<br>    object THREE : Constants()<br>}</pre><p>One benefit of using sealed class is that its item can have multiple instances. Let’s understand this with an example.</p><pre>sealed class Response {<br>    object Start : Response()<br>    data class Success(val result: String) : Response()<br>}</pre><p>Here we can create multiple instances of “Success”.</p><p>With sealed class, we have to define all its subclasses in same file. So we can view the hierarchy in same file.</p><p>This characteristics of sealed class could eliminate “else” case in “when”.</p><pre>fun update(response: Response) {<br>    when(response) {<br>        is Response.Start -&gt; {<br>            <br>        }<br>        is Response.Success -&gt; {<br>            <br>        }<br>    }<br>}</pre><p>For many use case, we can prefer using sealed classes instead of enums.</p><p>Thanks for reading…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=526f05479f0d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/enum-versus-sealed-classes-526f05479f0d">enum versus sealed classes</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create beautiful loading effect with facebook shimmer library]]></title>
            <link>https://medium.com/iot-android-things/create-beautiful-loading-effect-with-facebook-shimmer-library-3b4296889dac?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b4296889dac</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[libraries]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[shimmer]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Sun, 28 Apr 2019 17:56:24 GMT</pubDate>
            <atom:updated>2019-04-28T17:56:24.446Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oBcjSb6v2AmcFg5CTKdYVA.png" /></figure><p>Shimmer library from facebook allows you to create loading animation on your android activity before you could load your data in ListView or layout.</p><p>With these simple step, you could also integrate it your android page view.</p><p>Declaring dependency in your app’s build.gradle</p><pre>dependencies {<strong><br>    </strong>implementation <strong>&#39;com.facebook.shimmer:shimmer:0.4.0&#39;<br></strong>}</pre><p>Create a xml for shimmer layout.</p><pre>&lt;<strong>RelativeLayout<br>        xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>        xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;</strong>&gt;<br><br>    &lt;<strong>ImageView<br>            android:id=&quot;@+id/cell_imageView&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;100dp&quot;<br>            android:background=&quot;@color/cell_background&quot;<br>            android:layout_margin=&quot;10dp&quot; </strong>/&gt;<br><br>    &lt;<strong>LinearLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_below=&quot;@id/cell_imageView&quot;<br>            android:layout_centerVertical=&quot;true&quot;<br>            android:orientation=&quot;vertical&quot;<br>            android:padding=&quot;20dp&quot;</strong>&gt;<br><br>        &lt;<strong>TextView<br>                android:layout_width=&quot;wrap_content&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:background=&quot;@color/cell_background&quot;<br>                android:text=&quot;                                   &quot;<br>                android:textSize=&quot;20sp&quot;<br>                android:textStyle=&quot;bold&quot; </strong>/&gt;<br><br>        &lt;<strong>TextView<br>                android:layout_width=&quot;wrap_content&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:background=&quot;@color/cell_background&quot;<br>                android:text=&quot;                       &quot; </strong>/&gt;<br><br>    &lt;/<strong>LinearLayout</strong>&gt;<br><br><br>&lt;/<strong>RelativeLayout</strong>&gt;</pre><p>Declare background color of your choice in color.xml</p><pre>&lt;<strong>color name=&quot;cell_background&quot;</strong>&gt;#dddddd&lt;/<strong>color</strong>&gt;</pre><p>Now define shimmer cell in your main view.</p><pre>&lt;<strong>com.facebook.shimmer.ShimmerFrameLayout<br>        android:id=&quot;@+id/shimmer_layout&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_gravity=&quot;center&quot;<br>        android:orientation=&quot;vertical&quot;<br>        shimmer:shimmer_duration=&quot;800&quot;<br>        shimmer:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        shimmer:layout_constraintTop_toTopOf=&quot;parent&quot;<br>        shimmer:layout_constraintEnd_toEndOf=&quot;parent&quot;</strong>&gt;<br><br>    &lt;<strong>LinearLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:orientation=&quot;vertical&quot;</strong>&gt;<br>        &lt;<strong>include layout=&quot;@layout/shimmer_cell&quot;</strong>/&gt;<br>        &lt;<strong>include layout=&quot;@layout/shimmer_cell&quot;</strong>/&gt;<br>        &lt;<strong>include layout=&quot;@layout/shimmer_cell&quot;</strong>/&gt;<br>        &lt;<strong>include layout=&quot;@layout/shimmer_cell&quot;</strong>/&gt;<br>        &lt;<strong>include layout=&quot;@layout/shimmer_cell&quot;</strong>/&gt;<br>    &lt;/<strong>LinearLayout</strong>&gt;<br><br>&lt;/<strong>com.facebook.shimmer.ShimmerFrameLayout</strong>&gt;</pre><p>To start shimmer animation, use</p><pre><strong>shimmerLayout </strong>= findViewById(R.id.<em>shimmer_layout</em>)<strong><br>shimmerLayout</strong>?.startShimmer()</pre><p>To stop shimmer animation, use</p><pre><strong>shimmerLayout</strong>?.stopShimmer()</pre><p>And check the result on your device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*oBgX6mcl_-x6ZbzYw1Fo1g.png" /></figure><p>Download full source code at:</p><p><a href="https://github.com/abkhare/FacebookShimmer">abkhare/FacebookShimmer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b4296889dac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/create-beautiful-loading-effect-with-facebook-shimmer-library-3b4296889dac">Create beautiful loading effect with facebook shimmer library</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Hosting: Upload your static web contents in easy steps.]]></title>
            <link>https://medium.com/iot-android-things/firebase-hosting-upload-your-static-web-contents-in-easy-steps-9709baee7ce4?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/9709baee7ce4</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[static]]></category>
            <category><![CDATA[hosting]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Tue, 16 Apr 2019 17:55:45 GMT</pubDate>
            <atom:updated>2019-04-16T17:55:45.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_asLVMFSdfh7W1BzHrhluQ.png" /></figure><p>First you have to download NPM on your machine. Then you have to install firebase tool by:</p><pre>npm install -g firebase-tools</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppw1mQYzGH3F4rVyRu-IWw.png" /></figure><p>Next thing you need is, to get connected to your firebase account:</p><pre>firebase login</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*J9t-p3qLMeCPBop8w2j4iA.png" /></figure><p>Once this is executed, you will be able to see all your firebase project in your account by “firebase list”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*YGyrljHnKxRJkbqOesihOA.png" /></figure><p>Now get into your firebase project folder which contains your html, images or JSON files. Initialize this folder as firebase project by:</p><pre>firebase init</pre><p>Select option to “Configure and deploy Firebase Hosting sites”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2l3tjyvE7xSSwqjkHipMwg.png" /></figure><p>Select firebase project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9i1Lp4J0sJ-CLC3E4MFZhQ.png" /></figure><p>Define your public directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OIxb0AV7brJjAohXUTNVJg.png" /></figure><p>You will see “public” folder in your project root directory. Make sure you have placed all your site content in this folder. Now define index.html as entry point of your site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NTVu3L-8B4fkMlIBfzqaeA.png" /></figure><p>Once this is done you will see message “Firebase initialization complete!” which marks completion of initialization step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yN4bhOZ-eHDCYd_R-MYIDg.png" /></figure><p>You can see now firebase.json file which contains entry point and mapping of your web project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*p2TuyDSpvcHjAgGN0PBi_w.png" /></figure><p>Now its time to deploy you website.</p><pre>firebase deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*og2eh4V2LuNdf3mp-d2THQ.png" /></figure><p>Deploy step will generate a URL which will host your site content. Your live site can be viewed by:</p><pre>firebase open</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*71nAEJloHonTU7WduPQDug.png" /></figure><p>Now suppose you want to host a JSON in remote. you just have to create a file with .json extension and place it in public folder</p><pre>{<br> <strong>&quot;key&quot;</strong>: <strong>&quot;Firebase Hosting&quot;<br></strong>}</pre><p>Now again issue “firebase deploy” to make your json file live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlmPGqfJSe1OuFjtQkR8Ww.png" /></figure><p>You can access you live JSON file by:</p><p>&lt;Hosting-URL&gt;/filename.json</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9709baee7ce4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/firebase-hosting-upload-your-static-web-contents-in-easy-steps-9709baee7ce4">Firebase Hosting: Upload your static web contents in easy steps.</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Jetpack: WorkManager]]></title>
            <link>https://medium.com/iot-android-things/android-jetpack-workmanager-daad059f5bc2?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/daad059f5bc2</guid>
            <category><![CDATA[background]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[workmanager]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Mon, 25 Mar 2019 01:45:31 GMT</pubDate>
            <atom:updated>2019-03-25T01:55:09.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MpAUT9fdrMXmoPob7baqvw.png" /></figure><p>Latest happening in the word of android background processing is WorkManager. To check how WorkManager works, follow these simple steps.</p><p>Dependencies to include in build.gradle</p><pre>dependencies {<br>   <strong>def </strong>work_version = <strong>&#39;2.0.0&#39;<br>   </strong><em>// (Java only)<br>   </em>implementation <strong>&quot;androidx.work:work-runtime:</strong>$work_version<strong>&quot;<br>   </strong><em>// Kotlin + coroutines<br>   </em>implementation <strong>&quot;androidx.work:work-runtime-ktx:</strong>$work_version<strong>&quot;<br>}</strong></pre><p>If you have not yet migrated your code to androidx then,</p><pre>dependencies {<br>    <strong>def </strong>work_version = 1.0.0<br>    <em>// (Java only)<br>    </em>implementation <strong>&quot;android.arch.work:work-runtime:</strong>$work_version<strong>&quot;<br>    </strong><em>// Kotlin + coroutines<br>    </em>implementation <strong>&quot;android.arch.work:work-runtime-      ktx:</strong>$work_version<strong>&quot;<br></strong>}</pre><p>Create a worker class by extending it with Worker and overriding its method doWork().</p><pre><strong>class </strong>TestWorker(context: Context, parameter: WorkerParameters) : Worker(context, parameter) {<br>        // Do your background job here.<br>        <strong>return </strong>Result.success()<br>    }<br>}</pre><p>Create Data instance which is to passed to Worker.</p><pre><strong>var </strong>data = <em>workDataOf</em>(<strong>&quot;data_to_send&quot; </strong><em>to </em><strong>&quot;Input Data&quot;</strong>)</pre><p>Define a Constraints</p><pre><strong>var </strong>constraint: Constraints = Constraints.Builder().<em>apply </em><strong>{<br>    </strong>setRequiredNetworkType(NetworkType.<strong>CONNECTED</strong>)<br><strong>}</strong>.build()</pre><p>Declare one time request and periodic request.</p><pre><strong>var </strong>oneTimeWorkRequest: OneTimeWorkRequest = <em>OneTimeWorkRequestBuilder</em>&lt;TestWorker&gt;()<br>    .setInitialDelay(1, TimeUnit.<strong>SECONDS</strong>)<br>    .setInputData(data)<br>    .setConstraints(constraint).build()<br><br><strong>var </strong>periodicWorkRequest: PeriodicWorkRequest = <em>PeriodicWorkRequestBuilder</em>&lt;TestWorker&gt;(16, TimeUnit.<strong>MINUTES</strong>)<br>    .setInputData(data)<br>    .setConstraints(constraint).build()</pre><p>Periodic interval for periodic work request defined here must be greater than or equal to <em>PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS</em>(currently 15 minutes). It may run immediately, at the end of the period, or any time in between so long as the other conditions are satisfied at the time.</p><p>Now enqueue above created requests to WorkManager.</p><pre>WorkManager.getInstance().enqueueUniqueWork(<strong>&quot;one_time_work_request&quot;</strong>, ExistingWorkPolicy.<strong>KEEP</strong>, oneTimeWorkRequest)<br><br>WorkManager.getInstance().enqueueUniquePeriodicWork(<strong>&quot;periodic_work_request&quot;</strong>, ExistingPeriodicWorkPolicy.<strong>KEEP</strong>, periodicWorkRequest)</pre><p>You can find complete working example of WorkManager here,</p><p><a href="https://github.com/abkhare/JetpackWorkManager">abkhare/JetpackWorkManager</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daad059f5bc2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/android-jetpack-workmanager-daad059f5bc2">Android Jetpack: WorkManager</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Background Processing in Android]]></title>
            <link>https://medium.com/iot-android-things/all-about-background-processing-in-android-a003c0fb9bd3?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/a003c0fb9bd3</guid>
            <category><![CDATA[workmanager]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[background]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Sun, 24 Mar 2019 10:47:03 GMT</pubDate>
            <atom:updated>2019-03-25T01:47:55.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gWcBha2O2iZV1cTPdEvD9g.png" /></figure><p>UI operations in android is done on Main thread or UI thread. If heavy operations like network call, database access… is also done on this thread then it can give slow experience to user. It can even leads to ANR(Application not responding) if UI hangs for longer time(5 seconds) when heavy task are performed on main thread.</p><p>We can create simple thread to run heavy task in background.</p><pre>Thread thread = <strong>new </strong>Thread(<strong>new </strong>Runnable() {<br>    @Override<br>    <strong>public void </strong>run() {<br>        <em>// Heavy task<br>    </em>}<br>});<br>thread.start();</pre><p>And then we can use methods like View.postDelayed(Runnable, delay), Activity.runOnUiThread(Runnable), View.post(Runnable) etc to send results on UI thread.</p><h4>Limitation of simple thread.</h4><p>Since Android UI thread is not thread safe, creating simple thread may lead to weird UI issues. And it also makes code complex.</p><p>Here are few other ways where background task can be handled.</p><h4>1. AsyncTask</h4><p>AsyncTask can be good solution where your task is executed in background(worker thread) by using doInBackground() method and result is delivered to UI using onPostExecute() method.</p><h4>Limitation of AsyncTask.</h4><p>AsyncTask is created and executed from main thread. And you can execute instance of AsyncTask only once.</p><h4>2. Services</h4><p>Service is best used when your task is not too long because it runs on main thread. It can be created and executed from any thread. If any important task need to be executed then we can use ForegroundService. ForegroundService uses notification and android system will not kill your ForegroundService.</p><h4>Limitation of Services</h4><p>It blocks main thread or UI thread if started from main thread.</p><h4>3. IntentService</h4><p>IntentService stored all requested task in queue and executes them sequentially in worker thread. It stops itself when there is no more task in its queue.</p><h4>Limitation of IntentService</h4><p>It cannot run task in parallel and executes task after poping it from its queue.</p><h4>4. Download Manager</h4><p>Download manager should be preferred when app wants to download large media or document files.</p><h4>5. Firebase Jobdispatcher</h4><p>Jobdispatcher will execute your task in background taking into account system resources like battery and memory. Using Firebase jobdispatcher you can schedule your task periodically at regular interval. Internally it uses android JobScheduler to execute its task.</p><h4>Limitation of Firebase Jobdispatcher</h4><p>Jobdispatcher support only after api level 23+</p><h3>6. WorkManager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*eqDtxfULG1JlLErYqX9j_w.png" /></figure><p>Latest happening in the word of android background processing is WorkManager. It is library released under Android Jetpack.</p><p>Like Firebase Jobdispatcher, It also takes care of system resources while executing background task. You can even execute periodic task or one time task using handy classes provided in this library.</p><h4>Winning Points from Jetpack WorkManager</h4><p>WorkManager has support for api level 14+</p><p>It uses combination of AlarmManager, BroadcastReceiver to run background task for api level 14–22 and JobScheduler API to run background task above 23 api level.</p><p>Check below image from Google developers to understand when to use what while performing background operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*nvV7vN--gw9lSjnOp7ym0Q.png" /><figcaption><a href="https://developer.android.com/guide/background/">https://developer.android.com/guide/background/</a></figcaption></figure><p>If you want to try WorkManager, follow this article below.</p><p><a href="https://iotandroidthings.com/android-jetpack-workmanager-daad059f5bc2">Android Jetpack: WorkManager</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a003c0fb9bd3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/all-about-background-processing-in-android-a003c0fb9bd3">All about Background Processing in Android</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Remote Config]]></title>
            <link>https://medium.com/iot-android-things/firebase-remote-config-2647c7905175?source=rss-25737b8c0d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/2647c7905175</guid>
            <category><![CDATA[config]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[remote]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Abhiraj Khare]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 18:42:20 GMT</pubDate>
            <atom:updated>2019-03-09T06:38:01.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqXxHt9Ur_7kwoSW4BwR7w.png" /></figure><p>With Firebase remote config, you can change your app appearance and behaviour without publishing your app in play store or app store. For example whenever you want to enable or disable any feature in the app, you can change it from firebase remote config console or firebase remote rest api. And when you publish those changes, remote parameters overrides app default parameter.</p><p>Setup your project in firebase console</p><p><a href="https://console.firebase.google.com/"></a></p><p>Add project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*tsECQc4BzDRsUG7Of83Z2w.png" /></figure><p>Click on Add project.</p><p>Specify project name and click on “Create project”.</p><p>Add parameter with key and value.</p><p>Now click on “Publish changes” to make it available for the app to use.</p><p>Register your app with applicationId mention in build.gradle</p><p>Download “google-services.json” and place it in your main app module.</p><p>Add dependency at project build.gradle</p><pre>dependencies {<br>     classpath <strong>&#39;com.google.gms:google-services:4.2.0&#39;</strong><br>}</pre><p>Dependency in app build.gradle</p><pre>dependencies {<br>    implementation <strong>&#39;com.google.firebase:firebase-core:16.0.7&#39;</strong><br>    implementation <strong>&#39;com.google.firebase:firebase-config:16.3.0&#39;<br></strong>}<br><br>apply <strong>plugin</strong>: <strong>&#39;com.google.gms.google-services&#39;</strong></pre><p>Now gradle sync your project.</p><p>Create FirebaseRemoteConfig object in your activity.</p><pre><strong>var </strong>remoteConfig = FirebaseRemoteConfig.getInstance()</pre><p>Set config settings</p><pre><strong>val </strong>configSettings = FirebaseRemoteConfigSettings.Builder()<br>    .setDeveloperModeEnabled(BuildConfig.<em>DEBUG</em>)<br>    .build()<br>remoteConfig.setConfigSettings(configSettings)</pre><p>Create value XML file (res-&gt;New-&gt;XML). And set in app defaults.</p><pre>remoteConfig.setDefaults(R.xml.<em>default_config</em>)</pre><p>Now fetch remote config using fetch() method.</p><pre>remoteConfig.fetch(expirationInSeconds);</pre><p>Once Fetch is successful, call “activateFetched” to activate fetched values.</p><pre>remoteConfig.activateFetched()</pre><pre><strong>var </strong>expirationInSeconds: Long = <strong>if</strong>(BuildConfig.<em>DEBUG</em>)<br>    0<br><strong>else<br>    </strong>3600<br><br>remoteConfig.fetch(expirationInSeconds).addOnCompleteListener(<strong>this</strong>) <strong>{<br>    if</strong>(<strong>it</strong>.<em>isSuccessful</em>) {<br>        Toast.makeText(<strong>this</strong>, <strong>&quot;Config Fetched&quot;</strong>, Toast.<em>LENGTH_SHORT</em>).show()<br>        remoteConfig.activateFetched()<br>    } <strong>else </strong>{<br>        Toast.makeText(<strong>this</strong>, <strong>&quot;Config Fetched Failed&quot;</strong>, Toast.<em>LENGTH_SHORT</em>).show()<br>    }<br><strong>}</strong></pre><p>You can get remote parameter value by simple get() method.</p><pre>remoteConfig.getString(<strong>&quot;firebase_key&quot;</strong>)</pre><h4><strong>Default config, Active config and Fetch config</strong></h4><p>Firebase remote config has three stores. <strong>Default config, Active config and Fetch config.</strong></p><p>All app defaults are stored in default config. In case if app does not have network connectivity, default config is used. Later on once remote config parameters are fetched successfully, they are stored in “Fetch config”.</p><p>Active config has parameter which app will be using by “get” method.</p><p>So once Fetch config parameter are activated by “activateFetched” method, they are copied to active config. And new values are available to app through get method.</p><h4>Caching and Throttling</h4><p>Remote config provide cached values once it is successfully fetched from remote. By default caching period is 12 hours. So after this cache expiration only app will get refreshed value.</p><p>This cache expiration time can be modified by passing it in fetch(cachePeriod) method. If app request refreshed value too frequently, remote config starts throttling the fetched request throwing <strong>FirebaseRemoteConfigFetchThrottledException </strong>and app is provided with cached values. At most 5 times, app can issue fetch request in an hour. For development and testing purpose, “isDeveloperModeEnabled” can be enable on remote config object to get frequent updates from firebase server.</p><p>Full source code is available at :</p><p><a href="https://github.com/abkhare/FirebaseRemoteConfig">abkhare/FirebaseRemoteConfig</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2647c7905175" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iot-android-things/firebase-remote-config-2647c7905175">Firebase Remote Config</a> was originally published in <a href="https://medium.com/iot-android-things">Android Things</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>