Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] Android Paging Library – Map Room DataSource.Factory<*, DatabaseModel> to DataSource.Factory<*, PresenterModel>

Posted on November 11, 2022 By

Solution 1 :

Here is how i have done done it

Data Source

fun getDataSource(): DataSource.Factory<Int, DBModel> {
     return database.dao.getAllData()
   }

variable at view model

val scannedCompleteList=App.getRepository().getDataSource().toLiveData(
                Config(
                    pageSize = 60,
                    enablePlaceholders = true,
                    maxSize = 200
                )
            )

Now i have a binding adapter where i convert the data from db model to domain model

@BindingAdapter("setData")
fun setImageScanned(recyclerView: RecyclerView, data: List<DBModel>?) {
        val adapter = recyclerView.adapter as MyAdapter
        adapter.submitList(it.asDomainModel())
    }
}

So you are observing data at fragment so you can convert the data to presenter inside observer.
asDomainModel is an extension function which do the conversion

Problem :

I use two models in my app:

  1. Database
  2. Presenter (UI)

Android Paging gives me a DataSource.Factory<*, DatabaseModel>

@Dao
interface ProjectDao {
    @Query("SELECT * FROM project")
    fun getAllProjects(): DataSource.Factory<Int, DatabaseModel>
    ...
}

When I want to make the LiveData using LivePagedListBuilder(dataSourceFactory, config) I need to map:

DataSource.Factory<*, DatabaseModel> -|—-> DataSource.Factory<*, PresenterModel>

Is there any way possible to achieve this. I’m also open to here any approach done using RxKotlin (RxJava).

Comments

Comment posted by Abdul

how you have bind the data to recycle view ? Are you using binding adapter for it ?

Comment posted by Arrowsome

@Abdul I use

Comment posted by Arrowsome

Thanks, I really appreciate this. I will mark you as the correct answer if nothing better comes up.

Comment posted by Abdul

that will be great.

Comment posted by DennisVA

this is a bad solution. The UI should never even get a DBModel

READ  [FIXED] Android Toolbar and Menu are driving me crazy
Powered by Inline Related Posts
Android Tags:android, android-jetpack, android-paging, android-paging-library, android-room

Post navigation

Previous Post: [FIXED] React Native floating animation
Next Post: [FIXED] java – maintain single database between customer and seller of android app

Related Posts

[FIXED] android – Cant run or debug on a Mobile phone with flutter application Android
[FIXED] android – Reducing the size of some pdf files Android
[FIXED] Why I can’t open downloaded file on Android Q Android
[FIXED] android – how to play sound in service worker or even vibrate in chrome? Android
[FIXED] crash – Android x86 on VirtualBox: App crashes on startup Android
[FIXED] android – Get all nested JSON objects with GSON: Deserialization Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme