<?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 Chetan vaghela on Medium]]></title>
        <description><![CDATA[Stories by Chetan vaghela on Medium]]></description>
        <link>https://medium.com/@chetanvaghela457?source=rss-17a110246540------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*otVEAxavdIcvuZB4P1MDwQ.jpeg</url>
            <title>Stories by Chetan vaghela on Medium</title>
            <link>https://medium.com/@chetanvaghela457?source=rss-17a110246540------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:05:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chetanvaghela457/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[Securing Your Android Keys & Secrets with Native C++ Code: A Comprehensive Guide]]></title>
            <link>https://medium.com/@chetanvaghela457/securing-your-android-keys-secrets-with-native-c-code-fc99b871369a?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc99b871369a</guid>
            <category><![CDATA[android-app-security]]></category>
            <category><![CDATA[data-protection]]></category>
            <category><![CDATA[android-security]]></category>
            <category><![CDATA[secure-secrets]]></category>
            <category><![CDATA[native-cpp-code]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Sun, 06 Aug 2023 13:41:31 GMT</pubDate>
            <atom:updated>2024-09-02T08:16:57.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v6ttAGAU3jMH4UaL" /><figcaption>Photo by <a href="https://unsplash.com/@jefflssantos?utm_source=medium&amp;utm_medium=referral">Jefferson Santos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the fast-paced world of mobile app development, security remains a top priority. As an Android developer, you understand the importance of safeguarding sensitive information such as API keys, authentication tokens, and other secrets. While there are various techniques to secure this data within your Java or Kotlin code, leveraging Native C++ code can add an extra layer of protection. In this article, we will explore the benefits and best practices of using Native C++ code to secure your Android keys and secrets, ensuring your app’s data remains safe and resilient against potential threats.</p><p>There is no perfect protection mechanism to perfectly secure your data, applications, and systems from a passionate, sharp-minded hacker. So the only thing you can do in such scenarios is you can increase the security and use the best ways to be more secure. This will increase the hurdles in the ways of intruders and will take more time to sabotage the system.</p><p>Almost every app now uses some web services API. This is mostly enabled through any APU key or token. This key lets the server know that requests are coming from authenticated users and devices. Now, if you don’t keep these API keys secure, then any hacker can get access to this data through reverse engineering the APK file. This intruder can now make a flood of fake requests, which can be costly and may lead to some other serious breach issues and can create a very bad impression on your users.</p><p>Let’s talk now about some of the ways that developers use to store these API keys and other sensitive data.</p><h3>Storing Keys in strings.xml File</h3><p>This is a very common method to store keys. Although strings.xml is not recommended to use for the sensitive data, but often developers use this a lot. This will not keep that data secure and can be easily seen after reverse-engineering the APK file.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;resources&gt;<br>    &lt;!--API Key--&gt;<br>    &lt;string name=&quot;api_key&quot;&gt;abcdefg2q4qsaf34rtyy421k&lt;/string&gt;<br>&lt;/resources&gt;</pre><h3>Storing Keys As Constants</h3><p>Another common and bad way is to make a constant of your API key and put it in a Java/Kotlin file. This is easier to use in the code to access that key, but it will cost you a lot. Only keep the things in constants which are not sensitive.</p><pre>object Constants {<br>    const val API_KEY = &quot;abcdefg2q4qsaf34rtyy421k&quot;<br>}</pre><h3>Storing Keys in Gradle Files</h3><p>Another way to store the API keys is putting them in Gradle files. This asks for the compiling of those keys and can be accessed only after a successful build. Developers often assume that this is a safe and secure way to hide secrets from intruders, but actually it’s not. It’s as much insecure as other methods like strings.xml or constants.</p><pre>android {<br>  compileSdkVersion 33<br>  buildToolsVersion &quot;30.0.3&quot;<br><br>  defaultConfig {<br>    applicationId &quot;com.example.appdecoder&quot;<br>    minSdkVersion 21<br>    targetSdkVersion 33<br>    versionCode 1<br>    versionName &quot;1.0&quot;<br><br>    // THE API KEY FOR YOUR APP<br>    buildConfigField(&quot;String&quot;, &quot;API_KEY&quot;, &quot;abcdefg2q4qsaf34rtyy421k&quot;)<br>  }<br>  buildTypes {<br>    release {<br>      minifyEnabled false<br>      proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;),↵<br>       &#39;proguard-rules.pro&#39;<br>    }<br>  }<br>}</pre><p>This can be accessed in your code through BuildConfig.API_KEY.</p><h3>Storing Keys Natively with C++</h3><p>In Android Apps, you write code in Java or Kotlin, and it is easy to decompile the code written in Java and Kotlin as compared to C/C++ native code. Thus, there is a way to hide your Keys using C/C++ which is secure and safer than the previous ways.</p><p>Let’s look at the way to hide the API key by a code example. First, you have to install NDK (Native Development Kit) which allows C/C++ code to work with Android Studio and CMake to build your C/C++ code.</p><p>Now, make a folder name cpp in App’s src &gt; main &gt; and create a C++ file in it with the name native-lib.cpp. Put this code snippet in that cpp file.</p><p>This files is for configuring cmake in android project. Creates file inside src-&gt;main-&gt;c-&gt;CMakeLists.txt</p><pre># For more information about using CMake with Android Studio, read the<br># documentation: https://d.android.com/studio/projects/add-native-code.html<br><br># Sets the minimum version of CMake required to build the native library.<br><br>cmake_minimum_required(VERSION 3.4.1)<br><br># Creates and names a library, sets it as either STATIC<br># or SHARED, and provides the relative paths to its source code.<br># You can define multiple libraries, and CMake builds them for you.<br># Gradle automatically packages shared libraries with your APK.<br><br>add_library( # Sets the name of the library.<br>        native-lib<br><br>        # Sets the library as a shared library.<br>        SHARED<br><br>        # Provides a relative path to your source file(s).<br>        native-lib.cpp)<br><br># Searches for a specified prebuilt library and stores the path as a<br># variable. Because CMake includes system libraries in the search path by<br># default, you only need to specify the name of the public NDK library<br># you want to add. CMake verifies that the library exists before<br># completing its build.<br><br>find_library( # Sets the name of the path variable.<br>        log-lib<br><br>        # Specifies the name of the NDK library that<br>        # you want CMake to locate.<br>        log)<br><br># Specifies libraries CMake should link to your target library. You<br># can link multiple libraries, such as libraries you define in this<br># build script, prebuilt third-party libraries, or system libraries.<br><br>target_link_libraries( # Specifies the target library.<br>        native-lib<br>        # Links the target library to the log library<br>        # included in the NDK.<br>        ${log-lib})</pre><pre>#include &lt;jni.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;jni.h&gt;<br><br>extern &quot;C&quot; {<br><br>JNIEXPORT jstring<br>Java_com_example_appdecoder_ui_activity_LauncherScreenActivity_keyWork(<br>        JNIEnv *env, jobject thiz) {<br>    char *hello = &quot;A6q3qNa3u+hzHIvexvDYM2abp4Cm2yyyYNtZADJoaAc=&quot;;<br>    return env-&gt;NewStringUTF(hello);<br>  }<br><br>}</pre><p>Here com_example_appdecoder is the actual package name of your app. Note that instead of the dots, here are the underscores. So, com.example.appdecoder becomes com_example_appdecoder.</p><p>Then _keyWork is the name of .kt file which allows you to access the API key in Java/Kotlin files from C++ code.</p><p>Next to it, _apiKey is the name of the function which will return you the actual API key to make it accessible throughout your App.</p><p>This is enough for C++ code, now you have to create that LauncherScreenActivity.kt file, and write the following code;</p><pre>external fun keyWork(): String<br><br>    companion object {<br>        init {<br>            System.loadLibrary(&quot;native-lib&quot;)<br>        }<br>    }</pre><p>The code is used to access the keys throughout the application. Note that the apiKey method doesn’t have any method definition. The external modifier makes sure that this method’s definition is brought from the native C++ code through the native-lib.cpp file.</p><p>In the end, wherever you want to access the API key either while making some retrofit instance or whatever you need forl, you just have to write YourKeys.keyWork().</p><p>And that’s it. Now you can remain confident that your API keys and secrets are safe and sound and can not be easily viewed through reverse engineering the APK file.</p><h3>Some Advantages of Storing Keys in C++ File</h3><ol><li>Understanding the Importance of Secure Storage:</li></ol><p>It’s crucial to grasp the significance of securely storing sensitive data in Android applications. We will explore common vulnerabilities and potential consequences of inadequate data protection, laying the foundation for why C++ can be a valuable addition to your security arsenal.</p><p>2. Advantages of Utilizing Native C++ Code:</p><p>Unique advantages of integrating Native C++ code in Android apps to secure keys and secrets. This will include a comparison with Java/Kotlin-based security techniques and how C++ offers improved protection against reverse engineering and memory inspection.</p><p>3. Integrating Native C++ for Key &amp; Secret Management:</p><p>Step-by-step process of integrating Native C++ code into your Android project for managing keys and secrets securely. We’ll cover setting up the C++ environment, creating a C++ library, and calling C++ functions from Java/Kotlin, emphasizing secure data transfer between both languages.</p><p>4. Encrypting Secrets in Native C++:</p><p>Various encryption techniques that can be implemented within the Native C++ code. We will discuss symmetric and asymmetric encryption methods, highlighting their strengths and best practices for securing secrets effectively.</p><p>5. Adding an Extra Layer of Obfuscation:</p><p>the importance of obfuscating your Native C++ code to make it even more challenging for attackers to decipher your secrets. We’ll cover popular C++ obfuscation techniques, how to apply them, and their impact on app performance.</p><p>6. Secure Key Handling &amp; Memory Management:</p><p>Handling keys and secrets securely is vital to thwart any potential attacks. We’ll dive into best practices for managing keys within your Native C++ code, including memory management considerations and the importance of securely wiping sensitive data from memory.</p><p>7. Rigorous Testing &amp; Quality Assurance:</p><p>No security measure is complete without thorough testing. We’ll guide you through the essential testing procedures to ensure your C++-based security implementation is robust, reliable, and resilient against potential threats.</p><p><a href="https://github.com/chetanvaghela457">chetanvaghela457 - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc99b871369a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing Data and API Credentials with Encryption and Cipher Keys in Android]]></title>
            <link>https://medium.com/@chetanvaghela457/securing-data-and-api-credentials-with-encryption-and-cipher-keys-in-android-1629b3452f14?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/1629b3452f14</guid>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[android-security]]></category>
            <category><![CDATA[api-security]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[sae]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Sat, 05 Aug 2023 05:38:00 GMT</pubDate>
            <atom:updated>2024-09-02T08:20:12.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1yTe8q1t8eucQ0NrWyhRRA.jpeg" /></figure><p>In today’s digital world, data security is of utmost importance. With cyber threats constantly on the rise, it’s crucial to safeguard sensitive information, including API credentials, from unauthorized access. Encryption is a powerful technique that can be employed to protect data, ensuring that even if it falls into the wrong hands, it remains unreadable. In this article, we’ll explore the basics of encryption and how to secure API credentials using cipher keys.</p><p>1. Understanding Encryption: The Basics Encryption is the process of converting plain text or data into an unreadable format called ciphertext, using an encryption algorithm and a secret key. Only those with the correct decryption key can convert the ciphertext back into its original form. This method ensures that even if data is intercepted, it remains inaccessible and secure.</p><p>2. Cipher Keys: The Foundation of Encryption A cipher key is a secret value used in the encryption and decryption process. The strength of encryption largely depends on the complexity of the cipher key. It’s essential to use robust and well-established encryption algorithms, such as AES (Advanced Encryption Standard), and ensure that the cipher keys are kept confidential.</p><p>3. Encrypting Data with Cipher Keys When encrypting data, developers should follow best practices. Always encrypt sensitive information such as passwords, personal data, and API credentials before storing them in databases or transmitting over networks. This can prevent unauthorized access to critical data and minimize the impact of data breaches.</p><p>4. Securing API Credentials with Encryption APIs (Application Programming Interfaces) are essential for connecting and exchanging data between different systems. However, API credentials, such as API keys and tokens, must be treated with utmost care to prevent misuse.</p><ul><li>Never hardcode API credentials directly into the code. Use environment variables or configuration files to store them separately from the codebase.</li><li>Encrypt API credentials before storing them, ensuring they are protected even in case of database breaches.</li><li>Employ access control measures to restrict API access only to authorized users and applications.</li><li>Regularly rotate API keys and tokens to limit potential exposure.</li></ul><p>5. Key Management and Storage Proper key management is crucial for effective encryption. Some best practices include:</p><ul><li>Use a secure key management system to generate, store, and manage encryption keys.</li><li>Regularly rotate and update cipher keys to maintain high security.</li><li>Restrict access to encryption keys to only authorized personnel or systems.</li></ul><p>6. Transport Layer Security (TLS) for API Communication In addition to encrypting data at rest, it’s essential to secure data during transmission between systems using Transport Layer Security (TLS) protocols. This ensures that data is encrypted while in transit, further protecting sensitive information.</p><h3><strong>Encode and Decode the code with different methods:</strong></h3><ol><li>For the Encryption of data you need 16 digit private key which can be used as security chiper Encoding and Decoding the data.</li></ol><pre>val SECRET_KEY = &quot;nxne7eDmMrUs+DQ=&quot;<br>val INIT_VECTOR = &quot;encryptionIntVec&quot;<br><br>fun encrypt(value: String): String? {<br>    try {<br>        val iv = IvParameterSpec(INIT_VECTOR.toByteArray(charset(&quot;UTF-8&quot;)))<br>        val skeySpec = SecretKeySpec(SECRET_KEY.toByteArray(charset(&quot;UTF-8&quot;)), &quot;AES&quot;)<br>        val cipher = Cipher.getInstance(&quot;AES/CBC/PKCS5PADDING&quot;)<br>        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv)<br>        val encrypted = cipher.doFinal(value.toByteArray())<br>        return Base64.encodeToString(encrypted, Base64.DEFAULT)<br>    } catch (ex: java.lang.Exception) {<br>        ex.printStackTrace()<br>    }<br>    return null<br>}<br><br>fun decrypt(value: String?): String? {<br>    try {<br>        val iv = IvParameterSpec(INIT_VECTOR.toByteArray(charset(&quot;UTF-8&quot;)))<br>        val skeySpec = SecretKeySpec(SECRET_KEY.toByteArray(charset(&quot;UTF-8&quot;)), &quot;AES&quot;)<br>        val cipher = Cipher.getInstance(&quot;AES/CBC/PKCS5PADDING&quot;)<br>        cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv)<br>        val original = cipher.doFinal(Base64.decode(value, Base64.DEFAULT))<br>        return String(original)<br>    } catch (ex: java.lang.Exception) {<br>        ex.printStackTrace()<br>    }<br>    return null<br>}</pre><p>2. You can Encode the data without Using any key because the data will create automatic key from data and used that key to encode and decode.</p><pre>fun CipherDataEncrpt(str: String?): String? {<br>    val decode = Base64.decode(str, 0)<br>    if (decode.size &lt; 17) {<br>        return null<br>    }<br>    val copyOfRange: ByteArray = Arrays.copyOfRange(decode, 0, 16)<br>    val copyOfRange2: ByteArray = Arrays.copyOfRange(decode, 16, 32)<br>    val copyOfRange3: ByteArray = Arrays.copyOfRange(decode, 32, decode.size)<br>    return try {<br>        val cipher = Cipher.getInstance(&quot;AES/CBC/PKCS5Padding&quot;)<br>        cipher.init(<br>            2,<br>            SecretKeySpec(copyOfRange, &quot;AES&quot;),<br>            IvParameterSpec(copyOfRange2, 0, cipher.blockSize)<br>        )<br>        String(cipher.doFinal(copyOfRange3))<br>    } catch (unused: InvalidAlgorithmParameterException) {<br>        null<br>    } catch (unused: InvalidKeyException) {<br>        null<br>    } catch (unused: NoSuchAlgorithmException) {<br>        null<br>    } catch (unused: BadPaddingException) {<br>        null<br>    } catch (unused: IllegalBlockSizeException) {<br>        null<br>    } catch (unused: NoSuchPaddingException) {<br>        null<br>    }<br>}</pre><h3><strong>Conclusion</strong></h3><p>Encryption is a powerful tool for securing data and API credentials, providing a robust defense against potential cyber threats and unauthorized access. By understanding the basics of encryption, using strong cipher keys, and following best practices, developers can significantly enhance data security and build trust among users and clients. Remember that data security is an ongoing process, and staying updated with the latest encryption standards and practices is critical to maintaining a safe digital environment.</p><p>Remember to always test your encryption implementation thoroughly and seek the advice of security professionals if needed to ensure the highest level of protection for your data and API credentials. Stay vigilant and make data security a top priority in your development practices.</p><h3>References:</h3><ul><li><a href="https://developer.android.com/reference/javax/crypto/Cipher">Cipher | Android Developers</a></li><li><a href="https://github.com/chetanvaghela457">chetanvaghela457 - Overview</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1629b3452f14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Technologies an Android Mobile Application Developer Should Know?]]></title>
            <link>https://medium.com/@chetanvaghela457/what-technologies-an-android-mobile-application-developer-should-know-eb8f0f6dcc17?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb8f0f6dcc17</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Wed, 12 Jul 2023 06:08:17 GMT</pubDate>
            <atom:updated>2024-09-02T08:17:35.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1c3gzIV2X_nnnQSykQrMg.jpeg" /><figcaption>Photo by Christina Morillo</figcaption></figure><p>📍 Here’s the list of technologies and concepts that a Android programmer should be familiar with:</p><p>📌 MVVM (Model-View-ViewModel) architecture pattern for separation of concerns in Android development.</p><p>📌 LiveData: An observable data holder class that is lifecycle-aware and used for communication between components.</p><p>📌Kotlin Coroutines: A concurrency framework for writing asynchronous and non-blocking code.</p><p>📌 Activity Lifecycle: The lifecycle states and callbacks of an Android activity.</p><p>📌 Use case of abstract class and interface in creating reusable and extensible code.</p><p>📌 Flavor: A feature in Android Studio used to manage different build variants for different environments (e.g., development, QA, production).</p><p>📌 Kotlin Data class: A class that is primarily used to hold data and automatically generates essential methods.</p><p>📌 Network call with retry mechanism using a refresh token: Handling network requests with an automatic retry mechanism using a refresh token for authentication.</p><p>📌 Dependency Injection: Techniques like Dagger and Hilt to manage dependencies and improve modularity.</p><p>📌 Use case and application of Polymorphism, Abstraction, and other object-oriented programming concepts.</p><p>📌 Service: Components for performing long-running operations in the background, both foreground and background services.</p><p>📌 Broadcast Receiver: A component used for delivering system-wide or application-specific events.</p><p>📌 Light and Dark theme management: Implementing and managing different themes for your Android application.</p><p>📌 Memory leak: Understanding how memory leaks can occur in Android and techniques to fix them.</p><p>📌 Unit testing: Writing and executing tests to verify the behavior of individual units of code.</p><p>📌 Mutability and immutability: Understanding the concepts and benefits of mutable and immutable objects.</p><p>📌 Gradle: A build system responsible for compiling and packaging Android applications.</p><p>📌 CI/CD (Continuous Integration/Continuous Deployment): Automating the build, testing, and deployment processes.</p><p>📌 Offline cache: Implementing a cache mechanism to store data offline, utilizing techniques like Async Task, Kotlin’s Flows, and WorkManager.</p><p>📌 R8/Proguard: Tools used for code shrinking, obfuscation, and optimization of Android apps.</p><p>📌 WorkManager: An API for scheduling and managing background tasks.</p><p>📌 Flow: Understanding and utilizing StateFlow, SharedFlow, and channels in Kotlin.</p><p>📌 Delegate pattern: Implementing the delegation design pattern in Android.</p><p>📌 Annotation Processor: Utilizing annotation processors for code generation and metadata processing.</p><p>📌 MVI (Model-View-Intent) Pattern: A unidirectional architecture pattern for Android applications.</p><p>📌 Image processing libraries and Network libraries: Understanding how these libraries work and integrating them into Android apps.</p><p>📌 Custom Views implementation: Creating custom views with custom drawing and interaction behaviors.</p><p>📌 ExoPlayer and live streaming: Utilizing ExoPlayer for playing media content and handling live streaming.</p><p>📌 NDK (Native Development Kit): Developing and integrating native code into Android applications.</p><p>📌 Important keys management and encryption/decryption: Handling sensitive data with encryption and decryption techniques.</p><p>📌 Enum and sealed classes: Understanding and utilizing enumeration types and sealed classes in Kotlin.</p><p>📌 Scope functions in Kotlin: Functions like let, run, with, apply, and also for scoping and context manipulation.</p><p>📌 Activity launch modes: Understanding the different launch modes for Android activities.</p><p>📌 FlatMap vs. Map: Differences between the flatMap and map operations in functional programming.</p><p>📌 Val, var &amp; const: Understanding the differences and appropriate use cases for these declarations in Kotlin.</p><p>📌 Extension functions, inline functions, and crossinline: Kotlin features for enhancing code readability and functionality.</p><p>📌 Fragment communication: Techniques for communication between fragments.</p><p>📌 Alarm Manager / Pagination: Utilizing Alarm Manager for scheduling tasks and implementing pagination in Android apps.</p><p>📌 Java static vs. Kotlin object: Differences between static declarations in Java and object declarations in Kotlin.</p><p>📌 ANR (Application Not Responding), RxJava, Collection Framework,</p><p>📌 HashMap: Handling ANR scenarios, utilizing RxJava for reactive programming, and working with data collections.</p><p>📌 Local DB: Utilizing local databases like SQLite or Room for data storage and retrieval.</p><p>📌 Different design patterns and their use cases in Android development.</p><p>📌 Navigation Component: A library for implementing navigation and handling fragment transactions.</p><p>📌 Single Activity architecture: Designing apps with a single activity and multiple fragments.</p><p>📌 Paging, Remote Mediator, Higher-order functions vs. interface: Working with the Paging library, implementing a remote mediator for pagination, and understanding higher-order functions and interfaces.</p><p>📌 Infix functions: Defining functions that can be called without using the dot or parentheses syntax.</p><p>📌 DataBinding: Binding data directly to the UI components in layout files.</p><p>📌 Interceptor: Intercepting and modifying network requests and responses in networking libraries.</p><p>📌 Sensors and Tensorflow Lite in Android: Working with device sensors and integrating TensorFlow Lite for machine learning tasks.</p><p>📌 Jetpack Compose: A modern UI toolkit for building Android user interfaces using declarative programming.</p><p>📌 UI testing: Writing automated tests to verify the correctness of user interfaces.</p><p>📌 Security — symmetric and asymmetric encryption: Implementing encryption techniques for secure data transmission.</p><p>📌 Content Provider: A component for sharing data between applications in Android.</p><p>📌 WebSocket and GraphQL: Understanding and utilizing WebSocket communication and integrating GraphQL in Android apps.</p><p>📌 Serializable vs. Parcelable: Different mechanisms for transferring data between components in Android.</p><p>📌 Intent and Intent Filter, Pending Intent: Understanding intents, intent filters, and pending intents for inter-component communication.</p><p>I have completed the demo off all the content described here. want to learn more about this. You can checkout my repositories in Github here:</p><p><a href="https://github.com/chetanvaghela457">chetanvaghela457 - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb8f0f6dcc17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2272. Substring With Largest Variance — Leetcode Daily — 9 July 23]]></title>
            <link>https://medium.com/@chetanvaghela457/2272-substring-with-largest-variance-leetcode-daily-9-july-23-71a64929a67a?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/71a64929a67a</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[leetcode-hard]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 17:35:23 GMT</pubDate>
            <atom:updated>2023-07-09T17:35:23.729Z</atom:updated>
            <content:encoded><![CDATA[<h3>2272. Substring With Largest Variance — Leetcode Daily — 9 July 23</h3><h3>Question:-</h3><p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> 2 characters present in the string. Note the two characters may or may not be the same.</p><p>Given a string s consisting of lowercase English letters only, return <em>the </em><strong><em>largest variance</em></strong><em> possible among all </em><strong><em>substrings</em></strong><em> of</em> s.</p><p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p><p><strong>Example 1:</strong></p><pre>Input: s = &quot;aababbb&quot;<br>Output: 3<br>Explanation:<br>All possible variances along with their respective substrings are listed below:<br>- Variance 0 for substrings &quot;a&quot;, &quot;aa&quot;, &quot;ab&quot;, &quot;abab&quot;, &quot;aababb&quot;, &quot;ba&quot;, &quot;b&quot;, &quot;bb&quot;, and &quot;bbb&quot;.<br>- Variance 1 for substrings &quot;aab&quot;, &quot;aba&quot;, &quot;abb&quot;, &quot;aabab&quot;, &quot;ababb&quot;, &quot;aababbb&quot;, and &quot;bab&quot;.<br>- Variance 2 for substrings &quot;aaba&quot;, &quot;ababbb&quot;, &quot;abbb&quot;, and &quot;babb&quot;.<br>- Variance 3 for substring &quot;babbb&quot;.<br>Since the largest possible variance is 3, we return it.</pre><p><strong>Example 2:</strong></p><pre>Input: s = &quot;abcde&quot;<br>Output: 0<br>Explanation:<br>No letter occurs more than once in s, so the variance of every substring is 0.</pre><h3>Answer:-</h3><pre>class Solution {<br>    public int largestVariance(String s) {<br>        int [] freq = new int[26];<br>        for(int i = 0 ; i &lt; s.length() ; i++)<br>            freq[(int)(s.charAt(i) - &#39;a&#39;)]++;<br>        <br>        int maxVariance = 0;<br>        for(int a = 0 ; a &lt; 26 ; a++){<br>            for(int b = 0 ; b &lt; 26 ; b++){<br>                int remainingA = freq[a];<br>                int remainingB = freq[b];<br>                if(a == b || remainingA == 0 || remainingB == 0) continue;<br>                <br>    // run kadanes on each possible character pairs (A &amp; B)<br>                int currBFreq = 0, currAFreq = 0;<br>                for(int i = 0 ; i &lt; s.length() ; i++){<br>                    int c =  (int)(s.charAt(i) - &#39;a&#39;);<br>                    <br>                    if(c == b) currBFreq++;<br>                    if(c == a) {<br>                        currAFreq++;<br>                        remainingA--;<br>                    }<br>                    <br>                    if(currAFreq &gt; 0)<br>                        maxVariance = Math.max(maxVariance, currBFreq - currAFreq);<br>                    <br>                    if(currBFreq &lt; currAFreq &amp;&amp;  remainingA &gt;= 1){<br>                        currBFreq = 0;<br>                        currAFreq = 0;<br>                    }<br>                }<br>            }<br>        }<br>        <br>        return maxVariance;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71a64929a67a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2551. Put Marbles in Bags — Leetcode Daily Solution — 8 July 23]]></title>
            <link>https://medium.com/@chetanvaghela457/2551-put-marbles-in-bags-leetcode-daily-solution-8-july-23-a205e37af705?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/a205e37af705</guid>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-today]]></category>
            <category><![CDATA[leetcode-hard]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Sat, 08 Jul 2023 16:16:50 GMT</pubDate>
            <atom:updated>2023-07-08T16:16:50.422Z</atom:updated>
            <content:encoded><![CDATA[<h3>2551. Put Marbles in Bags — Leetcode Daily Solution — 8 July 23</h3><h3>Question:-</h3><p>You have k bags. You are given a <strong>0-indexed</strong> integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k.</p><p>Divide the marbles into the k bags according to the following rules:</p><ul><li>No bag is empty.</li><li>If the ith marble and jth marble are in a bag, then all marbles with an index between the ith and jth indices should also be in that same bag.</li><li>If a bag consists of all the marbles with an index from i to j inclusively, then the cost of the bag is weights[i] + weights[j].</li></ul><p>The <strong>score</strong> after distributing the marbles is the sum of the costs of all the k bags.</p><p>Return <em>the </em><strong><em>difference</em></strong><em> between the </em><strong><em>maximum</em></strong><em> and </em><strong><em>minimum</em></strong><em> scores among marble distributions</em>.</p><p><strong>Example 1:</strong></p><pre>Input: weights = [1,3,5,1], k = 2<br>Output: 4<br>Explanation: <br>The distribution [1],[3,5,1] results in the minimal score of (1+1) + (3+1) = 6. <br>The distribution [1,3],[5,1], results in the maximal score of (1+3) + (5+1) = 10. <br>Thus, we return their difference 10 - 6 = 4.</pre><p><strong>Example 2:</strong></p><pre>Input: weights = [1, 3], k = 2<br>Output: 0<br>Explanation: The only distribution possible is [1],[3]. <br>Since both the maximal and minimal score are the same, we return 0.</pre><h3>Answer:-</h3><pre>class Solution {<br>    public long putMarbles(int[] weights, int k) {<br>        int n = weights.length;<br>        int[] pairs = new int[n - 1];<br>        for (int i = 1; i &lt; n; i++) {<br>            pairs[i - 1] = weights[i] + weights[i - 1];<br>        }<br>        Arrays.sort(pairs);<br>        long minScore = 0;<br>        long maxScore = 0;<br>        for (int i = 0; i &lt; k - 1; i++) {<br>            minScore += pairs[i];<br>            maxScore += pairs[n - i - 2];<br>        }<br>        return maxScore - minScore;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a205e37af705" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Kotlin DataBinding With BindingAdapter Recyclerview Binding]]></title>
            <link>https://medium.com/@chetanvaghela457/android-kotlin-databinding-with-bindingadapter-recyclerview-binding-99c84aa7af68?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/99c84aa7af68</guid>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[data-binding]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 16:47:59 GMT</pubDate>
            <atom:updated>2024-09-02T08:18:42.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BP7Jy0-Om-9mgRxdNvf_cw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@zanilic?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Zan</a> on <a href="https://unsplash.com/photos/X_JsI_9Hl7o?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>MVVM Android App with Data Binding in Kotlin is a powerful application that follows the Model-View-ViewModel (MVVM) architectural pattern to provide a robust and maintainable codebase. The app utilizes Data Binding and RecyclerView, combined with the efficient management of EditText text changes using Binding Adapters.</p><p>Features:</p><ul><li>MVVM Architacture</li><li>Written in Kotlin</li><li>Used Clear code to understand</li><li>Data Binding inside recyclerview</li><li>Used of Binding Adapter to bind code directly to XML</li><li>Clear and Understandable Code</li><li>OnTextChange Validation on Recyclerview Item Edittext</li></ul><pre>id &#39;kotlin-kapt&#39;<br><br>buildFeatures {<br>        dataBinding true<br>        viewBinding true<br>    }<br><br>//lifecycle<br>    implementation &#39;androidx.lifecycle:lifecycle-runtime-ktx:2.6.1&#39;<br>    implementation &#39;androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1&#39;<br>    implementation &#39;androidx.lifecycle:lifecycle-livedata-ktx:2.6.1&#39;</pre><p>If you are using Kotlin, you have to add Data Binding’s compiler as a dependency like the above code or you can enable it inside gradle.properties file of the project properties section as shown below:</p><pre>android.databinding.enableV2=true</pre><p>The next step to enable Data Binding is to wrap your whole XML layout with a &lt;layout&gt; tag as a parent. Then if you build the project, it will generate all the needed classes, which enables Data Binding. From now, all your changes related to Data Binding will be effective and there is no need to rebuild the project for each change. For binding UI components to data sources add a &lt;data&gt; tag inside the &lt;layout&gt; tag as per below:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout 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;&gt;<br><br>    &lt;data&gt;<br><br>        &lt;variable<br>            name=&quot;viewModel&quot;<br>            type=&quot;com.databinding.databindingwithbindingadapterrecyclerviewbinding.viewmodel.ProductsViewModel&quot; /&gt;<br><br>    &lt;/data&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>        tools:context=&quot;.MainActivity&quot;&gt;<br><br>        &lt;com.google.android.material.appbar.AppBarLayout<br>            android:id=&quot;@+id/appBar&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&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>            &lt;androidx.appcompat.widget.Toolbar<br>                android:id=&quot;@+id/toolbar&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:backgroundTint=&quot;@color/white&quot;<br>                app:navigationIcon=&quot;@drawable/back_arrow&quot;&gt;<br><br>                &lt;TextView<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:text=&quot;@string/products&quot;<br>                    android:textStyle=&quot;bold&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;16sp&quot; /&gt;<br>            &lt;/androidx.appcompat.widget.Toolbar&gt;<br>        &lt;/com.google.android.material.appbar.AppBarLayout&gt;<br><br><br>        &lt;TextView<br>            android:id=&quot;@+id/textView&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_marginStart=&quot;12dp&quot;<br>            android:layout_marginTop=&quot;8dp&quot;<br>            android:text=&quot;@string/products&quot;<br>            android:textColor=&quot;@color/black&quot;<br>            android:textSize=&quot;16sp&quot;<br>            app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>            app:layout_constraintTop_toBottomOf=&quot;@id/appBar&quot; /&gt;<br><br>        &lt;androidx.recyclerview.widget.RecyclerView<br>            android:id=&quot;@+id/recyclerViewProducts&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            app:layoutManager=&quot;androidx.recyclerview.widget.LinearLayoutManager&quot;<br>            app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>            app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>            app:layout_constraintTop_toBottomOf=&quot;@id/textView&quot;<br>            tools:itemCount=&quot;5&quot;<br>            tools:listitem=&quot;@layout/item_products&quot; /&gt;<br><br>    &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br>&lt;/layout&gt;</pre><p>Layout variables are used to write layout expressions. Layout expressions are placed in the value of element attributes and they use the @{} syntax. Here are some examples:</p><pre>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;<br><br>    &lt;data&gt;<br><br>        &lt;import type=&quot;android.view.View&quot; /&gt;<br><br>        &lt;variable<br>            name=&quot;productsModel&quot;<br>            type=&quot;com.databinding.databindingwithbindingadapterrecyclerviewbinding.model.ProductData&quot; /&gt;<br><br>        &lt;variable<br>            name=&quot;viewModel&quot;<br>            type=&quot;com.databinding.databindingwithbindingadapterrecyclerviewbinding.viewmodel.ProductsViewModel&quot; /&gt;<br><br>    &lt;/data&gt;<br><br>    &lt;androidx.constraintlayout.widget.ConstraintLayout<br>        android:id=&quot;@+id/itemFridge1&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_marginTop=&quot;@dimen/_10sdp&quot;&gt;<br><br>        &lt;androidx.constraintlayout.widget.ConstraintLayout<br>            android:id=&quot;@+id/const1&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&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>            &lt;TextView<br>                android:layout_width=&quot;wrap_content&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:layout_marginStart=&quot;@dimen/_10sdp&quot;<br>                android:text=&quot;@{productsModel.name}&quot;<br>                android:textColor=&quot;@color/black&quot;<br>                android:textSize=&quot;16sp&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><br>            &lt;LinearLayout<br>                android:id=&quot;@+id/linearFridge1&quot;<br>                android:layout_width=&quot;@dimen/_100sdp&quot;<br>                android:layout_height=&quot;@dimen/_40sdp&quot;<br>                android:layout_marginEnd=&quot;@dimen/_10sdp&quot;<br>                android:background=&quot;@{productsModel.valid ? @drawable/temp_item_bg : @drawable/temp_error_item_bg}&quot;<br>                android:orientation=&quot;horizontal&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>                app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;<br><br>                &lt;EditText<br>                    android:id=&quot;@+id/editText1&quot;<br>                    android:layout_width=&quot;@dimen/_70sdp&quot;<br>                    android:layout_height=&quot;@dimen/_40sdp&quot;<br>                    android:layout_gravity=&quot;center&quot;<br>                    android:afterTextChanged=&quot;@{(text) -&gt; viewModel.onDataTextChanged(text,productsModel)}&quot;<br>                    android:background=&quot;@null&quot;<br>                    android:digits=&quot;0123456789&quot;<br>                    android:gravity=&quot;center&quot;<br>                    android:hint=&quot;@string/add_price&quot;<br>                    android:imeOptions=&quot;actionDone&quot;<br>                    android:inputType=&quot;numberDecimal&quot;<br>                    android:text=&quot;@={productsModel.price}&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textColorHint=&quot;@color/textGray&quot;<br>                    android:textSize=&quot;@dimen/_12ssp&quot;<br>                    /&gt;<br><br>                &lt;View<br>                    android:id=&quot;@+id/view1Color&quot;<br>                    android:layout_width=&quot;@dimen/_1sdp&quot;<br>                    android:layout_height=&quot;@dimen/_40sdp&quot;<br>                    android:background=&quot;@color/black&quot; /&gt;<br><br>                &lt;ImageView<br>                    android:id=&quot;@+id/celciusImg1&quot;<br>                    android:layout_width=&quot;@dimen/_25sdp&quot;<br>                    android:layout_height=&quot;@dimen/_30sdp&quot;<br>                    android:layout_gravity=&quot;center&quot;<br>                    android:padding=&quot;@dimen/_5sdp&quot;<br>                    android:src=&quot;@drawable/indian_rupee_symbol&quot; /&gt;<br><br><br>            &lt;/LinearLayout&gt;<br><br>        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br><br>        &lt;TextView<br>            android:id=&quot;@+id/tempError1&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_marginEnd=&quot;@dimen/_10sdp&quot;<br>            android:text=&quot;@string/product_price_should_be&quot;<br>            android:textColor=&quot;@color/error_color&quot;<br>            android:textSize=&quot;@dimen/_11ssp&quot;<br>            android:visibility=&quot;@{productsModel.valid ? View.GONE : View.VISIBLE}&quot;<br>            app:layout_constraintEnd_toEndOf=&quot;@+id/const1&quot;<br>            app:layout_constraintTop_toBottomOf=&quot;@+id/const1&quot; /&gt;<br><br>    &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br>&lt;/layout&gt;</pre><p>One with the name of ProductData and type of my current <strong>Model </strong>class inside the project which is a data class, called Product as the below snippet:</p><pre>class ProductData: BaseObservable() {<br><br>    @get:Bindable<br>    var name: String = &quot;&quot;<br>        set(value) {<br>            field = value<br>            notifyPropertyChanged(BR.name)<br>        }<br><br>    @get:Bindable<br>    var price: String = &quot;&quot;<br>        set(value) {<br>            field = value<br>            notifyPropertyChanged(BR.price)<br>        }<br><br>    @get:Bindable<br>    var valid: Boolean = true<br>        set(value) {<br>            field = value<br>            notifyPropertyChanged(BR.valid)<br>        }<br>}</pre><blockquote>Inside the ViewModel class, I needed to get the Id from UI, I defined an Id variable so that by pressing a button the process could start. So, I have defined the onDataTextChanged() function. Whatever value is entered in that edit text, it will be assigned automatically to the productData.valid value inside the below class:</blockquote><pre>class ProductsViewModel(context: Context) : ViewModel() {<br>    fun onDataTextChanged(text: CharSequence,productData: ProductData) {<br><br>        if(text.isNotEmpty()) {<br>            productData.valid = !(text.toString().toInt() &lt; 50)<br>        } else {<br>            productData.valid = true<br>        }<br>    }<br><br>    @BindingAdapter(<br>        &quot;buttonAllValid&quot;,<br>        requireAll = true<br>    )<br>    fun saveButtonPriority(<br>        textView: TextView,<br>        isValid: Boolean,<br><br>        ) {<br>        textView.apply {<br>            when (isValid) {<br>                true -&gt; {<br><br>                    setBackgroundResource(R.drawable.button_bg)<br>                    isEnabled = true<br><br>                }<br><br>                else -&gt; {<br>                    setBackgroundResource(R.drawable.button_disable_bg)<br>                    isEnabled = false<br>                }<br>            }<br>        }<br>    }<br><br>}</pre><p>Create Adapter Named ProductsItemAdapter which contains list of product items with Data binding initiated:</p><pre>class ProductsItemAdapter(<br>    val temperatureLogsViewModel: ProductsViewModel<br>) :<br>    ListAdapter&lt;ProductData, RecyclerView.ViewHolder&gt;(DiffCallback)  {<br><br>    inner class ProductsItemViewHolder(private val binding: ItemProductsBinding) :<br>        RecyclerView.ViewHolder(binding.root) {<br><br>        fun onBind(nasaData: ProductData, position: Int) {<br>            binding.productsModel = nasaData<br>            binding.viewModel = temperatureLogsViewModel<br>            binding.executePendingBindings()<br>        }<br>    }<br><br><br>    object DiffCallback : DiffUtil.ItemCallback&lt;ProductData&gt;() {<br>        override fun areItemsTheSame(oldItem: ProductData, newItem: ProductData): Boolean {<br>            return oldItem.name == newItem.name<br>        }<br><br>        override fun areContentsTheSame(oldItem: ProductData, newItem: ProductData): Boolean {<br>            return oldItem == newItem<br>        }<br>    }<br><br>    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {<br>        val binding =<br>            ItemProductsBinding.inflate(LayoutInflater.from(parent.context), parent, false)<br>        return ProductsItemViewHolder(binding)<br>    }<br><br>    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {<br>        val adjustViewHolder = holder as ProductsItemViewHolder<br>        val fridgeItem = getItem(position)<br><br>        fridgeItem.let {<br>            adjustViewHolder.onBind(it, position)<br>        }<br>    }<br>}</pre><p>At Last We are going to setup MainActivity with Data Binding and View Model initialization with getting data from the Raw Folder and show it in the Recyclerview with Adapter and Data Binding with Binding Adapter.</p><pre>class MainActivity : AppCompatActivity() {<br><br>    private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }<br><br>    private val productsViewModel: ProductsViewModel by viewModels {<br>        viewModelFactory {<br>            ProductsViewModel(this@MainActivity)<br>        }<br>    }<br><br>    val productsItemAdapter by lazy { ProductsItemAdapter(productsViewModel)}<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(binding.root)<br><br><br>        binding.apply {<br><br>            onBackPressedDispatcher.addCallback {<br>                finish()<br>            }<br><br>            setSupportActionBar(toolbar)<br>            supportActionBar?.setDisplayShowTitleEnabled(false)<br><br>            toolbar.setNavigationOnClickListener {<br>                onBackPressedDispatcher.onBackPressed()<br>            }<br><br>            getProductsItem().observeByLambda(this@MainActivity) {<br><br>                recyclerViewProducts.isNestedScrollingEnabled = false<br>                recyclerViewProducts.adapter = productsItemAdapter<br>                productsItemAdapter.submitList(it)<br><br>            }<br><br><br>        }<br>    }<br><br>    fun getProductsItem(): MutableLiveData&lt;ArrayList&lt;ProductData&gt;&gt; {<br>        val encodedString = MutableLiveData&lt;ArrayList&lt;ProductData&gt;&gt;()<br><br>        val rawFile = R.raw.products_items<br>        val jsonFileString = getJsonDataFromRaw(<br>            this,<br>            rawFile<br>        )<br>        val type = object : TypeToken&lt;ArrayList&lt;ProductData&gt;&gt;() {}.type<br>        encodedString.postValue(Gson().fromJson(jsonFileString, type))<br><br>        return encodedString<br>    }<br>}</pre><p>That was a simple example of using Data Binding with MVVM architecture design 🤩 … You can find the whole code at the below repository:</p><p><a href="https://github.com/chetanvaghela457/Android-Kotlin-DataBinding-WIth-BindingAdapter-Recyclerview-Binding">GitHub - chetanvaghela457/Android-Kotlin-DataBinding-WIth-BindingAdapter-Recyclerview-Binding: MVVM Android App with Data Binding in Kotlin is a powerful application that follows the Model-View-ViewModel (MVVM) architectural pattern to provide a robust and maintainable codebase. The app utilizes Data Binding and RecyclerView, combined with the efficient management of EditText text changes using Binding Adapters.</a></p><h3>References:</h3><ul><li><a href="https://developer.android.com/topic/libraries/data-binding">https://developer.android.com/topic/libraries/data-binding</a></li><li><a href="https://github.com/probelalkhan/android-mvvm-architecture">https://github.com/probelalkhan/android-mvvm-architecture</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99c84aa7af68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2024. Maximize the Confusion of an Exam — LeetCode Daily — 7 July 23]]></title>
            <link>https://medium.com/@chetanvaghela457/2024-maximize-the-confusion-of-an-exam-leetcode-daily-7-july-23-89b7240a8b2b?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/89b7240a8b2b</guid>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 16:24:06 GMT</pubDate>
            <atom:updated>2023-07-07T16:24:06.549Z</atom:updated>
            <content:encoded><![CDATA[<h3>2024. Maximize the Confusion of an Exam — LeetCode Daily — 7 July 23</h3><h3>Question:-</h3><p>A teacher is writing a test with n true/false questions, with &#39;T&#39; denoting true and &#39;F&#39; denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (multiple trues or multiple falses in a row).</p><p>You are given a string answerKey, where answerKey[i] is the original answer to the ith question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:</p><ul><li>Change the answer key for any question to &#39;T&#39; or &#39;F&#39; (i.e., set answerKey[i] to &#39;T&#39; or &#39;F&#39;).</li></ul><p>Return <em>the </em><strong><em>maximum</em></strong><em> number of consecutive</em> &#39;T&#39;s or &#39;F&#39;s <em>in the answer key after performing the operation at most</em> k <em>times</em>.</p><p><strong>Example 1:</strong></p><pre>Input: answerKey = &quot;TTFF&quot;, k = 2<br>Output: 4<br>Explanation: We can replace both the &#39;F&#39;s with &#39;T&#39;s to make answerKey = &quot;TTTT&quot;.<br>There are four consecutive &#39;T&#39;s.</pre><p><strong>Example 2:</strong></p><pre>Input: answerKey = &quot;TFFT&quot;, k = 1<br>Output: 3<br>Explanation: We can replace the first &#39;T&#39; with an &#39;F&#39; to make answerKey = &quot;FFFT&quot;.<br>Alternatively, we can replace the second &#39;T&#39; with an &#39;F&#39; to make answerKey = &quot;TFFF&quot;.<br>In both cases, there are three consecutive &#39;F&#39;s.</pre><p><strong>Example 3:</strong></p><pre>Input: answerKey = &quot;TTFTTFTT&quot;, k = 1<br>Output: 5<br>Explanation: We can replace the first &#39;F&#39; to make answerKey = &quot;TTTTTFTT&quot;<br>Alternatively, we can replace the second &#39;F&#39; to make answerKey = &quot;TTFTTTTT&quot;. <br>In both cases, there are five consecutive &#39;T&#39;s.</pre><h3>Answer:-</h3><pre>class Solution {<br>    public int maxConsecutiveAnswers(String answerKey, int k) {<br>        int ans = 0;<br>        int max_count = 0;<br>        int[] count = new int[2];<br>        for(int l = 0,r=0;r&lt;answerKey.length();r++)<br>        {<br>            max_count = Math.max(max_count,++count[answerKey.charAt(r) == &#39;T&#39; ? 1: 0]);<br>            while(max_count + k &lt; r-l+1)<br>            {<br>                --count[answerKey.charAt(l++) == &#39;T&#39;? 1 : 0];<br>            }<br>            ans = Math.max(ans,r-l+1);<br>        }<br>        return ans;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89b7240a8b2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[209. Minimum Size Subarray Sum — Leetcode Daily — 6 July 2023]]></title>
            <link>https://medium.com/@chetanvaghela457/209-minimum-size-subarray-sum-leetcode-daily-6-july-2023-f73f4e0b70af?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/f73f4e0b70af</guid>
            <category><![CDATA[dsa-courses]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Thu, 06 Jul 2023 14:43:10 GMT</pubDate>
            <atom:updated>2023-07-06T14:43:10.676Z</atom:updated>
            <content:encoded><![CDATA[<h3>209. Minimum Size Subarray Sum — Leetcode Daily — 6 July 2023</h3><h3>Question:-</h3><p>Given an array of positive integers nums and a positive integer target, return <em>the </em><strong><em>minimal length</em></strong><em> of a</em></p><p><em>subarray</em></p><p><em>whose sum is greater than or equal to</em> target. If there is no such subarray, return 0 instead.</p><p><strong>Example 1:</strong></p><pre>Input: target = 7, nums = [2,3,1,2,4,3]<br>Output: 2<br>Explanation: The subarray [4,3] has the minimal length under the problem constraint.</pre><p><strong>Example 2:</strong></p><pre>Input: target = 4, nums = [1,4,4]<br>Output: 1</pre><p><strong>Example 3:</strong></p><pre>Input: target = 11, nums = [1,1,1,1,1,1,1,1]<br>Output: 0</pre><h3>Answer:-</h3><pre>class Solution {<br>    public int minSubArrayLen(int target, int[] nums) {<br>        int i = 0; int j = 0;<br>        int sum = 0; int ans = 1000000;<br>        while(j&lt;nums.length){<br>            sum+=nums[j];<br>            while(sum&gt;=target){<br>                ans = Math.min(ans, j-i+1);<br>                sum -= nums[i];<br>                i++;<br>            }<br>            j++;<br>        }<br>        <br>        return ans==1000000?0:ans;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f73f4e0b70af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1493. Longest Subarray of 1’s After Deleting One Element — Leetcode Daily Challange]]></title>
            <link>https://medium.com/@chetanvaghela457/1493-longest-subarray-of-1s-after-deleting-one-element-leetcode-daily-challange-bcc29ca946c0?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcc29ca946c0</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[solutions]]></category>
            <category><![CDATA[leetcode-daily-challenge]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Wed, 05 Jul 2023 08:30:32 GMT</pubDate>
            <atom:updated>2023-07-05T08:30:32.502Z</atom:updated>
            <content:encoded><![CDATA[<h3>1493. Longest Subarray of 1’s After Deleting One Element — Leetcode Daily Challange</h3><h3><strong>Question:-</strong></h3><p>Given a binary array nums, you should delete one element from it.</p><p>Return <em>the size of the longest non-empty subarray containing only </em>1<em>&#39;s in the resulting array</em>. Return 0 if there is no such subarray.</p><p><strong>Example 1:</strong></p><pre>Input: nums = [1,1,0,1]<br>Output: 3<br>Explanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1&#39;s.</pre><p><strong>Example 2:</strong></p><pre>Input: nums = [0,1,1,1,0,1,1,0,1]<br>Output: 5<br>Explanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1&#39;s is [1,1,1,1,1].</pre><p><strong>Example 3:</strong></p><pre>Input: nums = [1,1,1]<br>Output: 2<br>Explanation: You must delete one element.</pre><h3><strong>Answer:-</strong></h3><pre>class Solution {<br>    public int longestSubarray(int[] nums) {<br>        int c1=0,c2=0,ans=0;<br>        for(int i:nums)<br>        {<br>            if(i==0)<br>            {<br>                ans=Math.max(ans,c1+c2);<br>                c2=c1;<br>                c1=0;<br>            }<br>            else c1++;<br>        }<br>        if(c1+c2==nums.length) return nums.length-1;<br>        return Math.max(ans,c1+c2);<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcc29ca946c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[137. Single Number II , Leetcode Daily Challenge Solution]]></title>
            <link>https://medium.com/@chetanvaghela457/137-single-number-ii-leetcode-daily-challenge-solution-81253cbbc2c9?source=rss-17a110246540------2</link>
            <guid isPermaLink="false">https://medium.com/p/81253cbbc2c9</guid>
            <category><![CDATA[daily-challenge]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Chetan vaghela]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 04:54:58 GMT</pubDate>
            <atom:updated>2023-07-04T04:54:58.884Z</atom:updated>
            <content:encoded><![CDATA[<h3>137. Single Number II , Leetcode Daily Challenge Solution</h3><h3>Question:-</h3><p>Given an integer array nums where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p><p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p><p><strong>Example 1:</strong></p><pre>Input: nums = [2,2,3,2]<br>Output: 3</pre><p><strong>Example 2:</strong></p><pre>Input: nums = [0,1,0,1,0,1,99]<br>Output: 99</pre><h3>Answer:-</h3><pre>class Solution {<br>    public int singleNumber(int[] nums) {<br><br>        int once = 0;<br>        int twice = 0;<br>        int thrice = 0;<br>        for (int i = 0; i &lt; nums.length; i ++){<br>            twice = twice | ( once &amp; nums[i]);<br>            once = once ^ nums[i];<br>            thrice = once &amp; twice;<br>            once = once &amp; (~thrice);<br>            twice = twice &amp; (~thrice);<br>        }<br>        return once;<br>        <br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81253cbbc2c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>