title: How to implement loadstate with adapter, recyclerView?
body: <p>I would like to implement a feature like loadStateFlow in Paging 3.
  I do not use pagination in my implementation and it is not necessary in my case.
  Could I make it another way?
  I have found something like LoadingStateAdapter library
  <a href="https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter" rel="nofollow noreferrer">https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter</a></p>
  <p>For now I get a list using method in the fragment:</p>
  <pre><code>    private fun collectNotificationItems() {
          vm.notificationData.collectWith(viewLifecycleOwner) {
              notificationAdapter.items = it
      }
  }
  </code></pre>
  <p>This is implementation I would like to achieve, example is in paging3:</p>
  <pre><code>    private fun collectItems() {
          vm.items.collectWith(viewLifecycleOwner, adapter::submitData)
          adapter.loadStateFlow.collectWith(viewLifecycleOwner) { loadState -&gt;
              vm.setLoadingState(loadState.refresh is LoadState.Loading)
              val isEmpty =
                  loadState.source.refresh is LoadState.NotLoading &amp;&amp; loadState.append.endOfPaginationReached &amp;&amp; archiveAdapter.itemCount &lt; 1
              vm.setEmptyStateVisible(isEmpty)
          }
      }
  </code></pre>
  <p>Where methods are:
  in ViewModel</p>
  <pre><code>    fun setLoadingState(isLoading: Boolean) {
          _areShimmersVisible.value = isLoading &amp;&amp; !_isSwipingToRefresh.value
          if (!isLoading) _isSwipingToRefresh.value = false
      }
  </code></pre>
  <p>areShimmers and isSwiping are MutableStateFlow</p>
  <p>Could you recommend any other options?</p>
  <p>EDIT:</p>
  <p>I have the whole implementation a little bit different.
  I have use case to make it</p>
  <pre><code>class GetListItemDetailsUseCase @Inject constructor(private val dao: Dao): BaseFlowUseCase&lt;Unit, List&lt;ItemData&gt;&gt;() {
      override fun create(params: Unit): Flow&lt;List&lt;ItemData&gt;&gt; {
          return flow{
              emit(dao.readAllData())
          }
      }
  }
  </code></pre>
  <p>For now it looks like the code above.
  How to use DateState in that case?</p>
  <p>EDIT2:</p>
  <pre><code>class GetNotificationListItemDetailsUseCase @Inject constructor(private val notificationDao: NotificationDao): BaseFlowUseCase&lt;Unit, DataState&lt;List&lt;NotificationItemsResponse.NotificationItemData&gt;&gt;&gt;() {
      override fun create(params: Unit): Flow&lt;DataState&lt;List&lt;NotificationItemsResponse.NotificationItemData&gt;&gt;&gt; {
          return flow{
              emit(DataState.Loading)
  
              try {
                  emit(DataState.Success(notificationDao.readAllDataState()))
              } catch(e: Exception) {
                  emit(DataState.Error(e)) // error, and send the exception
              }
          }
      }
  }
  </code></pre>
  <p>DAO</p>
  <pre><code>    @Query(&quot;SELECT * FROM notification_list ORDER BY id ASC&quot;)
      abstract suspend fun readAllDataState(): DataState&lt;List&lt;NotificationItemsResponse.NotificationItemData&gt;&gt;
  </code></pre>
  <p>/\ error beacause of it:</p>
  <pre><code>error: Not sure how to convert a Cursor to this method's return type
  </code></pre>
  <p>fragment</p>
  <pre><code>
      private suspend fun collectNotificationItems() {
          vm.notificationData.collectLatest { dataState -&gt;
              when(dataState) {
                  is DataState.Error -&gt; {
                      collectErrorState()
                      Log.d(&quot;collectNotificationItems&quot;, &quot;Collect ErrorState&quot;)
                  }
                  DataState.Loading -&gt; {
                      Log.d(&quot;collectNotificationItems&quot;, &quot;Collect Loading&quot;)
                  }
                  is DataState.Success&lt;*&gt; -&gt; {
                      vm.notificationData.collectWith(viewLifecycleOwner) {
                          notificationAdapter.items = it
                          notificationAdapter.notifyDataSetChanged()
                          Log.d(&quot;collectNotificationItems&quot;, &quot;Collect Sucess&quot;)
                      }
                  }
              }
          }
  </code></pre>