<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: raystatic</title>
    <description>The latest articles on DEV Community by raystatic (@raystatic).</description>
    <link>https://dev.to/raystatic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F481708%2F6c97f68a-69ef-4712-a7fe-66f76c23e2e2.jpeg</url>
      <title>DEV Community: raystatic</title>
      <link>https://dev.to/raystatic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raystatic"/>
    <language>en</language>
    <item>
      <title>"Support for password authentication was removed on August 13, 2021. Please use a personal access token instead."</title>
      <dc:creator>raystatic</dc:creator>
      <pubDate>Tue, 24 Aug 2021 18:02:52 +0000</pubDate>
      <link>https://dev.to/raystatic/support-for-password-authentication-was-removed-on-august-13-2021-please-use-a-personal-access-token-instead-2p99</link>
      <guid>https://dev.to/raystatic/support-for-password-authentication-was-removed-on-august-13-2021-please-use-a-personal-access-token-instead-2p99</guid>
      <description>&lt;p&gt;Recently, everyone is getting this message from Github.&lt;/p&gt;

&lt;p&gt;So, Github has removed the support for password authentication and now we have to use &lt;strong&gt;Personal Access Token (PAT)&lt;/strong&gt; in place of passwords to authenticate ourselves.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5eeaw99iggyjtzdwxnew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5eeaw99iggyjtzdwxnew.png" alt="Message"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's see how this works and move on to our lives!&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to your settings&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhj9qbf302toyv6rhgi6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhj9qbf302toyv6rhgi6a.png" alt="Settings"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Developer Settings&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gclgfjj7zkwb7dbrgen.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gclgfjj7zkwb7dbrgen.png" alt="Developer Settings"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Personal Access Token and click on Generate new token&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7n41hfbebi41cji93p9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7n41hfbebi41cji93p9.png" alt="Genrate new token"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select expiration duration and scopes for the token.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnld1gv6q4z30l8jpupi7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnld1gv6q4z30l8jpupi7.png" alt="Create Token"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once token is created make sure to copy your token to somewhere safe because you won't be able to see it again.&lt;br&gt;
If you lost it, you will have to create a new one.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxbrm4qdwbkwgykgkxrj3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxbrm4qdwbkwgykgkxrj3.png" alt="Token Created"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, you can use your PAT in place of your password and your code will be pushed.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwsfs42s6iqyftbe8k0y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwsfs42s6iqyftbe8k0y.png" alt="Code pushed"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you don't want to enter your PAT every time, you can save your git credentials in cache.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global credential.helper cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it, now we can get back to our bugs peacefully!&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>security</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to add a FAB within BottomNavigationView ⚡️</title>
      <dc:creator>raystatic</dc:creator>
      <pubDate>Sun, 01 Nov 2020 17:45:19 +0000</pubDate>
      <link>https://dev.to/raystatic/how-to-add-a-fab-within-bottomnavigationview-1dd4</link>
      <guid>https://dev.to/raystatic/how-to-add-a-fab-within-bottomnavigationview-1dd4</guid>
      <description>&lt;p&gt;In this article I will show you how to make a custom bottom navigation view in your Android Projects.&lt;/p&gt;

&lt;p&gt;So first of all lets update our build.gradle files.&lt;br&gt;
Open your build.gradle(app) file and add some sruffs there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'androidx.navigation.safeargs.kotlin'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add these plugins on top of your file. These are necessary for having bottom navigation view.&lt;/p&gt;

&lt;p&gt;Now add a dependency in the same file in the &lt;strong&gt;dependencies&lt;/strong&gt; block&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    implementation "androidx.navigation:navigation-ui-ktx:2.3.1"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding these, now move on to build.gradle(project-level) file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    dependencies {
        classpath "com.android.tools.build:gradle:4.1.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is must to add this classpath otherwise your dependency will not be imported.&lt;/p&gt;

&lt;p&gt;Logically we cannot add another view (fab) inside the bottom navigation view but we can achieve this by doing a workaround.&lt;/p&gt;

&lt;p&gt;First change your root view to Coordinator Layout then we will add a widget called BottomAppBar. Our bottom navigation view will be wrapped inside this bottomAppBar.&lt;/p&gt;

&lt;p&gt;Then we will add a FAB which will be anchored with the bottomAppBar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;androidx.coordinatorlayout.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"&amp;gt;
    &amp;lt;com.google.android.material.bottomappbar.BottomAppBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:id="@+id/bottomAppBar"
        app:fabCradleMargin="10dp"
        app:fabCradleRoundedCornerRadius="20dp"&amp;gt;
        &amp;lt;com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:menu="@menu/bttom_nav_menu"
            android:background="@android:color/transparent"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp" /&amp;gt;

    &amp;lt;/com.google.android.material.bottomappbar.BottomAppBar&amp;gt;
    &amp;lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fab"
        android:src="@drawable/ic_camera"
        app:layout_anchor="@id/bottomAppBar" /&amp;gt;
&amp;lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s create a menu for our navigation called bottom_nav_menu. This will be placed under the menu directory in resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&amp;gt;

    &amp;lt;item
        android:id="@+id/miHome"
        android:title="Home"
        android:icon="@drawable/ic_home"/&amp;gt;

    &amp;lt;item
        android:id="@+id/miChat"
        android:title="Chat"
        android:icon="@drawable/ic_chat"/&amp;gt;

    &amp;lt;item
        android:id="@+id/miPlaceholder"
        android:title=""/&amp;gt;

    &amp;lt;item
        android:id="@+id/miCloud"
        android:title="Cloud"
        android:icon="@drawable/ic_cloud"/&amp;gt;


    &amp;lt;item
        android:id="@+id/miSettings"
        android:title="Settings"
        android:icon="@drawable/ic_settings"/&amp;gt;

&amp;lt;/menu&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have added five items to our menu because we want to place out FAB in the middle and to evenly space the items.&lt;/p&gt;

&lt;p&gt;We have made the third item as a placeholder and will disable it so that it’s functionality doesn’t create any conflicts.&lt;/p&gt;

&lt;p&gt;Right now, the bottomNavigationView is not looking nice because of overlapping background, so will set its background to null.&lt;br&gt;
We cannot do that in the XML file, so we will it the MainActivity class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        bottomNavigationView.background = null

        bottomNavigationView.menu.getItem(2).isEnabled = false

        fab.setOnClickListener {
            Toast.makeText(this, "I'm working dude!", Toast.LENGTH_SHORT).show()
        }

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we have set the background to null and disabled the functionality of 3rd item of the menu.&lt;/p&gt;

&lt;p&gt;I am adding a working demo for the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5IEFiwXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qw0h1iv49dx8963waifo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5IEFiwXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qw0h1iv49dx8963waifo.gif" alt="demo_gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, this looks fine. To stay tuned for my further articles on Android stuffs follow me and connect me on &lt;a href="https://www.linkedin.com/in/rahul-ray-1b6748151/"&gt;LinkedIn here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>bottomnavigationview</category>
      <category>materialdesign</category>
    </item>
    <item>
      <title>Welcome Preferences DataStore 🚀</title>
      <dc:creator>raystatic</dc:creator>
      <pubDate>Sun, 04 Oct 2020 08:58:44 +0000</pubDate>
      <link>https://dev.to/raystatic/welcome-preferences-datastore-88b</link>
      <guid>https://dev.to/raystatic/welcome-preferences-datastore-88b</guid>
      <description>&lt;p&gt;Hello developers, in this article I am going to cover a new member of Jetpack Library 🚀 called &lt;strong&gt;DataStore&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We are working on shared preferences for a long time to store some of the data locally in our android apps and we know how shared preferences proved to be very useful to support our use cases.&lt;/p&gt;

&lt;p&gt;To make our lives easier Android has introduced DataStore to implement Shared Preferences in our apps in a more efficient way.&lt;/p&gt;

&lt;p&gt;DataStore provides two types of implementation,i.e; &lt;strong&gt;Preferences DataStore&lt;/strong&gt; and &lt;strong&gt;Proto DataStore&lt;/strong&gt;. Today we are looking at Preferences DataStore.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So, why should we use Preferences DataStore? 😕&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is an Async API that can be used via Flow&lt;/li&gt;
&lt;li&gt;It is safe to call on UI thread since work is moved to Dispatchers.IO under the hood&lt;/li&gt;
&lt;li&gt;It can signal errors&lt;/li&gt;
&lt;li&gt;It is safe from runtime exceptions&lt;/li&gt;
&lt;li&gt;It has a transactional API with strong consistency&lt;/li&gt;
&lt;li&gt;It handles data migration from Shared Preferences&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;This dude has some Advantages, right! 😃&lt;/p&gt;

&lt;p&gt;Now, let’s directly jump into the code 💻&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For this example I have used Dagger-Hilt to provide dependency Injection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s update our build.gradle files like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

android {

   ...

    // Compile options
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

}

dependencies {
    ....

    // Preferences DataStore
    implementation "androidx.datastore:datastore-preferences:1.0.0-alpha01"

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

    // Kotlin coroutines components
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"

    //Dagger - Hilt
    implementation "com.google.dagger:hilt-android:2.28-alpha"
    kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

   ....

    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create an Application class DataStore as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@HiltAndroidApp
class DataStore: Application() {

    override fun onCreate() {
        super.onCreate()
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will create a &lt;strong&gt;DataManager&lt;/strong&gt; class where all our logic will go. For this example I have stored user’s name, GitHub username and favorite number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class DataManager(context: Context) {

    private val dataStore = context.createDataStore("data_prefs")

    companion object{
        val USER_NAME = preferencesKey&amp;lt;String&amp;gt;("USER_NAME")
        val USER_GITHUB = preferencesKey&amp;lt;String&amp;gt;("USER_GITHUB")
        val USER_NO = preferencesKey&amp;lt;Int&amp;gt;("USER_NO")
    }

    suspend fun storeData(name:String, github:String, no:Int){
        dataStore.edit {
            it[USER_NAME] = name
            it[USER_GITHUB] = github
            it[USER_NO] = no
        }
    }

    val userNameFlow:Flow&amp;lt;String&amp;gt; = dataStore.data.map {
        it[USER_NAME] ?: ""
    }

    val userGithubFlow:Flow&amp;lt;String&amp;gt; = dataStore.data.map {
        it[USER_GITHUB] ?: ""
    }

    val userNo: Flow&amp;lt;Int&amp;gt; = dataStore.data.map {
        it[USER_NO] ?: -1
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the &lt;strong&gt;storeData&lt;/strong&gt; function is made suspend because to make it asynchronous and we love &lt;em&gt;coroutines&lt;/em&gt;💛&lt;/p&gt;

&lt;p&gt;Next, we will create our &lt;em&gt;AppModule&lt;/em&gt; which will provide this DataManager&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Module
@InstallIn(ApplicationComponent::class)
object AppModule {

    @Singleton
    @Provides
    fun provideDataManager(@ApplicationContext context: Context) = DataManager(context)

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will provide a &lt;strong&gt;Singleton&lt;/strong&gt; of &lt;strong&gt;DataManager&lt;/strong&gt; to our application&lt;/p&gt;

&lt;p&gt;It’s time to create a layout for our main activity as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="#0E0E0E"&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:fontFamily="@font/poppins_medium"
        android:text="Data Store Example"
        android:textColor="#fff"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/tvTitle"/&amp;gt;

    &amp;lt;EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/tvTitle"
        android:backgroundTint="@color/colorPrimary"
        android:textColor="#fff"
        android:hint="Enter name"
        android:textColorHint="#8C8C8C"
        android:fontFamily="@font/poppins_medium"
        android:layout_marginTop="50dp"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp"
        android:id="@+id/etName"/&amp;gt;

    &amp;lt;EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/etName"
        android:backgroundTint="@color/colorPrimary"
        android:textColor="#fff"
        android:hint="Github username"
        android:textColorHint="#8C8C8C"
        android:fontFamily="@font/poppins_medium"
        android:layout_marginTop="20dp"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp"
        android:id="@+id/etgithub"/&amp;gt;

    &amp;lt;EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/etgithub"
        android:backgroundTint="@color/colorPrimary"
        android:textColor="#fff"
        android:hint="Enter favourite Number"
        android:textColorHint="#8C8C8C"
        android:fontFamily="@font/poppins_medium"
        android:layout_marginTop="20dp"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp"
        android:id="@+id/etNumber"/&amp;gt;

    &amp;lt;com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/etNumber"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginTop="20dp"
        android:backgroundTint="@color/colorPrimary"
        app:cornerRadius="25dp"
        android:text="SAVE"
        android:paddingStart="20dp"
        android:paddingEnd="20dp"
        android:textColor="#fff"
        android:id="@+id/btnSave"/&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/btnSave"
        app:layout_constraintStart_toStartOf="parent"
        android:text="No data saved to display!"
        android:textColor="#fff"
        android:textSize="16sp"
        android:inputType="number"
        android:id="@+id/tvName"
        android:visibility="gone"
        android:fontFamily="@font/poppins_medium"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginTop="30dp"/&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/tvName"
        app:layout_constraintStart_toStartOf="parent"
        android:text="No data saved to display!"
        android:textColor="#fff"
        android:textSize="16sp"
        android:visibility="gone"
        android:id="@+id/tvGithub"
        android:fontFamily="@font/poppins_medium"
        app:layout_constraintEnd_toEndOf="parent"/&amp;gt;

    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/tvGithub"
        app:layout_constraintStart_toStartOf="parent"
        android:text="No data saved to display!"
        android:textColor="#fff"
        android:textSize="16sp"
        android:id="@+id/tvNo"
        android:visibility="gone"
        android:fontFamily="@font/poppins_medium"
        app:layout_constraintEnd_toEndOf="parent"/&amp;gt;

&amp;lt;/androidx.constraintlayout.widget.ConstraintLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally here comes our MainActivity 😌&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var dataManager: DataManager
    private var name:String = ""
    private var github:String = ""
    private var no:Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        subscribeToObservers()

        btnSave.setOnClickListener {
            val name:String = etName.text.toString()
            val github:String = etgithub.text.toString()
            val no:Int = etNumber.text.toString().toInt()

            if (name.isNotEmpty() &amp;amp;&amp;amp; github.isNotEmpty() &amp;amp;&amp;amp; no!=-1){
                GlobalScope.launch {
                    dataManager.storeData(name,github,no)
                }
            }else{
                Toast.makeText(this, "Enter details carefully!", Toast.LENGTH_SHORT).show()
            }

        }

    }

    private fun subscribeToObservers() {

        dataManager.userNameFlow.asLiveData().observe(this) {
            name = it
            if (name.isNotEmpty()){
                tvName.visibility = View.VISIBLE
                tvName.text = "Name: $name"
            }
        }

        dataManager.userGithubFlow.asLiveData().observe(this) {
            github = it
            if (github.isNotEmpty()){
                tvGithub.visibility = View.VISIBLE
                tvGithub.text = "Github: $github"
            }
        }

        dataManager.userNo.asLiveData().observe(this) {
            no = it
            if (no != -1){
                tvNo.visibility = View.VISIBLE
                tvNo.text = "Number: $no"
            }
        }

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have observed on our Preferences Keys as LiveData and made them visible.&lt;/p&gt;

&lt;p&gt;Everything is pretty smooth and straight forward in this implementation 😌&lt;/p&gt;

&lt;p&gt;For complete code reference checkout this &lt;a href="https://github.com/raystatic/Preference_store_demo/"&gt;repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you in the next story..&lt;/p&gt;

</description>
      <category>android</category>
      <category>datastore</category>
      <category>kotlin</category>
      <category>sharedpreferences</category>
    </item>
  </channel>
</rss>
