<?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 Reza Bigdeli on Medium]]></title>
        <description><![CDATA[Stories by Reza Bigdeli on Medium]]></description>
        <link>https://medium.com/@rezabigdeli6?source=rss-e0b687d4d761------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Gn9dVOwyQw22bS8PtOh5jg.jpeg</url>
            <title>Stories by Reza Bigdeli on Medium</title>
            <link>https://medium.com/@rezabigdeli6?source=rss-e0b687d4d761------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 05:53:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rezabigdeli6/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[Compose’s Composition]]></title>
            <link>https://proandroiddev.com/composes-composition-3df7821eb7d6?source=rss-e0b687d4d761------2</link>
            <guid isPermaLink="false">https://medium.com/p/3df7821eb7d6</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack-navigation]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[androidx]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Reza Bigdeli]]></dc:creator>
            <pubDate>Sat, 20 Jan 2024 18:02:51 GMT</pubDate>
            <atom:updated>2024-01-21T15:41:37.454Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_QlS9GrUKMVfHoCzbWOuA.jpeg" /></figure><h4>Best practices to use Compose with other Jetpack libs</h4><p>Being a UI toolkit, Jetpack <a href="https://developer.android.com/jetpack/compose">Compose</a> is in rather direct contact with most of the other libraries in the <a href="https://developer.android.com/topic/architecture#ui-layer">UI layer</a>. From dependency injection to ViewModel and from Multi-Module navigation to Testing.<br>Now the challenge, as usual, is to put these different puzzle pieces next to each other so that we can make a beautiful whole.</p><p>For demonstration purposes, imagine we have an email app with a lot of Compose code. We’ll try to see if we can find any room for improvement.</p><h4><a href="https://developer.android.com/jetpack/compose/state-hoisting">State Hoisting</a></h4><p>Let’s start with our first file for a screen that shows the details of an email based on its ID using a <a href="https://developer.android.com/topic/libraries/architecture/viewmodel">ViewModel</a> that has a <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/">StateFlow</a> to expose the view state:</p><pre>// EmailScreen.kt<br><br>@Composable<br>fun EmailScreen(id: String) {<br>  val viewModel: EmailViewModel by ...<br>  viewModel.fetchEmail(id)<br><br>  val email by viewModel.stateFlow.collectAsState()<br>  <br>  Column {<br>    Text(&quot;Subject: ${email.subject}&quot;)<br>    Text(email.body)<br>    Button(onClick = { viewModel.archive(id) }) {<br>      Text(&quot;Archive&quot;)<br>    }<br>  }<br>}</pre><p>So what are the problems with this code, other than its ability to make a UI designer cry?<br>Firstly, injecting a ViewModel inside our screen would create two problems.</p><ol><li>We can’t use @Preview anymore as Compose doesn’t know how to create it in the preview phase.</li><li>We would have to mock the entire ViewModel rather than just passing a mocked state of the screen.</li><li>We are actually fetching the email on each <a href="https://developer.android.com/jetpack/compose/mental-model#recomposition">recomposition</a> by calling fetchEmail().</li></ol><p>To fix them, you might be tempted to pass the ViewModel to the function as a parameter, but it won’t fix either of the issues. How about passing the StateFlow as a parameter? Try it yourself to see if you detect its issues.</p><p>Passing the email to the EmailScreen() as a parameter seems to fix all the issues. We also need to pass the archive button clicks back up as events because we won’t have the ViewModel here anymore:</p><pre>// EmailScreen.kt<br><br>@Preview<br>@Composable<br>fun EmailScreen(<br>  @PreviewParameter(EmailProvider::class) email: Email,<br>  onArchiveClick: () -&gt; Unit = {}<br>) {<br>  Column {<br>    Text(&quot;Subject: ${email.subject}&quot;)<br>    Text(email.body)<br>    Button(onClick = onArchiveClick) {<br>      Text(&quot;Archive&quot;)<br>    }<br>  }<br>}</pre><p>Great! As you can see, now we can use @preview easily using <a href="https://developer.android.com/jetpack/compose/tooling/previews#preview-data">PreviewParameter</a> and to test this composable function, all we need to do is to pass a mocked email:</p><pre>// EmailScreenTest.kt<br><br>@Test<br>fun `when archive is clicked then the callback is called`() {<br>  val listener = Mockito.mock(CustomArchiveListener::class.java)<br>  composeTestRule.setContent { EmailScreen(mockedEmail, listener::onArchiveClick) }<br>  <br>  with(composeTestRule) {<br>    onNodeWithText(mockedEmail.body).assertExists()<br>    onNodeWithText(&quot;archive&quot;).assertExists().performClick()<br>    verify(listener).onArchiveClick()<br>  }<br>}</pre><h4><a href="https://developer.android.com/guide/navigation/integrations/multi-module">Multi-Module Navigation</a></h4><p>One of the most common ways to <a href="https://developer.android.com/topic/modularization/patterns#common-modules">modularize an Android project</a> is to put each screen or flow of screens in its own module (called “feature” from here on).<br>Separating these UI modules means that they normally won’t have access to each other.</p><p>Our example project has two feature modules. One called ui:inbox to show the list of emails received, and another called ui:email to show the content of an email. Let’s take a look at the navigation logic to see what problems we can find:</p><pre>// MailNav.kt file inside app module,<br>// that has access to all other modules<br><br>@Composable<br>fun MainNav(navController: NavHostController) {<br>  NavHost(...) { // this: NavGraphBuilder<br>    composable(<br>      route = &quot;inbox&quot;,<br>      onEmailClick = { emailId -&gt; navController.navigate(&quot;email/$emailId&quot;) }<br>    ) {<br>      ...<br>    }<br>    composable(<br>      route = &quot;email/{emailId}&quot;,<br>      onArchiveClick = ...<br>    ) {<br>      ...<br>    }<br>  }<br>}</pre><p>As you can see, even though I used a couple of “…”, a lot is going on there. The first thing is that some navigation details, like the route, can be encapsulated better. The second is that the navigation parameters are not <a href="https://dev.to/ayodejii/type-safety-and-strong-typing-what-are-these-terms-3io5#:~:text=The%20type%20safety%20feature%20of,only%20allowed%20on%20string%20types.">type-safe</a>. The good news is that Google has some recommended <a href="https://www.youtube.com/watch?v=goFpG25uoc8">best practices</a> for us. So let’s divide the navigation logic into separate parts and move them into their respective modules. Using extension functions on NavGraphBuilder and NavController:</p><pre>// InboxNav.kt file inside ui:inbox module<br><br>fun NavGraphBuilder.inboxScreen() {<br>  composable(route = &quot;inbox&quot;) {<br>    InboxScreen(...)<br>  }<br>}<br><br>fun NavController.navigateToInbox() {<br>  navigate(route = &quot;inbox&quot;)<br>}</pre><pre>// EmailNav.kt file inside ui:email module<br><br>fun NavGraphBuilder.emailScreen() {<br>  composable(route = &quot;email/{emailId}&quot;) {<br>    EmailScreen(...)<br>  }<br>}<br><br>fun NavController.navigateToEmail(emailId: String) {<br>  navigate(route = &quot;email/$emailId&quot;)<br>}</pre><p>This way, not only did we hide and encapsulate the navigation details, but we also made the parameters type-safe. Now our Main Nav.kt would look like:</p><pre>// MainNav.kt file inside app module<br><br>@Composable<br>fun MainNav(navController: NavHostController) {<br>  NavHost(...) { // this: NavGraphBuilder<br>    inboxScreen(<br>      onEmailClick = { emailId -&gt; navController.navigateToEmail(emailId) }<br>    )<br>    emailScreen()<br>  }<br>}</pre><h4><a href="https://developer.android.com/jetpack/compose/libraries#hilt">Dependency Injection</a> and ViewModels</h4><p>The only missing part is to inject our ViewModel. So, let’s get back to our EmailNav.kt file. By injecting the ViewModel here, events like onArchiveClick can be handled here, and other events, like navigation events, can be passed up:</p><pre>// EmailNav.kt file inside ui:email module<br><br>fun NavGraphBuilder.emailScreen() {<br>  composable(route = &quot;email/{emailId}&quot;) {<br><br>    val viewModel: EmailViewModel = hiltViewModel()<br>    viewModel.fetchEmail(...)<br>    val email by viewModel.stateFlow.collectAsState()<br><br>    EmailScreen(<br>      email = email,<br>      onArchiveClick = { viewModel.onArchive(email.id) }<br>    )<br>  }<br>}<br><br>fun NavController.navigateToEmail(emailId: String) {<br>  navigate(route = &quot;email/$emailId&quot;)<br>}</pre><p>The last issue we should fix is to move emailId into the ViewModel‘s constructor so we don’t have to fetch it using fetchEmail() on each recomposition. This is where <a href="https://developer.android.com/topic/libraries/architecture/viewmodel/viewmodel-savedstate">SavedStateHandle</a> comes in to help. We can move back to our EmailNav.kt to get the email ID in a type-safe manner:</p><pre>// EmailNav.kt file inside ui:email module<br><br>fun NavGraphBuilder.emailScreen() {<br>  ...<br>}<br><br>fun NavController.navigateToEmail(emailId: String) {<br>  ...<br>}<br><br>internal val SavedStateHandle.emailId: String<br>  get() = checkNotNull(this[&quot;emailId&quot;])</pre><p>And in our ViewModel:</p><pre>// EmailViewModel.kt file inside ui:email module<br><br>@HiltViewModel<br>class EmailViewModel @Inject constructor(<br>  savedStateHandle: SavedStateHandle,<br>  ...<br>) {<br><br>  private val emailId: String = savedStateHandle.emailId<br><br>  init {<br>    // fetch email based on emailId and update the stateFlow<br>  }<br>}</pre><p>And that’s it!… I know, I know! I may not have been fully honest about this being type-safe. The Compose compiler does not offer full type safety <strong>yet</strong>. But at least this way we are doing all the risky operations in one place (i.e., routing and parameter parsing), which lowers the risk of producing weird bugs.</p><h4>TL;DR</h4><p>The Jetpack libraries have great compatibility with each other, which makes integrating them easy! And with them comes a good amount of best practices we can follow to have easier lives.<br>You can check out my <a href="https://gitlab.com/black-goblin/android/safebook">half-baked project on Gitlab</a>, where I try to follow these best practices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3df7821eb7d6" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/composes-composition-3df7821eb7d6">Compose’s Composition</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[BaseActivity and BaseFragment are monsters]]></title>
            <link>https://proandroiddev.com/baseactivity-and-basefragment-are-monsters-5cda31639938?source=rss-e0b687d4d761------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cda31639938</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Reza Bigdeli]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 11:44:41 GMT</pubDate>
            <atom:updated>2022-03-21T13:21:46.160Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*W1fP3YPBzyRL3lDf_Z5HpQ.png" /><figcaption><a href="https://www.pinterest.com/pin/650136896186464940/?autologin=true">Are you a car? Are you a robot? Should I extend car with 4 wheels or should I extend humanoid robot with two legs?!?!?!?!?!?!?</a></figcaption></figure><h4>An old tale of composition over inheritance, sort of!</h4><p>One of the good practices when writing code is “Reusability”. Instead of writing the same code multiple times, we should write it once and use it wherever we need to. Simple as that!<br>Well not so fast! How can we achieve it though? The first thing that comes to mind is to find the similarities/duplications and put them in a base class. This way whoever that is extending our base class can have the functionalities out of the box without needing to write them over again! But there is a problem with this approach,. Our base class tends to get messy, creepy and hard to touch after sometime, specially in the languages that don’t allow extending from two or more classes.<br>A day to day normal example would be that of a BaseActivity. We tend to put a lot of logic in that class, things like layout inflation, analytics, activity/permission results, et cetera. We start off with something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e33ddca5404e2b95e2f7e92614b19bf3/href">https://medium.com/media/e33ddca5404e2b95e2f7e92614b19bf3/href</a></iframe><p>Pretty clean, right? Well maybe now but not in a month. Specially when you introduced a ton of callbacks, implemented a lot of interfaces and added a big deal of logic! Your base activity is going to look eventually like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a28870840875bb1ac44efa9099fa90a/href">https://medium.com/media/3a28870840875bb1ac44efa9099fa90a/href</a></iframe><p>You see what I mean? Have fun extending this class, let alone refactoring or bug fixing it! No need to mention migrating to new technologies is going to be extra troublesome if your base activity is dependent on old tech.</p><p>OK, so how can we go about fixing it?</p><h4>Layout inflation</h4><p>If you are only worried about layout inflation for your activities and don’t want to repeat setContentView() all the time, then simply use AppCompatActivity(@LayoutRes contentLayoutId: Int) constructor from androidx.activity:activity-ktx:1.1.0 and for fragments Fragment(@LayoutRes contentLayoutId: Int)constructor fromandroidx.fragment:fragment-ktx:1.2.0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f1ffae723427f5d25dfdf2fb8f0910b/href">https://medium.com/media/8f1ffae723427f5d25dfdf2fb8f0910b/href</a></iframe><h4>Setting up toolbar</h4><p>To setup toolbar just use extension functions on activities and/or fragments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6840fac241543332a8e00da9e60a5857/href">https://medium.com/media/6840fac241543332a8e00da9e60a5857/href</a></iframe><p>This way only the activities who actively want to setup a toolbar would use it! And if some activities have a particular way of setting up their toolbar, then they can use another method or just write it their own way!</p><h4>Activity/Permission results</h4><p>This shouldn’t be something that make people use base classes but if you are using a base class to handle these stuff, maybe take a look at <a href="https://developer.android.com/training/basics/intents/result">ActivityResultContract</a> in androidx.activity:activity:1.2.0-alpha04</p><h4>Analytics</h4><p>To send tracks and do analytics stuff based on activity/fragment callbacks you can just use ActivityLifecycleCallbacks in your Application class for activities and for fragments you can use FragmentLifecycleCallbacks</p><h4>When to use Inheritance then?</h4><p>As discussed, when it comes to addressing duplications and code reusability, it seems that Inheritance isn’t the right approach. Instead we should try to use functions or compose smaller classes!<br>But if we are trying to bring about a new framework by creating a new concept of an activity and adding some new functionality and properties that are local and native to the new concept, then Inheritance is the right approach. And I wouldn’t suggest BaseActivity as its name! Maybe something like MyFrameworkActivity.</p><p>We should also acknowledge that there isn’t a fine line that determines when to use what approach!</p><h4>TL;DR</h4><p>To make your code reusable don’t try putting everything in a giant base activity or fragment (inheritance), instead introduce composition with the help of extension functions or dividing logic into different classes. Because:</p><ol><li>It makes it easy to migrate to new tech/architecture.</li><li>It makes it easy to start writing new activities and fragments, that are well know by all developers, instead of making them understand your version of activities and fragments!</li><li>Plus all the <a href="https://javarevisited.blogspot.com/2013/06/why-favor-composition-over-inheritance-java-oops-design.html">benefits composition brings over inheritance!</a></li></ol><p>TBH, I couldn’t find a use case or a good reason for using base activities or base fragments. Let me know if you know of a good one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cda31639938" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/baseactivity-and-basefragment-are-monsters-5cda31639938">BaseActivity and BaseFragment are monsters</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[Follow platform UI guidelines? Or invent our own?]]></title>
            <link>https://uxdesign.cc/follow-platform-ui-guidelines-or-invent-our-own-d1d67c7e8c0e?source=rss-e0b687d4d761------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1d67c7e8c0e</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Reza Bigdeli]]></dc:creator>
            <pubDate>Mon, 20 May 2019 23:08:39 GMT</pubDate>
            <atom:updated>2019-05-23T05:38:09.839Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*9f79m2W5tBLTny8-VzpgXg.jpeg" /><figcaption><a href="https://material.io/">material.io</a></figcaption></figure><h4>An Android developer’s perspective…</h4><ul><li>Our app shouldn’t look like other apps</li><li>We should have our own UI language</li><li>It is cheaper and faster to have a unified design for both Android and iOS</li><li>Standard views and stock widgets look cheap</li></ul><p>These and many others are the points that UI/UX designers try to make to tell us we shouldn’t follow <a href="https://material.io/design/">Material Design</a> for Android and <a href="https://developer.apple.com/design/">Human Interface Guidelines</a> for iOS, and to convince us to have our own custom icons, our own custom buttons and views and widgets and gestures and navigation and...</p><p>But should we? Let’s investigate each point one by one and answer the one million dollar question once and for all.. Not really.</p><h4>Our app shouldn’t look like other apps</h4><p>Why? Isn’t it all what UX is about? A consistence flow? To better explain what I mean I should give you an example. So one day we got my mother her first smartphone. She was quite used to her old conventional phone, so at first she couldn’t really work with it. But all we did was to teach her how to work with a messaging app named <a href="https://telegram.org/">Telegram</a> so she could chat with us. It was a little bit hard for her to learn the keyboard and navigation and all that, but after some time she started learning and exploring and doing the stuff faster. Because of working with Telegram she learned to work with <a href="https://play.google.com/store?hl=en">Play Store</a> and Messages and a lot of other apps. She learned the meaning of <a href="https://material.io/design/components/navigation-drawer.html">Navigation Drawer</a> so she already knew how to open navigation drawers in any other app that followed Material Design. She understood the meaning of <a href="https://material.io/design/components/buttons-floating-action-button.html">Floating Action Buttons</a>. All because these apps followed the same UI guidelines. They were consistent! They had a consistent flow. If you learn one you know how to work with the others! Instead of waisting time to understand new views and their jobs, the user can actually try to understand the application’s main functionality!<br>So let me ask you again: Isn’t it all what UX is about?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*hdoxuoYkEgzojm8y__9NHQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*3hWdF1RG2-ZdFbPwtFMXTg.jpeg" /><figcaption>These designs are different but they are using the same UI guideline, thus the user doesn’t need to learn the meaning of FAB or Burger Icon. They already know where to find the search functionality or how to open the Navigation Drawer.</figcaption></figure><h4>We should have our own UI language</h4><p>Are you telling me that we should reinvent the wheel? Okay let’s reinvent it! How many hours, how many user researches and experiments, how much are we going to invest and spend to understand what is the correct look for a button?! Does it look clickable enough? Does it look unclickable enough when it’s disabled?! Are our radio buttons look right? If you ask your designer they would probably say: “Yeah! I think they are obvious enough! They look good!”. Well ask them this question now : “On what basis? On what basis a button should look this and not like that? Did you invest as much as Google or Apple invested? Did you researched as much them? Or is it just your personal taste?”</p><p>When a designer says that we should invent our own UI language, it’s like when a developer says we should first invent our own programming language.<br>No! We should use the wheel! Use the platform UI guidelines and spend your time on the UX! Just like when a developer uses the platform programming language and spends time on finding the best software architecture.</p><p>Let’s face it: no user is excited enough to explore or/and try to learn our new apps! You can not count on that. You cannot say that we are going to teach them our design! When was the last time you enthusiastically tried to understand and explore an app that you just installed? Other than Tinder?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tE5SFFOrQBH8qEjQHObe1A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*p1aXxlJM4B3uUDy-KdTIRQ.jpeg" /><figcaption><a href="https://www.whatsapp.com/">Whatsapp</a> follows platform UI guidelines. The Android version and the iOS version are not like each other, but the users of each platform understand the app easily. They don’t need to be like each other</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*hdoxuoYkEgzojm8y__9NHQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*nPR-9G9mdrXKNchJV9u9fw.jpeg" /><figcaption>Telegram also has different designs for each platform. If an iOS user wants to search, they wouldn’t look for a search icon, they would try to find the search box! Also an Android user understands the relation between burger icon and Navigation Drawer but these terms are irrelevant for an iOS user.</figcaption></figure><h4>It is cheaper and faster to have one unified design for both Android and iOS</h4><p>Now it’s getting actually interesting! The amount of time that a developer should spend on creating UI and views that are not native to the platform, the amount of hacks and implantations that they should go through is much, much more than for a designer to actually use native views in their design. Most of the time a designer would show the developer an image and say: “When you swipe down this happens, when you click on this that happens!”. And it’s the job of the developer to make the designer wishes come true! Now it’s the job of the developer to implement, support and maintain these custom views for each Android or iOS versions! And you can always find new bugs now and then, all because you didn’t use the native views. Even if you take none of these points into account, you are going to stuck in each platform limitations or characteristics. Let’s say you want to have a Navigation Drawer in the iOS version of your app, then the iOS developer should add the swiping gesture to open the drawer which is totally against the platform gesture behaviour, because it is reserved for going back in the screen stack! It’s a navigation gesture.<br>So which one is faster or/and cheaper again?</p><h4>Standard views and stock widgets look cheap</h4><p>This is actually my favorite point. So are you actually suggesting that Google Photos or Play Store or even App Store or Apple Pages look cheap?<br>Not to my eyes but it’s really a matter of personal taste! Again you should always be able to back your point with some basis!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*DEFN1hB2IHhoBziKvguj6Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*Q6AwRtyDf6pKhV16bVYzPw.jpeg" /><figcaption><a href="https://play.google.com/store/apps/details?id=com.google.android.apps.maps">Google Maps</a> vs <a href="https://www.swarmapp.com/">Swarm</a>. Which one look cheaper?</figcaption></figure><h4>TL;DR:</h4><p>We should follow each platform UI guidelines. They are well known to the user and using them gives us more time to actually focus on the UX itself. They are also easy for the developer to implement and maintain on each version of the platform.</p><p>But I know, as designers you guys like to go crazy with the creativity and fun ideas. Great! That’s why we have web!<br>Web isn’t any companies platform! It’s a neutral environment. So here you shouldn’t follow Material Design or some other companies UI guidelines. You should make it special! Something unique for your company. As matter of fact every other company is doing the same thing.</p><p>Follow platform UI guidelines. If you are not on any platform do whatever you see fit!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vm7mpjVbQxI1HzxwhRXYtQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iiGJtdP3eXlLZh2i_D8egg.jpeg" /><figcaption>Whatsapp and Telegram websites are not using other companies UI guidelines because web is a neutral environment.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1d67c7e8c0e" width="1" height="1" alt=""><hr><p><a href="https://uxdesign.cc/follow-platform-ui-guidelines-or-invent-our-own-d1d67c7e8c0e">Follow platform UI guidelines? Or invent our own?</a> was originally published in <a href="https://uxdesign.cc/">UX Collective</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 Send a Semi Secure Request to a Server in Android]]></title>
            <link>https://medium.com/@rezabigdeli6/how-to-send-a-semi-secure-request-to-a-server-in-android-359b11b4e873?source=rss-e0b687d4d761------2</link>
            <guid isPermaLink="false">https://medium.com/p/359b11b4e873</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[native-app]]></category>
            <dc:creator><![CDATA[Reza Bigdeli]]></dc:creator>
            <pubDate>Thu, 14 Jan 2016 15:15:22 GMT</pubDate>
            <atom:updated>2020-09-29T09:36:26.707Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Disclaimer: This article is written a couple of years ago. There should be a lot of better ways to tackle this issue. Yet, I don’t think reading this article would be of no value.</em></p><p>Imagine that you have a server for your Android application. What the server does is registering the users of the application and creates accounts for them. But the problem here is, as usual, security. What if a hacker sniff your requests from the application and just creates the same structured requests and sends them to your server to fill its database with fake users. Of course there are some solutions for this type of attack, for example CAPTCHAS, but again the problem is CAPTCHAS will ruin the UX of your application. I mean who wants to write a bunch of nonsense when signing up in Instagram application? So is there a way to somehow stop a hacker from attacking our server without needing us to destroy our valuable UX? Well I believe I have a solution.</p><p>The solution has some steps to follow and in each step a problem will arise and we will try to solve them along the way to get to what we want which is a secure valid request to the server.</p><h4>Step One: Just Respond to Application Requests</h4><p>If we make the server to only respond to the requests sent from the application we can be a little bit more sure that requests are sent from a real person who is using our application, not a bot or a program of a hacker. But how does the server know a request is sent from the application? Well we can put some kind of encryption into our requests, for example using <em>RSA </em>we can have a private key, put it into the application, and encrypt the requests. So this way the hacker who is sniffing our requests wouldn’t know what we are doing and what information are we sending so they can’t go ahead and make fake requests.</p><pre>String email = emailEditText.getText().toString();<br>String password = passwordEditText.getText().toString();<br><br>String privateKey = <strong>&quot;ourPrivateKey&quot;</strong>;<br><br>String cipherRequest = encrypt(email, password, privateKey);<br><br>sendRegistrationRequest(cipherRequest);</pre><p>But the new problem here is that decompiling an Android application isn’t that hard, actually it’s pretty easy. There are tons of decompiling applications on the web that will decompile our <em>APK</em> to the java code that we have written. Of course there are some obfuscating approaches, like <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwjsgu_Mp6nKAhUDjnIKHXk7AtAQFggdMAA&amp;url=http%3A%2F%2Fdeveloper.android.com%2Ftools%2Fhelp%2Fproguard.html&amp;usg=AFQjCNEQhLwyE_EKrNsc-qlaGIaSmrTGxA&amp;sig2=XC2zUB6MeK5OuzKbTNOJjA"><em>ProGuard</em></a><em> </em>that you <strong>should</strong> use, but they wouldn’t stop a determined hacker to find our private key in our code. So even with obfuscating, after decompilation our code will look like this:</p><pre>bundle = <strong>new </strong>EditText(<strong>this</strong>);<br>EditText edittext = <strong>new </strong>EditText(<strong>this</strong>);<br>sendRegistrationRequest(encrypt(bundle.getText().toString(), edittext.getText().toString(), <strong>&quot;ourPrivateKey&quot;</strong>));</pre><p>As you can see finding the <em>key</em> isn’t that hard. So what do we do?</p><h4>Step two: Use Native Code</h4><p>In android you can write some or all of your code in <em>c/c++</em> languages using <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwjnybLUsanKAhWFqXIKHQovAm8QFggdMAA&amp;url=http%3A%2F%2Fdeveloper.android.com%2Ftools%2Fsdk%2Fndk%2Findex.html&amp;usg=AFQjCNEwVSx09Hgmfvhy2wvixQtDtpQh1g&amp;sig2=YFWd0PGZ4UmUA2L4qBWRGA"><em>NDK</em></a><em>.</em> The important thing is you have to know when to use it. I am not going to explain when to use native code but in our situation we are going to benefit from it. Decompiling <em>c/c++</em> code is possible and there some tools to do it but a <em>c/c++</em> decompiled code is a complete nonsense. Understanding and debugging a <em>c/c++</em> decompiled code is super complex and time consuming. And again of course a hacker can go all the way down to the machine code but at least we can make it as hard and as boring and as time consuming as possible. So our step two is to put our <em>private key</em> into the native code. So after doing so our code would look like this:</p><pre><strong>public native </strong>String encrypt(String email, String password);<br><br>@Override<br><strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>    <em>// ...<br><br>    </em>String email = <strong>emailEditText</strong>.getText().toString();<br>    String password = <strong>passwordEditText</strong>.getText().toString();<br><br>    String cipherRequest = encrypt(email, password);<br><br>    sendRegistrationRequest(cipherRequest);<br><br>    <em>// ...<br></em>}</pre><p>But wait a minute! Even if the hacker can’t find our <em>key</em> they can go ahead and manipulate or <em>Java</em> code or take the whole of our <em>c/c++ </em>library and method and call it in their own program with their code. If they create a <em>for </em>loop and generate random emails and passwords they can use our <em>c/c++</em> library against us and create a ton of fake valid requests. Their code can be like this:</p><pre><strong>public native </strong>String encrypt(String email, String password);<br><br>@Override<br><strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>    <em>// ...<br><br>    </em><strong>while </strong>(<strong>true</strong>) {<br>        String email = generateRandomEmail();<br>        String password = generateRandomPassword();<br><br>        String cipherRequest = encrypt(email, password);<br><br>        sendRegistrationRequest(cipherRequest);<br>    }<br><br>    <em>// ...<br></em>}</pre><p>So how do we stop this from happening!?</p><h4>Step three: Use Other Factors</h4><p>We know that they can use our library just like we are using it. But the advantage of using native code is that we can be, to some extend, sure that:</p><ul><li>First: They don’t have access to our private <em>key </em>so if they want to create requests they <strong>have to </strong>use our library.</li><li>Second: They can’t see or manipulate our native code and logic.</li></ul><p>So we can use and check a lot of factors and bring in a lot of checking in our native code. For example to counteract the <em>for</em> loop we can send the encrypted data back to the <em>java</em> code with a little of delay. This will take the power of machine from it and make it more like a normal person who is trying to register many times. And at the same time, delaying for half a second wouldn’t be as annoying as <em>CAPTCHAS </em>for someone who is trying to register. Or we can send something unique along with the email and password to the server so it can find repetitive requests and simply ignore them. That unique thing can be lots of things like the <em>processId</em> that is the identifier of the process’s <em>UID</em>. This is the kernel <em>UID</em> that the process is running under, which is the identity of its app-specific sandbox. The <em>processId </em>wont change when its package is installed on the device so every time that you get your <em>processId </em>it is the same, but it can be different in another device. You can get your <em>processId </em>in native code using <em>getuid()</em>, when including <em>unistd.h</em> and <em>sys/types.h </em>so if the server gets a lot of requests with the same unique factor, here <em>processId, </em>in a short amount of time it can simply ignore them. Also you can check the package name in your native code and a lot of other things. The important key is the hacker doesn’t really know what you are doing in there.</p><h3>Secured?</h3><p>No, not really. That is why I put the “semi” word in the title. We did a lot of things and used a lot of methods to make the things hard for the hacker but as I said a determined hacker can do anything. But making things hard for them can dissuade them from doing their job or at least gives you some time to change your approach or find a better way in your next release.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=359b11b4e873" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>