<?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 Anna Alekseyevich on Medium]]></title>
        <description><![CDATA[Stories by Anna Alekseyevich on Medium]]></description>
        <link>https://medium.com/@annaalekseyevich?source=rss-6b6791974781------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*L4SBooZ_LFJDoIwByqGq8w.jpeg</url>
            <title>Stories by Anna Alekseyevich on Medium</title>
            <link>https://medium.com/@annaalekseyevich?source=rss-6b6791974781------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:50:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@annaalekseyevich/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[How to Build an AI Agent in Kotlin for Your Android App Using Koog]]></title>
            <link>https://medium.com/@annaalekseyevich/how-to-build-an-ai-agent-in-kotlin-for-your-android-app-using-koog-433645cbfc92?source=rss-6b6791974781------2</link>
            <guid isPermaLink="false">https://medium.com/p/433645cbfc92</guid>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[books]]></category>
            <dc:creator><![CDATA[Anna Alekseyevich]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 22:01:22 GMT</pubDate>
            <atom:updated>2025-11-30T22:01:22.689Z</atom:updated>
            <content:encoded><![CDATA[<p>As AI becomes a natural part of modern applications, integrating intelligent features directly into Android apps is no longer optional — it’s a competitive advantage.<br> In this article, we’ll build a simple Android application enhanced with an AI agent. The agent will describe books and recommend similar ones using LLMs (Large Language Models).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p4bTVxA2hSdyzTL9ULG_JA.png" /></figure><p>We’ll use <strong>Koog</strong>, a powerful AI toolkit developed by JetBrains that simplifies working with LLMs in Kotlin.</p><p>Our final result will look like this:</p><ul><li>User enters a book title</li><li>The app fetches metadata using Google Books API</li><li>The AI Agent uses this metadata to generate:<br> - a short book description,<br> -3–5 similar book recommendations.</li></ul><p>Let’s get started.</p><p>The project’s structure will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MudN0NbCC7dJTSKfDoI3Gw.png" /></figure><ol><li>First of all, we have to add dependencies in your libs.versions.toml:</li></ol><pre>[versions]<br>kotlin = &quot;2.2.0&quot;<br>koog = &quot;0.5.0&quot;<br><br>[libraries]<br>koog-agents = { group = &quot;ai.koog&quot;, name = &quot;koog-agents-jvm&quot;, version.ref = &quot;koog&quot; }<br><br>[plugins]<br>kotlin-serialization = { id = &quot;org.jetbrains.kotlin.plugin.serialization&quot;, version.ref = &quot;kotlin&quot; }</pre><p>2. In your BookRepositoryContractImpl, add a function that builds an instance of AIAgent:</p><pre>private fun createAgent(): AIAgent&lt;String, String&gt; {<br>        return AIAgent(<br>            promptExecutor = KoogExecutorProvider.provide(openAiApiKey),<br>            llmModel = OpenAIModels.Chat.GPT5,<br>            systemPrompt = &quot;You are an intelligent literary assistant. Provide concise descriptions and recommend similar books.&quot;<br>        )<br>    }</pre><p>Here’s what happens:</p><ul><li>systemPrompt defines the agent’s behavior (tone, style, role).</li><li>Every request you send becomes a <strong>user prompt</strong>.</li><li>Koog handles execution and response parsing automatically.</li></ul><p>3. Adding Prompts and Business Logic.</p><p>Describe a book using metadata:</p><pre>override suspend fun describeBook(title: String): String {<br><br>    val googleRes = googleApi.searchVolumes(title)<br>    val meta = googleRes.items?.firstOrNull()?.volumeInfo?.description ?: &quot;&quot;<br><br>    val prompt =<br>        &quot;Describe the book titled \&quot;$title\&quot;.\nIf you know metadata: $meta\nKeep answer concise (2-4 sentences).&quot;<br><br>    val agent = createAgent()<br>    return agent.run(prompt)<br>}</pre><p>Suggest similar books:</p><pre>override suspend fun suggestSimilarBooks(title: String): String = withContext(Dispatchers.IO) {<br>    val prompt =<br>        &quot;Suggest 3–5 books similar to \&quot;$title\&quot; and explain briefly why each is similar. Provide titles and 1-line reasons.&quot;<br>    val agent = createAgent()<br>    agent.run(prompt)<br>}</pre><p>You can find the full code in BookRepositoryContractImpl.</p><p>4. UI Layer.</p><p>Below is the simplified version of the UI screen based on Compose.<br>The user enters a title → taps a button → result appears in a pager.</p><pre>@Composable<br>fun MainScreen(viewModel: BookViewModel = hiltViewModel()) {<br>    val describeResponse by viewModel.describeResponse.collectAsState()<br>    val similarResponse by viewModel.similarResponse.collectAsState()<br>    val isLoading by viewModel.isLoading.collectAsState()<br>    val scope = rememberCoroutineScope()<br><br>    var title by remember { mutableStateOf(&quot;&quot;) }<br>    val pagerState = rememberPagerState(<br>        initialPage = 0,<br>        pageCount = { 2 },<br>    )<br><br>    Scaffold(<br>        topBar = { TopAppBar(title = { Text(stringResource(R.string.app_bar_title)) }) }<br>    ) { padding -&gt;<br>        Column(<br>            modifier = Modifier<br>                .fillMaxSize()<br>                .padding(padding)<br>                .padding(16.dp),<br>            verticalArrangement = Arrangement.spacedBy(12.dp)<br>        ) {<br><br>            OutlinedTextField(<br>                value = title,<br>                onValueChange = { title = it },<br>                label = { Text(stringResource(R.string.input_hint)) },<br>                modifier = Modifier.fillMaxWidth()<br>            )<br><br>            Row(<br>                modifier = Modifier.fillMaxWidth(),<br>                horizontalArrangement = Arrangement.spacedBy(8.dp)<br>            ) {<br>                Button(<br>                    onClick = {<br>                        viewModel.describeBook(title)<br>                        scope.launch {<br>                            pagerState.animateScrollToPage(<br>                                page = 0,<br>                                animationSpec = tween(ANIMATION_DURATION),<br>                            )<br>                        }<br>                    },<br>                    modifier = Modifier.weight(1f),<br>                    enabled = !isLoading<br>                ) {<br>                    Text(stringResource(R.string.describe_btn))<br>                }<br><br>                Button(<br>                    onClick = {<br>                        viewModel.findSimilarBooks(title)<br>                        scope.launch {<br>                            pagerState.animateScrollToPage(<br>                                page = 1,<br>                                animationSpec = tween(ANIMATION_DURATION),<br>                            )<br>                        }<br>                    },<br>                    modifier = Modifier.weight(1f),<br>                    enabled = !isLoading<br>                ) {<br>                    Text(stringResource(R.string.similar_btn))<br>                }<br>            }<br><br>            if (isLoading) {<br>                LinearProgressIndicator(modifier = Modifier.fillMaxWidth())<br>            }<br><br>            Box(<br>                modifier = Modifier<br>                    .fillMaxWidth()<br>                    .weight(1f)<br>            ) {<br>                HorizontalPager(<br>                    state = pagerState,<br>                    modifier = Modifier.fillMaxSize()<br>                ) { page -&gt;<br>                    when (page) {<br>                        0 -&gt; ResponseCardScrollable(<br>                            title = stringResource(R.string.describe_title),<br>                            text = describeResponse<br>                        )<br>                        1 -&gt; ResponseCardScrollable(<br>                            title = stringResource(R.string.similar_title),<br>                            text = similarResponse<br>                        )<br>                    }<br>                }<br>            }<br>        }<br>    }<br>}<br><br>@Composable<br>fun ResponseCardScrollable(title: String, text: String) {<br>    val verticalScrollState = rememberScrollState()<br><br>    Card(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .verticalScroll(verticalScrollState)<br>            .padding(4.dp)<br>    ) {<br>        Column(modifier = Modifier.padding(16.dp)) {<br>            Text(<br>                title,<br>                style = MaterialTheme.typography.titleMedium,<br>                fontWeight = FontWeight.Bold<br>            )<br>            Spacer(modifier = Modifier.height(8.dp))<br>            Text(<br>                text = text.ifBlank { stringResource(R.string.no_response_title) },<br>                style = MaterialTheme.typography.bodyMedium<br>            )<br>        }<br>    }<br>}</pre><p>You will see such UI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*BOnTBp2eKlVmL_RbgHnOKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*leFtNx5rL4N5gjGT50u7oQ.png" /><figcaption>Example of description for Kotlin book according to the google response with Agent AI and providing by Agent AI similar suggestions.</figcaption></figure><p>This UI is intentionally minimal. Its goal is to demonstrate how easy it is to integrate LLM responses into a Compose layout.</p><p>5. ViewModel Layer<br>Here we handle:</p><ul><li>loading state,</li><li>error handling,</li><li>triggering use cases.</li></ul><pre>@HiltViewModel<br>class BookViewModel @Inject constructor(<br>    private val describeBookUseCase: DescribeBookUseCase,<br>    private val suggestSimilarBooksUseCase: SuggestSimilarBooksUseCase,<br>) : ViewModel() {<br><br>    private val _response = MutableStateFlow(&quot;&quot;)<br><br>    private val _isLoading = MutableStateFlow(false)<br>    val isLoading: StateFlow&lt;Boolean&gt; = _isLoading<br><br>    private val _describeResponse = MutableStateFlow(&quot;&quot;)<br>    val describeResponse: StateFlow&lt;String&gt; = _describeResponse<br><br>    private val _similarResponse = MutableStateFlow(&quot;&quot;)<br>    val similarResponse: StateFlow&lt;String&gt; = _similarResponse<br><br>    fun describeBook(title: String) {<br>        if (title.isBlank()) return<br>        viewModelScope.launch {<br>            _isLoading.value = true<br>            _response.value = &quot;Thinking...&quot;<br>            try {<br>                val result = describeBookUseCase(title)<br>                _response.value = result<br>                _describeResponse.value = result<br>            } catch (e: Exception) {<br>                _response.value = &quot;Error: ${e.message}&quot;<br>                _describeResponse.value = &quot;Error: ${e.message}&quot;<br>            } finally {<br>                _isLoading.value = false<br>            }<br>        }<br>    }<br><br>    fun findSimilarBooks(title: String) {<br>        if (title.isBlank()) return<br>        viewModelScope.launch {<br>            _isLoading.value = true<br>            _response.value = &quot;Thinking...&quot;<br>            try {<br>                val result = suggestSimilarBooksUseCase(title)<br>                _similarResponse.value = result<br>                _response.value = result<br>            } catch (e: Exception) {<br>                _response.value = &quot;Error: ${e.message}&quot;<br>                _similarResponse.value = &quot;Error: ${e.message}&quot;<br>            } finally {<br>                _isLoading.value = false<br>            }<br>        }<br>    }<br>}</pre><p>6. Generating an API Key</p><p>To use Koog with OpenAI (or any LLM provider you choose), you’ll need to generate an API key.<br> If you’re using OpenAI, you can create one directly in your dashboard.</p><p>Koog does not require any additional setup beyond providing your API key, which makes experimenting with agents extremely straightforward. If you’re using OpenAI or any other LLM provider, never hardcode your key — store it securely.</p><p>Useful guides:<br><a href="https://medium.com/@artsemkurantsou/secrets-in-android-part-1-fe04decc9d3a">https://medium.com/@artsemkurantsou/secrets-in-android-part-1-fe04decc9d3a</a> and <a href="https://medium.com/@artsemkurantsou/secrets-in-android-part-2-64e3872f41f5.">https://medium.com/@artsemkurantsou/secrets-in-android-part-2-64e3872f41f5.</a></p><p>7. More Ideas for AI-Powered Features</p><p>Once you have an AI Agent integrated into your Android app, there are many directions in which you can extend the project. A few examples:</p><p>• Genre-based recommendations.<br>• Book discovery by mood<br>• Personalized reading path<br>• Book-to-movie or book-to-author recommendations<br>• Voice-based queries<br>• Reading assistant / companion mode</p><p>With just a few lines of code, we integrated a fully functional AI agent into an Android app. Koog makes prompt execution simple, and LLMs enable powerful features like book summaries and recommendations.</p><p>You can now extend this project by adding:</p><ul><li>streaming responses,</li><li>caching prompts,</li><li>multiple agent profiles,</li><li>local LLMs (GGUF + Kotlin inference),</li><li>multimodal support.</li></ul><p>The full source code is available here:</p><p>You can find the entire code in this repository <a href="https://github.com/AnnaAlekseevich/LitLens">https://github.com/AnnaAlekseevich/LitLens</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=433645cbfc92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DeepLinks with Type-Safe Navigation Compose APIs with stack screen handlings]]></title>
            <link>https://medium.com/@annaalekseyevich/deeplinks-with-type-safe-navigation-compose-apis-with-stack-screen-handlings-4e85efdc5fc5?source=rss-6b6791974781------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e85efdc5fc5</guid>
            <category><![CDATA[deeplink]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Anna Alekseyevich]]></dc:creator>
            <pubDate>Thu, 20 Feb 2025 21:46:36 GMT</pubDate>
            <atom:updated>2025-02-20T21:46:36.668Z</atom:updated>
            <content:encoded><![CDATA[<p>While working with the <strong>compose-navigation</strong> library (v2.8.7), I needed a way to preserve the screen stack when handling deep links. To solve this, I built an example app featuring a <strong>BottomNavigation Bar</strong> with three tabs and a <strong>BottomSheet screen</strong>, which can also be opened via a deep link.</p><p>Each tab has its own <strong>NavController</strong> and a corresponding <strong>NavHost</strong> to manage its navigation stack independently. For more details on how to set up deep links in an Android app, refer to the <a href="https://developer.android.com/develop/ui/compose/navigation#deeplinks">official documentation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nxUtnCExyKOnvKm_szzWw.png" /><figcaption>Illustration generated using ChatGPT.</figcaption></figure><p>The MainAppContentScreen is the core of our navigation setup. It manages multiple NavController instances, deep link handling, and back navigation logic. Here is the MainAppContentScreen content:</p><pre>@Composable<br>fun MainAppContentScreen() {<br>    val blogNavController = rememberNavController()<br>    val postsNavController = rememberNavController()<br>    val profileNavController = rememberNavController()<br><br>    val selectedTab = remember { mutableStateOf&lt;Any&gt;(Blog) }<br>    val tabBackStack = remember { mutableStateListOf&lt;Any&gt;() }<br>    val context = LocalContext.current<br><br>    val adaptiveInfo = currentWindowAdaptiveInfo()<br>    val customNavSuiteType = with(adaptiveInfo) {<br>        if (windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED) {<br>            NavigationSuiteType.NavigationDrawer<br>        } else {<br>            NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(adaptiveInfo)<br>        }<br>    }<br><br>    HandleBackPress(selectedTab, tabBackStack, blogNavController, postsNavController, profileNavController, context)<br>    HandleDeepLinks(context, selectedTab, tabBackStack, profileNavController)<br><br>    Scaffold(<br>        topBar = {},<br>        contentWindowInsets = WindowInsets(top = 0.dp, bottom = 0.dp),<br>    ) { padding -&gt;<br>        NavigationSuiteScaffold(<br>            modifier = Modifier.padding(padding),<br>            layoutType = customNavSuiteType,<br>            navigationSuiteItems = {<br>                listOf(Blog, Posts, Profile).forEach { navItem -&gt;<br>                    item(<br>                        modifier = Modifier.wrapContentWidth(),<br>                        icon = {<br>                            Icon(<br>                                modifier = Modifier<br>                                    .padding(start = 10.dp, end = 10.dp)<br>                                    .size(32.dp)<br>                                    .padding(2.dp),<br>                                imageVector = when (navItem) {<br>                                    Blog -&gt; Icons.Default.Star<br>                                    Posts -&gt; Icons.Default.Edit<br>                                    Profile -&gt; Icons.Default.AccountCircle<br>                                    else -&gt; Icons.Default.Star<br>                                },<br>                                contentDescription = null<br>                            )<br>                        },<br>                        label = {<br>                            Text(<br>                                modifier = Modifier.wrapContentWidth(),<br>                                text = navItem::class.simpleName ?: &quot;&quot;<br>                            )<br>                        },<br>                        selected = selectedTab.value == navItem,<br>                        onClick = {<br>                            if (navItem != selectedTab.value) {<br>                                if (!tabBackStack.contains(selectedTab.value)) {<br>                                    tabBackStack.add(selectedTab.value)<br>                                }<br>                                selectedTab.value = navItem<br>                            }<br>                        }<br>                    )<br>                }<br>            }<br>        ) {<br>            Row(Modifier.fillMaxSize()) {<br>                when (selectedTab.value) {<br>                    Blog -&gt; BlogNavHost(blogNavController)<br>                    Posts -&gt; PostsNavHost(postsNavController)<br>                    Profile -&gt; ProfileNavHost(profileNavController)<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>The HandleBackPress function manages the back stack when navigating using the system back button or a screen’s back button. It utilizes canPopBackStack to determine if navigation to a previous screen within the current tab is possible. Additionally, it ensures that if the user is at the root of a tab, they can navigate back to the previously selected tab instead of exiting the app immediately.</p><pre>@Composable<br>fun HandleBackPress(<br>    selectedTab: MutableState&lt;Any&gt;,<br>    tabBackStack: MutableList&lt;Any&gt;,<br>    blogNavController: NavHostController,<br>    postsNavController: NavHostController,<br>    profileNavController: NavHostController,<br>    context: Context<br>) {<br>    BackHandler(true) {<br>        when {<br>            canPopBackStack(selectedTab, blogNavController, postsNavController, profileNavController) -&gt; {<br>                popBackStackForSelectedTab(selectedTab, blogNavController, postsNavController, profileNavController)<br>            }<br>            tabBackStack.isNotEmpty() -&gt; selectedTab.value = tabBackStack.removeAt(tabBackStack.lastIndex)<br>            else -&gt; (context as? Activity)?.finish()<br>        }<br>    }<br>}</pre><pre>fun canPopBackStack(<br>    selectedTab: Any,<br>    blogNavController: NavHostController,<br>    postsNavController: NavHostController,<br>    profileNavController: NavHostController<br>): Boolean {<br>    return when (selectedTab) {<br>        Blog -&gt; blogNavController.previousBackStackEntry != null<br>        Posts -&gt; postsNavController.previousBackStackEntry != null<br>        Profile -&gt; profileNavController.previousBackStackEntry != null<br>        else -&gt; false<br>    }<br>}</pre><p>The navigateToTabWithBackStack function maintains the navigation history for each tab. When switching tabs, it preserves the stack of previously visited screens instead of resetting the navigation state, allowing users to return to where they left off when switching between tabs.</p><pre>fun navigateToTabWithBackStack(<br>    newTab: Any,<br>    selectedTab: MutableState&lt;Any&gt;,<br>    tabBackStack: MutableList&lt;Any&gt;<br>) {<br>    if (selectedTab.value != newTab) {<br>        tabBackStack.add(selectedTab.value)<br>    }<br>    selectedTab.value = newTab<br>}</pre><p>The HandleDeepLinks function enables deep link handling while preserving the navigation stack. Unlike standard deep links inNavHost which often open a destination screen in isolation, this approach ensures that users see the expected screen hierarchy. This means that if a deep link opens a nested screen, the necessary parent screens are also in place, providing a more natural and consistent navigation experience.</p><pre>@Composable<br>fun HandleDeepLinks(<br>    context: Context,<br>    selectedTab: MutableState&lt;Any&gt;,<br>    tabBackStack: MutableList&lt;Any&gt;,<br>    profileNavController: NavHostController<br>) {<br>    LaunchedEffect((context as? Activity)?.intent) {<br>        (context as? Activity)?.intent?.data?.toString()?.let { data -&gt;<br>            when {<br>                &quot;bottomSheet&quot; in data -&gt; navigateToProfileTab(selectedTab, tabBackStack, profileNavController)<br>                &quot;profile&quot; in data -&gt; handleProfileDeepLink(data, selectedTab, tabBackStack, profileNavController)<br>                &quot;blog&quot; in data -&gt; navigateToTabWithBackStack(Blog, selectedTab, tabBackStack)<br>                &quot;posts&quot; in data -&gt; navigateToTabWithBackStack(Posts, selectedTab, tabBackStack)<br>            }<br>            (context as? Activity)?.intent = null<br>        }<br>    }<br>}</pre><p>The function handleProfileDeepLink ensures that when a deep link targets the ProfileSettingsScreen, it correctly maintains the navigation stack. If the deep link includes a test path, it also navigates to TestScreen, preserving the hierarchy:</p><p>✅ Blog -&gt; Profile -&gt; ProfileSettings -&gt; TestScreen</p><pre>private suspend fun handleProfileDeepLink(<br>    data: String,<br>    selectedTab: MutableState&lt;Any&gt;,<br>    tabBackStack: MutableList&lt;Any&gt;,<br>    profileNavController: NavHostController<br>) {<br>    navigateToTabWithBackStack(Profile, selectedTab, tabBackStack)<br>    delay(10)<br><br>    val pathSegments = Uri.parse(data).pathSegments<br>    val idArg = pathSegments?.getOrNull(1)?.toIntOrNull() ?: 0<br>    val openTestScreen = pathSegments?.getOrNull(2) == &quot;test&quot;<br><br>    profileNavController.navigate(ProfileSettings(idArg)) {<br>        launchSingleTop = true<br>        restoreState = true<br>    }<br><br>    if (openTestScreen) {<br>        profileNavController.navigate(Test) {<br>            launchSingleTop = true<br>            restoreState = true<br>        }<br>    }<br>}</pre><p>To handle deep linking into the BottomSheet, we ensure that the Profile tab is active before navigating to the bottom sheet screen. With the hierarchy:</p><p>✅ Blog -&gt; Profile -&gt; BottomSheet</p><pre>private suspend fun navigateToProfileTab(<br>    selectedTab: MutableState&lt;Any&gt;,<br>    tabBackStack: MutableList&lt;Any&gt;,<br>    profileNavController: NavHostController<br>) {<br>    navigateToTabWithBackStack(Profile, selectedTab, tabBackStack)<br>    delay(10)<br>    profileNavController.navigate(Profile) {<br>        launchSingleTop = true<br>        restoreState = true<br>        popUpTo(Profile) { saveState = true }<br>    }<br>}</pre><p>The ProfileNavHost controls navigation within the profile section. It allows users to move between the main profile screen, profile settings, and a test screen while also supporting deep links to open specific pages directly.</p><pre>@Composable<br>fun ProfileNavHost(profileNavController: NavHostController) {<br>    val overlayNavController = rememberNavController()<br><br>    val uri = LinkPatterns.uri<br>    Box(modifier = Modifier.fillMaxSize()) {<br>    // Main NavHost<br>    NavHost(<br>        navController = profileNavController,<br>        startDestination = Profile<br>    ) {<br>        composable&lt;Profile&gt;(<br>            deepLinks = listOf(<br>                navDeepLink&lt;ProfileSettings&gt;(basePath = &quot;$uri/profile/{idArg}&quot;)<br>            )<br>        )<br>        {<br>            ProfileScreen(<br>                onNavigateToProfile = { idArg -&gt;<br>                    profileNavController.navigate(ProfileSettings(idArg))<br>                },<br>                onBottomSheet = {<br>                    overlayNavController.navigate(BottomSheet)<br>                }<br>            )<br>        }<br><br>        composable&lt;ProfileSettings&gt; { backStackEntry -&gt;<br>            val id = backStackEntry.arguments?.getInt(&quot;idArg&quot;) ?: 0<br>            ProfileSettingsScreen(<br>                userId = id,<br>                onBack = profileNavController::popBackStack,<br>                onTestScreen = {<br>                    profileNavController.navigate(Test) {<br>                        launchSingleTop = true<br>                        restoreState = true<br>                    }<br>                }<br>            )<br>        }<br><br>        composable&lt;Test&gt;(<br>            deepLinks = listOf(<br>                navDeepLink&lt;Test&gt;(basePath = &quot;$uri/profile/100/test&quot;)<br>            )<br>        ) {<br>            TestScreen(onBack = profileNavController::popBackStack)<br>        }<br>    }<br><br>        // Overlay NavHost for Bottom Sheet<br>        NavHost(<br>            navController = overlayNavController,<br>            startDestination = Overlay,<br>            modifier = Modifier.zIndex(1f)<br>        ) {<br>            composable&lt;Overlay&gt; { /* Empty screen */ }<br>            composable&lt;BottomSheet&gt;(<br>                deepLinks = listOf(<br>                    navDeepLink&lt;BottomSheet&gt;(basePath = &quot;$uri/profile/bottomSheet&quot;)<br>                )<br>            ) {<br>                BottomSheetScreen(<br>                    title = stringResource(R.string.bottom_sheet_string),<br>                    onBack = { overlayNavController.popBackStack() },<br>                    content = { ContentExample() }<br>                )<br>            }<br>        }<br>    }<br>}</pre><p><strong>Testing deep links</strong></p><p>To trigger a deep link through adb, we have to use this command for opening the TestScreen:</p><pre>adb shell am start -W -a android.intent.action.VIEW -d &quot;https://www.example.com/profile/222/test&quot;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Frti03f-Oo8k%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Drti03f-Oo8k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Frti03f-Oo8k%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eaf93fb421838b31cd40128a80dc282/href">https://medium.com/media/8eaf93fb421838b31cd40128a80dc282/href</a></iframe><p>And this command for opening the BottomSheet screen:</p><pre>adb shell am start -W -a android.intent.action.VIEW -d &quot;https://www.example.com/profile/bottomSheet&quot;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FDCt_tpjlCXQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DDCt_tpjlCXQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FDCt_tpjlCXQ%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/36b7e0bee0d0b8e9a72858c952391ba4/href">https://medium.com/media/36b7e0bee0d0b8e9a72858c952391ba4/href</a></iframe><p>Feel free to explore the complete code in <a href="https://github.com/AnnaAlekseevich/FlowNavigator">this repository</a> and adapt it to your projects!</p><h3>Links</h3><p><strong>Type safety in Kotlin DSL and Navigation Compose</strong> — <a href="https://developer.android.com/guide/navigation/design/type-safety">https://developer.android.com/guide/navigation/design/type-safety</a></p><p><strong>Deep links</strong><br><a href="https://developer.android.com/develop/ui/compose/navigation#deeplinks">https://developer.android.com/develop/ui/compose/navigation#deeplinks</a></p><p><strong>Complete example in my GitHub — </strong><a href="https://github.com/AnnaAlekseevich/FlowNavigator">https://github.com/AnnaAlekseevich/FlowNavigator</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e85efdc5fc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type-Safe Navigation for Bottom Sheets in Jetpack Compose]]></title>
            <link>https://medium.com/@annaalekseyevich/a-type-safe-approach-to-opening-bottom-sheet-screens-using-a-route-in-jetpack-compose-navigation-ca52a33de158?source=rss-6b6791974781------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca52a33de158</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[compose-navigation]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[bottomsheet]]></category>
            <dc:creator><![CDATA[Anna Alekseyevich]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 07:09:29 GMT</pubDate>
            <atom:updated>2025-01-23T20:41:40.949Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn how to open a Bottom Sheet above the Navigation Bar in Jetpack Compose using a navigation route. Ensure type safety, clean navigation, and seamless integration above the navigation bar.</p><p>I created a custom solution that integrates a Bottom Sheet with Compose Navigation, allowing you to navigate to the Bottom Sheet using a route. Below is a visual representation of the Bottom Sheet integration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*CKgeO43wC-wfq-kLXJHT5g.png" /></figure><p>You can find the complete code in <a href="https://github.com/AnnaAlekseevich/FlowNavigator">this repository</a>.</p><h3>Problem Overview</h3><p>Jetpack Compose Navigation is a powerful tool for managing screens, but opening a Bottom Sheet while keeping the previous screen visible presents challenges. Typical approaches often:</p><ul><li>Lack of type safety in route definitions.</li><li>Require complex manual backstack handling.</li><li>Don’t easily integrate with navigation components like the BottomNavigationBar.</li></ul><p>My solution addresses these problems by:</p><ol><li>Using a separate NavHost for the Bottom Sheet.</li><li>Managing the back stack cleanly and efficiently.</li><li>Leveraging type-safe routes for navigation.</li></ol><h3>Solution Overview</h3><p>To implement this solution, we create a custom NavHost dedicated to the Bottom Sheet. This allows us to manage its lifecycle independently, while still working seamlessly with the main NavHost. Here is an overview of the setup:</p><ol><li><strong>Main </strong><strong>NavHost:</strong> Manages your primary navigation, such as the Profile and Profile Settings screens.</li><li><strong>Overlay </strong><strong>NavHost:</strong> Handles Bottom Sheet navigation independently.</li><li><strong>Type-Safe Routes:</strong> Ensures safe argument passing between screens.</li></ol><p>This structure ensures a clean separation of concerns and enables a smooth user experience.</p><h3>Implementation</h3><h3>Step 1: Setting Up the NavHosts</h3><p>We’ll create two NavHosts — one for the main navigation and another for the Bottom Sheet—and place them within a Box to manage their z-order.</p><pre>@Composable<br>fun ProfileNavHost() {<br>    val profileNavController = rememberNavController()<br>    val overlayNavController = rememberNavController()<br><br>    val uri = LinkPatterns.uri<br><br>    // Main NavHost<br>    NavHost(<br>        navController = profileNavController,<br>        startDestination = Profile<br>    ) {<br>        composable&lt;Profile&gt; {<br>            ProfileScreen(<br>                onNavigateToProfile = { idArg -&gt;<br>                    profileNavController.navigate(ProfileSettings(idArg))<br>                },<br>                onBottomSheet = {<br>                    overlayNavController.navigate(BottomSheet)<br>                }<br>            )<br>        }<br><br>        composable&lt;ProfileSettings&gt;(deepLinks = listOf(<br>            navDeepLink { uriPattern = &quot;$uri/profile/{idArg}&quot; }<br>        )) { backStackEntry -&gt;<br>            val profileSettings: ProfileSettings = backStackEntry.toRoute()<br><br>            val userId = profileSettings.idArg<br>            ProfileSettingsScreen(userId, onBack = profileNavController::popBackStack)<br>        }<br>    }<br><br>    // Overlay NavHost for Bottom Sheet<br>    NavHost(<br>        navController = overlayNavController,<br>        startDestination = Overlay,<br>        modifier = Modifier.zIndex(1f)<br>    ) {<br>        composable&lt;Overlay&gt; { /* Empty screen */ }<br>        composable&lt;BottomSheet&gt; {<br>            BottomSheetScreen(<br>                title = stringResource(R.string.bottom_sheet_string),<br>                onBack = { overlayNavController.popBackStack() },<br>                content = { ContentExample() }<br>            )<br>        }<br>    }<br>}</pre><p>In this setup:</p><ul><li>The main NavHost handles regular navigation.</li><li>The overlay NavHost is used exclusively for the Bottom Sheet, ensuring it is rendered above the main content.</li></ul><h3>Step 2: Implementing the BottomSheetScreen</h3><p>The BottomSheetScreen is a composable that displays a sheet with content and supports gestures for opening and closing. Here’s the implementation:</p><pre>@OptIn(ExperimentalMaterial3Api::class)<br>@Composable<br>fun BottomSheetScreen(title: String, onBack: () -&gt; Unit, content: @Composable () -&gt; Unit) {<br>    val coroutineScope = rememberCoroutineScope()<br>    val density = LocalDensity.current.density<br>    val screenHeightPx = LocalConfiguration.current.screenHeightDp * density<br>    val dragOffsetY = remember { Animatable(screenHeightPx) }<br>    val closeThreshold = screenHeightPx / 4f<br>    val scrollState = rememberScrollState()<br>    val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()<br><br>    var isVisible by remember { mutableStateOf(true) }<br>    val alphaAnim = animateFloatAsState(<br>        targetValue = if (isVisible) 0.25f else 0f,<br>        animationSpec = tween(durationMillis = 100), label = &quot;&quot;<br>    )<br><br>    val nestedScrollConnection = remember {<br>        object : NestedScrollConnection {<br>            override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {<br>                val delta = available.y<br>                if (delta &gt; 0 &amp;&amp; scrollState.value == 0) {<br>                    coroutineScope.launch {<br>                        val newOffset = (dragOffsetY.value + delta).coerceIn(0f, screenHeightPx)<br>                        dragOffsetY.snapTo(newOffset)<br>                    }<br>                    return Offset(0f, delta)<br>                }<br>                return Offset.Zero<br>            }<br><br>            override suspend fun onPreFling(available: Velocity): Velocity {<br>                if (available.y &gt; 0 &amp;&amp; dragOffsetY.value &gt; closeThreshold) {<br>                    coroutineScope.launch {<br>                        dragOffsetY.animateTo(screenHeightPx, tween(150))<br>                        onBack()<br>                    }<br>                }<br>                return super.onPreFling(available)<br>            }<br><br>            override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {<br>                if (dragOffsetY.value &gt; closeThreshold) {<br>                    dragOffsetY.animateTo(screenHeightPx, tween(150))<br>                    onBack()<br>                } else {<br>                    dragOffsetY.animateTo(0f, tween(200))<br>                }<br>                return available<br>            }<br>        }<br>    }<br><br>    if (isVisible) {<br>        Box(<br>            Modifier<br>                .fillMaxSize()<br>                .background(Color.Black.copy(alpha = alphaAnim.value))<br>                .pointerInput(Unit) {<br>                    detectTapGestures(<br>                        onTap = {<br>                            coroutineScope.launch {<br>                                dragOffsetY.animateTo(screenHeightPx, tween(300))<br>                                isVisible = false<br>                                delay(300)<br>                                onBack()<br>                            }<br>                        }<br>                    )<br>                }<br>                .nestedScroll(nestedScrollConnection),<br>            contentAlignment = Alignment.BottomCenter<br>        ) {<br>            LaunchedEffect(Unit) {<br>                coroutineScope.launch {<br>                    dragOffsetY.animateTo(0f, tween(300))<br>                }<br>            }<br><br>            Box(<br>                modifier = Modifier<br>                    .offset { IntOffset(0, dragOffsetY.value.toInt()) }<br>                    .background(Color.Transparent)<br>                    .nestedScroll(scrollBehavior.nestedScrollConnection)<br>                    .background(<br>                        color = Color.Transparent,<br>                        shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)<br>                    )<br>            ) {<br>                Column(<br>                    modifier = Modifier<br>                        .fillMaxWidth()<br>                        .background(Color.Transparent)<br>                ) {<br>                    BottomSheetToolbar(<br>                        title = title,<br>                        onCloseClick = {<br>                            coroutineScope.launch {<br>                                dragOffsetY.animateTo(screenHeightPx, tween(300))<br>                                isVisible = false<br>                                delay(300)<br>                                onBack.invoke()<br>                            }<br>                        },<br>                        scrollBehavior = scrollBehavior<br>                    )<br><br>                    Column(<br>                        modifier = Modifier<br>                            .fillMaxWidth()<br>                            .verticalScroll(scrollState)<br>                            .background(Color(0xFFFAF8F7))<br>                            .padding(16.dp)<br>                    ) {<br>                        content.invoke()<br>                    }<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>This composable manages:</p><ul><li>Gestures for drag and close.</li><li>Smooth animations for opening and closing.</li><li>Overlay background with dimming.</li></ul><p>Here is an example of how it works and looks:</p><ol><li>Closing the Bottom Sheet by pressing the arrow button on the toolbar.</li><li>Closing it with a swipe gesture.</li><li>Closing it by tapping on the dimmed background overlay.</li><li>Closing it using the system back button.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xi8hOXaavjDYn6sNGFvtVw.gif" /></figure><p>Below is an example of the full-screen content shown in the Bottom Sheet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UImP6NCOnrhhEC5pnO0AFA.gif" /></figure><p>With this approach, you can integrate a Bottom Sheet into Jetpack Compose Navigation in a type-safe and maintainable way. The solution is flexible and easily extensible for other use cases, such as adding additional overlay screens.</p><p>Feel free to explore the complete code in <a href="https://github.com/AnnaAlekseevich/FlowNavigator">this repository</a> and adapt it to your projects!</p><h3>Links</h3><p><strong>Type safety in Kotlin DSL and Navigation Compose</strong> — <a href="https://developer.android.com/guide/navigation/design/type-safety">https://developer.android.com/guide/navigation/design/type-safety</a></p><p><strong>Bottom sheets</strong> — <a href="https://developer.android.com/develop/ui/compose/components/bottom-sheets?hl=en">https://developer.android.com/develop/ui/compose/components/bottom-sheets?hl=en</a></p><p><strong>Partial bottom sheet</strong> — <a href="https://developer.android.com/develop/ui/compose/components/bottom-sheets-partial">https://developer.android.com/develop/ui/compose/components/bottom-sheets-partial</a></p><p><strong>Complete example in my GitHub — </strong><a href="https://github.com/AnnaAlekseevich/FlowNavigator">https://github.com/AnnaAlekseevich/FlowNavigator</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca52a33de158" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Books That Shaped My Android Development Journey]]></title>
            <link>https://medium.com/@annaalekseyevich/books-that-shaped-my-android-development-journey-ae957700e881?source=rss-6b6791974781------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae957700e881</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[books]]></category>
            <dc:creator><![CDATA[Anna Alekseyevich]]></dc:creator>
            <pubDate>Sat, 28 Dec 2024 23:47:57 GMT</pubDate>
            <atom:updated>2024-12-28T23:56:47.137Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! My name is Anna and I have been working as an Android developer for over 3 years. Over this time, I’ve faced many challenges, from understanding Kotlin intricacies to mastering modern tools like Jetpack Compose. Along the way, books have been my greatest allies. In this post, I want to share six books that have not only improved my skills but also changed my perspective on development. I hope they’ll inspire and help you as much as they’ve helped me.</p><p>In a world full of online tutorials, forums, and video courses, you might wonder, “Why bother with books?” The answer is simple: books offer depth and structure that other resources often lack.</p><p>Unlike short articles or quick videos, a well-written book takes you on a journey. It connects the dots between concepts, explains <em>why</em> things work a certain way, and helps you understand the bigger picture. For me, books have been a way to slow down and focus. They’ve helped me build a solid foundation in Android development and given me the confidence to tackle more complex challenges.</p><p>Books also allow you to learn directly from experts. Many of the authors I’ve mentioned in this post are leaders in their fields. Reading their work is like having a personal mentor guide you through new tools and ideas. That’s something no quick online search can replace.</p><h3>1) Kotlin in Action (Second Edition)</h3><p>Sebastian Aigner, Roman Elizarov, Svetlana Isakova, Dmitry Jemerov</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*iLcjVgiwTTz8eB9iK3VU5g.png" /></figure><p>This book is a must-read for anyone working with Kotlin. It covers Kotlin 2.0, including its new features and optimizations, with clear and practical examples. The authors — who are directly involved in Kotlin’s development — provide deep insights into its capabilities. After reading this book, I revisited some of my older projects and realized how I could simplify and optimize the code using Kotlin’s advanced features like extension functions and inline classes. For example, I reworked a utility class in one of my projects, turning ten lines of verbose code into a clean one-liner with an extension function. This not only improved readability but also taught me to think more idiomatically in Kotlin.</p><h3>2) Programming Android with Kotlin: Achieving Structured Concurrency with Coroutines (1st Edition)</h3><p>Pierre-Olivier Laurence, Amanda Hinchman-Dominguez, Mike Dunn, G. Blake Meike</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*LjhHcee3uNcdZpHlhTRovw.jpeg" /></figure><p>If you’re looking to master structured concurrency and coroutines in Android, this book is for you. It provides a detailed overview of thread safety, asynchronous programming, and performance optimization using tools like Android profilers. For beginners, this book efficiently explains Android fundamentals. After reading this book, I finally understood how to use coroutines for managing background tasks like fetching data from APIs. The chapter on structured concurrency completely changed how I approach asynchronous programming.</p><h3>3) Android Programming: The Big Nerd Ranch Guide 2nd Edition</h3><p>Bill Phillips, Chris Stewart, Brian Hardy, Kristin Marsicano</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*iVrVWfSDgkr6DZ-_UfjN8w.jpeg" /></figure><p>When I was starting my Android journey, this book became my go-to resource. It explains essential topics like debugging, creating simple apps, and using logging frameworks. I especially appreciated the practical ‘side tips,’ like managing screen rotations and localizing apps, which proved invaluable in real projects.</p><h3>4) Practical Jetpack compose</h3><p>Joe Birch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*5BDUGZBtDN2wdEeZESP7VQ.png" /></figure><p>This hands-on book focuses on creating 12 small applications using Jetpack Compose. Its clear and detailed explanations helped me confidently start migrating my company’s projects to Compose. The book also includes guides on UI testing, which is a great bonus for ensuring app quality.</p><h3>5) The Passionate Programmer</h3><p>Fowler Chad</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*FPrrQ9DJ9AjQt3iWOrDTKQ.png" /></figure><p>This book isn’t just about coding — it’s about becoming a better professional. It helps you identify areas for growth, find motivation, and take control of your career. For me, the book’s advice pushed me to finally write this post — something I had been putting off for a long time!</p><h3>6) Outliers. The Story of Success</h3><p>Malcolm Gladwell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*UWQmhBij9yx0Uln5qVm_QQ.png" /></figure><p>Malcolm Gladwell’s Outliers explores how success often depends on a mix of talent, opportunity, and dedication. The “10,000 hours rule” — one of the book’s most famous concepts — changed the way I think about skill-building. It reminded me that consistent effort and preparation are key to growth, not just luck or natural talent.</p><p>I hope this list inspires you to dive into these books and discover your own insights. Books have been my trusted mentors, and I’m excited to see how they can help you on your Android journey. If you have a favorite book or resource, please share it in the comments — let’s learn from each other and grow together!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae957700e881" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>