<?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 Pavlos-Petros Tournaris on Medium]]></title>
        <description><![CDATA[Stories by Pavlos-Petros Tournaris on Medium]]></description>
        <link>https://medium.com/@p.tournaris?source=rss-d2295c5f4208------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EG1uNqa-nvwomMiUISDZKg.jpeg</url>
            <title>Stories by Pavlos-Petros Tournaris on Medium</title>
            <link>https://medium.com/@p.tournaris?source=rss-d2295c5f4208------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:57:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@p.tournaris/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[Revolutionizing PostgreSQL Database Comparison: Introducing pgdatadiff in Rust — Unleash Speed…]]></title>
            <link>https://medium.com/@p.tournaris/revolutionizing-postgresql-database-comparison-introducing-pgdatadiff-in-rust-unleash-speed-e232a8bef31b?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/e232a8bef31b</guid>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Thu, 14 Mar 2024 20:04:47 GMT</pubDate>
            <atom:updated>2024-03-14T20:04:47.693Z</atom:updated>
            <content:encoded><![CDATA[<h3>Revolutionizing PostgreSQL Database Comparison: Introducing pgdatadiff in Rust — Unleash Speed, Safety, and Scalability</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5NjvXTkrax__Kw5Ld0Vzzg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@cadop?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mathew Schwartz</a> on <a href="https://unsplash.com/photos/time-lapse-photography-of-tunnel-sb7RUrRMaC4?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><p>🚀 Exciting News Alert! 🚀</p><p>🔍 Re-introducing pgdatadiff: Now in Rust! 🦀</p><p>🎉 We’re thrilled to announce the launch of the revamped pgdatadiff, now powered by Rust! Teaming up with my colleague <a href="https://www.linkedin.com/in/ACoAABuiMX4BIcHKSZK-poHxJRTYpaXAaPIfxM0">Nick Nikitas</a>, we’ve rewritten this essential tool for enhanced performance, robustness, and scalability.</p><p>🔧 pgdatadiff, originally written in Python, has undergone a remarkable transformation into Rust, leveraging the language’s speed, safety, and concurrency features to provide a seamless experience for PostgreSQL database administrators and developers.</p><p>🚀 Key Features:<br>✨ Lightning-fast performance: Take advantage of Rust’s performance to compare large datasets with blazing speed.<br>🔒 Enhanced reliability: Rust’s strong type system and memory safety guarantees ensure robust and secure database operations.<br>🔍 Comprehensive difference analysis: Effortlessly identify variances between database states, facilitating smooth data management and troubleshooting.<br>🌐 Cross-platform compatibility: Enjoy the flexibility of pgdatadiff across various operating systems, making it accessible to a broader audience.<br>🧰 Simple integration: Easily incorporate pgdatadiff into your existing workflows with its intuitive command-line interface.</p><p>🌟 Whether you’re a seasoned database administrator or a budding developer, pgdatadiff in Rust empowers you to streamline your database comparison tasks with unparalleled efficiency and confidence.</p><p>💡 Ready to elevate your PostgreSQL database management experience? Dive into the world of pgdatadiff in Rust today!</p><p>👉 Get started now: <a href="https://github.com/pavlospt/rust-pgdatadiff">https://github.com/pavlospt/rust-pgdatadiff</a></p><p><a href="https://www.linkedin.com/feed/hashtag/?keywords=rustpgdatadiff&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#rustpgdatadiff</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=rust&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#Rust</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=postgresql&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#PostgreSQL</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=databasemanagement&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#DatabaseManagement</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=dataanalysis&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#DataAnalysis</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=opensource&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#OpenSource</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=techinnovation&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#TechInnovation</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=developertools&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#DeveloperTools</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=codeinrust&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#CodeInRust</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=upgradeyourworkflow&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7174131957583273985">#UpgradeYourWorkflow</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e232a8bef31b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradle Kotlin DSL— Dynamically discover project modules]]></title>
            <link>https://proandroiddev.com/gradle-kotlin-dsl-dynamically-discover-project-modules-25204096c3b?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/25204096c3b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[gradle]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 09:14:33 GMT</pubDate>
            <atom:updated>2020-08-20T09:29:41.884Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PUGaRCsqwcE9gi7jhq9m6w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kaleidico?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kaleidico</a> on <a href="https://unsplash.com/s/photos/modules?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A lot of modern Gradle projects are starting as a monolith during the prototyping phase, but soon enough when the project has matured you start realising that a modularized project has a lot of advantages.</p><ul><li>Caching</li><li>Cleaner architecture (in terms of separation of concerns)</li><li>Re-usability of same module, in other applications</li></ul><h3>Module creation</h3><p>This is a pretty straight forward process in any Gradle project, but for the sake of the example let’s assume that we are using Android Studio here (IntelliJ based IDE for Android).</p><p>Through File -&gt; New -&gt; New Module we can create any kind of module from the list of available module wizards.</p><p>After creating it, what usually happens is that a new entry is getting added in settings.gradle .</p><h3>Issues</h3><p>In case someone is using Gradle Kotlin DSL though, the entry will not be added automatically or will create a new</p><pre>include(&quot;:module-name&quot;)</pre><p>directive in settings.gradle.kts file of our root project.</p><p>This in turn creates a lot of hassle when trying to heavily modularize an application.</p><p>Also given the team size that is currently modularizing the project, there can be a lot of conflicts on settings.gradle.kts each time a new PR for a module is merged and the rest of the team needs to rebase from the main branch.</p><h3>Dynamically discover modules</h3><p>Our idea around resolving that issue was to write some code that would dynamically discover modules in our project. We based our solution on some naming prefixes we are using for our modules (e.g.: android-core , kotlin-core etc). But basically the following code can be tweaked and work for any project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4d216caa76a289af65ae3a8c1fd9668/href">https://medium.com/media/b4d216caa76a289af65ae3a8c1fd9668/href</a></iframe><p>This seems to be working fine for our case and hopefully for other projects :) Feedback is always welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25204096c3b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/gradle-kotlin-dsl-dynamically-discover-project-modules-25204096c3b">Gradle Kotlin DSL— Dynamically discover project modules</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android MVI architecture with Jetpack & Coroutines/Flow — Part 3]]></title>
            <link>https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-3-5ef0c0960ce9?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ef0c0960ce9</guid>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Sat, 02 May 2020 10:56:16 GMT</pubDate>
            <atom:updated>2020-05-28T11:19:38.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android MVI architecture with Jetpack &amp; Coroutines/Flow — Part 3</h3><h3>Creating Coroutines/Flow empowered UseCases</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STrvjUFZAADmmxfcYMTb8g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kelly Sikkema</a> on <a href="https://unsplash.com/s/photos/programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>If you haven’t read the previous articles of these series, you can find them here:</blockquote><blockquote><a href="https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-1-recyclerview-adapter-w-83a10134207f">Part 1 — RecyclerView adapter with ViewBinding</a></blockquote><blockquote><a href="https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-2-bc1f3cb1dd2d">Part 2 — Creating ViewModels in an MVI architecture</a></blockquote><blockquote>In this article we will see how to create different types of UseCases that will be used in our ViewModels.</blockquote><h3>What is a UseCase?</h3><blockquote>A <strong>UseCase</strong> is a list of actions or event steps typically defining the interactions between a role (known in the <a href="https://en.wikipedia.org/wiki/Unified_Modeling_Language">Unified Modeling Language</a> (UML) as an <a href="https://en.wikipedia.org/wiki/Actor_(UML)"><em>actor</em></a>) and a system to achieve a goal. The actor can be a human or other external system. In systems engineering, use cases are used at a higher level than within <a href="https://en.wikipedia.org/wiki/Software_engineering">software engineering</a>, often representing missions or <a href="https://en.wikipedia.org/wiki/Project_stakeholder">stakeholder</a> goals. The detailed requirements may then be captured in the <a href="https://en.wikipedia.org/wiki/Systems_Modeling_Language">Systems Modeling Language</a> (SysML) or as contractual statements.</blockquote><p>This is the definition provided by Wikipedia <a href="https://en.wikipedia.org/wiki/Use_case">here</a>.</p><blockquote>But what is actually a UseCase in our project?</blockquote><p>In many applications there are parts of our business logic that involve the coordination of several local or remote sources in order to achieve a goal.</p><p>For example, whenever we make an API call to fetch a Github repository’s information, we also want to store this information or update it in case we already have this Github repository’s information stored. This is a business flow that can be triggered from several places in our application.</p><p>Due to that need we need to have it written only once and test that component in isolation :)</p><h3>Entering UseCases</h3><p>Our <strong>UseCase</strong> examples are heavily influenced from Chris Banes’ TIVI <a href="https://github.com/chrisbanes/tivi">repo</a>.</p><h4>FlowUseCase</h4><p>We want to extend <strong>FlowUseCase</strong> whenever we have observable/streamable results (e.g.: database changes), in the form of Flow&lt;T&gt; .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a3969c20ce181895d0d83de9a1b28df/href">https://medium.com/media/6a3969c20ce181895d0d83de9a1b28df/href</a></iframe><p>Our abstract class here, is implementing the ObservableUseCase&lt;T&gt; which defines a property and a method.</p><ul><li>dispatcher is the Kotlin Coroutines Dispatcher that we will use in order to execute our UseCase’s work. Usually this can be Dispatchers.IO for network or database operations, or Dispatchers.Default if we want to execute CPU intensive tasks.</li><li>observe is the method that will return a Flow&lt;T&gt; containing the results of our UseCase’s actions.</li></ul><p>FlowUseCase&lt;Params: Any, Type : Any&gt; abstract class includes a channel that accepts the Params type. Params can be any type of data that our UseCase needs in order to execute its actions and produce the result.</p><p>As we can also see here, the invoke operator is being overriden in order to send the Params input to our internal channel.</p><p>The channel then is converted to a Flow and is flatMap ‘d in order to execute the method that produces a Flow&lt;T&gt; result, which is doWork(Params) .</p><h4>NoResultUseCase</h4><p>We want to extend <strong>NoResultUseCase</strong> whenever we have an action that we want to execute without caring for the actual success or failure of the task since it may not be critical to our business logic, or will not impact our user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/025d2790b7c748b571adef63a2970005/href">https://medium.com/media/025d2790b7c748b571adef63a2970005/href</a></iframe><p>In this <strong>UseCase</strong> all we need to do, is provide the Dispatcher that best fits our needs, based on our previous explanation. It will then switch Coroutines context to that Dispatcher and execute any action given in run method.</p><h4>ResultUseCase</h4><p>We want to extend <strong>ResultUseCase</strong> whenever we have an action that we want to execute, but we actually care of its result. This can be in cases our product needs to also do error handling or inform the user that the action was not successfully completed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08d7fa3e54d8092e08dc2badfeadeac0/href">https://medium.com/media/08d7fa3e54d8092e08dc2badfeadeac0/href</a></iframe><p>As previously we need to indicate the Dispatcher that we want our UseCase to utilize. Here our run method though has a return type. In our case this type is Result , which can take 2 different forms. It can be either a Success or a Failure . Usually we can create that very simple Result class with a sealed class, but generally this is based on the project’s needs.</p><h3>Conclusion</h3><p>The above base <strong>UseCase</strong> classes are usually enough to satisfy our needs on a project, but like I always say “it depends”. In a later article we will also explore how easy it is to test our UseCases in isolation.</p><p>You can find all of the code above and examples of their usage to the following repo, which will be the one we will cover in this series of articles!</p><p><a href="https://github.com/pavlospt/refactored-umbrella">pavlospt/refactored-umbrella</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ef0c0960ce9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-3-5ef0c0960ce9">Android MVI architecture with Jetpack &amp; Coroutines/Flow — Part 3</a> was originally published in <a href="https://medium.com/google-developer-experts">Google Developer Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android MVI architecture with Jetpack & Coroutines/Flow — Part 2]]></title>
            <link>https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-2-bc1f3cb1dd2d?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc1f3cb1dd2d</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 12:54:44 GMT</pubDate>
            <atom:updated>2020-04-11T15:53:21.810Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android MVI architecture with Jetpack &amp; Coroutines/Flow — Part 2</h3><h3>Creating ViewModels in an MVI architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lu7PUSB3Q-P0IYi4AlhBw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@nordwood?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">NordWood Themes</a> on <a href="https://unsplash.com/t/business-work?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>If you haven’t read the previous article of these series, you can find it here:</blockquote><blockquote>Part 1 — <a href="https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-1-recyclerview-adapter-w-83a10134207f">RecyclerView adapter with ViewBinding</a></blockquote><blockquote>Now that we have created a base RecyclerView adapter in order to bootstrap lists, we need to see how we will fetch , transform and present the data of our screen.</blockquote><h3>Entering ViewModel</h3><p><strong>ViewModel</strong> is the Jetpack component that we will need to extend in order to host the orchestration of several other components. The orchestration of the other components will result in fulfilling our business goals.</p><p>Usually in a <strong>ViewModel</strong> we will need to make some API calls or Database operations and accordingly display our updated information in the UI consumer of our ViewModel.</p><p>The components that we will showcase and are currently using in our example project, are UseCases aka Interactors.</p><p>We prefer to “inject” those usecases into the constructor of our ViewModel. By doing this, we gain in testability.</p><h3><strong>Constructor injection</strong></h3><h4>With Koin</h4><p>A <strong>ViewModel </strong>can have its dependencies injected on its constructor pretty easily if we are making use of Koin.</p><p>We declare a new Koin module like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6d2108e6b067de60daa20b704fa4678/href">https://medium.com/media/b6d2108e6b067de60daa20b704fa4678/href</a></iframe><p>We use factory in order to always get a new instance injected in our <strong>ViewModel</strong> (depending on the needs of our app and the work done by our usecase, it might be suitable to declare it as a singleton). The rest of the dependencies of our <strong>UseCase</strong> are fetched from the rest of the graph (we will analyze that in a future article).</p><h4>With Dagger</h4><p>In order to inject dependencies through constructor when using <strong>Dagger</strong>, we need to create a <strong>ViewModelFactory</strong> and bind our <strong>ViewModels</strong> by their class name to the <strong>Dagger</strong> graph.</p><p>A quick implementation of that injection is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b2cf7c2b748d9f9cf504fe97f9ef59d/href">https://medium.com/media/3b2cf7c2b748d9f9cf504fe97f9ef59d/href</a></iframe><h3>User actions consumption in ViewModel</h3><p>Since our desired architecture is an MVI one, we need to create a stream of user actions/intentions that our <strong>ViewModel</strong> will consume and act upon.</p><p>The approach we have used in our example project is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a9dfd8a6d02d04eb6c36b33461c5ed0/href">https://medium.com/media/3a9dfd8a6d02d04eb6c36b33461c5ed0/href</a></iframe><p>Our <strong>ViewModel</strong> here is using a ConflatedBroadcastChannel which is converted to a Flow in our init method. On each emission we are invoking the equivalent suspend fun that will either produce some data to be propagated on our UI or do some other work!</p><h3>Exposing data to our UI (lifecycle aware) components</h3><p>Now that we are able to consume user actions/intentions we need to see how we will propagate data to our UI.</p><p>In order to do that we will prefer to use the database as our single source of truth and produce a stream of data that we might pre-process before delegating to our UI.</p><p>For the example we will observe a table in our local database, where we have stored all of our Github repositories (we will examing how we fetched them on a future article).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a782459431bf265dd473e4eb747865c/href">https://medium.com/media/5a782459431bf265dd473e4eb747865c/href</a></iframe><p>Our injected <strong>UseCase</strong> here can be observed in order to return a <strong>Flow&lt;T&gt;</strong> after it has been invoked in order to produce its work. The invocation of the <strong>UseCase</strong> is being done on the end of our init method.</p><p>We then map the emitted database entities into our adapter items and convert them to <strong>LiveData</strong> before we “send” them to our UI (in our case a <strong>Fragment</strong>). Last but not least, since we are using Flow, we need to use the viewModelScope.coroutineContext in order to take advantage of buil-in cancellation for our <strong>Flow</strong>.</p><p>All we need to do now is just observe this <strong>LiveData</strong> and submit the list of items to our adapter. By taking into account the fact that we diff our items properly base on the work we have done in the previous article, we can be sure that despite the number of invalidations in our DB table we will have the minimum required updates in our adapter.</p><p>Another enhancement we can do here, is to also use .distinctUntiChanged() operator in order to avoid identical database emissions.</p><blockquote>Disclaimer: UseCase implementation is inspired by <a href="https://medium.com/u/9303277cb6db">Chris Banes</a> TiVi repo</blockquote><h4>Conclusion</h4><p>This is a proposed way of how to approach an MVI architecture based on what we have seen that works for us :) We will cover the testing part of our <strong>ViewModel</strong> in one of the following articles! Any enhancements or suggestions are welcome! #staysafe</p><p>You can find all of the code above and examples of their usage to the following repo, which will be the one we will cover in this series of articles!</p><p><a href="https://github.com/pavlospt/refactored-umbrella">pavlospt/refactored-umbrella</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc1f3cb1dd2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-2-bc1f3cb1dd2d">Android MVI architecture with Jetpack &amp; Coroutines/Flow — Part 2</a> was originally published in <a href="https://medium.com/google-developer-experts">Google Developer Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android MVI architecture with Jetpack & Coroutines/Flow — Part 1 — RecyclerView Adapter w/…]]></title>
            <link>https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-1-recyclerview-adapter-w-83a10134207f?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/83a10134207f</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Sun, 29 Mar 2020 21:07:42 GMT</pubDate>
            <atom:updated>2020-03-30T09:10:01.226Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android MVI architecture with Jetpack &amp; Coroutines/Flow — Part 1</h3><h3>RecyclerView Adapter with ViewBinding</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdHQrw_ZDOQnCQLS-OromA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@mikeanywhere?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Mike Lewis HeadSmart Media</a> on <a href="https://unsplash.com/s/photos/flow?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I have been developing on Android since late 2011 and always remember that we wanted, since the early days, Google to be opinionated about the suggested architecture on Android :)</p><p>This indeed happened a few years later, with Jetpack’s Android Architecture Components, which introduced <strong>ViewModels</strong>. <strong>ViewModels</strong> is the <strong>VM </strong>part of a <strong>MVVM </strong>architecture and can also survive configuration changes on screens. ViewModels communicate with the UI through an observable stream implemented by <strong>LiveData</strong>.</p><p>The thing though, is that the community also needed a new way to make async API calls and Database operations (or generally off-main thread work) easier, without the learning curve that the RxJava has for most of beginners on Reactive frameworks. The alternatives to RxJava were also quite boilerplate-y and more prone to be used incorrectly from people that are not good on primitive threading &amp; concurrency, like me 😝!</p><h3>Enter Kotlin Coroutines &amp; Flow</h3><p>The community though had started recently been switching to Kotlin Coroutines, which offer structured concurrency and Kotlin Flow that can essentially replace the RxJava way we used to work, in order to transform the data between our architecture’s layers, to a stream. That could be either a bi-directional or a uni-directional fashion, depending on the needs of each project.</p><h3>What we are going to cover</h3><p>In this series of articles we are going to see how we created a new app that fetches Github repositories of a Github user, persists them in the local storage and observes the local storage only, in order to display any UI changes. We will also see how we can create a RecyclerView ListAdapter with the help of newly released ViewBinding, in order to also leverage the diffing functionality for free.</p><p>In order to achieve all of the above we will make use of Jetpack’s Android Architecture Components and also Kotlin Coroutines + Flow for the parts that we will need to do asynchronous work on any of our layers, either that is a remote API source, or our local storage which will be backed by Room.</p><p>Last but not least, we will see how we modularized the application and configured our Kotlin style &amp; static code analysis tools for a multi-module project (Detekt + Spotless). At the end we will see how to leverage all of this configuration in order to create a seamless CI pipeline for our newly created app.</p><h3>Creating a base RecyclerView adapter with ViewBinding</h3><p>In order to create a base adapter for all of our RecyclerViews in the app, we decided to make use of the newly released ViewBinding as well and use ListAdapter’s functionality to implement diffing quite easily.</p><h4>Creating a base adapter item</h4><p>By doing this we will be able to have a single interface to implement and use as common configuration for our adapter’s items.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/238354db071ed2b968c560850354073d/href">https://medium.com/media/238354db071ed2b968c560850354073d/href</a></iframe><p>This item only includes an itemViewType property so that we can have polymorphic RecyclerView adapters. We only need this property for now, but we can surely add more in order to enrich our base functionality in the future.</p><h4>Creating a base ViewHolder</h4><p>Our base ViewHolder will be extended from each ViewHolder in each of our adapters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/900cafb0730405b170005b3a1e682115/href">https://medium.com/media/900cafb0730405b170005b3a1e682115/href</a></iframe><p>What we do here is create an abstract class and use generics to utilize the base adapter item we have created above and the ViewBinding for the item’s layout.</p><p>The bind method for our ViewHolder is abstract since we require every new ViewHolder extending that one to implement this method.</p><p>The other available method is bind with a List of payloads that can help us partially update our rows in the RecyclerView. Since we are overriding both of them on the base adapter (see below) we need to make that method open and provide a default implementation that calls abstract bind(item: Item) in order to ensure that we fallback correctly when the diffing operation does not output any results (see below).</p><h4>Creating a base adapter</h4><p>Our base adapter will extend from ListAdapter since we want to use DiffUtil for diffing in our RecyclerViews.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb67720ec1abf4191e03dbe55484ecb0/href">https://medium.com/media/fb67720ec1abf4191e03dbe55484ecb0/href</a></iframe><p>The implementation we have here just delegates the onBindViewHolder methods to our own ViewHolders. We also provide an extension function for easier access to the layout inflater when creating a new adapter.</p><h4>Creating a base DiffUtil callback</h4><p>Our base DiffUtil callback will extend from DiffUtil.ItemCallback and use ViewBindingAdapterItem as a generic input.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76b27c574b80f23b63bf018aca19600c/href">https://medium.com/media/76b27c574b80f23b63bf018aca19600c/href</a></iframe><h3>Conclusion</h3><p>We can now create as many adapters as we want with minimal effort by just extending the already created base components :)</p><p>You can find all of the code above and examples of their usage to the following repo, which will be the one we will cover in this series of articles!</p><p><a href="https://github.com/pavlospt/refactored-umbrella">pavlospt/refactored-umbrella</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83a10134207f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-developer-experts/android-mvi-architecture-with-jetpack-coroutines-flow-part-1-recyclerview-adapter-w-83a10134207f">Android MVI architecture with Jetpack &amp; Coroutines/Flow — Part 1 — RecyclerView Adapter w/…</a> was originally published in <a href="https://medium.com/google-developer-experts">Google Developer Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CloudBuild: Open-sourcing Cancelot]]></title>
            <link>https://medium.com/@p.tournaris/cloudbuild-open-sourcing-cancelot-de58f3ceaa83?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/de58f3ceaa83</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google-cloud-build]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[cloud-build]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 19:54:06 GMT</pubDate>
            <atom:updated>2019-09-11T14:35:23.557Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Automatically cancel running builds on the same branch, when a new commit is pushed</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*VfGSmcGRGBYfKcUuAAOgSw.png" /><figcaption>Image taken from: <a href="https://cloud.google.com/images/products/cloud-build/cloud-build.png">https://cloud.google.com/images/products/cloud-build/cloud-build.png</a></figcaption></figure><p>CloudBuild is a CI/CD offered by Google. At <a href="https://medium.com/u/e5ecc5b405f2">Workable</a>’s Mobile department we made a proof of concept to check if CloudBuild fits our needs in order to be used for artifact (APK) building.</p><p>A complex project requires a lot of custom configuration in order to properly set it up and we were able to find most of them in the great CloudBuilders community repo.</p><h3>Cancelling a running build</h3><p>CloudBuild builds though come at a cost and depending on your budget and the machine type you use. So having builds run for multiple commits that are pushed on a branch, means a bigger cost on your monthly bill.</p><p>As you might have guessed this is something that would not work in case multiple members of our team were working on the same branch and pushing commits with a high frequency.</p><p>We need to find a solution that would let us cancel any previously running builds in favor of the new ones.</p><h3>Entering Cancelot</h3><p>Cancelot is the name of the Builder we built for the purpose described above. Initially our team had named it “Ralph” from the movie “Wreck-it Ralph”, but Twitter is so resourceful and came up with the name “Cancelot”.</p><p>Cancelot is added as a buildstep on your CloudBuild YAML file and is responsible to check for any builds that are currently running for the same branch.</p><p>It makes use of the CloudBuild Go package in order to fetch the running builds, by filtering with the following criteria:</p><pre>build_id != &quot;[CURRENT_BUILD_ID]&quot; AND <br>source.repo_source.branch_name = &quot;[BRANCH_NAME]&quot; AND <br>status = &quot;WORKING&quot; AND <br>start_time&lt;&quot;[CURRENT_BUILD_START_TIME]&quot;</pre><p>After successfully fetching any previously started (&amp; still running builds) it loops through them and cancels them.</p><h4>Usage</h4><p>Cancelot’s usage and setup is inspired by the CloudBuilders “slackbot” so it is very easy to use it.</p><ul><li>Deploy the GCR image of Cancelot to your project’s GCR</li><li>Add Cancelot’s buildstep in your CloudBuild YAML file</li></ul><pre>steps:<br>- name: &#39;gcr.io/$PROJECT_ID/cancelot&#39;<br>  args: [ <br>    &#39;--current_build_id&#39;, &#39;$BUILD_ID&#39;,<br>    &#39;--branch_name&#39;, &#39;$BRANCH_NAME&#39;<br>  ]</pre><h3>Open Source</h3><p>We wanted to give back to the community, just like we were able to use the great stuff that other members have built. Cancelot currently lives on an open PR in CloudBuilders community repository. You are free to use it at your own will until the PR is either accepted or closed 😄</p><p>Edit: <strong>Cancelot</strong> has now been merged into CloudBuilders repo :D You can find the official builder there!</p><p><a href="https://github.com/GoogleCloudPlatform/cloud-builders-community/pull/271">[New builder] Introduce Cancelot by pavlospt · Pull Request #271 · GoogleCloudPlatform/cloud-builders-community</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de58f3ceaa83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducing Android Gradle module configuration boilerplate]]></title>
            <link>https://medium.com/@p.tournaris/reducing-android-gradle-module-configuration-boilerplate-93ee661c80c4?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/93ee661c80c4</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-dsl]]></category>
            <category><![CDATA[gradle]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 18:04:31 GMT</pubDate>
            <atom:updated>2019-07-21T15:51:53.624Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*Cq5mVmjuJzaqN2yOfuouRw.png" /><figcaption>Image taken from: <a href="https://bit.ly/32EDPVH">https://bit.ly/32EDPVH</a></figcaption></figure><p>Our codebase at <a href="https://medium.com/u/e5ecc5b405f2">Workable</a>’s Android app has grown over the years due to the wide variety of features we offer. As most of you already know, a single monolithic Android app is often one factor that contributes to slow build times.</p><p>One of the proposed ways of reducing build times, is to split the monolithic app module into smaller modules, that could be cached and compiled once. The suggested way of achieving that is to create more Kotlin/Java modules in comparison to Android modules and have the least possible inter-dependencies between those modules in order to avoid changes that would cause more upstream modules to re-compile.</p><p>After deciding on the ideal way for us to structure each new module, we started un-tangling our codebase and creating simple and small modules.</p><p>Most of them though had to be Android ones, since we needed to use Android dependencies or they represented a feature of the app.</p><h3>Creating a new module</h3><p>When creating a new module, we needed to have the same compileSdkVersion — targetSdkVersion — minSdkVersion values like the ones existing in the app module. This was a trivial task at first since all those versions were referenced from a versions.gradle file and they would automagically generate proper accessors.</p><h4>Entering KotlinDSL</h4><p>When we decided that we should move all our build.gradle files to KotlinDSL, the automagic generation of accessors became a little bit of boilerplate since now we needed to reference all those properties in the following fashion, before using them:</p><pre>val compile_sdk_version: Int by rootProject<br>val min_sdk_version: Int by rootProject<br>val target_sdk_version: Int by rootProject</pre><p>The way this worked, is that we applied the versions.gradle file on the root level build.gradle file, so we could reference all these values by the rootProject property delegate.</p><p><em>It might not be the best way to do it, but this is what we have figured and was working for us at the time :D</em></p><h4>The boilerplate</h4><p>As you can imagine, having to copy all those properties on each modules build.gradle.kts file and specifying the android {} configuration every time, created a huge boilerplate process and added several not needed lines.</p><p>Here is an example of a new module’s build.gradle.kts :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7beedead138c6c7fe2f0ac11a0401714/href">https://medium.com/media/7beedead138c6c7fe2f0ac11a0401714/href</a></iframe><p>All this configuration is 11 lines, but there are more things that would add to those lines. For example if we specified compileOptions {} as well, it would reach 15 lines. Now multiply that x120 (which is the number of our modules currently) and right there you have 1800 lines of excess code and code prone to breaking all over the place if we made a single change on one of those properties for example.</p><h3>The solution</h3><p>The solution was not something new, it was just that we never tried it before. Might that be because we underestimated the number of modules we would produce or the fact that we did not have the time to devote in finding a better solution, at that point :D</p><h4>Root build.gradle.kts</h4><p>The root build.gradle.kts file gives us access to allprojects &amp; subprojects</p><ul><li>allprojects Are all the Gradle modules, including the root one</li><li>subprojects Are all the Gradle modules, excluding the root one</li></ul><p>The proper place to include our single configuration, as you have guessed is the subprojects since we did not need to configure anything on the rootProject .</p><h4>Configuring based on App/Library Android plugin</h4><p>Before adding any new configurations, we needed to check for each project in subprojects that it was applying either the AppPlugin or the LibraryPlugin since we wanted to configure the android part for those only (Kotlin &amp; Java modules have separate configurations that can be abstracted and configured once as well).</p><p>The root build.gradle.kts ended up looking somewhat like the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3441b91fdc181819755095adc66857c5/href">https://medium.com/media/3441b91fdc181819755095adc66857c5/href</a></iframe><h4>Diving in the code</h4><p>If we take a closer look at the code above, we can see that the following things are happening:</p><ul><li>Accessing PluginContainer in order to configure a project only when a plugin is added.</li><li>Based on the plugin class configuring separate things. AppPlugin can also specify versionCode &amp; versionName</li></ul><p>Another good observation here is that we use apply on the AppExtension/LibraryExtension , as well as defaultConfig &amp; compileOptions . The reason we are doing this, is because we do not want to override anything that was specified on the module’s build.gradle.kts . We just need to append those as well, so we retain the flexibility of using things like:</p><pre>android { dataBinding.isEnabled = true }</pre><p>without having to replicate the whole configuration in the modules that would need some more configuration.</p><p>Of course, there are more abstractions that can be applied to the above example, but this is left as a practice for the reader (hint: BaseExtension :D)</p><h3>Conclusion</h3><p>An interesting impact of that refactoring, is the additions/deletions in the PR applying the changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*SRlKkyy30xAlKrJQqoVChA.png" /></figure><p>Who would not be happy with that kind of change? :)</p><p>We are pretty confident that this will let us create more modules in the future, since we reduced some of the friction of creating one! I suggest you to try it even if you have a smaller number of modules :)</p><p><em>Would like to thank anyone who shared their advice while figuring out how to actually do this :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93ee661c80c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effectively disabling Crashlytics buildId re-generation in KotlinDSL]]></title>
            <link>https://medium.com/@p.tournaris/effectively-disabling-crashlytics-buildid-re-generation-in-kotlindsl-a3025d7c38c8?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3025d7c38c8</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-dsl]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[crashlytics]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Sat, 25 May 2019 12:17:26 GMT</pubDate>
            <atom:updated>2019-05-26T08:28:58.564Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*3p6QgdK_5UTWnDItgXW79Q.png" /><figcaption>Image taken from ProAndroidDev</figcaption></figure><p>Android Studio 3.5 has reached beta and it was time to try it out as a daily driver in work. Especially with Project Marble having introduced so many bug fixes and performance improvements, that meant the benefits would have an immediate effect.</p><p>Android Studio 3.5 also includes a new version of “instant run” written from scratch. Since we had it disabled in order to avoid possible build issues with the previous implementation, it was time to give the new “instant run” aka “Apply changes”, a try.</p><h3>The problem</h3><p>After enabling “Apply Changes” we tried changing something and just pressing the “Apply Code changes” button to check how fast it would work. After it finished building, the changes failed to take effect because and there was an issue reported in red color on Android Studio.</p><p>That issue was outlining that Resources had changed and that was the reason it failed to apply any changes made like it was supposed to. But it also included the offending resource file, which was: asssets/crashlytics-build.properties located in merged_assets/your_build_type/ of the main app module usually.</p><p>Immediately we thought that this was not supposed to happen, because we had disabled Crashlytics <strong>buildId </strong>re-generation in order to speed up build times and have better task caching for kapt &amp; Kotlin compilation.</p><h3>A bit of background</h3><p>Our Gradle files were all written in Groovy, but one time we decided to give KotlinDSL a try and migrated all of them.</p><p>In Groovy all we needed to do in order to disable Crashlytics <strong>buildId</strong> re-generation was to add the following:</p><p>ext { alwaysUpdateBuildId = false }</p><p>which translated to KotlinDSL was similar to:</p><p>ext.set(&quot;alwaysUpdateBuildId&quot;, false)</p><p>The above line was placed in a custom build type which was the one we were using to init some of the rest of our build types, that are being used for different staging servers. The setup was similar to something like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe006fc4227caf21daa811f50f230624/href">https://medium.com/media/fe006fc4227caf21daa811f50f230624/href</a></iframe><p>Apparently this solution was not correct. Since “Apply Code changes” yield such an error, we started investigating and actually trying out different solutions.</p><h3>The actual solution</h3><p>Fabric advises to use the syntax displayed above in order to disable <strong>buildId</strong> re-generation but KotlinDSL was not very fond of that. It seems that there is a compatibility issue between Groovy’s dynamic type generation and the way KotlinDSL works, so the flag was not properly propagated in order to disable re-generation.</p><p>After searching a bit around we found a few different ways to write the same thing, either on Github or on StackOverflow. Some of them, are the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2394a168fa962101cd465c5a6c79a126/href">https://medium.com/media/2394a168fa962101cd465c5a6c79a126/href</a></iframe><p>The correct one can be found on line 5. This solution though had to be manually applied on each <strong>buildType </strong>since it seems that it was not propagated when using the initWith function on custom <strong>buildTypes</strong>.</p><h4>Explanation</h4><p>As user Ivan Tokic mentions on their <a href="https://stackoverflow.com/a/55745719/1470614">answer</a>:</p><blockquote>You can only call extra on ExtensionAware objects, with BuildType not being declared as one.</blockquote><blockquote>However, during runtime, build types actually are ExtensionAware, which is why this works in Groovy due to its dynamicity, but not in Kotlin where extra in this scope will reference the Project&#39;s extensions.</blockquote><p>This was actually the reason that explained the mishap we had between our transition from Groovy to KotlinDSL.</p><h3>More on this</h3><p>While we were searching around for a fix and the reasoning, we also found a repo reproducing the error from a Gradle engineer: <a href="https://github.com/autonomousapps/Crashlytics-KDSL-Issue">https://github.com/autonomousapps/Crashlytics-KDSL-Issue</a>. Another solution that we found being suggested and was also suggested to us, was the creation of a *.gradle that would contain the disabling flag in <strong>extras </strong>written in Groovy, which would then be applied to the build.gradle file of the module that was utilizing the Fabric Gradle plugin:</p><p>apply(from = &quot;*.gradle&quot;) in app/build.gradle (most probably it is the main app module utilizing Fabric Gradle plugin)</p><h3><strong>Conclusion</strong></h3><p>We are very excited to try out the new “Apply Changes” feature and also very happy to see such detailed error reporting, which actually saved quite a few seconds in build time for us.</p><p>One thing to also keep in mind, is that when <strong>transitioning</strong> between Groovy and KotlinDSL we should be more careful from now on, since it is entirely possible to miss some details quite crucial to our daily workflow.</p><p>It is very re-assuring though to know that the Android community is great and there will always be out there someone that could help you debug the issue and provide a solution to your problem!</p><p>Thank you Ivan Tokic for that SO answer :D !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3025d7c38c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating to new Places SDK: Rx & Coroutines world]]></title>
            <link>https://medium.com/@p.tournaris/migrating-to-new-places-sdk-rx-coroutines-world-9adcedef20c?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/9adcedef20c</guid>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 13:10:51 GMT</pubDate>
            <atom:updated>2019-02-27T20:06:13.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEoKm2ynVwzuWU9pWrrahg.png" /><figcaption>Taken from <a href="https://cloud.google.com/blog/products/maps-platform/introducing-new-improved-places-sdks">https://cloud.google.com/blog/products/maps-platform/introducing-new-improved-places-sdks</a> Courtesy of Google.</figcaption></figure><h3>Context</h3><p>Up until <strong>January 29, 2019</strong> all Places functionality was part of Play Services. Since that day Google announced new <strong>Places SDKs</strong> for both <strong>Android</strong> &amp; <strong>iOS</strong> platforms. (<a href="https://cloud.google.com/blog/products/maps-platform/introducing-new-improved-places-sdks">https://cloud.google.com/blog/products/maps-platform/introducing-new-improved-places-sdks</a>). The deadline for the migration to new Places SDK, is <strong>July 29, 2019</strong>.</p><p>The new Places SDK brings in new methods replacing the previous ones, so this should be considered as a breaking change if you want to follow that path. However, there is a compat library released as well, which delegates all the calls on Location library from Play Services, to Places client.</p><p>In this article we will explore the migration to the new Places SDK on Android and provide helper examples for <strong>RxJava</strong> and <strong>Coroutines</strong>.</p><h3>Changed methods</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUQaee_MUOLSoDVU_V1BrQ.png" /></figure><p>As you can see, the above methods follow some common patterns:</p><ol><li>get verb has been removed from the functions’ names.</li><li>All methods have a common pattern for their type of argument and type of response. nameOfMethod.capitalize() + Request/Response This makes it quite easy to be able to construct your request data, just by thinking what method you need to invoke.</li><li>All the above methods are being invoked on an instance of PlacesClient which you can easily create by just calling: Places.createClient(context)</li></ol><h3>Entering the Rx world</h3><h4>Issues</h4><p>Previously we were using a wrapper library above the old Play Services Location library, which exposed all the functionality to a reactive fashion by converting a <strong>PendingResult </strong>to an <strong>Observable</strong>.</p><p>Although, this library has not received any updates since 2017 and it had also not been migrated to the newest style of Location library, which uses <strong>Task </strong>instead of <strong>PendingResult.</strong></p><h4>Initial approach</h4><p>Our initial approach was to fork the library and migrate it to use the newest Places SDK, but after the first proof-of-concept this turned to be a huge task and also quite bloated, since the parts we needed could be abstracted in something simpler (we will see below).</p><h4>Solution</h4><p>Since the burden of migrating the whole library was too much, we decided to convert the callback-style <strong>Task </strong>API, to a reactive way that would fit in our codebase and would produce the minimum changes needed.</p><p>The solution was pretty simple. All we needed to do is create a new class that would extend <strong>ObservableOnSubscribe.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0266ba2aa37690cfd90d893efb39cda/href">https://medium.com/media/c0266ba2aa37690cfd90d893efb39cda/href</a></iframe><p>This allowed us to create a simple extension function (we are using Kotlin, but this would be pretty trivial task in a Java codebase as well), to convert any <strong>Task </strong>to an <strong>Observable</strong>.</p><pre>fun &lt;T&gt; Task&lt;T&gt;.toObservable(): Observable&lt;T&gt; = Observable.create(TaskObservable(this))</pre><p>The last step was to remove the library we were using and replace the usage sites with our solution.</p><p>We should also notice here, that previously we were using the library as-is. After this change and since this is always a subject to change, the legacy part needed to be hidden behind an interface. This will save us time in the future, in case there are more changes to come and will make our testing easier.</p><h3>It’s 2019, who cares about Rx 😝</h3><p>You are probably right! A lot of people are converting parts of their Rx codebase or writing new things, that require asynchronous programming, with <strong>Coroutines</strong>.</p><p>Also that was a chance for us to get our hands dirty and try-out Coroutines and how we could achieve something similar to the Rx result.</p><p>The solution here was pretty simple as well. We only needed to convert the <strong>Task </strong>callback-style API to a <strong>suspend fun.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/682e76f04fa261556599e8eba5694467/href">https://medium.com/media/682e76f04fa261556599e8eba5694467/href</a></iframe><p>Once again, we added an extension function doing the work described previously. For the sake of simplicity we are only handling the <strong>success</strong> and <strong>failure</strong> cases here, but you might want to cover more cases, like cancelled tasks etc.</p><h3><strong>Conclusion</strong></h3><p>The migration to the new Places SDK seemed to be a lot harder initially, but with a clear planning and finding what can be abstracted away, you can save a lot of time.</p><p>The article’s purpose is to help you make that migration easier and effortless. I did not want to dive into specific changes of the new SDK. You can find those detailed here: <a href="https://developers.google.com/places/android-sdk/client-migration">https://developers.google.com/places/android-sdk/client-migration</a></p><p>Hope you enjoyed it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9adcedef20c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a helpful Android CI with Danger & Jenkins]]></title>
            <link>https://medium.com/@p.tournaris/building-a-helpful-android-ci-with-danger-jenkins-bf751be7a74c?source=rss-d2295c5f4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf751be7a74c</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[danger]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Pavlos-Petros Tournaris]]></dc:creator>
            <pubDate>Wed, 29 Aug 2018 08:17:55 GMT</pubDate>
            <atom:updated>2018-08-30T19:12:02.299Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTQmdK0x8AMD5CjTDjU5dw.png" /><figcaption>An example of our testing pipeline</figcaption></figure><p>In our days, almost every project, is backed by a <strong>Continuous Integration</strong> system (aka <strong>CI</strong>). Either that is an Open Source project or a private repository in the organization of your company.</p><blockquote>Why do I need a CI?</blockquote><p>Well, CI is what will have your back, at any given time. We are engineers and we might make mistakes from time to time, but 99% of those times our mistakes could have been easily detected by the proper tools, running in our CI, for each PR or commit.</p><p>To give you a real life example, we were using .forEach on Map which is only available on API 24+ but because we were targeting Java 1.8 we did not get any warnings, even though this was causing a fatal exception due to NoClassDefFoundError on APIs below 24. Other than searching for such usages and fixing them we also decided to write a Lint rule that will protect us in the future, in case someone forgets about this limitation (will probably explain in another article, how to write such a rule).</p><blockquote>What tools are you talking about?</blockquote><p>I will mention some of the tools currently being used in modern Android stacks.</p><p>1. Detekt</p><p>2. KtLint</p><p>3. FindBugs</p><p>4. ErrorProne</p><p>5. Android Lint</p><p>While some of those can be used only for code style and formatting (e.g. KtLint) others can really detect bugs using static analysis (e.g. ErrorProne, FindBugs or even Android Lint with custom rules).</p><p>A way to use the tools above is by adding a pre-commit hook that will prevent you from committing un-styled or non-formatted code. Such a setup, you can find in <a href="https://github.com/squanchy-dev/squanchy-android/blob/develop/team-props/git-hooks.gradle">Squanchy</a> repository. But most of them, will take some time to execute and having to run them, before being able to commit, is not viable. That is where a CI comes to offload that task from you.</p><h3>Our beloved CI</h3><p>There are many solutions in the market that need minimal setup or are quite easy to integrate, such as CircleCI, TravisCI or Google Cloud Build. In Workable’s Mobile Team, we have developed our own in-house CI, based on already existing infrastructure, powered by Jenkins. Of course, one might say, why would you need to “invent the wheel” all over again? Well, most of those services, have paid plans for private repos and are quite costly for our needs. Having 2–3 Jenkins slaves in-house, felt a lot more cost effective!</p><p>In addition, it’s always better to build something on your own, rather than using an already established service :P It makes you feel a bit geeky!</p><h3>Danger Systems</h3><blockquote>Danger runs during your CI process, and gives teams the chance to automate common code review chores.</blockquote><p>Such chores, are potential nullability bugs, formatting issues or even prohibited usages of methods, like the one we mentioned before.</p><p>We used Jenkins’ <strong>Github Pull Request Builder</strong> plugin to invoke a Jenkins job for PR commits. After that, all you need to do, is add a file on your repo namedDangerfile. In this file, you let Danger know, what plugins to invoke and/or whatever you want it to post on your PR.</p><p>For example, you can let reviewers know, that the current PR is a work in progress:</p><pre>if (github.pr_body + github.pr_title).include?(&quot;WIP&quot;)<br>   warn(&quot;Pull Request is Work in Progress&quot;)<br>end</pre><p>What we found useful, was the following JUnit Danger plugin, which outputs unit test results, on your PR:</p><pre>junit_tests_dir = &quot;path/to/your/results/**/*.xml&quot;<br>Dir[junit_tests_dir].each do |file_name|<br>  junit.parse file_name<br>  junit.show_skipped_tests = true<br>  junit.report<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*u0bPwTJ034_OgPVHUY9gDA.png" /></figure><p>Lastly, we also used Danger’s Android Lint plugin to output any Lint issues as well, on the PR:</p><pre>android_lint.report_file = &quot;path/to/your/lint-results.xml&quot;<br>android_lint.filtering = true<br>android_lint.skip_gradle_task = true<br>android_lint.lint(inline_mode: true)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*lW_TvaY-JBdbnI6WZ5wWSg.png" /><figcaption>An example of a custom Lint rule result reported inline in the offending file.</figcaption></figure><p>As you might have noticed, JUnit &amp; Lint plugins, expect to find the result files and just parse them.</p><p>In order to succeed on this task and prevent it from failing the execution, with, we had to use the following Gradle command:</p><pre>./gradlew <br>--continue yourTestTask \<br>--tests=your.test.suite \ <br>yourLintTask \<br>-PabortOnLintError=false</pre><ul><li>We use<strong> — continue </strong>in order for <strong>testDebug </strong>task to keep executing when a test has failed.</li><li>Use <strong>abortOnLintError </strong>parameter in order to let Lint also finish its execution when an error is produced.</li></ul><p>We also need to add that extra snippet in our root <strong>build.gradle</strong> file, to allow <strong>yourTestTask </strong>ignore any failures and let Danger report them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c362eaf7589c88c7f993bddc7e177c26/href">https://medium.com/media/c362eaf7589c88c7f993bddc7e177c26/href</a></iframe><h3>But…</h3><p>Danger is a PR only tool and unfortunately you can not bypass its hardcoded checks that detect whether you are using a CI system. We could supposedly take advantage of its reporting tools on Github’s Commit Status API and turn off any commenting functionality.</p><h3>What about non PR commits?</h3><p>As I mentioned before, we already had a custom CI in place, that was running our tests on every commit, and report back to Slack, should the build or tests have broken.</p><p>It was time to enrich it with more features like static analysis and also integrate it with Github’s Commit Status API.</p><p>We are also using <a href="https://fastlane.tools/">fastlane</a> to automate some tasks like test running, APK building and uploading either to Fabric Beta or PlayStore. All of the above tasks, are executed in what fastlane calls “lanes”. Each lane is assigned a specific task and you essentially “drive” that lane when you want to execute it.</p><p>All we had to do, was create a lane that will run Android Lint and <a href="https://github.com/arturbosch/detekt">Detekt</a> and use that one along with the test running lane. Apart from that, it would be great to have Jenkins also post on Github’s Commit Status API, for the ongoing state of the lane run.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/348366fb3d4a97df2143a736f4aa11f9/href">https://medium.com/media/348366fb3d4a97df2143a736f4aa11f9/href</a></iframe><p>The above snippet executes an HTTP request using Jenkins’ <strong>httpRequest</strong> plugin, in order to update a given commit’s state.</p><p>The requestBody in the example above is something similar to the following:</p><pre>{<br>  &quot;state&quot;: commit-status,// values: failure, success, pending, error<br>  &quot;target_url&quot;: your-current-build-url,<br>  &quot;description&quot;: &quot;A description&quot;,<br>  &quot;context&quot;: context // A differentiation label<br>}</pre><p>All that is left now, is to call postCommitStatus method, when our build initiates, to mark the commit as <strong>pending </strong>and when the lane finishes, update the commit state to <strong>successful</strong> or <strong>failed</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*OaIMfNS6aUiLDtLoy26EIg.png" /><figcaption>Showcasing all possible states of a commit</figcaption></figure><h3>Conclusion</h3><p>After having written a bit of CircleCI and TravisCI configurations, I have to say that configuring Jenkins was 100x more difficult. When your company though, has an in-house Jenkins infrastructure, you can avoid spending money on third-party services.</p><p>As always, you should choose what is best for you and your needs. In case you happen to be using Jenkins, like we do, I hope this article helped you make CI a friend of yours.</p><p>After all, this is what will help you keep your crash-free rate above 99.5% 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf751be7a74c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>