<?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 Abhishek Srivastava on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Srivastava on Medium]]></description>
        <link>https://medium.com/@innovatingideas?source=rss-c642e3fbd5ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Abhishek Srivastava on Medium</title>
            <link>https://medium.com/@innovatingideas?source=rss-c642e3fbd5ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:21:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@innovatingideas/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[Endless list scrolling with RecyclerView or ListView in Kotlin in 4 steps with the easiest way…]]></title>
            <link>https://innovatingideas.medium.com/endless-list-scrolling-with-recyclerview-or-listview-in-kotlin-in-4-steps-with-the-easiest-way-ad8ab1e204e7?source=rss-c642e3fbd5ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad8ab1e204e7</guid>
            <dc:creator><![CDATA[Abhishek Srivastava]]></dc:creator>
            <pubDate>Thu, 05 Nov 2020 07:12:28 GMT</pubDate>
            <atom:updated>2020-11-05T07:50:47.960Z</atom:updated>
            <content:encoded><![CDATA[<h3>Endless list scrolling with RecyclerView or ListView in Kotlin in 4 steps with the easiest way using RestAPI</h3><p>Hi Readers,</p><p>Today’s, Every mostly applications have Endless list scrolling features there i.e INSTAGRAM, FACEBOOK, FLIPKART, and so on…</p><p>So that this common feature in the application is to load automatically more items as the user scrolls through the items endless list.</p><p>There are so many prons like</p><p>1: You don’t want to make a huge API request call to the server, making your user wait infinitely or much time.</p><p>2: You don’t want to make your UI or App look like the 90&#39;s generation with Next and previous button.</p><p>In such a scenario implementing an endless scroll might be the ideal choice.</p><p>This choice is working like to provide the appearance of endless scrolling, it’s important to fetch data before the user gets to the end of the list. That the time you can add more value to call the next RESTAPI request to the server and get data and therefore need to append more data and show the user without block user UI and get the best user experience.0</p><p>If We have to implement an Endless list in our code that a big task and more difficult, especially for beginners. So here the solution with a simple and easy way to implement Endless list scrolling in our code within few steps. I have also pushed the code in GITHUB and you can find the complete code at my GitHub link which is mentioned below.</p><p>So Readers, Can We Start?</p><p>Yes !! We are ready.</p><blockquote><a href="https://github.com/abhi10jul/EndlessListScrolling_KotlinExample/blob/master/demo.gif"><strong>Sample of Demo link &amp; Video</strong></a></blockquote><p><a href="https://github.com/abhi10jul/EndlessListScrolling_KotlinExample/blob/master/demo.gif">abhi10jul/EndlessListScrolling_KotlinExample</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fharshentirecockerspaniel&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Fharshentirecockerspaniel&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FHarshEntireCockerspaniel-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="1080" height="1920" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddbe94cf1c8c6a6bae42e085c3861b02/href">https://medium.com/media/ddbe94cf1c8c6a6bae42e085c3861b02/href</a></iframe><blockquote><strong>Sample of API URL:</strong></blockquote><p><strong><em>{{baseURL}}/api/{{endpoint}}??page={{currentPageNumber}}</em></strong></p><p>Sample of API response:</p><p><strong><em>{<br>page: 1, //This is current page<br>pages: 108, //This is total pages</em></strong></p><p><strong><em>otherObjectKey: [otherResponseObject]<br>}</em></strong></p><blockquote><strong><em>Page and Pages is mandatory in API response to use Endless list Scrolling</em></strong></blockquote><h3><strong>STEP 1:</strong></h3><p>First, You have implemented Retrofit APICLIENT and API SERVICE to establish a connection and get data from the server.</p><p>Here, We need the below classes and dependencies</p><p>i)Dependencies</p><p>ii) ApiClient</p><p>iii)ApiService</p><blockquote><strong>Add Dependencies in your build.gradle</strong></blockquote><pre><em>//TODO Retrofit<br></em>implementation &#39;com.squareup.retrofit2:retrofit:2.9.0&#39;<br>implementation &#39;com.google.code.gson:gson:2.8.6&#39;<br>implementation &#39;com.squareup.retrofit2:converter-gson:2.9.0&#39;</pre><pre><em>//TODO GLIDE implementation for fetch images<br></em>implementation &#39;com.github.bumptech.glide:glide:4.11.0&#39;<br>annotationProcessor &#39;com.github.bumptech.glide:compiler:4.11.0&#39;</pre><pre>implementation &#39;androidx.cardview:cardview:1.0.0&#39;<br><em>//TODO For dimension<br></em>implementation &#39;com.intuit.sdp:sdp-android:1.0.6&#39;</pre><blockquote><strong>ApiClient.kt</strong></blockquote><pre>package com.github.abhi10jul.endlesslistscrolling_kotlinexample<br><br>import retrofit2.Callback<br>import retrofit2.Retrofit<br>import retrofit2.converter.gson.GsonConverterFactory<br><br><em>/**<br> *  @author abhishek srivastava.<br> */<br></em>class ApiClient <em>{<br>    </em>private val BASE_URL = &quot;{{ADD YOUR BASE URL}}&quot;<br>    private var apiService: ApiService = Retrofit.Builder<em>()<br>        </em>.baseUrl<em>(</em>BASE_URL<em>)<br>        </em>.addConverterFactory<em>(</em>GsonConverterFactory.create<em>())<br>        </em>.build<em>()<br>        </em>.create<em>(</em>ApiService::class.<em>java)<br><br>    </em>fun callTvShowListRequest<em>(</em>page: Int, callback: Callback<em>&lt;</em>ShowModel<em>&gt;) {<br>        </em>apiService.getTvShowList<em>(</em>page<em>)</em>.enqueue<em>(</em>callback<em>)<br>    }<br>}</em></pre><blockquote><strong><em>ApiService.kt</em></strong></blockquote><pre>package com.github.abhi10jul.endlesslistscrolling_kotlinexample<br><br>import retrofit2.Call<br>import retrofit2.http.GET<br>import retrofit2.http.Query<br><br><em>/**<br> *  @author abhishek srivastava.<br> */<br></em>interface ApiService <em>{<br><br>    </em>@GET<em>(</em>&quot;{{ADD YOUR END POINT}}&quot;<em>)<br>    </em>fun getTvShowList<em>(</em>@Query<em>(</em>&quot;page&quot;<em>) </em>page: Int<em>)</em>: Call<em>&lt;</em>ShowModel<em>&gt;<br><br>}</em></pre><h3>STEP 2:</h3><p>Add Your model class base on response and make sure ‘PAGE’ &amp; ‘PAGES’ is there in response.</p><p>i) ShowModel.kt</p><p>ii) TvShow.kt</p><blockquote><strong>ShowModel.kt</strong></blockquote><pre><br>package com.github.abhi10jul.endlesslistscrolling_kotlinexample<br><br>import com.google.gson.annotations.Expose<br>import com.google.gson.annotations.SerializedName<br><br><em>/**<br> *  @author abhishek srivastava.<br> */<br></em>data class ShowModel<em>(<br>    </em>@SerializedName<em>(</em>&quot;total&quot;<em>)<br>    </em>@Expose val total: String,<br>    @SerializedName<em>(</em>&quot;page&quot;<em>)<br>    </em>@Expose<br>    val page: Int,<br>    @SerializedName<em>(</em>&quot;pages&quot;<em>)<br>    </em>@Expose<br>    val pages: Int,<br>    @SerializedName<em>(</em>&quot;tv_shows&quot;<em>)<br>    </em>@Expose<br>    val tvShows: ArrayList<em>&lt;</em>TvShow<em>&gt;<br>)</em></pre><blockquote><strong>TVShow.kt</strong></blockquote><pre>data class TvShow<em>(<br>    </em>@SerializedName<em>(</em>&quot;id&quot;<em>)<br>    </em>@Expose<br>    val id: Int,<br>    @SerializedName<em>(</em>&quot;name&quot;<em>)<br>    </em>@Expose<br>    val name: String,<br>    @SerializedName<em>(</em>&quot;status&quot;<em>)<br>    </em>@Expose<br>    val status: String,<br>    @SerializedName<em>(</em>&quot;image_thumbnail_path&quot;<em>)<br>    </em>@Expose val imageThumbnailPath: String<br><em>)</em></pre><h3>STEP 3:</h3><p>Now We can design the UI part for “main view” and “child view”.</p><p>i)activity_main.xml</p><p>ii)show_list_raw.xml</p><blockquote><strong>activity_main.xml</strong></blockquote><pre><em>&lt;?</em>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;<em>?&gt;<br>&lt;</em>layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    tools:context=&quot;.MainActivity&quot;<em>&gt;<br><br>    &lt;</em>RelativeLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<em>&gt;<br><br>        &lt;</em>TextView<br>            android:id=&quot;@+id/tvTitle&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;@dimen/_40sdp&quot;<br>            android:layout_alignParentTop=&quot;true&quot;<br>            android:background=&quot;@color/purple_200&quot;<br>            android:gravity=&quot;center_vertical|center_horizontal&quot;<br>            android:text=&quot;Endless Scrolling RecyclerView&quot;<br>            android:textAppearance=&quot;@style/TextAppearance.AppCompat.Large&quot;<br>            android:textColor=&quot;@color/white&quot;<br>            android:textStyle=&quot;bold&quot; <em>/&gt;<br><br>        &lt;</em>ProgressBar<br>            android:id=&quot;@+id/defaultProgress&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_below=&quot;@+id/tvTitle&quot;<br>            android:layout_centerHorizontal=&quot;true&quot;<br>            android:indeterminate=&quot;true&quot;<br>            android:visibility=&quot;gone&quot; <em>/&gt;<br><br>        &lt;</em>androidx.recyclerview.widget.RecyclerView<br>            android:id=&quot;@+id/recyclerview&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            android:layout_above=&quot;@id/loadMoreProgress&quot;<br>            android:layout_below=&quot;@+id/defaultProgress&quot; <em>/&gt;<br><br>        &lt;</em>ProgressBar<br>            android:id=&quot;@+id/loadMoreProgress&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_alignParentBottom=&quot;true&quot;<br>            android:layout_centerHorizontal=&quot;true&quot;<br>            android:indeterminate=&quot;true&quot;<br>            android:visibility=&quot;gone&quot; <em>/&gt;<br>    &lt;/</em>RelativeLayout<em>&gt;<br>&lt;/</em>layout<em>&gt;</em></pre><blockquote><strong>show_list_raw.xml</strong></blockquote><pre><em>&lt;?</em>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;<em>?&gt;<br>&lt;</em>layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<em>&gt;<br><br>    &lt;</em>androidx.cardview.widget.CardView<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_marginStart=&quot;@dimen/_5sdp&quot;<br>        android:layout_marginTop=&quot;@dimen/_2sdp&quot;<br>        android:layout_marginEnd=&quot;@dimen/_5sdp&quot;<br>        android:layout_marginBottom=&quot;@dimen/_2sdp&quot;<br>        app:cardCornerRadius=&quot;@dimen/_20sdp&quot;<em>&gt;<br><br>        &lt;</em>LinearLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:gravity=&quot;center_vertical|center_horizontal&quot;<br>            android:orientation=&quot;horizontal&quot;<em>&gt;<br><br>            &lt;</em>ImageView<br>                android:id=&quot;@+id/thumbnail&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;@dimen/_70sdp&quot;<br>                android:layout_gravity=&quot;center_vertical|center_horizontal&quot;<br>                android:layout_weight=&quot;1.7&quot;<br>                android:contentDescription=&quot;@string/app_name&quot;<br>                android:scaleType=&quot;centerCrop&quot; <em>/&gt;<br><br><br>            &lt;</em>TextView<br>                android:id=&quot;@+id/tvTitle&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:layout_gravity=&quot;center_vertical|center_horizontal&quot;<br>                android:layout_weight=&quot;1&quot;<br>                android:background=&quot;@null&quot;<br>                android:fontFamily=&quot;sans-serif&quot;<br>                android:gravity=&quot;center_horizontal|center_vertical&quot;<br>                android:padding=&quot;@dimen/_2sdp&quot;<br>                android:singleLine=&quot;true&quot;<br>                android:textAppearance=&quot;@style/TextAppearance.AppCompat.Medium&quot;<br>                android:textColor=&quot;@color/black&quot; <em>/&gt;<br>        &lt;/</em>LinearLayout<em>&gt;<br>    &lt;/</em>androidx.cardview.widget.CardView<em>&gt;<br></em>&lt;/layout&gt;</pre><h3>STEP 4:</h3><p>Now We can set up the adapter to bind data in RecylerView. Here I have created a custom way to the adapter for updating list because sometimes in KOTLIN notify method i.e ‘notifyDataSetChanged<em>(), </em>notifyItemRangeInserted<em>() and so on…’ is not worked. So I can use a custom method to update the list.</em></p><p><em>So I have created </em><strong><em>“</em>fun updateList(tvShowList: ArrayList&lt;TvShow&gt;, oldCount: Int, tvShowListSize: Int)” </strong>in MainActivityAdapter class.</p><p>And also implement logic in “MainActivity.kt” to handle all “Endless list scrolling ”.</p><p>i)MainActivityAdapter.kt</p><p>ii)MainActivity.kt</p><blockquote><strong>MainActivityAdapter.kt</strong></blockquote><pre>package com.github.abhi10jul.endlesslistscrolling_kotlinexample<br><br>import android.view.LayoutInflater<br>import android.view.View<br>import android.view.ViewGroup<br>import androidx.recyclerview.widget.RecyclerView<br>import com.bumptech.glide.Glide<br>import com.github.abhi10jul.endlesslistscrolling_kotlinexample.databinding.ShowListRawBinding<br><br><em>/**<br> *  @author abhishek srivastava.<br> */<br></em>class MainActivityAdapter() :<br>    RecyclerView.Adapter<em>&lt;</em>MainActivityAdapter.MainActivityAdapterHolder<em>&gt;() {<br>    </em>private var tvShowList = ArrayList<em>&lt;</em>TvShow<em>&gt;()<br><br>    </em>override fun onCreateViewHolder<em>(</em>parent: ViewGroup, viewType: Int<em>)</em>: MainActivityAdapterHolder <em>{<br>        </em>return MainActivityAdapterHolder<em>(<br>            </em>LayoutInflater.from<em>(</em>parent.<em>context)</em>.inflate<em>(</em>R.layout.<em>show_list_raw</em>, parent, false<em>)<br>        )<br>    }<br><br>    </em>override fun onBindViewHolder<em>(</em>holder: MainActivityAdapterHolder, position: Int<em>) {<br>        </em>holder.binding.tvTitle.<em>text </em>= &quot;<em>${</em>tvShowList<em>[</em>position<em>]</em>.name<em>}</em>&quot;<br>        Glide<br>            .with<em>(</em>holder.itemView<em>)<br>            </em>.load<em>(</em>tvShowList<em>[</em>position<em>]</em>.imageThumbnailPath<em>)<br>            </em>.centerCrop<em>()<br>            </em>.placeholder<em>(</em>R.drawable.<em>ic_launcher_foreground)<br>            </em>.into<em>(</em>holder.binding.thumbnail<em>)<br>    }<br><br>    </em>override fun getItemCount<em>()</em>: Int <em>{<br>        </em>return tvShowList.size<br>    <em>}<br><br>    </em>class MainActivityAdapterHolder<em>(</em>itemView: View<em>) </em>: RecyclerView.ViewHolder<em>(</em>itemView<em>) {<br>        </em>val binding = ShowListRawBinding.bind<em>(</em>itemView<em>)<br>    }<br><br>    </em>fun updateList<em>(</em>tvShowList: ArrayList<em>&lt;</em>TvShow<em>&gt;</em>, oldCount: Int, tvShowListSize: Int<em>) {<br>        </em>this.tvShowList = tvShowList<br>        notifyDataSetChanged<em>()<br>        </em>notifyItemRangeInserted<em>(</em>oldCount, tvShowListSize<em>)<br>    }<br>}</em></pre><blockquote><strong>MainActivity.kt</strong></blockquote><pre>package com.github.abhi10jul.endlesslistscrolling_kotlinexample<br><br>import android.os.Bundle<br>import android.util.Log<br>import android.view.View<br>import androidx.appcompat.app.AppCompatActivity<br>import androidx.databinding.DataBindingUtil<br>import androidx.recyclerview.widget.LinearLayoutManager<br>import androidx.recyclerview.widget.RecyclerView<br>import com.github.abhi10jul.endlesslistscrolling_kotlinexample.databinding.ActivityMainBinding<br>import retrofit2.Call<br>import retrofit2.Callback<br>import retrofit2.Response<br><br>class MainActivity : AppCompatActivity<em>() {<br>    </em>private val TAG = MainActivity::class.<em>java</em>.<em>simpleName<br>    </em>private lateinit var binding: ActivityMainBinding<br>    private lateinit var mainActivityAdapter: MainActivityAdapter<br>    private var apiClient = ApiClient<em>()<br>    </em>private var currentPage = 1<br>    private var totalAvailablePages = 1<br>    private lateinit var tvShowList: ArrayList<em>&lt;</em>TvShow<em>&gt;<br><br>    </em>override fun onCreate<em>(</em>savedInstanceState: Bundle?<em>) {<br>        </em>super.onCreate<em>(</em>savedInstanceState<em>)<br>        </em>binding = DataBindingUtil.setContentView<em>(</em>this, R.layout.<em>activity_main)<br>        </em>initViews<em>()<br>    }<br><br><br>    </em>private fun initViews<em>() {<br>        </em>binding.recyclerview.setHasFixedSize<em>(</em>true<em>)<br>        </em>binding.recyclerview.<em>layoutManager </em>=<br>            LinearLayoutManager<em>(</em>this, LinearLayoutManager.<em>VERTICAL</em>, false<em>)<br>        </em>tvShowList = ArrayList<em>()<br>        </em>mainActivityAdapter = MainActivityAdapter<em>()<br>        </em>binding.recyclerview.<em>adapter </em>= mainActivityAdapter<br>        binding.recyclerview.addOnScrollListener<em>(</em>object : RecyclerView.OnScrollListener<em>() {<br>            </em>override fun onScrolled<em>(</em>recyclerView: RecyclerView, dx: Int, dy: Int<em>) {<br>                </em>super.onScrolled<em>(</em>recyclerView, dx, dy<em>)<br>                </em>if <em>(</em>!binding.recyclerview.canScrollVertically<em>(</em>1<em>)) {<br>                    </em>if <em>(</em>currentPage &lt;= totalAvailablePages<em>) {<br>                        </em>currentPage += 1<br>                        loadPageList<em>()<br>                    }<br>                }<br>            }<br>        })<br>        </em>loadPageList<em>()<br>    }<br><br>    </em>private fun loadPageList<em>() {<br>        </em>toogleLoading<em>()<br>        </em>apiClient.callTvShowListRequest<em>(</em>currentPage, object : Callback<em>&lt;</em>ShowModel<em>&gt; {<br>            </em>override fun onResponse<em>(</em>call: Call<em>&lt;</em>ShowModel<em>&gt;</em>, response: Response<em>&lt;</em>ShowModel<em>&gt;) {<br>                </em>if <em>(</em>response.<em>isSuccessful) {<br>                    </em>val showModel = response.body<em>()<br>                    </em>if <em>(</em>showModel != null<em>) {<br>                        </em>val oldCount = tvShowList.size<br>                        totalAvailablePages = showModel.pages<br>                        tvShowList.addAll<em>(</em>showModel.tvShows<em>)<br>                        </em>mainActivityAdapter.updateList<em>(</em>tvShowList, oldCount, tvShowList.size<em>)<br>                        </em>Log.e<em>(<br>                            </em>TAG,<br>                            &quot;oldCount $oldCount totalAvailablePages $totalAvailablePages tvShowList <em>${</em>tvShowList.size<em>}</em>&quot;<br>                        <em>)<br>                    }<br>                }<br>                </em>toogleLoading<em>()<br>            }<br><br>            </em>override fun onFailure<em>(</em>call: Call<em>&lt;</em>ShowModel<em>&gt;</em>, t: Throwable<em>) {<br>                </em>t.printStackTrace<em>()<br>                </em>Log.e<em>(</em>TAG, &quot;exception&quot;, t<em>)<br>                </em>toogleLoading<em>()<br>            }<br>        })<br>    }<br><br>    </em>private fun toogleLoading<em>() {<br>        </em>if <em>(</em>currentPage == 1<em>) {<br>            </em>if <em>(</em>binding.defaultProgress.<em>isShown) {<br>                </em>binding.defaultProgress.<em>visibility </em>= View.<em>GONE<br>            } </em>else <em>{<br>                </em>binding.defaultProgress.<em>visibility </em>= View.<em>VISIBLE<br>            }<br>        } </em>else <em>{<br>            </em>if <em>(</em>binding.loadMoreProgress.<em>isShown) {<br>                </em>binding.loadMoreProgress.<em>visibility </em>= View.<em>GONE<br>            } </em>else <em>{<br>                </em>binding.loadMoreProgress.<em>visibility </em>= View.<em>VISIBLE<br>            }<br>        }<br>    }<br>}</em></pre><p>Hope you learn</p><blockquote><strong>Project Sample Github Link</strong></blockquote><p>You can find the complete code at my GitHub link here.</p><p><a href="https://github.com/abhi10jul/EndlessListScrolling_KotlinExample">abhi10jul/EndlessListScrolling_KotlinExample</a></p><p>Thanks for reading!</p><p>Special Thanks to ALL ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad8ab1e204e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Android Data Binding in 2 steps with a simple way to make easier coding]]></title>
            <link>https://innovatingideas.medium.com/using-android-data-binding-in-2-steps-with-a-simple-way-to-make-easier-coding-cf8e7e71bf92?source=rss-c642e3fbd5ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf8e7e71bf92</guid>
            <dc:creator><![CDATA[Abhishek Srivastava]]></dc:creator>
            <pubDate>Sun, 27 Sep 2020 15:58:54 GMT</pubDate>
            <atom:updated>2020-09-27T16:00:14.787Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Reader,</p><p>The Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.</p><p>Layouts are often defined in activities with code that calls UI framework methods. For example, the code below calls <a href="https://developer.android.com/reference/android/app/Activity#findViewById(int)">findViewById()</a> to find a <a href="https://developer.android.com/reference/android/widget/TextView">TextView</a> widget and bind it to the userName property of the viewModel variable:</p><p>Java:</p><pre>TextView textView = findViewById(R.id.sample_text);<br>textView.setText(viewModel.getUserName());</pre><p>Kotlin:</p><pre>findViewById&lt;TextView&gt;(R.id.sample_text).apply {<br>    text = viewModel.userName<br>}</pre><blockquote><strong>So Reader We can start</strong></blockquote><blockquote><strong>First Step:</strong></blockquote><p><strong>1: Enable data binding in your Android application</strong></p><p>Go to the app/build.gradle and add the below code</p><pre>android <strong><em>{<br>    </em></strong>...<br>    ...<br>    dataBinding <strong><em>{<br>        </em></strong>enabled = <strong>true<br>    <em>}<br>}</em></strong></pre><blockquote><strong>Now the time of step 2</strong></blockquote><p><strong>2: Go to your any .xml file in the layout folder</strong></p><p>I show you one example</p><p>I create <strong><em>activity_main.xml</em></strong> and I can use data-binding here. So that I add the below code in my XML file.</p><pre><strong><em>&lt;?</em>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;<em>?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;<br><br>    &lt;</em>RelativeLayout xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<em>&gt;<br><br>        &lt;</em>include<br>            android:id=&quot;@+id/toolbar&quot;<br>            layout=&quot;@layout/toolbar&quot; <em>/&gt;<br><br><br>    &lt;/</em>RelativeLayout<em>&gt;<br>&lt;/layout&gt;</em></strong></pre><ul><li>The layout should have <strong>&lt;layout&gt;</strong> as the root element. Inside &lt;layout&gt; the usual code of layout will be placed.</li><li>Once data binding is integrated into the layout file, goto <strong>Build -&gt; Clean Project</strong> and <strong>Build -&gt; Rebuild Project</strong>. This will generate necessary binding classes.</li><li>The generated binding classes follow the naming convention considering the layout file name in which binding is enabled. For the layout <strong>activity_main.xml</strong>, the generated binding class will be <strong>ActivityMainBinding</strong> (Binding suffix will be added at the end).</li></ul><blockquote><strong>Almost done</strong></blockquote><p>Now you can call any id of <strong><em>activity_main.xml </em></strong>in your activities like this</p><h3><strong><em>IN-ACTIVITY</em></strong></h3><pre><strong>public class </strong>MainActivity <strong>extends </strong>AppCompatActivity <strong><em>{<br>    </em>private </strong>ActivityMainBinding <strong>binding</strong>;<br>    <br>    @Override<br>    <strong>protected void </strong>onCreate<strong><em>(</em></strong>Bundle savedInstanceState<strong><em>) {<br>        </em>super</strong>.onCreate<strong><em>(</em></strong>savedInstanceState<strong><em>)</em></strong>;<br>        <em>/**<br>         * No need to add this below line so that you can remove <br>         */<br>        // setContentView(R.layout.activity_main); <br><br>        /**<br>         * Here the use of data-binding <br>         */<br>        </em><strong>binding </strong>= DataBindingUtil.<em>setContentView</em><strong><em>(</em>this</strong>, R.layout.<strong><em>activity_main)</em></strong>;<br><br>        <em>/**<br>         * Now you can access all id here I show you one example below<br>         */<br>        </em><strong>binding</strong>.<strong>textView</strong>.setText<strong><em>(</em>&quot;Binding is working&quot;<em>)</em></strong>;<br>    <strong><em>}<br>}</em></strong></pre><h3><strong><em>IN-FRAGMENT</em></strong></h3><pre><strong>public class </strong>MainFragment <strong>extends </strong>AppCompatActivity <strong><em>{<br>    </em>private </strong>ActivityMainBinding <strong>binding</strong>;<br>    @Override<br>    <strong>public </strong>View onCreateView<strong><em>(</em></strong>@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState<strong><em>) {<br>        </em>super</strong>.onCreate<strong><em>(</em></strong>savedInstanceState<strong><em>)</em></strong>;<br>        <em>/**<br>         * No need to add this below line so that you can remove<br>         */<br>        // setContentView(R.layout.activity_main);<br><br>        /**<br>         * Here the use of data-binding<br>         */<br>        </em><strong>binding </strong>= DataBindingUtil.<em>inflate</em><strong><em>(</em></strong>inflater, R.layout.<strong><em>activity_main</em></strong>, container, <strong>false<em>)</em></strong>;<br><br>        <em>/**<br>         * Now you can access all id here I show you one example below<br>         */<br>        </em><strong>binding</strong>.<strong>textView</strong>.setText<strong><em>(</em>&quot;Binding is working&quot;<em>)</em></strong>;</pre><pre>        /**<br>          This is required to return binding with getRoot</pre><pre>        */</pre><pre>        <strong>return binding</strong>.getRoot<strong><em>()</em></strong>;<br>    <strong><em>}<br>}</em></strong></pre><p><strong>For more references</strong></p><p>check out the official website: <a href="https://developer.android.com/topic/libraries/data-binding">https://developer.android.com/topic/libraries/data-binding</a></p><h3><strong>— — — — — — Now everything is finished. — — — — —</strong></h3><h3>Conclusion</h3><p>Those are not all the advantages of the DataBiding library but it’s time to end this article. I hope we have sparked your interest in this library, you have learned something new and will put this knowledge into practice.</p><p>Hope you learn</p><p>Thanks for reading!</p><p>Special Thanks to ALL ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf8e7e71bf92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Save Logs In Storage from Android Application]]></title>
            <link>https://innovatingideas.medium.com/save-logs-in-storage-from-android-application-6acc56c4c72a?source=rss-c642e3fbd5ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/6acc56c4c72a</guid>
            <dc:creator><![CDATA[Abhishek Srivastava]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 18:18:42 GMT</pubDate>
            <atom:updated>2023-01-04T09:27:14.608Z</atom:updated>
            <content:encoded><![CDATA[<p>I have created one library to save logs in local storage.</p><p>If you want to save logs in your local storage and access or check logs when the application is released or in production mode then you can narrow your records from storage.</p><p>There are a few steps to implement a logs library in your android code to save logs in local storage.</p><p>If you want to check this please go through the below link and check How to implement the save logs library in a few minutes</p><p><a href="https://github.com/abhi10jul/SaveLogsInStorage">abhi10jul/SaveLogsInStorage</a></p><p>Step 1. Add the JitPack repository to your build file</p><pre>allprojects {<br>	repositories {<br>		...<br>		maven { url &#39;https://jitpack.io&#39; }<br>	}<br>}</pre><p>Step 2. Add the dependency</p><pre>dependencies {<br>        implementation &#39;com.github.abhi10jul:SaveLogsInStorage:1.0.1&#39;<br>}</pre><p>Step 3. Add these variables in Activity or Fragment globally</p><pre>private static final int PERMISSION_REQUEST_CODE = 101;<br>public SaveLogsInStorage saveLoggerInstance;<br>public static final String directoryName = &quot;CustomLogger&quot;;</pre><p>Optional: You can also declare directoryName in a constant file or static variable because If you want to add like this you can easily use the same parameter in the SaveLogsInStorage constructor</p><p>Step 4. Ask to write storage permission to the User</p><pre>private boolean askWriteStoragePermission() {<br>    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {<br>        return (ContextCompat.checkSelfPermission(LauchingActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);<br>    }<br>    return true;<br>}</pre><pre>private void requestPermission() {<br>    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);<br>}</pre><p>Step 5. Get onRequestPermissionsResult</p><pre>@Override<br>public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {<br>    if (requestCode == PERMISSION_REQUEST_CODE) {<br>        if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {<br>            Log.i(&quot;value&quot;, &quot;Permission Granted, Now you can use save logs in local drive .&quot;);<br>            initialisedLogger();<br>        } else {<br>            Log.e(&quot;value&quot;, &quot;Permission Denied, You cannot use  save logs in local drive .&quot;);<br>            Toast.makeText(LauchingActivity.this, &quot;Write External Storage permission allows us to do store logs in local storage. Please allow this permission 		in App Settings.&quot;, Toast.LENGTH_LONG).show();<br>        }<br>    }<br>}</pre><p>Step 6: Initialise logger</p><pre>private void initialisedLogger() {<br>    /*<br>     * First initialised SaveLogsInStorage in variable<br>     * to access all save logs instance method<br>     */<br>    saveLoggerInstance = SaveLogsInStorage.getSaveLoggerInstance(this, directoryName);<br>    /*<br>     *Explain how to use all save logs instance method<br>     */<br>    printLogsInStorage();<br>  }</pre><pre>private void printLogsInStorage() {  <br>Log.i(TAG, &quot;save info logs&quot;);        saveLoggerInstance.saveInfoLogs(TAG, &quot;successfully saved info logs&quot;);        <br>Log.d(TAG, &quot;save debug logs&quot;);        saveLoggerInstance.saveDebugLogs(TAG, &quot;successfully saved debug logs&quot;);        <br>Log.w(TAG, &quot;save warning logs&quot;);        saveLoggerInstance.saveWarningLogs(TAG, &quot;successfully warnings info logs&quot;);        <br>Log.e(TAG, &quot;save error logs&quot;);        saveLoggerInstance.saveErrorLogs(TAG, &quot;successfully saved error logs&quot;);        <br>try {            <br>Log.e(TAG, &quot;save error logs with exception&quot;);            <br>//  int dividedZero = 1 / 0;        <br>} catch (Exception e) {            <br>e.printStackTrace();            saveLoggerInstance.saveErrorLogs(TAG, &quot;successfully saved error logs&quot;, e);        <br>}    <br>}</pre><p>Step 7: Read the below lines</p><p>Do not repeat Steps 1 to 5 for each Activity or fragment. These implement one time in Launching Activity or First Activity.<br>This is optional If you want to add all activities You can add these steps. These steps give us the benefit of checking permission all time</p><p>Examples 😍</p><p><a href="https://github.com/abhi10jul/SaveLogsInStorage/blob/master/app/src/main/java/com/blogspot/abhiandroidknowledge/customlogger/LauchingActivity.java">abhi10jul/SaveLogsInStorage</a></p><p>Special Thanks to ALL ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6acc56c4c72a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>