<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Md . Jahid Hasan Naiem</title>
    <description>The latest articles on DEV Community by Md . Jahid Hasan Naiem (@jhnaiem).</description>
    <link>https://dev.to/jhnaiem</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1021454%2F80123a86-7ca5-4bda-84a9-29de6b70cf70.jpeg</url>
      <title>DEV Community: Md . Jahid Hasan Naiem</title>
      <link>https://dev.to/jhnaiem</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jhnaiem"/>
    <language>en</language>
    <item>
      <title>Modify items in paginated list in Jetpack Compose</title>
      <dc:creator>Md . Jahid Hasan Naiem</dc:creator>
      <pubDate>Fri, 03 Mar 2023 02:45:42 +0000</pubDate>
      <link>https://dev.to/jhnaiem/modify-items-in-paginated-list-in-jetpack-compose-20ad</link>
      <guid>https://dev.to/jhnaiem/modify-items-in-paginated-list-in-jetpack-compose-20ad</guid>
      <description>&lt;p&gt;When utilizing the paging library to retrieve a list and subsequently populate the user interface with the paging list, modifying individual items from the list can pose considerable challenges. This tutorial aims to present a solution to this issue by demonstrating how custom pagination can be used to accomplish the same task with ease in Jetpack Compose.&lt;/p&gt;

&lt;p&gt;Let's get started... &lt;/p&gt;

&lt;p&gt;For this tutorial I have followed one of the tutorial by Philipp Lackner. &lt;a href="https://youtu.be/D6Eus3f6U9I"&gt;How to Implement Pagination With Jetpack Compose - Android Studio Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, I have replaced paging 3 library with this custom pagination. Also declared a data class for updating screen state. Also declared a  CompositionLocal key that can be provided using CompositionLocalProvider. &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;After that used that screen state as a composable state in the ViewModel. Also declared a paginator of type DefaultPaginator.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 

&lt;p&gt;I have used &lt;code&gt;CompositionLocalProvider&lt;/code&gt; and wraped the root composable function with the provider. You can learn about CompositionLocalProvider from &lt;a href="https://medium.com/mobile-app-development-publication/android-jetpack-compose-compositionlocal-made-easy-8632b201bfcd"&gt;here..&lt;/a&gt; &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;So, whenever a clip gets played the value of the &lt;code&gt;state&lt;/code&gt; declared in the ViewModel getting updated and causing Compose to recompose the screen.And the item from the list get modified.&lt;/p&gt;

&lt;p&gt;This is it for today!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting started with jetpack compose from XML</title>
      <dc:creator>Md . Jahid Hasan Naiem</dc:creator>
      <pubDate>Tue, 07 Feb 2023 08:52:53 +0000</pubDate>
      <link>https://dev.to/jhnaiem/getting-started-with-jetpack-compose-from-xml-1870</link>
      <guid>https://dev.to/jhnaiem/getting-started-with-jetpack-compose-from-xml-1870</guid>
      <description>&lt;p&gt;As developers specializing in Android, we are well-versed in creating user interfaces using XML. However, it is worth noting that Google is currently advocating the use of Jetpack Compose for developing native user interfaces. Jetpack Compose represents a contemporary toolkit designed for creating native user interfaces on the Android platform. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/jetpack/compose/why-adopt"&gt;&lt;em&gt;Why adopt Compose?&lt;/em&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This article aims to demonstrate the process of incorporating Jetpack Compose into an existing project that utilizes XML for building the user interface. To facilitate this tutorial, the same &lt;a href="https://github.com/jhnaiem/UnsplashPhotos/tree/develop"&gt;project&lt;/a&gt; will be utilized throughout. Without further ado, let us commence...&lt;/p&gt;

&lt;p&gt;Initially, it is necessary to include the Jetpack Compose dependency within the &lt;code&gt;build.gradle&lt;/code&gt; file of the application. However, this can be a tedious process when integrating the dependency into an existing project due to the requisite matching of various dependency versions, compilation SDK versions, and Kotlin versions. After several iterations of modifying the dependency versions, I was eventually able to successfully integrate Jetpack Compose into one of my existing projects. Below is a code snippet outlining the configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composeOptions {
        kotlinCompilerExtensionVersion = "1.3.1"
    }
kotlinOptions {
        jvmTarget = '1.8'
    }
buildFeatures {
        compose true
        dataBinding true
        viewBinding true
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ext.versions = [
            'navigation'         : '2.5.1',
            'lifecycle_version'  : '2.4.0',
            'retrofit_version'   : '2.9.0',
            'glide'              : '4.12.0',
            'hilt'               : '2.44.2',
            'paging'             : '3.1.1',
            'timber'             : '5.0.1',
            'compose_version'    : '1.2.0',
            'hilt_navigation'    : '1.0.0',
            'accompanist_version': '0.25.1'
    ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Paging Library
    implementation "androidx.paging:paging-runtime:${versions.paging}"
    implementation "androidx.paging:paging-compose:1.0.0-alpha14"

    //logger
    implementation "com.jakewharton.timber:timber:${versions.timber}"

    //compose
    implementation "androidx.compose.animation:animation:${versions.compose_version}"
    implementation "androidx.compose.foundation:foundation:${versions.compose_version}"
    implementation "androidx.compose.material:material:${versions.compose_version}"
    implementation "androidx.compose.material:material:${versions.compose_version}"
    implementation "androidx.compose.runtime:runtime:${versions.compose_version}"
    implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.0-alpha01"
    implementation "androidx.compose.ui:ui:${versions.compose_version}"
    debugImplementation "androidx.compose.ui:ui-tooling:${versions.compose_version}"
    implementation "androidx.compose.ui:ui-tooling-preview:${versions.compose_version}"
    implementation('io.coil-kt:coil-compose:2.2.2')
    implementation "androidx.hilt:hilt-navigation-compose:${versions.hilt_navigation}"
    implementation "androidx.navigation:navigation-compose:1.0.0"
    implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0"
    // Accompanist
    implementation "com.google.accompanist:accompanist-placeholder-material:${versions.accompanist_version}"
    implementation "com.google.accompanist:accompanist-navigation-animation:${versions.accompanist_version}"
    implementation "com.google.accompanist:accompanist-permissions:${versions.accompanist_version}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; First replace the part from the XML that you want to convert to Jetpack Compose with &lt;em&gt;&lt;strong&gt;Compose view&lt;/strong&gt;&lt;/em&gt;. Let's remove a recycler view and use Compose view there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Qt8PG-X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oq90cz0q62i5qm4fl2k0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Qt8PG-X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oq90cz0q62i5qm4fl2k0.png" alt="Image description" width="880" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Compose view:&lt;/strong&gt; It's view in XML which can host Jetpack &lt;br&gt;
  Compose UI content. Using this we can get familiar with &lt;br&gt;
  jetpack compose on our existing project. Basically all the &lt;br&gt;
  view drawn using Jetpack compose will be drawn over this &lt;br&gt;
  Compose view.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Create necessary UI component for the recyclerview you have replaced. We are going to replace recyclerview with &lt;strong&gt;LazyVerticalGrid&lt;/strong&gt; in Compose and also create  ItemView(PhotoItemCard) in Compose for the &lt;strong&gt;LazyVerticalGrid&lt;/strong&gt; item. &lt;/p&gt;

&lt;p&gt;// The UI for each item can be generated by a reusable composable&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Here, I have created a UI for photo item. I have used &lt;code&gt;Card&lt;/code&gt; to make the photo item clickable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Now, I'll put this itemview(PhotoItemCard) inside a  LazyVerticalGrid which is similar to RecyclerView with GridLayoutManager. Creating recyelerview in compose is so simple and easy. No adapters. No view holders. In Compose Recyclerview is replace with LazyColumn, LazyRow, LazyVerticalGrid and LazyHorizontalGrid appropriately.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here, I am using the ViewModel (PhotoViewModel) to get the photos PagingData Flow object. After that inside the &lt;code&gt;PhotoGriding&lt;/code&gt; UI composable convert it to PagingItem by using &lt;code&gt;collectAsLazyPagingItem&lt;/code&gt; extension function. it collects the flow’s data as lazy items. And that’s exactly what we need. Compose knows how to handle this object and request more items when the user reaches the end of the list. I am loading this paginated data into the list using LazyVerticalGrid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Lastly, define a function in the fragment on which view you are replacing and access the composeView in the xml using binding. set view composition strategy to DisposeOnViewTreeLifecycleDestroyed. Then inside setcontent call the composable function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ViewCompositionStrategy that disposes the composition when the ViewTreeLifecycleOwner of the next window the view is attached to is destroyed.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here, I have defined a lamda for item click to navigate to&lt;br&gt;
 PhotoFullScreen and passed it to the composable function as an argument. Also passed the ViewModel(PhotoViewModel) to access the data(photos).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;---&amp;gt;&lt;/strong&gt;&lt;br&gt;
  It's a good idea to start with small parts of your app and gradually convert more and more of it to Compose.That would be all for this article, I hope you liked it!&lt;br&gt;
&lt;strong&gt;N.B. You may find Jetpack Compose app laggy in debug mode.&lt;/strong&gt; &lt;a href="https://medium.com/androiddevelopers/why-should-you-always-test-compose-performance-in-release-4168dd0f2c71"&gt;You should always test Compose performance in release.&lt;/a&gt;&lt;br&gt;
The full code with detailed implementation can be found on GitHub. Checkout the &lt;a href="https://github.com/jhnaiem/UnsplashPhotos/tree/to-JetpackCompose"&gt;to-JetpackCompose&lt;/a&gt; branch:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/jhnaiem"&gt;
        jhnaiem
      &lt;/a&gt; / &lt;a href="https://github.com/jhnaiem/UnsplashPhotos"&gt;
        UnsplashPhotos
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      An android app that displays a list of photos as a gallery.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
UnsplashPhotos&lt;/h1&gt;

&lt;h2&gt;
&lt;em&gt;An android app that displays a list of photos as a gallery.&lt;/em&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/jhnaiem/UnsplashPhotos/blob/develop/Mockup/ezgif.com-gif-maker.gif"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zy7NGwvV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jhnaiem/UnsplashPhotos/raw/develop/Mockup/ezgif.com-gif-maker.gif" width="280" height="500"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
Feature List&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Get a list of photos from “&lt;a href="https://api.unsplash.com/%E2%80%9D" rel="nofollow"&gt;https://api.unsplash.com/”&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A user can infinitely scroll on the gallery screen&lt;/li&gt;
&lt;li&gt;A user can tap on a photo to see a full-screen photo&lt;/li&gt;
&lt;li&gt;The app’s flavor/scheme can be changed easily from development API to production API&lt;/li&gt;
&lt;li&gt;Caching images&lt;/li&gt;
&lt;li&gt;Caching API response&lt;/li&gt;
&lt;li&gt;Saving photos in JPEG format to the local gallery&lt;/li&gt;
&lt;li&gt;Sharing the photo&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
The architectural pattern used in the app&lt;/h2&gt;
&lt;p&gt;In this app, I have adopted Clean architecture with MVVM. According to clean architecture, I have divided the code into three layers:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Presentation/UI layer&lt;/li&gt;
&lt;li&gt;Domain layer&lt;/li&gt;
&lt;li&gt;Data Layer&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;a href="https://medium.com/huawei-developers/android-clean-app-base-library-clean-architecture-mvvm-part-i-e8614978877f" rel="nofollow"&gt;
   &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P7hcTyb_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/jhnaiem/UnsplashPhotos/raw/develop/Mockup/1_uQYJsu2agzmjp9s_eEieeA.png" width="400" height="250"&gt;
&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt; The Clean Code Blog by Robert C.Martin (Uncle Bob)&lt;/p&gt;

&lt;h3&gt;
1. Domain layer&lt;/h3&gt;

&lt;p&gt;This is the center of Clean Architecture. It establishes communication between the data and the Presentation layer. This layer contains a Domain model and repository( interface). We can see…&lt;/p&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/jhnaiem/UnsplashPhotos"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.android.com/jetpack/compose/interop"&gt;https://developer.android.com/jetpack/compose/interop&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.android.com/jetpack/compose/interop/interop-apis"&gt;https://developer.android.com/jetpack/compose/interop/interop-apis&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>jetpackcompose</category>
      <category>tutorial</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
