<?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 Alican Sekban on Medium]]></title>
        <description><![CDATA[Stories by Alican Sekban on Medium]]></description>
        <link>https://medium.com/@alicansekban?source=rss-dc069c78029e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S_Qqd6hQO7iGPso4he053A.png</url>
            <title>Stories by Alican Sekban on Medium</title>
            <link>https://medium.com/@alicansekban?source=rss-dc069c78029e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:00:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alicansekban/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[Integrating Room Database with Koin in Compose Multiplatform]]></title>
            <link>https://medium.com/@alicansekban/integrating-room-database-with-koin-in-compose-multiplatform-b9b3cd3e6791?source=rss-dc069c78029e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9b3cd3e6791</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Alican Sekban]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 20:53:11 GMT</pubDate>
            <atom:updated>2024-11-12T20:53:11.940Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In this tutorial, we’ll explore how to integrate Room Database with Koin in a Compose Multiplatform project. We’ll cover adding necessary dependencies, setting up a Room database, and configuring Koin to handle dependency injection on Android and iOS platforms. This setup will allow us to manage data persistence effectively across both platforms with a shared codebase.</p><h3>Prerequisites</h3><p>Ensure your project is configured to support Compose Multiplatform, and you are familiar with Koin and Room. The following versions and dependencies will be used:</p><ul><li><strong>Room:</strong> 2.7.0-alpha11</li><li><strong>Koin:</strong> 4.0.0</li><li><strong>KSP:</strong> 2.0.20–1.0.24</li><li><strong>SQLite Bundled:</strong> 2.5.0-SNAPSHOT</li></ul><pre><br>koin-android = { module = &quot;io.insert-koin:koin-android&quot;, version.ref = &quot;koin&quot; }<br>koin-androidx-compose = { module = &quot;io.insert-koin:koin-androidx-compose&quot;, version.ref = &quot;koin&quot; }<br>koin-core = { module = &quot;io.insert-koin:koin-core&quot;, version.ref = &quot;koin&quot; }<br>koin-compose = { module = &quot;io.insert-koin:koin-compose&quot;, version.ref = &quot;koin&quot; }</pre><pre><br>room-runtime = { module = &quot;androidx.room:room-runtime&quot;, version.ref = &quot;room&quot; }<br>room-compiler = { module = &quot;androidx.room:room-compiler&quot;, version.ref = &quot;room&quot; }<br>sqlite-bundled = { module = &quot;androidx.sqlite:sqlite-bundled&quot;, version.ref = &quot;sqlite&quot; }</pre><pre>Plugin<br><br>ksp = { id = &quot;com.google.devtools.ksp&quot;, version.ref = &quot;ksp&quot; }<br>room = { id = &quot;androidx.room&quot;, version.ref = &quot;room&quot; }</pre><h3>Step 1: Adding Dependencies</h3><p>In the build.gradle.kts, add the following dependencies:</p><pre>// Common dependencies for Room and Koin<br>commonMain {<br> // koin<br>    api(libs.koin.core)<br>    implementation(libs.koin.compose)<br>    implementation(libs.koin.compose.viewmodel)<br> // room db<br>     implementation(libs.room.runtime)<br>     implementation(libs.sqlite.bundled)<br>}</pre><pre>// Android-specific dependencies for Koin and Room<br>androidMain {<br>    implementation(libs.koin.android)<br>    implementation(libs.koin.androidx.compose)<br>}<br>// iOS-specific dependencies<br>iosMain {<br>    implementation(libs.ktor.client.darwin)<br>}</pre><h3>Step 2: Configuring the KSP and Room Compiler Plugins</h3><p>In the main build.gradle.kts file, add the following Room configuration:</p><pre>plugins {<br>    alias(libs.plugins.ksp)<br>    alias(libs.plugins.room)<br>}</pre><pre>room {<br>    schemaDirectory(&quot;$projectDir/schemas&quot;)<br>}<br><br><br>dependencies {<br>    implementation(libs.androidx.material3.android)<br>    ksp(libs.room.compiler)<br>}</pre><h3>Step 3: Setting Up Room Database in the Common Module</h3><p>First, create a Database and an entity in the common module.</p><pre>@Database(entities = [ExampleEntity::class], version = 2)<br>@ConstructedBy(AppDatabaseConstructor::class)<br>abstract class AppDatabase : RoomDatabase() {<br>    abstract fun getDao(): ExampleDao<br>}</pre><pre>data class ExampleEntity(<br>    @PrimaryKey(autoGenerate = true) val id: Int = 0,<br>    val name: String<br>)</pre><p>Define a DAO interface for accessing data:</p><pre>@Dao<br>interface ExampleDao {<br>    @Insert(onConflict = OnConflictStrategy.REPLACE)<br>    suspend fun insertExample(model: ExampleEntity)<br>}</pre><h3>Step 4: Implementing the Koin Module for Each Platform</h3><h4>Common Koin Setup</h4><p>In the common module, initialize Koin and define platformModule() as an expect function:</p><pre>expect fun platformModule(): Module</pre><pre>fun initKoin(config: KoinAppDeclaration? = null) {<br>    startKoin {<br>        config?.invoke(this)<br>        modules(platformModule())<br>    }<br>}</pre><h4>iOS Platform-Specific Module</h4><p>Define platformModule() for iOS to provide the database instance:</p><pre>actual fun platformModule(): Module {<br>    return module {<br>        single&lt;AppDatabase&gt; { getAppDatabase() }<br>    }<br>}</pre><pre>fun getAppDatabase(): AppDatabase {<br>    val dbFilePath = documentDirectory() + &quot;/app.db&quot;<br>    return Room.databaseBuilder&lt;AppDatabase&gt;(<br>        name = dbFilePath,<br>    ).setDriver(BundledSQLiteDriver())<br>        .build()<br>}</pre><pre>private fun documentDirectory(): String {<br>    val documentDirectory = NSFileManager.defaultManager.URLForDirectory(<br>        directory = NSDocumentDirectory,<br>        inDomain = NSUserDomainMask,<br>        appropriateForURL = null,<br>        create = false,<br>        error = null,<br>    )<br>    return requireNotNull(documentDirectory?.path)<br>}</pre><p>In your MainViewController (iOS entry point), initialize Koin:</p><pre>fun MainViewController() = ComposeUIViewController(<br>    configure = {<br>        initKoin()<br>    }<br>) {<br>    App()<br>}</pre><h4>Android Platform-Specific Module</h4><p>Define platformModule() for Android to provide the database instance:</p><pre>actual fun platformModule(): Module {<br>    return module {<br>        single&lt;AppDatabase&gt; { getAppDatabase(get()) }<br>    }<br>}</pre><pre>fun getAppDatabase(context: Context): AppDatabase {<br>    val dbFile = context.getDatabasePath(&quot;app.db&quot;)<br>    return Room.databaseBuilder&lt;AppDatabase&gt;(<br>        context = context.applicationContext,<br>        name = dbFile.absolutePath<br>    ).setDriver(BundledSQLiteDriver())<br>        .build()<br>}</pre><p>In the Android Application class, initialize Koin:</p><pre>class MyApplication : Application() {<br>    override fun onCreate() {<br>        super.onCreate()<br>        initKoin {<br>            androidContext(this@MyApplication)<br>        }<br>    }<br>}</pre><h3>Step 5: Using the Database</h3><p>With Koin and Room set up, you can inject AppDatabase and use ExampleDao in your application logic:</p><pre>class ExampleRepository(private val db: AppDatabase) {<br>    suspend fun insertExample(example: ExampleEntity) {<br>        db.getDao().insertExample(example)<br>    }<br>}</pre><h3>Conclusion</h3><p>By following these steps, you’ve set up Room Database in a Compose Multiplatform project with Koin dependency injection. This approach allows you to maintain a unified codebase for both Android and iOS while utilizing platform-specific configurations where needed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9b3cd3e6791" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose-Stepper: A Customizable Step Indicator Library for Jetpack Compose]]></title>
            <link>https://medium.com/@alicansekban/compose-stepper-a-customizable-step-indicator-library-for-jetpack-compose-938d301ee397?source=rss-dc069c78029e------2</link>
            <guid isPermaLink="false">https://medium.com/p/938d301ee397</guid>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Alican Sekban]]></dc:creator>
            <pubDate>Sat, 19 Oct 2024 11:10:08 GMT</pubDate>
            <atom:updated>2024-10-19T11:10:08.796Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I introduce <strong>Compose-Stepper</strong>, a highly customizable step indicator library designed specifically for Android applications using <strong>Jetpack Compose</strong>. This library visually represents multi-step progress with labels and checkmarks, making it easy to track steps in a user-friendly way. Whether you’re building a registration form, a product purchase flow, or any other multi-step process, Compose-Stepper can seamlessly integrate into your project.</p><h3>Features at a Glance</h3><p>Compose-Stepper comes packed with several useful features:</p><ul><li><strong>Customizable Colors</strong>: You can define different colors for completed, current, and future steps.</li><li><strong>Dynamic Labels</strong>: Add labels below each step to provide contextual information.</li><li><strong>Progress Tracking</strong>: Visually indicate which steps are complete, in-progress, or pending.</li><li><strong>Adaptive Layout</strong>: The layout automatically adjusts to fit the screen, preventing overflow issues.</li></ul><h3>Getting Started</h3><p>To get started, follow these simple steps:</p><p><strong>Step 1:</strong> Add the JitPack repository to your root build.gradle file:</p><pre>repositories {<br>    maven { url &quot;https://jitpack.io&quot; }<br>}</pre><p><strong>Step 2:</strong> Include the Compose-Stepper dependency in your module’s build.gradle file:</p><pre>dependencies {<br>    implementation &#39;com.github.alicansekban:ComposeStepProgressBar:1.0&#39;<br>}</pre><h3>Usage</h3><p>Once you’ve added the dependency, you can implement a basic step progress bar as shown below.</p><pre>val stepList = arrayListOf(<br>    StepModel(<br>        title = &quot;Step 1&quot;,<br>        isCompleted = true<br>    ),<br>    StepModel(<br>        title = &quot;Step 2&quot;,<br>        isCompleted = true<br>    ),<br>    StepModel(<br>        title = &quot;Step 3&quot;,<br>        isCompleted = true<br>    ),<br>    StepModel(<br>        title = &quot;Step 4&quot;,<br>        isCompleted = false<br>    )<br>)</pre><pre>StepProgressBar(<br>    stepList = stepList,<br>    completedTextColor = Color.Red,<br>    completedBackgroundColor = Color.Red,<br>    completedDrawLineColor = Color.Red,<br>    modifier = Modifier.fillMaxWidth()<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*ZcuVT7YXJ6E2KadQP1lp6w.png" /></figure><p>In this basic example, we create a list of steps using StepModel and then pass that list into the StepProgressBar component. You can customize the colors for the completed steps as needed.</p><h3>Customization</h3><p>Compose-Stepper is fully customizable to fit the needs of your app. Here’s how you can personalize the component’s appearance:</p><pre>StepProgressBar(<br>    stepList = stepList,<br>    completedTextColor = Color.Green,<br>    completedBackgroundColor = Color.Green,<br>    completedDrawLineColor = Color.Green,<br>    uncompletedTextColor = Color.Red,<br>    uncompletedBackgroundColor = Color.Red,<br>    uncompletedDrawLineColor = Color.Red,<br>    modifier = Modifier.fillMaxWidth()<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*JqsrjApY3Os3Qth_MNAsKQ.png" /></figure><p>You can modify the following properties:</p><ul><li><strong>Completed Step Colors</strong>: completedTextColor, completedBackgroundColor, and completedDrawLineColor.</li><li><strong>Uncompleted Step Colors</strong>: uncompletedTextColor, uncompletedBackgroundColor, and uncompletedDrawLineColor.</li><li><strong>Icons</strong>: You can replace the default icons with your own.</li></ul><h3>GitHub</h3><p>You can find the full source code and contribute to the library on GitHub:<br><a href="https://github.com/alicansekban/ComposeStepProgressBar">Compose-Stepper GitHub Repository</a></p><h3>License</h3><p>This library is licensed under the MIT License. For more details, check the <a href="https://github.com/alicansekban/ComposeStepProgressBar/blob/main/LICENSE">LICENSE</a> file.</p><p>By integrating Compose-Stepper into your Android app, you can provide a visually appealing and intuitive step progress experience to users. You can easily customize the appearance, ensuring that it aligns with your app’s theme and style. I hope you find this library useful, and I look forward to seeing it in your projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=938d301ee397" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Koin and Ktor on Compose Multiplatform]]></title>
            <link>https://medium.com/@alicansekban/koin-and-ktor-on-compose-multiplatform-93425032286f?source=rss-dc069c78029e------2</link>
            <guid isPermaLink="false">https://medium.com/p/93425032286f</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[compose]]></category>
            <dc:creator><![CDATA[Alican Sekban]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 17:53:20 GMT</pubDate>
            <atom:updated>2024-08-05T17:53:20.797Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In this article, we will explore the use of Ktor and Koin in Compose Multiplatform projects. First, we will create a network layer using Ktor, and then we will show how to perform dependency injection with Koin. Next, we will examine how to fetch data in a ViewModel and pass it to the user interface. Our example application will fetch and display a list of heroes and their details.</p><h3>Dependencies</h3><p>To use Ktor and Koin, you need to add the following dependencies to your build.gradle.kts file. These code snippets include Ktor&#39;s HTTP client, JSON processing features, and Koin&#39;s dependency injection capabilities.</p><h4>Ktor Dependencies</h4><pre>dependencies {<br>    implementation(&quot;io.ktor:ktor-client-core:2.3.1&quot;)<br>    implementation(&quot;io.ktor:ktor-client-cio:2.3.1&quot;)<br>    implementation(&quot;io.ktor:ktor-client-content-negotiation:2.3.1&quot;)<br>    implementation(&quot;io.ktor:ktor-serialization-kotlinx-json:2.3.1&quot;)<br>}</pre><h4>Koin Dependencies</h4><pre>dependencies {<br>    implementation(&quot;io.insert-koin:koin-core:3.4.0&quot;)<br>    implementation(&quot;io.insert-koin:koin-android:3.4.0&quot;) // For Android<br>    implementation(&quot;io.insert-koin:koin-androidx-compose:3.4.0&quot;) // For Jetpack Compose<br>}</pre><h3>Creating the Network Layer</h3><p>The first step is to create a network layer using Ktor. Ktor is a powerful library for HTTP client functionality in Kotlin Multiplatform projects. Below is an example of the NetworkRepository class and the toResultFlow function, which demonstrate how to handle network requests:</p><pre>import io.ktor.client.HttpClient<br>import io.ktor.client.request.get<br>import io.ktor.client.statement.body<br>import io.ktor.http.URLProtocol<br>import kotlinx.coroutines.flow.Flow<br>import kotlinx.coroutines.flow.flow<br>import kotlinx.serialization.json.Json</pre><pre>fun &lt;T&gt; toResultFlow(call: suspend () -&gt; NetWorkResult&lt;T?&gt;): Flow&lt;NetWorkResult&lt;T&gt;&gt; {<br>    return flow {<br>        emit(NetWorkResult.Loading(true))<br>        val c = call.invoke()<br>        c.let { response -&gt;<br>            try {<br>                println(&quot;response${response.data}&quot;)<br>                emit(NetWorkResult.Success(response.data))<br>            } catch (e: Exception) {<br>                emit(NetWorkResult.Error(response.data, e.message ?: &quot;&quot;))<br>            }<br>        }<br>    }<br>}</pre><pre>sealed class NetWorkResult&lt;out T&gt;(val status: ApiStatus, val data: T?, val message: String?) {<br>    data class Success&lt;out T&gt;(val _data: T?) :<br>        NetWorkResult&lt;T&gt;(status = ApiStatus.SUCCESS, data = _data, message = null)<br>    data class Error&lt;out T&gt;(val _data: T?, val exception: String) :<br>        NetWorkResult&lt;T&gt;(status = ApiStatus.ERROR, data = _data, message = exception)<br>    data class Loading&lt;out T&gt;(val isLoading: Boolean) :<br>        NetWorkResult&lt;T&gt;(status = ApiStatus.LOADING, data = null, message = null)<br>}</pre><pre>enum class ApiStatus {<br>    SUCCESS,<br>    ERROR,<br>    LOADING,<br>}</pre><pre>class NetworkRepository(private val httpClient: HttpClient) {<br>    suspend fun getHeroes(): Flow&lt;NetWorkResult&lt;List&lt;HeroesResponse&gt;&gt;&gt; {<br>        return toResultFlow {<br>            val response = httpClient.get {<br>                url {<br>                    protocol = URLProtocol.HTTPS<br>                    host = Constants.BASE_URL_WITHOUT_HTTPS<br>                    path(&quot;heroes.json&quot;)<br>                }<br>            }.body&lt;List&lt;HeroesResponse&gt;&gt;()<br>            NetWorkResult.Success(response)<br>        }<br>    }</pre><pre>    suspend fun getHeroDetail(heroName: String): Flow&lt;NetWorkResult&lt;HeroesResponse&gt;&gt; {<br>        return toResultFlow {<br>            val response = httpClient.get {<br>                url {<br>                    protocol = URLProtocol.HTTPS<br>                    host = Constants.BASE_URL_WITHOUT_HTTPS<br>                    encodedPath = &quot;heroes/$heroName.json&quot;<br>                }<br>            }.body&lt;HeroesResponse&gt;()<br>            NetWorkResult.Success(response)<br>        }<br>    }<br>}</pre><p>This code includes a general toResultFlow function that returns the results of network requests as a Flow object. The NetworkRepository class provides two functions to fetch a list of heroes and the details of a specific hero.</p><h3>Creating Koin Modules</h3><p>Next, we will configure dependency injection using Koin. Koin is a lightweight library for dependency injection in Kotlin projects. Below are Koin modules that provide the HTTP client, repositories, and view models:</p><pre>import org.koin.dsl.module<br>import io.ktor.client.HttpClient<br>import io.ktor.client.plugins.contentnegotiation.ContentNegotiation<br>import io.ktor.http.ContentType<br>import kotlinx.serialization.json.Json</pre><pre>fun appModule() = listOf(provideHttpClientModule, provideRepositoryModule, provideViewModelModule)</pre><pre>val provideHttpClientModule = module {<br>    single {<br>        HttpClient {<br>            install(ContentNegotiation) {<br>                json(json = Json { ignoreUnknownKeys = true }, contentType = ContentType.Any)<br>            }<br>        }<br>    }<br>}</pre><pre>val provideRepositoryModule = module {<br>    single&lt;NetworkRepository&gt; { NetworkRepository(get()) }<br>}</pre><pre>val provideViewModelModule = module {<br>    single {<br>        HomeViewModel(get())<br>    }<br>    single {<br>        DetailViewModel(get())<br>    }<br>}</pre><p>These modules provide the HTTP client, NetworkRepository class, and HomeViewModel and DetailViewModel classes. Koin automatically injects these dependencies, making your code cleaner and more manageable.</p><h3>Constants File</h3><p>To manage static values in the project, we create a Constants file</p><pre>object Constants {<br>    const val BASE_URL = &quot;https://omeda.city/&quot;<br>    const val BASE_URL_WITHOUT_HTTPS = &quot;omeda.city/&quot;<br>}</pre><p>This file contains the base URLs used in network requests.</p><h3>Fetching Data in ViewModel and Passing it to the UI</h3><p>Fetching data in the ViewModel and passing it to the UI is a crucial step in modern application development. Below is an example showing how to fetch data in the HomeViewModel class and pass it to the UI:</p><pre>import androidx.compose.runtime.*<br>import androidx.lifecycle.ViewModel<br>import androidx.lifecycle.viewModelScope<br>import kotlinx.coroutines.CoroutineScope<br>import kotlinx.coroutines.Dispatchers<br>import kotlinx.coroutines.flow.MutableStateFlow<br>import kotlinx.coroutines.flow.asStateFlow<br>import kotlinx.coroutines.flow.collect<br>import kotlinx.coroutines.launch<br>import org.koin.androidx.compose.getKoin</pre><pre>class HomeViewModel(private val networkRepository: NetworkRepository) : ViewModel() {<br>    private val _homeState = MutableStateFlow(HomeState())<br>    private val _homeViewState: MutableStateFlow&lt;HomeScreenState&gt; = MutableStateFlow(HomeScreenState.Loading)<br>    val homeViewState = _homeViewState.asStateFlow()</pre><pre>    suspend fun getProducts() {<br>        CoroutineScope(Dispatchers.IO).launch {<br>            try {<br>                networkRepository.getHeroes().collect { response -&gt;<br>                    when(response.status) {<br>                        ApiStatus.LOADING -&gt; {<br>                            _homeState.update { it.copy(isLoading = true) }<br>                        }<br>                        ApiStatus.SUCCESS -&gt; {<br>                            _homeState.update { it.copy(isLoading = false, errorMessage = &quot;&quot;, responseData = response.data ?: emptyList()) }<br>                        }<br>                        ApiStatus.ERROR -&gt; {<br>                            _homeState.update { it.copy(isLoading = false, errorMessage = response.message) }<br>                        }<br>                    }<br>                    _homeViewState.value = _homeState.value.toUiState()<br>                }<br>            } catch (e: Exception) {<br>                _homeState.update { it.copy(isLoading = false, errorMessage = &quot;Failed to fetch data&quot;) }<br>            }<br>        }<br>    }</pre><pre>    sealed class HomeScreenState {<br>        data object Loading : HomeScreenState()<br>        data class Error(val errorMessage: String) : HomeScreenState()<br>        data class Success(val responseData: List&lt;HeroesResponse&gt;) : HomeScreenState()<br>    }</pre><pre>    private data class HomeState(<br>        val isLoading: Boolean = false,<br>        val errorMessage: String? = null,<br>        val responseData: List&lt;HeroesResponse&gt; = emptyList()<br>    ) {<br>        fun toUiState(): HomeScreenState {<br>            return if (isLoading) {<br>                HomeScreenState.Loading<br>            } else if (errorMessage?.isNotEmpty() == true) {<br>                HomeScreenState.Error(errorMessage)<br>            } else {<br>                HomeScreenState.Success(responseData)<br>            }<br>        }<br>    }<br>}</pre><pre>@Composable<br>fun HomeScreen(<br>    viewModel: HomeViewModel = getKoin().get(),<br>    onHeroClicked: (String) -&gt; Unit<br>) {<br>    val homeScreenState by viewModel.homeViewState.collectAsState()<br>    LaunchedEffect(Unit) {<br>        viewModel.getProducts()<br>    }<br>    Column(modifier = Modifier.fillMaxSize()) {<br>        when (homeScreenState) {<br>            is HomeViewModel.HomeScreenState.Loading -&gt; {<br>                // Show loading state<br>            }<br>            is HomeViewModel.HomeScreenState.Success -&gt; {<br>                val heroes = (homeScreenState as HomeViewModel.HomeScreenState.Success).responseData<br>                HomeUIContent(heroes = heroes, onHeroClicked = onHeroClicked)<br>            }<br>            is HomeViewModel.HomeScreenState.Error -&gt; {<br>                // Show error state<br>            }<br>        }<br>    }<br>}</pre><pre>@Composable<br>fun HomeUIContent(<br>    modifier: Modifier = Modifier,<br>    heroes: List&lt;HeroesResponse&gt;,<br>    onHeroClicked: (String) -&gt; Unit<br>) {<br>    LazyVerticalGrid(<br>        columns = GridCells.Fixed(3),<br>        modifier = modifier.fillMaxSize()<br>    ) {<br>        items(heroes) { hero -&gt;<br>            Column(<br>                horizontalAlignment = Alignment.CenterHorizontally,<br>                modifier = Modifier.clickable {<br>                    onHeroClicked.invoke(hero.display_name ?: &quot;&quot;)<br>                }<br>            ) {<br>                AsyncImage(<br>                    modifier = Modifier.size(50.dp).clip(RoundedCornerShape(5.dp)),<br>contentScale = ContentScale.Crop<br>)<br>Text(hero.display_name ?: &quot;&quot;)<br>               }<br>         }<br>     }<br> }</pre><h3>Wrap-Up</h3><p>Using Ktor and Koin in Compose Multiplatform can make your application development process more efficient and manageable. By leveraging Ktor’s powerful HTTP client and Koin’s dependency injection, you can effectively manage network requests and easily handle your application’s dependencies.</p><p>In this article, we explored creating a network layer with Ktor, configuring dependency injection with Koin, and retrieving data in a ViewModel to pass it to the UI. The flexibility of Ktor and the ease of use of Koin can provide significant advantages in your application development process.</p><p>I hope this article has been helpful in understanding how to use Ktor and Koin in your Compose Multiplatform projects. For more information and details, don’t forget to check the official documentation for the respective libraries!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93425032286f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose Multiplatform’da Ktor ve Koin Kullanımı]]></title>
            <link>https://medium.com/@alicansekban/compose-multiplatformda-ktor-ve-koin-kullan%C4%B1m%C4%B1-d7a506c0cd60?source=rss-dc069c78029e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7a506c0cd60</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Alican Sekban]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 17:43:01 GMT</pubDate>
            <atom:updated>2024-08-05T17:48:50.803Z</atom:updated>
            <content:encoded><![CDATA[<p>Merhaba! Bu makalede, Compose Multiplatform projelerinde Ktor ve Koin kullanımını ele alacağız. İlk olarak, Ktor’u kullanarak bir ağ katmanı oluşturacağız ve ardından Koin ile bağımlılık enjeksiyonunu nasıl yapacağımızı göstereceğiz. Daha sonra, verileri ViewModel’da alıp kullanıcı arayüzüne nasıl aktaracağımızı inceleyeceğiz. Bu örneklerde, kahramanların listesini ve detaylarını çeken bir uygulama geliştireceğiz.</p><h3>Bağımlılıklar</h3><p>Ktor ve Koin kullanmak için projenizin build.gradle.kts dosyasına aşağıdaki bağımlılıkları eklemeniz gerekmektedir. Aşağıdaki kod parçaları, Ktor&#39;un HTTP istemcisi, JSON işleme özellikleri ve Koin&#39;in bağımlılık enjeksiyonu yeteneklerini içerir.</p><h3>Ktor Bağımlılıkları</h3><pre>dependencies {<br>    implementation(&quot;io.ktor:ktor-client-core:2.3.1&quot;)<br>    implementation(&quot;io.ktor:ktor-client-cio:2.3.1&quot;)<br>    implementation(&quot;io.ktor:ktor-client-content-negotiation:2.3.1&quot;)<br>    implementation(&quot;io.ktor:ktor-serialization-kotlinx-json:2.3.1&quot;)<br>}</pre><h3>Koin Bağımlılıkları</h3><pre>dependencies {<br>    implementation(&quot;io.insert-koin:koin-core:3.4.0&quot;)<br>    implementation(&quot;io.insert-koin:koin-android:3.4.0&quot;) // Android için Koin<br>    implementation(&quot;io.insert-koin:koin-androidx-compose:3.4.0&quot;) // Jetpack Compose için Koin<br>}</pre><h3>Ağ Katmanı Oluşturma</h3><p>İlk adımımız, Ktor kullanarak bir ağ katmanı oluşturmaktır. Ktor, Kotlin Multiplatform projelerinde HTTP istemcisi olarak kullanılabilen güçlü bir kütüphanedir. Aşağıda, bir ağ isteğinin nasıl yönetileceğini gösteren NetworkRepository sınıfını ve toResultFlow fonksiyonunu bulabilirsiniz:</p><pre>import io.ktor.client.HttpClient<br>import io.ktor.client.request.get<br>import io.ktor.client.statement.body<br>import io.ktor.http.URLProtocol<br>import kotlinx.coroutines.flow.Flow<br>import kotlinx.coroutines.flow.flow<br>import kotlinx.serialization.json.Json</pre><pre>fun &lt;T&gt; toResultFlow(call: suspend () -&gt; NetWorkResult&lt;T?&gt;) : Flow&lt;NetWorkResult&lt;T&gt;&gt; {<br>    return flow {<br>        emit(NetWorkResult.Loading(true))<br>        val c = call.invoke()<br>        c.let { response -&gt;<br>            try {<br>                println(&quot;response${response.data}&quot;)<br>                emit(NetWorkResult.Success(response.data))<br>            } catch (e: Exception) {<br>                emit(NetWorkResult.Error(response.data, e.message ?: &quot;&quot;))<br>            }<br>        }<br>    }<br>}</pre><pre>sealed class NetWorkResult&lt;out T&gt;(val status: ApiStatus, val data: T?, val message: String?) {</pre><pre>    data class Success&lt;out T&gt;(val _data: T?) :<br>        NetWorkResult&lt;T&gt;(status = ApiStatus.SUCCESS, data = _data, message = null)</pre><pre>    data class Error&lt;out T&gt;(val _data: T?, val exception: String) :<br>        NetWorkResult&lt;T&gt;(status = ApiStatus.ERROR, data = _data, message = exception)</pre><pre>    data class Loading&lt;out T&gt;(val isLoading: Boolean) :<br>        NetWorkResult&lt;T&gt;(status = ApiStatus.LOADING, data = null, message = null)<br>}</pre><pre>enum class ApiStatus {<br>    SUCCESS,<br>    ERROR,<br>    LOADING,<br>}</pre><pre>class NetworkRepository(private val httpClient: HttpClient) {<br>    suspend fun getHeroes(): Flow&lt;NetWorkResult&lt;List&lt;HeroesResponse&gt;&gt;&gt; {<br>        return toResultFlow {<br>            val response = httpClient.get {<br>                url {<br>                    protocol = URLProtocol.HTTPS<br>                    host = Constants.BASE_URL_WITHOUT_HTTPS<br>                    path(&quot;heroes.json&quot;)<br>                }<br>            }.body&lt;List&lt;HeroesResponse&gt;&gt;()<br>            NetWorkResult.Success(response)<br>        }<br>    }</pre><pre>    suspend fun getHeroDetail(heroName: String): Flow&lt;NetWorkResult&lt;HeroesResponse&gt;&gt; {<br>        return toResultFlow {<br>            val response = httpClient.get {<br>                url {<br>                    protocol = URLProtocol.HTTPS<br>                    host = Constants.BASE_URL_WITHOUT_HTTPS<br>                    encodedPath = &quot;heroes/$heroName.json&quot;<br>                }<br>            }.body&lt;HeroesResponse&gt;()<br>            NetWorkResult.Success(response)<br>        }<br>    }<br>}</pre><p>Bu kod, ağ isteklerinin sonuçlarını bir Flow nesnesi olarak döndüren genel bir toResultFlow fonksiyonunu içerir. NetworkRepository sınıfı, kahramanların listesini ve bir kahramanın detaylarını çekmek için iki fonksiyon sunar.</p><h3>Koin Modüllerini Oluşturma</h3><p>Bir sonraki adımda, Koin kullanarak bağımlılık enjeksiyonunu yapılandıracağız. Koin, Kotlin projelerinde bağımlılık enjeksiyonu yapmak için kullanılan hafif bir kütüphanedir. Aşağıda, HTTP istemcisini, repository’leri ve view model’leri sağlayan Koin modüllerini bulabilirsiniz:</p><pre>import org.koin.dsl.module<br>import io.ktor.client.HttpClient<br>import io.ktor.client.plugins.contentnegotiation.ContentNegotiation<br>import io.ktor.http.ContentType<br>import kotlinx.serialization.json.Json</pre><pre>fun appModule() = listOf(providehttpClientModule, provideRepositoryModule, provideviewModelModule)</pre><pre>val providehttpClientModule = module {<br>    single {<br>        HttpClient {<br>            install(ContentNegotiation) {<br>                json(json = Json { ignoreUnknownKeys = true }, contentType = ContentType.Any)<br>            }<br>        }<br>    }<br>}</pre><pre>val provideRepositoryModule = module {<br>    single&lt;NetworkRepository&gt; { NetworkRepository(get()) }<br>}</pre><pre>val provideviewModelModule = module {<br>    single {<br>        HomeViewModel(get())<br>    }<br>    single {<br>        DetailViewModel(get())<br>    }<br>}</pre><p>Bu modüller, HTTP istemcisini, NetworkRepository sınıfını ve HomeViewModel ile DetailViewModel sınıflarını sağlar. Koin, bu bağımlılıkları otomatik olarak enjekte eder ve bu sayede kodunuzu daha temiz ve yönetilebilir hale getirir.</p><h3>Constants Dosyası</h3><p>Projede sabit değerleri yönetmek için bir Constants dosyası oluşturuyoruz</p><pre>object Constants {<br>    const val BASE_URL = &quot;https://omeda.city/&quot;<br>    const val BASE_URL_WITHOUT_HTTPS = &quot;omeda.city/&quot;<br>}</pre><p>Bu dosya, ağ isteklerinde kullanılacak temel URL’leri içerir.</p><h3>Verilerin ViewModel’da Alınması ve UI’a Aktarılması</h3><p>Verilerin ViewModel’da alınması ve kullanıcı arayüzüne aktarılması, modern uygulama geliştirmede önemli bir adımdır. Aşağıda, verileri HomeViewModel sınıfında nasıl alacağınızı ve UI&#39;a nasıl aktaracağınızı gösteren bir örnek bulabilirsiniz:</p><pre>import androidx.compose.runtime.*<br>import androidx.lifecycle.ViewModel<br>import androidx.lifecycle.viewModelScope<br>import kotlinx.coroutines.CoroutineScope<br>import kotlinx.coroutines.Dispatchers<br>import kotlinx.coroutines.flow.MutableStateFlow<br>import kotlinx.coroutines.flow.asStateFlow<br>import kotlinx.coroutines.flow.collect<br>import kotlinx.coroutines.launch<br>import org.koin.androidx.compose.getKoin</pre><pre>class HomeViewModel(private val networkRepository: NetworkRepository) : ViewModel() {</pre><pre>    private val _homeState = MutableStateFlow(HomeState())<br>    private val _homeViewState: MutableStateFlow&lt;HomeScreenState&gt; = MutableStateFlow(HomeScreenState.Loading)<br>    val homeViewState = _homeViewState.asStateFlow()</pre><pre>    suspend fun getProducts() {<br>        CoroutineScope(Dispatchers.IO).launch {<br>            try {<br>                networkRepository.getHeroes().collect { response -&gt;<br>                    when(response.status) {<br>                        ApiStatus.LOADING -&gt; {<br>                            _homeState.update { it.copy(isLoading = true) }<br>                        }<br>                        ApiStatus.SUCCESS -&gt; {<br>                            _homeState.update { it.copy(isLoading = false, errorMessage = &quot;&quot;, responseData = response.data ?: emptyList()) }<br>                        }<br>                        ApiStatus.ERROR -&gt; {<br>                            _homeState.update { it.copy(isLoading = false, errorMessage = response.message) }<br>                        }<br>                    }<br>                    _homeViewState.value = _homeState.value.toUiState()<br>                }<br>            } catch (e: Exception) {<br>                _homeState.update { it.copy(isLoading = false, errorMessage = &quot;Failed to fetch data&quot;) }<br>            }<br>        }<br>    }</pre><pre>    sealed class HomeScreenState {<br>        data object Loading: HomeScreenState()<br>        data class Error(val errorMessage: String): HomeScreenState()<br>        data class Success(val responseData: List&lt;HeroesResponse&gt;): HomeScreenState()<br>    }</pre><pre>    private data class HomeState(<br>        val isLoading: Boolean = false,<br>        val errorMessage: String? = null,<br>        val responseData: List&lt;HeroesResponse&gt; = emptyList()<br>    ) {<br>        fun toUiState(): HomeScreenState {<br>            return if (isLoading) {<br>                HomeScreenState.Loading<br>            } else if (errorMessage?.isNotEmpty() == true) {<br>                HomeScreenState.Error(errorMessage)<br>            } else {<br>                HomeScreenState.Success(responseData)<br>            }<br>        }<br>    }<br>}</pre><pre>@Composable<br>fun HomeScreen(<br>    viewModel: HomeViewModel = getKoin().get(),<br>    onHeroClicked: (String) -&gt; Unit<br>) {<br>    val homeScreenState by viewModel.homeViewState.collectAsState()<br>    LaunchedEffect(Unit) {<br>        viewModel.getProducts()<br>    }<br>    Column(modifier = Modifier.fillMaxSize()) {<br>        when (homeScreenState) {<br>            is HomeViewModel.HomeScreenState.Loading -&gt; {<br>                // Gösterilecek yükleme durumu<br>            }<br>            is HomeViewModel.HomeScreenState.Success -&gt; {<br>                val heroes = (homeScreenState as HomeViewModel.HomeScreenState.Success).responseData<br>                HomeUIContent(heroes = heroes, onHeroClicked = onHeroClicked)<br>            }<br>            is HomeViewModel.HomeScreenState.Error -&gt; {<br>                // Hata durumu göster<br>            }<br>        }<br>    }<br>}</pre><pre>@Composable<br>fun HomeUIContent(<br>    modifier: Modifier = Modifier,<br>    heroes: List&lt;HeroesResponse&gt;,<br>    onHeroClicked: (String) -&gt; Unit<br>) {<br>    LazyVerticalGrid(<br>        columns = GridCells.Fixed(3),<br>        modifier = modifier.fillMaxSize()<br>    ) {<br>        items(heroes) { hero -&gt;<br>            Column(<br>                horizontalAlignment = Alignment.CenterHorizontally,<br>                modifier = Modifier.clickable {<br>                    onHeroClicked.invoke(hero.display_name ?: &quot;&quot;)<br>                }<br>            ) {<br>                AsyncImage(<br>                    modifier = Modifier.size(50.dp).clip(RoundedCornerShape(5.dp)),<br>contentScale = ContentScale.Crop<br>)<br>Text(hero.display_name ?: &quot;&quot;)<br>               }<br>         }<br>     }<br> }</pre><h3>Sonuç</h3><p>Compose Multiplatform’da Ktor ve Koin kullanmak, uygulama geliştirme sürecinizi daha verimli ve yönetilebilir hale getirebilir. Ktor’un güçlü HTTP istemcisi ve Koin’in bağımlılık enjeksiyonunu kullanarak, hem ağ isteklerinizi etkili bir şekilde yönetebilir hem de uygulamanızın bağımlılıklarını kolayca yönetebilirsiniz.</p><p>Bu makalede, Ktor kullanarak bir ağ katmanı oluşturmayı, Koin ile bağımlılık enjeksiyonunu yapılandırmayı ve verileri ViewModel’da alıp UI’a aktarmayı inceledik. Ktor’un esnekliği ve Koin’in kullanım kolaylığı sayesinde, uygulama geliştirme sürecinizde önemli avantajlar sağlayabilirsiniz.</p><p>Umarım bu makale, Compose Multiplatform projelerinizde Ktor ve Koin kullanımı konusunda size faydalı olmuştur. Daha fazla bilgi ve detay için ilgili kütüphanelerin resmi belgelerine göz atmayı unutmayın!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7a506c0cd60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose Multiplatform’da WebView Kullanımı]]></title>
            <link>https://medium.com/@alicansekban/compose-multiplatformda-webview-kullan%C4%B1m%C4%B1-1d515464aabf?source=rss-dc069c78029e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d515464aabf</guid>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Alican Sekban]]></dc:creator>
            <pubDate>Sun, 04 Aug 2024 09:14:42 GMT</pubDate>
            <atom:updated>2024-08-04T09:27:10.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Günümüzde, farklı platformlarda çalışabilen uygulamalar geliştirmek büyük bir avantaj sağlıyor. Compose Multiplatform, bu konuda oldukça güçlü bir araç olarak karşımıza çıkıyor. Bu yazıda, Compose Multiplatform kullanarak nasıl WebView ekleyebileceğinizi anlatacağım.</p><h3>Giriş</h3><p>Compose Multiplatform, Android ve diğer platformlarda kullanıcı arayüzü oluşturmayı kolaylaştıran bir kütüphanedir. Ancak, bazen uygulamanızda web içeriği göstermeniz gerekebilir. Bu durumda WebView bileşeni devreye girer. compose-webview-multiplatform kütüphanesi, Compose Multiplatform&#39;da WebView kullanmanızı sağlar.</p><h3>Gerekli Bağımlılıklar</h3><p>Öncelikle, projenize compose-webview-multiplatform kütüphanesini eklemeniz gerekmektedir. Bu kütüphane, WebView bileşenini kullanabilmenizi sağlar. build.gradle.kts dosyanıza aşağıdaki bağımlılığı ekleyin:</p><pre>dependencies {<br>    implementation(&quot;io.github.kevinnzou:compose-webview-multiplatform:1.9.20&quot;)<br></pre><h3>WebView Kullanımı</h3><p>WebView’i kullanmak için öncelikle bir WebViewState nesnesine ihtiyacımız var. Bu nesne, WebView&#39;in durumu hakkında bilgi sağlar ve URL&#39;yi belirtebilmemizi sağlar. Örneğin, aşağıdaki kodda GitHub profilinizi göstermek için bir WebView oluşturuyoruz:</p><pre>val webViewState = rememberWebViewState(&quot;https://github.com/alicansekban&quot;)</pre><pre>MaterialTheme {<br>    WebView(<br>        state = webViewState,<br>        modifier = Modifier.fillMaxSize()<br>    )<br>}</pre><h3>Adım Adım Uygulama</h3><ol><li><strong>Proje Kurulumu:</strong> Öncelikle, yeni bir Compose Multiplatform projesi oluşturun veya mevcut projenizi açın.</li><li><strong>Bağımlılık Ekleme:</strong> build.gradle.kts dosyanıza compose-webview-multiplatform bağımlılığını ekleyin.</li><li><strong>WebViewState Oluşturma:</strong> Gösterilecek URL’yi belirterek bir WebViewState oluşturun.</li><li><strong>WebView Bileşeni Ekleyin:</strong> MaterialTheme içinde WebView bileşenini kullanarak oluşturduğunuz WebViewState ile birlikte ekleyin.</li><li><strong>UI Güncelleme:</strong> WebView bileşenini uygun bir şekilde yerleştirin ve gerekli düzenlemeleri yapın.</li></ol><h3>Tam Kod Örneği</h3><p>Aşağıda, yukarıdaki adımları takip ederek oluşturduğumuz tam bir kod örneğini bulabilirsiniz</p><pre>import androidx.compose.material.MaterialTheme<br>import androidx.compose.runtime.Composable<br>import androidx.compose.ui.Modifier<br>import androidx.compose.ui.platform.setContent<br>import com.google.accompanist.web.WebView<br>import com.google.accompanist.web.rememberWebViewState</pre><pre>@Composable<br>fun WebViewExample() {<br>    val webViewState = rememberWebViewState(&quot;https://github.com/alicansekban&quot;)<br>    MaterialTheme {<br>        WebView(<br>            state = webViewState,<br>            modifier = Modifier.fillMaxSize()<br>        )<br>    }<br>}</pre><pre>fun main() {<br>    setContent {<br>        WebViewExample()<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qa05Lebn9C8Cq3o7NqZGDw.png" /></figure><h3>Sonuç</h3><p>Compose Multiplatform’da WebView kullanmak, uygulamanızın işlevselliğini artırmanın harika bir yoludur. compose-webview-multiplatform kütüphanesi sayesinde bu işlemi oldukça kolay bir şekilde gerçekleştirebilirsiniz. Yukarıdaki adımları takip ederek siz de kendi projelerinizde WebView bileşenini kullanabilir ve kullanıcılarınıza zengin bir web deneyimi sunabilirsiniz.</p><p>Umarım bu makale, Compose Multiplatform projelerinizde WebView kullanımı konusunda size yardımcı olmuştur. Daha fazla bilgi ve detay için resmi belgelere göz atmayı unutmayın!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d515464aabf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>