Skip to content

PositionalDataSource cancelling fetch for loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Songs>) crashes #64

@AndrewBloom

Description

@AndrewBloom

What I do:

override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback<Songs>) {
    coroutineScope.launch(Dispatchers.IO) {
        val (songs, count) = getSongs(this, params.requestedLoadSize, params.requestedStartPosition)
        callback.onResult(songs, 0, count)
    }
}

So It's with "count" to get those infamous placeholders ....

override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Songs>) {
    //job?.cancel()
    job = coroutineScope.launch(Dispatchers.IO) {
        callback.onResult(mutableListOf<Songs>())
        //callback.onResult(getSongs(this, params.loadSize, params.startPosition).first)
    }
}

Here it would make sense to cancel the coroutine (It's a fetch on the MediaStore) and give back the part of the list loaded, but seems that it doesn't like less elements than what it expects. On the other end what's the point to fill up the list with rubbish if I want to abort the operation and visualise placeholders on the adapter with the suggested technique
if getItem(position)==null then show my beautiful placeholder

As a side note, the fact everyone says that you can't get the count from a contentProvider with "select count(*) from whatever" it's pretty annoying, but that's another story.

ah almost forgot. the stacktrace i get:

2020-06-19 10:42:29.550 23854-23854/com.shapedbyiris.consumer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shapedbyiris.consumer, PID: 23854
java.lang.IllegalArgumentException: page introduces incorrect tiling
at androidx.paging.PagedStorage.insertPage(PagedStorage.java:545)
at androidx.paging.PagedStorage.tryInsertPageAndTrim(PagedStorage.java:504)
at androidx.paging.TiledPagedList$1.onPageResult(TiledPagedList.java:60)
at androidx.paging.DataSource$LoadCallbackHelper$1.run(DataSource.java:324)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Edit#2:
The effect you see without cancelling is that if you scroll like crazy (and I mean real crazy) UI slows down visibly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions