<?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>Forem: Ajinkya Patil</title>
    <description>The latest articles on Forem by Ajinkya Patil (@ajinkya_patil).</description>
    <link>https://forem.com/ajinkya_patil</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%2F1192596%2Fdfc48e5d-6e1d-4cf0-9def-f9c372db1bc6.jpg</url>
      <title>Forem: Ajinkya Patil</title>
      <link>https://forem.com/ajinkya_patil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ajinkya_patil"/>
    <language>en</language>
    <item>
      <title>RecyclerView Pagination in MVVM(Model-View-ViewModel) architecture using Scroll Listener</title>
      <dc:creator>Ajinkya Patil</dc:creator>
      <pubDate>Tue, 24 Oct 2023 07:01:51 +0000</pubDate>
      <link>https://forem.com/ajinkya_patil/recyclerview-pagination-in-mvvmmodel-view-viewmodel-architecture-using-scroll-listener-5cm5</link>
      <guid>https://forem.com/ajinkya_patil/recyclerview-pagination-in-mvvmmodel-view-viewmodel-architecture-using-scroll-listener-5cm5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why Pagination&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While using social media apps, we scroll until all posts from our social network are seen. Consider there are hundreds plus posts in your social media app. Requesting all data at once will have the following drawbacks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;List loading time will be high.&lt;/li&gt;
&lt;li&gt;Rendering all data on UI at once will cause a longer wait time for the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is Pagination&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Requesting data in bits instead of requesting all at once is called Pagination. When you open the Instagram app and scroll, it will show a list of posts. After some posts, an indicator will be shown at the bottom and it will request new posts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are 2 ways to implement Pagination in Android:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using RecyclerView Scroll Listener&lt;/li&gt;
&lt;li&gt;Using Jetpack’s Paging library. To implement using the Paging library, follow the below link:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/topic/libraries/architecture/paging/v3-overview?source=post_page-----19be70c31a30--------------------------------"&gt;https://developer.android.com/topic/libraries/architecture/paging/v3-overview?source=post_page-----19be70c31a30--------------------------------&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation using Scroll Listener&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your Activity/Fragment, add scroll listener 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;linearLayoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.rvListPurchaseOrderLines.layoutManager = linearLayoutManager
binding.rvListPurchaseOrderLines.adapter = adapter
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
        super.onScrolled(recyclerView, dx, dy)
        val visibleItemCount = linearLayoutManager.childCount
        val totalItemCount = linearLayoutManager.itemCount
        val firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition()

        if (!viewModel.isLoading.value!! &amp;amp;&amp;amp; 
            (visibleItemCount + firstVisibleItemPosition) &amp;gt;= totalItemCount &amp;amp;&amp;amp; 
            firstVisibleItemPosition &amp;gt;= 0) {
            viewModel.fetchNextPage()
        }
    }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In View Model, request next page data 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;class MyFeedsViewModel(private val repository: MyFeedsRepository) : ViewModel() {
    val feedsDataList: LiveData&amp;lt;List&amp;lt;MyFeedsData&amp;gt;&amp;gt; = MutableLiveData()
    val isLoading: LiveData&amp;lt;Boolean&amp;gt; = MutableLiveData()

    private var currentPage = 1

    fun fetchNextPage() {
        viewModelScope.launch {
            isLoading.postValue(true)
            val newData = repository.fetchData(page = currentPage)
            val currentData = feedsDataList.value ?: emptyList()
            (feedsDataList as MutableLiveData).postValue(currentData + newData)
            isLoading.postValue(false)
            currentPage++
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Repository, fetch data from DB, network, etc 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;class MyFeedsRepository {
    suspend fun fetchData(page: Int): List&amp;lt;MyFeedsData&amp;gt; {
    // You can fetch data from network, DB, etc.
       return database.feedsListDAO().getFeedsList()
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Fragment/Activity, observe live data 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;viewModel.feedsDataList.observe(this, Observer { dataList -&amp;gt;
    adapter.submitList(dataList)
})

viewModel.isLoading.observe(this, Observer { isLoading -&amp;gt;
    if(isLoading) {
        progressBar.visibility = View.VISIBLE
    } else {
        progressBar.visibility = View.GONE
    }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it! With this setup, your RecyclerView will fetch new pages of data as the user scrolls. Adjust the specifics of the data fetching and update logic according to your needs. Thanks for reading.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>mvvm</category>
    </item>
    <item>
      <title>Overview of Mobile Device Management(MDM)</title>
      <dc:creator>Ajinkya Patil</dc:creator>
      <pubDate>Tue, 24 Oct 2023 06:50:24 +0000</pubDate>
      <link>https://forem.com/ajinkya_patil/overview-of-mobile-device-managementmdm-2pci</link>
      <guid>https://forem.com/ajinkya_patil/overview-of-mobile-device-managementmdm-2pci</guid>
      <description>&lt;p&gt;In the recent past, we have implemented MDM solutions for our mobile apps. In this post, I will share brief information about MDM and its available market solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is MDM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MDM is all about remotely managing devices. It provides solutions to businesses by managing devices on their own terms.&lt;br&gt;
Some uses of MDM are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enforcing corporate policies.&lt;/li&gt;
&lt;li&gt;Securing corporate documents/emails.&lt;/li&gt;
&lt;li&gt;Providing specific features in apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What MDM can manage&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Applications: Remotely install/update/delete apps.&lt;/li&gt;
&lt;li&gt;Access Restriction: Configure WiFi access, secure content on the device, etc.&lt;/li&gt;
&lt;li&gt;Remote Management: Wipe the device, turn the screen off/on, lock the device, etc.&lt;/li&gt;
&lt;li&gt;Content Management: Deleting files/Updating files, Adding new files to the device, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What advantages MDM can provide&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App Management: IT admins can deploy, set up, control and update mobile apps easily.&lt;/li&gt;
&lt;li&gt;Web filtering: IT admins can approve websites that can be accessed on enrolled devices. This increases productivity as the device will be used for work purposes only.&lt;/li&gt;
&lt;li&gt;Remote Access: IT admins can access and control enrolled devices whenever required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What MDM solutions are available&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are many MDM solutions available in the market. However, you need to choose based on your requirements. Hence, consider the following parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Platforms: MDM vendors support major platforms like Android, iOS, Windows, macOS, etc. However, every MDM vendor doesn’t support all platforms.&lt;/li&gt;
&lt;li&gt;Easy to use: MDM vendors have different user interface(UI) and user experience(UX). Hence, choose an MDM vendor with an easy-to-use UI and good UX.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below are some MDM solutions available in the market:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cisco Meraki&lt;/li&gt;
&lt;li&gt;Jamf PRO&lt;/li&gt;
&lt;li&gt;Fleetsmith&lt;/li&gt;
&lt;li&gt;Microsoft Endpoint Manager&lt;/li&gt;
&lt;li&gt;Workspace ONE UEM&lt;/li&gt;
&lt;li&gt;MobileIron&lt;/li&gt;
&lt;li&gt;Apperian&lt;/li&gt;
&lt;li&gt;Dell EMM&lt;/li&gt;
&lt;li&gt;Citrix XenMobile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;p&gt;&lt;u&gt;- &lt;a href="https://en.wikipedia.org/wiki/Mobile_device_management"&gt;https://en.wikipedia.org/wiki/Mobile_device_management&lt;/a&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/work/index.html"&gt;https://developer.android.com/work/index.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>mdm</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
