<?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 Morgane Soula on Medium]]></title>
        <description><![CDATA[Stories by Morgane Soula on Medium]]></description>
        <link>https://medium.com/@morganes56?source=rss-e368cd7aa90b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hv5bKcCS1PA33LF4.jpg</url>
            <title>Stories by Morgane Soula on Medium</title>
            <link>https://medium.com/@morganes56?source=rss-e368cd7aa90b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:37:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@morganes56/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[Integrate Sign-In with Apple via Firebase in KMP & CMP]]></title>
            <link>https://medium.com/@morganes56/integrate-sign-in-with-apple-via-firebase-in-a-compose-multiplatform-project-b951e524d610?source=rss-e368cd7aa90b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b951e524d610</guid>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Morgane Soula]]></dc:creator>
            <pubDate>Thu, 15 May 2025 16:49:51 GMT</pubDate>
            <atom:updated>2025-05-28T12:43:24.425Z</atom:updated>
            <content:encoded><![CDATA[<p>I am currently migrating my personal project, <a href="https://github.com/morganesoula/hobby-matchmaker/tree/convention_plugin">HobbyMatchMaker</a> (HMM), from an Android-native codebase to <a href="https://www.jetbrains.com/kotlin-multiplatform/">Kotlin Multiplatform</a> (KMP). With an Android background, I am completely new to the iOS ecosystem — but after 7 years of development experience, I am confident enough to overcome any difficulty I may encounter.</p><p>Like most apps, HMM opens with a sign-in/sign-up screen:</p><ol><li>On the Android side, users can sign in using email/password, Facebook, or Google.</li><li>On the Apple side, I wanted to support email/password, Apple and Google.</li></ol><p>All of these methods are implemented using a Firebase wrapper made for KMP: <a href="https://github.com/GitLiveApp/firebase-kotlin-sdk">GitLive</a>. The library makes Firebase APIs available for any platform.</p><p>Setting up the Android part was pretty straightforward, so I won’t dwell on it here. There are already plenty of tutorials, YouTube videos and, Medium articles covering the topic. Integrating Google Sign-In for iOS was also relatively simple, and again, well documented.</p><p>The real difficulty I encountered was implementing Apple Sign-In <strong>without using SwiftUI</strong>. So let’s dive into it!</p><p>To keep this article as simple and straightforward as possible, I won’t explain how the application works in detail. Just keep in mind that I am working on a <strong>multi-modular project</strong> using MVVM and Clean Architecture. Each of my module implements these three sources sets: <em>commonMain</em>, <em>androidMain</em> and, <em>iosMain</em>. My shared main module is called <em>composeApp</em>.</p><p>With that in mind, let me quickly explain how I decoupled the authentication part:</p><ol><li>Authentication module: No ui layer, only data and domain. This module calls the remote data source (Firebase, in this case) and all network-related use cases are defined here (password reset, sign in, sign up, log out, etc…).</li><li>Login module: no data layer, only domain and presentation. This one handles user interaction. It contains the SignIn and SignUp ViewModels, which delegate to the authentication use cases.</li><li>Session module: no ui layer, only data and domain. This module handles anything happening after the user is logged in. I use it to store any information related to the current session.</li></ol><p>Let’s take a look at the workflow I am trying to achieve when the user clicks on the custom Sign-In with Apple button.</p><p>On the UI side, I implement different Composables depending on the source set, using expect/actual.</p><pre>// core:login:presentation:components: PlatformSpecificUI (commonMain)<br><br>@Composable<br>expect fun SocialMediaButtonListPlatformSpecificUI(<br>    modifier: Modifier,<br>    signInState: SignInEvent,<br>    onFacebookButtonClicked: ((credential: AuthCredential) -&gt; Unit)? = null,<br>    onAppleButtonClicked: (() -&gt; Unit)? = null,<br>    onGoogleButtonClicked: () -&gt; Unit,<br>    facebookUIClient: FacebookUIClient?<br>)</pre><p>In <em>androidMain</em>, I implement Google and Facebook sign-in. In <em>iosMain</em>, I implement Google and Apple. Here’s an example of my Google Sign-in button. The same logic applies for the other social buttons.</p><pre>// core:login:presentation:components:SocialMediaComponent (androidMain)<br><br>OutlinedButton(<br>   onClick = { onGoogleButtonClicked() },<br>   shape = RoundedCornerShape(4.dp),<br>   colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent),<br>   modifier = modifier.size(80.dp)<br>) {<br>   Image(<br>       modifier = modifier,<br>       painter = painterResource(Res.drawable.google_logo),<br>       contentDescription = stringResource(Res.string.google_alt)<br>   )<br>}</pre><p>When the user clicks on one of these buttons, an event is triggered in the ViewModel, calling the corresponding UseCase.</p><pre>// core:login:presentation:signIn:SignInViewModel (commonMain)<br><br>    private fun launchSocialSignIn(<br>        providerType: ProviderType,<br>        fetchedCredential: AuthCredential? = null<br>    ) {<br>        if (isSignIn) return<br>        isSignIn = true<br><br>        viewModelScope.launch(Dispatchers.IO) {<br>            val client = socialClients[providerType]<br>            val credential = fetchedCredential ?: client?.getCredential()<br><br>            if (credential != null) {<br>                signInUnified(<br>                    UnifiedSignInUseCase.Params.SocialMedia(<br>                        credential, providerType<br>                    )<br>                )<br>            } else {<br>                Logger.e(&quot;Could not load social credentials&quot;)<br>                _signInState.value = SignInEvent.Error(&quot;Unable to get credentials&quot;)<br>                isSignIn = false<br>            }<br>        }<br>    }</pre><p>The <em>providerType</em> parameter is an enum class representing any social media provider I would use by the app. This makes the implementation <strong>easily extensible</strong>: if you want to implement a new provider — like Twitter- you start by adding it to the enum, then implement the logic.</p><pre>// core:authentication:domain:models:ProviderType (commonMain)<br><br>enum class ProviderType(val className: String) {<br>    GOOGLE(&quot;GoogleAuthProvider&quot;),<br>    FACEBOOK(&quot;FacebookAuthProvider&quot;),<br>    APPLE(&quot;AppleAuthProvider&quot;)<br>}</pre><p>From there, the logic flows through the <em>different layers</em> — following the Clean Architecture principles- until it reaches the data source.</p><pre>// core:authentication:domain:useCases:UnifiedSignInUseCase (commonMain)<br>// Excerpt from the signIn method<br><br>is Params.SocialMedia -&gt; channelFlow {<br>            try {<br>                send(Result.Loading)<br><br>                when (val result = signInWithCredentialUseCase(<br>                    params.credential, params.providerType<br>                )) {<br><br>                    is Result.Success -&gt; {<br>                        setIsConnectedUseCase(true)<br>                        send(Result.Success(SignInSuccess))<br>                    }<br><br>                    is Result.Failure -&gt; send(Result.Failure(SignInError.Other(result.error.message<br>                        .ifBlank { &quot;Apple Sign-In failed&quot; })))<br>                    else -&gt; Unit<br>                }<br>            } catch (e: Exception) {<br>                send(Result.Failure(SignInError.Other(&quot;Crash: ${e.message}&quot;)))<br>            } finally {<br>                close()<br>            }<br>        }</pre><pre>// core:authentication:data:dataSources:<br>// remote:AuthenticationRemoteDataSourceImpl (commonMain)<br><br>    override suspend fun signInWithCredentials(<br>        credential: AuthCredential,<br>        providerType: ProviderType<br>    ): Result&lt;FirebaseUserInfoDomainModel, SocialMediaError&gt; {<br>        return try {<br>            when (val result = authManager.signIn(providerType, credential)) {<br>                is Result.Success -&gt; Result.Success(result.data)<br>                is Result.Failure -&gt; Result.Failure(SocialMediaError.SignInWithCredentialsError)<br>                else -&gt; Result.Failure(SocialMediaError.SignInWithCredentialsError)<br>            }<br>        } catch (e: Exception) {<br>            Logger.e(&quot;Exception caught while signing in with credentials: ${e.message}&quot;)<br>            Result.Failure(SocialMediaError.SignInWithCredentialsError)<br>        }<br>    }</pre><p>There are two key questions here:</p><ol><li>What does client.getCredential() do in <em>launchSocialSignIn</em>()?</li><li>What does authManager.signIn() do in <em>signInWithCredentials</em>()?</li></ol><p>The SignInUseCase takes a credential parameter that each social media provider must supply. The provider client is initialized in the <em>presentation </em>layer<em>, </em>as it often requires access to the platform-specific context (such as Google). Let’s focus on the Apple case as promised.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFr0OSXLnM4k8OheOzTK5Q.png" /></figure><h3>Step 1 — Define an abstraction for Apple UI interaction</h3><p>I start by creating an AppleUIClient interface in <em>commonMain</em>. Then, I implement a SocialUIClient wrapper for it. Follow the same pattern across all providers.</p><pre>// core:login:presentation:clients:AppleUIClient (commonMain)<br><br>interface AppleUIClient {<br>    suspend fun getAppleCredentials(): AuthCredential?<br>}<br><br>class AppleUIClientImpl(<br>    private val appleUIClient: AppleUIClient<br>) : SocialUIClient {<br><br>    override val providerType: ProviderType<br>        get() = ProviderType.APPLE<br><br>    override suspend fun getCredential(): AuthCredential? {<br>        return appleUIClient.getAppleCredentials()<br>    }<br>}</pre><h3>Step 2 — Implement the iOS-specific logic</h3><p>In the <em>iosMain</em> source set, define an AppleClient class that will provide the actual implementation using a <strong>bridge</strong> to native code (I will explain). The <em>IosAppleUIClient</em> returns an <em>AuthCredential</em>, as expected by Firebase.</p><pre>// core:login:presentation:clients:IosAppleUIClient (iosMain)<br><br>import nativeIosAuthShared.AppleSignInManager<br><br>@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)<br>class IosAppleUIClient : AppleUIClient {<br><br>    override suspend fun getAppleCredentials(): AuthCredential? {<br>        return suspendCancellableCoroutine { continuation -&gt;<br>            AppleSignInManager.shared().signInWithApple { token, nonce, error -&gt;<br>                when {<br>                    token != null &amp;&amp; nonce != null -&gt; {<br>                        val credential = OAuthProvider.credential(<br>                            providerId = &quot;apple.com&quot;,<br>                            idToken = token,<br>                            rawNonce = nonce<br>                        )<br>                        continuation.resume(credential)<br>                    }<br><br>                    error != null -&gt; {<br>                        Logger.e(&quot;Error in getAppleCredentials is: $error&quot;)<br>                        continuation.resumeWithException(Exception(error))<br>                    }<br><br>                    else -&gt; continuation.resumeWithException(Exception(&quot;Unknown Apple Sign-In failure&quot;))<br>                }<br>            }<br>        }<br>    }<br>}</pre><h3>Step 3 — Native iOS bridge</h3><p>The <em>AppleSignInManager</em> class is implemented in Swift, on the native iOS side. To build it, I recommend to rely on: <a href="https://firebase.google.com/docs/auth/ios/apple">Firebase documentation</a> and ChatGPT. Do not forget to cross check any code IA provide with some Google research.</p><p>You might be wondering why we can’t just do all of this directly in Kotlin.<br>Technically speaking, <strong>Sign-In with Apple </strong>on iOS <strong>requires </strong>deep integration with the native framework <em>AuthenticationServices</em>, especially <em>ASAuthorizationController</em> and its delegate callbacks. Kotlin/Native does not provide high-level bindings for these classes (yet).</p><p>Additionally, Firebase expects a token (named <em>idToken</em>) issued by Apple, using the proper <strong>Service ID</strong> defined in your Firebase project settings.<br>This token <strong>must</strong> be requested through the native Apple Sign-In flow — otherwise, Firebase will reject it (invalid “aud” — for audience- claim, for instance).</p><p>That’s why I used a Swift class <em>AppleSignInManager</em> to handle the authorization flow and return the result via a Kotlin callback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WY1VZtN4ec-G1fJcBnknfQ.png" /></figure><p>How can you integrate native Swift code into your Kotlin Multiplatform project? By using <a href="https://www.linkedin.com/in/francois-dabonot/">François</a> library: <a href="https://github.com/frankois944/spm4Kmp?tab=readme-ov-file">spm4Kmp</a>. This library is a great alternative to CocoaPods for integrating Swift Packages. It also makes it <strong>so easy</strong> to use Swift native code within a KMP project.</p><p>First, add the spm4Kmp plugin to your project. Then, in your module-level <em>build.gradle</em>, apply the following configuration as shown in the following snippet (inside <strong>kotlin</strong> block).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*npGKoxPpPlc0rFUCmxcTew.png" /><figcaption>(excerpt from build.gradle.kts — core:login:presentation)</figcaption></figure><p>Still in the same file, but outside the kotlin block, add the Swift configuration block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*5694YBmncz-XmyDAjy9oaw.png" /><figcaption>(excerpt from build.gradle.kts — core:login:presentation)</figcaption></figure><p>Careful, the cinterop name <strong>has</strong> to match the one defined in the swiftPackageConfig block.</p><p>After rebuilding, you will notice a new swift/ directory with a nativeIosAuthShared/ (or whichever name you specified) sub-module inside it. You can now place your Swift classes in the sub-module to make it accessible across the KMP project, through your Kotlin code via interop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*EO4TzK9fUQQtNLWABZXz_A.png" /></figure><p>Here is the content of the native Swift file (do not forget the imports — they are required to access the necessary iOS frameworks and will not import by themselves):</p><pre>import UIKit<br>import AuthenticationServices<br>import Foundation<br>import CryptoKit<br><br>@objcMembers public class AppleSignInManager: NSObject {<br>    @objc public static let shared = AppleSignInManager()<br>    private var callback: ((String?, String?, String?) -&gt; Void)?<br><br>    private var currentNonce: String?<br><br>    @available(iOS 13, *)<br>    @objc public func signInWithApple(_ completion: @escaping (String?, String?, String?) -&gt; Void) {<br>        self.currentNonce = randomNonceString()<br>        self.callback = completion<br><br>        let appleIDProvider = ASAuthorizationAppleIDProvider()<br>        let request = appleIDProvider.createRequest()<br>        request.requestedScopes = [.fullName, .email]<br>        request.nonce = sha256(currentNonce!)<br><br>        let authorizationController = ASAuthorizationController(authorizationRequests: [request])<br>        authorizationController.delegate = self<br>        authorizationController.presentationContextProvider = self<br>        authorizationController.performRequests()<br>    }<br><br>    @available(iOS 13, *)<br>    private func sha256(_ input: String) -&gt; String {<br>        let inputData = Data(input.utf8)<br>        let hashedData = SHA256.hash(data: inputData)<br>        let hashString = hashedData.compactMap {<br>            String(format: &quot;%02x&quot;, $0)<br>        }.joined()<br><br>        return hashString<br>    }<br><br>    private func randomNonceString(length: Int = 32) -&gt; String {<br>        precondition(length &gt; 0)<br>        var randomBytes = [UInt8](repeating: 0, count: length)<br>        let errorCode = SecRandomCopyBytes(kSecRandomDefault, randomBytes.count, &amp;randomBytes)<br>        if errorCode != errSecSuccess {<br>            fatalError(<br>                &quot;Unable to generate nonce. SecRandomCopyBytes failed with OSStatus \(errorCode)&quot;<br>            )<br>        }<br><br>        let charset: [Character] =<br>            Array(&quot;0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._&quot;)<br><br>        let nonce = randomBytes.map { byte in<br>            charset[Int(byte) % charset.count]<br>        }<br><br>        return String(nonce)<br>    }<br><br>}<br><br>extension AppleSignInManager: ASAuthorizationControllerDelegate {<br>    public func authorizationController(<br>        controller: ASAuthorizationController,<br>        didCompleteWithAuthorization authorization: ASAuthorization<br>    ) {<br>        guard<br>            let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential,<br>            let identityTokenData = appleIDCredential.identityToken,<br>            let tokenString = String(data: identityTokenData, encoding: .utf8),<br>            let nonce = currentNonce else {<br>                callback?(nil, nil, &quot;Unable to parse Apple ID credentials.&quot;)<br>                return<br>            }<br><br>            callback?(tokenString, nonce, nil)<br>    }<br><br>    public func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: any Error) {<br>        callback?(nil, nil, error.localizedDescription)<br>    }<br>}<br><br>extension AppleSignInManager: ASAuthorizationControllerPresentationContextProviding {<br>    public func presentationAnchor(for controller: ASAuthorizationController) -&gt; ASPresentationAnchor {<br>        return UIApplication.shared.windows.first { $0.isKeyWindow }!<br>    }<br>}</pre><p>This class handles the complete Apple Sign-In authorization flow, including nonce generation (as highly suggested by Firebase) and result forwarding to Kotlin via a callback.</p><p>Do not forget to enable “Sign in with Apple” in your app’s capability. In XCode, select your target &gt; Signing &amp; Capabilites &gt; add capability (plus sign) &gt; Sign in with Apple. You can find the full instructions here: <a href="https://developer.apple.com/help/account/capabilities/about-sign-in-with-apple/">https://developer.apple.com/help/account/capabilities/about-sign-in-with-apple/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJS3PnHWbV-MA_bFPBlbrQ.png" /></figure><p>After adding your Swift file inside the <em>swift/nativeIosAuthShared/</em> directory and rebuilding your project, you will be able to call it from Kotlin. Import the directory in your iOS source set file and you will get your credentials!</p><pre>import nativeIosAuthShared.AppleSignInManager</pre><p>It was a <strong>big piece</strong> so let’s wrap it up with the last piece of this puzzle: what exactly happens inside <em>authManager.signIn()</em> in the data source?</p><h3>Step 1 — Selecting the right provider</h3><p>The <em>AuthManager</em> class is a generic utility that receives a list of authentication providers. It is responsible for delegating authentication calls (such as sign-in and sign-out) to the correct provider based on the input.</p><pre>// core:authentication:data:dataSources:remote:AuthManager (commonMain)<br><br>class AuthManager(private val providers: List&lt;AuthProvider&gt;) {<br><br>    suspend fun signIn(<br>        providerType: ProviderType,<br>        credential: AuthCredential<br>    ): Result&lt;FirebaseUserInfoDomainModel, ProviderError&gt; {<br>        val provider = providers.find { it::class.simpleName == providerType.className }<br>            ?: return Result.Failure(ProviderError.NoProviderFound(&quot;Provider not found&quot;))<br><br>        return provider.signIn(credential)<br>    }<br><br>    // Other methods like sign-out<br>}</pre><p>This pattern makes it very easy to extend the authentication logic. Each provider (such as Apple or Google) implements its own behavior and is injected into the manager. At runtime, the right one is selected based on <em>providerType</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUXN8qERjdHcM0AexrY6Nw.png" /></figure><h3>Step 2 — Firebase Sign-in on iOS</h3><p>For Apple Sign-In specifically, here’s what is happening under the hood:</p><pre>// core:authentication:data:dataSources:remote:AppleAuthProvider (iosMain)<br><br>class AppleAuthProvider(<br>    private val auth: FirebaseAuth<br>) : AuthProvider {<br><br>    override suspend fun signIn(credentials: AuthCredential): Result&lt;FirebaseUserInfoDomainModel, ProviderError&gt; {<br>        return try {<br>            val result = auth.signInWithCredential(credentials)<br>            val user = result.user<br><br>            if (user != null) {<br>                Result.Success(<br>                    FirebaseUserInfoDomainModel(<br>                        uid = user.uid,<br>                        email = user.email ?: &quot;&quot;,<br>                        providers = user.providerData.map { it.providerId }<br>                    )<br>                )<br>            } else {<br>                Result.Failure(ProviderError.AppleSignInError(&quot;User is null&quot;))<br>            }<br>        } catch (e: Exception) {<br>            Logger.e(&quot;❌ Apple sign-in exception: ${e::class.simpleName} - ${e.message}&quot;)<br>            e.printStackTrace()<br>            Result.Failure(ProviderError.AppleSignInError(&quot;Firebase sign-in failed: ${e.message ?: &quot;Unknown error&quot;}&quot;))<br>        }<br>    }<br><br>    // Other methods<br>}</pre><p>This implementation:</p><ol><li>Takes the AuthCredential (previously generated with the <em>AppleSignInManager</em>, as explained above)</li><li>Calls the Firebase SDK to authenticate the user</li><li>Returns a domain model if the authentication succeeds</li></ol><h3>Conclusion</h3><p>This architecture brings <strong>flexibility, clear separation of concerns</strong>, and <strong>easy extensibility </strong>(all while staying testable and clean).<br> Adding support for a new provider (like Twitter or GitHub) would only require implementing a new <em>AuthProvider</em> and registering it in the <em>AuthManager</em>.</p><p>I did not go into details about how to set up your Firebase project, configure your Apple Developer account, or define which providers are available in each source set. These parts are often specific to the tools you use: in my case, I rely on <a href="https://github.com/arkivanov/Decompose">Decompose</a> for navigation and <a href="https://insert-koin.io/docs/reference/koin-mp/kmp/">Koin</a> for dependency injection. If you are curious — or using the same stack — you will find everything in MainActivity (<em>androidMain</em>) and MainViewController (<em>iosMain</em>).</p><p>You can find the whole project on my <a href="https://github.com/morganesoula/hobby-matchmaker/tree/convention_plugin">Github</a> (do not forget to navigate through the branches).</p><p>Let’s connect on <a href="https://www.linkedin.com/in/morgane-soula-08b33312a/">LinkedIn</a> if you want to see more of this project or my work!</p><p>As always, keep coding, exploring new topics and, most importantly, keep enjoying it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b951e524d610" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Junior to Senior: Evolving UseCases and ViewModel in Android Clean Architecture]]></title>
            <link>https://medium.com/@morganes56/from-junior-to-senior-evolving-usecases-and-viewmodel-in-android-clean-architecture-e88725161855?source=rss-e368cd7aa90b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e88725161855</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Morgane Soula]]></dc:creator>
            <pubDate>Fri, 10 Jan 2025 17:37:19 GMT</pubDate>
            <atom:updated>2025-01-10T17:37:19.076Z</atom:updated>
            <content:encoded><![CDATA[<p>Back to this series with a new chapter! This time, I am diving into how my implementation of UseCases and ViewModel in Android Clean Architecture projects has evolved over the years. Let’s dive in!</p><p>As usual, I will use my personal project <a href="https://github.com/morganesoula/hobby-matchmaker">HobbyMatchMaker</a> to illustrate the concepts. This project adheres to Clean Architecture principles and leverages the latest native Android libraries. For simplicity, we will focus solely on one feature: movies.</p><p>Back when I was a <strong>Junior</strong>, armed with knowledge from <a href="https://www.youtube.com/@PhilippLackner">Philipp Lackner</a>’s videos, Medium articles, and Google’s documentation, I created my first draft of a MovieViewModel. The ViewModel’s sole responsibility was to fetch movies from a remote source (TMDB api). Here’s how it looked:</p><pre>// MovieViewModel.kt<br><br>private fun initMovies() {<br>   viewModelScope.launch {<br>      getMovieUseCase()<br>         .collect { result -&gt;<br>             when (result) {<br>                 is MovieUiStateResult.Loading -&gt; <br>                    _movieStateUi.update { it.copy(isLoading = true) }<br>                 is MovieUiStateResult.Error -&gt; <br>                    _movieStateUi.update { <br>                        it.copy(error = result.throwable?.message) <br>                    }<br>                 is MovieUiStateResult.Fetched -&gt; {<br>                     _movieStateUi.update { it.copy(movies = result.list) }<br>                 }<br>             }<br>          }<br>   }<br>}</pre><p>The initMovies() method was invoked directly from init block of the ViewModel. The GetMovieUseCase injected into the ViewModel constructor looked like this:</p><pre>// GetMovieUseCase.kt<br><br>fun interface GetMovieUseCase : () -&gt; Flow&lt;MovieUiStateResult&gt;<br><br>fun getMovies(<br>    movieRepository: MovieRepository,<br>    mapper: MapMovieEntityToMovie<br>): Flow&lt;MovieUiStateResult&gt; {<br>    return movieRepository<br>        .getMoviesByPopularityDesc()<br>        .map { movies -&gt;<br>            if (movies.isEmpty()) {<br>                MovieUiStateResult.Error(Exception(&quot;Empty movies&quot;))<br>            } else {<br>                MovieUiStateResult.Fetched(mapper.mapList(movies))<br>            }<br>        }<br>        .catch {<br>            emit(MovieUiStateResult.Error(it.cause))<br>        }<br>}</pre><p><strong>Where I Went Wrong</strong></p><p>In Clean Architecture, the core principles revolve around three main layers: data, domain and presentation.</p><ol><li>Domain lies in the center and serves as the foundation. It <strong>never adapts</strong> for the other layers.</li><li>Data and presentation layers interact with it but never directly modify its behavior.</li></ol><p>Looking back, I see a critical flaw and understanding of Clean Architecture: I was treating my UseCase, as part of the presentation later, by mapping data from the data layer directly to the UI. This violated the principle of separation of concerns.</p><p>Overall the implementation wasn’t terrible even though it had (a lot of) room for improvement:</p><ol><li>Incorrect mapping as mentioned above.</li><li>Misuses of interfaces: I was inspired by an article advocating for using the interfaces but to be honest, I did not fully grasp the understanding behind it, leading to a copy-paste approach.</li><li>Bad practice in initialization: Initializing data in the ViewModel’s init block is generally considered poor practice. Developers like <a href="https://proandroiddev.com/mastering-android-viewmodels-essential-dos-and-donts-part-1-%EF%B8%8F-bdf05287bca9">Raza</a> or <a href="https://www.youtube.com/watch?v=mNKQ9dc1knI">Lackner</a> have both explained the risks involved.</li><li>Lack of reactivity: My ViewModel wasn’t reactive. Ideally it should observe the database and react dynamically whenever movies are updated.</li></ol><p>After additional research on the subject and many discussions with experienced Android developers, I was guided to improve my ViewModel. This period also marked the transition, in my opinion, between being a Junior developer and an Intermediate one.</p><p>So here’s to my second iteration of my <a href="https://github.com/morganesoula/hobby-matchmaker/blob/koin_migration/feature/movies/domain/src/main/java/com/msoula/hobbymatchmaker/features/movies/domain/use_cases/ObserveAllMoviesUseCase.kt">UseCase</a></p><pre>// ObserveAllMoviesUseCase<br><br>class ObserveAllMoviesUseCase(private val movieRepository: MovieRepository) {<br>    operator fun invoke(): Flow&lt;List&lt;MovieDomainModel&gt;&gt; {<br>        return movieRepository.observeMovies()<br>    }<br>}</pre><p><strong>What I improved</strong></p><p>In this version, the UseCase contains only code that I would be able to explain to anybody (meaning recruiters/companies). It is straightforward: it simply relays results from the data layer. Also, it is placed in the correct architectural layer: domain.</p><p>I changed the nomenclature from <em>Get</em> to <em>Observe </em>to better reflect its purpose. The movies it observes are fetched only when necessary. The only purpose of this UseCase is to observe changes. And finally, the repository is injected to make it easier to test.</p><p>Let’s take a look at the <a href="https://github.com/morganesoula/hobby-matchmaker/blob/koin_migration/feature/movies/presentation/src/main/java/com/msoula/hobbymatchmaker/features/movies/presentation/MovieViewModel.kt">ViewModel</a>:</p><pre>// MovieViewModel.kt<br><br>    val movieState: StateFlow&lt;MovieUiStateModel&gt; =<br>        observeAllMoviesUseCase()<br>            .combine(fetchStatusFlow) { movies, fetchStatus -&gt;<br>                Pair(movies, fetchStatus)<br>            }.mapLatest { (movies, fetchStatus) -&gt;<br>                when {<br>                    movies.isEmpty() -&gt; {<br>                        when (fetchStatus) {<br>                            is FetchStatusModel.Error -&gt; MovieUiStateModel.Error(fetchStatus.error)<br>                            is FetchStatusModel.Loading -&gt; MovieUiStateModel.Loading<br>                            is FetchStatusModel.Success -&gt; MovieUiStateModel.Empty<br>                            FetchStatusModel.NeverFetched -&gt; {<br>                                fetchMovies()<br>                                MovieUiStateModel.Loading<br>                            }<br>                        }<br>                    }<br><br>                    else -&gt; {<br>                        if (fetchStatus is FetchStatusModel.Error) {<br>                            _oneTimeEventChannel.send(<br>                                MovieUiEventModel.OnMovieUiFetchedError(fetchStatus.error)<br>                            )<br>                        }<br><br>                        MovieUiStateModel.Success(<br>                            list = movies.map { it.toMovieUiModel() }.toPersistentList()<br>                        )<br>                    }<br>                }<br>            }<br>            .flowOn(Dispatchers.Main)<br>            .stateIn(<br>                viewModelScope,<br>                SharingStarted.WhileSubscribed(5000),<br>                MovieUiStateModel.Loading<br>            )<br><br></pre><p>We use the power of the flow methods such as <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html">combine</a> or <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-latest.html">mapLatest</a>. It looks more modern and less “youngish”.</p><p>We are also more reactive as we are observing two flows: the list of movies from the local source (in my case, a database, but it could be any data source) and a fetchStatusFlow that monitors the status of the network fetch.</p><p>The <a href="https://github.com/morganesoula/hobby-matchmaker/blob/koin_migration/feature/movies/presentation/src/main/java/com/msoula/hobbymatchmaker/features/movies/presentation/MovieViewModel.kt">fetchMovies</a>() method updates the fetchStatusFlow variable based on the network state. It ensures that fetching happens only when necessary and transitions smoothly between states like Loading, Success our Error.</p><p>And to be honest, I left it at that for quite some time. I still had an inner voice telling me something was missing, but I couldn’t pinpoint what it was. As I gained more experience, it finally clicked. Funny enough, it happened around the same time <a href="https://www.linkedin.com/in/maxime-michel-23a29b180/">Maxime Michel</a> wrote his piece <a href="https://proandroiddev.com/correctly-combining-apis-with-business-logic-d4a4eb6e36e8">Correctly combining APIs with Business logic</a>. If you haven’t read it yet, I highly recommend it!</p><p><strong>Where I went wrong</strong></p><p>I am breaking one of principles of the Clean Architecture. The ViewModel should be <strong>empty of any business logic</strong>. Any business logic should belong to the <strong>domain</strong> layer, leaving the ViewModel to focus solely on managing UI state in the <em>presentation </em>layer.</p><p>Here come’s our most updated <a href="https://github.com/morganesoula/hobby-matchmaker/blob/user_implementation/feature/movies/presentation/src/main/java/com/msoula/hobbymatchmaker/features/movies/presentation/MovieViewModel.kt">version</a>.</p><pre>// MovieViewModel.kt<br><br>    val movieState: StateFlow&lt;MovieUiStateModel&gt; =<br>        observeAllMoviesUseCase(Parameters.StringParam(language)).mapLatest { result -&gt;<br>            when (result) {<br>                is Result.Success -&gt; {<br>                    when (val movies = result.data) {<br>                        is ObserveAllMoviesSuccess.Loading -&gt; MovieUiStateModel.Loading<br>                        is ObserveAllMoviesSuccess.Success -&gt;<br>                            MovieUiStateModel.Success(movies.movies.map { it.toMovieUiModel() }<br>                                .toPersistentList())<br><br>                        is ObserveAllMoviesSuccess.DataLoadedInDB -&gt; MovieUiStateModel.Empty<br>                    }<br>                }<br><br>                 is Result.Failure -&gt; {<br>                    val errorMessage = handleError(result.error)<br>                    MovieUiStateModel.Error(errorMessage)<br>                }<br><br>                else -&gt; MovieUiStateModel.Loading<br>            }<br>        }<br>            .stateIn(<br>                viewModelScope,<br>                SharingStarted.WhileSubscribed(5000),<br>                MovieUiStateModel.Loading<br>            )</pre><p><strong>What I improved</strong></p><p>We kept the structure but removed the logic from the ViewModel. Here’s why this version is much better and straightforward:</p><ul><li>Reactive code: the code is now fully reactive. Whenever there is a change in the data source, the UI state is automatically updated.</li><li>UI updates: based on the result returned by my domain layer, the ViewModel sends the correct UI state to the view.</li><li>Correct mapping: this is the only place where the domain object is mapped to a <a href="https://github.com/morganesoula/hobby-matchmaker/blob/user_implementation/feature/movies/presentation/src/main/java/com/msoula/hobbymatchmaker/features/movies/presentation/mappers/Mappers.kt">presentation object</a>. As mentioned earlier, the <strong>domain layer never adapts</strong> to any other layer, ensuring a clean separation of concerns.</li><li>Easy to test: eliminating business logic makes it easier to <a href="https://github.com/morganesoula/hobby-matchmaker/blob/user_implementation/testUtils/feature/src/test/kotlin/feature/movies/viewModel/MovieViewModelTest.kt">unit test it</a>.</li></ul><p>And finally, the <a href="https://github.com/morganesoula/hobby-matchmaker/blob/user_implementation/feature/movies/domain/src/main/java/com/msoula/hobbymatchmaker/features/movies/domain/useCases/ObserveAllMoviesUseCase.kt">UseCase</a></p><pre>class ObserveAllMoviesUseCase(<br>    private val movieRepository: MovieRepository,<br>    private val fetchMoviesUseCase: FetchMoviesUseCase,<br>    dispatcher: CoroutineDispatcher<br>) : FlowUseCase&lt;Parameters.StringParam, ObserveAllMoviesSuccess, ObserveAllMoviesErrors&gt;(dispatcher) {<br><br>    override fun execute(parameters: Parameters.StringParam):<br>        Flow&lt;Result&lt;ObserveAllMoviesSuccess, ObserveAllMoviesErrors&gt;&gt; {<br>        return channelFlow {<br>            movieRepository.observeMovies().collect { list -&gt;<br>                if (list.isEmpty()) {<br>                    send(Result.Success(ObserveAllMoviesSuccess.Loading))<br><br>                    when (val fetchStatus = fetchMoviesUseCase(parameters.value)) {<br>                        is Result.Success -&gt; send(Result.Success(ObserveAllMoviesSuccess.DataLoadedInDB))<br>                        is Result.Failure -&gt; {<br>                            val error = when (fetchStatus.error) {<br>                                is MovieErrors.NetworkError -&gt; ObserveAllMoviesErrors.NetworkError(<br>                                    fetchStatus.error.message<br>                                )<br><br>                                is MovieErrors.ApiError -&gt; ObserveAllMoviesErrors.ApiError(<br>                                    fetchStatus.error.message<br>                                )<br><br>                                else -&gt; ObserveAllMoviesErrors.UnknownError(fetchStatus.error.message)<br>                            }<br>                            send(Result.Failure(error))<br>                        }<br><br>                        else -&gt; send(Result.Success(ObserveAllMoviesSuccess.Loading))<br>                    }<br>                } else {<br>                    send(Result.Success(ObserveAllMoviesSuccess.Success(list)))<br>                }<br>            }<br>        }<br>    }<br>}<br><br>sealed class ObserveAllMoviesSuccess {<br>    data class Success(val movies: List&lt;MovieDomainModel&gt;) : ObserveAllMoviesSuccess()<br>    data object Loading : ObserveAllMoviesSuccess()<br>    data object DataLoadedInDB : ObserveAllMoviesSuccess()<br>}<br><br>sealed class ObserveAllMoviesErrors(override val message: String) : AppError {<br>    data object Empty : ObserveAllMoviesErrors(&quot;&quot;)<br>    data class NetworkError(val networkErrorMessage: String) :<br>        ObserveAllMoviesErrors(networkErrorMessage)<br><br>    data class ApiError(val apiErrorMessage: String) : ObserveAllMoviesErrors(apiErrorMessage)<br>    data class UnknownError(val unknownErrorMessage: String) :<br>        ObserveAllMoviesErrors(unknownErrorMessage)<br>}</pre><p>Inspired by Maxime Michel <a href="https://proandroiddev.com/correctly-combining-apis-with-business-logic-d4a4eb6e36e8">article</a> on abstract UseCases, I implemented my improved ObserveAllMoviesUseCase. I also introduced two sealed classes that allow me to clearly define both successful and failed states, making it easier to tie everything to the domain layer.</p><p><strong>What I improved</strong></p><ul><li>Logic in the right place: all the logic resides in the UseCase. It includes handling empty data, fetching data and mapping errors.</li><li>Asynchronous and reactive: using <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/channel-flow.html">channelFlow</a>, I can handle asynchronous operations such as — in this case — fetching data. This ensure my app remains responsive even when performing some complex operations.</li><li>Domain layer alignment: the domain layer mediates interactions between the data and presentation layers. It means that I am finally respecting one of the principle of the Clean Architecture.</li><li>Readability and maintainability: by creating two sealed classes such as ObserveAllMoviesSuccess and ObserveAllMoviesErrors, adding new states or handling additional scenarios becomes straightforward</li><li>Testability: I can write <a href="https://github.com/morganesoula/hobby-matchmaker/blob/user_implementation/testUtils/feature/src/test/kotlin/feature/movies/useCases/ObserveAllMoviesUseCaseTest.kt">unit tests that focus on the domain logic</a> without relying on UI components</li></ul><p><strong>Conclusion</strong></p><p>The ViewModel is now entirely free of business logic, fulfilling its true purpose: managing and updating the UI efficiently.</p><p>This final version of ObserveAllMoviesUseCase marks a significant milestone in my developer journey. By refactoring the logic to the domain layer, leveraging sealed classes for state management, and adopting reactive patterns such as channelFlow, the code has become cleaner, more maintainable and fully aligned with Clean Architecture principles.</p><p>You can find the whole project on my <a href="https://github.com/morganesoula/hobby-matchmaker">Github</a> (do not forget to navigate through the branches).</p><p>Let’s connect on <a href="https://www.linkedin.com/in/morgane-soula-08b33312a/">LinkedIn</a> if you want to see more of this project or my work!</p><p>As always, keep coding, exploring new topics and, most importantly, keep enjoying it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e88725161855" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Junior to Senior: Modularization in Clean Architecture Android projects]]></title>
            <link>https://medium.com/@morganes56/from-junior-to-senior-modularization-in-clean-architecture-android-projects-8eb9de2a84a0?source=rss-e368cd7aa90b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eb9de2a84a0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Morgane Soula]]></dc:creator>
            <pubDate>Thu, 04 Jul 2024 09:37:04 GMT</pubDate>
            <atom:updated>2024-07-04T09:37:04.956Z</atom:updated>
            <content:encoded><![CDATA[<p>This article follows on from my previous one <a href="https://medium.com/codex/from-junior-to-senior-the-real-way-to-implement-clean-architecture-in-android-8514005e85e1">The real way to implement Clean Architecture in Android</a>.</p><p>Once again, thank you, <a href="https://www.linkedin.com/in/guillaumeberanger/">Guillaume</a>, for taking the time to review this article and to give me your insights. It is really much appreciated!</p><p>In that article, we used two dummy projects “Note app” to explore different aspects of Clean Architecture in Android. This time, we will discuss the <strong>modularization</strong> of a Clean Architecture project using my personal app <a href="https://github.com/morganesoula/hobby-matchmaker/tree/develop">HobbyMatchMaker</a>. We will explore the modularization of the authentication process, shared between three modules: <em>authentication</em>, <em>login,</em> and <em>session</em>.</p><p>Chop-chop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*Vbhnumc-kGMbfU_n.gif" /><figcaption>(Source: giphy.com)</figcaption></figure><h3>Why You Should Modularize Your Project</h3><p>Because your project is a puzzle, made up of multiple pieces that fit together. The magic? It is an infinite jigsaw puzzle. Modularization allows you to break your project into reusable pieces, that can be injected whenever needed. For example, if you want to display a list of movies to a user. The user could favorite any of these movies. You could then display their favorite movies on both their home screen and profil screen using the same piece of code and the same list of movies from one source only.</p><p>Authentication in mobile apps generally follows a similar process. The modules I have coded for my project can definitely be reused in any other project. Want to add Twitter as an authentication method? No problem. Just add it to the data module of the parent <strong>authentication</strong> module, and you’re good to go.</p><p>As for Clean Architecture, modularization allows you to develop, reuse, maintain and, test each part of your project independently. It also encourages the separation of concerns. By following these principles, your application will be easier to test and easier to add new features to.</p><h3>What We Will Develop</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDs7T9dMAZfug39lB9zTKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPsenAOtmzIUFllKOEtflw.png" /><figcaption>(Sign in screen — Sign up screen)</figcaption></figure><p>As usual, this is my stack: Kotlin 1.9.22, Android Studio Koala, Jetpack Compose 1.6.8, Hilt 2.50 and Firebase 33.1.0</p><p>To authenticate my users, I have decided to use the good old email/password method, Google Sign-In, and Meta (aka Facebook). I am using Firebase Authentication as my backend. I am aware that Firebase no longer recommends using email/password, but I want to be inclusive, as not everyone should be forced to use social media.</p><p>As mentioned above, the authentication process is divided between three modules (all under the <strong>core</strong> parent module):</p><ul><li>Authentication (data &amp; domain): Handles the network calls needed for authentication</li><li>Login (domain &amp; presentation): Manages the UI for sign-in, sign-up, reset password, etc…</li><li>Session (data &amp; domain): Responsible for storing and retrieving session data such as user ID, user email, tokens, etc…</li></ul><p>Let’s start with the UI !</p><h3>Parent Module: Login</h3><p>The <strong>login</strong> module is divided into two submodules: domain and presentation.</p><pre>// From core.login.domain.use_cases.ValidateEmailUseCase<br><br>operator fun invoke(email: String): ValidationResult {<br>        return if (email.matches(&quot;^[A-Za-z](.*)(@)(.+)(\\.)(.+)$&quot;.toRegex())) {<br>            ValidationResult(true)<br>        } else {<br>            ValidationResult(false)<br>        }<br>    }</pre><p>I have several use cases to check my business logic. In my case, the domain layer is used to validate the input of the forms.</p><p>Presentation has two main packages: sign-in and sign-up. Each package contains the screen and its associated ViewModel.</p><pre>// from core.login.presentation.sign_up<br><br>@OptIn(FlowPreview::class)<br>@HiltViewModel<br>class SignUpViewModel @Inject constructor(<br>    private val loginValidateFormUseCase: LoginValidateFormUseCase,<br>    private val signUpUseCase: SignUpUseCase,<br>    private val ioDispatcher: CoroutineDispatcher,<br>    private val resourceProvider: StringResourcesProvider,<br>    private val savedStateHandle: SavedStateHandle,<br>    private val signUpNavigation: SignUpNavigation<br>) : ViewModel() {<br><br>// content<br><br>}</pre><p>For the sign-up part, I handle the user’s input with my use cases mentioned above. Once the form is validated, I submit it using SignUpUseCase. SignUpUseCase is defined in the <strong>authentication</strong> module as it makes a network call through Firebase.</p><pre>// from core.login.presentation.sign_up.SignUpViewModel<br><br>signUpUseCase(<br>            formDataFlow.value.email,<br>            formDataFlow.value.password<br>        )<br>            .onEach {<br>                viewModelScope.launch {<br>                    abortCircularProgress()<br>                }<br>            }<br>            .mapSuccess {<br>                savedStateHandle.clearAll&lt;SignUpStateModel&gt;()<br>                signUpNavigation.redirectToAppScreen()<br>            }<br>            .mapError { error -&gt;<br>                Log.e(&quot;HMM&quot;, &quot;Could not create an account with error: $error&quot;)<br>                val errorMessageToDisplay: String = when (error) {<br>                    is CreateUserError.EmailAlreadyExists -&gt; resourceProvider.getString(<br>                        R.string.email_already_exists_error<br>                    )<br>                    is CreateUserError.UserDisabled -&gt; resourceProvider.getString(<br>                        R.string.user_disabled_error<br>                    )<br>                    is CreateUserError.TooManyRequests -&gt; resourceProvider.getString(<br>                        R.string.too_many_requests_error<br>                    )<br>                    is CreateUserError.InternalError -&gt; resourceProvider.getString(<br>                        R.string.internal_error<br>                    )<br><br>                    else -&gt; error.message<br>                }<br><br>                updateFormState { it.copy(signUpError = errorMessageToDisplay) }<br>                error<br>            }</pre><p>Once I have the result of the call, I either navigate to the Main Screen of my application or update my UI with a snackbar displaying the tailed error message.</p><p>For the sign-in other part, I handle three login sources: email/password, Meta, and Google.</p><pre>    // from core.login.presentation.sign_in.SignInScreen<br><br>    val facebookLauncher =<br>        rememberLauncherForActivityResult(<br>            loginManager.createLogInActivityResultContract(callBackManager, null)<br>        ) {}<br><br>    RegisterFacebookCallback(<br>        loginManager = loginManager,<br>        callBackManager = callBackManager,<br>        coroutineScope = coroutineScope,<br>        handleFacebookAccessToken = handleFacebookAccessToken,<br>        context = context<br>    )</pre><p>For Meta, I first retrieve the credentials in my UI using a callback.</p><pre>// from app.MainActivity<br><br>private val googleAuthClient = GoogleAuthClient(CredentialManager.create(this), this)<br><br>// from core.login.presentation.sign_in.SignInScreen<br><br>    SocialMediaRowCustom(<br>        onFacebookButtonClicked = {<br>            facebookLauncher.launch(listOf(&quot;email&quot;, &quot;public_profile&quot;))<br>        },<br>        onGoogleButtonClicked = {<br>            scope.launch {<br>                val credential = googleAuthClient.launchGetCredential()<br>                handleGoogleSignIn(credential, googleAuthClient)<br>            }<br>        }<br>    )</pre><p>For Google, I initialize my GoogleAuthClient in my MainActivity and use this client to call <em>launchGetCredential</em> to get the credentials.</p><pre>// from core.login.presentation.sign_in.SignInViewModel<br><br>    private fun handleSocialMediaLogin(<br>        credential: AuthCredential,<br>        onFailureEvent: (String) -&gt; AuthenticationEvent,<br>        errorMessage: String<br>    ) {<br>        viewModelScope.launch(ioDispatcher) {<br>            loginWithSocialMediaUseCase(credential)<br>                .onEach {<br>                    viewModelScope.launch {<br>                        abortCircularProgress()<br>                    }<br>                }<br>                .mapSuccess {<br>                    saveIsConnected()<br>                }<br>                .mapError { error -&gt;<br>                    Log.e(&quot;HMM&quot;, errorMessage)<br>                    viewModelScope.launch {<br>                        sendEvent(onFailureEvent(error.message))<br>                    }<br>                    error<br>                }<br>        }<br>    }</pre><p>Once I have these credentials, I use the appropriate use case from the <strong>authentication</strong> module. For email/password, the workflow is very similar to sign-up. Depending on the network response, I either redirect to the Main Screen or use a Channel to display an error. Now, let’s dive into the <strong>authentication</strong> module.</p><h3>Parent Module: Authentication</h3><p>The <strong>authentication</strong> module is divided into two submodules: data and domain.</p><p>I have several functions in my <strong>domain</strong> repository such as login (with credentials and with email/password), register, reset password, etc… These methods are called from the UI described above.</p><pre>  // from core.authentication.data.data_sources.remote<br><br>    override suspend fun signInWithEmailAndPassword(<br>        email: String,<br>        password: String<br>    ): Result&lt;Boolean&gt; {<br>        return try {<br>            auth.signInWithEmailAndPassword(email, password).await()<br>            Result.Success(true)<br>        } catch (e: Exception) {<br>            Log.e(&quot;HMM&quot;, &quot;Exception caught while logging user: ${e.message}&quot;)<br>            if (e is FirebaseAuthException) {<br>                when (e.errorCode) {<br>                    &quot;ERROR_USER_DISABLED&quot; -&gt; Result.Failure(SignInError.UserDisabled)<br>                    &quot;ERROR_USER_NOT_FOUND&quot; -&gt; Result.Failure(SignInError.UserNotFound)<br>                    &quot;ERROR_WRONG_PASSWORD&quot; -&gt; Result.Failure(SignInError.WrongPassword)<br>                    &quot;ERROR_TOO_MANY_REQUESTS&quot; -&gt; Result.Failure(SignInError.TooManyRequests)<br>                    else -&gt; Result.Failure(SignInError.Other(&quot;&quot;))<br>                }<br>            } else {<br>                Result.Failure(SignInError.Other(&quot;Unexpected error with error message: ${e.message}&quot;))<br>            }<br>        }<br>    }</pre><p>The authentication <strong>data</strong> module only handles the remote sources. I call the correct method from the Firebase instance <em>signInWithEmailAndPassword</em> for email/password and <em>signInWithCredentials</em> for Google and Meta. If the network returns an error, I catch it and update my returning Result according to the errorCode.</p><p>And… that’s it! Simple, right?</p><p>We interact with our app, we make our network calls, we update the UI, and then we store our data needed by the app. And that’s exactly what the next module does: <strong>session</strong>.</p><h3>Parent module: Session</h3><p>The <strong>session</strong> module is divided into two submodules: data and domain. This module is crucial for retrieving any authentication information across the app, especially for features — like a Settings screen.</p><pre>// from core.session.domain.models.SessionUserDomainModel<br><br>data class SessionUserDomainModel(<br>    val email: String,<br>    val connexionMode: SessionConnexionModeDomainModel<br>)<br><br>// from core.session.domain.repositories.SessionRepository<br><br>class SessionRepository(private val sessionLocalDataSource: SessionLocalDataSource) {<br>    suspend fun saveUser(user: SessionUserDomainModel) =<br>        sessionLocalDataSource.saveUser(user)<br><br>    suspend fun clearSessionData() =<br>        sessionLocalDataSource.clearSessionData()<br><br>    suspend fun setIsConnected(isConnected: Boolean) =<br>        sessionLocalDataSource.setIsConnected(isConnected)<br><br>    fun observeIsConnected(): Flow&lt;Boolean&gt; =<br>        sessionLocalDataSource.observeIsConnected()<br><br>    fun getConnexionMode(): Flow&lt;String?&gt; =<br>        sessionLocalDataSource.getConnexionMode()<br>}</pre><p>In the <strong>domain</strong> layer, the repository has methods like <em>saveUser</em> and <em>retrieveUser</em>. You may notice that these methods focus on local data operations only.</p><pre>  // from core.session.data.data_sources.local.SessionLocalDataSourceImpl<br><br>  override suspend fun saveUser(user: SessionUserDomainModel) {<br>      dataStore.edit { preferences -&gt;<br>          preferences[EMAIL_KEY] = user.email<br>          preferences[CONNEXION_MODE] = user.connexionMode.name<br>      }<br>  }<br><br>  // Other local methods</pre><p>In the <strong>data</strong> layer, I implement the methods from the domain’s SessionLocalDataSource.</p><p>We now know how our three modules interact with each other. Let’s see how to make them interact with the rest of the app.</p><h3>Parent Module: App</h3><p>We have two key points to address.</p><ol><li><strong>Checking Connexion Status on App Launch</strong></li></ol><pre>  // from app.presentation.AppViewModel<br><br>    val authenticationState: StateFlow&lt;AuthUiStateModel&gt; by lazy {<br>        observeAuthenticationStateUseCase()<br>            .mapLatest { isConnected -&gt;<br>                if (isConnected) AuthUiStateModel.IsConnected else AuthUiStateModel.NotConnected<br>            }<br>            .flowOn(Dispatchers.Main)<br>            .stateIn(<br>                viewModelScope,<br>                SharingStarted.WhileSubscribed(5000),<br>                AuthUiStateModel.CheckingState<br>            )<br>    }<br><br>  // from core.session.data.data_sources.local.SessionLocalDataSourceImpl<br><br>    override fun observeIsConnected(): Flow&lt;Boolean&gt; = dataStore.data<br>        .catch { exception -&gt;<br>            if (exception is IOException) emit(emptyPreferences())<br>            else throw exception<br>        }<br>        .map { preferences -&gt;<br>            preferences[IS_CONNECTED_KEY] ?: false<br>        }</pre><p>In AppViewModel (from the <strong>app</strong> module), we observe the connexion status stored in the local data source through <em>observeIsConnected</em>.</p><pre>// extract from the method signIn() in core.login.presentation.sign_in.SignInViewModel<br>   <br>    viewModelScope.launch(ioDispatcher) {<br>                signInUseCase(formDataFlow.value.email, formDataFlow.value.password)<br>                    .onEach {<br>                        viewModelScope.launch {<br>                            abortCircularProgress()<br>                        }<br>                    }<br>                    .mapSuccess {<br>                        ----&gt; setIsConnected(true) &lt;---- only on success, we save our connexion status<br>                        clearFormState()<br>                        withContext(Dispatchers.Main) {<br>                            redirectToAppScreen()<br>                        }<br>                    }<br>    }<br>    <br>    private suspend fun setIsConnected(isConnected: Boolean) {<br>        setIsConnectedUseCase(isConnected)<br>    }<br><br>  // from core.session.domain.repositories<br><br>    suspend fun setIsConnected(isConnected: Boolean) =<br>        sessionLocalDataSource.setIsConnected(isConnected)<br><br>  // from core.session.data.data_sources.local.SessionLocalDataSourceImpl<br><br>    override suspend fun setIsConnected(isConnected: Boolean) {<br>        dataStore.edit { preferences -&gt;<br>            preferences[IS_CONNECTED_KEY] = isConnected<br>        }<br>    }</pre><p>I have a waiting state called CheckingState: whenever we update <em>IS_CONNECTED_KEY</em>, any listener to the authenticationState variable is triggered.</p><pre> // from app.navigation.HobbyMatchMakerNavHost<br>  <br>    val authenticationState by appViewModel.authenticationState.collectAsStateWithLifecycle()<br><br>    val startDestination = when (authenticationState) {<br>        is AuthUiStateModel.CheckingState -&gt; SplashScreenRoute.ROUTE<br>        is AuthUiStateModel.NotConnected -&gt; SignInScreenRoute.ROUTE<br>        is AuthUiStateModel.IsConnected -&gt; AppScreenRoute.ROUTE<br>    }</pre><p>Finally, in the NavHost, the <em>startDestination</em> is defined according to the connexion status. Once we launch the app, while we are checking <em>observeIsConnected</em> we display a SplashScreen. And once the authenticationState is updated, the navHost either redirect to the SignIn screen or App screen.</p><p>2. <strong>Determining the Connexion Mode for Logout</strong></p><pre>// from app.MainActivity<br><br>    private fun setAuthenticationListener() {<br>        authStateListener = AuthStateListener { firebaseAuth -&gt;<br>            val user = firebaseAuth.currentUser<br><br>            user?.let { firebaseUser -&gt;<br>                val email = firebaseUser.email<br><br>                val providers = firebaseUser.providerData.map { it.providerId }<br><br>                val connexionMode = when {<br>                    providers.contains(&quot;google.com&quot;) -&gt; ConnexionMode.GOOGLE<br>                    providers.contains(&quot;facebook.com&quot;) -&gt; ConnexionMode.FACEBOOK<br>                    else -&gt; ConnexionMode.EMAIL<br>                }<br><br>                lifecycleScope.launch(Dispatchers.IO) {<br>                    saveUserUseCase(UserDomainModel(email ?: &quot;&quot;, connexionMode))<br>                }<br>            } ?: run {<br>                lifecycleScope.launch(Dispatchers.IO) {<br>                    clearUserUseCase()<br>                }<br><br>                Log.d(&quot;HMM&quot;, &quot;User is not connected&quot;)<br>            }<br>        }<br>    }<br><br>// from core.session.domain.repositories<br><br>    suspend fun saveUser(user: SessionUserDomainModel) =<br>        sessionLocalDataSource.saveUser(user)</pre><p>In MainActivity, we define the Firebase listener in the <em>onCreate</em> function. <strong>Do not forget</strong> to remove the listener in the <em>onStop</em> function. Firebase is reactive, and once we used any sign-in method, the listener is triggered. The User’s Firebase object has a list of providers. Once we get the right provider, we update the local data source.</p><pre>// from app.presentation.AppViewModel<br><br>    fun logOut() {<br>        viewModelScope.launch(ioDispatcher) {<br>            val connexionMode = getConnexionModeUseCase().first()<br>            logOutUseCase(connexionMode ?: &quot;EMAIL&quot;).mapSuccess {<br>                setIsConnectedUseCase(false)<br>            }<br>        }<br>    }<br><br>// from core.authentication.domain.repositories.AuthenticationRepository<br><br>    suspend fun logOut(connexionMode: String): Result&lt;Boolean&gt; {<br>        return try {<br>            when (connexionMode) {<br>                &quot;FACEBOOK&quot; -&gt; remoteDataSource.loginManagerSignOut()<br>                &quot;GOOGLE&quot; -&gt; remoteDataSource.credentialManagerLogOut()<br>                else -&gt; remoteDataSource.authenticationSignOut()<br>            }<br>            Result.Success(true)<br>        } catch (exception: Exception) {<br>            Result.Failure(LogOutError(message = exception.message ?: &quot;Error while logging out&quot;))<br>        }<br>    }</pre><p>Then we can retrieve the connectionMode stored in the session module, in order to apply the proper action, as, for instance, Google sign-ins don’t require any disconnection call if the user logged in with Facebook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*5V09Rgal8uKTuFji.gif" /><figcaption>(source: giphy.com)</figcaption></figure><p>You made it to the end! By now, you should have a clear and solid understanding of how modularization enhances a Clean Architecture Android project. We’ve seen how clear separation of concerns within modules — such as session management and authentication — facilitates maintainability and scalability. Feel free to ask any questions, and I’ll do my best to answer them :)</p><p>You can find the whole project on my <a href="https://github.com/morganesoula/hobby-matchmaker">Github</a> (do not forget to navigate through the branches).</p><p>Let’s connect on <a href="https://www.linkedin.com/in/morgane-soula-08b33312a/">LinkedIn</a> if you want to see more of this project or my work!</p><p>As always, keep coding, exploring new topics and, most importantly, keep enjoying it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eb9de2a84a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Junior to Senior: the real way to implement Clean Architecture in Android]]></title>
            <link>https://medium.com/codex/from-junior-to-senior-the-real-way-to-implement-clean-architecture-in-android-8514005e85e1?source=rss-e368cd7aa90b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8514005e85e1</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Morgane Soula]]></dc:creator>
            <pubDate>Wed, 15 May 2024 09:26:52 GMT</pubDate>
            <atom:updated>2024-07-10T12:56:53.108Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p><a href="https://www.linkedin.com/in/morgane-soula-08b33312a/">I have been coding as an Android Developer</a> for over 6 years now. Regardless of the technology, every developer’s journey starts with one thought <strong>I need to know how to code</strong>. And after your first Hello World and many years of practice, you slightly but surely shift your developer perspective from “I need to make it work” to “I need to know how and why it works”.</p><p>Like many developers, I experimented with various architectures in my personal and professional projects (MVC, MVP, and MVVM). However, I found it so challenging to test, scale, and maintain my code through time. Then, I discovered the <a href="https://developer.android.com/topic/architecture">Clean Architecture</a>.</p><p>If you want to know more about Modularization, <a href="https://medium.com/@morganes56/from-junior-to-senior-modularization-in-clean-architecture-android-projects-8eb9de2a84a0">check out my second article of this serie</a>!</p><p>I started my personal project <a href="https://github.com/morganesoula/hobby-matchmaker">HobbyMatchMaker</a> and after talking with <a href="https://www.linkedin.com/in/guillaumeberanger/">Guillaume</a>, a Lead Senior Developer at <a href="https://www.meero.com/fr/">Meero</a><a href="https://www.meero.com/">,</a> he graciously pointed out a few mistakes I was making with my architecture. He generously shared his time and knowledge with me. And honestly, he is so <strong>easy</strong> to talk to: you feel smart whenever you chat with him. Thank you <strong>so much</strong> for your invaluable time and expertise!</p><p>I know many developers, like my past self, struggle with implementing Clean Architecture effectively. Allow me to illustrate, through two projects, how to adhere to Clean Architecture principles.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT9IgKOUD1EwuLpfXi%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExcHRkYnE4MnR5dDhsdmE3eHF3bmJvZDQxaWhqYTFhNHRnbGgwNGd4cSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxT9IgKOUD1EwuLpfXi%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExcno3bW5najBoemRlNGRxcHBwb3lvYWVnMDF1NXd2MWRlZW1oZzdlMiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxT9IgKOUD1EwuLpfXi%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="241" frameborder="0" scrolling="no"><a href="https://medium.com/media/47333768b04f3f8f3137034ecf03655e/href">https://medium.com/media/47333768b04f3f8f3137034ecf03655e/href</a></iframe><h3>Initialization</h3><p>We will create a note-taking application with three main functionalities: displaying a list of notes, displaying its detail and adding a new note. Simple yet effective. First, I will demonstrate how many - <em>myself —</em> used to implement it, followed by a second version strictly using Clean Architecture principles. We will focus solely on Clean Architecture so don’t be surprised if I put little to no effort on the design.</p><p>For both projects I will be using the following stack: Kotlin, Jetpack Compose, Coroutines, Room, and Hilt. I am using Android Studio Iguana and Kotlin 1.9.22.</p><p>While I won’t be implementing tests, feel free to do it of course. It is a good exercice.</p><p><strong>Remember, no code is perfect</strong>. I am perpetually becoming a better version of myself and I am enjoying every step of this journey. I am also more than happy to engage in discussions with any of you on the subject. Don’t forget: alone, we go faster, but together, we go further.</p><p>And now, let’s dive in.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FH1dbpJ35iFz3lkGdZu%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbGYyMzZudHFvYjV5bnNidDdzenViaHgwMThvbXZqNXdlZXk5azJnMCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FH1dbpJ35iFz3lkGdZu%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExd3NjOG56NXc2dHd2Y2Z1azVibjdibjFyaWxxbzFscDgxMXJpZ29jYiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FH1dbpJ35iFz3lkGdZu%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/0539f6b6b3e2c50e698d43bbfb01ea36/href">https://medium.com/media/0539f6b6b3e2c50e698d43bbfb01ea36/href</a></iframe><h3>Packages — 1st Version — No (real) Clean Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*lf6ql-DZl2lK3afsW8VhNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*cKj9uzS5d7lpWBp6xUd4sw.png" /><figcaption>(Project view in Android Studio)</figcaption></figure><p>Let’s review this first project together, shall we?</p><p>Firstly, despite my efforts to create a multi-module project, there is only one module named <em>app</em>. All my folders are under the main package. One of the primary goals of the Clean Architecture is to only use what is needed in different layers. For example, if you need a DAO somewhere, you won’t probably also need the configuration of the database.</p><p>Setting aside the construction of my layers, let’s examine each one of them inside the features. We can see that in each feature, the domain layer seems to only contain <strong>UseCases</strong>. Ideally this layer should have any business logic related not only UseCases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*ZBfS9BW0PTBO-qh-Yf43bA.png" /></figure><p>If we focus on only one of my features, let’s say main —<em> also, the nomenclature is not ideal: “main” doesn’t convey any specific meaning for a featur</em>e — one thing should come to mind and totally breaks the principle of Clean Architecture: I only have one model <em>NoteEntity</em>. Through my entire project, I use this model which is the one representing my database entry. And most importantly, I am using this unique model across all layers. <strong>Each layer should have their own model. </strong>The model displayed to your users should differ from the one used in your database. Doing so I am breaking the <a href="https://developer.android.com/topic/architecture#separation-of-concerns">Separation of concerns</a> rule.</p><p>Additionally, the abstraction <em>NoteDataSource</em> and its concrete implementation <em>NoteDataSourceImpl</em> are both in the same layer, breaking the <a href="https://developer.android.com/topic/modularization/patterns">Dependency Inversion</a> principle. And while we are at it, we should have two different packages for data sources: local and remote. While not mandatory if you only use local data, having separate packages would <strong>facilitate</strong> future additions of remote sources without disrupting the architecture. It would definitely be a good practice.</p><pre>class GetAllNotesUseCase(private val noteDataSource: NoteDataSource) {<br>  operate fun invoke(): Flow&lt;List&lt;NoteEntity&gt;&gt; = noteDataSource.getNotes()<br>}</pre><p>Moving on to one of my UseCases. Back to one or two years ago, I did not understand most concepts behind the Clean Architecture. So it lead me to make some honest mistakes like the one above: not creating a repository. I was injecting the data source directly because I had only one source (a local one). But, it is always better to use a repository to handle different data sources (local and remote) to address the single source of truth principle.</p><p>But this case is perfect for illustrating the violation of the <a href="https://nogueiras.medium.com/make-your-android-application-rock-solid-part-three-4397f3c866a2">Liskov Substitution Principle</a>. What does it mean? You can’t link a use case (or any class) to a specific implementation of another class. Keep in mind that your domain layer is completely independent and <strong>should never know</strong> about your data and presentation layers. It means you need to go through a contract — interface — and the data source should inherit from this interface. That way, it does not matter if you change the way the sources fetch your data: your use case won’t know about it since it is only connected to your interface. Therefore, your domain layer is independent of your data layer.</p><p>Moreover, we should point out that this use case returns a Flow. Doing so, it completely ignores any exceptions the repository could potentially encounter.</p><pre>@HiltViewModel<br>class NoteViewModel @Inject constructor(<br>    getNotesUseCase: GetAllNotesUseCase<br>) : ViewModel() {<br><br>    val noteState: StateFlow&lt;NotesFeedUiState&gt; = getNotesUseCase()<br>        .map { list -&gt;<br>            if (list.isEmpty()) {<br>                NotesFeedUiState.Empty<br>            } else {<br>                NotesFeedUiState.Success(list)<br>            }<br>        }<br>        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), NotesFeedUiState.Loading)<br>}</pre><p>The presentation layer is only made of my ViewModel and my Composables. Honestly, it is not a bad ViewModel but it could be a little bit improved.</p><pre>class NoteDataSourceImpl(private val noteDAO: NoteDAO) : NoteDataSource {<br><br>    // Other CRUD methods<br><br>    override suspend fun upsertNote(note: NoteEntity): Result&lt;Boolean&gt; =<br>        try {<br>            noteDAO.upsertNote(note)<br>            Result.Success(true)<br>        } catch (e: Exception) {<br>            e.printStackTrace()<br>            Result.Error(<br>                throwable = e.cause ?: Throwable(message = &quot;Could not upsert note&quot;)<br>            )<br>        }<br>}</pre><p>Let’s focus on a single method from my CRUD concrete implementation. It returns a Result but is completely ignored in my use cases (and my missing Repository). Additionally, the exception handling could be improved. However, overall, it is a good method since it adheres to the <a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e">Single Responsability Principle</a> by only performing one task.</p><p>Let’s see how we can improve this project with a cleaner second version.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FR79xMPy2dDuIegbUp2%2Fvideo&amp;display_name=GIPHY&amp;url=https%3A%2F%2Fgiphy.com%2Fclips%2Fstraystv-strays-R79xMPy2dDuIegbUp2&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FR79xMPy2dDuIegbUp2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="480" height="270" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d60f96968dccef6435add760f9b4df7/href">https://medium.com/media/6d60f96968dccef6435add760f9b4df7/href</a></iframe><h3>Packages — 2nd Version — Clean Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*-QKRTHzWoyWHRuw0Biphew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*xafUR5qghyMRccKvaRPMsQ.png" /></figure><p>First off? We now have 3 (real 🎉) main modules:</p><ul><li>App</li><li>Core</li><li>Feature</li></ul><p>The <em>App</em> module is mandatory. Here, you will find your MainActivity and everything related to the smooth running of your application (e.g., your Application file).</p><pre>    // from build.gradle.kts (app)<br>   <br>    // Modules<br>    implementation(project(Modules.DATABASE))<br>    implementation(project(Modules.DAO))<br>    implementation(project(Modules.DI))<br>    implementation(project(Modules.ADD_NOTE_PRESENTATION))<br>    implementation(project(Modules.NOTE_DATA))<br>    implementation(project(Modules.NOTE_DOMAIN))<br>    implementation(project(Modules.NOTE_PRESENTATION))<br>    implementation(project(Modules.NOTE_DETAIL_PRESENTATION))</pre><p>Also, your app’s <em>build.gradle</em> should contain (almost) every module you will create in this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*-WgxjAkvoPCWSEqo3ZgDEg.png" /><figcaption>(Core module)</figcaption></figure><p>Inside <em>Core</em> you will place everything that is not a feature. We typically use it to group together code that provides basic functionality and utilities shared by other modules (e.g., database, design, common…). Each folder should be a module so that you can inject it whenever you need one of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*rGTysyJT7VRs6THD58HSKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*eD0Pv2iMzQ17NuKCu5D-Wg.png" /><figcaption>(Feature module — — — build.gradle from feature.notes.domain)</figcaption></figure><p>And inside <em>Feature</em> you will place your… features (good catch!). Within each feature, you will create a module for each layer of the Clean Architecture: data, domain, and presentation. Your domain module will be injected in your presentation and data modules, but it will remain independent from them. However, keep in mind that you <strong>do not need</strong> to create a presentation layer (for example) if your feature won’t display anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*GWVoD8XBxL7ra5rD4gJH3w.png" /><figcaption>(Domain module from feature.notes.domain)</figcaption></figure><p>Once again, let’s focus on the <em>Notes </em>module<em> </em>—<em> notice that the nomenclature is clearer this time</em> —<em> </em>and start with the domain layer. What did we learn earlier about the domain layer?</p><ul><li>It knows nothing about data and presentation</li><li>It contains the business logic</li><li>The limit between domain and data is adjustable. Some people would prefer to put everything data sources related inside the Data folder instead: like the repository not being tailored to the domain layer.</li></ul><pre>// from feature.notes.domain.data_sources.local<br><br>interface NoteLocalDataSource {<br>    fun observeNotes(): Flow&lt;List&lt;NoteDomainModel&gt;&gt;<br>    suspend fun insertNote(note: NoteDomainModel): Result&lt;Boolean&gt;<br>    suspend fun fetchNoteById(id: Long): Result&lt;NoteDomainModel&gt;<br>}</pre><p>We have our first business logic folder: data sources. As previously mentioned, I have only included a <em>local</em> folder. As we want to respect the <em>Liskov</em> Principle, we have created an interface with the methods our business logic requires. When returning data, we encapsulate it into a custom <a href="https://github.com/morganesoula/NoteAppClean/blob/master/core/common/src/main/java/com/msoula/noteappclean/core/common/Result.kt">Result</a> object (from our common module). This sealed interface is made of two classes: Success and Failure. Implementing these methods is <strong>not the responsability of the domain layer</strong>,<strong> </strong>so we leave it at that.</p><pre>    // from feature.notes.domain.repositories<br><br>    suspend fun fetchNoteById(id: Long): Result&lt;NoteDomainModel&gt; {<br>        return noteLocalDataSource.fetchNoteById(id)<br>    }</pre><p>Our Repository solely focus on working with the previous interface: it doesn’t matter where the data is coming from. We return a Result and most importantly, we return a custom model <em>NoteDomainModel</em> <strong>tailored</strong> to this layer. <strong>Every file requiring </strong>a model within the domain layer utilizes this custom model.</p><pre>// from feature.notes.domain.use_cases<br><br>class InsertNoteUseCase(<br>    private val noteRepository: NoteRepository<br>) {<br>    suspend operator fun invoke(note: NoteDomainModel): Result&lt;Boolean&gt; {<br>        return noteRepository.insertNote(note)<br>    }<br>}</pre><p>And finally, we have some use cases. As mentioned earlier, it uses the custom model <em>NoteDomainModel </em>and returns a Result so we can handle exception in our presentation layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*U21nFTeBVmnNJql9giZK1A.png" /><figcaption>(from feature.notes.data)</figcaption></figure><p>Let’s proceed to our data module layer. Its purpose is to fetch data: it can be provided by your storage device, database, server, API, shared preferences… In our case, we focus on a straightforward example utilizing a local database. For those interested in exploring API functionality, I recommend checking out my <a href="https://github.com/morganesoula/hobby-matchmaker">HobbyMatchMaker</a> project.</p><p>Our key file here is <em>NoteLocalDataSourceImpl</em>, the concrete implementation of the <em>NoteLocalDataSource</em> interface defined in our domain layer.</p><pre>// from features.notes.data.data_sources.local<br><br>class NoteLocalDataSourceImpl(<br>  private val noteDAO: NoteDAO<br>) : NoteLocalDataSource {<br><br>    // Other methods<br><br>    override fun observeNotes(): Flow&lt;List&lt;NoteDomainModel&gt;&gt; {<br>        return noteDAO.observeNotes()<br>            .map { list -&gt;<br>                list.map { noteEntityModel -&gt; noteEntityModel.toNoteDomainModel() }<br>            }<br>            .onEmpty {<br>                return@onEmpty<br>            }<br>    }<br>}</pre><p>NoteDAO is injected through the class constructor. NoteDAO is defined in another module named <em>dao</em> within the parent module <em>database</em> encapsulated in the main module <em>core</em>. As mentioned before, when requiring a DAO, only the interface is necessary, not the database implementation.</p><pre>// from core.database.main<br><br>@Module<br>@InstallIn(SingletonComponent::class)<br>object DatabaseModule {<br><br>    @Provides<br>    @Singleton<br>    fun provideDatabase(<br>        @ApplicationContext context: Context<br>    ): NoteAppCleanDatabase =<br>        Room.databaseBuilder(<br>            context,<br>            NoteAppCleanDatabase::class.java,<br>            &quot;database-clean&quot;<br>        )<br>            .build()<br><br>    @Provides<br>    fun providesNoteDAO(database: NoteAppCleanDatabase): NoteDAO = database.noteDAO()<br>}</pre><p>We retrieve entities from the database <em>NoteEntityModel</em> and since our domain layer exclusively interacts with <em>NoteDomainModel</em>, we employ a mapper.</p><pre>// from feature.notes.data.data_sources.local.mappers<br><br>fun NoteEntityModel.toNoteDomainModel(): NoteDomainModel {<br>    return NoteDomainModel(<br>        id = this.id,<br>        title = this.title,<br>        description = this.description<br>    )<br>}</pre><p>It’s the responsibility of the data layer to adapt to the requirements of the domain layer. <strong>Never</strong> the other way around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*4EIK-en6YTyJvjjhA7P6_w.png" /><figcaption>(from feature.notes)</figcaption></figure><p>Lastly, our last layer: presentation. Its primary function is to present data to our users or any interaction with them, handling all aspect related to UI or UX. To do so, we will need a specific model <em>NoteUiModel</em>. Good practice here is to annotate it with <a href="https://developer.android.com/reference/kotlin/androidx/compose/runtime/Immutable">Immutable</a>.</p><p>We will find 3 main elements: our Mapper, Composables, and ViewModel. The mapper follows the same pattern as seen in our data layer: it transforms our business model into a UI model.</p><pre>// from feature.notes.presentation<br><br>@Composable<br>fun NoteScreen(<br>    modifier: Modifier = Modifier,<br>    notes: List&lt;NoteUiModel&gt;,<br>    openNoteDetail: (id: Long) -&gt; Unit<br>) { // content }</pre><p>Composables represent different part of our screens, such as the list of notes in our case. We utilize our UI model <em>NoteUiModel</em> and employ lambda functions whenever interaction with our ViewModel is necessary.</p><pre>// from feature.notes.presentation<br><br>@OptIn(ExperimentalCoroutinesApi::class)<br>@HiltViewModel<br>class NoteViewModel @Inject constructor(<br>    private val observeNotesUseCase: ObserveNotesUseCase<br>) : ViewModel() {<br><br>    val noteState: StateFlow&lt;NoteUiStateModel&gt; by lazy {<br>        observeNotesUseCase()<br>            .mapLatest { notes -&gt;<br>                if (notes.isEmpty()) {<br>                    NoteUiStateModel.Empty<br>                } else {<br>                    NoteUiStateModel.Fetched(notes.map { it.toNoteUiModel() }.toPersistentList())<br>                }<br>            }<br>            .flowOn(Dispatchers.Main)<br>            .stateIn(<br>                viewModelScope,<br>                SharingStarted.WhileSubscribed(5000),<br>                NoteUiStateModel.Loading<br>            )<br>    }<br>}</pre><p>And finally, our ViewModel. We inject our use case because, for this feature, we only need to observe our list of notes and to display it.</p><p>Room being reactive, any addition to the database <strong>triggers</strong> the observable variable <em>noteState </em>(because it is a Flow). Depending on the data received, we adjust the UI with the appropriate model. Here, we use <em>NoteUiStateModel</em> which is a sealed interface comprising 3 possibilities: Loading (default state), Empty, and Fetched.</p><p>To enhance app performance, you can set your list as being <a href="https://developer.android.com/develop/ui/compose/performance/stability/fix">persistent</a>. This prompts the Compose compiler to mark the list as stable.</p><h3>Conclusion</h3><p>We made it to the end! Congratulations! I hope you gain some new insights and that I have aroused your curiosity.</p><p>However, for the sake of simplicity in this article, there are some topics that I haven’t covered, such as (non-exhaustive list):</p><ul><li>The use of SavedStateHandle in our ViewModel (you should definitely explore it, documentation is <a href="https://developer.android.com/topic/libraries/architecture/viewmodel/viewmodel-savedstate">available here</a>)</li><li>The implementation of Hilt across our projects (although you may have noticed our DI module in almost every module). On the other hand, if you want to explore <a href="https://www.jetbrains.com/kotlin-multiplatform/">KMP</a>, <a href="https://insert-koin.io/docs/quickstart/kmp">Koin</a> is definitely the best dependency injection tool!</li><li>The Navigation pattern. I highly recommend checking out <a href="https://www.francescvilarino.com/injectable-navigator-in-jetpack-compose">Francesc Vilariño’s article</a> on this topic. It is the approach I currently use in all my projects. And recently, the Android team cooked us something really great: <a href="https://medium.com/androiddevelopers/navigation-compose-meet-type-safety-e081fb3cf2f8">Ian Lake made this article</a> about Compose Navigation being Type Safe 🎊!</li></ul><p>You can find both of these projects on my Github page: <a href="https://github.com/morganesoula/NoteApp">NoteApp</a> and <a href="https://github.com/morganesoula/NoteAppClean">NoteAppClean</a>.</p><p>Again, I explore <a href="https://medium.com/@morganes56/from-junior-to-senior-modularization-in-clean-architecture-android-projects-8eb9de2a84a0">modularization in this second article</a>. Check it out 😊</p><p>Let’s connect on <a href="https://www.linkedin.com/in/morgane-soula-08b33312a/">LinkedIn</a> if you want to see more!</p><p><strong>Stay tuned</strong> for another episode of the Android ecosystem 👀!</p><p>Keep coding, keep exploring new topics and, most importantly, keep enjoying it!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxPzSQiqskMriWf7HRm%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNnJ3ejB6cjl3OW1pYnphZDhndzljZzRodWd1Y2EyYjJwdjJqcW80YyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxPzSQiqskMriWf7HRm%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbmxzMDkzZmY4NnRzd2t2ZG5tZXJvYWRodGIzdHhxajU4a2lzNzQ1MiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxPzSQiqskMriWf7HRm%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c222ab196d43ab42c2df6d0ad12826f/href">https://medium.com/media/2c222ab196d43ab42c2df6d0ad12826f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8514005e85e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/from-junior-to-senior-the-real-way-to-implement-clean-architecture-in-android-8514005e85e1">From Junior to Senior: the real way to implement Clean Architecture in Android</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reasons why I am not cut out to be a Developer (according to others) — part one]]></title>
            <link>https://medium.com/@morganes56/reasons-why-i-am-not-cut-out-to-be-a-developer-according-to-others-part-one-47c4fad4b8ba?source=rss-e368cd7aa90b------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c4fad4b8ba</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[storyofmylife]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Morgane Soula]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 16:28:41 GMT</pubDate>
            <atom:updated>2024-04-04T16:28:41.841Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reasons why I am not cut out to be a Developer (according to others) — part one</h3><p>I have been working as an Android Developer for over 6 years now and I have accumulated my fair share of stories. Everywhere I look (hello LinkedIn) I see tales of perfect experiences, welcoming teams, and wonderful companies. But I never hear about the <strong>downfalls</strong>, the tough moments, the times of doubt and the way people do not like you that much actually. Progressing in a company, or within society, brings many upgrades but it should also be interesting to dive into the moments where you failed because or thanks to others. <br>Let’s dive into the <strong>less glamorous side</strong> of your professional growth.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3oEduNYqBMGd7c4wes%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZHZiMTE1M3hjcHpjNms3bjZ2YXZ6Yzg5OXRnZXFteXphNnZyaHI5ZyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F3oEduNYqBMGd7c4wes%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdWF2NXN0eW1nMzhrc2k5ZDd6dGw2azdkNzY2bmwzeTJvZjBwa3E5cCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F3oEduNYqBMGd7c4wes%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="272" frameborder="0" scrolling="no"><a href="https://medium.com/media/32610738f743979c55e404644a670cd0/href">https://medium.com/media/32610738f743979c55e404644a670cd0/href</a></iframe><h3># False start</h3><p>I am <strong>average</strong>. I am not one of these people that knew what to do with their life the moment they took their first breath. When I was younger I wanted to be an archeologist but I was doing terrible in history class. Then I wanted to be a police commissioner but my height did not allow me to. After that, I wanted to defend people so I had decided I would become a lawyer. First year of law school seriously made me <strong>reconsider my plan</strong>. Finally, I wanted to be a reporter but school wasn’t for me anymore and I could not bear the idea to stay on a bench for 3 to 5 years. I needed <strong>experience</strong>. I needed <strong>to fit somewhere</strong>. I needed to be <strong>good at something</strong>.</p><p>So I returned to my first love. As an animal lover with too many cats (<em>and a human partner, so please leave your clichés in the trash</em>): I became an animal caretaker for rescues for 3 years. But something was <strong>missing</strong>. The job involved way too much repetitive tasks, narrow-minded people and no opportunities for financial growth.</p><p>At the end of my professional contract, my boss told me she was not doing me a favor by keeping me around and suggested that I consider a career in computer science. At this point, my only knowledge was a <em>very</em> limited experience with Excel documents.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl378g85zRcP4aCmJi%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNzlhZmhtOWhvdmNtaDh5Nmc0dzk4cmF2aTE1NnNldjFpYjRnMG5jaiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2Fl378g85zRcP4aCmJi%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExeWRlZTZyZmVtaHBsN2ZxaGNucXp1aHRvaG93Nm53dXlpM21hNGNtNCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2Fl378g85zRcP4aCmJi%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/702ef7357c0eea82d4c27345bbb3da9c/href">https://medium.com/media/702ef7357c0eea82d4c27345bbb3da9c/href</a></iframe><h3># And end is always followed by a beginning</h3><p>I attended more than 20 schools throughout my life (from kindergarten to universities) due to personal reasons. I had to move a lot so each time I went to a different school it was always the same story: “ Hello my name is Morgane, I am new here and I do not know how long I am gonna stay around ”.</p><p>In my country, you need to pick your academic “specialty” in the second year of high school. However my first year of high school was <strong>atypical</strong>: I attended one high school for 3 months, another for 3 weeks and yet another for 5 months. Let me tell you that I missed out on a lot of subjects and I did not really pick my specialty once I went to a different high school for my second and third year. <em>It picked me.</em></p><p>The three specialities were:</p><ul><li>Literature: you mostly study philosophy, languages and literature</li><li>Scientific: you mostly study biology, physique and mathematic</li><li>Economic: all about economics and socials sciences</li></ul><p>It was well-known that the sciences were for the <em>brainy</em> people and literature was for the <em>failures</em> as it would open less professional doors. Could you guess where I ended up? <br>Back to the chapter on computer science with a literature speciality, a lot of schools told me <strong>no</strong>: and honestly, I could not blame them. I don’t make the system, I had not the required mathematical level to continue. <br>So I went to college: it was <strong>free</strong>, I did not need <strong>any specific specialization</strong> as long as I had graduated from high school.</p><p>I chose one with these specializations: mathematics, statistics, and computer science.</p><p>And after 5 months, I dropped out.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FS2KjvbkV8NrmStDUBw%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdDFpbXBxNG9rdWQzb3A3Z28xOW5jeHlpb3o2a2tvbDkzdjY3dGoyMiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FS2KjvbkV8NrmStDUBw%2Fgiphy-downsized-large.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbTBqZ2RkcDUwaG9uNThpa3poajBpNmhndzlycTh1MGxqenRqcjFqOSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FS2KjvbkV8NrmStDUBw%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/d276e52171953ccbe6029e508462c3d7/href">https://medium.com/media/d276e52171953ccbe6029e508462c3d7/href</a></iframe><h3># No door? Try the window</h3><p>I was back on the school benches, loathing every second of it. Plus, my mathematical skills were really lacking even though I loved — and still do — the subject. So, I dropped out. But of course, I had a safety net. One thing you need to know about me: I always have a safety net and I always plan my exits. I <strong>act quickly,</strong> but I am not reckless.</p><p>A computer science course opened up in my city and it seemed <strong>perfect</strong> for me: computer science curriculum, 6 months in duration and a job <strong>waiting for me</strong> at the end of the training with a good salary. I successfully completed the course but let’s be honest, was I smart enough to compete on the job market against people with <strong>3 or more years of experience</strong>? Not. A. Chance. Be really careful with courses that promise you countless wonders. Unless you are a genius and can prove it, a company will always prefer the most <strong>experienced</strong> candidate. Even if you are likable, even if you are highly motivated. Keep the attitude, but <strong>keep also working</strong>.</p><p>Luckily for me, I don’t take any word for <strong>granted</strong>. I felt uncertain about my knowledge and decided to pursue my education before applying for any job. I came across a private school (bear with me, I do not come from a rich and stable financial family) and signed a contract with them on one required condition: find a company to work for for <strong>2 years</strong>. The company pays for your education and you would also receive a minimum wage salary. Where is the catch?</p><p>It took me <em>eight months</em> to find a company to work with. <strong>Eight. Months.</strong> Remember the promised wonders mentioned earlier? That you could find any job right after the course? <strong><em>For sure</em></strong>. I went through so many interviews, and it was always the same verdict: “We like you, you have a good and strong personality but you are <strong>lacking experience</strong>”. When I was not <strong>ghosted</strong>. And after eight months, I was ready to call it quits and try a completely different path (still no idea what, honestly 😂).</p><p>I had this last interview booked and I always honor my commitments. But I was <em>so over it</em>, I did not even dressed well (I wore a sweater with a panda on it 😂). It was a quick job dating session, fifteen minutes tops, and I barely said a word: the manager did most of the talking, I just nodded along. They liked my previous experience because I learnt PHP, and before I knew it, I got hired for two years.</p><p>Little did I know the journey that awaited me.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FznodP9eurvThe%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdG45OTZ1bHo0dnU4cmI5cXo3M21jMTZ2bzFiOGljb3RmeXBoNWJydCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FznodP9eurvThe%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdml3aTAxNTl0eXpuYzN0MnVwcHM5ZGZqYjVkOXZpbXVoZDd6dmxxZyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FznodP9eurvThe%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="228" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc6ba6e4645e53103167910ac750a8a4/href">https://medium.com/media/fc6ba6e4645e53103167910ac750a8a4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c4fad4b8ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>