<?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 Aditya on Medium]]></title>
        <description><![CDATA[Stories by Aditya on Medium]]></description>
        <link>https://medium.com/@tiadiaditya?source=rss-1210f92ea427------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Aj08Kvm5TwnniaJY</url>
            <title>Stories by Aditya on Medium</title>
            <link>https://medium.com/@tiadiaditya?source=rss-1210f92ea427------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 00:17:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tiadiaditya/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[Migrating Your Production App from XML to Jetpack Compose — A Real-World Guide: Part 2]]></title>
            <link>https://tiadiaditya.medium.com/migrating-your-production-app-from-xml-to-jetpack-compose-a-real-world-guide-part-2-0f500ad9ced8?source=rss-1210f92ea427------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f500ad9ced8</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Aditya]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 07:40:54 GMT</pubDate>
            <atom:updated>2025-07-31T07:40:54.097Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sucLy9_gLZVxt2BOMCu6Tw.png" /><figcaption>Migartion from XML to Compose</figcaption></figure><h3>Migrating Your Production App from XML to Jetpack Compose — A Real-World Guide: Part 2</h3><p><em>“In Part 1, we explored the migration overview. Now it’s time to roll up our sleeves and compare XML vs Jetpack Compose hands-on, with actual examples, fragments, adapters, and all the spicy bits.”</em></p><p>Welcome to Part 2 of our series on migrating a production app from XML to Jetpack Compose. In the first part, we discussed the overall roadmap, setup, themes, and strategic migration steps. If that was the <strong>theory</strong>, this is the <strong>lab work</strong> — complete with practical comparisons between XML and Compose, and detailed explanations of core concepts.</p><p>Whether you’re still half-and-half or already deep into Compose territory, this guide will help you bridge the gap between legacy views and modern declarative UI.</p><h3>Fragment to Compose — The Hybrid Era</h3><blockquote>Let’s see a simple example where we will convert one Listscreen into Compose in Hybrid way <br>So in the below code we have fragment_course_list<strong>.xml</strong>, CourseListFragment<strong>.kt</strong>, CourseAdapter<strong>.kt</strong></blockquote><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:id=&quot;@+id/course_list_root&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:orientation=&quot;vertical&quot;<br>    android:padding=&quot;8dp&quot;&gt;<br><br>    &lt;androidx.recyclerview.widget.RecyclerView<br>        android:id=&quot;@+id/recyclerView&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:clipToPadding=&quot;false&quot;<br>        android:paddingBottom=&quot;8dp&quot; /&gt;<br>&lt;/LinearLayout&gt;</pre><pre>@AndroidEntryPoint<br>class CourseListFragment : Fragment() {<br>    private var _binding: FragmentCourseListBinding? = null<br>    private val binding get() = _binding!!<br><br>    private val viewModel: CourseViewModel by viewModels()<br>    private lateinit var adapter: CourseAdapter<br><br>    override fun onCreateView(<br>        inflater: LayoutInflater, container: ViewGroup?,<br>        savedInstanceState: Bundle?<br>    ): View {<br>        _binding = FragmentCourseListBinding.inflate(inflater, container, false)<br>        return binding.root<br>    }<br><br>    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {<br>        adapter = CourseAdapter { course -&gt;<br>            val action = CourseListFragmentDirections<br>                .actionCourseListToDetail(course.title, course.description)<br>            findNavController().navigate(action)<br>        }<br><br>        binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())<br>        binding.recyclerView.adapter = adapter<br><br>        viewModel.courseList.observe(viewLifecycleOwner) {<br>            adapter.submitList(it)<br>        }<br>    }<br><br>    override fun onDestroyView() {<br>        super.onDestroyView()<br>        _binding = null<br>    }<br>}</pre><pre>class CourseAdapter(private val onClick: (Course) -&gt; Unit) :<br>    ListAdapter&lt;Course, CourseAdapter.CourseViewHolder&gt;(DiffCallback()) {<br><br>    inner class CourseViewHolder(private val binding: ItemCourseBinding) :<br>        RecyclerView.ViewHolder(binding.root) {<br>        fun bind(course: Course) {<br>            binding.courseTitle.text = course.title<br>            binding.courseDesc.text = course.description<br>            binding.root.setOnClickListener { onClick(course) }<br>        }<br>    }<br><br>    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CourseViewHolder {<br>        val binding = ItemCourseBinding.inflate(LayoutInflater.from(parent.context), parent, false)<br>        return CourseViewHolder(binding)<br>    }<br><br>    override fun onBindViewHolder(holder: CourseViewHolder, position: Int) {<br>        holder.bind(getItem(position))<br>    }<br><br>    class DiffCallback : DiffUtil.ItemCallback&lt;Course&gt;() {<br>        override fun areItemsTheSame(old: Course, new: Course) = old.title == new.title<br>        override fun areContentsTheSame(old: Course, new: Course) = old == new<br>    }<br>}</pre><blockquote>For Converting into Jetpack compose in Hybrid Stage. We’ll create CourseListScreen<strong>.kt</strong>, CourseCard.kt(instead of item_course<strong>.xml</strong>). and Preview of CourseListScreen<strong>.kt</strong></blockquote><pre>//presentation/screens/courselist/CourseListScreen.kt<br><br>@Composable<br>fun CourseListScreen(<br>    courses: List&lt;Course&gt;,<br>    onCourseClick: (Course) -&gt; Unit<br>) {<br>    Surface(modifier = Modifier.fillMaxSize()) {<br>        LazyColumn(modifier = Modifier.padding(16.dp)) {<br>            items(courses) { course -&gt;<br>                CourseItem(course = course, onClick = { onCourseClick(course) })<br>            }<br>        }<br>    }<br>}<br><br><br>@Preview<br>@Composable<br>fun CourseListScreenPreview() {<br>    val sampleCourses = listOf(<br>        Course(&quot;Course 1&quot;, &quot;Description of Course 1&quot;),<br>        Course(&quot;Course 2&quot;, &quot;Description of Course 2&quot;),<br>        Course(&quot;Course 3&quot;, &quot;Description of Course 3&quot;)<br>    )<br><br>    CourseListScreen(courses = sampleCourses, onCourseClick = {})<br>}</pre><blockquote>If you are following <strong>clean architechture</strong> then you have keep these files under presentation layer eg. <strong>presentation/screens/courselist/CourseListScreen.kt</strong></blockquote><pre>//presentation/screens/courselist/components/CourseItem.kt<br><br>@Composable<br>fun CourseItem(course: Course, onClick: () -&gt; Unit) {<br>    Card(<br>        modifier = Modifier<br>            .fillMaxWidth()<br>            .padding(vertical = 8.dp)<br>            .clickable { onClick() }<br>    ) {<br>        Column(modifier = Modifier.padding(16.dp)) {<br>            Text(text = course.title, style = MaterialTheme.typography.titleMedium)<br>            Spacer(modifier = Modifier.height(4.dp))<br>            Text(text = course.description, style = MaterialTheme.typography.bodyMedium)<br>        }<br>    }<br>}</pre><blockquote>Now Our presentation layer is ready, it’s time to include these screens in CourseListFragment.kt</blockquote><pre>@AndroidEntryPoint<br>class CourseListFragment : Fragment() {<br>    private val viewModel: CourseViewModel by viewModels()<br><br>    override fun onCreateView(<br>        inflater: LayoutInflater, container: ViewGroup?,<br>        savedInstanceState: Bundle?<br>    ): View {<br>        return ComposeView(requireContext()).apply {<br>            setContent {<br>                val courses = viewModel.courseList.value<br>                courses?.let {<br>                    CourseListScreen(<br>                        courses = courses,<br>                        onCourseClick = { selectedCourse -&gt;<br>                            val action = CourseListFragmentDirections.actionCourseListToDetail(<br>                                selectedCourse.title,<br>                                selectedCourse.description<br>                            )<br>                            findNavController().navigate(action)<br>                        }<br>                    )<br>                }<br>            }<br>        }<br>    }<br>}</pre><blockquote><strong>Note:</strong> If you’re currently using LiveData, it&#39;s advisable to delay migrating to StateFlow until all your screens have been converted to Jetpack Compose. Since your ViewModel is shared across multiple parts of the app, changing it prematurely would require updating all the dependent components, leading to unnecessary overhead during the transition.</blockquote><blockquote>A simple example how you can change from LiveData to StateFlow</blockquote><pre>//Viewmodel.kt<br>private val _courses = MutableLiveData&lt;List&lt;Course&gt;&gt;()<br>val courses: LiveData&lt;List&lt;Course&gt;&gt; = _courses<br><br>//Using somewhere inside Fragment.kt<br>val courses by courseViewModel.batches.observeAsState(emptyList())</pre><pre>//Change to this in Viewmodel.kt   <br>private val _courses = MutableStateFlow&lt;List&lt;Course&gt;&gt;(emptyList())<br>val courses: StateFlow&lt;List&lt;Course&gt;&gt; = _courses<br><br>//Change this line also in Fragment.kt<br>val batches by viewModel.batches.collectAsState()</pre><blockquote>Now it’s time to work on NavigationComponent to NavHost. Initially you NavComponent( Nav_graph.xml )might looks like this. before this you have add navigationcompose dependency in build.gradle.kts that I have explained in <a href="https://medium.com/@tiadiaditya/migrating-your-production-app-from-xml-to-jetpack-compose-a-real-world-guide-ab289f760e2d">Part 1</a></blockquote><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;navigation 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:id=&quot;@+id/nav_graph&quot;<br>    app:startDestination=&quot;@id/courseListFragment&quot;&gt;<br><br>    &lt;fragment<br>        android:id=&quot;@+id/courseListFragment&quot;<br>        android:name=&quot;com.example.xmltocompose.fragments.CourseListFragment&quot;<br>        android:label=&quot;Courses&quot;&gt;<br>        &lt;action<br>            android:id=&quot;@+id/action_courseList_to_detail&quot;<br>            app:destination=&quot;@id/courseDetailFragment&quot; /&gt;<br>    &lt;/fragment&gt;<br><br>    &lt;fragment<br>        android:id=&quot;@+id/courseDetailFragment&quot;<br>        android:name=&quot;com.example.xmltocompose.fragments.CourseDetailFragment&quot;<br>        android:label=&quot;Course Detail&quot; &gt;<br>        &lt;argument<br>            android:name=&quot;title&quot;<br>            app:argType=&quot;string&quot; /&gt;<br>        &lt;argument<br>            android:name=&quot;description&quot;<br>            app:argType=&quot;string&quot; /&gt;<br>    &lt;/fragment&gt;<br><br>    &lt;fragment<br>        android:id=&quot;@+id/aboutFragment&quot;<br>        android:name=&quot;com.example.xmltocompose.fragments.AboutFragment&quot;<br>        android:label=&quot;About&quot; /&gt;<br><br>&lt;/navigation&gt;</pre><blockquote>Now can Create NavigationHelper, NavHost and compare this nav_graph.xml with NavHost</blockquote><pre>//Navigation Helper <br>sealed class Screen(val route: String) {<br>    object CourseList : Screen(&quot;course_list&quot;)<br>    object CourseDetail : Screen(&quot;course_detail/{title}/{description}&quot;) {<br>        fun createRoute(title: String, description: String): String =<br>            &quot;course_detail/${Uri.encode(title)}/${Uri.encode(description)}&quot;<br>    }<br>    object About : Screen(&quot;about&quot;)<br>}</pre><pre><br>//NavHost.kt<br>@Composable<br>fun CourseNavHost(<br>    modifier: Modifier = Modifier,<br>    navController: NavHostController = rememberNavController(),<br>    startDestination: String = Screen.CourseList.route<br>) {<br>    NavHost(<br>        navController = navController,<br>        startDestination = startDestination,<br>        modifier = modifier<br>    ) {<br>        // Course List Screen<br>        composable(route = Screen.CourseList.route) {<br>            CourseListScreen(navController = navController)<br>        }<br><br>        // Course Detail Screen<br>        composable(<br>            route = Screen.CourseDetail.route,<br>            arguments = listOf(<br>                navArgument(&quot;title&quot;) { type = NavType.StringType },<br>                navArgument(&quot;description&quot;) { type = NavType.StringType }<br>            )<br>        ) { backStackEntry -&gt;<br>            val title = backStackEntry.arguments?.getString(&quot;title&quot;) ?: &quot;No Title&quot;<br>            val description = backStackEntry.arguments?.getString(&quot;description&quot;) ?: &quot;No Description&quot;<br>            CourseDetailScreen(title = title, description = description)<br>        }<br><br>        // About Screen<br>        composable(route = Screen.About.route) {<br>            AboutScreen()<br>        }<br>    }<br>}</pre><blockquote><strong>Last and Final Step:</strong> Now According to this you have to change in CourseListScreen<strong>.kt, </strong>so that you can remove complete CourseListFragment<strong>.kt, </strong>now you can also remove the nav_graph<strong>.xml.</strong></blockquote><pre>@Composable<br>fun CourseListScreen(<br>    navController: NavController,<br>    viewModel: CourseViewModel = hiltViewModel()<br>) {<br>    val courses by viewModel.courseList.collectAsState()<br><br>    Surface(modifier = Modifier.fillMaxSize()) {<br>        courses?.let {<br>            LazyColumn(modifier = Modifier.padding(16.dp)) {<br>                items(it) { course -&gt;<br>                    CourseItem(course = course, onClick = {<br>                        navController.navigate(<br>                            Screen.CourseDetail.createRoute(<br>                                title = course.title,<br>                                description = course.description<br>                            )<br>                        )<br>                    })<br>                }<br>            }<br>        } ?: Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {<br>            CircularProgressIndicator()<br>        }<br>    }<br>}</pre><p>🎉 Boom! You’ve just leveled up by migrating an entire screen from XML to Jetpack Compose. Likewise you can complete one by one screen in production level app.<br>you can see this example I have two branch one is XML and Hybrid and soon i will migrate fully to Jetpack compose.</p><p><a href="https://github.com/Aditya3815/XMLtoCompose">https://github.com/Aditya3815/XMLtoCompose</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f500ad9ced8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating Your Production App from XML to Jetpack Compose — A Real-World Guide]]></title>
            <link>https://tiadiaditya.medium.com/migrating-your-production-app-from-xml-to-jetpack-compose-a-real-world-guide-ab289f760e2d?source=rss-1210f92ea427------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab289f760e2d</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[xml]]></category>
            <dc:creator><![CDATA[Aditya]]></dc:creator>
            <pubDate>Sun, 27 Jul 2025 11:47:56 GMT</pubDate>
            <atom:updated>2025-07-31T07:49:37.223Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sucLy9_gLZVxt2BOMCu6Tw.png" /><figcaption>Migartion from XML to Compose</figcaption></figure><h3>Migrating Your Production App from XML to Jetpack Compose — A Real-World Guide: Part 1</h3><p><em>“Breaking up with XML in a 15-screen production app is kind of like finally giving up on your 2010 hairstyle — scary but necessary.”</em></p><p>If you’ve been dreading the migration from traditional XML layouts to Jetpack Compose for a large production app, trust me, you’re not alone. Between dependency injection, multiple ViewModels, RecyclerView adapters, menus, and that monster of a navigation drawer — it’s a minefield.</p><p>But breathe easy. I recently walked this path and distilled the process into a clean, step-by-step migration plan.</p><p>Let’s dive in.</p><h3>Step 0: Compose Setup — The Bare Minimum</h3><blockquote>Before migrating a single screen, make sure your project is ready to support Compose.</blockquote><p>1. build.gradle(:app) updates:</p><pre>android {<br>    buildFeatures {<br>        compose = true<br>    }<br>    compileOptions {<br>        sourceCompatibility = JavaVersion.VERSION_11<br>        targetCompatibility = JavaVersion.VERSION_11<br>    }<br>}</pre><p>2. Dependencies (Using libs.versions.toml)</p><blockquote>Add the following libraries and versions:<br>Note: You can also use the updated version</blockquote><pre>[versions]<br>lifecycleRuntimeKtx = &quot;2.9.2&quot;<br>activityCompose = &quot;1.10.1&quot;<br>composeBom = &quot;2024.09.00&quot;<br>materialIconsExtended = &quot;1.7.8&quot;<br>navigationCompose = &quot;2.9.2&quot;<br><br>[libraries]<br>androidx-activity-compose = { group = &quot;androidx.activity&quot;, name = &quot;activity-compose&quot;, version.ref = &quot;activityCompose&quot; }<br>androidx-compose-bom = { group = &quot;androidx.compose&quot;, name = &quot;compose-bom&quot;, version.ref = &quot;composeBom&quot; }<br>androidx-ui = { group = &quot;androidx.compose.ui&quot;, name = &quot;ui&quot; }<br>androidx-ui-graphics = { group = &quot;androidx.compose.ui&quot;, name = &quot;ui-graphics&quot; }<br>androidx-ui-tooling = { group = &quot;androidx.compose.ui&quot;, name = &quot;ui-tooling&quot; }<br>androidx-ui-tooling-preview = { group = &quot;androidx.compose.ui&quot;, name = &quot;ui-tooling-preview&quot; }<br>androidx-ui-test-manifest = { group = &quot;androidx.compose.ui&quot;, name = &quot;ui-test-manifest&quot; }<br>material-icons-extended = { group = &quot;androidx.compose.material&quot;, name = &quot;material-icons-extended&quot;, version.ref = &quot;materialIconsExtended&quot; }<br>androidx-navigation-compose = { module = &quot;androidx.navigation:navigation-compose&quot;, version.ref = &quot;navigationCompose&quot; }</pre><h3>Step 1: Migrate Recyclerviews ➜ LazyColumn</h3><blockquote>If you’re still writing XML ViewHolders with Adapter, now’s the time to let go. Compose’s LazyColumn (and LazyVerticalGrid) are your new best friends. Instead of inflating XML layouts in an adapter, define a Composable item like this:</blockquote><pre>@Composable<br>fun UserItem(user: User, onClick: () -&gt; Unit) {<br>    Row(modifier = Modifier.clickable { onClick() }) {<br>        Text(user.name)<br>    }<br>}</pre><blockquote>And display it in a list:</blockquote><pre>LazyColumn {<br>    items(users) { user -&gt;<br>        UserItem(user = user, onClick = { /* Handle click */ })<br>    }<br>}</pre><h3>Step 2: Convert Simple Screens</h3><blockquote>Start with screens that don’t depend on heavily on Viewmodels and mostly don’t depend on tons of logic</blockquote><pre>@Composable<br>fun WelcomeScreen() {<br>    Column(modifier = Modifier.padding(16.dp)) {<br>        Text(&quot;Welcome to Jetpack Compose&quot;)<br>        Button(onClick = { /* navigate */ }) {<br>            Text(&quot;Continue&quot;)<br>        }<br>    }<br>}</pre><blockquote>Don’t forget @Preview!</blockquote><pre>@Preview(showBackground = true)<br>@Composable<br>fun WelcomeScreenPreview() {<br>    WelcomeScreen()<br>}</pre><h3>Step 3: Replace Navigation XML with Compose Navigation</h3><p>Here comes the big one: migrating your navigation graph.</p><pre>NavHost(navController, startDestination = &quot;home&quot;) {<br>    composable(&quot;home&quot;) { HomeScreen() }<br>    composable(&quot;details/{id}&quot;) { backStackEntry -&gt;<br>        DetailsScreen(id = backStackEntry.arguments?.getString(&quot;id&quot;))<br>    }<br>}</pre><blockquote><strong>Pro tip</strong>: Use hiltViewModel() inside Composables to scope ViewModels properly</blockquote><pre>val viewModel: MyViewModel = hiltViewModel()</pre><h3>Step 4: ViewModel, Repository, and DI (Hilt)</h3><blockquote>Your ViewModels won’t need much change — just inject them as usual, and collect state using<br>Use state hoisting for callbacks and events to keep Composables stateless.</blockquote><pre>val uiState by viewModel.stateFlow.collectAsState()</pre><h3>Step 5: Drawer, Menus, and TopAppBar</h3><p>Replace your old DrawerLayout and AppBar with Compose’s Scaffold:</p><pre>Scaffold(<br>    topBar = {<br>        TopAppBar(title = { Text(&quot;Dashboard&quot;) })<br>    },<br>    drawerContent = {<br>        DrawerContent()<br>    }<br>) {<br>    Content()<br>}</pre><blockquote>Use <em>ModalNavigationDrawer</em> and <em>DrawerState</em> for fancier behavior.</blockquote><p>Hurray! you have a overview that how we can migrate a Screen 🎉<br>Now Let’s Challenge Yourself and complete this below</p><blockquote><a href="https://github.com/Aditya3815/XMLtoCompose">XML to Compose Half-migrated</a></blockquote><p>Also you can checkout <a href="https://medium.com/@tiadiaditya/migrating-your-production-app-from-xml-to-jetpack-compose-a-real-world-guide-part-2-0f500ad9ced8">Part 2</a>, where we fully migrated Screen with NavHost in Jetpack compose</p><p>This project is partially migrated, making it a great example to understand how XML and Jetpack Compose can work together during a transition phase — yes, they can coexist peacefully!</p><p>Thank you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab289f760e2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>