<?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 Andrius Baruckis on Medium]]></title>
        <description><![CDATA[Stories by Andrius Baruckis on Medium]]></description>
        <link>https://medium.com/@baruckis?source=rss-b2c384f5891d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WZdZmMGsk9QI361ePxRA7g.jpeg</url>
            <title>Stories by Andrius Baruckis on Medium</title>
            <link>https://medium.com/@baruckis?source=rss-b2c384f5891d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 15:01:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@baruckis/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[Kotlin Clean Architecture with MVVM prototype app for Android]]></title>
            <link>https://medium.com/@baruckis/kotlin-clean-architecture-with-mvvm-prototype-app-for-android-d51b7b40a3c?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d51b7b40a3c</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Sun, 22 Dec 2019 17:40:00 GMT</pubDate>
            <atom:updated>2020-01-15T13:52:54.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J6RhffWUFGNQ520750RGxQ.jpeg" /></figure><p>We as developers are always in the search for better ways to build our apps. The need to build flexible to adapt high quality software usually comes from constantly changing business requirements. To do that our goal should be to write decoupled, maintainable and testable code as much as we can. That depends a lot on how we organise our code base, what architecture we use.</p><h3>Prototype app</h3><p>To accomplish discussed goal we can combine Model-View-ViewModel (MVVM) software architectural pattern together with the concept of Clean Architecture. Applying clean architecture concept is much better way to develop apps. With it changes can be done quickly, code can be understood better as its readability improves and development costs are reduced. Testability improves drastically. It becomes easy to find bugs.</p><p>To study this concept I have build a simple single screen demonstration native Android app based on Clean Architecture with MVVM written using Kotlin programming language.</p><h4><a href="https://github.com/baruckis/VenuesNearby"><strong>It’s on GitHub</strong></a></h4><p><strong>VenuesNearby</strong> — is a demonstration app that allows a user to enter a place name, submit, and then view the recommended venues nearby. The venues are provided by the <a href="https://developer.foursquare.com/docs/api/venues/explore">Foursquare API</a> which you can integrate with. You will need to sign up as a <a href="https://developer.foursquare.com/">Foursquare developer</a> and create an app in order to use their services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*IUClguHar8CwanTPptjydQ.gif" /><figcaption>Prototype app “VenuesNearby”</figcaption></figure><h3>What is MVVM architecture?</h3><p>MVVM is a software architectural pattern. It stands for Model-View-ViewModel.</p><ul><li><strong>Model</strong>: This represents the data and business logic of the app. It cannot directly talk to the View. Generally, it’s recommended to expose data through observables to be decoupled completely from ViewModel.</li><li><strong>View</strong>: It represents the UI of the application. The view role in this pattern is to observe (subscribe to) a ViewModel observable to get data in order to update UI elements accordingly.</li><li><strong>ViewModel</strong>: It acts as a link between the Model and the View. It’s responsible for transforming the data from the Model. It provides data streams to the View. It also uses hooks or callbacks to update the View. It will ask for the data from the Model. ViewModel should not be aware about the view who is interacting with.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/0*NF-7FgJYviUeUW_n.png" /></figure><p>MVVM pattern is recommended one by Google as it is supported by Android Jetpack Architecture Components.</p><h3>What is Clean Architecture?</h3><p>Clean Architecture exists at a higher abstraction level than the MVVM presentation architecture pattern. Usually MVVM is enough to use for small projects, but when our project codebase expands and becomes huge we need something better for separating all the responsibilities. Clean Architecture is enforcing <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> and SOLID principles. Actually these principles is core concept for Clean Architecture. Check out my <a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-part-1-36fe781a75c1">previous article about SOLID</a>.</p><p>Clean Architecture describes the overall application architecture: how the various layers of an app (business objects, use cases, presenters, data storage, and UI) communicate with one another. With it, code is separated into layers. The layers should not know anything about the outer layers. They can depend only on other inner layers for them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*6ScBspf3EDerx9B9.png" /></figure><p>Following Clean Architecture idea all project code should be separated into different layers such as domain, storage, presentation. However the architecture doesn’t strictly define exact layers and you should adapt the number of layers to your needs.</p><p>My demo project VenuesNearby was separated to these six layers — packages:</p><p><strong>Domain</strong> — a layer to store the business logic of your app. Here we have our Use Case classes — the operations which your app can perform. This layer also contain Unit tests for these classes.</p><p><strong>Data</strong> — a layer which is used to control the flow of data between the remote (external data) and cache (local data) layers through to the Domain layers operational requests. This layer contains Unit tests to ensure that this control of data is operating as intended.</p><p><strong>Remote</strong> — a layer which contains all of the remote operations with the third party API that is used for the project. Unit tests here to ensure that these operations are working as intended.</p><p><strong>Cache</strong> — a layer which stores our applications data in a local database using the Room architecture component. This allows our app to appear working at all time even while being offline.</p><p><strong>Presentation</strong> — a layer to house the presentation logic of our application. MVVM pattern is used in this layer and built with lifecycle-aware architecture components such as ViewModel, LiveData. Also view model class is covered by own tests.</p><p><strong>UI</strong> — a layer contains the user interface for our mobile application. Here an activity is used to display the data. Espresso tests ensures the operation as intended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*5MsRDfg-5dLS3AFzd7Csaw.png" /></figure><p>Clean Architecture is the most modulated app development architecture which is perfect for continuously developed app and team work. Besides it allows to build on top on other efficient architectures such as MVVM.</p><p>Advantages:</p><ul><li>Clear separation of concerns.</li><li>Decoupled responsibilities good for team work.</li><li>Easier to maintain.</li><li>Code more testable.</li><li>Works well for large complex projects so it can scale.</li></ul><h3>Final words</h3><p>In this article I have just quickly covered the concepts of Clean Architecture with MVVM. Please understand that we don’t necessary need to have any architecture at all for our apps development. The app can be completely made without it and the end user wont notice any visual difference. But I hope that when your boss, your client or your colleague will ask whats the point of it, you won’t doubt, be confident and explain all the benefits it brings. The biggest difference here is always going to be the long-term effect architecture it gives. At last in Android development word we have not only the professional tools provided but also matured blueprint for building highest quality apps. There have been no better time to try building such one by your own.</p><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/clean-architecture-mvvm-prototype/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on December 22, 2019.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d51b7b40a3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to handle RESTful web Services using Retrofit, OkHttp, Gson, Glide and Coroutines]]></title>
            <link>https://medium.com/free-code-camp/my-crypto-coins-app-series-part-5-160e7aaa6382?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/160e7aaa6382</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[web-services]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Sat, 11 May 2019 08:26:24 GMT</pubDate>
            <atom:updated>2019-05-22T16:00:54.646Z</atom:updated>
            <content:encoded><![CDATA[<h4>Kriptofolio app series — Part 5</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9gJTRqiq_YPvga0sPu_qw.png" /></figure><p>These days almost every Android app connects to internet to get/send data. You should definitely learn how to handle RESTful Web Services, as their correct implementation is the core knowledge while creating modern apps.</p><p>This part is going to be complicated. We are going to combine multiple libraries at once to get a working result. I am not going to talk about the native Android way to handle internet requests, because in the real world nobody uses it. Every good app does not try to reinvent the wheel but instead uses the most popular third party libraries to solve common problems. It would be too complicated to recreate the functionality that these well-made libraries have to offer.</p><h3>Series content</h3><ul><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-61be4f8af906">Introduction: A roadmap to build a modern Android app in 2018–2019</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-1-36fe781a75c1">Part 1: An introduction to the SOLID principles</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-2-580ccb4d8cf6">Part 2: How to start building your Android app: creating Mockups, UI, XML layouts</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-3-df57f86daf74">Part 3: All about that Architecture: exploring different architecture patterns and how to use them in your app</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-4-60fbc2bac2bf">Part 4: How to implement Dependency Injection in your app with Dagger 2</a></li><li>Part 5: Handle RESTful Web Services using Retrofit, OkHttp, Gson, Glide and Coroutines (you’re here)</li></ul><h3>What is Retrofit, OkHttp and Gson?</h3><p>Retrofit is a REST Client for Java and Android. This library, in my opinion, is the most important one to learn, as it will do the main job. It makes it relatively easy to retrieve and upload JSON (or other structured data) via a REST based webservice.</p><p>In Retrofit you configure which converter is used for the data serialization. Typically to serialize and deserialize objects to and from JSON you use an open-source Java library — Gson. Also if you need, you can add custom converters to Retrofit to process XML or other protocols.</p><p>For making HTTP requests Retrofit uses the OkHttp library. OkHttp is a pure HTTP/SPDY client responsible for any low-level network operations, caching, requests and responses manipulation. In contrast, Retrofit is a high-level REST abstraction build on top of OkHttp. Retrofit is strongly coupled with OkHttp and makes intensive use of it.</p><p>Now that you know that everything is closely related, we are going to use all these 3 libraries at once. Our first goal is to get all the cryptocurrencies list using Retrofit from the Internet. We will use a special OkHttp interceptor class for CoinMarketCap API authentication when making a call to the server. We will get back a JSON data result and then convert it using the Gson library.</p><h3>Quick setup for Retrofit 2 just to try it first</h3><p>When learning something new, I like to try it out in practice as soon as I can. We will apply a similar approach with Retrofit 2 for you to understand it better more quickly. Don’t worry right now about code quality or any programming principles or optimizations — we’ll just write some code to make Retrofit 2 work in our project and discuss what it does.</p><p>Follow these steps to set up Retrofit 2 on My Crypto Coins app project:</p><h4><strong>First, give INTERNET permission for the app</strong></h4><p>We are going to execute HTTP requests on a server accessible via the Internet. Give this permission by adding these lines to your Manifest file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/209157a6fe8dfa919cbfa89c66cc5ae9/href">https://medium.com/media/209157a6fe8dfa919cbfa89c66cc5ae9/href</a></iframe><h4><strong>Then you should add library dependencies</strong></h4><p>Find the latest <a href="https://square.github.io/retrofit/">Retrofit version</a>. Also you should know that Retrofit doesn’t ship with an integrated JSON converter. Since we will get responses in JSON format, we need to include the converter manually in the dependencies too. We are going to use latest Google’s JSON converter <a href="https://github.com/google/gson">Gson version</a>. Let’s add these lines to your gradle file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d282408c9f5823de7ad115bbdf6a175a/href">https://medium.com/media/d282408c9f5823de7ad115bbdf6a175a/href</a></iframe><p>As you noticed from my comment, the OkHttp dependency is already shipped with the Retrofit 2 dependency. Versions is just a separate gradle file for convenience:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54e069854dc0334d9bb9a37fef9e24de/href">https://medium.com/media/54e069854dc0334d9bb9a37fef9e24de/href</a></iframe><h4><strong>Next set up the Retrofit interface</strong></h4><p>It’s an interface that declares our requests and their types. Here we define the API on the client side.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/044404644f1f825d46dbdc22e7faf6b6/href">https://medium.com/media/044404644f1f825d46dbdc22e7faf6b6/href</a></iframe><h4><strong>And set up the data class</strong></h4><p>Data classes are POJOs (Plain Old Java Objects) that represent the responses of the API calls we’re going to make.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52678e93106765df1ec8c6930c732d9c/href">https://medium.com/media/52678e93106765df1ec8c6930c732d9c/href</a></iframe><h4><strong>Create a special interceptor class for authentication when making a call to the server</strong></h4><p>This is the case particular for any API that requires authentication to get a successful response. Interceptors are a powerful way to customize your requests. We are going to intercept the actual request and to add individual request headers, which will validate the call with an API Key provided by <a href="https://pro.coinmarketcap.com/">CoinMarketCap Professional API Developer Portal</a>. To get yours, you need to register there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8cfa11583f699759727063b40282f23/href">https://medium.com/media/d8cfa11583f699759727063b40282f23/href</a></iframe><h4><strong>Finally, add this code to our activity to see Retrofit working</strong></h4><p>I wanted to get your hands dirty as soon as possible, so I put everything in one place. This is not the correct way, but it’s the fastest instead just to see a visual result quickly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4af7098bf520de25692a5f3779e8e2a3/href">https://medium.com/media/4af7098bf520de25692a5f3779e8e2a3/href</a></iframe><p>You can explore the code <a href="https://github.com/baruckis/Kriptofolio/tree/4d7946705b8c4dc2db3775bcc000d2918f8f1b73">here</a>. Remember this is only an initial simplified implementation version for you to get the idea better.</p><h3>Final correct setup for Retrofit 2 with OkHttp 3 and Gson</h3><p>Ok after a quick experiment, it is time to bring this Retrofit implementation to the next level. We already got the data successfully but not correctly. We are missing the states like loading, error and success. Our code is mixed without separation of concerns. It’s a common mistake to write all your code in an activity or a fragment. Our activity class is UI based and should only contain logic that handles UI and operating system interactions.</p><p>Actually, after this quick setup, I worked a lot and made many changes. There is no point to put all the code that was changed in the article. Better instead you should browse the final Part 5 code repo <a href="https://github.com/baruckis/Kriptofolio/tree/Part-5">here</a>. I have commented everything very well and my code should be clear for you to understand. But I am going to talk about most important things I have done and why I did them.</p><p>The first step to improve was to start using Dependency Injection. Remember from the <a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-4-60fbc2bac2bf">previous part</a> we already have Dagger 2 implemented inside the project correctly. So I used it for the Retrofit setup.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c731f8debb67a19c749c108751bdd33/href">https://medium.com/media/8c731f8debb67a19c749c108751bdd33/href</a></iframe><p>Now as you see, Retrofit is separated from the activity class as it should be. It will be initialized only once and used app-wide.</p><p>As you may have noticed while creating the Retrofit builder instance, we added a special Retrofit calls adapter using addCallAdapterFactory. By default, Retrofit returns a Call&lt;T&gt;, but for our project we require it to return a LiveData&lt;T&gt; type. In order to do that we need to add LiveDataCallAdapter by using LiveDataCallAdapterFactory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/551a6e52f80e9c90776f078daee1b81d/href">https://medium.com/media/551a6e52f80e9c90776f078daee1b81d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68565527b5022b440018525017da5817/href">https://medium.com/media/68565527b5022b440018525017da5817/href</a></iframe><p>Now we will get LiveData&lt;T&gt; instead of Call&lt;T&gt; as the return type from Retrofit service methods defined in the ApiService interface.</p><p>Another important step to make is to start using the Repository pattern. I have talked about it in <a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-3-df57f86daf74">Part 3</a>. Check out our MVVM architecture schema from that post to remember where it goes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*UENC6yZB9aFaHLcR.png" /></figure><p>As you see in the picture, Repository is a separate layer for the data. It’s our single source of contact for getting or sending data. When we use Repository, we are following the separation of concerns principle. We can have different data sources (like in our case persistent data from an SQLite database and data from web services), but Repository is always going to be single source of truth for all app data.</p><p>Instead of communicating with our Retrofit implementation directly, we are going to use Repository for that. For each kind of entity, we are going to have a separate Repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/810d48ebbcca68ffc44a623d9544b0f2/href">https://medium.com/media/810d48ebbcca68ffc44a623d9544b0f2/href</a></iframe><p>As you notice in the CryptocurrencyRepository class code, I am using the NetworkBoundResource abstract class. What is it and why do we need it?</p><p>NetworkBoundResource is a small but very important helper class that will allow us to maintain a synchronization between the local database and the web service. Our goal is to build a modern application that will work smoothly even when our device is offline. Also with the help of this class we will be able to present different network states like errors or loading for the user visually.</p><p>NetworkBoundResource starts by observing the database for the resource. When the entry is loaded from the database for the first time, it checks whether the result is good enough to be dispatched or if it should be re-fetched from the network. Note that both of these situations can happen at the same time, given that you probably want to show cached data while updating it from the network.</p><p>If the network call completes successfully, it saves the response into the database and re-initializes the stream. If the network request fails, the NetworkBoundResource dispatches a failure directly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adafe8d6e06bd947cff03481d6a2f371/href">https://medium.com/media/adafe8d6e06bd947cff03481d6a2f371/href</a></iframe><p>Under the hood, the NetworkBoundResource class is made by using MediatorLiveData and its ability to observe multiple LiveData sources at once. Here we have two LiveData sources: the database and the network call response. Both of those LiveData are wrapped into one MediatorLiveData which is exposed by NetworkBoundResource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*_H-8ATlEHKtVFZtVgnMeow.png" /><figcaption>NetworkBoundResource</figcaption></figure><p>Let’s take a closer look how the NetworkBoundResource will work in our app. Imagine the user will launch the app and click on a floating action button on the bottom right corner. The app will launch the add crypto coins screen. Now we can analyze NetworkBoundResource&#39;s usage inside it.</p><p>If the app is freshly installed and it is its first launch, then there will not be any data stored inside the local database. Because there is no data to show, a loading progress bar UI will be shown. Meanwhile the app is going to make a request call to the server via a web service to get all the cryptocurrencies list.</p><p>If the response is unsuccessful then the error message UI will be shown with the ability to retry a call by pressing a button. When a request call is successful at last, then the response data will be saved to a local SQLite database.</p><p>If we come back to the same screen the next time, the app will load data from the database instead of making a call to the internet again. But the user can ask for a new data update by implementing pull-to-refresh functionality. Old data information will be shown whilst the network call is happening. All this is done with the help of NetworkBoundResource.</p><p>Another class used in our Repository and LiveDataCallAdapter where all the &quot;magic&quot; happens is ApiResponse. Actually ApiResponse is just a simple common wrapper around the Retrofit2.Response class that converts each response to an instance of LiveData.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3b17da54819030b5c855a6a28436c04/href">https://medium.com/media/a3b17da54819030b5c855a6a28436c04/href</a></iframe><p>Inside this wrapper class, if our response has an error, we use the Gson library to convert the error to a JSON object. However, if the response was successful, then the Gson converter for JSON to POJO object mapping is used. We already added it when creating the retrofit builder instance with GsonConverterFactory inside the Dagger AppModule function provideApiService.</p><h3>Glide for image loading</h3><p><a href="https://github.com/huyn/glide">What is Glide</a>? From the docs:</p><blockquote>Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.</blockquote><blockquote>Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but it is also effective for almost any case where you need to fetch, resize, and display a remote image.</blockquote><p>Sounds like a complicated library which offers many useful features that you would not want to develop all by yourself. In My Crypto Coins app, we have several list screens where we need to show multiple cryptocurrency logos — pictures taken from the internet all at once — and still ensure a smooth scrolling experience for the user. So this library fits our needs perfectly. Also this library is very popular among Android developers.</p><p>Steps to setup Glide on My Crypto Coins app project:</p><h4><strong>Declare dependencies</strong></h4><p>Get the latest <a href="https://bumptech.github.io/glide">Glide version</a>. Again versions is a separate file versions.gradle for the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3391d467dc1dfcaa1560256fa4b9edd4/href">https://medium.com/media/3391d467dc1dfcaa1560256fa4b9edd4/href</a></iframe><p>Because we want to use the networking library OkHttp in our project for all network operations, we need to include the specific Glide integration for it instead of the default one. Also since Glide is going to perform a network request to load images via the internet, we need to include the permission INTERNET in our AndroidManifest.xml file — but we already did that with the Retrofit setup.</p><h4><strong>Create AppGlideModule</strong></h4><p>Glide v4, which we will be using, offers a generated API for Applications. It will use an annotation processor to generate an API that allows applications to extend Glide’s API and include components provided by integration libraries. For any app to access the generated Glide API we need to include an appropriately annotated AppGlideModule implementation. There can be only a single implementation of the generated API and only one AppGlideModule per application.</p><p>Let’s create a class extending AppGlideModule somewhere in your app project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11d72731a4dbf7a3fca56cdc88fba8ac/href">https://medium.com/media/11d72731a4dbf7a3fca56cdc88fba8ac/href</a></iframe><p>Even if our application is not changing any additional settings or implementing any methods in AppGlideModule, we still need to have its implementation to use Glide. You&#39;re not required to implement any of the methods in AppGlideModule for the API to be generated. You can leave the class blank as long as it extends AppGlideModule and is annotated with @GlideModule.</p><h4><strong>Use Glide-generated API</strong></h4><p>When using AppGlideModule, applications can use the API by starting all loads with GlideApp.with(). This is the code that shows how I have used Glide to load and show cryptocurrency logos in the add crypto coins screen all cryptocurrencies list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2935cce82cd3ef98203aaa6e3c79082f/href">https://medium.com/media/2935cce82cd3ef98203aaa6e3c79082f/href</a></iframe><p>As you see, you can start using Glide with just few lines of code and let it do all the hard work for you. It is pretty straightforward.</p><h3>Kotlin Coroutines</h3><p>While building this app, we are going to face situations when we will run time consuming tasks such as writing data to a database or reading from it, fetching data from the network and other. All these common tasks take longer to complete than allowed by the Android framework’s main thread.</p><p>The main thread is a single thread that handles all updates to the UI. Developers are required not to block it to avoid the app freezing or even crashing with an Application Not Responding dialog. Kotlin coroutines is going to solve this problem for us by introducing main thread safety. It is the last missing piece that we want to add for My Crypto Coins app.</p><p>Coroutines are a Kotlin feature that convert async callbacks for long-running tasks, such as database or network access, into sequential code. With coroutines, you can write asynchronous code, which was traditionally written using the Callback pattern, using a synchronous style. The return value of a function will provide the result of the asynchronous call. Code written sequentially is typically easier to read, and can even use language features such as exceptions.</p><p>So we are going to use coroutines everywhere in this app where we need to wait until a result is available from a long-running task and than continue execution. Let’s see one exact implementation for our ViewModel where we will retry getting the latest data from the server for our cryptocurrencies presented on the main screen.</p><p>First add coroutines to the project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e744603123a344dacf2552a26e1e58db/href">https://medium.com/media/e744603123a344dacf2552a26e1e58db/href</a></iframe><p>Then we will create abstract class which will become the base class to be used for any ViewModel that needs to have common functionality like coroutines in our case:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f20a0a22acf2b4c25c6806548802178/href">https://medium.com/media/0f20a0a22acf2b4c25c6806548802178/href</a></iframe><p>Here we create specific coroutine scope, which will control the lifetime of coroutines through its job. As you see, scope allows you to specify a default dispatcher that controls which thread runs a coroutine. When the ViewModel is no longer used, we cancel viewModelJob and with that every coroutine started by uiScope will be cancelled as well.</p><p>Finally, implement the retry functionality:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85f861f4ab617e8998ca57b7f8f14054/href">https://medium.com/media/85f861f4ab617e8998ca57b7f8f14054/href</a></iframe><p>Here we call a function marked with a special Kotlin keyword suspend for coroutines. This means that the function suspends execution until the result is ready, then it resumes where it left off with the result. While it is suspended waiting for a result, it unblocks the thread that it is running on.</p><p>Also, in one suspend function we can call another suspend function. As you see we do that by calling new suspend function marked withContext that is executed on different thread.</p><p>The idea of all this code is that we can combine multiple calls to form nice-looking sequential code. First we request to get the ids of the cryptocurrencies we own from the local database and wait for the response. Only after we get it do we use the response ids to make a new call with Retrofit to get those updated cryptocurrency values. That is our retry functionality.</p><h3>We made it! Final thoughts, repository, app &amp; presentation</h3><p>Congratulations, I am happy if you managed to reach to the end. All the most significant points for creating this app have been covered. There was plenty of new stuff done in this part and a lot of that is not covered by this article, but I commented my code everywhere very well so you should not get lost in it. Check out final code for this part 5 here on GitHub:</p><p><a href="https://github.com/baruckis/Kriptofolio/tree/Part-5">View Source On GitHub</a>.</p><p>The biggest challenge for me personally was not to learn new technologies, not to develop the app, but to write all these articles. Actually I am very happy with myself that I completed this challenge. Learning and developing is easy compared to teaching others, but that is where you can understand the topic even better. My advice if you are looking for the best way to learn new things is to start creating something yourself immediately. I promise you will learn a lot and quickly.</p><p>All these articles are based on version 1.0.0 of “Kriptofolio” (previously “My Crypto Coins”) app which you can download as a separate APK file <a href="https://github.com/baruckis/Kriptofolio/releases">here</a>. But I will be very happy if you install and rate the latest app version from the store directly:</p><h4><a href="https://play.google.com/store/apps/details?id=com.baruckis.kriptofolio">Get It On Google Play</a></h4><p>Also please feel free to visit this simple presentation website that I made for this project:</p><h4><a href="https://kriptofolio.app/">Kriptofolio.app</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BynmLAFgS8nVRi8dOOBRQw.png" /></figure><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-5/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on May 11, 2019.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=160e7aaa6382" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-part-5-160e7aaa6382">How to handle RESTful web Services using Retrofit, OkHttp, Gson, Glide and Coroutines</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement Dependency Injection in your app with Dagger 2]]></title>
            <link>https://medium.com/free-code-camp/my-crypto-coins-app-series-part-4-60fbc2bac2bf?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/60fbc2bac2bf</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Sun, 07 Oct 2018 09:35:06 GMT</pubDate>
            <atom:updated>2019-08-14T06:45:43.621Z</atom:updated>
            <content:encoded><![CDATA[<h4>Kriptofolio app series - Part 4</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CVSY-XyHRtZZJd2lDV-ZZw.png" /></figure><p>Dependency injection will significantly improve your code. It makes your code more modular, flexible and testable. Actually its name sounds more complicated than the idea which stands behind it.</p><p>In this part of the series we are going to learn about dependency injection. We will then implement it in “Kriptofolio” (previously “My Crypto Coins”) app. We are going to use Dagger 2. Dagger 2 is the most popular open-source dependency injection framework for Android. This is a valuable skill to have for creating modern apps, even thought the learning curve is hard enough.</p><h3>Series content</h3><ul><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-61be4f8af906">Introduction: A roadmap to build a modern Android app in 2018–2019</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-1-36fe781a75c1">Part 1: An introduction to the SOLID principles</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-2-580ccb4d8cf6">Part 2: How to start building your Android app: creating Mockups, UI, XML layouts</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-3-df57f86daf74">Part 3: All about that Architecture: exploring different architecture patterns and how to use them in your app</a></li><li>Part 4: How to implement Dependency Injection in your app with Dagger 2 (you’re here)</li><li><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-5">Part 5: Handle RESTful Web Services using Retrofit, OkHttp, Gson, Glide and Coroutines</a></li></ul><h3>What is Dependency Injection?</h3><p>To explain dependency injection first we have to understand what dependency means in programming. A dependency is when one of the objects depends on the concrete implementation of another object. You can identify a dependency in your code whenever you instantiate an object within another. Let’s take a look at a practical example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8d14b3965161bfd6bdc36feb3986179/href">https://medium.com/media/d8d14b3965161bfd6bdc36feb3986179/href</a></iframe><p>As you see from this example your class MyAppClass will depend directly on concrete configuration and implementation of your library class MyLibrary. What if you would like one day to use a third-party library instead? What if you would like to have another class where you would like to use exactly the same library configuration? Every time you will have to search through your code, find exact place and change it. It’s just a few examples.</p><p>The idea is that this tight coupling between the components of the application will make your development work harder as your project grows. To avoid any problems, let’s use dependency injection for loosening the coupling described.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9a5ec9870a0211fdb59cca5146058e5/href">https://medium.com/media/f9a5ec9870a0211fdb59cca5146058e5/href</a></iframe><p>That’s it, that’s a very primitive dependency injection example. Instead of creating and configuring a new MyLibrary class object inside your class MyAppClass, you just pass or inject it into the constructor. So MyAppClass can be totally irresponsible for MyLibrary.</p><h3>What is Dagger 2?</h3><p>Dagger is a fully static, compile-time, open-source dependency injection framework for both Java and Android. In this article I will be talking about its second version which Google maintains. Square created its earlier version.</p><p>Dagger 2 is considered to be one of the most efficient dependency injection frameworks built to date. Actually if you compare Dagger 1, Dagger 2 and Dagger 2.10 you would discover each implementation is different. You need to relearn it each time as there were significant changes done by the authors. When writing this article I am using Dagger 2.16 version and we are going to focus only on it.</p><p>As you now understand about dependency injection, our classes should not create or have dependencies. Instead they need to get everything from outside. So when using Dagger 2, this framework will provide all the dependencies needed.</p><p>It does this by generating a lot of boilerplate code for us. That generated code will be fully traceable and will mimic the code which a user may write by hand. Dagger 2 is written in Java and the code generated by its annotation processor will be Java code too.</p><p>However it works with Kotlin without any problems or modifications. Remember that Kotlin is fully interoperable with Java. If compared to similar frameworks, Dagger 2 is a less dynamic one. It works at compile time rather than at run-time with reflection. There is no reflection usage at all. All that means is that this framework will be harder to set up and to learn. It will provide performance boost with compile-time safety.</p><h3>Manual Dependency Injection without tools</h3><p>You may have noticed in the My Crypto Coins app <a href="https://github.com/baruckis/Kriptofolio/tree/Part-3">source code from the previous part</a> that there is a piece of code for injecting objects without using any dependency injection tools. It works fine, and this solution would be good enough for such a small app like this. Take a look at the utilities package:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fa05430bfdc548f966f7dde6ce0ba8d/href">https://medium.com/media/9fa05430bfdc548f966f7dde6ce0ba8d/href</a></iframe><p>As you see this class will do all the work. It will create ViewModel factories for activities or fragments that require them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17f9313d6e6b60418ee2bb3695afdcf0/href">https://medium.com/media/17f9313d6e6b60418ee2bb3695afdcf0/href</a></iframe><p>Then you use InjectorUtils class like this where you need to get a specific ViewModel factory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d3e3908249a8ba43a8b0f3ad17887e7/href">https://medium.com/media/5d3e3908249a8ba43a8b0f3ad17887e7/href</a></iframe><p>As you see our MainListFragment class don’t even know about CryptocurrencyRepository or AppDatabase. It gets a successfully constructed factory from InjectorUtils class. Actually this is one simple way to do it. We are going to get rid of it and learn how to setup Dagger 2 tool for advanced dependency injection. If this app would expand in functionality and code, I don’t doubt we would start seeing benefits really fast of using a professional dependency injection framework over a manual solution.</p><p>So let’s delete InjectorUtils class right now and learn how to setup Dagger 2 in My Crypto Coins app source code.</p><h3>Dependency Injection for MVVM with Kotlin</h3><h4>How to setup Dagger 2 with ViewModels, Activities and Fragments</h4><p>Now we’ll go through the Dagger 2 step by step setup on the My Crypto Coins app project.</p><p><strong>To begin, you should enable Kotlin’s own </strong><a href="https://kotlinlang.org/docs/reference/kapt.html"><strong>Annotation Processing Tool</strong></a><strong> (kapt). Then add special Dagger 2 dependencies.</strong></p><p>You can do this by adding these lines to your gradle file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25e3207474851dad2882bed22706d8ce/href">https://medium.com/media/25e3207474851dad2882bed22706d8ce/href</a></iframe><p>Kapt plugin will enable the compiler to generate stub classes required for interoperability between Java and Kotlin. For convenience we will define the concrete Dagger 2 version in a separate gradle file, as we do that with all our dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f557c880487f8e3dd4ee4e9b6eb8cad1/href">https://medium.com/media/f557c880487f8e3dd4ee4e9b6eb8cad1/href</a></iframe><p>To find the latest version available check the releases at <a href="https://github.com/google/dagger">Dagger 2&#39;s official repository on Github</a>.</p><p><strong>Now, create your application </strong><strong>App class.</strong></p><p>Skip this if you already have this class set. After you’ve done that, we will leave it as it is for a while, but come back later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06278ae109957e38d0145459c2690696/href">https://medium.com/media/06278ae109957e38d0145459c2690696/href</a></iframe><p>For My Crypto Coins app, we already have created the application class earlier.</p><p><strong>Next, update your manifest file to enable your </strong><strong>App class.</strong></p><p>Skip this if you have already done that before.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04a71071adaeaac88e6ccc44a044ba6c/href">https://medium.com/media/04a71071adaeaac88e6ccc44a044ba6c/href</a></iframe><p>For My Crypto Coins app, we’ve also already set the App class in the manifest earlier.</p><p><strong>Now let’s create a new package called </strong><strong>dependencyinjection.</strong></p><p>Here we are going to keep all the files related to Dagger implementation.</p><p><strong>Create </strong><strong>AppModule class module which will provide dependencies all over your application.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0e168e47108d4242f7e161850d1dab4/href">https://medium.com/media/e0e168e47108d4242f7e161850d1dab4/href</a></iframe><p>As you see, to create a Dagger module we need to annotate it with the special @Module annotation. Projects usually have multiple Dagger modules. It is typical for one of them to provide app-wide dependencies. This AppModule will be used to initialize objects used across our application, such as Room database, Retrofit, Shared Preference, etc.</p><p>As an example, we could discuss a very common scenario for AppModule to provide a Context object in case we need it to get access to it anywhere in our app. Let’s analyze the code to see how to do that.</p><p>We need to use a special Dagger annotation @Provides. It tells Dagger that the method provides a specific type of dependency, in our case, a Context object. So when somewhere in the app we request to inject a Context, AppModule is the place where Dagger finds it. And it does not matter the names of our methods, as Dagger cares only about the return type. It is only common practice to name the method with provide prefix, but it can be anything you want.</p><p>The @Singleton annotation which you see applied to the same method is not part of the Dagger annotations. It is contained inside the javax package. This annotation tells Dagger that there should only be a single instance of that dependency.</p><p>You don’t need to write the boilerplate code to check if another instance of the object is already available. When generating the code Dagger will handle all that logic for you because of this annotation. Notice that our AppModule includes another module ViewModelsModule. Let’s create it now.</p><p><strong>Create a </strong><strong>ViewModelsModule class module. This module will be responsible for providing ViewModels all over your application.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70b7e98024cce033cd6d47373435a4f1/href">https://medium.com/media/70b7e98024cce033cd6d47373435a4f1/href</a></iframe><p>This module uses Dagger 2 feature map multi bindings. Using it, we contribute objects of our choosing into a map that becomes injectable anywhere in our app. Using the combination of Dagger annotations @Binds, @IntoMap and our custom annotation @ViewModelKey(this one we are going to create), we create an entry inside our map with key MainViewModel::class and value MainViewModel instance. We bind specific factory with the help of some common ViewModelFactory class. We need to create this class.</p><p><strong>Create a custom annotation class </strong><strong>ViewModelKey.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70bc5b909c2c81b09acacf46ed53b639/href">https://medium.com/media/70bc5b909c2c81b09acacf46ed53b639/href</a></iframe><p>This class is used for binding ViewModels in the ViewModelsModule. The specific annotation @ViewModelKey represents the key of our map. Our key can be only a class that inherits from ViewModel.</p><p><strong>Create the </strong><strong>ViewModelFactory class.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d99e663e46a2afe54f9b29942b3fbf7a/href">https://medium.com/media/d99e663e46a2afe54f9b29942b3fbf7a/href</a></iframe><p>This ViewModelFactory is a utility class which helps you dynamically create ViewModels. Here you provide the generated map as an argument. The create() method will be able to pick the right instance from the map.</p><p><strong>Create the </strong><strong>ActivityBuildersModule class module.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09fda21f1f229c18262f1e87f523a63c/href">https://medium.com/media/09fda21f1f229c18262f1e87f523a63c/href</a></iframe><p>This module is responsible for constructing all your activities. It will generate AndroidInjector for all Activities defined in this class. Then objects can be injected into activities using AndroidInjection.inject(this) in the onCreate function from the activity lifecycle. Notice that this module also uses another separate module responsible for fragments. We will create this module next.</p><p><strong>Create the </strong><strong>MainListFragmetBuildersModule class module.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b23a632bc490b9b6ec94c2399f25679a/href">https://medium.com/media/b23a632bc490b9b6ec94c2399f25679a/href</a></iframe><p>This module will build all your fragments related to MainActivity. It will generate AndroidInjector for all Fragments defined in this class. Objects can be injected into Fragments using AndroidSupportInjection.inject(this) in the onAttach function from the fragment lifecycle.</p><p><strong>Create the </strong><strong>AppComponent interface component.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55355df76ba77d24df43e3c84008ac02/href">https://medium.com/media/55355df76ba77d24df43e3c84008ac02/href</a></iframe><p>Component is a very important interface. It will enable all the above to start working together. It does this by connecting objects to their dependencies. Dagger will use this interface to generate the code necessary to perform the dependency injection.</p><p>To create a component class you will need to use Dagger annotation @Component. It takes a list of modules as an input. Another annotation @Component.Builder allows us to bind some instance to component.</p><p><strong>Then generate a graph object.</strong></p><p>At this moment you have all your modules and your component setup. You can generate your graph object by selecting Build -&gt; Make Module inside your Android Studio IDE. We will need this generation for future steps.</p><p><strong>Now create an </strong><strong>Injectable interface.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95441c3fef67c9162bd4ab25bcea0236/href">https://medium.com/media/95441c3fef67c9162bd4ab25bcea0236/href</a></iframe><p>This will also be needed for future steps. Injectable interface should be implemented by activities or fragments which we want to be injectable automatically.</p><p><strong>Create a new helper class named </strong><strong>AppInjector.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/518ba4afcf5c244acac4fec43920321c/href">https://medium.com/media/518ba4afcf5c244acac4fec43920321c/href</a></iframe><p>It is just a simple helper class to avoid calling the inject method on each activity or fragment.</p><p><strong>Next, setup the </strong><strong>App class which we already created before.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bce904c69cca626539f1a7bfc38cd6ac/href">https://medium.com/media/bce904c69cca626539f1a7bfc38cd6ac/href</a></iframe><p>Because the application has activities, we need to implement the HasActivityInjector interface. If you see an error called out by Android Studio on DaggerAppComponent, it is because you have not generated a new file, as was pointed out in the previous step.</p><p><strong>So, setup </strong><strong>MainActivity to inject the main ViewModel factory and add a support for fragment injections.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a84f0ba984896df43caf50221c99b477/href">https://medium.com/media/a84f0ba984896df43caf50221c99b477/href</a></iframe><p>Because our activities have child fragments we need to implement HasSupportFragmentInjector interface. We also need this because we plan to make injections into our fragments. Our activity should not know about how it is injected. We use the AndroidInjection.inject(this) code line inside overriding onCreate() method.</p><p>Calling inject() method will cause Dagger 2 to locate the singletons in the dependency graph to try to find a matching return type. However we don’t need to write any code here because it’s done for us by previously created AppInjector helper class which we initialized inside our application class.</p><p><strong>Then, setup </strong><strong>MainListFragment to inject the main ViewModel factory.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51038ed00be4df66c25caf32cd14d779/href">https://medium.com/media/51038ed00be4df66c25caf32cd14d779/href</a></iframe><p>Similar to activities, if we want our fragment to be injectable, then into its onAttach method we should write the code AndroidSupportInjection.inject(this). But again this is a job done by the AppInjector helper, so we can skip that. Just notice that we need to add the Injectable interface which we created earlier for the helper to work.</p><p>Congratulations, we’ve implemented Dagger 2 in the My Crypto Coins app project. Of course this article is a quick guide to deploy Dagger 2 in your app straight away, but not deep coverage of it. I recommend that you continue researching this topic if you feel lost on the basics.</p><h3>Repository</h3><p>Check out the source code of the updated “Kriptofolio” (previously “My Crypto Coins”) app on GitHub.</p><h4><a href="https://github.com/baruckis/Kriptofolio/tree/Part-4">View Source On GitHub</a></h4><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-4/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on October 7, 2018.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60fbc2bac2bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-part-4-60fbc2bac2bf">How to implement Dependency Injection in your app with Dagger 2</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about that architecture: exploring different architecture patterns and how to use them in your…]]></title>
            <link>https://medium.com/free-code-camp/my-crypto-coins-app-series-part-3-df57f86daf74?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/df57f86daf74</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Wed, 22 Aug 2018 14:10:55 GMT</pubDate>
            <atom:updated>2019-05-11T13:44:36.371Z</atom:updated>
            <content:encoded><![CDATA[<h3>All about that architecture: exploring different architecture patterns and how to use them in your app</h3><h4>Kriptofolio app series - Part 3</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xtjCi9Hfi8W4ye54HM2Y0w.png" /></figure><p>The most important thing to focus on when starting to build a new app is architecture. The biggest mistake you can make is to go with no architecture style at all.</p><p>The topic of architecture choice has been quite controversial for the Android community in recent years. Even Google decided to get involved. In 2017 they proposed their own approach of standardized architecture by releasing Android Architecture Components. It was intended to make developers’ lives easier.</p><p>In this post, I am first going to discuss why we need to architect our apps. We will cover what options we have. Then we are going to learn how to do that. Rather than reinventing the wheel, we will use guidelines provided by the Android team.</p><p>This post was the hardest one for me to write because of my own lack of knowledge about it. First I had to study the topic of architecture really well to see the bigger picture. Now I am ready to share my findings with you.</p><h3>Series content</h3><ul><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-61be4f8af906">Introduction: A roadmap to build modern Android app in 2018–2019</a></li><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-part-1-36fe781a75c1">Part 1: An introduction to the SOLID principles</a></li><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-part-2-580ccb4d8cf6">Part 2: How to start building your Android app: Mockups, UI, XML layouts</a></li><li>Part 3: All about that architecture: exploring different architecture patterns and how to use them in your app (you’re here)</li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-4-60fbc2bac2bf">Part 4: How to implement Dependency Injection in your app with Dagger 2</a></li><li><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-5">Part 5: Handle RESTful Web Services using Retrofit, OkHttp, Gson, Glide and Coroutines</a></li></ul><h3>Why should you care about app architecture?</h3><p>Usually when you start working with Android you end up writing most of the core business logic in activities or fragments. This happens to all new Android developers, including myself. All short tutorials and all samples suggest doing that. And actually, for small apps created for explanation, that works good enough.</p><p>However, try to do that on a real app which is constantly changing according to the users’ needs and expanding it with new features. Soon you will see that your coding experience is getting more and more painful. Everything becomes managed by so-called “God Classes” like activities or fragments. These have so many lines of code that you get lost easily.</p><p>Basically all your code starts to look like spaghetti where everything is mixed up. All the parts depend on each other. Then when new changes are required by the business, you are left with no choice but to rebuild the entire project. Also that’s the point where architecture questions start to appear.</p><h3>Is there a better way to structure your code?</h3><p>Of course there is! The key for high quality code is to follow the SOLID principles. I talked about this in my previous post (not without a reason). You should also apply some architecture pattern for separation of concerns. In fact, separation of concerns should be your ultimate goal. It is the most significant point which indicates code quality. There are quite a few patterns out there for app architectures. The most well known are the classic three tier architectures such as:</p><ul><li>MVC: Model-View-Controller</li><li>MVP: Model-View-Presenter</li><li>MVVM: Model-View-ViewModel</li></ul><p>All these patterns represent the main similar idea — to structure your project’s code in a way that it is separated by the different generic layers. Every layer has its own responsibility. That’s why your project becomes modular: separated code parts are more testable, and your app is flexible enough for continuous changes.</p><p>If we talk about each pattern individually, the topic becomes too broad. I am only going to introduce you to each one just so you can understand main differences.</p><h3>The Model-View-Controller (MVC) pattern</h3><p>This pattern was the first iteration Android app architecture took back in the old times. It suggests that you separate your code to 3 different layers:</p><p>Model — the data layer. Responsible for handling the business logic and communication with the network and database layers.</p><p>View — the user interface (UI) layer. It’s a simple visualization of the data from the Model.</p><p>Controller — the logic layer, gets notified of the user behavior and updates the Model as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DU4N6tj30K-cdILm.png" /></figure><p>This is the MVC schema. In it we can see that both the Controller and the View depend on the Model. The Controller updates the data. The View gets the data. However, the Model is separated and could be tested independently of the UI.</p><p>There are a few approaches of how to apply the MVC pattern. It’s quite confusing.</p><p>One is when activities and fragments act like the Controller. They are in charge of processing the data and updating the views. The problem with this architecture approach is that activities and fragments can become quite large and very difficult to test.</p><p>Another approach which seems more logical (and correct) is where activities and fragments should be the Views in the MVC world. The Controllers should be separate classes that don’t extend or use any Android class. Same for the Models.</p><p>Anyway if you investigate more about MVC, you will find out that when applied to an Android project, even in the correct way the code layers depend on each other. That’s why I would not recommend that you use it anymore for your next Android app.</p><h3>The Model-View-Presenter (MVP) pattern</h3><p>After the first approach, which didn’t work, Android developers moved on and tried to use one of the most popular architectural patterns — MVP. This pattern represents a second iteration of architecture choice. This pattern became widely used and is still a recommended one. For anybody who starts Android development, it is easy to learn. Let’s have a look at its 3 separate layers roles:</p><p>Model — the data layer, which is the same as on MVC pattern. Responsible for handling the business logic and communication with the network and database layers.</p><p>View — the user interface (UI) layer. Displays the data and notifies the Presenter about user actions.</p><p>Presenter — retrieves the data from the Model, applies the UI logic and manages the state of the View, decides what to display, and reacts to user input notifications from the View. This is essentially the controller from MVC except that it is not at all tied to the View, just an interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-FvjLCU4hd5O1mjn.png" /></figure><p>MVP schema shows that the View and the Presenter are closely related. They need to have a reference to one another. Their relationship is defined in a Contract interface class.</p><p>This pattern has one significant but controllable disadvantage. The Presenter tends to expand to a huge all-knowing class if you are not careful enough and don’t break your code according to single responsibility principle. However, generally speaking, the MVP pattern offers a very good separation of concerns. It could be your main choice for your project.</p><h3>The Model-View-ViewModel (MVVM) pattern</h3><p>MVVM pattern is the third iteration of the approach. It became the architecture pattern recommended by Android team with Android Architecture Components’ release. That’s why we will be focusing on learning this pattern most of all. Also I will be using it for “My Crypto Coins” app. As before, let’s take a look at its separate code layers:</p><p>Model — abstracts the data source. The ViewModel works with the Model to get and save the data.</p><p>View — that informs the ViewModel about the users’ actions.</p><p>ViewModel — exposes streams of data relevant to the View.</p><p>The difference compared to MVP pattern is that, in MVVM, the ViewModel does not hold a reference to the View as it is with the Presenter. In MVVM, the ViewModel exposes a stream of events to which various Views can bind. On the other hand, in the MVP case, the Presenter directly tells the View what to display. Let’s take a look at the MVVM schema:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wgul-7f3_G5PcN8T.png" /></figure><p>In MVVM the View has a reference to ViewModel. ViewModel has no information about the View. There is a many-to-one relationship between View and ViewModel.</p><h4>Comparison of MVC vs MVP vs MVVM</h4><p>Here is a table which sums up all the patterns I talked about:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IOIlEBcHQcJrTUks.png" /></figure><p>As you may have noticed, MVC is not so good compared to MVP and MVVM when building a modular and testable modern app. But each pattern has its own advantages and disadvantages. It is a good choice if it exactly fits your needs. I suggest that you investigate and learn more about all these patterns as it is worth it.</p><p>In the meantime, I will continue my project with the trending pattern in 2018, which is also pushed by Google — MVVM.</p><h3>Android Architecture Components</h3><p>If you’re familiar with the Android application lifecycle, you know what a headache it can be to build an app that avoids all data flow problems and persistence and stability issues which usually appear during configuration change.</p><p>In 2017, the Android team decided we’d struggled enough. They assumed responsibility and introduced the Android Architecture Components framework. This finally lets you solve all these issues without complicating your code or even applying hacks to it.</p><p>Android Architecture Components is a collection of libraries that helps you design robust, testable, and maintainable apps. At the current moment when I am writing this blog post, it consists of these components:</p><ul><li><a href="https://developer.android.com/topic/libraries/data-binding">Data Binding</a> — declaratively bind observable data to UI elements</li><li><a href="https://developer.android.com/topic/libraries/architecture/lifecycle">Lifecycles</a> — manage your activity and fragment lifecycles</li><li><a href="https://developer.android.com/topic/libraries/architecture/livedata">LiveData</a> — notify views when underlying database changes</li><li><a href="https://developer.android.com/topic/libraries/architecture/navigation">Navigation</a> — handle everything needed for in-app navigation</li><li><a href="https://developer.android.com/topic/libraries/architecture/paging">Paging</a> — gradually load information on demand from your data source</li><li><a href="https://developer.android.com/topic/libraries/architecture/room">Room</a> — fluent SQLite database access</li><li><a href="https://developer.android.com/topic/libraries/architecture/viewmodel">ViewModel</a> — manage UI-related data in a lifecycle-conscious way</li><li><a href="https://developer.android.com/topic/libraries/architecture/workmanager">WorkManager</a> — manage your Android background jobs</li></ul><p>With the help of the Android Architecture Components we are going to implement MVVM architecture pattern in My Crypto Coins app following this diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*0-hsCQF-Ry0cV2332YE3Aw.png" /></figure><p>It’s a recommended architecture by Google. It shows how all the modules should interact with one another. Next we’ll be covering only the specific Android Architecture Components that we will use in our project.</p><h3>Organizing your source files</h3><p>Before starting development we should consider how we should organize our project’s source files. We can not leave this question unanswered, as later we would have a messy structure hard to understand and modify.</p><p>There are several ways to do it. One is to organize by component category. For example, all activities goes to their own folder, all adapters go to their folder and so on.</p><p>Another way would be to organize everything by app features. For example, search and add crypto in all crypto currencies list feature goes to its own addsearchlist folder. The main idea is that you need to do it in some specific way instead of having everything placed randomly. I use some kind of mix of both of these.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*iP8HHiXOtxWesHowvjhvUQ.png" /><figcaption>My Crypto Coins app folder structure</figcaption></figure><p>Besides the project’s folder structure, you should consider applying some rules for naming project files. For example, when naming Android classes you should define the class purpose clearly in the name.</p><h3>ViewModel</h3><p>For the start of our app architecture development, first we are going to create the ViewModel. View models are objects that provide data for UI components and survive configuration changes.</p><p>You can use a ViewModel to retain data across the entire lifecycle of an activity or a fragment. Activities and fragments are short-lived objects. They are created and destroyed frequently as a user interacts with an app. A ViewModel is also better suited to managing tasks related to network communication, as well as data manipulation and persistence.</p><p>As example now lets create a ViewModel for MainListFragment to separate the UI data from it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c1d311cbfbab0b48a5856d5c8285b08/href">https://medium.com/media/7c1d311cbfbab0b48a5856d5c8285b08/href</a></iframe><p>Then obtain the ViewModel with single line of code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/376f23ec1ccc54ae706a90a9182ed9b4/href">https://medium.com/media/376f23ec1ccc54ae706a90a9182ed9b4/href</a></iframe><p>Basically that’s it, congratulations! 🙂 Let’s move on.</p><h3>LiveData</h3><p>LiveData is an observable data holder class. It follows the <a href="https://en.wikipedia.org/wiki/Observer_pattern">observer pattern</a>. LiveData is lifecycle-aware. This means that it only updates app component (activity, fragment, etc.) observers that are in an active lifecycle state.</p><p>LiveData class returns the latest value of the data. When data changes it returns the updated value. LiveData is best suited with ViewModel.</p><p>We will use LiveData together with ViewModel like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a71634977f1c8885554dfd9769bdf1d0/href">https://medium.com/media/a71634977f1c8885554dfd9769bdf1d0/href</a></iframe><p>Observe data on the ViewModel, exposed as LiveData:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9da04c383c86099e25393bc694098c77/href">https://medium.com/media/9da04c383c86099e25393bc694098c77/href</a></iframe><p>Browse the repository at this point in the history <a href="https://github.com/baruckis/MyCryptoCoinsApp-Android/tree/622cf980c4fb68efab546eeddf31c4bf5aee7ba1">here</a>.</p><h3>Data Binding</h3><p>Data Binding Library was created to remove boilerplate code needed to connect to XML layouts.</p><p>To use Data Binding in your Kotlin projects, you will need to turn on support for annotation processors with the kapt compiler plugin. Also add data binding block to the Android configuration gradle file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75e4a2ae07a977110d021e6addfb47ff/href">https://medium.com/media/75e4a2ae07a977110d021e6addfb47ff/href</a></iframe><p>To use data binding generated classes, we need to put all the view code in &lt;layout&gt; tags. The most powerful concept of data binding is that we can bind some data class to an xml layout and item properties to fields directly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/022b61d52840b2f4d2f9789996e319ee/href">https://medium.com/media/022b61d52840b2f4d2f9789996e319ee/href</a></iframe><p>RecyclerView adapter with data biding will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/649163792d4d91b58a5eb46ff9f4049a/href">https://medium.com/media/649163792d4d91b58a5eb46ff9f4049a/href</a></iframe><p>At last no more writing findViewById 🙂 Browse the repository at this point in the history <a href="https://github.com/baruckis/MyCryptoCoinsApp-Android/tree/05a05e0cbc1cac0aefc7a0030fd77779da213214">here</a>.</p><h3>Room</h3><p>Our app needs to store persistent data of different cryptocurrencies that the user holds. This should be stored inside the local database that is kept inside the Android device privately.</p><p>For storing structured data in a private database we will use a SQLite database. This is often the best choice.</p><p>In order to create the SQLite database for our app we will use Room. Room is a persistence library made by the Android team which is a wrapper above SQLite. It is an abstraction layer that removes much of the boilerplate code you need to interact with SQLite. It also adds compile-time checking of your SQL queries.</p><p>The best way to think of it is as an ORM (Object Relational Mapper) tool designed to automatically generate glue code to map between your object instances and rows in your database.</p><p>There are basically 3 major components in Room:</p><ol><li>Entity — this component represents a class that holds a database row. For each entity, a database table is created to hold the items.</li><li>DAO (Data Access Object) — the main component which is responsible for defining the methods that access the database.</li><li>Database — a component which is a holder class that uses annotation to define the list of entities, the list of DAOs, and database version and serves as the main access point for the underlying connection.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*jT94pc71uD_A2TPN_E2ulg.png" /></figure><p>Let’s follow these simple steps to setup Room in our My Crypto Coins app:</p><ol><li>Create an Entity.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/961daf654d86117a93f244c03166c307/href">https://medium.com/media/961daf654d86117a93f244c03166c307/href</a></iframe><p>Add some extra information to tell Room about its structure in the database.</p><p>2. Create the DAO.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8aef23e5f9e54973363a57782c6676f8/href">https://medium.com/media/8aef23e5f9e54973363a57782c6676f8/href</a></iframe><p>For the start, we are going to create a DAO which only allows us to retrieve records from the table that we have created with Entity and also to insert some sample data.</p><p>3. Create and setup the Database.</p><p>It is important to say that the Database instance should ideally be built only once per session. The one way to achieve this would be to use a Singleton pattern.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76ebd9119e700413f014e9fecca040de/href">https://medium.com/media/76ebd9119e700413f014e9fecca040de/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58a5f6457eaeaae848d4e40eeb8d38b6/href">https://medium.com/media/58a5f6457eaeaae848d4e40eeb8d38b6/href</a></iframe><p>As you see on initial run, the database will be prepopulated with some sample data just for testing purposes.</p><p>4. <strong>EXTRA step.</strong> Create the Repository.</p><p>The Repository is not part of the Architecture Components libraries. It is a suggested best practice for code separation and architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*_A8UbQDjX8YjzVZ3T7bhNw.png" /></figure><p>It stands as a single source of truth for all app data in case you have to manage multiple data sources.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ccfd233a124cf3ae93dda904b157709/href">https://medium.com/media/9ccfd233a124cf3ae93dda904b157709/href</a></iframe><p>We are going to use this repository in our ViewModel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b858a131b00fdf31808c9b5a689cae5/href">https://medium.com/media/5b858a131b00fdf31808c9b5a689cae5/href</a></iframe><p>Our Fragment code also evolves.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5579dce39b4c0e0292333f3fe4fb7217/href">https://medium.com/media/5579dce39b4c0e0292333f3fe4fb7217/href</a></iframe><p>Because our ViewModel class now has a constructor which is not empty anymore, we need to implement a provider factory pattern. This will be passed to the ViewModelProviders.of() method as the second parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93c84e75ca5ebd1a462e30df9d1277cf/href">https://medium.com/media/93c84e75ca5ebd1a462e30df9d1277cf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8397114204dcc10f1e80b61dccad2556/href">https://medium.com/media/8397114204dcc10f1e80b61dccad2556/href</a></iframe><p>Browse the repository at this point in the history <a href="https://github.com/baruckis/Kriptofolio/tree/b555fd9e2319bd4580122036d71066860fa82589">here</a>.</p><h3>Final thoughts</h3><p>Design architectures, that we discussed in this part, should be used as informed guidelines but not a hard rules. I did not wanted to go too much into detail on each topic. With Android Architecture Components we had a look at the coding process. Have in mind that there is lot more to learn on each component individually and I advise you to do that.</p><p>Let’s summarize everything that we manage to make already:</p><ul><li>In My Crypto Coins app, every separate screen has its own ViewModel. This will survive any configuration change and protect the user from any data loss.</li><li>The App’s user interface is a reactive type. This means it will update immediately when the data changes in the back-end. That is done with the help of LiveData.</li><li>Our project have less code as we bind to the variables in our code directly using Data Binding.</li><li>Finally, our app stores user data locally inside the device as a SQLite database. The database was created conveniently with the Room component. The App’s code is structured by features and all project architecture is MVVM — a recommended pattern by Android team.</li></ul><h3>Repository</h3><p>Now, as you’re seeing the “Kriptofolio” (previously “My Crypto Coins”) app is really starting to take shape. With the latest repository commit for this part 3, you can find it nicely showing prepopulated database data for the user with the total holdings portfolio value calculated correctly.</p><h4><a href="https://github.com/baruckis/Kriptofolio/tree/Part-3">View Source On GitHub</a></h4><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-3/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on August 22, 2018.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df57f86daf74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-part-3-df57f86daf74">All about that architecture: exploring different architecture patterns and how to use them in your…</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to start building your Android app: creating Mockups, UI, and XML layouts]]></title>
            <link>https://medium.com/free-code-camp/my-crypto-coins-app-series-part-2-580ccb4d8cf6?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/580ccb4d8cf6</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[apps]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Mon, 14 May 2018 12:39:30 GMT</pubDate>
            <atom:updated>2019-05-11T13:43:25.874Z</atom:updated>
            <content:encoded><![CDATA[<h4>Kriptofolio app series - Part 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tewVfnzAfO8iuqskpoIdow.png" /></figure><p>So how do you actually start to build a new app? What should be your first move? If you think we just need to launch Android Studio and jump directly to the code, think again. That’s exactly the thing I would advise not to do as it can do more damage than good. But it is so tempting to start writing your first lines of code as soon as possible.</p><p>Instead I would suggest focusing on making a wise plan with UI mockups. Remember that every good new app project should start with that. With this approach you will not loose a lot of time and will be able to build high quality products from the beginning.</p><p>So in this part of the series, I will present “Kriptofolio” (previously “My Crypto Coins”) app mockups and discuss how to create them. Also we are going to build all the UI layouts. These layouts will become our solid foundation indicating clearly what to code. Finally we will localize our app to different languages and learn how to handle the ones which are written from right to left.</p><h3>Series content</h3><ul><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-61be4f8af906">Introduction: A roadmap to build modern Android app in 2018–2019</a></li><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-part-1-36fe781a75c1">Part 1: An introduction to the SOLID principles</a></li><li>Part 2: How to start building your Android app: creating Mockups, UI, and XML layouts (you’re here)</li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-3-df57f86daf74">Part 3: Architecture patterns MVC, MVP, MVVM with Android Architecture Components — ViewModel, LiveData, Data Binding, Room</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-4-60fbc2bac2bf">Part 4: Dependency Injection with Dagger 2</a></li><li><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-5">Part 5: Handle RESTful Web Services using Retrofit, OkHttp, Gson, Glide and Coroutines</a></li></ul><h3>Mockups</h3><p>There are various ways you can create your project mockups. The simplest one is to take a pencil and a sheet of paper and start drawing on it. The best part is this way doesn’t cost you anything and you can start immediately. Oh and I almost forgot, you should also get yourself an eraser as there will not be any undo function. 🙂</p><p>If you, like I, feel that you need more functionality, then consider using special software for creating detailed mockups. I prefer using software instead of pencil &amp; paper, even if it requires you to invest your money to buy it and your time to learn how to use it.</p><p>There are various software options on the market to choose from. You will have to do your own investigation into which one best fits all your needs. For all my projects mockups right now I am using <a href="https://balsamiq.com/">Balsamiq</a> Mockups for Desktop app. Balsamiq is rapid, effective and very easy to use wire framing software. As I am rather happy with it, I recommend it for creating Android apps, so please feel free to try.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5TA06Hy-zj-uaxxcb1zyw.jpeg" /></figure><p>I started My Crypto Coins app project by creating well thought-out and very detailed mockups. I thought to myself that if I create everything in a very detailed way, than I will avoid mistakes. I will also not waste time for suddenly changing functionality during the development process. If you put a lot of effort in creating good mockups, than, with a little bit of imagination, you can see and feel the final product.</p><p>My goal was to have everything defined in the mockups like it should look in the end product. For that I tried not to rush but to spend as much time as I needed. Here are my final mockups for My Crypto Coins app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ciWyOJ2Lftb7hiXLNYNl9Q.png" /><figcaption>Mockup of My Crypto Coins app made with Balsamiq Mockups software</figcaption></figure><h3>Stock design — Material</h3><p>Another important thing to talk about is the app’s visual design. At the time of this writing, <a href="https://en.wikipedia.org/wiki/Material_Design">Material Design</a> is the stock visual design recommended by Google for all Android apps. And guess what — you can’t go wrong with stock design.</p><p>For My Crypto Coins app we will be using Material Design. The app follows the best practices defined in the detailed online guidelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0kyrt1pJA8XaUSKE9j1INg.jpeg" /></figure><p><a href="https://material.io/guidelines">Material.io/guidelines</a> — official material design living specs document which will be our design guidelines for this project.</p><h3>Layouts</h3><p>Now when we already have wireframes of our app prepared, it’s time to build real UI. Again we could jump into writing code, but why rush? Instead I would recommend concentrating on building all your XML layouts. My advice here would be that the more you manage to put into XML the less code you will need to write.</p><p>The Android team constantly improves the way you can build your UI by adding new features to XML layouts. Sometimes it’s so tempting to write few lines of code to reach a desired look. But it’s better to investigate the topic more deeply to find if it is possible to do without code. Remember: less code makes your project look cleaner. It will also be more understandable for other developers and easier to maintain.</p><p>Finally when you create all your XML layouts, you will feel like you have your app made. You will be able to launch it and see how it feels for the end user. It doesn’t matter that it is showing some fake data and does nothing. Now you have the last chance to make some drastic changes.</p><p>If you are building an app for somebody else, it’s such a good time to present it. Maybe you will be asked to make some surprising last minute changes. That way you will avoid writing code for functionality that will never be used. A lot of people don’t have enough imagination and they need to see and touch first to decide if it is what they want. So don’t leave your layouts for the last step in your work process.</p><p>For this app I will be using various components that are common in all modern Android apps:</p><ul><li><a href="https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout">CoordinatorLayout</a> — a super-powered FrameLayout, the main appeal of which is its ability to coordinate the animations and transitions of the views within it.</li><li><a href="https://developer.android.com/reference/android/support/design/widget/AppBarLayout">AppBarLayout</a> — a vertical LinearLayout which implements many of the features of material design’s app bar concept, namely scrolling gestures.</li><li><a href="https://developer.android.com/reference/android/support/v7/widget/Toolbar">Toolbar</a> — a generalization of action bars for use within application layouts.</li><li><a href="https://developer.android.com/reference/android/support/design/widget/CollapsingToolbarLayout">CollapsingToolbarLayout</a> — a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout.</li><li><a href="https://developer.android.com/reference/android/support/constraint/ConstraintLayout">ConstraintLayout</a> — a ViewGroup which allows you to position and size widgets in a flexible way. Imagine a RelativeLayout on steroids.</li><li><a href="https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout">SwipeRefreshLayout</a> — the widget which allows the swipe-to-refresh user interface pattern to be implemented entirely. It detects the vertical swipe, displays a distinctive progress bar, and triggers callback methods in your app.</li><li><a href="https://developer.android.com/reference/android/support/design/widget/FloatingActionButton">FloatingActionButton</a> — a circular button that triggers the primary action in your app’s UI.</li></ul><p>For the main screen we will use a combination of all these components to create nice UI/UX. Users can expand and collapse the top part of the layout to find the total value of all their cryptocurrency portfolio. They can check any change in value during the last 24 hours and change selected fiat currency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3GzRC56EjaWxMvhE8O2cQ.png" /><figcaption>Main screen layout creation</figcaption></figure><p>Of course there are other components besides these nine. It is very important to master the whole component palette to know which one to use in any particular case. With the mobile trends changing from time to time the palette will expand too.</p><p>I am not going to talk about every component, but my advice is to investigate that on your own. For me the best way to understand them is by trying to build XML layouts manually instead of using automatic drag &amp; drop tools in Android Studio.</p><h3>Styles, Colors, Dimensions, Strings, Icons</h3><p>At first glance, the things mentioned in this section title may appear not to be important ones. However, I ask that you to put in effort when creating them in any app if you want to make it modern and exclusive. Remember this blog posts series is how to build a MODERN Android app! No matter how wrong it is, people will usually judge your app by its looks first, not its functionality.</p><p>So here is a perfect chance to earn new users love from the beginning. These are my tips:</p><ul><li>When building your XML layout files, you should recognize where you repeat some common attributes for the views. Move them to be defined as separate XML styles. That way you will have shorter XML layout files. You can control all the app styling aspects from a separate place. Imagine what benefit it will give you. For example, you could allow the user to choose the app skin (bright, dark, etc.).</li><li>Define all your app colors in a separate file too, and enjoy ability to experiment with the look by changing them immediately. Sometimes the same product can be given new life and engage users again by simply refreshing with new colors. There are quite a few websites that can help you choose nice colors, but my favorite one is <a href="https://www.materialpalette.com/">MaterialPalette.com</a>, so take a look.</li><li>Define your app dimensions in a separate file. This will allow you to adjust your app to look good on different size screens.</li><li>All your strings should not be hard-coded, and Android Studio will inform you if you forget. Do not ignore that. The best part when your strings are separated is you can translate your app to different languages.</li><li>When using icons for your app, always prefer an XML vector drawable format. That’s the new recommended standard and a clever way to go to avoid any pixelation. To find many professionally made material design style icons from the community, please check out <a href="https://materialdesignicons.com/">MaterialDesignIcons.com</a>. I used this website to get icons for My Crypto Coins app.</li></ul><h3>RecyclerView</h3><p>The main screen of My Crypto Coins app will consist of a list of cryptocurrencies that the user holds. For this purpose the RecyclerView widget is the best fit. It is a widget that displays a scrolling list of elements based on large data sets (or data that frequently changes).</p><p>Because of its advantages, RecyclerView is the recommended component for creating any list screen. It is a more advanced and flexible version of the simpler ListView component. We will talk about it later too. In this part we are creating just layouts. We are not concentrating on coding.</p><p>To see our app visually, we will have to implement RecyclerView by writing some code. These are the steps to implement RecyclerView:</p><h4>1. Add a RecyclerView component.</h4><p>Our MainActivity layout is activity_main.xml. This layout includes content_main.xml layout which is a fragment. This MainActivityListFragment layout inflates fragment_main_list.xml. So you should add RecyclerView component here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e24b9e0de1dbaaa240d2336da65cdec/href">https://medium.com/media/9e24b9e0de1dbaaa240d2336da65cdec/href</a></iframe><p>As you see we configure our RecyclerView to leave some padding space at the bottom. We do this to avoid covering the last list item with the FloatingActionButton. Also we turn on the vertical scrollbar so it’s available.</p><h4>2. Create RecyclerView row layout.</h4><p>For our initial purpose we will only set the item name for each row. Our simplified layout should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/067e2a934808d55bd6231b8c7ac61fd7/href">https://medium.com/media/067e2a934808d55bd6231b8c7ac61fd7/href</a></iframe><h4>3. Create data adapter class.</h4><p>Our adapter for now will accept string data. Later we will need to create a separate class data model. We will need to pass more information than only one string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6e38081bbc85ced10ad27c4954fdfdb/href">https://medium.com/media/c6e38081bbc85ced10ad27c4954fdfdb/href</a></iframe><h4>4. Connect RecyclerView to custom adapter.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aca0c509ee5f15e0388099796d773891/href">https://medium.com/media/aca0c509ee5f15e0388099796d773891/href</a></iframe><p>Done! Now our main screen looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*1WVQXLqwxuXb910bQcc54Q.png" /><figcaption>Main screen</figcaption></figure><h3>ListView</h3><p>In this project, we will use ListView for the screen where you can add crypto coin(s) which you already hold. Because of its shortcomings in recent years it is hardly used anymore.</p><p>So I guess a lot of you at this moment are wondering why I decided to use it in My Crypto Coins app when we could create the same functionality easily with RecyclerView.</p><p>Remember, though, that this project was created for training purposes first. I thought it would be beneficial to gain insights into ListView and how it works. Any developer may run into ListView in legacy code, and it’s best to know how to work with it. Besides, the list we will be creating is so simple that ListView’s technical limitations won’t cause us any problems.</p><p>Let’s follow the very similar steps needed to implement ListView:</p><h4>1. Add a ListView component.</h4><p>The first thing to do is to add a ListView to AddSearchActivity. Open the activity layout file activity_add_search.xml and you will see that it includes content_add_search.xml. There we will add the ListView component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48146dd3236d46a32477108e3972e78c/href">https://medium.com/media/48146dd3236d46a32477108e3972e78c/href</a></iframe><h4>2. Create ListView row layout.</h4><p>As before, just for initial purposes, we will only set the item name for each row. Here is the simplified layout:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6ac18e7618b194529defa6d3eac3cfb/href">https://medium.com/media/b6ac18e7618b194529defa6d3eac3cfb/href</a></iframe><h4>3. Create data adapter class.</h4><p>Like RecyclerView our ListView adapter for now will accept only string data to get the item name and show it on screen. Later we will use a separate class data model. As for this part, we want to build a very simple list displaying only cryptocurrency titles. Instead of creating our custom adapter we could use the default, ArrayAdapter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d7ac0c10fa87c741ef172c8e6b64efa/href">https://medium.com/media/6d7ac0c10fa87c741ef172c8e6b64efa/href</a></iframe><p>As you see in the adapter code, by creating CustomViewHolder object I use the ViewHolder pattern. It stores list row view references. Calling the findViewById() method only occurs a couple of times. It allows us to make our list scrolling act smoothly and efficiently.</p><p>The ListView doesn’t require us to use the ViewHolder pattern. The RecyclerView’s adapter gives us that kind of protection by default, as it forces us to use it.</p><h4>4. Connect ListView to custom adapter.</h4><p>With default ArrayAdapter it could look like val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, data). That’s the beauty of the ListView component. If you want, you can create a simple list really fast without building your own adapter or row layout (skip steps 2 and 3).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56f1be75e37ae740e8a1598f22e40cba/href">https://medium.com/media/56f1be75e37ae740e8a1598f22e40cba/href</a></iframe><p>ListView setup is ready!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*6lpfmyzidzGQju_YmPHekQ.png" /><figcaption>Add crypto coin(-s) screen</figcaption></figure><h3>SearchView</h3><p>In the same screen with all cryptocurrencies listed, we also need to add SearchView. Search will be a useful functionality to have for any user who wants to find a specific cryptocurrency by typing its name. For this part we will not build functionality fully but just implement its visual part. Follow these steps to add SearchView to the project:</p><h4>1. Declare the searchable configuration in XML.</h4><p>The searchable configuration file should be added in your res directory named xml. Here you can specify attributes for your SearchView component which define how it behaves.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1701112f75f928ff0097affd0fe51800/href">https://medium.com/media/1701112f75f928ff0097affd0fe51800/href</a></iframe><h4>2. Create new activity which will become our searchable activity.</h4><p>We are going to create new blank activity which extends AppCompatActivity(). We will name it AddSearchActivity.</p><h4>3. Specify newly created activity in Android manifest file to be searchable.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4961c6818682732afb96d2c1265260d/href">https://medium.com/media/f4961c6818682732afb96d2c1265260d/href</a></iframe><p>We will let the Android system handle the search process. That’s why we add the intent action search and meta-data in the activity element of the AddSearchActivity. The meta-data has name and resource which is linked to the searchable configuration file located in the res/xml folder.</p><h4>4. Create search menu.</h4><p>Inside the res/menu folder we are going to create a menu resource file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7faf079a7a329f6fc296725cb2a9261/href">https://medium.com/media/f7faf079a7a329f6fc296725cb2a9261/href</a></iframe><h4>5. Add search menu to activity.</h4><p>We will add the Android search widget as a menu action view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d47ba81a41e7e5aac08d7405529f0ff/href">https://medium.com/media/7d47ba81a41e7e5aac08d7405529f0ff/href</a></iframe><p>Now the SearchView is added to the activity. Still the search functionality is not working. But we have it implemented as we wanted for this part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*H04EuFhD3r1vrIHSD_tbJg.png" /><figcaption>Add crypto coin(-s) screen — search functionality</figcaption></figure><h3>Settings</h3><p>If you want to create a modern Android app, I recommend that you include a settings screen and give access to app settings for the user. Including settings in your app gives your users the power to control some of the functionality of your app which makes them happier. They are now in control of how the app behaves. So we are going to create a settings screen for My Crypto Coins app too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*m6NnpRpwZnrsAeKW6rybqA.png" /><figcaption>New Settings Activity from gallery template</figcaption></figure><p>You can create a settings screen with Android Studio template and it will generate all the code you need. By default at the time of writing this blog post, settings activity is generated with preference headers. That’s not what we want for such a small app where we plan to have only few settings at first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*Kdlb-ZQKonUu-9xeTe0Nbw.png" /><figcaption>Default settings template with preference headers</figcaption></figure><p>Therefore we are going to build everything manually. Settings screen is designed with an XML-like layout. Let’s go step by step to create again only the visual part for this blog post:</p><h4>1. Create preferences screen XML file.</h4><p>We are going to create the preferences screen XML file which should be placed in the res/xml directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d9201ea97fa6357963c4e2a811243b9/href">https://medium.com/media/0d9201ea97fa6357963c4e2a811243b9/href</a></iframe><h4>2. Create preferences fragment.</h4><p>Then we should create a simple blank fragment — SettingsFragment, which should extend PreferenceFragment(). This fragment will create preferences from the XML resource that we created. In the future this fragment will contain all the necessary methods to inflate the XML settings. It will also provide callbacks when the settings are changed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26c1ebb97955d2d4aa5ff82e099954c7/href">https://medium.com/media/26c1ebb97955d2d4aa5ff82e099954c7/href</a></iframe><h4>3. Create preferences activity.</h4><p>With the settings fragment ready let’s create new activity — AppCompatPreferenceActivity, which extends PreferenceActivity(). This class provides compatibility across all the devices and versions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33916d7b7a260746d9f9e0c52df3dfa3/href">https://medium.com/media/33916d7b7a260746d9f9e0c52df3dfa3/href</a></iframe><h4>4. Create settings activity.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba58f172c2a34ad61edc43feaed51111/href">https://medium.com/media/ba58f172c2a34ad61edc43feaed51111/href</a></iframe><h4>5. Add settings item to main menu.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb943bdf563eceae84ca68b061427b2c/href">https://medium.com/media/eb943bdf563eceae84ca68b061427b2c/href</a></iframe><h4>6. Launch newly created settings activity when the settings is selected from overflow menu.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02fc8320a97e76715ab0d68249986610/href">https://medium.com/media/02fc8320a97e76715ab0d68249986610/href</a></iframe><h4>7. Specify newly created settings activity in Android manifest file.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49f6dd984fb9336ac0a1e41700b3a110/href">https://medium.com/media/49f6dd984fb9336ac0a1e41700b3a110/href</a></iframe><p>Congratulations, you can finally launch the settings from the toolbar’s menu item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*IuIa3QSVU-XkIJhvvFHKWg.png" /><figcaption>Settings screen</figcaption></figure><h3>Using 3rd party libraries — Gmail style flip circle button-view</h3><p>OK, there are various opinions about using 3rd party libraries — code created by a developer other than the original vendor of the development platform. Some people avoid them as it is never clear how long and how well they will be supported. Meanwhile others use them as they can accelerate the development process.</p><p>Your decision to use them should depend on your particular case. You should do your own investigation of the library and determine if it flexible enough to fit all your requirements.</p><p>For My Crypto Coins app, there is a situation where I would like to create a circle image view. This image should show a specific cryptocurrency icon inside a circle shape. But if the icon doesn’t exist, then I would like to show the first three letters of the cryptocurrency code.</p><p>Besides all that I would like to be able to select images by clicking them. Selection should be presented as a short flip view animation.</p><p>All this UX that I described was not originally invented by me. You can find similar behavior on the Gmail app and it looks really good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/0*26bbM1htoeIKiGs9.gif" /><figcaption>Gmail app flip circle view animation</figcaption></figure><p>But how do we create it? In fact, circle image view is not even a default component which you can find in the Android Studio components palette.</p><p>You could go the hard way and try to create everything yourself, but this could waste time and energy. Instead, you could choose to implement one of the many open source libraries created particularly for that.</p><p>For my UI/UX requirement, I found a library on GitHub <a href="https://github.com/davideas/FlipView">davideas/FlipView</a>. After some investigation I decided that it was really professionally made. It is easy to implement and supported long enough to give it a try. So to start using it, we’ll follow these easy steps:</p><h4>1. Add dependency.</h4><p>Import the library into your project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a15e5d60d6b06c1a1484e8d2f6515412/href">https://medium.com/media/a15e5d60d6b06c1a1484e8d2f6515412/href</a></iframe><h4>2. Use it.</h4><p>Configure FlipView with Android’s usual and custom app attributes. Isn’t that easy?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4b85b3e5b5b42f427ce9c6b333b3be0/href">https://medium.com/media/b4b85b3e5b5b42f427ce9c6b333b3be0/href</a></iframe><p>So don’t reinvent the wheel. Always consider using some library first to deliver results faster. And if you project becomes messy, it’s not the old libraries to blame but how well you structure your code. If your project is modular enough there won’t be problems. But that’s a separate topic and I am going to talk about project architecture in later blog posts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/0*x4Nx1fwI4iwck8-c.gif" /><figcaption>Flip View used inside main screen list</figcaption></figure><h3>Localization with RTL support</h3><p>When I decided to create this app, I set myself a goal not only to create it with a default English UI, but also to translate it to my mother tongue, Lithuanian, from the start of development.</p><p>This goal lead me to learn about localization in Android. What I have found is that to add support for multiple languages is very easy. As I mentioned before, first you need to separate all your strings to the strings.xml file. Then you can launch the Translations Editor tool inside Android Studio. This will allow you to add new languages support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2hzxAC2dDSMnqlyF4VHCw.png" /></figure><p>You will see that the interface is very intuitive. Now you need to translate each string from your strings.xml file to a new language. A new file will be generated by the IDE in separate directory. For example, for Lithuanian language, it’s values-lt/strings.xml. That’s it! 🙂</p><p>If you switch your Android device system language to the one you just translated to and then run your app, all the UI will be automatically updated to your translations. Moreover, for My Crypto Coins app, later I plan to add the ability to switch languages at run-time. That’s why you will notice the language switcher inside the settings screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*Wa3BEirdnfg21PB-IRwYXA.png" /><figcaption>Settings screen — language Lithuanian</figcaption></figure><p>Translating your app to different languages will definitely widen your audience. Why not go further by adding support for a few special languages that are written from Right to Left (RTL) — like Arabic, Hebrew or Persian.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COi5U81UK015BfLSsoQtPg.png" /></figure><p>Actually to add RTL support is not difficult at all. Just add the support attribute to your manifest file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c210231d0f30e0213cbea7e80404a14c/href">https://medium.com/media/c210231d0f30e0213cbea7e80404a14c/href</a></iframe><p>Congratulations, your app now supports RTL. However you can’t trust blindly that everything will work correctly straightaway. You should check how well it is supported yourself. To do that select one of the RTL languages as your primary device language.</p><p>A few tips for RTL:</p><ul><li>In all your layouts you will need to replace all Left and Right layout properties with Start and End equivalent. For example android:paddingLeft should be replaced with android:paddingStart.</li><li>If you don’t have a special drawable for RTL, perhaps you would like to mirror your current ones with a special autoMirrored attribute.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b090a32074e7da97a2a1181330f4dc5d/href">https://medium.com/media/b090a32074e7da97a2a1181330f4dc5d/href</a></iframe><ul><li>If there are certain places where you need to have LTR instead of RTL, you can do that too. For example to force any layout to LTR just add android:layoutDirection=&quot;ltr&quot; to that view. If you need to force text direction inside text view than use android:textDirection=&quot;ltr&quot;.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*V-zeS7WGF8Af0sua5MyhuA.png" /></figure><p>By the way, when using Translations Editor, there is a very useful feature to order a professional translation service. Even if I personally don’t know anything about the Hebrew language, I still set myself a goal to add support for it as an example RTL language for My Crypto Coins project. So this feature seemed like a really good idea to try. I ordered the translation successfully from English to Hebrew directly from the IDE with just a few clicks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1or1qQdqMBR-crfmkGe3Wg.png" /><figcaption>Order a translation service</figcaption></figure><h3>Final thoughts</h3><p>In this second part of the series, we created all the UI layouts with some initial code based on detailed mockups. I did not want to go into too much detail on each topic so as not to confuse you. My goal was to show you how to see a bigger picture, how to focus on small details first, and avoid costly mistakes later.</p><p>If you find something not covered well enough, use it as a jumping off point to do your own research. There are always plenty of good resources around the web to learn from. 😉</p><h3>Repository</h3><p>You can find all the XML layouts and code created for this part here:</p><h4><a href="https://github.com/baruckis/Kriptofolio/tree/Part-2">View Source On GitHub</a></h4><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-2/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on May 14, 2018.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=580ccb4d8cf6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-part-2-580ccb4d8cf6">How to start building your Android app: creating Mockups, UI, and XML layouts</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction to the SOLID principles]]></title>
            <link>https://medium.com/free-code-camp/my-crypto-coins-app-series-part-1-36fe781a75c1?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/36fe781a75c1</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[apps]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 23:43:35 GMT</pubDate>
            <atom:updated>2026-03-24T11:07:18.485Z</atom:updated>
            <content:encoded><![CDATA[<h4>Kriptofolio app series - Part 1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zl4KIqJJhbnroDJh-y3_AQ.png" /></figure><p>Software is always in a state of change. Each change can have a negative impact on a whole project. So the essential thing is to prevent damage that can be done while implementing all new changes.</p><p>With “Kriptofolio” (previously “My Crypto Coins”) app, I will be creating a lot of new code step by step and I want to start doing that in a good way. I want my project to be solid quality. First we need to understand the foundation principles of creating modern software. They are called SOLID principles. Such a catchy name! 🙂</p><h3>Series content</h3><ul><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-61be4f8af906">Introduction: A roadmap to build a modern Android app in 2018–2019</a></li><li>Part 1: An introduction to the SOLID principles (you’re here)</li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-2-580ccb4d8cf6">Part 2: How to start building your Android app: creating Mockups, UI, XML layouts</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-3-df57f86daf74">Part 3: All about that Architecture: exploring different architecture patterns and how to use them in your app</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-4-60fbc2bac2bf">Part 4: How to implement Dependency Injection in your app with Dagger 2</a></li><li><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-5">Part 5: Handle RESTful Web Services using Retrofit, OkHttp, Gson, Glide and Coroutines</a></li></ul><h3>Principles slogan</h3><p><strong>SOLID</strong> is a mnemonic acronym. It helps to define the five basic object-oriented design principles:</p><ol><li><strong>S</strong>ingle Responsibility Principle</li><li><strong>O</strong>pen-Closed Principle</li><li><strong>L</strong>iskov Substitution Principle</li><li><strong>I</strong>nterface Segregation Principle</li><li><strong>D</strong>ependency Inversion Principle</li></ol><p>Next we are going to discuss each of them individually. For each, I am going to provide bad vs good code examples. These examples are written for Android using the Kotlin language.</p><h3>Single Responsibility Principle</h3><blockquote><em>A class should have only a single responsibility.</em></blockquote><p>Each class or module should be responsible for one part of the functionality provided by the app. So when it handles one thing, there should be only one main reason to change it. If your class or module does more than one thing, then you should split the functionalities in separate ones.</p><p>For a better understanding of this principle, I would take as an example a Swiss Army knife. This knife is well known for its multiple functions besides its main blade. It has other tools integrated inside, such as screwdrivers, a can opener, and many others.</p><p>The natural question here for you is why am I suggesting this knife as an example for single functionality? But just think about it one moment. The other main feature of this knife is mobility while being pocket size. So even if it offers a few different functions it still fits its main purpose to be small enough to take it with you comfortably.</p><p>The same rules go with programming. When you create your class or module, it has to have some main global purpose. At the same time you can’t overplay when trying to simplify everything too much by separating functionality. So remember, keep the balance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*m1OGuBK5fYZM1Lof6GkH3Q.jpeg" /></figure><p>A classic example could be the often used method onBindViewHolder when building RecyclerView widget adapter.</p><p>👿 BAD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34969663c5dfd51bd052468a58302352/href">https://medium.com/media/34969663c5dfd51bd052468a58302352/href</a></iframe><p>🙂 GOOD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/888558a1d4f171c28b75709327f28c6c/href">https://medium.com/media/888558a1d4f171c28b75709327f28c6c/href</a></iframe><p>Code specifically designed with the Single Responsibility Principle in mind will be close to the other principles that we are going to discuss.</p><h3>Open-Closed Principle</h3><blockquote><em>Software entities should be open for extension, but closed for modification.</em></blockquote><p>This principle states that when you write all the software parts like classes, modules, and functions, you should make them open for extension but closed for any modification. What does that mean?</p><p>Let’s say we create a working class. There should be no need to tweak that class if we need to add new functionality or do some changes. Instead we should be able to extend that class by creating its new subclass where we could easily add all new necessary features. Features should always be parameterized in a way that a subclass can override.</p><p>Let’s take a look at an example where we will create a special FeedbackManager class to show a different type of custom message for the user.</p><p>👿 BAD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5e666067255964a031bca4a038781c7/href">https://medium.com/media/b5e666067255964a031bca4a038781c7/href</a></iframe><p>🙂 GOOD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c874bb827fbb3b81a23d31418a371292/href">https://medium.com/media/c874bb827fbb3b81a23d31418a371292/href</a></iframe><p>The open-closed principle summarizes the goals of the next two principles that I talk about below. So let’s move on to them.</p><h3>Liskov Substitution Principle</h3><blockquote><em>Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.</em></blockquote><p>This principle is named after <a href="https://en.wikipedia.org/wiki/Barbara_Liskov">Barbara Liskov</a> — an accomplished computer scientist. The general idea of this principle is that objects should be replaceable by instances of their subtypes without changing the behavior of the program.</p><p>Let’s say in your app you have MainClass which depends on BaseClass, which extends SubClass. In short, to follow this principle, your MainClass code and your app in general should work seamlessly without any problems when you decide to change BaseClass instance to the SubClass instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*72oYWBRb9y7HgiE-KkMQGw.png" /></figure><p>To understand this principle even better, let me give you a classical, easy to understand example with Square and Rectangle inheritance.</p><p>👿 BAD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db5b32e907c0e7cd410f990e935405f3/href">https://medium.com/media/db5b32e907c0e7cd410f990e935405f3/href</a></iframe><p>🙂 GOOD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/869a268f629fd816dee02b3b1377404a/href">https://medium.com/media/869a268f629fd816dee02b3b1377404a/href</a></iframe><p>Always think before writing down your hierarchy. As you see in this example, real-life objects do not always map to the same OOP classes. You need to find a different approach.</p><h3>Interface Segregation Principle</h3><blockquote><em>Many client-specific interfaces are better than one general-purpose interface.</em></blockquote><p>Even the name sounds complicated, but the principle itself is rather easy to understand. It states that a client should never be forced to depend on methods or implement an interface that it doesn’t use. A class needs to be designed to have the fewest methods and attributes. When creating an interface try not to make it too big. Instead split it into smaller interfaces so that client of the interface will only know about the methods that are relevant.</p><p>To get the idea of this principle I have created again bad vs good code examples with butterfly and humanoid robots. 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JTIxFog4gli6Z7rWlVhWEQ.jpeg" /></figure><p>👿 BAD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3beae62a00f734f361581ba4318ef27e/href">https://medium.com/media/3beae62a00f734f361581ba4318ef27e/href</a></iframe><p>🙂 GOOD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00b223c5a82c029c223e1e4bc299f2ab/href">https://medium.com/media/00b223c5a82c029c223e1e4bc299f2ab/href</a></iframe><h3>Dependency Inversion Principle</h3><blockquote><em>One should “depend upon abstractions, [not] concretions.”</em></blockquote><p>The last principle states that high-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.</p><p>The main idea of the principle is not to have direct dependencies between the modules and classes. Try to make them dependent on the abstractions (e.g. interfaces) instead.</p><p>To simplify it even more, if you use a class inside another class, this class will be dependent on the class injected. This violates the principle’s idea and you should not do that. You should try to decouple all classes.</p><p>👿 BAD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/653f44b940edac79217d5a1835677615/href">https://medium.com/media/653f44b940edac79217d5a1835677615/href</a></iframe><p>🙂 GOOD CODE EXAMPLE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/121f7d5fbf1caf8fd6de1b63e9a797ae/href">https://medium.com/media/121f7d5fbf1caf8fd6de1b63e9a797ae/href</a></iframe><h3>To sum up briefly</h3><p>If we think about all these principles, we can notice that they are complementary to each other. Following the SOLID principles will give us many benefits. They will make our app reusable, maintainable, scalable, testable.</p><p>Of course it is not always possible to follow all these principles completely, as everything depends on individual situations when writing code. But as a developer you should at least know them so you can decide when to apply them.</p><h3>Repository</h3><p>This is the first part where we learn and plan our project instead of writing new code. Here is a link to Part 1 branch commit, which basically is “Hello world” initial code of the project.</p><h4><a href="https://github.com/baruckis/Kriptofolio/tree/Part-1">View Source On GitHub</a></h4><p>I hope I managed to explain SOLID principles well. Feel free to leave comments below.</p><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-1/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on February 23, 2018.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36fe781a75c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-part-1-36fe781a75c1">An introduction to the SOLID principles</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A roadmap to build a modern Android app in 2018–2019]]></title>
            <link>https://medium.com/free-code-camp/my-crypto-coins-app-series-61be4f8af906?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/61be4f8af906</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[apps]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Mon, 12 Feb 2018 20:05:00 GMT</pubDate>
            <atom:updated>2019-08-12T05:48:09.417Z</atom:updated>
            <content:encoded><![CDATA[<h4>Kriptofolio app series — Introduction</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvYYjocj8-ytP2OBY_Fdpg.png" /><figcaption>A roadmap to build a modern Android app in 2018–2019</figcaption></figure><p>Welcome to this series of blog posts where I will be creating a modern Android app. I will use the best tools and practices available in the year 2018–2019. I am doing this because I want to cover all the hottest topics in the Android world and acquire knowledge in them by teaching you.</p><p>If you follow this series, you will learn how to develop the app from scratch. Each blog post from this series will cover some specific development topic which I want to talk about. I will try to do my best to create a good quality app and explain the development process. This first blog post from the series is a project’s roadmap of what we are going to do.</p><h3>Series content</h3><ul><li>Introduction: A roadmap to build a modern Android app in 2018–2019 (you’re here)</li><li><a href="https://medium.freecodecamp.org/my-crypto-coins-app-series-part-1-36fe781a75c1">Part 1: An introduction to the SOLID principles</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-2-580ccb4d8cf6">Part 2: How to start building your Android app: creating Mockups, UI, XML layouts</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-3-df57f86daf74">Part 3: All about that Architecture: exploring different architecture patterns and how to use them in your app</a></li><li><a href="https://medium.com/@baruckis/my-crypto-coins-app-series-part-4-60fbc2bac2bf">Part 4: How to implement Dependency Injection in your app with Dagger 2</a></li><li><a href="https://www.baruckis.com/android/kriptofolio-app-series-part-5">Part 5: Handle RESTful Web Services using Retrofit, OkHttp, Gson, Glide and Coroutines</a></li></ul><h3>The app: “Kriptofolio” (previously “My Crypto Coins”) idea</h3><p>At first it was hard to think of a plan to showcase all Android development trends, but finally, I found one which I liked. It is related to my huge interest area — blockchain and cryptocurrencies. I decided to create an app which would contain your cryptocurrencies portfolio and let you know how much they are worth converted to fiat money.</p><p>The important thing for the user is that this app is going to ensure 100% trust. It will not require any login/registration process. It won’t collect users’ data by sending it to the server. I guess nobody would feel comfortable sharing information online about owned money.</p><p>Users’ provided data about cryptocurrency investments will be only stored inside a local database that is kept inside an Android device. However, to know the portfolio’s value converted to the fiat money, the app is going to use the Internet to get the latest conversion rates.</p><p>So as you see for training purposes, this app idea is great. It is technically challenging you to try different approaches to work with data. This is one of the most important skills to know to build modern apps. The topic of money for people is so sensitive. To ensure even more trust, I will be developing this app openly by creating this blog posts series and making the project code available so everyone can see that there is nothing to hide.</p><h3>What are we going to use?</h3><p>First, to create this app, we need to know about various cryptocurrency prices at the current moment. This data will be provided from the Internet as it is continually changing.</p><h4>Data API:</h4><p><a href="https://coinmarketcap.com/">CoinMarketCap</a> — one of the most popular websites for getting an overview of the cryptocurrency market. This website offers a free <a href="https://coinmarketcap.com/api">API</a> that anyone can use and it fits perfectly for us as a data service provider.</p><p>Next, I made a list of my most significant trending things in the Android world that fit this project and should be used in it.</p><h4>Programming language:</h4><p><a href="https://kotlinlang.org/">Kotlin</a> — an official language on Android. It is expressive, concise, and powerful. Best of all, it’s interoperable with existing Android languages and runtime.</p><p>This new language introduction was one of the hottest topics in 2017 for Android. Our app needs to be written in it. I also talk about Kotlin and its features in my past blog post “<a href="https://medium.com/mindorks/learn-kotlin-android-calculator-app-b86b275cc27c">Let’s learn Kotlin by building Android calculator app</a>”.</p><h4>Integrated development environment (IDE):</h4><p><a href="https://developer.android.com/studio">Android Studio</a> — the official IDE for Android. It provides the fastest tools for building apps on every type of Android device. There are no better alternatives for developing native apps. It’s our main choice for an IDE without any question.</p><h4>Project build management system:</h4><p><a href="https://gradle.org/">Gradle</a> — is an advanced general purpose build management system based on Groovy and Kotlin. It supports the automatic download and configuration of dependencies or other libraries. It is the recommended build system by Google. It is well integrated inside Android Studio so we will be using it.</p><h4>Architecture:</h4><p><a href="https://developer.android.com/topic/libraries/architecture">Android Architecture Components</a> — a collection of libraries that help you design robust, testable, and maintainable apps.</p><p><a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel">Model–View–ViewModel (MVVM)</a> — an architectural pattern. The concept is to separate data presentation logic from business logic by moving it into a particular class for a clear distinction. The Android team is pushing this pattern as the default choice. Also, it’s an alternative to <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">MVC</a> and popular <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter">MVP</a> patterns.</p><p>I’ll be talking separately in this series about this pattern choice, other architecture options and how to organize our code well in general. It is essential if we want to build an easily maintainable solid project.</p><p><a href="https://kotlinlang.org/docs/reference/coroutines-overview.html">Coroutines</a> — a concurrency design pattern that you can use on Android to simplify code that executes asynchronously.</p><h4>Data persistence:</h4><p><a href="https://developer.android.com/training/data-storage/sqlite">SQLite Database</a> — it is an open source SQL database that stores data persistently to a text file on a device. Android comes in with built-in SQLite database implementation. SQLite supports all the relational database features.</p><p><a href="https://developer.android.com/reference/android/content/SharedPreferences">Shared Preferences</a> — an API from Android SDK to store and retrieve application preferences. SharedPreferences are merely sets of data values stored persistently. It allows you to save and retrieve data in the form of key value pairs.</p><h4>Libraries:</h4><p><a href="https://developer.android.com/jetpack"><em>Android Jetpack</em></a><em> components:</em></p><p><a href="https://developer.android.com/topic/libraries/support-library/packages#v7-appcompat">AppCompat</a> — it is a set of support libraries which can be used to make the apps that were developed with newer versions work with older versions.</p><p><a href="https://developer.android.com/kotlin/ktx">Android KTX</a> — a set of Kotlin extensions for Android app development. The goal of Android KTX is to make Android development with Kotlin more concise, pleasant, and idiomatic by leveraging the features of the language such as extension functions/properties, lambdas, named parameters, and parameter defaults.</p><p><a href="https://developer.android.com/topic/libraries/data-binding">Data Binding</a> — is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.</p><p><a href="https://developer.android.com/topic/libraries/architecture/lifecycle">Lifecycles</a> — for managing your activity and fragment lifecycles.</p><p><a href="https://developer.android.com/topic/libraries/architecture/livedata">LiveData</a> — is an observable data holder class which was designed to help solve common Android Lifecycle challenges and to make apps more maintainable and testable.</p><p><a href="https://developer.android.com/topic/libraries/architecture/room">Room</a> — it provides an abstraction layer over SQLite to allow easy database access while harnessing the full power of SQLite.</p><p><a href="https://developer.android.com/topic/libraries/architecture/viewmodel">ViewModel</a> — designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.</p><p><em>Other:</em></p><p><a href="https://developer.android.com/reference/android/support/constraint/ConstraintLayout">ConstraintLayout</a> — for building flexible and efficient layouts. The Layout Editor uses constraints to determine the position of a UI element within the layout. A constraint represents a connection or alignment to another view, the parent layout, or an invisible guideline.</p><p><a href="https://developer.android.com/reference/android/support/v7/widget/CardView">CardView</a> — element which represents the information in a card manner with a drop shadow (elevation) and corner radius which looks consistent across the platform.</p><p><a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView">RecyclerView</a> — a flexible and efficient version of ListView. It is a container for rendering large data set of views that can be recycled and scrolled very efficiently.</p><p><em>Third-party:</em></p><p><a href="https://google.github.io/dagger">Dagger 2</a> — this is an entirely static, compile-time dependency injection framework for both Java and Android.</p><p><a href="https://square.github.io/retrofit">Retrofit 2</a> — an open source type-safe HTTP client for Android and Java. With Retrofit, we can compose the HTTP connection easily through a simple, expressive interface just like an API document.</p><p><a href="http://square.github.io/okhttp">OkHttp</a> — an open source modern, fast and efficient HTTP client which supports HTTP/2 and SPDY.</p><p><a href="https://github.com/google/gson">Gson</a> — an open source Java library to serialize and deserialize Java objects to and from JSON.</p><p><a href="https://bumptech.github.io/glide">Glide</a> — a fast and efficient image loading library for Android focused on smooth scrolling. Glide offers an easy to use API, a performant and extensible resource decoding pipeline and automatic resource pooling.</p><h3>Configuring a new project</h3><p>We will create this project from scratch. So I’ll launch Android Studio, create a new Project, name it “My Crypto Coins” and select “Basic Activity”. At this point, there is nothing special to discuss. Our goal is to make a fresh, clean start and avoid any complexity in our minds by adding additional features (e.g., instant app support). We can add anything later if we want during the development process.</p><p>For a start let’s include Kotlin language support and target <a href="https://en.wikipedia.org/wiki/Android_Marshmallow">API 23: Android 6.0 (Marshmallow)</a>.</p><p>Why am I not targeting a lower or higher API? Let’s face it. It’s nice to cut the support for some older devices and not worry about any compatibility issues during development. Also, I am a proud owner of an old <a href="https://en.wikipedia.org/wiki/Nexus_7_(2013)">Nexus 7 (2013) tablet</a>, which is running Android 6.0.1. I hope to test my app live on it. 🙂 So for this individual project that impacted my minimum SDK choice.</p><p>Also as you’ve noticed, I am going to ask IDE to add automatically generated basic activity with fragment support and a floating action button. I feel all that could be useful for our project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*8bJ0_9jzHsRsDsCCCaW_ow.png" /><figcaption><strong>In Android Studio from v3.0 Kotlin plugin is already built-in, just select checkbox to add support.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*Itk48Ve-mCemiRzztlfpWA.png" /><figcaption><strong>Select minimum targeted SDK based on business needs.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*oQN5mSJWAmSdYOFhtPYEWA.png" /><figcaption><strong>Choose basic activity which will generate useful code for a start.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*nnuNmqbmc9XBZ8hUofvrdw.png" /><figcaption><strong>Select the checkbox to have content placed into the fragment.</strong></figcaption></figure><p><a href="https://github.com/">GitHub</a> — one of the most popular web-based hosting service for version control. This is an open source project, and of course, I will be using it.</p><p>All the blog posts from this series will have its commits made as separate branches and the master branch for the latest source code version. Here is a link for you to the repository.</p><h4><a href="https://github.com/baruckis/Kriptofolio">View Source code on GitHub</a></h4><p>That’s it for the start. If you have any questions, suggestions, remarks to make, please feel free to do that in comments. And now let’s learn together! Part 2 is up next…😉</p><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my blog </em></strong><a href="https://www.baruckis.com/android/kriptofolio-app-series/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on February 12, 2018.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61be4f8af906" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-crypto-coins-app-series-61be4f8af906">A roadmap to build a modern Android app in 2018–2019</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimize your life by making strategical pauses]]></title>
            <link>https://medium.com/@baruckis/optimize-life-strategical-pauses-25dc2dc5790b?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/25dc2dc5790b</guid>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programmers-life]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[freedom]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Wed, 31 Jan 2018 17:44:28 GMT</pubDate>
            <atom:updated>2018-12-18T11:35:16.870Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iHclpkQR73z00egpfz4eNA.jpeg" /></figure><p>I want to talk about optimization. This is very important topic for all us, IT developers, which we face when we are creating software. I bet you agree that programmers are tend to be lazy people, that’s why they always look for the best way to do something with minimum effort, they try to automate all they can and use lowest computing power possible. Of course there can be some exemptions when we rush to deliver as we are short on time, but in general we try to optimize our code and our daily tasks to the maximum efficiency. We all understand and agree that we need to allocate some extra time if we want to create easily maintainable, extendable, clean and high quality code. We need time because we can not rush as we need to experiment, educate ourselves in order to use best strategy and tools. Usually we ask our team leaders, managers, boss for that and we are angry if they don’t understand us. And at this point of agreement I want to stop and ask you, when the last time do you allocated some similar time to optimize your life? When have you made a pause for all your daily routine just to think about your goals, do unfinished things you always wanted and perhaps apply some better strategy for your career or personal life like you apply design patterns for your code. And I am not talking just about few hours of thinking in the silence while relaxing after the good party, but the time period (month, year) big enough actually to do something real. If you can confirm for yourself that you done that recently or you even do that regularly than let me congratulate you. You can skip this post. However if you are not sure or you don’t understand what I am talking about I invite you to continue reading.</p><h3>Busy developer picture</h3><p>So let me try to draw the picture of you, which could be more precise especially if you are IT developer. So first of all you love technology and you are really busy with constantly learning new IT skills. You feel that you are always chasing and trying to catch up. The more your learn the more you feel that you don’t know. Time after time you change companies and jobs as you want to improve, you want to be up to date while working on new latest technology projects. You do that because if you want to be IT developer you have to learn constantly. So it’s really hard. But you know because it’s hard you get paid well, really well (or that’s what you think). After work you are tired and you just don’t have time. You don’t have time for anything else serious. Yes you have weekends left but when they start you have so many gathered daily life issues to solve, and also you want to relax and entertain yourself. And if at that daily constantly repeating circle that you live in you come up with some crazy creative new ideas that you would like to try guess what happens? You just think about it, usually talk about it and never do that. Why? Let me repeat myself, because you don’t have time left for anything serious and abstract. Do you see what I mean?</p><h4>It’s a loop.</h4><p>If we want to optimize our lives we need to break that loop. To do that we need to identify why it’s continuing. In my opinion the reason is simple to see, it is related with money and fear. We all fear to loose money. Actually I got really disappointed inside when I had read one blog post where a programmer says that for him every day is money, big money earned and that even to be sick is not worth it because you just loose money. Just think about this opinion for a while. On the one hand people dream and talk about businesses they could create, interesting things they could do, adventures that they would have and on the other hand they refuses all that for their greed, greed for money. Money which when you think about it are really not big enough, but just comfortable to live with and gives you imaginable safety. If you now start wondering what’s wrong to live comfortable life let me stop you right now. Let’s discuss the benefits of breaking that loop and making strategical pause in life.</p><h3>Benefits of breaking the loop</h3><p>What is strategical pause? What do I mean? As I said previously it’s similar to code optimization, just here you optimize your life. First you step out of your daily routine and suddenly you have plenty of time for everything. Remember you need to think that you stepped out for unlimited time to get that feeling. It’s not a holidays, not a long break between changing jobs or contracts, you don’t have to feel a pressure to come back anywhere. When you do that you immediately notice that you have so many small things gathered up that you need to solve and do. These small things bothered you for a long time, maybe even a years, but now you have time for them. Best part here is that you will solve all these annoying things faster as you thought, because you can concentrate to them fully each every day without interruption. Just imagine that good feeling when you finish the last one and feel free again. With freedom will come back the joy. Finally feeling free again you will get some time to entertain yourself by concentrating to abandoned hobbies. Read popular book you always wanted, learn to play guitar, finish all the levels of a computer game that you love… It’s just examples, and again if you do that full time each day, it won’t take so long as you think. You don’t believe me? How about eating the cake every day? It can be the most delicious cake in world but do you think you will want to eat it after a week, two weeks, a month? Just relax, dive deep to your hobby and enjoy that time. I tell you it won’t continue too much long until you get bored.</p><h4>So what’s next?</h4><p>I bet you will start noticing more small details of the world we are living in. Just imagine ordinary Monday when everybody is rushing to their workplace, and you can enjoy your long walk in the park, breath fresh air, listen to the birds, feel the nature and relax. It’s a brilliant feeling which we loose because of a rush every day. Also I think that you will start to care your physical body shape much more, because that is going to happen naturally. While having so much free time and seeing sun shining you instinctively will go outside for training, running, biking, swimming, playing football, basketball, tennis and so on. If compared to the time when you work, usually you leave any sports for the end of the day when you go to some enclosed gym. Natural daylight is getting over or completely finished, you feel less energetic, just more stressed after long day at work. Just imagine what a good feeling is to go outside when you are really in the mood and the weather condition is at it’s best instead of sitting near computer screen in the office until the momentum is lost. Let me ask what impact do you think all these experiences will make on you? I promise it will be the best soul and body healing time of your life. The good news is that when your body and soul is healed your brain will start to work. Your inner creativity will be turned on. When you step out from your daily routine, you will start seeing bigger picture. Finally you will have time to analyze, experiment, educate yourself. That will be a best quality time when you will question yourself about everything: which people do you need keep in your life, connections you need renew, actions you need to take to fix your health, what worthless habits you need to remove and what new useful ones to add. At this time new business, projects ideas will be born. But the best part here is that you can try to implement all your ideas immediately. Not next week, month or year. No more excuses that you are busy, just actions.</p><h3>Strategical pause idea</h3><p>Have I intrigued you with the benefits of strategical pause idea? I hope so. 🙂 So your next question is how to do it? Simple answer would be just do it. But I know that the more comfortable life you live the more complicated it will sound to you. Please understand that here the only thing what separates you from doing it is money. And money is complicated thing. I know that you may have many questions, like how about my all liabilities to my daily job, to my family, even to myself. Simple solution is to save some money or create passive income source (advanced level solution) and than try to make a pause. Basically you will buy time for your money. You will only know if it was worth it if you try to buy it. Remember you can not assert that it is not worth it if you never tried. The secret here is that you don’t need to win a million in the lottery just to try. When you try for the first time you will learn a lot from such situation. Also there is another popular opinion how to reach your goals without loosing money. Some say that when you really really want you can allocate some time after your work with serious time management involved. But I repeat to you, trust me, it’s different because when you make a pause as I recommend, you step out of your comfort zone, feel insecure and than you brain feels the danger, starts to work 110% and that’s where the magic happens.</p><h3>Be brave, be free</h3><p>OK I am happy if you managed to reach this post point. Let’s finish this abstract topic. I hope you found my own life experience of making strategical pauses worth to read. Remember we all humans are intelligent species and we are natural creators, that’s why we are happy when we dream, plan, do, build something what we personally want. That only comes with freedom. So be brave and give yourself even just a short moment of freedom with strategical pause in life. 😉</p><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/life-experience/optimize-life-strategical-pauses/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on January 31, 2018.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25dc2dc5790b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s learn Kotlin by building Android calculator app]]></title>
            <link>https://medium.com/mindorks/learn-kotlin-android-calculator-app-b86b275cc27c?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b86b275cc27c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Tue, 07 Nov 2017 16:08:14 GMT</pubDate>
            <atom:updated>2018-09-11T11:37:31.138Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BA2xZdkX_gvY-cRq13bm1w.jpeg" /></figure><p>One of the biggest news of Android world in 2017 definitely became <a href="https://kotlinlang.org/">Kotlin</a>. This is new programming language from <a href="https://www.jetbrains.com/">JetBrains</a> which has been announced as official Android development language during <a href="https://events.google.com/io">Google I/O</a> 2017 event. So there are no more excuses to make for not learning it. In this post I will share my findings on Kotlin and show you how to build small Android calculator app using this new language.</p><h3>Why should you want to switch to Kotlin?</h3><p>But first lets talk about any questions or doubts that could developer have to start using Kotlin. I won’t lie, I had all these myself, but after some research managed to find all the answers. Main question for me was why the hell do we need Kotlin when we have already reliable and one of the most popular language in the world Java? Answer here is so predictable. We all know that Java is already old language which is not changing a lot and fast enough, so it don’t have modern programming language features compared to other languages. Meanwhile Kotlin is really modern, with it you can write more safer and more functional code which besides being shorter manages to do more than written in Java. It is is designed with the idea to be just a better language than Java. Sounds good? Another question that comes to my mind is if Kotlin is already finished language, can we trust it to use in real life projects? You know sometimes to rush and chase the latest technology is not the best idea while it’s just half-baked. However Kotlin language first appeared on 2011. First stable Kotlin version was released only on 2016, so as you see it was developed for really long time until matured to reliable complete language. Finally I bet you would like to know how easy is to start using Kotlin in your Android projects? After trying myself I was really surprised to find out how many effort is made to have as easy transition from Java as possible. Most amazed I was with the fantastic feature inside <a href="http://developer.android.com/tools">Android Studio</a>, our daily IDE used for Android development work, to convert from Java to Kotlin code automatically. If you are new to Kotlin this will be really helpful during your first steps while you get used to the language. Besides Kotlin is fully interoperable with Java code, which means that you can create mixed projects with both Kotlin and Java files coexisting. So you can start gradual migration from Java to Kotlin with your projects. Also please think about the idea that you can confidently expect best compatibility for Kotlin language with Android Studio and always up to date support. Why? Because Kotlin is designed by JetBrains, company known for creating <a href="https://www.jetbrains.com/idea">IntelliJ IDEA</a>, a powerful IDE for Java development. And Android Studio is based on IntelliJ. Moreover Google announced first-class support for Kotlin on Android, which means all their libraries, frameworks, features should work smoothly with the new language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C2kzPHJgr3zh4kbfk4KUOw.jpeg" /></figure><h3>First Kotlin project — simple calculator app</h3><p>Ok do you recognized my idea of importance to switch from Java to Koltin as soon as possible? Are you already motivated to try Kotlin building real app? For my first experiments with Kotlin I decided to go with the plan of creating simple calculator app. It’s one of my most often used applications whether it would be a personal computer or mobile phone. Actually between all these different platforms that I use, my favorite representation of calculator is on Windows 10. What I like in it that it shows nicely your recent actions and then stores your history.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ul3PEe1pFgwph93zVl2I2A.jpeg" /></figure><p>So I decided to recreate it’s standard version on Android using Kotlin with all these my mentioned features included, which became more challenging than I thought at first time, but after all I reached nice result that I share with you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*O5xMrnhMCJDm17iL.gif" /></figure><p>You can dive to the <a href="https://github.com/baruckis/Android-Calculator"><strong>code directly on GitHub</strong></a> to check it out how it was done.</p><h3>Kotlin differences and advantages over Java</h3><p>Kotlin language comes with many differences and advantages over Java that you will notice. Let’s have a look to some of them that I have faced immediately while working on my calculator app project:</p><ul><li>We don’t use semi-colons at the end of the sentences anymore. This is simple one and the first thing I noticed instantly. 😉 Also it is recommended practice by IDE which warns about that.</li><li>When extending a class or implementing interface, you replace Java’s extends or implements with a colon, and then attach the name of the parent class or interface. Also classes are final by default, and can be extended only if it’s explicitly declared as open or abstract.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/000aa67c6729ecb957d9c1e5a6d70392/href">https://medium.com/media/000aa67c6729ecb957d9c1e5a6d70392/href</a></iframe><ul><li>In Kotlin defining parameters is vice versa to Java. Here first we write the name and then its type.</li><li>Variables defined by two different keywords var which means variable value can be changed and val which means that value cannot be changed. Also compiler is smart enough to recognize type of variable without declaring it as Kotlin is a strongly typed language that supports type inference.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2d9e214702dbcb5217ddb3ccd4d6dd0/href">https://medium.com/media/d2d9e214702dbcb5217ddb3ccd4d6dd0/href</a></iframe><ul><li>Functions are defined using the fun keyword instead of void. Function’s name comes before its type, which is opposite to Java.</li><li>Kotlin is null safe. You decide whether an object can be null or not by using the safe call operator — question mark. By default it cannot. We avoid a lot of defensive code which we used in Java just to check whether something is null before using it just to avoid unexpected NullPointerException.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1f9461d9086c8d30efc2d52e9702458/href">https://medium.com/media/c1f9461d9086c8d30efc2d52e9702458/href</a></iframe><ul><li>Has lambda expressions which allows reducing the amount of code needed to perform some tasks. The common example is adding a click listener to a button with one line instead of multiple lines in Java.</li></ul><pre>button1.setOnClickListener {onNumberButtonClick(ONE)}</pre><ul><li>Newly introduced property modifier lateinit identifies that the property should have a non-nullable value and its assignment will be delayed. This is very handy when we need something else to initialize a property, but we don’t have the required state available in the constructor or no access at that moment.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e762da8dc0577b54730f12e53e34b273/href">https://medium.com/media/e762da8dc0577b54730f12e53e34b273/href</a></iframe><ul><li>Meanwhile also new keyword lazy means that your variable should not be initialized unless you use that variable in your code. Have in mind that it would be initialized only once and after that always the same value used.</li><li>Kotlin has extension functions and properties. This adds new functionality or properties to a class even we don’t have access to modify the source code of that class. So if you ever wished that a class should have a function or a property that was not available, now you are free to create one. This is such a nice feature clearly showing that it is a modern programming language. 🙂</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85b139307efe26d02eabf1a0ab2582b3/href">https://medium.com/media/85b139307efe26d02eabf1a0ab2582b3/href</a></iframe><ul><li>Statement if..else is also as an expression in Kotlin as it has the ability to assign a variable from the returned value of the statement.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9670a0cad31717e135bc95b81937460/href">https://medium.com/media/b9670a0cad31717e135bc95b81937460/href</a></iframe><ul><li>As a replacement for the familiar switch statement Kotlin offers new expression when which has more powerful features and is more concise.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76cbd18005e0e97ce427fdf77addb8f8/href">https://medium.com/media/76cbd18005e0e97ce427fdf77addb8f8/href</a></iframe><ul><li>Kotlin has string templates.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8410825402ebe0354c84ef590e09cb88/href">https://medium.com/media/8410825402ebe0354c84ef590e09cb88/href</a></iframe><ul><li>Kotlin doesn’t have checked exceptions but instead all exceptions are unchecked. That’s the main difference between Kotlin and Java exception mechanisms. Exceptions are not explicitly declared in the function signatures, as they are in Java. If we feel that exception might arise even if it is not enforced by the Kotlin compiler, we should handle it by surrounding the method with with a try...catch block. Useful annotation called @Throws in Kotlin might come in handy when you still want to add the possible exceptions that might be thrown to a method signature.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b45ae902c9d4b41f2c5d98e82679a1b/href">https://medium.com/media/3b45ae902c9d4b41f2c5d98e82679a1b/href</a></iframe><h3>Where to learn</h3><p>Here I pointed out just a few things, but there are so much more new features in Kotlin that makes this language different from Java and really modern one. To find out all of them and to learn Kotlin in general I would like to recommend amazing book which I have read myself — <a href="https://antonioleiva.com/kotlin-android-developers-book">“Kotlin for Android Developers” by Antonio Leiva.</a> If you feel that reading a book is too slow and too boring for you than any online course could be best alternative. You could try one from my favorite provider Pluralsight called <a href="https://www.pluralsight.com/courses/kotlin-fundamentals">“Kotlin Fundamentals” by Kevin Jones.</a> After watching it I found out this to be made really professional with deep language coverage, and also as a great addition to reading a book.</p><h3>My advice</h3><p>I hope you will find this small Android calculator app code useful while exploring various Koltin language projects over internet. But remember that really to learn new language you need to start building something by your own. Happy learning and coding in Kotlin! Don’t forget to share your projects too.</p><h4><a href="https://github.com/baruckis/Android-Calculator">Check out project on GitHub</a></h4><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/android/learn-kotlin-android-calculator-app/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on November 7, 2017.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b86b275cc27c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/learn-kotlin-android-calculator-app-b86b275cc27c">Let’s learn Kotlin by building Android calculator app</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What does it mean to work in startup? Work for equity? My job story at Better Day™ Health]]></title>
            <link>https://medium.com/@baruckis/startup-work-equity-bdh-21a4e253c751?source=rss-b2c384f5891d------2</link>
            <guid isPermaLink="false">https://medium.com/p/21a4e253c751</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[equity]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[corporate]]></category>
            <dc:creator><![CDATA[Andrius Baruckis]]></dc:creator>
            <pubDate>Mon, 23 Oct 2017 21:57:40 GMT</pubDate>
            <atom:updated>2018-09-16T08:42:50.154Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXBYjuZTpP6WjsvCbvMr3w.jpeg" /></figure><p>Have you ever got an offer to work in startup? What’s work at startup like? Offered to work for equity and asked yourself what that actually means? Should you rush to accept that offer as it is so unique opportunity? Or is it just a fool’s gold and sounds too good to be true? With this blog post I want to try to clear your confusion by sharing with you my own story about one longer part of my life which I feel can be interesting for other IT developers to read about and perhaps learn something from my experience. 🙂</p><p>A lot of us after finishing university usually starts searching for a job and joins matured profitable companies where you just do your daily tasks, get fixed salary and try to go up career ladder in time. Sometimes we go for smaller companies sometimes for big international ones, but usually we join a group of people who are already working together, have goals set up, have own team leaders and managers distributed. That exactly was my experience as described, before I was invited to join at that moment young startup company — <a href="http://www.betterdayhealth.com/">Better Day™ Health</a> — my new adventure career wise about which I want to tell you here. But first things first, let me tell you why and how I left everything behind and opened new blank page in my life. For that I created separate story blog post — “<a href="https://www.baruckis.com/life-experience/never-afraid-change-technology/">Never be afraid to change technology</a>“.</p><h3>About the company</h3><p>So what is Better Day™ Health? I would like to give a credit and introduce this promising company as I worked there for more than 4 years and chosen to believe in its idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*C8aBGLdbbcQSP4fjbpuNHQ.jpeg" /></figure><p>Better Day™ Health was founded by <a href="https://www.linkedin.com/in/peteraragusa">Peter Ragusa, MD, MPH</a> and a group of dedicated healthcare &amp; technology professionals from the US &amp; Europe around a single, unifying purpose: to create innovations that drive dramatic improvements in the way medicine is practiced that lower costs, save lives, extend resources and facilitate closer patient-provider relationships.</p><p>Better Day™ is a web-based software platform that uses predictive modeling and 3rd-party applications &amp; devices to turn data into action and, in doing so, actively facilitate patient-provider collaboration in order to proactively manage health, fitness &amp; chronic disease. It is focused on providing a first-of-breed ‘smart’ electronic health record (EHR) platform to facilitate the highest quality of care in a highly-complex healthcare system.</p><p>So to say in short and in simple human words, it’s just innovative company with really modern ideas to drastically improve healthcare software using latest technologies and its trends. Being only Android developer there I worked on creating <a href="https://www.baruckis.com/portfolio/better-day-pro/">Better Day™ Pro app</a>.</p><h3>What it is like to work in startup?</h3><p>Now let’s come back to the main question: so what it is like to work in startup and even get some equity for that? The answer is that actually it is a mixed feeling as it has its own advantages and disadvantages which I want to talk about here in this post. I believe this information could be especially helpful for someone who is trying to decide between startup over corporation, if startup could be the right choice and what to expect.</p><h4>Disadvantages</h4><p>To mess up your mind let’s start with the hard things you can expect to experience when joining any startup. These things I experienced myself when joining this particular organization. Of course hard not necessarily means bad but it’s challenging. Depending on your attitude to life and values that you prefer these things can be counted as disadvantages or just be ignored, acceptable to you.</p><p>Here they are:</p><ol><li>You are suddenly left alone to work almost completely on your own! For startup it is natural to count money and hire as little as possible new people until some progress is made. This means that you can’t get any help from anybody as you alone are responsible for some specific area. All that really professional colleagues who lead you by example and was always around you to help now are gone and you have to solve all the problems just by using your own head and Google of course. 🙂 Are you ready for such challenge?</li><li>You need to learn how to communicate well. You can be the best specialist in your area, but that’s not enough, you need to know how to present your work. By saying present I mean explain it so clearly like you would do for a child. There is no more producers, managers, team leaders or any other middleman between you and your boss. Company CEO usually has only generic knowledge in all areas, so you can’t expect him to understand your technical language and challenges you face every day. And actually it is normal, you need to be less geeky while communicating and understand importance of that. You can even lose your job if don’t learn this advice. Believe me as I saw that happening in my own eyes. 😛</li><li>You need to deliver! Results is the only thing that matters in startup environment. If working in bigger company you could avoid personal responsibility for some time, here you can’t hide.</li><li>You can be asked to use your personal devices, like laptop, monitor, phone, tablet for work. Why? Because it’s just too big investment for startup at first to buy everything you need and they try to save money as they can.</li><li>You lose a lot of perks that big companies offer as competition for IT workforce is so tough these days. Most valuable ones are company contributions to your pension, healthcare insurance, various paid memberships. Also you need to forget about free snacks, drinks, fruits, pizza at work. If your startup company does not decide to rent some brand new co-working space and starts everything in house environment like we did at first than you definitely feel the difference. For us who work in IT area good work conditions an modern environment became so natural that sometimes we do not even evaluate that and accept as a normal thing. What happened to me was that big comfortable office with good quality professional chairs, wide desks, dual monitors’ setup, pool table, wending machines, clean restrooms had been suddenly changed to small dark private apartment with old uncomfortable tables, my personal laptop and mobile phone for development. It was miserable and funny at the same time.</li><li>You are naturally forced to become “jack of all trades” — a person whose expertise spans a significant number of different subject areas. If you are a programmer than expect to be a designer for some time too and computer repair technician if needed, and anybody else based on demand when special work situation arise.</li><li>Personal training? Sorry, but there is no time for this! Never, as there is always rush to deliver to secure new money injection from investors. Forget such things like paid tech conferences. Also don’t expect a lot of training from other team members, not because they don’t want to, but because everybody has special role assigned for building product and not for training somebody. If they are going to do it, it will be just a minimal introduction to avoid wasting their time.</li></ol><h4>Advantages</h4><p>However working in startup has many own advantages too. Let’s try to list them all here:</p><ol><li>Most important one is that you get tons of priceless experience. Just think yourself a minute about it. You do work from day one, you actually build product. You do that through the trials and errors, you constantly challenge yourself every day. It’s like next level. You learn effectively create added value and that is most important to any business. Every future employer will understand how valuable such experience is without much explanation.</li><li>Naturally such experience working in startup is one of the best ways to boost your career as a developer. With challenging tasks and responsibilities assigned you learn a lot new skills fast which makes you better developer. Experienced developers earns more and are always on demand.</li><li>It’s interesting and fun to work in startup. Until now I just emphasized how hard and challenging work in startup is, but with all that it also becomes interesting. No more boring repetitive tasks every days. You are involved in almost all stages of product development, not just in specific ones.</li><li>You all become really close like a family working towards one goal. In startup there are no job titles. You know CEO personally, you can chat with him anytime you want because he is sitting next to you. It’s not some big corporation where you don’t even understand who is responsible for what, or where you never talked with the main boss.</li><li>Freedom. Compared to corporations in startup you get much more flexibility. There is no employees tracking or managing, no strict rules, no need to ask for special permissions. You can dress as you want, go out when you want. You feel that you control your day and you don’t get that prisoner’s feeling. In general people are clever creatures and it’s not natural for them to be controlled by others that’s why freedom feeling is so important. Usually even without a control everybody still does a good job as they feel responsible.</li><li>If startup is going to be successful and to grow, you can confidently expect to get a leading position and much more money easy. Most important people will always be the ones who were the core of the company when it was created.</li><li>You have opportunity to see and experience company’s growth from inside and learn from true innovators. Behind every successful startup there is entrepreneur. Entrepreneurs approach problems differently, are constantly finding solutions and demonstrate original way of thinking. That’s why they are some of the best people to learn from. After working in startup and seeing how it’s done, you can get inspired to start your own adventure.</li><li>Working in startup will give you personal ownership feeling, pride that you created something by your own, you are representing the company and the product. This is difficult to understand, but can become big inspiration for you to do your daily job.</li><li>To avoid loosing best employers during the time and keep them more motivated, it’s very common practice to offer them participation in company’s equity earning program. That can become huge advantage over the time.</li></ol><h3>Work for equity?</h3><p>My mentioned the last one advantage, equity offer, is worth separate discussion as it is tricky one. It is also a reason why I decided to write this blog post in the first place as I got my own life lessons with it. What does it mean? In short, having equity in a company means that you have a stake in the business. From the first look it sounds like a clear winner. Finally you think that you have a chance to earn real money if the company does well. And people are usually optimistic about the companies in which they work. First of all if you have chosen to join particular organization because you already believe in its idea and future success. That’s normal and that’s how it should be. Also a lot of inspiration comes from massive media where you read success stories of various startups every day. However you need to understand that the value of equity is neither certain nor fixed. The difference between the worst case and best case scenarios can be huge. Remember that the huge amount of startups around the world fails constantly and only the best one succeed, but nobody talks about the losers. In order to get some equity you will need to sign a contract to stay in the company for certain time. And time is definitely the most valuable thing you have in life. Even if you done everything correctly by agreement (stayed with the company for set time, worked hard on creating product, respected the confidentiality orders, et cetera) are you sure that you can trust these people when it comes to money. Are they going to pay you without going to the court? Does that contract document which you signed years ago really means something? What if company suddenly becomes not so friendly towards you when you decide to leave and you will have to fight for your equity part? Are you ready for that and you have enough willpower to do it as every fight can be so tiring and time wasting? My goal by modeling these scenarios is not to say that equity offers are worthless, not at all, but what I want to explain you that you shouldn’t overemphasize it when deciding over on getting a new job. It’s a good bonus to have if it’s offered next to your salary, but to go and work only for equity instead of real money is too much risky, and I would not recommend such crazy idea. In my opinion the advantages disadvantages I listed above but not the equity offer should impact your decision to join startup over corporation or not.</p><h3>Sum up</h3><p>To sum up everything I would like to say that I had amazing life and developer experience when joining a startup over the corporation, and if I could rewind back the time I would probably do that again. 🤔 If you never worked in “real” startup (apartment based) definitely try that. You can expect to get motivation boost, learn how to learn new things fast, how to control your time wisely, become responsible and self-confident in doing everything by your own, learn how to lead and teach others instead of expecting to be trained by someone and I could go on.</p><p><strong><em>Ačiū! Thanks for reading! I originally published this post for my personal blog </em></strong><a href="https://www.baruckis.com/life-experience/startup-work-equity-bdh/"><strong><em>www.baruckis.com</em></strong></a><strong><em> on October 23, 2017.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21a4e253c751" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>