<?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 Jacek Marchwicki on Medium]]></title>
        <description><![CDATA[Stories by Jacek Marchwicki on Medium]]></description>
        <link>https://medium.com/@JMarchwicki?source=rss-2db85a7cbbe8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yW4NnOY_sp0GBq-OtGWE7Q.jpeg</url>
            <title>Stories by Jacek Marchwicki on Medium</title>
            <link>https://medium.com/@JMarchwicki?source=rss-2db85a7cbbe8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:07:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JMarchwicki/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[My Story@Appunite]]></title>
            <link>https://medium.com/appunite-edu-collection/my-story-appunite-27cf4fc67ed7?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/27cf4fc67ed7</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[software-house]]></category>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Mon, 11 Jun 2018 10:44:53 GMT</pubDate>
            <atom:updated>2018-06-11T10:44:53.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dqz8-Tb-coUaIIPayu9JWQ.jpeg" /><figcaption>Night sky, Milky Way</figcaption></figure><p>It was some time ago (2011), a year after I joined AppUnite as the first employee. At the time, I’ve just developed third iOS app (yes, this is no typo — iOS app :) ).</p><p>Our client was so content with our iOS development that he asked Karol (CEO and one of AppUnite’s co-founders) to develop the same app for Android. Karol refused because AppUnite hadn’t had experience developing Android apps. Actually, 2 years before I’d worked with Android and by then was completely besotted by it. But experience and love didn’t mean “production-ready”. This didn’t discourage the client, he knew that we are good developers and we have good project management strategies so he insisted. Karol refused, explaining to the client the risk of not delivering good quality product because of developing an app for the new platform. The client knew that in his iOS app, we had implemented features that hadn’t been on the market at the time, so he knew that the risk was smaller than looking for other company. Karol asked me if I want to start developing the same app for Android. I said in Polish <em>“kto nie ryzykuje, ten nie pije szampana”</em> (this Polish proverb means, in free translation: who doesn’t risk, doesn’t drink champagne). Karol talked to the client and ensured that he was willing to take the risk.</p><p>The client was sure.</p><p>Our friendly designer read Android Design Guidelines and with my help adjusted the designs.. They were approved. The schedule was set and development of app has started.<br>Keep in mind that these were ancient times for Android (minimal supported Android version: 1.5, newest Android version was 3.0).</p><p>We had to face many problems.</p><p>There was no good library for fetching images from the Internet that met our speed standards (yes, there were no Picasso or Glide libraries). I needed a whole week only to present images to users.<br>At the time, we had a stunning iOS library (called AUKit) for fetching data from the network, caching them and displaying them to a user. There was no such library for Android. We had to implement our own.<br>And the real disaster… The app’s main feature was sharing video content. Sharing videos between Android devices, and iOS devices was no problem — the issue was to share content between iOS and Android. Today, it’s a common practice to use a server as a converter for different video formats between iOS and Android. But our client need was to use serverless solution.<br>We needed FFmpeg library to convert video files on the device. The problem was that FFmpeg library wasn’t yet adjusted to compile for Android. We had to do it. Then, we needed to create a wrapper between C language in which FFmpeg is written, and Java in which the app was written. And of course, these weren’t times when you could just type a question into Google and find a solution. These were times when you had to read Android Operating System source code to find tips. This caused delays, but we managed nonetheless..</p><p>We did this!</p><p>And the best part was that development and tests were overdue only by a week. The customer was satisfied and we were even more.</p><p>I think this is a problem of many software houses — they don’t want to risk.<br>If you want to implement great software, you need to use better and better technology, you need to take a risk. Albert Einstein said, <em>“Insanity is doing the same thing over and over again and expecting different results”</em>.<br>In these 7 years, light years in computer science, so many new developers joined AppUnite but I’m convinced that we’re still the same company, the company that still wants to use new technology, the company that still wants to ensure that the client’s aware of the risk.</p><p>Jacek Marchwicki<br><em>Lead Android Developer,<br>Android Evangelist,<br>former iOS developer :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27cf4fc67ed7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/my-story-appunite-27cf4fc67ed7">My Story@Appunite</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Errors… oh… those errors]]></title>
            <link>https://medium.com/appunite-edu-collection/errors-oh-those-errors-b69da8545c62?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b69da8545c62</guid>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[issues]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[erros]]></category>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Tue, 24 Apr 2018 09:50:23 GMT</pubDate>
            <atom:updated>2018-04-24T09:53:18.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNhFTrb796fxKfKyIoFqKw.jpeg" /><figcaption>The man fell into the chewing gum</figcaption></figure><p>In my opinion, good error handling is one of the most important features of the application. But most people in development process ignore them:</p><ul><li>Product owner focuses on happy path ignoring issues like missing an internet connection.</li><li>UI/UX designers focus on product owner satisfaction and they don’t have good technical knowledge.</li><li>Developers have thousands of tasks fulfill, and none of the tasks are called “error handling”.</li><li>And testers…</li></ul><p>Yes… sadly, most of the companies find issues in error handling at this point, where a tester starts doing theirs work or users have installed the application from a store.</p><h3>Frustration</h3><p>So let’s start with an example: Your app is an e-mail application, it will have a list of emails and some fields so a user can send email using the send button.</p><p>Because everyone did the job very well implementing features but forgot about error handling, there are possible situations that might happen:</p><ol><li>A QA tester rejects a task with a comment “I clicked on send and nothing had happened”. Your testing team is very good, so a tester will also attach a video and application’s logs.</li><li>You sent an application to the product owner and he/she will say: “I just got a version without sending e-mails implemented”</li><li>An application is in store and some user said that “I can’t click on send button”</li><li>A user is frustrated because they thinks that they aren’t smart enough to use the application and they don’t want to contact you.</li></ol><p>Now everyone becomes frustrated:</p><ul><li>A tester becomes frustrated because the feature does not work as expected.</li><li>A product owner is frustrated because the feature is not delivered but the task stands that it’s working.</li><li>A user is frustrated because the application that he/she uses doesn’t work, or he/she is frustrated because he/she doesn’t know how to use the app.</li><li>A mobile developer is frustrated because he/she doesn’t know what happened and he/she doesn’t know how to fix it. He/She also needs to spend additional hours resolving the issue, that might not be an issue.</li><li>a backend developer is frustrated because the mobile developer accuses him/her that this is backend issue.</li><li>An investor is very angry because he/she losing clients, time and money.</li><li>A UI/UX will be angry because everyone will say that this was his/her fault.</li></ul><h3>Retrospection</h3><p>Now, it’s time for a retrospection.</p><p>The scrum master or the project owner starts the discussion about what happened. Developers (mobile/server) didn’t change anything and everything started working. The tester, product owner, and users don’t see the problem anymore. Problem solved! — But wait… good PM will continue to push the team to find the solution to the future problems like these.</p><p>So they will brainstorm to find what might have happened:</p><ol><li>There were temporary problems with the connection to database,</li><li>The Europe-America fiber had some temporary outage,</li><li>There was a deploy during that time,</li><li>There is some ugly bug in production,</li><li>The mobile app has some bug in the version that is in the store,</li><li>The device was connected to some network that didn’t have an internet access (like wifi without accepting network agreement),</li><li>A client was disconnected from wifi,</li><li>The device has some problems with network,</li><li>etc…</li></ol><p>And guess what?… No-one will know which problem occurred. Moreover, no-one will know how to address such issues.</p><p>What’s more, someone from the team realized that we can show a message to users “Oops, something wrong has happened.” if some issue occurred. This is a good starting point but doesn’t help to understand which problem will appear.</p><h3>Solution</h3><p><strong>Error handling should distinguish problems and help to resolve issues. Errors are not only for the end user but also for developers.</strong></p><ol><li>If a user sees an error, he/she should know what to do next.</li><li>If a tester sees an error, he/she should know how he/she should fill an issue.</li><li>If a developer sees an error, he/she should know how to fix it.</li></ol><p>Remember, that the production version of the application should also contain errors that are helpful for a developer. In our example, if a user sent screenshot with error: “Oops, Temporary server outage (502)” and a developer will see it, he/she will instantly know that the problem was related to the deployment of production server that took too much time — and there is a place for improvement. You also can send back quick response to a user, informing what problem arose and you can promise that this was temporary.</p><h3>Error types</h3><p>So let’s start with basic errors that we implement and why they are important:</p><ol><li><em>Loading…</em> — the most important feedback for a user that something is loading. A user needs to know that there is nothing to worry about, just that the content is loading. If loading takes too much time, he/she might think about changing his/her network provider. During the loading, without indicator in the e-mail app, a user might think: “All my e-mails were deleted”.</li><li><em>No Internet, check your connection</em> — this is the second most important feedback for a user. No Internet is a common situation. On the train, plane, tunnel, underground station, or even some places in a flat. Without this message, a user might think that an app has broken or he/she doesn’t know how to do things. Show a user that it’s neither his nor your fault. Show him/her that he/she can fix this problem.</li><li><em>Your password is wrong</em>, <em>Title should be filled</em> — This is definitely frustrating to a user if he/she clicks the send button and doesn’t know why he/she can’t send an e-mail — he/she just forgot to type recipients. People are imperfect and we tend to forget about something. So if a user will forget to fill something, you should help him/her.</li><li><em>Problem with network connection</em> — (optional but useful) An app can distinguish missing network issues reported by device operating system from exceptions thrown while fetching data (like an unknown host, a connection is broken etc.). These types of errors do not precisely mean that a problem is with a client or server network. The good practice is to distinguish these two, so a developer can guess what is wrong.</li><li><em>No friends, add them using + icon</em>, <em>No messages, you can create new ones</em> — Sometimes when the list is empty, users think that something went wrong. It’s a good idea to show a placeholder with a suggestion how he/she should react to change this state.</li><li><em>Temporary server downtime, try again in couple of minutes</em> — Server updates happen from time to time, even if usually you have updates without downtime. It’s a good idea to have some information for a user and for you that server is currently deploying. Usually, servers tend to return 502 HTTP error code in such situations. Your client will be happy because he/she knows that an issue will be resolved in minutes. You will be happy because the QA team will not reject your task, they’ll ask the backend team if there is an ongoing deploy on staging. You will be happy during development because you will know that an app didn’t break, just a dev team doing a deployment.</li><li><em>Temporary server issue (500)</em> — This message should be displayed when you get some 5xx response code from a server. This issue should never happen but if it does appear, your QA team will fill a ticket t theo backend team. If a user will send you a screenshot of the bug, you will know better what went wrong. The mobile team will be happy because they will not be disturbed. The backend team will be happy because they will get a better understanding what issues might appear.</li><li><em>Unknown application error (422)</em> — This message should be displayed when you get some 4xx response code from a server. This issue also should never happen but this time the QA team will assign it to the mobile team. Also this time, you will better understand users’ problems. This time the mobile team will know how to handle the problem and the backend team will be safe.</li><li><em>Post not found</em>, <em>Not found</em> — It’s also a good practice to implement this specialized error to show the smarter message. The user will know how to handle such situations and will know what to do.</li></ol><h3>Errors persistence</h3><p>There is also one more thing. Apps tend to show toast/snack bars with errors. It’s better than no errors but toasts automatically pass away without solving an issue.</p><p>Let’s show this by example:</p><ol><li>you open an e-mail application,</li><li>there is a problem with the Internet so e-mails couldn’t load and snack bar is displayed,</li><li>but you didn’t see a snack bar because you talked with a friend,</li><li>the snack bar disappeared after 2 seconds,</li><li>you look at your e-mail application and you see nothing and you become very angry because you think someone has hacked into your e-mail account and deleted all of your emails,</li><li>also this screenshot of the screen will be sent to the development team.</li></ol><p>Wouldn’t it be much better to show this persistent error until emails will load with success? It wouldn’t cause such problems.</p><p>But snack bars aren’t so wrong. If you pull-to-refresh your emails snack bar will be much better than persistent error. If refreshing will fail you can still show old emails with a small snack bar that will not cover user content.</p><p>Also, a snack bar is pretty good for errors about liking, commenting, sending data, even in login when a user is aware that content didn’t send and when he is quickly able to retry.</p><h3>Disturbing errors</h3><p>Errors shouldn’t make a user work harder.</p><ol><li>content shouldn’t be overlapped by errors,</li><li>a snack bar shouldn’t overlap action buttons,</li><li>you shouldn’t use errors as dialogs because they disrupt users’ workflow. Only in a very critical situation, you can show errors as dialog,</li><li>errors shouldn’t block other parts of UI. A user could use other app features during this outage time.</li></ol><h3>Summary</h3><ul><li>Learn from others’ mistakes — do error handling TODAY, not tomorrow.</li><li>Catch as many errors as you can.</li><li>Weak error handling is better than none.</li><li>Error handling should be as easy to implement as it can be to ALL features.</li><li>If you show an error message that will help your user resolve a problem, you will not have his/her problems on your shoulders.</li><li>If you show an error message that will help a QA team find a bug, you will spend less time on finding issues.</li><li>If you show an error message that will help you, you will spend less time debugging the app.</li><li>If you show an error message that will help everyone, everyone will be happy.</li><li>Error handling should distinguish problems and help to resolve issues.</li><li>Errors are not only for an end user but also for developers.</li></ul><h3>What’s more</h3><p>The example how to show errors using Kotlin on Android is presented in the next article.</p><p><em>Originally published at </em><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/blob/master/articles/error-handling.md"><em>github.com.</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b69da8545c62" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/errors-oh-those-errors-b69da8545c62">Errors… oh… those errors</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</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 find StackOverflowError’s]]></title>
            <link>https://medium.com/appunite-edu-collection/how-to-find-stackoverflowerrors-99264e9709f8?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/99264e9709f8</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <category><![CDATA[crash]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 12:44:19 GMT</pubDate>
            <atom:updated>2018-04-18T09:39:11.602Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AcOGzMsa7aFhKaBV8sY7cg.jpeg" /><figcaption>Image from <a href="https://unsplash.com/photos/eofm5R5f9Kw">https://unsplash.com/photos/eofm5R5f9Kw</a></figcaption></figure><p>Sometimes you see StackOverflowError’s on some devices. Some of them you can’t reproduce on your device or the crashes come about in unexpected situations. There are some tips that will allow finding the issues more easily.</p><h3>Description.</h3><p>Usually, StackOverflowError appears unexpectedly and sometimes it’s hard to trace them with just a stack trace that you will get from a crash on your device or from a crash on your crash reporter. On Android, different devices have different stack size depending on the API level or even manufacturer. So the good way is to easily catch StackOverflowError is to decrease a stack trace on an emulator.</p><h3>Decreasing stack size</h3><p>Run Dalivik emulator (before API level 5, I didn’t check this solution on ART emulators). Now you need to decrease the stack size:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae2d2762d069b6a605ae07c7c37d21c8/href">https://medium.com/media/ae2d2762d069b6a605ae07c7c37d21c8/href</a></iframe><p>Now, your emulator will restart. You need to look at your logcat for errors like these:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d49fdf6868dcf72b9e56d904cc148954/href">https://medium.com/media/d49fdf6868dcf72b9e56d904cc148954/href</a></iframe><p>If you see such a notification, it means that you have given too small or too large a stack size (In this case -Xss1 - One byte of a stack size has obviously been too small ;) )</p><p>What’s more, if you give too small stack size, your emulator can crash because Android OS is not meant to support 1kB of a stack size ;) You need to experiment with a value that suites your needs.</p><h3>Catching issues</h3><p>The good way is to start in the debug mode and catch the exception before it appears.</p><h3>Setting up a breakpoint</h3><p>So first, setup a breakpoint for StackOverflowError on Android Studio.</p><ol><li>In the menu choose <em>Run</em> -&gt; <em>View Brakepoints…</em> or <em>CMD+Shift+F8</em></li><li>Click <em>+</em> -&gt; <em>3. Jave Exception Brakepoints</em></li><li>Search for StackOverflowError</li><li>Click <em>OK</em></li><li>Click <em>Done</em></li></ol><p>Now, you have a breakpoint set.</p><h3>Running application</h3><p>Run your application in the debug mode and click until your exception will catch.</p><h3>Looking for important information</h3><p>When a breakpoint will catch your issue you can easily navigate through the entire stack and find useful information.</p><h3>References</h3><ul><li><a href="https://stackoverflow.com/questions/16843357/what-is-the-android-ui-thread-stack-size-limit-and-how-to-overcome-it">StackOverflow #1</a></li><li><a href="http://* https://stackoverflow.com/questions/7453336/setting-stack-size-to-thread-seems-to-make-no-difference-in-android">StackOverflow #2</a></li><li><a href="https://blog.csdn.net/lhf_tiger/article/details/17719955">Some BlogPost</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99264e9709f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/how-to-find-stackoverflowerrors-99264e9709f8">How to find StackOverflowError’s</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A nice reader/writer pattern]]></title>
            <link>https://medium.com/appunite-edu-collection/nice-reader-writer-pattern-8439ec3ebe0?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8439ec3ebe0</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[synchronization]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 08:41:17 GMT</pubDate>
            <atom:updated>2018-02-05T15:34:59.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ryJ5vz5na9stJJF3P6gPGw.png" /></figure><p>During the implementation of a chat app, I had to implement some kind of lock logic. Usually, a code with locking and unlocking is hard to read. If business logic is complicated and you will add complicated locking, your code will become unreadable and unmaintainable.</p><h3>TL;DR;</h3><p>Good example:</p><ul><li><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/tree/master/examples/nice-reader-writer-pattern/src/test/java/com/jacekmarchwicki/locking/NewDatabaseTest.kt">NewDatabaseTest</a></li><li><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/tree/master/examples/nice-reader-writer-pattern/src/main/java/com/jacekmarchwicki/locking/NewDatabase.kt">NewDatabase</a></li></ul><p>Compared to bad example:</p><ul><li><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/tree/master/examples/nice-reader-writer-pattern/src/test/java/com/jacekmarchwicki/locking/OldDatabaseTest.kt">OldDatabaseTest</a></li><li><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/tree/master/examples/nice-reader-writer-pattern/src/main/java/com/jacekmarchwicki/locking/OldDatabase.kt">OldDatabase</a></li></ul><h3>Example</h3><p>Let’s start with a database which looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bd2d83ad82d575dbd24a8a37bcd6356/href">https://medium.com/media/9bd2d83ad82d575dbd24a8a37bcd6356/href</a></iframe><p>and if you add an element and then read it, your code will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b222cdb5ffdadaf744e4fbd75083fa8/href">https://medium.com/media/5b222cdb5ffdadaf744e4fbd75083fa8/href</a></iframe><p>It’s very, very hard to read. Thankfully, Kotlin has built-in extension functions for ReadWriteLock so you can change your code to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e74cbb52cfc22f2be993bbf02712bf0/href">https://medium.com/media/9e74cbb52cfc22f2be993bbf02712bf0/href</a></iframe><p>But still, the code is vulnerable to potential issues like (Use read lock instead of write, or even forget to use locking). Also reading the code with something like this db.internalList = db.internalList.plus(&quot;something&quot;) is hard to understand.</p><p>So let’s write a better database with nicer API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3d36308c66f16fdd08794c28832ccec/href">https://medium.com/media/e3d36308c66f16fdd08794c28832ccec/href</a></iframe><p>or even:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16724cf314e36e10b7ef083052fd1a5f/href">https://medium.com/media/16724cf314e36e10b7ef083052fd1a5f/href</a></iframe><p>and code like db.read {addItem(&quot;something)} will not even compile.</p><p>Let’s do it better:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/845c667d5991591a94b51331920701a0/href">https://medium.com/media/845c667d5991591a94b51331920701a0/href</a></iframe><h3>Conclusions</h3><ol><li>Good patterns makes complicated logic more understandable,</li><li>If your code is hard to read you need to rewrite it,</li><li>Especially when you write something hard, try to refactor your code to black boxes that implement only part of your logic.</li></ol><p><em>Originally published at </em><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/blob/master/articles/nice-reader-writer-pattern.md"><em>gist.github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8439ec3ebe0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/nice-reader-writer-pattern-8439ec3ebe0">A nice reader/writer pattern</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin and RxJava with extension functions]]></title>
            <link>https://medium.com/appunite-edu-collection/kotlin-and-rxjava-with-extensions-functions-59ea354b843e?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/59ea354b843e</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 07:51:58 GMT</pubDate>
            <atom:updated>2018-01-29T09:25:43.615Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mTs6ZAl8v5PiPXWehs6RzQ.jpeg" /></figure><p>This is an introduction to some patterns that can be helpful during an implementation of Android applications that operate on any structured data, especially downloaded from APIs.</p><p><strong>Warning: Lots of codes.</strong> Since it’s relatively a technical article and I am an Android dev (probably as you are), there will be a lot of code examples.</p><h3>TL;DR;</h3><p><a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/blob/master/examples/kotlin-and-rxjava-with-extensions-functions/src/main/java/com/jacekmarchwicki/examplerxextensions/MainActivity.kt">The full code is available here</a></p><h3>Used libraries</h3><p><strong>TIP:</strong> In the example I use RxJava 1.x but almost the same code can be used with RxJava 2.x</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd42b5a4d805d60b83056f678e1d0d6b/href">https://medium.com/media/bd42b5a4d805d60b83056f678e1d0d6b/href</a></iframe><h3>Let’s start with an example</h3><p>We would like to implement UI that displays posts from API and allows sending new ones. Our UI needs a RecyclerView for displaying the posts, a button, and a text field, so a user is able to post to the server.</p><p>Firstly, you have two classes that represent API responses:</p><ul><li>ApiError — represents some errors from API,</li><li>Post — represents a post that needs to be added to the server.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd44a635a53e4ac85fd1ac7cc8b96da/href">https://medium.com/media/afd44a635a53e4ac85fd1ac7cc8b96da/href</a></iframe><p>You have also some service, probably written using <a href="http://square.github.io/retrofit/">retrofit</a>. We will mock it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/553395c333c1716437ac319e68c5b1df/href">https://medium.com/media/553395c333c1716437ac319e68c5b1df/href</a></iframe><p>I expect that you already have some UI and some model (Dao — Data Access Object) that will provide authorization.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8b7bbc755f7dd2878d4abfdb9d2a7b7/href">https://medium.com/media/a8b7bbc755f7dd2878d4abfdb9d2a7b7/href</a></iframe><p>In this case, this will be just a mock:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3e818980c796ddb1b44e3be30c117d2/href">https://medium.com/media/b3e818980c796ddb1b44e3be30c117d2/href</a></iframe><p><strong>Important:</strong> All Dao’s are singletons.</p><p>Your Application class can look like this if you don&#39;t want to use dagger:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e478f7ace9cbfa6362b53977c498bae3/href">https://medium.com/media/e478f7ace9cbfa6362b53977c498bae3/href</a></iframe><h3>Start the implementation</h3><p>You create some base class for receiving posts and for sending new ones.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6951da0babc2ab2479b80bd855051392/href">https://medium.com/media/6951da0babc2ab2479b80bd855051392/href</a></iframe><p>PostsDao needs val authorizedDao: AuthorizedDao because posts are different for different authorized users and we don&#39;t want to return other user’s posts when a user re-logs in-to a another account. Cache is used so the same instance will always return the same authorized user. We could use more sophisticated cache but HashMap is good enough.</p><p>Now, you implement receiving posts in your PostsDao:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f40c73c9756881083c86090be2499964/href">https://medium.com/media/f40c73c9756881083c86090be2499964/href</a></iframe><ul><li>Now, you request a new authorization token (<em>1</em>) and request API (<em>2</em>).</li><li>You need to use request API over a different thread.</li><li>You want to handle errors in a nifty way (<em>4, 5</em>).</li><li>You want to convert your Single&lt;&gt; to Observable&lt;&gt; (<em>6</em>).</li><li>And you also want to cache results (<em>7</em>).</li></ul><p>Now, you need to implement sending posts in your PostsDao:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6904f750c120fd3895d5a0123913fd19/href">https://medium.com/media/6904f750c120fd3895d5a0123913fd19/href</a></iframe><ul><li>Points from <em>1–6</em> are the same as in the fetch example.</li><li>But now, you don’t convert to Observable because this is an action that will create a post and give one result.</li><li>You also don’t cache result because invoking createPost(Post) should always create a post.</li><li>But you need to inform posts that something has changed (<em>6</em>).</li></ul><p>Now you adjust posts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d139d156eeaf5a22c019e6656f661d12/href">https://medium.com/media/d139d156eeaf5a22c019e6656f661d12/href</a></iframe><ul><li>First (<em>0.1</em>) we will wait for changes from refreshSubject and start with some default value that will execute our request.</li><li>We make sure we ignore multiple refreshes requests when they occur (<em>0.2</em>).</li><li>We will flatMapSingle (<em>0.3</em>) with our API call each request for downloading data. We don&#39;t want to use more than one concurrent API call.</li><li>Instead of caching all results, we want to use only the most recent one (replay(1).refCount()) (<em>6.1, 6.2</em>)</li></ul><p>Now your PostsDao is super cool. When a post will be added, the list of posts will be automatically refreshed. Your business logic is hidden inside of PostsDao.</p><h3>Presenters</h3><p>Presenters and UI are not a parts of this tutorial but if you would like to see how to use code that you have just written, check the full code here: <a href="https://github.com/jacek-marchwicki/example-rx-and-kotlin-and-either/blob/master/examples/kotlin-and-rxjava-with-extensions-functions/src/main/java/com/jacekmarchwicki/examplerxextensions/MainActivity.kt">Presenters and UI implementation</a></p><h3>So what can we do better?</h3><p>In my opinion, the ugliest code is here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0c02359791e56e20e9dd8990c3b1580/href">https://medium.com/media/d0c02359791e56e20e9dd8990c3b1580/href</a></iframe><ul><li>It requires type definition and casting.</li><li>It’s very common for API requests.</li><li>It requires two operations but it’s a single operation (just a changing error to either).</li></ul><p>So let’s define the useful extension function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab581246850eb1cfd1ea7c7ad756a9c9/href">https://medium.com/media/ab581246850eb1cfd1ea7c7ad756a9c9/href</a></iframe><p>so your code will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89859cd1927c5429b62b77ebf9ccab1d/href">https://medium.com/media/89859cd1927c5429b62b77ebf9ccab1d/href</a></iframe><p>But the implementation of our extensions function could more universal:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6f746cd3b6539ebfec40d6901de55dc/href">https://medium.com/media/b6f746cd3b6539ebfec40d6901de55dc/href</a></iframe><p>Now, you can implement handling an API errors in a universal super cool way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/906cff7e18e34b7e07cdf4812580e7c2/href">https://medium.com/media/906cff7e18e34b7e07cdf4812580e7c2/href</a></iframe><h3>Better refreshing</h3><p>IMHO the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e82c8afd22b2519a0a58c20a94577199/href">https://medium.com/media/e82c8afd22b2519a0a58c20a94577199/href</a></iframe><p>is pretty hard to understand. If the code is hard to understand, you need to rewrite it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ef195dce728185912b1b931e258f1cf/href">https://medium.com/media/0ef195dce728185912b1b931e258f1cf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abef34cf15668e136fd3f4a3b81dce4f/href">https://medium.com/media/abef34cf15668e136fd3f4a3b81dce4f/href</a></iframe><h3>Summary</h3><p>What you have learned:</p><ol><li>Extension functions in Kotlin can make your code more readable. You also do not have to write the same code constantly.</li><li>Writing business logic in DAO’s (Data Access Objects) makes your code easier to understand. Logic is separated from views.</li><li>Either’s are better than throwable’s for handling errors.</li><li>Good code model allows agile modification of it without touching views.</li></ol><h3>What’s more</h3><p>If you would like to see how to test it, check this out: <a href="https://medium.com/@JMarchwicki/using-schedulers-while-testing-your-code-cd924940cc04">Using schedulers while testing your code</a></p><p><em>Originally published at </em><a href="https://gist.github.com/a7de38ca89eecb7a42f03f389b372f81"><em>gist.github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59ea354b843e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/kotlin-and-rxjava-with-extensions-functions-59ea354b843e">Kotlin and RxJava with extension functions</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using schedulers while testing your code]]></title>
            <link>https://medium.com/appunite-edu-collection/using-schedulers-while-testing-your-code-cd924940cc04?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd924940cc04</guid>
            <category><![CDATA[mockito]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Fri, 15 Dec 2017 14:16:56 GMT</pubDate>
            <atom:updated>2018-01-08T08:01:06.238Z</atom:updated>
            <content:encoded><![CDATA[<p>We like to implement UI that sends some post to API. Our UI need a button that sends a post, and a text field called “message” so a user is able to choose a message that is posted to the server. Of course, our UI can display errors and show success (via toast). We are going to implement everything via MVC pattern and test the presenter.</p><p>At the starting point, you have two classes that represent API responses:</p><ul><li>ApiError — represents some errors from API,</li><li>Post — represents post that needs to be added to the server.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa19d11f2977838035b4459606a05769/href">https://medium.com/media/aa19d11f2977838035b4459606a05769/href</a></iframe><p>You have some kind of Dao that will contact server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aba1ccf39365c192ff8f133e315123be/href">https://medium.com/media/aba1ccf39365c192ff8f133e315123be/href</a></iframe><p>Of course, you have some UI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1222b2fbacc6153ad925825428bebff0/href">https://medium.com/media/1222b2fbacc6153ad925825428bebff0/href</a></iframe><p>And presenter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbccc1e7f25adbf03cdd33eac1760b26/href">https://medium.com/media/fbccc1e7f25adbf03cdd33eac1760b26/href</a></iframe><p>So you add tests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fec35d7be084781d67bcca057c51a41a/href">https://medium.com/media/fec35d7be084781d67bcca057c51a41a/href</a></iframe><p>But actually, there is an issue in the presenter, because API thread isn’t changed to the main thread. This isn’t hard to fix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9c22021c44394a7cb81135ea874abfe/href">https://medium.com/media/c9c22021c44394a7cb81135ea874abfe/href</a></iframe><p>and than update presenter with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ede499179f9fe2d7defbf26b479f3986/href">https://medium.com/media/ede499179f9fe2d7defbf26b479f3986/href</a></iframe><p>pretty simple wasn’t it?</p><p>Now you would like to debounce users clicks on send button within 1second, so you update your presenter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f23f7c214e29f96cadf43fc3877344fe/href">https://medium.com/media/f23f7c214e29f96cadf43fc3877344fe/href</a></iframe><p>And hurray.. everything works… but wait… have you noticed the amount of time that took for your tests to accomplish?</p><p>It was 66ms before and now its 3s and 66ms? Maybe this isn’t a problem for this small test suite. But if you will have a test suite that contains 1000 or 10000 tests this can become 15minutes/3hours longer for your build to finish.</p><p>So what is the solution? The answer is TestScheduler (Schedulers.test()). Test scheduler allows manipulation of time. So you change your test initialization to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3eb791ba53a98d88607baaa231dd35f/href">https://medium.com/media/f3eb791ba53a98d88607baaa231dd35f/href</a></iframe><p>then you need to give instructions to the test how much time has passed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b282440e587e7eda5ce4e0d523fc8b5a/href">https://medium.com/media/b282440e587e7eda5ce4e0d523fc8b5a/href</a></iframe><p>Using uiScheduler.advanceTimeBy(1, TimeUnit.SECONDS) you virtually move into the future by one second. And yes… it’s possible to move even 1 year into the future ;)<br>But TestScheduler can be a little annoying in some situations. Lest’s remove debounce from our code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45e95afff98a33147374d0a685fefc45/href">https://medium.com/media/45e95afff98a33147374d0a685fefc45/href</a></iframe><p>and still use TestScheduler it test initialization:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf6d04666cb079e0e8b41a925e15984e/href">https://medium.com/media/cf6d04666cb079e0e8b41a925e15984e/href</a></iframe><p>and test code without advanceTimeBy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecdd5b0ce3d0308a5314142058d9c776/href">https://medium.com/media/ecdd5b0ce3d0308a5314142058d9c776/href</a></iframe><p>And now tests fails :/ What’s wrong? If you’ll switch to Schedulers.immediate() your test code will work. This is because scheduling (.observeOn, .subscribeOn) via TestScheduler needs to be invoked by uiScheduler.advanceTimeBy() or by uiScheduler.triggerActions(), so you need to change your test code to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6eb7b1bfd5bdfd1208654787683edc9/href">https://medium.com/media/b6eb7b1bfd5bdfd1208654787683edc9/href</a></iframe><p>And this is ugly… It’s definitely ugly if you need to think about threads in your tests when you don’t want to. Wouldn’t be cool to have a Scheduler that works instantly for instant schedules and manually for time-delayed schedules? I can give you one that took minutes to implement:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adb2442c29918e45e79f8d860b64d18c/href">https://medium.com/media/adb2442c29918e45e79f8d860b64d18c/href</a></iframe><p>If you use this scheduler in your code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84e7b2b1e0c04b9ce42b5dcdf404c8fb/href">https://medium.com/media/84e7b2b1e0c04b9ce42b5dcdf404c8fb/href</a></iframe><p>You no longer need to invoke uiScheduler.triggerActions() this is be done automatically.</p><h3>Conclustions</h3><ol><li>Don’t care about threading changes in your tests if you don’t want to check threading,</li><li>Don’t use Schedulers.immediate() so your tests will be quicker and more reliable,</li><li>Don’t use TestSubscriber.await* methods because they can be flaky if tests will take more time to finish,</li><li>Use ImmediateTestScheduler() in your tests — so they will be fast and reliable.</li></ol><h3>Whole test file</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86ce86ef79828d1c5ea062eb9a4ac899/href">https://medium.com/media/86ce86ef79828d1c5ea062eb9a4ac899/href</a></iframe><p>More examples of this pattern can be found here: <a href="https://medium.com/@JMarchwicki/kotlin-and-rxjava-with-extensions-functions-59ea354b843e">Kotlin and RxJava with extensions functions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd924940cc04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/using-schedulers-while-testing-your-code-cd924940cc04">Using schedulers while testing your code</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCM User Notifications]]></title>
            <link>https://medium.com/appunite-edu-collection/notifications-d7df385b0ff4?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7df385b0ff4</guid>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Thu, 07 Aug 2014 13:21:42 GMT</pubDate>
            <atom:updated>2014-08-07T13:37:26.466Z</atom:updated>
            <content:encoded><![CDATA[<p>Unfortunately documentation about GCM User Notifications is incomplete and sometimes wrong. Here are some server-site curl requests that can be used while using this api.</p><h3>Creating new notification</h3><h4>Request</h4><pre>curl -vvv -X POST —header “Content-Type: application/json” —header “project_id: &lt;YOUR-PROJECT-ID&gt;” —header “Authorization: key=&lt;YOUR-PROJECT-SECRET-KEY&gt;” —data @- “https://android.googleapis.com/gcm/notification&quot; &lt;&lt; EOF<br>{ <br> “operation”: “create”,<br> “notification_key_name”: “asdf”,<br> “registration_ids”: [“&lt;REGISTRATION-ID-FROM-DEVICE&gt;”]<br>}<br>EOF</pre><h4>Response</h4><p>HTTP/1.1 200 OK</p><pre>{“notification_key”:”&lt;NOTIFICATION-ID&gt;”}</pre><h3>Adding registration id</h3><h4>Request</h4><pre>curl -vvv -X POST —header “Content-Type: application/json” —header “project_id: &lt;YOUR-PROJECT-ID&gt;” —header “Authorization: key=&lt;YOUR-PROJECT-SECRET-KEY&gt;” —data @- “https://android.googleapis.com/gcm/notification&quot; &lt;&lt; EOF<br>{ <br> “operation”: “add”,<br> “notification_key_name”: “asdf”,<br> “notification_key”: “&lt;NOTIFICATION-ID&gt;”,<br> “registration_ids”: [“&lt;REGISTRATION-ID-FROM-DEVICE&gt;”]<br>}<br>EOF</pre><h4>Response</h4><p>HTTP/1.1 200 OK</p><pre>{“notification_key”:”&lt;NOTIFICATION-ID&gt;”}</pre><h3>Send to a single registration id:</h3><h4>Command</h4><pre>curl -vvv -X POST —header “Content-Type: application/json” —header “project_id: &lt;YOUR-PROJECT-ID&gt;” —header “Authorization: key=&lt;YOUR-PROJECT-SECRET-KEY&gt;” —data @- “https://android.googleapis.com/gcm/send&quot; &lt;&lt; EOF<br>{ <br> “registration_ids”: [“&lt;REGISTRATION-ID-FROM-DEVICE&gt;”],<br> “data”: {},<br>}<br>EOF</pre><h4>Response</h4><pre>{“multicast_id”:6938855486830250566,”success”:1,”failure”:0,”canonical_ids”:0,”results”:[{“message_id”:”&lt;SOME_ID&gt;”}]}</pre><h3>Send to a notification id</h3><h4>Command</h4><pre>curl -vvv -X POST —header “Content-Type: application/json” —header “project_id: &lt;YOUR-PROJECT-ID&gt;” —header “Authorization: key=&lt;YOUR-PROJECT-SECRET-KEY&gt;” —data @- “https://android.googleapis.com/gcm/send&quot; &lt;&lt; EOF<br>{ <br> “to”: “&lt;NOTIFICATION-ID&gt;”,<br> “data”: {},<br>}<br>EOF</pre><h4>Response</h4><pre>{“success”:1,”failure”:0}</pre><h3>Links</h3><ul><li>video — <a href="http://youtu.be/owhf42SZadk?t=7m50s">http://youtu.be/owhf42SZadk?t=7m50s</a></li><li>documentation — <a href="http://developer.android.com/google/gcm/notifications.html#response-send">http://developer.android.com/google/gcm/notifications.html#response-send</a> (sadly uncomplete and soemtimes wrong)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7df385b0ff4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/notifications-d7df385b0ff4">GCM User Notifications</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create lightweight login screen background]]></title>
            <link>https://medium.com/appunite-edu-collection/create-lightweight-login-screen-background-10fb31e9b518?source=rss-2db85a7cbbe8------2</link>
            <guid isPermaLink="false">https://medium.com/p/10fb31e9b518</guid>
            <dc:creator><![CDATA[Jacek Marchwicki]]></dc:creator>
            <pubDate>Fri, 18 Jul 2014 07:51:25 GMT</pubDate>
            <atom:updated>2014-09-02T18:49:12.075Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*YJ6pGjXPLyFZ7_QpuJmptw.png" /></figure><h3>Large background problem</h3><p>Recently it has become popular to design UI with a large bitmap in the background — the same as on the screenshot aside. However designers usually don’t think about the problem with the application size. We should cover all devices shapes and sizes including tablets with xxhdpi density. Such approach will lead us to a dramatic increase in the application size: single background image for xxhdpi density is 3600x2180px and after <a href="http://cl.ly/image/461u1H2P0c0A/logo_jpeg.jpg">60% jpeg compression it takes 887kB</a>, what is obviously too much. What is more, we have to prepare the same image for low-res devices to bypass OutOfMemoryException. In total our apk file gets increased by ~2MB for single image in all resolutions.</p><h3>WebP solution</h3><p>The idea to solve presented problem is to use WebP format. Firstly, we save the image as .png to have the best possible quality (btw. .png image is ~8MB). Then we use <a href="https://developers.google.com/speed/webp/docs/using">cwebp</a> converter to get webp file — just type following command:</p><pre>cwebp -q 80 bg_login_screen.png -o bg_login_screen.webp</pre><p>I would recommend to convert it several times with different quality levels. Personally, I decided to use 40% because it was still looking better than .jpg, what was my intention. I was shocked with the results — <a href="http://cl.ly/1Z0S230F0k1q/bg_login_screen.webp">higher quality image</a> (quality meant as average human-eye impressions) was almost 4x smaller than jpg (228kB).</p><h3>Supporting older platforms</h3><p>However there is an issue — WebP is only supported since Jelly Bean (4.2.1+). Don’t worry, there a solution for this problem. Older devices have lower quality displays, so what we can do is convert this image to 800x800px (“Samsung Galaxy S” size in portrait/landscape) and then. Then we use 30% jpeg compression to get new file which takes only 64kB.</p><h3>Numbers</h3><p>We pack all these files:</p><pre>.//drawable-nodpi/bg_login_screen.jpg — 64kB<br>.//drawable-hdpi-v19/bg_login_screen.webp — 92kB<br>.//drawable-mdpi-v19/bg_login_screen.webp — 52kB<br>.//drawable-xhdpi-v19/bg_login_screen.webp — 128kB<br>.//drawable-xxhdpi-v19/bg_login_screen.webp — 228kB<br>Overall: 564kB</pre><h3>Summarize</h3><p>I think this is quite impressive to not only shrink our login screen from ~2MB to 564kB, but also get slightly better image quality.</p><h4>Authors</h4><ul><li>Jacek Marchwicki</li></ul><h4>Corrections:</h4><ul><li>Natalia Osiecka</li><li>Piotr Krystyniak</li><li>Maciej Ulatowski</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10fb31e9b518" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appunite-edu-collection/create-lightweight-login-screen-background-10fb31e9b518">Create lightweight login screen background</a> was originally published in <a href="https://medium.com/appunite-edu-collection">Appunite Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>