Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBFLOW and FlowCursor with Flexibleadapter #86

Closed
carmas123 opened this issue May 22, 2016 · 13 comments
Closed

DBFLOW and FlowCursor with Flexibleadapter #86

carmas123 opened this issue May 22, 2016 · 13 comments
Labels

Comments

@carmas123
Copy link

Hi I use in my app (write with Kotlin) DBFlow lib. Now I want to use your lib to add more functionality but I have a problem. How can I use your adapter with a flow list? Flow list is very good on device with low performance and with more than 10k items.

@davideas
Copy link
Owner

Hello @carmas123, thanks for the message.
I need to look into it, I need more information and time, actually I can't tell you.

@carmas123
Copy link
Author

Simply the FlowCursorList get from the cursor the data only when it is needed and not for all items, but it know how many items are. (getCount)

@davideas
Copy link
Owner

@carmas123, maybe you can use the onLoadMore feature.

@carmas123
Copy link
Author

Oh yes this can be a solution, but it is not very simple, because I need to extract the first N items from DB and initialize the adapter and after that with same query I need to load other items.

@carmas123
Copy link
Author

Please can you add a param to execute or not initializeItem().
I made a custom LazyList that load items from Array when it's required or displayed into recyclerview, but into "initializeItems" method all items a get from the array. Please can you bypass this method when no one expandable items.

You can add a method to disable this initialization.

@davideas
Copy link
Owner

@carmas123, loading hundreds or thousands items, it's much better doing with the OnLoadMore. But it depends of which items we are talking about.

Regarding the item initialization parameter, I think we can add it. I will check later what is the effect if items are not initialized. This has a strong impact for expandable items.

@davideas
Copy link
Owner

@carmas123, what do you think about these names: setInitiallyExpandItemsAtStartUp(boolean) or doNotExpandItemsAtStartUp(boolean) ? the latter has an impact for the rotation, the former actually never expands items at startUp, so it must be called by the user, if called it initializes and expands items to be expanded and so I can remove it from the constructor.

@carmas123
Copy link
Author

Oh yes this is very good for me.
About the hundreds or thousands items...what you say it's true but if I use my lazy list it's have no impact with the performance. I post my code (write in Kotlin) to know how it work:

class LazyList<T>(cursor: FlowCursorList<AbstractModel>, creator: LazyList.ItemFactory<T>) : ArrayList<T?>() {

    // Chiudo il cursore corrente
    var mCursor: FlowCursorList<AbstractModel> = cursor
        set(cursor) {
            closeCursor()
            this.mCursor = cursor
        }

    private val mCreator: ItemFactory<T>

    init {
        mCreator = creator
    }

    override fun get(index: Int): T? {
        val size = super.size
        if (index < size) {
            // find item in the collection
            var item = super.get(index)
            if (item == null) {
                item = mCreator.create(mCursor, index)
                set(index, item)
            }
            return item
        } else {
            // we have to grow the collection
            for (i in size..index - 1) {
                add(null)
            }
            // create last object, add and return
            val item = mCreator.create(mCursor, index)
            add(item)
            return item
        }
    }

    override val size: Int
        get() = mCursor.getCount()

    fun closeCursor() {
        mCursor.close()
    }

    interface ItemFactory<T> {
        fun create(cursor: FlowCursorList<AbstractModel>, index: Int): T
    }
}

everything you need is a class that implement ItemFactory interface and all is done with a lazy item creation. This have only a problem!! That the result is an ArrayList and need to be casted to a mutable list.

@carmas123
Copy link
Author

Unfortunately I had to leave this library...

@davideas davideas reopened this Jun 5, 2016
@carmas123
Copy link
Author

I tried to use onLoadMore functionality but the problem is when I try to use fast scroll or a custom index with alphabet. With onloadmore I don't do that. This is the majior problem

@carmas123
Copy link
Author

Please can you push a commit with this changes or I need to fork this project?

@davideas
Copy link
Owner

davideas commented Jun 5, 2016

I will push.

@carmas123
Copy link
Author

Thank you so much

davideas added a commit that referenced this issue Jun 5, 2016
…dItemsAtStartUp() must be explicitly called by the user in Activity creation phase.
@davideas davideas closed this as completed Jun 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants