<?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 Robin on Medium]]></title>
        <description><![CDATA[Stories by Robin on Medium]]></description>
        <link>https://medium.com/@dev_padawan?source=rss-e65fd879a38------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YAvGVe6blssDQJEpvOttdQ.png</url>
            <title>Stories by Robin on Medium</title>
            <link>https://medium.com/@dev_padawan?source=rss-e65fd879a38------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:52:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dev_padawan/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[How to setup Kotlin Multiplatform on M1 and get the best possible results.]]></title>
            <link>https://medium.com/geekculture/how-to-setup-kotlin-multiplatform-on-m1-and-get-the-best-possible-results-b4fb759ec8b7?source=rss-e65fd879a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4fb759ec8b7</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Robin]]></dc:creator>
            <pubDate>Wed, 25 Aug 2021 09:23:01 GMT</pubDate>
            <atom:updated>2021-08-25T14:17:15.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GOGOsG6S0cBz5WtV" /><figcaption>Photo by <a href="https://unsplash.com/@cmalquist?utm_source=medium&amp;utm_medium=referral">Clayton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s say you just bought a new M1 Mac and you are excited to hop on the kotlin multiplatform train, You already do Android and you have setup your Mac to run with an <strong>arm64</strong> supported JDK such as <a href="https://www.azul.com/downloads/?package=jdk">azul JDK</a> .</p><p>You’ve got this multiplatform project you want to check out or you just created a new project yourself with the KMM plugin.</p><p>Everything is fine and peachy, you run the android app (on Android Studio) which treats the kotlin multiplatform module as a library and everything works fine.</p><p>Then you run the iOS app (on XCode) which uses kotlin native to bundle the module as a framework and….. It fails? 😲</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9742d4d781579aae2ace9940095d8c/href">https://medium.com/media/bf9742d4d781579aae2ace9940095d8c/href</a></iframe><p>You furiously google a solution but you soon find several solutions like this <a href="https://github.com/JetBrains/kotlin-native/issues/4034#issuecomment-837950575">here</a> and this old <a href="https://youtrack.jetbrains.com/issue/KT-43596">youtrack issue</a> that suggest you should use an <strong>intel x64 jdk</strong>.</p><p>You also find this <a href="https://yaxarat.medium.com/setting-up-the-correct-environment-for-kotlin-multiplatform-mobile-development-in-m1-apple-silicon-fa9ee62d0c1d">detailed article on the problem </a>and it all dawns on you that you have you may have to forgo some of the M1 performance benefits that you currently enjoy.</p><p><a href="https://github.com/JetBrains/kotlin-native/issues/4034#issuecomment-837950575">NoClassDefFoundError: Could not initialize class llvm.llvm · Issue #4034 · JetBrains/kotlin-native</a></p><p>If you grumbled like me (I did 😂), There is a way to get the native benefits while still doing multiplatform. First you have to understand that the issue exists because konan the kotlin native compiler version does not not support arm64 jdk thereby causing issues with the low level virtual machine (llvm).</p><p>Upon doing a little research I found out that there was a way to get early access support for M1 on the <a href="https://blog.jetbrains.com/kotlin/2021/07/kotlin-1-5-30-m1-released/">jetbrains blog</a>.</p><p><a href="https://blog.jetbrains.com/kotlin/2021/07/kotlin-1-5-30-m1-released/">Preview of Kotlin 1.5.30 With Native Apple Silicon Support, Improved Kotlin DSL for the CocoaPods Gradle Plugin, and More | The Kotlin Blog</a></p><p>So changing the multiplatform koltin gradle plugin to point to 1.5.30-M1 <a href="https://search.maven.org/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin/1.5.30-M1/jar">dependency</a> should solve the problem right?</p><p><a href="https://search.maven.org/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin/1.5.30-M1/jar">Maven Central Repository Search</a></p><p>Well…. Not exactly. If you are running the app on an iPhone, you should have no issues building but if your target device is a simulator, you get hit with this issue.</p><blockquote>ld: warning: building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64</blockquote><p>Shocked because the article clearly states support for <strong>iosSimulatorArm64. </strong>You furiously google other solutions but quickly find ones that say you should <a href="https://stackoverflow.com/a/68301640/7093155">run XCode under rosetta</a> to get it to work.</p><p>If you grumbled yet again, there is a solution for that which is excluding arm64 from simulator builds. This should get your app up and running in XCode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RhBNCpEjKjcMlhsprKJqWw.jpeg" /></figure><p>So in summary, you didn’t have to change your jdk, you only had to change the plugin version and in addition you only do a minor tweak in XCode if you want to run on simulators while retaining M1 native-ish performance.</p><p>Thanks for reading, stay caffeinated!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4fb759ec8b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-setup-kotlin-multiplatform-on-m1-and-get-the-best-possible-results-b4fb759ec8b7">How to setup Kotlin Multiplatform on M1 and get the best possible results.</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Fundamentals (A shallow dive)]]></title>
            <link>https://medium.com/swlh/spring-fundamentals-a-little-tour-of-the-block-761d00c0def0?source=rss-e65fd879a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/761d00c0def0</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Robin]]></dc:creator>
            <pubDate>Sun, 24 May 2020 13:30:24 GMT</pubDate>
            <atom:updated>2020-06-20T20:16:03.100Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ro2xGlFiFnZpPlcT" /><figcaption>Photo by <a href="https://unsplash.com/@seletcky?utm_source=medium&amp;utm_medium=referral">Mark Seletcky</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello! This article is on spring fundamentals. If you have been hearing about the spring framework and you don’t know what it is, then this article is for you.</p><h4>The Problem</h4><p>To understand the solution which is <strong>spring</strong> in this case, we must look at the problem to know what was wrong and exactly what the solution fixes.</p><p>Developing Java enterprise apps was in a weird place once upon a time and it made code hard to <strong>test</strong>, <strong>maintain</strong> and <strong>scale</strong>. There was a lot of complexity and codes didn’t focus on the business logic but more on the configuration.</p><h4>The Solution</h4><p>Spring came out as a way to easily do things in Java Development. It enabled programmers to easily configure applications through the use of annotations or XML based configurations. It’s original concept was to provide an alternative to EJB but it has grown a lot more than that.</p><p>This enabled developers to focus on the important code or business logic which increased productivity.</p><h4>How it works</h4><p>Spring can be simply thought of as a registry where our POJO’s are stored. It can be visualized as storing our beans inside a container and then making these beans available for access in our apps easily</p><h3>Ways to configure Spring beans</h3><h4>XML configuration</h4><p>This approach is often seen as simpler to some. It separates concerns because the configuration is done in a separate xml file usually called <strong>applicationContext.xml </strong>( optional naming convention)<strong> </strong>and usually looks like the xml below.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;beans xmlns=&quot;<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>&quot;<br> xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br> xsi:schemaLocation=&quot;<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a> <br> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">http://www.springframework.org/schema/beans/spring-beans.xsd</a>&quot;&gt;</pre><pre>&lt;bean name=&quot;userRepository&quot; <br>       class=&quot;com.robinson.repository.HibernateUserRepositoryImpl&quot; /&gt;</pre><pre>&lt;bean name=&quot;userService&quot; <br>    class=&quot;com.robinson.service.UserServiceImpl&quot; autowire=&quot;byType&quot; /&gt;</pre><pre>   // Setter Injection by xml<br>  &lt;property=&quot;userRepository&quot; ref =&quot;userRepository&quot; /&gt;</pre><pre>   // Constructor Injection by xml<br>   &lt;constructor-arg index=&quot;0&quot; ref=&quot;userRepository&quot; /&gt;</pre><pre>&lt;/bean&gt;</pre><p>Above you can see that it contains an xml namespace and bean declarations, but what are <strong>beans</strong>?</p><p><strong>Beans</strong> are just essentially POJOs in apps, using <strong>beans</strong> here replaces calling the new keyword. Using the xml file in our Application class should be done like this</p><pre>ApplicationContext appContext = new ClassPathXmlApplicationContext(&quot;applicationContext.xml&quot;);<br>  <br>UserService service = appContext.getBean(&quot;userService&quot;, UserService.class);</pre><h4><strong>How do we use these beans?</strong></h4><p>We can use these beans we have defined here in other places by using constructor injection and setter injection.</p><p>Constructor injection and setter injection are as you must have guessed, it involves using the constructor and setter methods to get bean value. I am not going to talk much about them. I will talk about Autowiring later.</p><h4>Annotation Configuration Using XML</h4><p>This is another way similar to what we did earlier but here we use annotations and add a component scanner in our XML.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;beans xmlns=&quot;<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>&quot;<br> xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br> xsi:schemaLocation=&quot;<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a> <br> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">http://www.springframework.org/schema/beans/spring-beans.xsd</a>&quot;&gt;<br>xmlns:context=&quot;<a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a>&quot;<br>xsi:schemaLocation=&quot;...<br><a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a><br><a href="http://www.springframework.org/schema/context/spring-">http://www.springframework.org/schema/context/spring-</a><br>context.xsd&quot;&gt;</pre><pre>&lt;context:annotation-config/&gt;<br>&lt;context:component-scan base-package=&quot;com.robinson&quot;/&gt;</pre><p>Here we can see we add the context namespace, annotation config and component scanner to look in the<strong> com.robinson </strong>package.</p><p>We use<strong> stereotype annotations</strong> to mark the classes we want and <strong>@Autowired </strong>to set it up. I will talk about the stereotype annotations later</p><h4>Java Configuration</h4><p>This is the last and by far the best way to configure spring applications. It is preferred because you do not have to use any xml for your configurations and everything is done in the Java file.</p><pre>@Configuration<br>@ComponentScan({“com.robinson&quot;})<br>public class AppConfig {</pre><pre><a href="http://twitter.com/Bean">@Bean</a>(name=&quot;userService&quot;)<br>public UserService getUserService() {<br>UserServiceImpl userService = new UserServiceImpl();<br>userService.setUserRepository(getUserRepository());<br>return userService;<br>}</pre><pre><a href="http://twitter.com/Bean">@Bean</a>(name = &quot;userRepository&quot;)<br>public UserRepository getUserRepository() {<br>return new HibernateUserRepositoryImpl();<br>}<br>}</pre><p>applicationContext.xml is replaced by @Configuration as a class level annotation. We can choose to use constructor, setter or property injection. We can also optionally remove bean declarations here and use stereotypes to declare them like in the previous section.</p><pre><a href="http://twitter.com/Repository">@Repository</a>(&quot;userRepository&quot;)<br>public class HibernateUserRepositoryImpl implements UserRepository{}</pre><h4>Stereotype annotations</h4><p>These are annotations that help define beans in applications. The main ones are <strong>@Component</strong>, <strong>@Service</strong>, <strong>@Repository</strong>. They are semantically the same<br><strong>@Component</strong> is usually used with any POJO.<strong> @Service</strong> is used in business logic layer and not web service. <strong>@Repository</strong> is used in the data layer.</p><p>Using stereotype annotation in our repository would look something like this</p><pre><a href="http://twitter.com/Repository">@Repository</a>(&quot;userRepository&quot;)<br>public class HibernateUserRepositoryImpl implements UserRepository{}</pre><h4>Autowire</h4><p>There are four options when it comes to auto wiring. Spring wires beans <strong>byType</strong>, <strong>byName</strong>, <strong>constructor</strong> or <strong>no</strong>.</p><p><strong>ByName</strong> simply means that the bean will be gotten by it’s defined name , <strong>byType</strong> means that it would be gotten via it’s type or class, <strong>constructor</strong> is self explanatory and means that it will be autowired to the constructor. <strong>no</strong> is the last choice which asks spring not to autowire anything for us</p><h4>Bean Scopes</h4><p>Beans generally have 5 Scopes. Two which are valid in any configuration and includes <strong>Singleton</strong> and <strong>Prototype</strong>. The other 3 are valid only in web-aware Spring projects and include <strong>Request, Session </strong>and<strong> Global. </strong>Scopes here are somewhat similar to <strong>design patterns</strong> we already know.</p><p><strong>Singleton</strong> is the default scope and is use when no scope is defined. Like the design pattern, it creates an instance of the bean if it has not been created before and caches it for reuse.</p><p><strong>Prototype</strong> scope forces or guarantees a new unique instance of the bean to be created whenever the bean is needed from the container and is the total opposite of the singleton scope.</p><p><strong>Request </strong>generates a new bean per HTTP request, <strong>Session </strong>generates and uses the same been throughout the users session and <strong>Global </strong>will return a single bean per application and will be shared throughout the application.</p><p>Adding a scope to the app should look like this</p><pre><a href="http://twitter.com/Service">@Service</a>(&quot;userService&quot;)<br><a href="http://twitter.com/Scope">@Scope</a>(&quot;singleton&quot;)<br>public class UserServiceImpl implements UserService {}</pre><h4><strong>Properties</strong></h4><p>This is a great way to abstract out important information that cannot be hard-coded in the app. Can be done with xml like this</p><pre>&lt;context:property-placeholder location=&quot;app.properties&quot; /&gt;</pre><pre>&lt;bean name=&quot;userRepository&quot;<br>class=&quot;com.robinson.repository.HibernateUserRepositoryImpl&quot;&gt;<br>&lt;property name=&quot;dbUsername&quot; value=&quot;${dbUsername}&quot;/&gt;<br>&lt;/bean&gt;</pre><p>can be configure in Java like this</p><pre><a href="http://twitter.com/Configuration">@Configuration</a><a href="http://twitter.com/PropertySource"><br>@PropertySource</a>(&quot;app.properties&quot;)<br>@ComponentScan({&quot;com.robinson&quot;})</pre><pre><a href="http://twitter.com/Bean">@Bean</a><br>public static PropertySourcesPlaceholderConfigurer<br>getPropertySourcesPlaceholderConfigurer() {</pre><pre>return new PropertySourcesPlaceholderConfigurer();<br>}</pre><p>value is used like this in code</p><pre><a href="http://twitter.com/Value">@Value</a>(&quot;${dbUsername}&quot;)<br>private String dbUsername;</pre><p><strong>Note: </strong>To do certain things with spring you need to add it’s dependencies to your code and I recommend spring boot because of it’s ease. Thanks for reading and as usual, leave alike only if it was helpful 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=761d00c0def0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/spring-fundamentals-a-little-tour-of-the-block-761d00c0def0">Spring Fundamentals (A shallow dive)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Expandable RecyclerViews with the groupie library]]></title>
            <link>https://medium.com/@dev_padawan/expandable-recyclerviews-with-the-groupie-library-51626fe836af?source=rss-e65fd879a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/51626fe836af</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Robin]]></dc:creator>
            <pubDate>Sat, 23 May 2020 05:20:18 GMT</pubDate>
            <atom:updated>2020-05-23T05:44:23.557Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8ZggCldpsuy311Oe" /><figcaption>Photo by <a href="https://unsplash.com/@glenncarstenspeters?utm_source=medium&amp;utm_medium=referral">Glenn Carstens-Peters</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> (Making a list)</figcaption></figure><p>I recently had to implement an expandable recyclerView to an app I was building and was confused as to what to use and how to go about it.</p><p>I weighed my options and choice of Libraries and at the current time of writing, I found <a href="https://github.com/lisawray/groupie">Groupie</a> by <a href="https://twitter.com/lisawrayz">lisawrayz</a> and <a href="https://github.com/thoughtbot/expandable-recycler-view">ExpandableRecyclerview</a> to be the best options. In this article, I will be showing you how to use <a href="https://github.com/lisawray/groupie">Groupie</a> to make an expandable recyclerView.</p><p>Just to be clear, Groupie does more than expandable recyclerView’s, it’s a library that helps you make complex RecyclerView’s.</p><p>It makes it easy to do all the things your regular recyclerView can do and even more but with less code than you would have to write. It supports diffing and animating moves, updates and other changes too.</p><h4>What we will be making</h4><p>For this example, I will use a simple app scenario since I cannot share exactly what I was working on due to certain reasons.</p><p>Our app will be a simple screen that shows a <strong>parent list</strong> of artists and a <strong>child</strong> sub-list of all the albums they have made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*S1U_Yf3uqLqTxO4peGp7vA.png" /><figcaption>Final App</figcaption></figure><p>In the child, we will simply show a generic album name for all artists but you can do whatever you like for your own app. Lets get started!</p><h4>Dependencies</h4><p>To use groupie, you have add the dependency to your build.gradle file.</p><pre>implementation &quot;com.xwray:groupie:$groupie_version&quot;</pre><p>Visit the github repo to get the latest groupie version.</p><p>In our example, I will be using the Kotlin android extensions dependency too. Groupie includes a module for Kotlin and Kotlin Android extension. This means I don’t have to write any viewHolders… Yay!</p><pre>implementation &quot;com.xwray:groupie-kotlin-android-extensions:$groupie_version&quot;</pre><h4>Item Layouts</h4><p>First we create our item_list_parent. This will show the top level items. You can see that it simply contains a text, a CardView and an image to indicate if the layout is expanded or not.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.cardview.widget.CardView<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_gravity=&quot;center&quot;<br>    android:elevation=&quot;12dp&quot;<br>    android:layout_margin=&quot;4dp&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;&gt;<br><br>    &lt;androidx.constraintlayout.widget.ConstraintLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:padding=&quot;20dp&quot;&gt;<br><br>        &lt;TextView<br>            android:id=&quot;@+id/parent_text_title&quot;<br>            style=&quot;@style/TextAppearance.EditText.Secondary&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_marginStart=&quot;21dp&quot;<br>            android:gravity=&quot;center&quot;<br>            android:text=&quot;Artist&quot;<br>            android:textColor=&quot;@android:color/black&quot;<br>            android:textSize=&quot;18sp&quot;<br>            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>            app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>            app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;<br>        &lt;/TextView&gt;<br><br>        &lt;ImageView<br>            android:id=&quot;@+id/indicator&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:src=&quot;@drawable/ic_collapsed_indicator&quot;<br>            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>            app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>            app:layout_constraintHorizontal_bias=&quot;0.925&quot;<br>            app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>            app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>            app:layout_constraintVertical_bias=&quot;0.505&quot;&gt;<br>        &lt;/ImageView&gt;<br><br>   &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br>&lt;/androidx.cardview.widget.CardView&gt;</pre><p>Next we create our item_list_child, this is the file to show what our second level child should look like. In our case it simply contains a textview widget that is centered.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:paddingTop=&quot;20dp&quot;<br>    android:paddingBottom=&quot;20dp&quot;&gt;<br><br>    &lt;TextView<br>        android:id=&quot;@+id/child_textTitle&quot;<br>        style=&quot;@style/TextAppearance.Profile.Primary&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:gravity=&quot;center&quot;<br>        android:text=&quot;Design UI&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;<br><br><br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><h4>Add the Recyclerview to the layout</h4><p>Next we add the Recycerview to the mainActivity layout xml. This is done just like normal. The next part is where things get interesting.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:context=&quot;.MainActivity&quot;&gt;<br><br>    &lt;androidx.recyclerview.widget.RecyclerView<br>        android:id=&quot;@+id/xRecyclerView&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>        tools:listitem=&quot;@layout/item_list_parent&quot;&gt;<br><br>    &lt;/androidx.recyclerview.widget.RecyclerView&gt;<br><br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><p>When making RecyclerViews the normal way, this is the part where we would have to make the Adapter and ViewHolder and start working with the model classes.</p><p>Groupie makes all that easy for us by providing us with convenient classes and Extensions we can use.</p><h4>ExpandableHeaderItem</h4><p>To represent our item views, Groupie gives us the concept of Item. Each Item declares a view layout id, and gets a callback to bind the inflated layout.</p><p>We will make a class called ExpandableHeaderItem by Inheriting from the already created Item() class.</p><p>In our case, the Item() class we are using is from the<strong> android extensions </strong>package (com.xwray.groupie.kotlinandroidextensions) and <strong>not</strong> the regular package (com.xwray.groupie). Inheriting from this package makes it possible to work without a ViewHolder explicitly defined.</p><pre>class ExpandableHeaderItem(val title: String) : Item() , <strong>ExpandableItem </strong>{<br>    private lateinit var expandableGroup: ExpandableGroup<br><br>    override fun bind(viewHolder: GroupieViewHolder, position: Int) {<br><br>        viewHolder.<em>root</em>.parent_text_title.<em>text </em>= title<br>        viewHolder.itemView.setOnClickListener <strong>{<br>            </strong>expandableGroup.onToggleExpanded()<br>            changeStuff(viewHolder)<br>        <strong>}<br><br>    </strong>}<br><br>    override fun getLayout(): Int {<br>        return  R.layout.<em>item_list_parent<br>    </em>}<br><br>    private fun changeStuff(viewHolder: GroupieViewHolder) {<br><br>        viewHolder.<em>root</em>.indicator.apply <strong>{<br>            </strong>setImageResource(<br>                if (expandableGroup.<em>isExpanded</em>) R.drawable.<em>ic_expanded_indicator<br>                </em>else R.drawable.<em>ic_collapsed_indicator</em>)<br>        <strong>}<br><br>    </strong>}<br><br>    override fun setExpandableGroup(onToggleListener: ExpandableGroup) {<br>        this.expandableGroup = onToggleListener<br>    }<br><br><br>}</pre><p>From the code we can see that we can see that there are two methods we must override which is the <strong>getLayout() </strong>method where we return the xml layout we created and the <strong>bind()</strong> method.</p><p>You may also notice that we implemented the <strong>ExpandableItem </strong>interface and overrode it’s method. This is done to show that we want to create an expandable header Item specifically.</p><p>We define a clickListener for the item (the whole layout) and call the method <strong>changeStuff() </strong>and <strong>expandableGroup.onToggleExpanded()</strong>. The <strong>changeStuff() </strong>method simply toggles our indicator image to display the correct one for both the expanded and collapsed state.</p><p>The <strong>expandableGroup.onToggleExpanded()</strong> call simply toggles the the parent item state.</p><h4>ChildItem</h4><p>Next we create a class for the child item views. This is similar to what we did with the ExpandableHeaderItem. We also override the <strong>getLayout()</strong> and <strong>bind() </strong>methods</p><pre>open class ChildItem( val title : String) : Item() {<br><br>    override fun bind(viewHolder: GroupieViewHolder, position: Int) {<br>        viewHolder.<em>root</em>.child_textTitle.<em>text </em>= title<br><br>    }<br>    override fun getLayout(): Int {<br>        return R.layout.<em>item_list_child<br>    </em>}<br><br>}</pre><h4>Wiring it all together</h4><p>Finally, we wire up all the details together.</p><pre>class MainActivity : AppCompatActivity() {<br><br>    private val groupAdapter = GroupAdapter&lt;GroupieViewHolder&gt;()<br>    private lateinit var groupLayoutManager: LinearLayoutManager<br><br>    private val childList = <em>listOf</em>(<br>        ChildItem(&quot;First Album&quot;),<br>        ChildItem(&quot;Second Album&quot;),<br>        ChildItem(&quot;Third Album&quot;),<br>        ChildItem(&quot;Fourth Album&quot;)<br><br>    )<br><br>    private val parentList = <em>listOf</em>(<br>     ExpandableHeaderItem(&quot;Travis Scott&quot;),<br>    ExpandableHeaderItem(&quot;Migos&quot;),<br>    ExpandableHeaderItem(&quot;Post Malone&quot;),<br>    ExpandableHeaderItem(&quot;Drake&quot;)<br><br>    )<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br>        groupLayoutManager = LinearLayoutManager(this)<br><br>        xRecyclerView.apply <strong>{<br>            </strong><em>layoutManager </em>= groupLayoutManager<br>            <em>adapter </em>= groupAdapter<br>        <strong>}<br><br><br>        </strong>groupAdapter.apply <strong>{<br>            </strong>for (i in parentList){<br>                this += ExpandableGroup(i).apply <strong>{<br>                    </strong>for (j  in childList) {<br>                        add(j)<br>                    }<br>                <strong>}<br><br>            </strong>}<br>        <strong>}<br>    </strong>}<br>}</pre><p>We create a groupAdapter where all our items will enter. In our example, we create two lists, one for the child items that will show when the parent has been expanded and the parent items themselves.</p><p>In a real world scenario, data such as this should not be hardcoded but retrieved from something like the viewModel and populated to the groupAdapter.</p><p>We loop through our parent Items and add them to the groupAdapter. We also loop through the child items and call the already defined add() function on the data.</p><p>That is it!</p><h4>Tada!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*IcOzMyEC2Iz-alowuNd-ZQ.gif" /><figcaption>Final App</figcaption></figure><p>It’s worth mentioning again that the app can get more complex than this, you can manage complex cases easily with groupie.</p><p>For more info and insights on Groupie, I recommend you check out the library <a href="https://github.com/lisawray/groupie">sample here</a>. If you want to get the code to this specific sample I made here, is <a href="https://github.com/codejunk1e/Groupie_Expandable_RectclerView_sample">hosted here on my github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51626fe836af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Servlets and JSP — A beginners guide]]></title>
            <link>https://medium.com/@dev_padawan/servlets-and-jsp-a-beginners-guide-54c539f93614?source=rss-e65fd879a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/54c539f93614</guid>
            <category><![CDATA[java-server-pages]]></category>
            <category><![CDATA[jsp]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[java-enterprise]]></category>
            <category><![CDATA[java-servlet]]></category>
            <dc:creator><![CDATA[Robin]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 08:51:07 GMT</pubDate>
            <atom:updated>2020-04-30T09:05:47.383Z</atom:updated>
            <content:encoded><![CDATA[<h3>Servlets and JSPs— A beginners guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VJzmCloQL-0IyPcvqc59kA.png" /><figcaption>Starting a web application on IntelliJ</figcaption></figure><p>So you’re interested in developing web applications in Java but you have come across different talks about Servlets and Java Server Pages (JSP) and you want to know what they mean, this article is for you.</p><h3>Why learn about this?</h3><p>Before anyone learns anything new they must have learning goals and targets or even a good reason to learn that particular thing at minimum.</p><p>If you on the other hand have not found a good reason why you would want to learn this, it is important that I bring to your attention that such low level concepts are still useful even if not as popular a it used to be.</p><p>Also frameworks such as Struts build upon such low level details and knowledge of the internals will help you find your way when you run into errors building with such tools.</p><h3>The Server</h3><p>It is important to note that to run Servlet applications, you need a web sever like Apache TomCat installed on your machine.</p><p>Java EE IDE’s like Eclipse and IntelliJ come with support for tomcat and you can start your server once it is configured. If you are running a Linux machine, you can read my article on how to get it setup.</p><p><a href="https://medium.com/@dev_padawan/how-to-setup-apache-tomcat-9-on-ubuntu-the-easy-way-5dc434113797">How to setup Apache TomCat 9  on Ubuntu the easy way</a></p><h3>What are Servlets?</h3><p>Simply put, servlets are web application components that resides on the server side and generates dynamic web pages.</p><p>The servlet interface is a protocol agnostic interface. It describes how to configure the servlet and the servlet lifecycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*OKDuL1pJPMIFvTblLqz8fw.png" /><figcaption>Servlet Inerface</figcaption></figure><h3>The Servlet Life Cycle</h3><p>The life-cycle of a servlet is managed by the Servlet container. The life-cycle methods for the servlet interface are the init(), destroy() and service() methods.</p><p>The init() method is first called when the servlet is initialized, then the service() method to handle the clients request and then the destroy() method is called once during the end of the servlet life-cycle.</p><p>The configuration method for the servlet interface include serverletConfig() and getServerletInfo() methods. As the names suggest, the former is used to get configuration info about the servlet from the web.xml file and the latter is used to get information about the servlet itself like its name or copyright notice.</p><p>The service() method is where the main work is done using the two params, req and resp. It is worth noting that we <strong>do not implement</strong> the servlet interface directly, but there are other implementations for the interface provided for us to work with.</p><h3>The GenericServlet class</h3><p>The GenericServlet class is a non protocol specific abstract base class for protocol specific implementations to extend. It implements the <strong>Servlet</strong>, , <strong>ServletConfig</strong> and <strong>Serializable</strong> interfaces.</p><h3>The HttpServerlet class</h3><p>The HttpServerlet class is a protocol specific class. If you had taken a guess here, you would have been correct. The protocol here is HTTP (Hypertext Transfer Protocol). It extends the GenericServlet class.</p><p>HttpServerlet class provides several methods to help us work with http specific implementation of the service method like the doPost() and doGet() methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*hOabyl58WlyEAbeeAuMK4w.png" /><figcaption>HttpServerlet class</figcaption></figure><h3>Creating Our Servlets</h3><p>We create our own servlets by exending HttpServlet class. We can override methods such as doGet() and doPost().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*AduRhCYdD8UYBOLHsPthAQ.png" /><figcaption>Our own created servlet</figcaption></figure><p>After creating our servlet the server cannot navigate without adding the servlet mapping. There are two ways to do this which includes using annotations or the web.xml file.</p><p>Annotations can be used like this <a href="http://twitter.com/WebServlet"><strong>@WebServlet</strong></a><strong>(“/blog”)</strong> to depict a path that should trigger calling the servlet or something like <a href="http://twitter.com/WebServlet"><strong>@WebServlet</strong></a><strong>(urlPatterns = { “/blog”, “*.kv”}) </strong>which specifies a path and an extension .kv as multiple url patterns.</p><p>For the web.xml file, we first register the servlet and then add a servlet mapping. Multiple mappings can be added to a single servlet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*DlOEi1PJrtnHz8HFP_ixdQ.png" /><figcaption>servlet mapping via web.xml file</figcaption></figure><h3>Java Server Pages (JSP)</h3><p>JSP or Java Server Pages are used to create applications just like Servlet. JSP’s are compiled to serverlets and usually a mixture of text, scripts and directives.</p><p>JSP provide more functionality than a servlet with features such as expression language, Java Standard Tag Library (JSTL), Directives etc.</p><h3>Directives</h3><p>Simply put JSP directives are the messages to JSP container. Some major directives include the page directive, include directive and taglib directive. Learn more about directive usage via the link.</p><p><a href="https://www.javatpoint.com/jsp-page-directive">JSP Directives | JSP Page Directive - javatpoint</a></p><p>Below is an example of using a directive to specify that the page is an error page.</p><pre>&lt;%@ page isErrorPage=”true” %&gt;</pre><p>Directives can also be used to specify things like autoFlush, buffer etc. They can be used to access Java Beans but using the expression language is simpler.</p><pre><strong>//Acessing the bean from JSP</strong></pre><pre>&lt;% User user = (User)request.getAttribute(&quot;user&quot;);<br>    if(user == null){<br>       user = new User();<br>}%&gt;</pre><pre><strong>// Use bean with directive</strong><br>&lt;h2&gt;Welcome &lt;%= user.getName() %&gt;&lt;/h2&gt;</pre><p>The example above is a simple snippet where directives are used to access beans and also use the bean.</p><h3>JSP Expression language</h3><p>The Expression language was created for a variety of reasons, some of which include that Java was not flexible and non-friendly to non Java folks who work in the front-end.</p><p>You may have noticed that in directives we used in the first part, we actually had to write Java code. EL gives us the ability to do common things we may have otherwise had to write code for. It is worth noting that in EL you don’t have access to full blown language features.</p><p>For the above example where we used directives to get a value from a bean, we can do it in EL with simple syntax like this. This replaces the java code we wrote earlier and looks into all the scopes to get the value.</p><pre><strong>${user.name}</strong></pre><p>The Expression language can be used to access arrays, lists, maps and other beans. Learn more about expression language via the link.</p><h3>Java Standard Tag Library (JSTL)</h3><p>Tags provide encapsulation for UI logic and replace scripts on page, it is also better than writing Java. The JSP Standard Tag Library (JSTL) represents a set or collection of tags to simplify JSP development. Some advantages of using it include Fast Development and Code Re-usability.</p><p>JSTL can be grouped into the following: Core tags, Formatting tags, SQL tags, XML tags, Function tags.</p><h3>End Credits</h3><p>It is worth mentioning that I am by no means an expert, but simply a padawan on my quest to become a Jedi developer and saw a good chance to share knowledge.</p><p>Thank you for reading the article. This short article is inspired by a cool course on pluralsight by <strong>Kevin Jones </strong>which i took recently. Check out the link for more info.</p><p><a href="https://app.pluralsight.com/library/courses/java-web-fundamentals/table-of-contents">Java Web Fundamentals</a></p><p>Will be writing a longer article on the java web fundamentals to cover other stuff like filter, listeners and MVC in servlets. Will update this article it’s link. Thank you!</p><p>As usual, leave a clap<strong> only</strong> if it was helpful 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54c539f93614" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup Apache TomCat 9  on Ubuntu the easy way]]></title>
            <link>https://medium.com/@dev_padawan/how-to-setup-apache-tomcat-9-on-ubuntu-the-easy-way-5dc434113797?source=rss-e65fd879a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dc434113797</guid>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jsp]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[tomcat]]></category>
            <dc:creator><![CDATA[Robin]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 00:06:55 GMT</pubDate>
            <atom:updated>2020-04-13T00:06:55.294Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to setup Apache TomCat 9 on Ubuntu the easy way</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*AfPW1Rn8f6XmRF78cd-ISQ.jpeg" /><figcaption>The apache tomcat logo</figcaption></figure><p>Apache Tomcat is an open source Java servlet container that implements several core Java enterprise specs, namely the Java Servlet, JavaServer Pages (JSP), and WebSockets APIs. So if for what so ever reason you find yourself playing with these technologies, Apache TomCat is a must have.</p><h3>Java Installation</h3><p>You must have java installed on your machine for Apache TomCat to work. The supported java version at the time of writing for TomCat 9 is java 8 and above.</p><p>If you already have java installed check your java version with:</p><pre>java -version</pre><p>If you don’t have java installed, or you are running a lower version, install it with:</p><pre>sudo apt-get update<br>sudo apt-get install default-jdk</pre><h3>Get TomCat</h3><p>After confirming your java versions are correct, you need to download Tomcat from the <a href="https://tomcat.apache.org/">official download site</a> to get the latest version.</p><p>Download the archive file and extract to the desired location, something like <strong>/usr/local/apache-tomcat-9.x.xx</strong> is great</p><h3>Configure Environment Variables</h3><p>You need to configure the required environment variables for Tomcat. Set eviroment variables for <strong>CATALINA_HOME </strong>and java.</p><pre>echo &quot;export CATALINA_HOME=&quot;/usr/local/apache-tomcat-9.x.xx&quot;&quot; &gt;&gt; ~/.bashrc<br>echo &quot;export JAVA_HOME=&quot;/usr/lib/jvm/java-8-openjdk-amd64&quot;&quot; &gt;&gt; ~/.bashrc<br>echo &quot;export JRE_HOME=&quot;/usr/lib/jvm/java-8-openjdk-amd64&quot;&quot; &gt;&gt; ~/.bashrc<br>source ~/.bashrc</pre><h3><strong>Setup TomCat User Accounts</strong></h3><p>create user accounts to secure and access admin/manager pages. Edit the <strong>conf/tomcat-users.xml </strong>file in your tomcat install</p><pre>&lt;!-- user manager can access only manager section --&gt;<br>&lt;role rolename=&quot;manager-gui&quot; /&gt;<br>&lt;user username=&quot;manager&quot; password=&quot;password&quot; roles=&quot;manager-gui&quot; /&gt;</pre><pre>&lt;!-- user admin can access manager and admin section both --&gt;<br>&lt;role rolename=&quot;admin-gui&quot; /&gt;<br>&lt;user username=&quot;admin&quot; password=&quot;password&quot; roles=&quot;manager-gui,admin-gui&quot; /&gt;</pre><h3>Running Tomcat</h3><p>Tomcat server can be started by navigating to the install, getting execution access on the files and runing startup.sh.</p><p>In my case I prefer getting execution access for all the files in the bin folder.</p><pre>cd /usr/local/apache-tomcat-9.x.xx<br>chmod +x ./bin<br>./bin/startup.sh</pre><p>You should see something like this</p><pre>Using CATALINA_BASE:   /home/kemosabe_x/Desktop/apache-tomcat-9.0.34<br>Using CATALINA_HOME:   /home/kemosabe_x/Desktop/apache-tomcat-9.0.34<br>Using CATALINA_TMPDIR: /home/kemosabe_x/Desktop/apache-tomcat-9.0.34/temp<br>Using JRE_HOME:        /usr/lib/jvm/java-8-openjdk-amd64<br>Using CLASSPATH:       /home/kemosabe_x/Desktop/apache-tomcat-9.0.34/bin/bootstrap.jar:/home/kemosabe_x/Desktop/apache-tomcat-9.0.34/bin/tomcat-juli.jar<br>Tomcat started.</pre><p>Tomcat works on port 8080 by default so to access it in a browser use</p><pre>http://localhost:8080</pre><p>You should get this screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_TvJk_D_BSKk7rM0O7A3Pw.png" /></figure><h3>Stopping TomCat</h3><p>Navigate to the install bin folder and run ./shutdown.sh</p><pre>cd /usr/local/apache-tomcat-9.x.xx/bin<br>./shutdown.sh</pre><p>That’s it, Thanks for reading! Leave a clap only if it was helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dc434113797" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>