<?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 Jitendra Prajapati on Medium]]></title>
        <description><![CDATA[Stories by Jitendra Prajapati on Medium]]></description>
        <link>https://medium.com/@jkprajapati?source=rss-8c7dd93f07e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ePlm4LTeG_gf683abB6sbQ.png</url>
            <title>Stories by Jitendra Prajapati on Medium</title>
            <link>https://medium.com/@jkprajapati?source=rss-8c7dd93f07e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:34:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jkprajapati/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[type aliases in Kotlin]]></title>
            <link>https://jkprajapati.medium.com/type-aliases-in-kotlin-2887a83123be?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2887a83123be</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Tue, 18 Jun 2024 03:05:22 GMT</pubDate>
            <atom:updated>2024-07-19T06:14:02.536Z</atom:updated>
            <content:encoded><![CDATA[<p>In Kotlin, type aliases are essentially nicknames you give to existing types. They don’t create new types, but rather provide a more descriptive or concise way to refer to them.</p><p>Here are some key points about type aliases:</p><ul><li><strong>Readability:</strong> They can improve code readability, especially when dealing with long or complex types. For example, instead of writing HashMap&lt;String, ArrayList&lt;Int&gt;&gt;, you could define a type alias like ShoppingList for better clarity.</li><li><strong>Context:</strong> Type aliases can add context to a type, making the code more self-explanatory. For instance, typealias CreditCard = String clarifies that a string variable represents a credit card number.</li><li><strong>Generic Types:</strong> They can be particularly useful for shortening lengthy generic types. Imagine a Set&lt;Network.Node&gt;, you could define a type alias like NodeSet for a more manageable name.</li></ul><p>Here’s an example to illustrate:</p><pre>typealias Username = String<br><br>fun registerUser(username: Username, password: String) {<br>  // ... perform registration logic ...<br>}<br><br>val myUsername = &quot;Bard&quot;<br>registerUser(myUsername, &quot;s3cr3tp@ssw0rd&quot;)</pre><p>In this example, Username is a type alias for String. It makes the code more readable and conveys the specific purpose of the string variable.</p><p><strong>Remember:</strong></p><ul><li>The compiler rewrites type aliases to their underlying type when processing the code.</li><li>They are not new types, but simply alternative names.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2887a83123be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplifying Code with Context Receivers in Kotlin]]></title>
            <link>https://jkprajapati.medium.com/simplifying-code-with-context-receivers-in-kotlin-f919906f50e5?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f919906f50e5</guid>
            <category><![CDATA[androi]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Thu, 30 May 2024 06:38:16 GMT</pubDate>
            <atom:updated>2024-05-30T06:42:33.521Z</atom:updated>
            <content:encoded><![CDATA[<p>Kotlin, known for its expressive and concise syntax, continues to evolve with features that make developers’ lives easier. One such feature is context receivers, a powerful tool that enhances the way functions interact with multiple objects. In this blog post, we’ll explore what context receivers are, how they work, and why they can be a game-changer in your Kotlin projects.</p><h4>What Are Context Receivers?</h4><p>Context receivers allow you to specify additional context for a function, making it possible to access properties and methods of multiple objects without explicitly passing them as parameters. This feature is especially useful when you need a function to operate within the scope of several types.</p><h4>Why Use Context Receivers?</h4><blockquote><em>1. Improved Code Clarity:</em> Dependencies of a function are explicitly stated, making the code more understandable.<br>2. <em>Better Scope Management:</em> Manage multiple receivers effortlessly, resulting in cleaner and more maintainable code.<br>3. <em>Enhanced Type Safety:</em> The compiler ensures that the required contexts are available, reducing runtime errors.</blockquote><p>Let’s dive into a simple example to illustrate how context receivers work in Kotlin.</p><h4>Step 1: Define the Context Classes</h4><p>First, we’ll define two classes that represent the contexts we want to use:</p><pre>class User(val name: String)<br>class Account(val balance: Double)</pre><h4>Step 2: Define a Function with Context Receivers</h4><p>Next, we’ll create a function that requires both `User` and `Account` contexts:</p><pre>context(User, Account)<br>fun printUserInfo() {<br> println(“User: ${this@User.name}, Balance: ${this@Account.balance}”)<br>}</pre><p>In this function:<br>“context(User, Account)” specifies that “printUserInfo” needs both “User” and “Account” contexts. “this@User.name” and “this@Account.balance” access properties from the “User” and “Account” contexts.</p><h4>Step 3: Using the Function</h4><p>Now, we’ll use the function with the required contexts:</p><pre>fun main() {<br> val user = User(“Alice”)<br> val account = Account(1000.0)<br>with(user) {<br> with(account) {<br> printUserInfo()<br>    }<br> }<br>}</pre><p>Here:<br>- We create instances of “User” and “Account”.<br>- We use “with” to bring these instances into the current scope as receivers, allowing us to call “printUserInfo” seamlessly.</p><h4>Benefits of Context Receivers</h4><p><em>1. Code Clarity</em></p><p>By explicitly stating the required contexts, the function’s dependencies are clear. This eliminates the need for passing multiple objects as parameters, resulting in more readable code.</p><p><em>2. Scope Management</em></p><p>Managing multiple receivers becomes simpler and more intuitive. You can access properties and methods of all specified contexts directly within the function, without additional boilerplate.</p><p><em>3. Type Safety</em></p><p>The Kotlin compiler ensures that the required contexts are available when the function is called. This reduces the risk of runtime errors and enhances the overall robustness of your code.</p><h4>Comparison with Regular Receivers</h4><p>To better appreciate the benefits of context receivers, let’s compare them with regular receivers and extension functions.</p><p><strong>Without Context Receivers</strong></p><pre><br>fun User.printUserInfo(account: Account) {<br> println(“User: $name, Balance: ${account.balance}”)<br>}<br>fun main() {<br> val user = User(&quot;Alice&quot;)<br> val account = Account(1000.0)<br> user.printUserInfo(account)<br>}</pre><p>In this approach:</p><p>The “printUserInfo” function is an extension function on “User” and takes Account` as a parameter.<br>-While this works, it isn’t as clean or flexible as using context receivers.</p><p><strong>With Context Receivers</strong></p><p>With context receivers, the function signature is cleaner, and the dependencies are explicitly stated, enhancing readability and maintainability.</p><p><strong>Conclusion</strong></p><p>Context receivers in Kotlin provide a powerful way to specify and use multiple contexts within a function. They improve readability, manageability, and type safety, making your code more expressive and concise. As Kotlin continues to evolve, features like context receivers exemplify its commitment to developer productivity and code quality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f919906f50e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preview was unable to find a compositionlocal]]></title>
            <link>https://jkprajapati.medium.com/preview-was-unable-to-find-a-compositionlocal-d65e55bdee3e?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d65e55bdee3e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose-preview]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Sat, 22 Jul 2023 23:36:42 GMT</pubDate>
            <atom:updated>2024-02-05T17:46:28.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4KlRS1LJjRY4jMxOJNhjw.jpeg" /></figure><p>I am using <em>staticCompositionLocalOf</em>, to provide <em>LocalNavController</em> and <em>LocalSnackBarHostState</em></p><pre>val LocalNavController = staticCompositionLocalOf&lt;NavHostController&gt; {<br>    error(&quot;No LocalNavController provided&quot;)<br>}<br>val LocalSnackBarHostState = staticCompositionLocalOf&lt;SnackbarHostState&gt; {<br>    error(&quot;No LocalScaffold provided&quot;)<br>}</pre><p>In the @Composable function, I’m trying to access the local values:</p><pre>@Composable<br>fun FirstScreen() {<br>  val navController: NavController = LocalNavController.current<br>  val snackBarHostState = LocalSnackBarHostState.current<br><br> Column(modifier = Modifier.fillMaxSize(),<br>        horizontalAlignment = Alignment.CenterHorizontally)<br>   {<br>     // other code<br>   }<br>}</pre><p>When I try to render the preview, it fails with the message &quot;This preview was unable to find a CompositionLocal. You might need to define it so it can render correctly.&quot;</p><pre>@Preview(showSystemUi = true, showBackground = true)<br>@Composable<br>fun FirstScreenPreview() {<br>        FirstScreen()<br>}</pre><blockquote>One solution is to put the preview inside CompositionLocalProvider like this:</blockquote><pre>@Preview(showSystemUi = true, showBackground = true)<br>@Composable<br>fun FirstScreenPreview() {<br>CompositionLocalProvider(<br>    LocalNavController provides rememberNavController(),<br>    LocalSnackBarHostState provides remember { SnackbarHostState() },<br>){<br><br>    FirstScreen()<br>}</pre><p>For a simplicity, we can create a wrapper component,</p><pre>@Composable<br>fun ComposeLocalWrapper(content: @Composable () -&gt; Unit) {<br>    CompositionLocalProvider(<br>        LocalNavController provides rememberNavController(),<br>        LocalSnackBarHostState provides remember { SnackbarHostState() },<br>        content = content<br>    )<br>}</pre><p>This wrapper can be used in all of your project’s previews:</p><pre>@Preview(showSystemUi = true, showBackground = true)<br>@Composable<br>fun FirstScreenPreview() {<br>ComposeLocalWrapper{<br>    FirstScreen()<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d65e55bdee3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Change City on Clock Widget Lock Screen iOS 16]]></title>
            <link>https://jkprajapati.medium.com/change-city-on-clock-widget-lock-screen-ios-16-9b81b86a0d1d?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b81b86a0d1d</guid>
            <category><![CDATA[custom-clock]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[dualclock]]></category>
            <category><![CDATA[ios-16]]></category>
            <category><![CDATA[iphone]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Tue, 13 Sep 2022 13:49:40 GMT</pubDate>
            <atom:updated>2022-09-13T14:16:35.271Z</atom:updated>
            <content:encoded><![CDATA[<p>When I got update of iOS 16 on my iPhone Mini, I was excited to see lock screen customisation, but disappointed because before writing this article I could’t find a way on internet to change the city of clock on lock screen, It was stuck on Cupertino clock and no way to change, After a struggle I found a way how to change the city of Clock widget on Lock screen on iOS 16,</p><p>Here are the steps :-</p><p>Long press on lock screen and click on Customise, Select first widget, That is Calendar widget and replace/change it to Clock widget</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*wegKCXzYgrKndn8lPLvOlA.jpeg" /></figure><p>Now you will see the option to change the City, click on Word Icon 🌐 and choose the desire city and click on done</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*spYXXfXD2h-3JR8NLV_B7Q.jpeg" /></figure><p>Now again long press on lock screen and go to customise, add the clock widget, if not added, and just simple click on widget will give option to change the city for this clock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*48kgy3MaI_V6HfbmOXOzdQ.jpeg" /></figure><p>You are done, Enjoy with dual clock on Lock screen on your iPhone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*rI7UEDRkMzxV_iG-F43Pxw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b81b86a0d1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing SnackBar in JetPack Compose]]></title>
            <link>https://jkprajapati.medium.com/managing-snackbar-in-jetpack-compose-78646d4c6b8f?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/78646d4c6b8f</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[snackbar]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 07:44:52 GMT</pubDate>
            <atom:updated>2022-07-26T07:49:44.269Z</atom:updated>
            <content:encoded><![CDATA[<p>We all know that snack bar is very efficient way to show information in app, We have a different way to show SnackBar in Jetpack compose. To create and show snackBar we need SnackBarHost. Let’s understand about SnackBarHost<strong>.</strong></p><p>This is use to maintain state of the SnackBarHost, controls the queue and the current SnackBar being shown inside the SnackBarHost. we usually get that from the ScaffoldState</p><p>This state usually lives as a part of a ScaffoldState and provided to the SnackBarHost automatically, but can be decoupled from it and live separately when desired.</p><p>SnackBarHost Host for SnackBars to be used in Scaffold to properly show, hide and dismiss items based on material specification and the hostState.<br>This component with default parameters comes build-in with Scaffold,</p><p>if we need to show a default SnackBar, use <em>ScaffoldState. SnackBarHostState</em> and call showSnackBar()</p><pre>val snackBarHostState = remember <strong>{ </strong>SnackbarHostState() <strong>}</strong></pre><pre><em>Scaffold</em>(<br>    backgroundColor = MaterialTheme.colors.surface,<br>    snackbarHost = <strong>{<br>         </strong>SnackbarHost(<br>           hostState = snackBarHostState,<br>           modifier = Modifier<br>                   .<em>fillMaxWidth</em>()<br>                   .<em>wrapContentHeight</em>(Alignment.Bottom)<strong>   </strong>  <strong><br>    }<br>)</strong><br>    {<br>Box(contentAlignment= Alignment.Center){<br>     Button(<br>        onClick ={<br>          LaunchedEffect(key1 = activity)<strong>{</strong>  <br>              snackBarHostState.showSnackbar(<br>              message = &quot;Saved Successfully&quot;,<br>              duration = SnackbarDuration.<em>Indefinite</em>,<br>              actionLabel = &quot;Ok&quot;<br>          )  }<br>       }<br>    )<br>  }<br>}</pre><p>showSnackBar() Shows or queues to be shown a SnackBar at the bottom of the Scaffold at which this state is attached and suspends until snackBar is disappeared. SnackbarHostState guarantees to show at most one snackBar at a time. If this function is called while another snackBar is already visible, it will be suspended until this snack bar is shown and subsequently addressed. If the caller is cancelled, the snackBar will be removed from display and/or the queue to be displayed.</p><p>showSnackBar returns SnackBarResult, We can use this to implement our own logic, when ActionPerformed or Dismissed</p><pre>      when (result) {<br>            SnackbarResult.ActionPerformed -&gt; {<br>                /* action has been performed */<br>            }<br>            SnackbarResult.Dismissed -&gt; {<br>                /* dismissed, no action needed */<br>            }<br>        }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78646d4c6b8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Flutter Android Apps With GitHub Actions]]></title>
            <link>https://jkprajapati.medium.com/building-flutter-android-apps-with-github-actions-9ea6c0d3b23a?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ea6c0d3b23a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Fri, 15 May 2020 13:41:59 GMT</pubDate>
            <atom:updated>2022-07-26T06:50:54.456Z</atom:updated>
            <content:encoded><![CDATA[<p>I will set up an automated build for your Flutter apps using Github actions &amp; will also know how quickly Github Action will implement the concepts of an automated build and continuous integration.</p><p>Github actions is a framework for building custom workflows for software development processes. Creating your first automated build and continuous integration pipeline is now as simple as adding a single file to your pre-existing Github repository.</p><p>Lets create a branch (in mine case it actions branch) and checkout, Now we need to create a workflow file which is a YML file, In case of new in YML file, YML is a data-orientated human readable serialization language, and I have come across it in many projects including OpenAPI, Docker, Kubernetes and Ansible playbooks among others. You must store workflow files in the .github/workflows directory of your repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*wCSx6DOowgcAHBlCF0EP3w.png" /></figure><p>Here in this yml file we need to write steps to automate our build process,</p><p>Lets give a name, we can give any name, this is name will be display in workflow list in the action tab under your GitHub repository</p><pre>name: Dart CI</pre><p>Next we need to define when our workflow should run, workflow can be response to a variety of event, including commits, pushes as well as on a schedule or even manually, A great place to start however for a new continue integration pipeline is to validate code changes when a new pull request is created, we can do this using following expression.</p><pre>on:<br><br>  pull_request:<br>    branches: <em>[ </em>master <em>]</em></pre><p>Now we are ready to define the task that will be run on each pull request, to do this need to create job, Job is just Environment+Tasks, but every workflow must have at least one task</p><pre>jobs:<br>  build-and-test:</pre><p>Now we have to define our environment or the runner that will be used to execute all of the tasks.</p><pre>runs-on: ubuntu-latest</pre><p>Lets define steps that will actually run to validate our Flutter code, we will define like</p><pre>steps:<br>  - uses: actions/checkout@v1<br>  - uses: actions/setup-java@v1<br>    with:<br>      java-version: &#39;12.x&#39;<br>    name: Flutter Action<br>  - uses: subosito/flutter-action@v1.3.2<br>    with:<br>      channel: &#39;stable&#39; <em># or: &#39;dev&#39; or &#39;beta&#39;<br>  </em>- run: flutter pub get<br>  - run: flutter analyze<br>  - run: flutter build apk</pre><p>Thats it , our simple flutter workflow is ready for android platform, now we are ready to go</p><p>we will push our changes on the actions branch as we created initially, once done got to github and will see our pull request something like, this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*is7vmhXLUE22kzxYYT2Uog.png" /></figure><p>Since this is pull request, it will automatically start our workflow,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HgrgJlEPS0cIOiaWaPzAnA.png" /></figure><p>Once done successfully, we can see the log,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hn3JoYGtBbjv6qN4MMoVwg.png" /></figure><p>GitHub Actions Resources ➡️</p><p><a href="https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow">https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ea6c0d3b23a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configure Jenkins to run on AWS(EC2) & setup GitHub web hook for android apps]]></title>
            <link>https://jkprajapati.medium.com/configure-jenkins-to-run-on-aws-ec2-setup-github-web-hook-for-android-apps-72fce5aa9e2d?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/72fce5aa9e2d</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github-webhook]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Sat, 08 Feb 2020 04:32:26 GMT</pubDate>
            <atom:updated>2020-02-08T05:29:16.327Z</atom:updated>
            <content:encoded><![CDATA[<h3>Configure Jenkins to run on AWS(EC2) &amp; setup GitHub web hook for Android apps</h3><p>I am going to explain how to setup a web hook to trigger a build on Jenkins whenever a change pushed to Github, I have amazon EC2 server already running,</p><p>After launching a EC2 , connect to your instance using anyone of below method</p><ul><li>A standalone SSH client</li><li>Session Manager</li><li>EC2 Instance Connect (browser-based SSH connection)</li></ul><p>For this example I am connecting using third way that is browser-based SSH connection,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZrNIMjK8N6PFqhe05O1tQ.png" /></figure><p>Once you successfully connect, can see command line interface(CLI), like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i8wX5bnsh8gNjUf_SbdfQA.png" /></figure><p>Now it is time to install Jenkins, but that need to install Java first</p><p>execute below line to install java</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo yum install java-1.8.0</em></pre><p>To download and install Jenkins follow below:</p><ol><li>To ensure that your software packages are up to date on your instance, use the following command to perform a quick software update:</li></ol><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo yum update –y</em></pre><p>2. Add the Jenkins repo using the following command:</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo </em><a href="http://pkg.jenkins-/"><em>http://pkg.jenkins-</em></a><em> ci.org/redhat/jenkins.repo</em></pre><p>3. Import a key file from Jenkins-CI to enable installation from the package:</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo rpm — import </em><a href="https://pkg.jenkins.io/redhat/jenkins.io.key"><em>https://pkg.jenkins.io/redhat/jenkins.io.key</em></a></pre><p>4. Install Jenkins:</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo yum install jenkins -y</em></pre><p>5. Start Jenkins as a service:</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo service jenkins start</em></pre><p>Jenkins is now installed and running on your EC2 instance. To configure Jenkins go to browser and connect to <strong>http://&lt;your_server_public_DNS&gt;:8080</strong>, you can get your EC2 Public DNS from AWS console,</p><p>You will be able to access Jenkins through its management interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1iE_fNaYrL2ro5RZ2URUw.png" /></figure><p>Now to get administrator password, simply go to Command line interface and navigate to give file path and run cat command , you able to see password, enter it and go to next page,</p><pre><em>[ec2-user@ip-172–31–28–91 ~]</em>$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><p>The Jenkins installation script directs you to the <strong>Customize Jenkins </strong>page. Click <strong>Install suggested plugins</strong>.Once the installation is complete, enter Administrator Credentials, click <strong>Save Credentials</strong>, and then click <strong>Start Using Jenkins, </strong>you may asked to create new user, if required create and go to Jenkins Dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rgOyMqy2BEzVbqTwEe1G0A.png" /></figure><p>Now create a Freestyle project go to New Item -&gt; Enter name -&gt; Select Freestyle Project</p><p>Go to source control management and Select Git</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVXt3-CeZ_tIazNnXfB4qQ.png" /></figure><p>enter Repository URl, and click apply and save. if you getting any error about Git , please make sure git is install on EC2, check it by entering below line on Command line interface</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ git — version</em></pre><p>if not installed, try below line to install,</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ sudo yum install git-all</em></pre><p>once done, check the installation directory to configure in Jenkins</p><pre><em>[ec2-user@ip-172–31–28–91 ~]$ whereis git</em></pre><p>In Git section of Global Tool Configuration enter the correct path to Git executable,</p><p>Once git setup done, Select Github hook trigger for GITScm Polling in Build Triggers section in Source code management section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-f1WbRSrEGvATlmZRb3tPQ.png" /></figure><p>Now select Use Gradle Wrapper in build section to run Gradle for your android project and click on Apply and Save this configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucw66c5tLBRmuKoK_qNQ1A.png" /></figure><p>once done everything correctly, you can see this on Dashboard,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8wAt40KN1ySVlTjnolCMSw.png" /></figure><p>hopefully you able to build by clicking on Item name and selecting Build Now option, if it’s working, in final step will configure WebHook to initial a build once we push any changes to Github.</p><p>before going to setup webHook, you need to authenticate Jenkins to access gitHub, for that Enter Github user name/password on Credential section of Dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x0Rv3jZt6WxrluGYsJ2bzw.png" /></figure><p>Go to Github repo setting and add new webHook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_N4mA1pecOb3RI0BnNyHg.png" /></figure><p>Payload url will be your Jenkins url ending with “/github-webhook/”</p><p>select “just Event when you want to trigger”, thats It, New webHook is ready to trigger, once you click on add Webhook, it will test it with a delivery, you can see delivery result, if response is 200</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vx0HpYSkudwKS_MZIOsHUA.png" /></figure><p>Hope this will give a guide to configure a Github webHook for android app on Jenkins CI/CD, if any question please feel free to comment here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72fce5aa9e2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Struct Vs Class in Swift]]></title>
            <link>https://jkprajapati.medium.com/struct-vs-class-in-swift-635b17bcb4da?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/635b17bcb4da</guid>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Thu, 30 Jan 2020 10:37:51 GMT</pubDate>
            <atom:updated>2020-01-30T12:16:14.623Z</atom:updated>
            <content:encoded><![CDATA[<p>In Swift programming language, class and swift are general-purpose, You define properties and methods to add functionality to your classes and structures by using exactly the same syntax as for constants, variables, and functions.</p><p>Main difference in class an struct in swift is that structs are value types and classes are reference types.</p><p>When you make a copy of a value type, it copies all the data from the thing you are copying into the new variable. They are 2 separate things and changing one does not affect the other.</p><p>When you make a copy of a reference type, the new variable refers to the same memory location as the thing you are copying. it means that changing one will change the other since they both refer to the same memory location,</p><pre>class MyClass{</pre><pre>var name: String</pre><pre>init(name: String) {</pre><pre>self.name = name</pre><pre>}</pre><pre>}</pre><pre>var aClass = MyClass (name: &quot;Jitendra&quot;)</pre><pre>var bClass = aClass // aClass and bClass now reference the same instance!</pre><pre>bClass.name = &quot;Amit&quot;</pre><pre>println(aClass.name) // &quot;Amit&quot;</pre><pre>println(bClass.name) // &quot;Amit&quot;</pre><p>And now with a struct we see that the values are copied and each variable keeps it’s own set of values.</p><pre>struct MyStruct {</pre><pre>var name: String</pre><pre>init(name: String) {</pre><pre>self.name = name</pre><pre>}</pre><pre>}</pre><pre>var aStruct = MyStruct(name: &quot;Jitendra&quot;)</pre><pre>var bStruct = aStruct // aStruct and bStruct are two structs with the same value!</pre><pre>bStruct.name = &quot;Amit&quot;</pre><pre>println(aStruct.name) // &quot;Jitendra&quot;</pre><pre>println(bStruct.name) // &quot;Amit&quot;</pre><p>So for representing a stateful complex entity, a class is awesome. But for values that are simply a measurement or bits of related data,</p><p>a struct makes more sense so that you can easily copy them around and calculate with them or modify the values without fear of side effects.</p><p>Second difference is Automatic Initialisation of Structure in Swift</p><p>Did u notice, in Swift we can auto initialise properties, lets see I have below Struct:</p><pre>struct myStruct {<br>    let myString: String?<br>    let myInt: Int?<br>    let myDouble: Double?<br>}</pre><p>in this situation, you don’t need to write init, It has been automatically generated by swift.</p><p>when you try to initialise it and will see autocomplete.</p><p>But here you have to set all those 3 parameters with some values or nil</p><pre>myStruct(myString: &quot;Something&quot;, myInt: nil, myDouble: nil)</pre><p>One more thing you can do here is you can define init method argument optional like this:</p><pre>struct myStructWithInit {<br>    let myString: String?<br>    let myInt: Int?<br>    let myDouble: Double?<br>  <br>    init(myString: String? = nil, //<br>         myInt: Int? = nil,<br>         myDouble: Double? = nil) {<br>      <br>        self.myString = myString<br>        self.myInt = myInt<br>        self.myDouble = myDouble<br>    }<br>}</pre><p>It will give you freedom to use this struct with only one or any optional parameters. Like</p><pre>myStructWithInit(myString: &quot;Something&quot;)<br>myStructWithInit(myString: &quot;Something&quot;, myInt: 2)<br>myStructWithInit(myString: &quot;Something&quot;, myInt: 2, myDouble: 3.0)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=635b17bcb4da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Driven Development(TDD) with Mockito Android]]></title>
            <link>https://jkprajapati.medium.com/tdd-with-mockito-android-958fec3fb183?source=rss-8c7dd93f07e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/958fec3fb183</guid>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[mockito]]></category>
            <dc:creator><![CDATA[Jitendra Prajapati]]></dc:creator>
            <pubDate>Fri, 10 Aug 2018 08:00:21 GMT</pubDate>
            <atom:updated>2018-08-10T08:37:30.044Z</atom:updated>
            <content:encoded><![CDATA[<p>In Test driven development (TDD), unlike Behavior drive development (BDD) first we write a Test, run the test. Definitely first time it will fail, because we haven&#39;t written the code for which going to test, then according to our test we start writing code to pass these tests. same we repeats till all test pass. to do this with mockito, we need to add a dependency in your build.gradle file as normally we add other dependency</p><pre>testImplementation &quot;org.mockito:mockito-core:2.15.0&quot;</pre><p>Mockito is basically a Mocking library used for mocking objects, you can get more about from its official documentation <a href="https://site.mockito.org/">here</a></p><p>I will explain this more by simple demo:</p><p><strong>Login View</strong></p><pre>package com.hoppers.mockito.demo<br><br>    interface ILoginView {<br>        fun getUserName(): String<br>        fun showUserNameError(showError: Int)<br>        fun getPassword(): String<br>        fun showPasswordError(showError: Int)<br>    }</pre><p><strong>Presenter</strong></p><p>Click alt+Enter from android studio, it will show a way to create test of this class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*n476uvs_Tz4GIbR4KGAeDQ.png" /></figure><p>In next dialog select testing library (Junit 4) class name and check on appropriate method to generate automatically by android studio and choose the path of this test class in test folder of project. initially your test file will be something similar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*SezqzlUouRbVd5O9es82IQ.png" /></figure><p>Here @Before and @After annotation tells that these method will be executed before the test and at the end of the test and used to do kind of initialization thing and releasing the resources, it works bit similar like onCreate and onDestroy method of android activity. Now lets think about normal login flow using username and password. whats our requirement here:</p><ol><li>username</li><li>password</li></ol><p>if username is empty show Error and if password is empty show Error, Just go to test class and write test case to test these flow:</p><p>This is the first test that will check validation if username is empty</p><pre>@Test<br>fun shouldShowErrorMessageWhenUserNameEmpty() {<br>}</pre><p>Here we need to return “” whenever view.getUserName called and click on onLoginClick() and verify through mockito that showUserNameError() method should call</p><pre>@Test<br>fun shouldShowErrorMessageWhenUserNameEmpty() {<br>    WhenEver(view.getUserName()).thenReturn(&quot;&quot;)<br>    presenter?.onLoginClick()<br>    verify(view).showUserNameError(R.string.<em>showUserNameError</em>)<br><br><br>}</pre><p>Now to run this code we need <strong>view, presenter </strong>object and presenter class is dependent on LoginService class, we will create these object through Mockito , we will press alt+enter and create a field and will annotate field with @Mock which tells mockito to give a mock (fake) object of these classes and mockito will take care</p><pre>@Mock<br>private lateinit var view: ILoginView<br><br>private var presenter: Presenter? = null</pre><pre>@Mock<br>private lateinit var service: LoginService</pre><p>But here we need presenter object also and it is dependent on loginview and loginservice, no worry we already have mocked object of both , we can simply create presenter object with help of these, will do it in setUp method here and will annotate it with @Before</p><pre>@Before<br>fun setUP() {<br>    presenter = Presenter(view, service)<br>}</pre><p>Our first test completed now, this is actual thing in TDD, but it will not work as we have written test only and not yet written actual code in our app, now lets do it</p><pre>class LoginActivity : AppCompatActivity(), ILoginView {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_login</em>)<br>      <strong><br>    </strong>}<br><br>    override fun getPassword(): String {<br>        return password.<em>text</em>.toString()<br>    }<br><br>    override fun showPasswordError(showError: Int) {<br>        password.<em>error </em>= getString(showError)<br>    }<br><br>    private val presenter: Presenter by <em>lazy </em><strong>{<br>        </strong>Presenter(this, LoginService())<br>    <strong>}<br><br>    </strong>override fun getUserName(): String {<br>        return email.<em>text</em>.toString()<br>    }<br><br>    override fun showUserNameError(showError: Int) {<br>        email.<em>error </em>= getString(showError)<br>    }</pre><p>That’s our test and code both ready now, can we test this ? yes</p><p>go to test file and press ctrl+shift+f10, What happen , Error</p><blockquote>org.mockito.exceptions.base.MockitoException: <br>Cannot mock/spy class com.hoppers.mockito.demo.LoginService<br>Mockito cannot mock/spy because :<br> — final class</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*0mwOr_9WGBFJHnsrTiVZwg.png" /></figure><p>As we know in Kotlin by default every class is final, and mockito unable to mock final class object… Problem, Solution is here</p><p>we need to create a file <em>org.mockito.plugins.MockMaker </em>in test/resources folder and add below text in the file</p><pre>mock-maker-inline</pre><p>now it will looks like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*PEzs4P2ryC25Ev9i3KQ-7g.png" /></figure><p>Looks nice, can we test ? yes go to test file and press ctrl+shift+f10, Success here , now test passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YFLKY4vxYp9_RGeg0_N0Rg.png" /></figure><p>This is simple basic TDD implementation in andorid using kotlin, Hopefully with all these you can get a basic idea behind TDD and Mockito</p><p>You can get full source code of this example <a href="https://github.com/jk2pr/Mockito-Test">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=958fec3fb183" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>