<?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 Egbai Smile Mmumene on Medium]]></title>
        <description><![CDATA[Stories by Egbai Smile Mmumene on Medium]]></description>
        <link>https://medium.com/@SmileEgbai?source=rss-6301fd2435b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aQmoK6Leps-fV1HNdLlu-Q.jpeg</url>
            <title>Stories by Egbai Smile Mmumene on Medium</title>
            <link>https://medium.com/@SmileEgbai?source=rss-6301fd2435b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 13 Nov 2026 22:00:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@SmileEgbai/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[Setting up Circle CI for Android (Github repo)]]></title>
            <link>https://medium.com/@SmileEgbai/setting-up-circle-ci-for-android-github-repo-7bade7c93b1d?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bade7c93b1d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 15:22:16 GMT</pubDate>
            <atom:updated>2022-03-19T15:26:22.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*WxmnCTSJm3WLWLNP0oJsPg.png" /><figcaption>Header with Android and Circle CI logo</figcaption></figure><p>I’ve recently started building up CI settings for Android and have tested a few other CI technologies, however Circle CI seems to stand out owing to its simplicity. I’ll walk you through the steps to get this up in your app in no time.</p><h3>Setup</h3><p>To begin, you must register with Circle CI; I chose the github authentication option to make things easier for myself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_g4NsHcaeDGtG4oilnKNcQ.png" /><figcaption>Image showing Circle CI Auth page</figcaption></figure><p>This made it easier to setup my projects as circle ci automatically pulled this info for me.</p><p>After getting access to your new dashboard, select the Android project (of course 😅) you want Circle CI to interact with. (you can skip this since you would still have access to doing this from the dashboard)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_tTjfz9YJrOnv3IjwdvhQ.png" /><figcaption>Image showing Repo setup</figcaption></figure><p>When this step is done, you would most likely see a hello world build already successful. Here is where the fun begins, head over to the projects tab then click the options (3 dots) on your project select configuration file and your main branch you want to set circle ci on. After doing this you should get a nice little dialog showing you some preset templates, just scroll down a little to see the android template and click then you should have a window that shows you the template where you can modify some of the commands if you want, else just click commit and run .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04lu2m7SgF0ydCX17ATzjA.png" /><figcaption>Image showing Circle CI config sample file</figcaption></figure><p>If all goes well with the previous step, you should have something similar to the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtJiLCJWOq_9meQd5eh3Mg.png" /><figcaption>Image showing successful builds</figcaption></figure><p>Now head over to Github, merge your pull request, and voilà you have successfully integrated the CI.</p><h3>WebHook &amp; Triggers</h3><p>Next fun part is creating a trigger for your pull requests to start a build and send a status before every merge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F1btUhxOWUhoBXBIxhNeLw.png" /><figcaption>Image showing webhooks selection page on github</figcaption></figure><p>Here are the steps on how to get this going:</p><ol><li>Go to the settings page of your repo and under “code &amp; automation” select webhooks.</li><li>Click “edit” you would then see various options for triggers, just confirm pull requests is enabled.</li><li>Head over to your circle ci projct and under project settings select advanced and enable “only build for pull requests” <strong>note </strong>all pushes and commits to default branches would still be built regardless of this option.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*afc1ymNxrCKl9XAFIhdQeA.png" /><figcaption>Image showing Trigger screen on Circle CI</figcaption></figure><p>Head over to your project send a new pull request and test out your webhook and Circle CI build flow.</p><p>Thanks for reading and getting this far, that’s all you need to setup a Circle CI workflow.</p><p>For a visual representation, you can check out my video on how to setup Circle CI on Android <a href="https://youtu.be/JtW29fqNPC8">click here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bade7c93b1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android View State Machine Part 2: State data creation and pipeline]]></title>
            <link>https://proandroiddev.com/android-view-state-machine-part-2-state-data-creation-and-pipeline-36f3eccdeb7f?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/36f3eccdeb7f</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[sealed-classes]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Sat, 20 Nov 2021 21:30:26 GMT</pubDate>
            <atom:updated>2021-11-24T20:22:37.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*LkJNs5sqeCAsaICDPgml-w.png" /></figure><blockquote><a href="https://proandroiddev.com/android-view-state-machine-part-1-8cf4599f1338">previously Android View State Machine Part 1</a></blockquote><p>State representation is integral to our software systems/applications, but what’s more important is where this data comes from and the various transformations processes that occur before it gets to the final checkpoint, which could be the user interface or in other scenarios would be back to a data store for retrieval at a future time.</p><blockquote>Something to note the term “state” is used freely here, where we associate the term state being a set of data going to be represented in a view i.e an error state would translate to the user seeing an error screen with texts gotten from the error state object</blockquote><h3>State Marker</h3><p>I have this term I call a <strong><em>State Marker</em></strong><em>, </em>which I describe as an indicator in your data object that is used to compute a state or represents the state itself. Let’s take a closer look at this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZDV1qpQyrcq8YJ4T4GO5GQ.png" /></figure><p>Looking at this sample JSON data, the first represents a user without any transactions, and the second sample has a transaction list. If you had a screen that is supposed to show a list of user transactions, you would have a UI state machine that would either show an empty state when there are no transactions or show a list of user transactions. Now without any mapping, we know the <strong><em>transactions </em></strong>JSON key is our <strong>“State Marker” </strong>for<strong> </strong>this sample JSON.<strong> </strong>This is just a simple representation, and as we probably know there are lots of different ways in which we create State Markers, some representations deal with using things like enum or sealed classes, even boolean flags with specific keys. Now, this is using State Marker from the perspective of returning server data and identifying markers without post-processing.</p><p>In more real-world scenarios, we have state markers that would usually be a mix of different properties, and we would need to have multi-level checks, for available keys either in a server response or an object from an in-device database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff0619cd1bf1696fa49cf42a18ab7400/href">https://medium.com/media/ff0619cd1bf1696fa49cf42a18ab7400/href</a></iframe><p>In these scenarios, we define our states as a combination of different data properties or the absence of certain values, and the processing of such data and the assigning or creation of embedded state data could be seen as a state pipeline.</p><h4>Success and Error States</h4><p>When you request data from a service, you usually expect one of two states a success when you receive a happy path data type or an error (not so happy path), regardless of the path this response is the start of your data pipeline process and would include certain markers for the state within the path flow.</p><blockquote>The returned data path (happy or sad) would determine the type transformations to apply to said data till you get your final state data object.</blockquote><p>Let’s talk about the error state, errors most times seem to always have the most obvious markers and their representation within a state machine to a view is almost always very straightforward. Let’s say you make a request from a mobile device and you get an Exception, Depending on the exception you would then know what error state to transition to.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f04786d623e54b92bfa77c8dbbac2d1/href">https://medium.com/media/4f04786d623e54b92bfa77c8dbbac2d1/href</a></iframe><p>Above we have 2 sub-states from an error we could map to any of them depending on a response i.e we could map to general error for any failures from the server or we map to connectivity for internet-related issues.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de600d3a5455795eb262ff83450a2e3b/href">https://medium.com/media/de600d3a5455795eb262ff83450a2e3b/href</a></iframe><p>A straightforward approach on mapping the errors to an error ViewState, here we use the Throwable/Exception type as a StateMarker so a IOException would lead us to a ConnectivityErrorState while any other Exception would be seen as a GeneralError. These mappings are always application-specific and this is only shown as an example of how error markers can be translated into a StateMachine for a View. Unlike our happy path where we would generally look for markers within the data object such as an enum, boolean, int or a certain combination of string to determine what sort of state the user is in. For example, would incomplete details mean the data belongs to a new user?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef20c8ffb011f7fbf23fa125999f5b07/href">https://medium.com/media/ef20c8ffb011f7fbf23fa125999f5b07/href</a></iframe><h3>State Pipeline Happy Path</h3><p>If we are moving down the happy path where we receive a successful data response from a service typically our next step would be to clean up this data, re-map objects to something that&#39;s easier associated with your views. As a preference, I like to represent my state data using sealed classes and attach the associated data as a parameter, this makes it easier to switch through logic on what state is returned and pull the data out while only accessing specific fields I know are available, in more complex scenarios I prefer to do further processing in the pipeline into stateful widgets, were my sealed class children represent views and after mapping to these widgets, the emitted final object is just attached to a view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe8408c579c102817f8c5d720a778f85/href">https://medium.com/media/fe8408c579c102817f8c5d720a778f85/href</a></iframe><p>Above we have a simple view state, that would represent an empty view and a data view, our expected illustration is to receive data, have an intermediary mapper convert it to one of the listed states, then consume the final object in the view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2cbbbedce6006c272ffebaa01f00605/href">https://medium.com/media/f2cbbbedce6006c272ffebaa01f00605/href</a></iframe><p>Creating a mapper lets us make use of our supposed <strong><em>“State Marker”</em></strong> which in this case is the availability of the transactions list, when the list is empty we return an EmptyView state. In more complex applications, you could have one mapper feeding data into another mapper, till you get to your required data/assumed state, this is done usually because the state markers in those systems arise from the computation or separation of various properties.</p><p><em>Note: Creating mappers as objects, makes it easier to test these mappers, and check output without having to rely on adding lots of initial setups.</em></p><p>Generally, in terms of data mapping, most people would map across system layers, so from <strong><em>data -&gt; domain -&gt; presentation </em></strong>or <strong><em>data -&gt; presentation</em></strong>, and only mapping to a domain when a cache is needed. This is subjective towards the application architecture, as it’s not uncommon to find domain objects being used in the view for presentation. Regardless of what step process is employed, always try to:</p><ol><li>Identify the States in which a view or system could fall and create the necessary representation needed for handling this data.</li><li>Separate state logic in the presentation/view. This just helps to easily follow through the logic of state when coding and thinking of the data flow.</li><li>Don’t return data in objects that will never be used. Like in the above state example our EmptyState, would essentially be a screen with some sort of image/illustration, so our EmptyView object doesn’t need to return user data.</li></ol><blockquote>Our pipeline here sums to a group of mappers, or subprocesses taken on data to identify, assign and then emit or create a Stateful object that may contain associative data.</blockquote><blockquote>In a nutshell…</blockquote><ol><li>The transition between states for data is based on a series of transformations defined by various markers from the data object or set.</li><li>Identifying or conceptualizing a number of finite states (<strong>parent class with sub-classes being the states</strong>)inclusive of the happy-sad path (error &amp; success responses) makes it easy to handle various transitions between states as well the addition of new states is simply adding a set of transformations to map to this new state to its respective view.</li><li>Having a single source for state data emission in your views helps to keep a clean logical representation for the view transitions.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36f3eccdeb7f" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/android-view-state-machine-part-2-state-data-creation-and-pipeline-36f3eccdeb7f">Android View State Machine Part 2: State data creation and pipeline</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android View State Machine Part 1]]></title>
            <link>https://proandroiddev.com/android-view-state-machine-part-1-8cf4599f1338?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cf4599f1338</guid>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Wed, 29 Jul 2020 09:32:46 GMT</pubDate>
            <atom:updated>2021-11-23T10:24:23.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ptcul-99C6pKG-HyvN8rEg.jpeg" /></figure><p>In software development one of the most prevalent things is state management or simply put, knowing <strong>what to do and when to do it</strong>. The main focus of this series would be the <strong>presentational layer</strong> of an <strong>app</strong> and devise modelling of received data into a state object and interpretation at the view i.e managing the view in correspondence to emitted state.</p><p>Every user interaction event triggers a process, this could be an HTTP request, a CRUD operation, a scroll action, or simply launching a new activity. It’s very important to note that each process can lead to a new state.</p><blockquote>A state is the set of values of all variable aspects of the particular system under concern at an instant in time. i.e the remembered information is called the <strong>state</strong> of the system. “<a href="https://www.quora.com/profile/Stephen-Kurtzman-1"><strong>Stephen Kurtzman</strong></a><strong> PhD</strong>”</blockquote><blockquote>A finite state machine is an <a href="https://en.wikipedia.org/wiki/Abstract_machine">abstract machine</a> that can be in exactly one of a finite number of <a href="https://en.wikipedia.org/wiki/State_(computer_science)"><em>states</em></a> at any given time. “Wikipedia”</blockquote><p>It’s safe to say, that when building screens in our apps, whether we choose to define finite states for these screens or not they already exist and how we access them or group such state-based data is important to both the sanity of the app and that of other developers involved, as well as guarding against irregular transitions or leaks in state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*F3scS5Y71YivaHRpue6XCg.jpeg" /><figcaption>a typical state transition from app start to loaded screen or error screen</figcaption></figure><p>The above diagram shows a typical applications state lifecycle or as we like to call it a “flow”. Each state represents either the presence of a certain type of data or the absence of it, and we would have associative views to show the user the current state of the app, which could be a progress bar for the loading state, an error message/screen for error state or a scrollable list for depicting a successful data load. Representing this data in our code in concise and clear fashion is important as it helps us to successfully separate and group operations particular to each state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10282d2efd84f80397356049719d4940/href">https://medium.com/media/10282d2efd84f80397356049719d4940/href</a></iframe><p>The snippet above represents a general state overview of what our diagram tries to represent. Defining a class to represent finite states in our Views is important because this helps us group operations to perform on emittance of a particular object ViewState, rather than checking across wide form factors of data variables and have a “guess” as to what state the application is in.</p><p>After creating our Abstract state model, in our fragments or activities, we would have a resolver (usually a<strong> </strong><strong>when </strong>or a<strong> </strong><strong>switch case</strong> statement) that would match functions or grouped procedures to each emitted state. In other instances the states would be mapped to a Viewholder or widget and we would emit a StatefulViewObject and when resolving in the View we would just inflate the view object, we would take a look at this in the <strong>next part </strong>of this series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*U6eVgAjbZVgln--kRzaWTg.png" /></figure><p>Let’s see how we would put this above illustration into practice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1f18d868be2c5dd5003a8a6fc54823a/href">https://medium.com/media/c1f18d868be2c5dd5003a8a6fc54823a/href</a></iframe><p>In the above sample, we have a method that loads a list of data characters the CharacterToUIMapper() is responsible for mapping the received object into the supposed ViewState for emission to the view. The function CharacterToUIMapper() would check the response gotten from the loadCharactersUseCase() and then push the relevant ViewState object into the liveData .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fd7d302df606471110b0d0888ae4654/href">https://medium.com/media/0fd7d302df606471110b0d0888ae4654/href</a></iframe><p>Subsequently after emitting our ViewState object, we would receive it in the view, and depending on the object the appropriate function would then populate the associated view.</p><blockquote>Finally…</blockquote><p>Managing states and view hierarchies are one of the things we find ourselves consistently doing in android app development, it’s better we define bounds and set rules to our views and what state would be associated with them. This not only makes debugging problems easier but also makes adding extra view logic/state a run in the park. Whether we choose to explicitly define our states, it doesn’t stop the states from being present.</p><p><a href="https://medium.com/@SmileEgbai/android-view-state-machine-part-2-state-data-creation-and-pipeline-36f3eccdeb7f">Android View State Machine part 2: State Creation &amp; Pipeline</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cf4599f1338" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/android-view-state-machine-part-1-8cf4599f1338">Android View State Machine Part 1</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 1% climb from procrastination]]></title>
            <link>https://medium.com/@SmileEgbai/the-1-climb-from-procrastination-63ed8050ba42?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/63ed8050ba42</guid>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[procrastination]]></category>
            <category><![CDATA[lifestyle]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[growth]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Thu, 16 Apr 2020 20:04:53 GMT</pubDate>
            <atom:updated>2020-04-16T20:10:02.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ir7vLBZhm8redtRzPm4iFw.png" /></figure><p>One thing about growth and learning is it takes a lot of effort to learn something new, we wake up with great ideas about things we want to be in life, things we would love to do but when the time comes to sit down and do the work, we easily find excuses to put it off. Most people would call this procrastination, but it most likely is a fear of success(Achievemephobia).</p><p>Now we can define success like many things :</p><ol><li>We could say success is the completion of that which was aspired for</li><li>A feeling of self-fulfillment and peace.</li><li>Gratification in one’s life or career</li></ol><p>So why then would we say someone is afraid of success when it is what we all want from life, or what most people want out of life I mean if we work hard every day what else would be the justification if not to achieve this?</p><p>Let’s retrospect a bit here, we have spoken about success so how can we then be afraid of it?</p><blockquote><strong>Procrastination</strong> is the <strong>fear of success</strong>. People <strong>procrastinate</strong> because they are <strong>afraid</strong> of the <strong>success</strong> that they know will result if they move ahead now — <strong><em>Denis Waitley</em></strong></blockquote><p>How can I be afraid of what I want? to be honest, fear of success is not about being afraid of what we want, it stems as being afraid of our inability to handle the state of success, the responsibilities that come of it.</p><blockquote><strong><em>Because success is heavy, carries responsibility with it, it is much easier to procrastinate and live on the “someday I’ll” philosophy”.</em></strong> — <strong><em>Denis Waitley</em></strong></blockquote><p>A human mind is a wonderful machine that lets us create glimpses of how our life could be by carefully grafted mind movies, imaginations or as some might say daydreaming. These dreams are what later on become desire turned passion and fuel our motivation to work, learn and build to achieve our goals and thereby achieving success but there’s a catch.</p><p>These same daydreams can as well end up putting pressure on us when our growth is slow and we see others moving to the levels we are only attaining in our mind’s eye, we get to a point where it’s easier to put off our tasks than to work on something that is no longer giving us that satisfaction of getting close to our dream. We become more comfortable living in our minds with the comfort of saying <strong>“someday I will have this”</strong> without actually putting any more effort.</p><p>The fear of success most times manifests as a feeling of not having enough skills to pull through our goals, we feel as though we only came this far because we were lucky or we had to work super hard, most times that’s not the case, this kind of manifestation leads people to not try to grasp their goals or aim too high, this fear keeps people working jobs they are not happy with simply because they think they don’t have the skills or brains to get or be somewhere better.</p><p>In mainstream media, this manifestation is known as imposter syndrome, where the individual no matter what has been achieved will always feel they have fewer skills or knowledge than they do.</p><p>Outlining and defining a section of the problems we may experience leads us to the 1%. Now the 1% is simply a method to help stave off procrastination and the subtle fear of us not being able to achieve our dreams which might be on top of a mountain of things to do.</p><blockquote>Little bites of a cake will result in a finished cake</blockquote><p>The 1% is doing the littlest or smallest possible task, within our goal or set of task, most times looking at a huge pile of work can create a sense of fearful apprehension to the point where we let go and do nothing, but when it seems small it’s easier to get it done, and we still get to feel good about it.</p><p>Every time we do 1% of the work required we get closer to our personal goals, it’s better to do a tiny piece of work or self-improvement than doing nothing at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IIbtwTl3WHACSA8gmmRGBg.gif" /></figure><p>How do we start?</p><ol><li>Make a high-level list or write down what you want or what you aim to achieve</li><li>Create another list that would serve as a breakdown, all the steps that need to be taken to achieve this <strong>(<em>if this is difficult or you find your self skipping it, you can add one item of the break down per day or 3 hours)</em></strong></li><li>Now every time you take a task if it gives you that feeling of maybe I should do it later, then start thinking about the smallest piece of work you can do with that task and quickly do it, then set out what’s left. Now the piece of work you successfully did is your <strong>1%.</strong></li></ol><p>Doing your 1% every day might not seem like much, but after a month looking back, you would have something to smile about instead of pushing it forward and looking back and have nothing to show.</p><p>Also, something very important to note, planning for your next day before you sleep, helps your brain prepare you mentally for the stress of the next day, this greatly reduces your chances of procrastinating towards tasks set out for the day.</p><p>Keeping a list of important things you need to get done for the day is super important even if it would include mundane things like laundry, dishes. Create these lists before going to bed or at least mentally make this list, every time you tick of an item the next day, you feel better than you did something of your day and finished what you planned for that day, I mean we still need our little wins.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63ed8050ba42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlinx Serialization]]></title>
            <link>https://proandroiddev.com/kotlinx-serialization-83815cc1c57b?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/83815cc1c57b</guid>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 16:18:04 GMT</pubDate>
            <atom:updated>2019-01-12T13:12:19.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*CN7xh5ADjqoH3bUa6k7tgw.png" /></figure><p>After working on a multiplatform library which builds a .framework and .aar artifact, I came to the realisation that there are a lot of nifty things which are included for us in kotlin that most of us never really knew about.</p><p>One thing about working on a multiplatform project is you have to be careful about the libraries you use, and it is best to stick closely to what is offered by the kotlin team. So when I had a situation where I needed to serialize JSON which should supposedly be for the both platforms(android &amp; ios) I had a problem on compiling my code for ios. That’s when I did a bit of digging around and found out about the <strong>Kotlinx Serialization library</strong>. To be frank I never knew about it, so this post is basically for people like me who didn’t know of it’s existence.</p><blockquote>First of according to the <a href="https://github.com/Kotlin/kotlinx.serialization">kotlinx.serialization repo</a>, this is a compiler plugin which produces visitor code for classes and has a runtime library which uses generated code to serialize objects without reflection.</blockquote><p>The fact that this does not use reflection is a big plus in app performance, to learn more about reflection overhead you can checkout <a href="https://blog.frankel.ch/performance-cost-of-reflection/">this excerpt</a>.</p><p>Setting up your project to use the plugin is quiet simple, but I will include a complete setup for both android projects as well as multiplatform projects. But feel free to check out the <a href="https://github.com/Kotlin/kotlinx.serialization">Kotlinx.Serializer repo</a> for instructions on this and more.</p><p>One small hiccup on the multiplatform serialisation setup is the need to add this dependency under the native dependecy section of your gradle script.</p><pre>implementation org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.9.1</pre><p><strong>SETUP GRADLE EXAMPLE</strong></p><p>For multiplatform:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98c84b4de3f0c2204e676f00ef27118f/href">https://medium.com/media/98c84b4de3f0c2204e676f00ef27118f/href</a></iframe><p>For Android:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ad71e56cfd31ea745701e70000fb375/href">https://medium.com/media/8ad71e56cfd31ea745701e70000fb375/href</a></iframe><p><strong>Serialization</strong></p><p>Serializing is done quite easily, for one you would need to annotate the intended class with the @Serializable annotation as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59a66c401090eb94782f25a4c53430b8/href">https://medium.com/media/59a66c401090eb94782f25a4c53430b8/href</a></iframe><p><strong>Note</strong>: This can as well work with data classes.</p><p>Now to actually use this in action let’s take an example of how to convert a JSON to object and back</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f8ca77718f8c6d67f4c9347a62e5c5f/href">https://medium.com/media/1f8ca77718f8c6d67f4c9347a62e5c5f/href</a></iframe><p>The ease and simplicity which the kotlinx serializer helps us to convert objects in a clean way is absolutely amazing.</p><p>Two more annotations to note are transient and optional. Using transient will have the serializer ignore that field and using optional will allow the serializer not to break if a field is missing, but at the same time a default value will need to be provided.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff8b8a723c744a9fa95805653a60cd68/href">https://medium.com/media/ff8b8a723c744a9fa95805653a60cd68/href</a></iframe><h3><strong>Android Use Case for Retrofit</strong></h3><p>For those who would like to as well use this library in android, Retrofit 2 has an adapter for converting JSON responses to objects. The adapter can be found <a href="https://github.com/JakeWharton/retrofit2-kotlinx-serialization-converter">here</a>. Some Sample code of adding the adapter</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/532db07c81097863aa30a304b750b502/href">https://medium.com/media/532db07c81097863aa30a304b750b502/href</a></iframe><p>Assuming your class already has the required annotations, after making a request this should serialise your class into the required object.</p><p>All in all, the kotlin serializer is a wonderful addition to any project and makes serialization a painless process when you want to save objects as a string or parse them into other data structures. Here is a sample repo for the android setup with a small(non-architectural) working example:</p><p><a href="https://github.com/smilecs/kotlinxRetrofit">smilecs/kotlinxRetrofit</a></p><p>Here is the official Serializer repo and as well the retrofit adapter</p><ul><li><a href="https://github.com/Kotlin/kotlinx.serialization">GitHub - Kotlin/kotlinx.serialization: Kotlin multiplatform / multi-format serialization</a></li><li><a href="https://github.com/JakeWharton/retrofit2-kotlinx-serialization-converter">JakeWharton/retrofit2-kotlinx-serialization-converter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83815cc1c57b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/kotlinx-serialization-83815cc1c57b">Kotlinx Serialization</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concise Error Handling with LiveData and Retrofit]]></title>
            <link>https://proandroiddev.com/concise-error-handling-with-livedata-and-retrofit-15937ceb555b?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/15937ceb555b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[livedata]]></category>
            <category><![CDATA[retrofit]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Thu, 12 Apr 2018 21:07:54 GMT</pubDate>
            <atom:updated>2018-07-13T12:11:01.019Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZc7MuxIieLNgiXhtW0ajg.jpeg" /></figure><p>While working with Architecture components, I noticed the great ease of getting a response from my repository(API) whenever data is available, but this breath of fresh air also brought about a bit of pollution.</p><p>Now for which ever architecture design be it MVVM or MVP, we usually would want our view to interact with the repository through the ViewModel so as deliver latest updates if something(configuration change) where to happen to our activity. The problem I noticed was I was having to do almost the same number of checks every time I received a response from the server. These checks include:</p><ol><li>If response.body() is not null.</li><li>If no exception is thrown on the onFailure() method.</li><li>Having to do checks on my view if an exception was thrown so I handle it else I display my data.</li></ol><p>Now if you come to think of it, these problems where already existing even before the conception of Architecture Components, but they just became more obvious I think. Also when I receive an update to my observer on the onChangeListener I ended up having to do so many checks within that listener or before I set the value to my live data, which still kept a hole on how do I retrieve my errors so I can give the user feedback on the view.</p><p>So I thought of abstracting the whole process from the network requests callbacks to even my data models to use a wrapper then also modified my Observer so it could return custom exceptions which I could use to notify the user of errors on their request.</p><blockquote>Now note these are only done for long running network processes and probably this might not be the best approach for some other use cases.</blockquote><h3><strong>API Concerns</strong></h3><p>So first of all I thought of simplifying my retrofit callback method by implementing the Callback&lt;T&gt; interface and providing my own implementation which would handle the error checks and make sure it only delivered actual processed data. To do that we need to first write a ApiCallback.java class which implements the retrofit Callback&lt;T&gt; class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d6a123cf0f6f17844224c5ed4c42d9a/href">https://medium.com/media/6d6a123cf0f6f17844224c5ed4c42d9a/href</a></iframe><p>So this class handles error cases, success and exceptions then delivers a result depending on what method is executed. So invariably this reduces some “if checks” we would always have to repeat. Next we apply this class to our retrofit call. Note to make the error handling seem less I created a special model which I would use with my LiveData instance, this model has only two properties which are a Generic data type and an Exception.</p><pre>public class DataWrapper&lt;T&gt; {<br>    private Exception <em>apiException</em>;<br>    private T <em>data</em>;<br>}</pre><p>For brevity I used the <a href="https://blog.chizobaogbonna.me/getting-rid-of-boilerplate-code-with-lombok-android-95e03a281b34">lombok plugin</a> which auto generates a getter and setter kind of like Kotlin. This above method is used as a wrapper for all my objects that will be observed for a change regarding api calls and feedback.</p><p>Now that we have our DataWrapper, let’s go on ahead and create a GenericRequestHandler to take care of logic which will be commonly used for api calls.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba8e2b100e20921ca832a3e0c2793dc6/href">https://medium.com/media/ba8e2b100e20921ca832a3e0c2793dc6/href</a></iframe><p>After creating this class, all we need to do is extend the class provide an implementation of the makeRequest() method, then call doRequest() which would return a LiveData of the Generic type passed into the class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48dbf62fe28772005efc7b5cae4bd1de/href">https://medium.com/media/48dbf62fe28772005efc7b5cae4bd1de/href</a></iframe><p>So now I extend my GenericRequestHandler and override makeRequest() to .return a retrofit Call, then the AuthRequest() method calls and returns a LiveData object gotten from the inherited doRequest() method.</p><p>Now we can see how abstracting our request logic gives us a cleaner code base, and keeps us from repeating the same things over again especially when it comes to error handling.</p><h3><strong>View Concerns</strong></h3><p>Now to make life easier for myself yet again I created a custom Observer which returns an exception or a success.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffce8330d276b78769bfbd8de1b704ad/href">https://medium.com/media/ffce8330d276b78769bfbd8de1b704ad/href</a></iframe><p>Now after defining our ApiObserver we can go ahead and put the pieces together in our view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27e1d39a430e9e9f00e2526c85cccbf8/href">https://medium.com/media/27e1d39a430e9e9f00e2526c85cccbf8/href</a></iframe><p>Now it may seem like a lot of code to write at first but the benefits accrue over time where you don’t have to repeat your self with mindless if checks and exception/error handling both from the retrofit calls all the way to displaying an error in the view.</p><p>Error handling is an important process in app development especially when it comes to api calls, but when you keep repeating multiple checks it can get tiring and most times we end up leaving important checks out.</p><p>Also as a jumper starter you can checkout <a href="https://github.com/smilecs/ketro">this library</a> I wrote that helps with error handling and returning LiveData together with exception propagation to the view as described in this post.</p><p>Thanks for reading do well to leave your comments on any questions you might have.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15937ceb555b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/concise-error-handling-with-livedata-and-retrofit-15937ceb555b">Concise Error Handling with LiveData and Retrofit</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Realm with Kotlin and LiveData]]></title>
            <link>https://proandroiddev.com/the-realm-of-kotlin-and-live-data-using-mvp-architecture-f04fc41c914e?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f04fc41c914e</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[livedata]]></category>
            <category><![CDATA[realm]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Tue, 06 Feb 2018 14:38:40 GMT</pubDate>
            <atom:updated>2019-01-28T08:05:15.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*C_ugKN7wNie6GDqXdlwjCA.png" /></figure><p>Some time back, I started working on an eccommerce app called shop440, so as usual the first choice is to define the architecture and I decided to go for MVP(Model View Presenter). I chose this architecture solely because it would allow me add new features without worrying about breaking existing code and changing the view just meant having to re-implement my interfaces and everything works as good out of the box. I chose to use Realm because of it’s reactive nature and pairing that up with LiveData gave me a true feedback centric app design, where I not only get notified when a retrieval from my db is completed but also when an insert operation is done. Also using Kotlin and experimenting with extension functions as a wrapper for RealmDb &amp; LiveData seemed like a nice idea as well.</p><p>First off here’s an excerpt from their <a href="https://realm.io/products/realm-database">official site</a> about Realm:</p><blockquote>Realm Database is an alternative to SQLite and Core Data. Thanks to its zero-copy design, Realm Database is much faster than an ORM, and often faster than raw SQLite.</blockquote><p>Firstly you need to setup your project to use Realm and LiveData I won’t be going into this with this post. But you these links to get detailed information on how to setup your <a href="https://realm.io/blog/android-installation-change/">RealmDb</a> and <a href="https://developer.android.com/topic/libraries/architecture/adding-components.html">Live Data</a>. After installing realm you need to initialise it in your application file(if not already available, create a class and extend Application) then do <strong>Realm.init(this).</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00d1f49175f35504c789b28a39e205e1/href">https://medium.com/media/00d1f49175f35504c789b28a39e205e1/href</a></iframe><p>For me, one of the best defining features of Realm db is the fact that I can store my objects as is. So lets not go out of scope of our e-commerce “add to cart functionality”. First off we define our model that will be stored locally every time a user add’s an item to cart.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09f7fb4323636542c6f03444229f702d/href">https://medium.com/media/09f7fb4323636542c6f03444229f702d/href</a></iframe><p>Now as you noticed this is a standard kotlin class with a few exceptions:</p><ol><li>We had to declare the class as <strong>open</strong> because <a href="https://discuss.kotlinlang.org/t/classes-final-by-default/166">kotlin by default declares all classes as final</a>, of which realm needs the classes to be public so it can inherit from it.</li><li>We are using a secondary constructor so realm will be able to create a default instance of this class without values.</li></ol><p>If you noticed we are extending the <strong>RealmObject(), </strong>what this means is the class is managed by Realm and all write operations on the object after creation are persisted to the database.</p><p>Like I said earlier we will be using an MVP architectural pattern, so in the current project we have this file structure for the product section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*zx_U0hkEb18oHUSy-uUVRg.png" /></figure><p>Don’t worry this file structure is not compulsory, it’s just easier to understand in an MVP perspective this is where we start getting technical. So our desired interaction is the user comes into the selects a product and wants to make a purchase or add to their shopping cart. They click a button saying add to cart, now the desired interaction on button click is for us to push the item into the database then update the UI with the changes, simple right?</p><p>For our Realm objects to work with LiveData we need to create a wrapper for our realm instance which would expose LiveData properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53a003901b3f564e78556e5c9947338f/href">https://medium.com/media/53a003901b3f564e78556e5c9947338f/href</a></iframe><p>Now a distinct feature about Realm db is the fact that it was built to be reactive, so what we would normally do is to add ChangeListeners for every realm query so we could update our UI when the query is resolved. But with our LiveData wrapper all we need to do is to add a single ChangeListener to the current realm instance being used by the ViewModel (we’ll get into this shortly) then set the data to the LiveData instance so all components observing it will be notified and update themselves.</p><p>If you have gone through the android developer site on the architectural components you would be familiar with the <a href="https://developer.android.com/topic/libraries/architecture/viewmodel.html">ViewModel</a>, a brief primer: The ViewModel manages and stores UI related data in a lifecycle conscious way. So we can safely update our UI’s without fear of the view being destroyed or no longer available when dealing with asynchronous processes, which is what you might experience when using the realm change listener and an operation returning after the view is no longer available in most cases this could be a source of memory leaks when the listener has a strong reference to the holding activity.</p><p>Before we proceed, with our structure we need to create a way to return our realm queries as LiveData() . Now when you run a query on Realm it returns either a RealmResults&lt;T&gt;() or E , what we need to do is convert those objects returned into a LiveData() object. Remember the wrapper we wrote? well we are going to use that but with a little bit of kotlin magic. So we are going to create an extension function off of a RealmResults&lt;T&gt;() object. Now if your not familiar with <a href="https://kotlinlang.org/docs/reference/extensions.html">kotlin extensions check this link</a>.</p><p>Create a class probably call it RealmDao, and add the snippet below. Note you don’t need to declare an opening class block, in reality these extension functions are similar to static methods but they are built of the calling object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cab4c49b8df7586980b6ff99bced1438/href">https://medium.com/media/cab4c49b8df7586980b6ff99bced1438/href</a></iframe><p>Now that being done we can create our KartDao (or CartDao but since it’s kotlin i’ll go with the “k”). So our KartDao is going to house all our realm queries which will be made via our ViewModel. For simplicity lets just do one query for now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15402c5f7ca907235e7682c18052a4d4/href">https://medium.com/media/15402c5f7ca907235e7682c18052a4d4/href</a></iframe><p>The above method makes a realm query to get all items in the cart and converts the result to LiveData using the extension function we created earlier. If you look closely you’ll see this query is asynchronous so anytime it returns it executes the ChangeListener then sets the value to LiveData which notifies all observers to update. If this seems a bit confusing take a step back and go over the extension function and look at how the ChangeListener is triggered.</p><p>Now we need to make our KartDao class an extension of the realm object so anytime we have an instance of the realm object we can easily access the db queries in the KartDao class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a278d788a674656d269823a7596ece89/href">https://medium.com/media/a278d788a674656d269823a7596ece89/href</a></iframe><p>For the KartDao for operation on the realm:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd7eca8e5b2d6d398615e8e201f5b49/href">https://medium.com/media/afd7eca8e5b2d6d398615e8e201f5b49/href</a></iframe><p>So our RealmDao class will look like the above. It’s not really a must to make our KartDao class an extension, but if it makes it easier it doesn’t hurt.</p><p>Now for our ViewModel which is practically the glue, take note we haven’t created our ViewContract which serves as an interface between the view and the presenter in terms of an MVP architecture, but we’ll get into that shortly. For simplicity it’s advised that all database operations including the realm wrapper and extension function to be place in a single package called dao, and each ViewModel depending on their use cases should be place in the activities respective package.</p><p>Now for our process I have a kart package which contains my ViewModel and the presenter/view contract for the activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*R9OAzh-6X8uRDKgILkOwSQ.png" /></figure><p>Like I said earlier the ViewModel will manage it’s own instance of Realm so when the activity/fragment(lifecycle owner) is no longer available it will release it’s hold on the instance of that realm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15402c5f7ca907235e7682c18052a4d4/href">https://medium.com/media/15402c5f7ca907235e7682c18052a4d4/href</a></iframe><p>Another thing you need to take note of is adding the open keyword to the class because when creating an instance of this class an abstraction is created which tries to inherit from it, and kotlin classes being final by default will cause this process to fail. Our getKartData() method returns a LiveData object which will be observed by our presenter and when changes occur the presenter will alert our view and return data to it so our view can update its UI.</p><p>For our presenter we first define our Contract class which our fragment and presenter will implement. The contract serves as a basis of communication between the presenter and the view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/078beef2914e888a5645c924299ad664/href">https://medium.com/media/078beef2914e888a5645c924299ad664/href</a></iframe><p>Now our Contract is created lets make our presenter and implement the specified behaviour.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b93a5e019d4272c3e25a530c29b6359/href">https://medium.com/media/6b93a5e019d4272c3e25a530c29b6359/href</a></iframe><p>If you look at the top part of the file we use a method from the view which returns an instance of the ViewModel for us that lets us make requests to our DAO.</p><p>Now lets look at our fragment(View) and see how this all fits into one place. I’ll break this into multiple parts so we can have context on all the moving parts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d10338e076cff849edcd13964932e0c/href">https://medium.com/media/1d10338e076cff849edcd13964932e0c/href</a></iframe><p>The first part of the fragment has us implementing our KontractView, initialising our presenter and also creating our ViewModel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d10338e076cff849edcd13964932e0c/href">https://medium.com/media/1d10338e076cff849edcd13964932e0c/href</a></iframe><p>This part overrides the onKartLoaded() interface which is called by the presenter when the LiveData observer returns data.</p><p>As per our implementation you can see that the ViewModel is created in the view(activity/fragment), the presenter holds an instance to the ViewModel returned by the view and uses that to make requests to our dao repository.</p><p>That’s a brief primer on using realm with mvp implemented with kotlin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f04fc41c914e" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/the-realm-of-kotlin-and-live-data-using-mvp-architecture-f04fc41c914e">Using Realm with Kotlin and LiveData</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Localisations with Mobile country code]]></title>
            <link>https://medium.com/android-news/android-localisations-with-mobile-country-code-1c1596857d5?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c1596857d5</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[localization]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Thu, 25 Jan 2018 11:11:19 GMT</pubDate>
            <atom:updated>2019-05-27T17:28:44.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*ZzzdFGVDf761eqs_3F_tFw.png" /></figure><p>When doing localisations for apps we have a couple of options which include</p><ol><li>Screen size</li><li>Language</li><li>Mobile Country Code</li></ol><p>The most common one’s ever used are Screen size(dp/sw) &amp; Language(en,fr, etc), while Mobile Country Code can be a very efficient way to select resources based on what country the user is in. This allows you to tailor features to your users countries. Here’s a <a href="https://developer.android.com/guide/topics/resources/providing-resources.html">link</a> to the android resource on localisation, there specifies a table which shows how resources are selected based on precedence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07avIXeSo4Fevm7zdCxU2g.png" /></figure><p>According to the table above you can see that android takes the MCC(Mobile country code) &amp; MNC(Mobile network code) into consideration first in resource selection before it takes other parameters into consideration.</p><p>Now you may be asking why you should consider using mcc or mnc when you can already use screen density pixels(dp) and region to define resources. Well using the mcc code allows you to target a particular resource or even feature(build flavours) by country since a countries mcc is unique to it. For me this just helps me with an easier way to segregate my resources and image drawables, incase am using an image that might be offensive in a particular country or I need to display various currency symbols, the possibilities are endless. Combining mcc and resource <a href="https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources">alias</a> is a very beautiful way of segmenting your ui resources.</p><p>If for any reason you need to access the current mcc of a country you can easily do so using the TelephonyManager</p><pre>TelephonyManager telephonyManager <strong>=</strong> <strong>(</strong>TelephonyManager<strong>)</strong> App<strong>.</strong>getInstance<strong>().</strong>getSystemService<strong>(</strong>Context<strong>.</strong>TELEPHONY_SERVICE<strong>); </strong>//gets the country mcc code                                    String countryISO <strong>=</strong> telephonyManager<strong>.</strong>getNetworkCountryIso();</pre><pre>/*gets the mcc appended with the mnc. Note that mcc is always the first 3 digits returned with this method so to get the mnc you can just split the String or get the chars from the 3rd index to the last.*/</pre><pre>String countryMnc = telephonyManager.<a href="https://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkOperator()">getNetworkOperator</a>(); </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c1596857d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/android-localisations-with-mobile-country-code-1c1596857d5">Android Localisations with Mobile country code</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Views: make your android app stand out]]></title>
            <link>https://medium.com/android-news/custom-views-make-your-android-app-stand-out-fa386b506860?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa386b506860</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[custom-views]]></category>
            <category><![CDATA[android-sdk]]></category>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Thu, 14 Sep 2017 17:09:01 GMT</pubDate>
            <atom:updated>2017-10-30T13:48:30.422Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDUgwFsE_dcE66s9BizSgw.jpeg" /></figure><p>CustomViews are always seen like a tailed beast, especially when you check the developer site on how you can create your custom view widgets, you see a lot of things that don’t really do what your looking for. Most of the tutorials on the developer site for creating custom views rely on you drawing your own layout which can be quiet confusing and difficult especially when you think of how to get a reference to the objects you draw. Here is an easier way to quickly get you through a custom view and still satisfy your ui concern.</p><p>One thing you need to know about creating a custom view is the FrameLayout is your friend. This ViewGroup isn’t commonly used by many developers especially since its hard to understand its role in the view heir achy well for one FrameLayout is one of the most convenient views to extend and start hacking away your custom widget. Below is an example of what we are trying to achieve.</p><p><a href="https://youtu.be/PqYy0TG9_QY">https://youtu.be/PqYy0TG9_QY</a></p><p>STEP 1:</p><p>Create a new java file lets name it “Custom.java”, extend the FrameLayout and override the necessary constructors.</p><pre>public class RevealView extends FrameLayout{<br> protected boolean toggle;<br> protected Drawable lessArrow =    getResources().getDrawable(R.drawable.<em>ic_expand_less</em>);<br> protected Drawable moreArrow =  getResources().getDrawable(R.drawable.<em>ic_expand_more_white</em>);<br> private FontTextView topBarText, bottomBarText;<br> protected View topBar;<br> protected ViewGroup bottomBar;<br> protected ImageView toggleBottom;</pre><pre>    public RevealView(@NonNull Context context) {<br>        super(context);<br>    }<br><br>    public RevealView(@NonNull Context context, @Nullable AttributeSet attrs) {<br>        super(context, attrs);<br>    }<br><br>    public RevealView(@NonNull Context context, @Nullable      AttributeSet attrs, @AttrRes int defStyleAttr) {<br>        super(context, attrs, defStyleAttr);<br>    }<br>}</pre><p>STEP 2:</p><p>Lets create our xml layout file, this is where all the construction will take place. So for this tutorial we will create an Accordion which reveals extra content on touch. So head over to the res folder and create our custom.xml layout file. Now before you add the xml code you need to download and add two icons to your drawable folder, 1. an arrow <a href="https://storage.googleapis.com/material-icons/external-assets/v4/icons/zip/ic_keyboard_arrow_up_black_24dp.zip">facing up</a> and 2. the other <a href="https://storage.googleapis.com/material-icons/external-assets/v4/icons/zip/ic_keyboard_arrow_down_black_24dp.zip">facing down</a>. You can get them from the google material design icon pack</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>              xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>              android:orientation=&quot;vertical&quot;<br>              android:layout_width=&quot;match_parent&quot;<br>              android:layout_height=&quot;wrap_content&quot;&gt;<br>    &lt;RelativeLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:background=&quot;@android:color/holo_blue_dark&quot;<br>        android:id=&quot;@+id/topBar&quot;<br>        android:paddingTop=&quot;8dp&quot;<br>        android:paddingBottom=&quot;8dp&quot;<br>        android:orientation=&quot;horizontal&quot;&gt;<br>    &lt;TextView<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:id=&quot;@+id/top_bar_title&quot;<br>        android:layout_marginLeft=&quot;12dp&quot;<br>        android:textSize=&quot;16sp&quot;<br>        android:textColor=&quot;@android:color/white&quot;<br>        android:layout_centerVertical=&quot;true&quot;<br>        /&gt;<br>        &lt;ImageView<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:id=&quot;@+id/toggle_button&quot;<br>            android:src=&quot;@drawable/ic_expand_more_white&quot;<br>            android:layout_marginRight=&quot;12dp&quot;<br>            android:layout_centerVertical=&quot;true&quot;<br>            android:layout_alignParentRight=&quot;true&quot;<br>            /&gt;<br>    &lt;/RelativeLayout&gt;<br>    &lt;LinearLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:id=&quot;@+id/bottomBar&quot;<br>        android:visibility=&quot;gone&quot;<br>        android:animateLayoutChanges=&quot;true&quot;<br>        android:background=&quot;@android:color/holo_blue_light&quot;<br>        &gt;<br>        &lt;TextView<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_margin=&quot;12dp&quot;<br>            android:id=&quot;@+id/bottom_bar_text&quot;<br>            android:textColor=&quot;@android:color/white&quot;/&gt;<br>    &lt;/LinearLayout&gt;<br><br><br>&lt;/LinearLayout&gt;</pre><p>If you look closely you will notice the last ViewGroup which is a LinearLayout we are hiding the view by setting visibility:gone just put this in your head as a side note we will come back to this view later.</p><p>STEP 3:</p><p>So here’s where the fun begins, you know all those properties you set on Views in your xml file? Well we are going to define some for our customView. To do that head over to the res directory then look for a folder called values there should be a file called attrs.xml in there if its not available then create it in other words the full path your looking for should be res/values/attrs.xml. Now add this block of code to the file to define each property we can set from any xml file where we use our customview.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;resources&gt;</pre><pre>&lt;declare-styleable name=&quot;RevealView&quot;&gt;<br>    &lt;attr name=&quot;colorBar&quot; format=&quot;color|reference&quot; /&gt;<br>    &lt;attr name=&quot;contentBar&quot; format=&quot;color|reference&quot;/&gt;<br>    &lt;attr name=&quot;barTitle&quot; format=&quot;string&quot; localization=&quot;suggested&quot;/&gt;<br>    &lt;attr name=&quot;message&quot; format=&quot;string&quot; localization=&quot;suggested&quot;/&gt;<br>    &lt;attr name=&quot;showMessage&quot; format=&quot;boolean&quot;/&gt;<br>&lt;/declare-styleable&gt;</pre><pre>&lt;/resources&gt;</pre><p>Your file should look like the one above. So lets briefly go through the properties:</p><ol><li>colorBar: Defines the color for the header</li><li>contentBar: Defines the color for the body/content(the part of the view that will be visible or hidden by user interaction.</li><li>barTitle: Title text that will appear on the view header.</li><li>message: Body text of the bottoview</li><li>showMessage: A value that determines if the view should show the body container or not.</li></ol><p>STEP 4:</p><p>Lets head over to our Custom.java and initialise some variables we’ll use in constructing our view.</p><pre>public class RevealView extends FrameLayout{</pre><pre>//init properties<br> protected boolean toggle;<br> protected Drawable lessArrow =    getResources().getDrawable(R.drawable.<em>ic_expand_less</em>);<br> protected Drawable moreArrow = getResources().getDrawable(R.drawable.<em>ic_expand_more_white</em>);<br> private   TextView topBarText, bottomBarText;<br> protected View topBar;<br> protected ViewGroup bottomBar;<br> protected ImageView toggleBottom;</pre><pre>public RevealView(@NonNull Context context) {<br>        super(context);<br>    }<br><br>    public RevealView(@NonNull Context context, @Nullable AttributeSet attrs) {<br>        super(context, attrs);<br>    }<br><br>    public RevealView(@NonNull Context context, @Nullable      AttributeSet attrs, @AttrRes int defStyleAttr) {<br>        super(context, attrs, defStyleAttr);<br>    }<br>}</pre><p>Now lets create our helper methods that will control the view. Add these methods to the bottom of the file.</p><p>i.e I know we haven’t initialised these properties yet don’t worry we are coming to that, we don’t want null pointers.</p><pre>public void setTitle(String title){<br>    topBarText.setText(title);<br>}<br><br>public void setMessage(String message){<br>    bottomBarText.setText(message);<br>}<br><br>public void setTitleBarColor(int color){<br>    topBar.setBackgroundColor(getResources().getColor(color));<br>}<br><br>public void setBottomBarColor(int color){<br>    bottomBar.setBackgroundColor(getResources().getColor(color));<br>}</pre><p>Lets create our onClickListener so ever time someone touches the top bar the bottom part of the view is either revealed or hidden. You can add this to the bottom of the file.</p><p>Remember that view we added visibility:gone to? this listener will take care of enabling or hiding it.</p><pre>protected OnClickListener setToggle(final ImageView toggleButton, final View bottomBar){<br>    return new OnClickListener() {<br>        @Override<br>        public void onClick(View v) {<br>            Drawable drawable = lessArrow;<br>            int visibility = View.<em>VISIBLE</em>;<br>            if(toggle){<br>                drawable = moreArrow;<br>                visibility = View.<em>GONE</em>;<br>                toggle = false;<br>            }else {<br>                toggle = true;<br>            }<br>            toggleButton.setImageDrawable(drawable);<br>            bottomBar.setVisibility(visibility);<br>        }<br>    };<br><br>}</pre><p>Alright so now lets wrap them all together in an init method that the view will call every time an action is performed on it.</p><pre>public void init(Context context, AttributeSet attributeSet){<br>    <em>inflate</em>(context, R.layout.<em>reveal_view</em>, this);<br>    topBar = findViewById(R.id.<em>topBar</em>);<br>    bottomBar = (ViewGroup) findViewById(R.id.<em>bottomBar</em>);<br>    toggleBottom = (ImageView) findViewById(R.id.<em>toggle_button</em>);<br>    topBarText = (TextView) findViewById(R.id.<em>top_bar_title</em>);<br>    bottomBarText = (TextView) findViewById(R.id.<em>bottom_bar_text</em>);<br>    topBar.setOnClickListener(setToggle(toggleBottom, bottomBarText));<br>    if(attributeSet != null){<br>        TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.<em>RevealView</em>);<br>        try {<br>            toggle = typedArray.getBoolean(R.styleable.<em>RevealView_showMessage</em>, false);<br>            bottomBar.setVisibility(toggle ? View.<em>VISIBLE </em>: View.<em>GONE</em>);<br>            toggleBottom.setImageDrawable(toggle ? lessArrow : moreArrow);<br>            if(typedArray.hasValue(R.styleable.<em>RevealView_barTitle</em>)){<br>                topBarText.setText(typedArray.getString(R.styleable.<em>RevealView_barTitle</em>));<br>            }<br>            if(typedArray.hasValue(R.styleable.<em>RevealView_colorBar</em>)){<br>                topBar.setBackgroundColor(typedArray.getColor(R.styleable.<em>RevealView_colorBar</em>, getResources().getColor(R.color.<em>top_bar_color</em>)));<br>            }<br>            if(typedArray.hasValue(R.styleable.<em>RevealView_contentBar</em>)){<br>                bottomBar.setBackgroundColor(typedArray.getColor(R.styleable.<em>RevealView_contentBar</em>, getResources().getColor(R.color.<em>bottom_bar_color</em>)));<br>            }<br>            if(typedArray.hasValue(R.styleable.<em>RevealView_message</em>)){<br>                bottomBarText.setText(typedArray.getString(R.styleable.<em>RevealView_message</em>));<br>            }<br>        } finally {<br>            typedArray.recycle();<br>        }<br>    }<br><br>}</pre><p>Now we need to call the init() in our constructors defined earlier. Note that whenever a view is updated the constructors are called hence our method will be called and we can perform actions on our view.</p><pre>public RevealView(@NonNull Context context) {<br>    super(context);<br>    init(context, null);<br>}<br><br>public RevealView(@NonNull Context context, @Nullable AttributeSet attrs) {<br>    super(context, attrs);<br>    init(context, attrs);<br>}<br><br>public RevealView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {<br>    super(context, attrs, defStyleAttr);<br>    init(context, attrs);<br>}</pre><p>Now you can see how we reference the attrs.xml file we created earlier to see which value is set and modify our view based on that. So lets add our view to a layout file and see if we did good. So lets create reveal_tester.xml To add your view just call the class name of the custom view and android studio autocomplete should help you with the full package name.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>             xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>             android:layout_width=&quot;match_parent&quot;<br>             android:layout_height=&quot;match_parent&quot;<br>             android:background=&quot;#EEEEEE&quot;<br>             android:orientation=&quot;vertical&quot;&gt;<br><br>            &lt;com.example.RevealExample.RevealView<br>                android:id=&quot;@+id/reveal_view&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:visibility=&quot;gone&quot;<br>                app:showMessage=&quot;true&quot;/&gt;<br>&lt;/FrameLayout&gt;</pre><p>Now if you notice a namespace is added automatically for use app: we use this to access our custom properties, and we set the showMessage property to true so the body can be shown on default.</p><p>So head over to main activity and set this layout as the layout for the activity so we can test what we’ve done.</p><pre>setContentView(R.layout.reveal_tester);</pre><p>thats all no need for extra inits since the view widget is already taking care of click/touch interactions.</p><p>Thanks for reading, hope this helps you when creating more complex custom views for your android apps.</p><p>Remember that you can set the color of the title and body through xml or your java code where you declared the view. The function is part of the attributes we set on the attrs.xml and also the methods we defined earlier to setTitle() and etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*AHcMPHHEaR-AZH9Yo8KJGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*oGO4s6tkaRsuUWPjSx7aZg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa386b506860" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/custom-views-make-your-android-app-stand-out-fa386b506860">Custom Views: make your android app stand out</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android kotlin: (Object Constant file)]]></title>
            <link>https://medium.com/@SmileEgbai/android-kotlin-how-to-part-2-object-constant-file-689380f64f95?source=rss-6301fd2435b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/689380f64f95</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Egbai Smile Mmumene]]></dc:creator>
            <pubDate>Fri, 30 Jun 2017 17:54:13 GMT</pubDate>
            <atom:updated>2017-08-25T17:12:21.290Z</atom:updated>
            <content:encoded><![CDATA[<p>So as android devs I know we can’t do without our god-constants file, usually if you have a java class full of static finals maybe urls and you convert this to kotlin the first thing you will notice is the class changes to a object class. Below is a typical Url class of constants:</p><pre>public class Urls {   <br> public static String BASE_URL = &quot;https://shop440.com&quot;;    <br> public static String NEW_USER = &quot;/api/new_user&quot;;    <br> public static String PASSCODE = &quot;/api/get_passcode&quot;;    <br>}</pre><p>Here’s the kotlin equivalent :</p><pre>object Urls {<br>    var BASE_URL = &quot;https://shop440.com&quot;<br>    var NEW_USER = &quot;/api/update_name_and_email&quot;<br>    var <em>PASSCODE </em>= &quot;/api/get_<em>passcode</em>&quot;<br>}</pre><p>Now usually this would not be a problem because it works as it should but when checking the translated code after compile you will see alot of inefficiencies also unless you will be accessing this class from another kotlin class else if you try to use it from a java class you may run into problems because apparently kotlin sees the properties as private hence it restricts access.I cannot say for sure now why you can access them within a kotlin file and not java but I’ll dig deeper and find out. Now to solve this problem just put a “const” keyword in front of your property and all solved and change the var to val i.e its supposed to be immutable after all.</p><pre>const val BASE_URL = &quot;https://shop440.com&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=689380f64f95" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>