Giter VIP home page Giter VIP logo

Comments (11)

fondesa avatar fondesa commented on June 4, 2024

With the new API, you shouldn't need it since with originX and originY inside Divider you could obtain every desired result.
Which type of logic do you have to implement?

from recycler-view-divider.

kjsolo avatar kjsolo commented on June 4, 2024

How can I achieve this complex effect
Lark20200605-161531

 * 0;0 --------------> 1;0
 *  |                   |
 *  |         1         |
 *  ∨                   ∨
 * 0;1 ----> 1;1 ----> 2;1
 *  |         |         | 
 *  |    2    |    3    | 
 *  ∨         ∨         ∨ 
 * 0;2 ----> 1;2 ----> 2;2
 *  |         |         | 
 *  |    4    |    5    | 
 *  ∨         ∨         ∨ 
 * 0;3 ----> 1;3 ----> 2;3
  • 1 is A Type
  • 2, 3, 4, 5 is B Type
  • Item position not fixed

from recycler-view-divider.

fondesa avatar fondesa commented on June 4, 2024

You can obtain the absolute index using originX and originY since you have the cell's span size and the grid's span count, but this would be a probably useless task.

What do you need to do in that layout? Do you want to make the vertical dividers red? Do you want to make the last divider blue? I mean, if you tell me the logic you want to implement, I'm pretty sure you can implement it without using absoluteCellIndex.

from recycler-view-divider.

kjsolo avatar kjsolo commented on June 4, 2024

What should I do about this situation? Without item index, it's hard to know which part it is

Because:

  • The size of divider is determined by the upper and lower parts
  • Item position is dynamic
  • Divider only as space

WX20200605-165308@2x

from recycler-view-divider.

fondesa avatar fondesa commented on June 4, 2024

@kjsolo You can achieve that effect with the following lines, obviously with some adaptations, like converting the size in dp.

dividerBuilder()
    .asSpace()
    .sizeProvider(object : SizeProvider {
        override fun getDividerSize(grid: Grid, divider: Divider, dividerDrawable: Drawable): Int = when {
            divider.orientation.isHorizontal && divider.originX == 0 -> 16
            divider.orientation.isHorizontal && (divider.originX == 1 || divider.originX == 3) -> 12
            else -> 8
        }
    })
    .visibilityProvider(object : VisibilityProvider {
        override fun isDividerVisible(grid: Grid, divider: Divider): Boolean =
            divider.orientation.isHorizontal || divider.originY != 0
    })
    .build()

from recycler-view-divider.

kjsolo avatar kjsolo commented on June 4, 2024

@kjsolo You can achieve that effect with the following lines, obviously with some adaptations, like converting the size in dp.

dividerBuilder()
    .asSpace()
    .sizeProvider(object : SizeProvider {
        override fun getDividerSize(grid: Grid, divider: Divider, dividerDrawable: Drawable): Int = when {
            divider.orientation.isHorizontal && divider.originX == 0 -> 16
            divider.orientation.isHorizontal && (divider.originX == 1 || divider.originX == 3) -> 12
            else -> 8
        }
    })
    .visibilityProvider(object : VisibilityProvider {
        override fun isDividerVisible(grid: Grid, divider: Divider): Boolean =
            divider.orientation.isHorizontal || divider.originY != 0
    })
    .build()

I can not use this code: divider.originX == 0, because item position is dynamic, they can swap index. It may be another situation:

WX20200605-172119@2x

from recycler-view-divider.

fondesa avatar fondesa commented on June 4, 2024

The absoluteCellIndex can't be exposed because with the new API, the dividers changed the way they behave and the same divider can be owned by two different items, unlike the previous version. We can try to find a specific solution for your problem though, without changing the library. Can you post here the part of your code in which you decide if the view type is A, B or C?

from recycler-view-divider.

kjsolo avatar kjsolo commented on June 4, 2024

Without absoluteCellIndex, I can only get this value in this way:

// This code waste a lot of time if there's a lot of data
fun Grid.itemIndex(lineIndex: Int, cellIndex: Int): Int {
    return lines.take(lineIndex).sumBy { it.cellsCount } + cellIndex
}

And here the code that's why I need it:

fun getSideDividerSize(itemIndex: Int): Int {
    val item = dataList[itemIndex]
    when (item) {
        is A -> 0.dp
        else -> 8.dp
    }
}

fun getHorizontalDividerSize(beforeItemIndex: Int, afterItemIndex: Int): Int {
    val beforeItem = dataList[beforeItemIndex]
    val afterItem = dataList[afterItemIndex]
    return when (afterItem) {
        is A -> 12.dp
        is B -> 8.dp
        is C -> {
            when (beforeItem) {
                is A, B -> 16.dp
                else -> 36.dp
            }
        }
        else -> 0
    }
}

fun getVerticalDividerSize(beforeItemIndex: Int, afterItemIndex: Int): Int {
    val afterItem = dataList[afterItemIndex]
    when (afterItem) {
        is B -> 8.dp
    }
}

from recycler-view-divider.

fondesa avatar fondesa commented on June 4, 2024

How can you access the line index and the cell index?
Because, if you are using originX and originY, they can match the line/cell before or the line/cell after depending on when they are invoked.

(BTW, you can cache the computation of Grid.itemIndex() to make it way faster)

from recycler-view-divider.

kjsolo avatar kjsolo commented on June 4, 2024

line/cell has a relationship with origin

val lineIndex: Int
val cellIndex: Int
if (orientation.isVertical) {
    lineIndex = divider.originY
    cellIndex = divider.originX
} else {
    lineIndex = divider.originX
    cellIndex = divider.originY
}

from recycler-view-divider.

fondesa avatar fondesa commented on June 4, 2024

Those lines are referred to accumulatedSpan which is internal and can't be exposed because it relies on a specific usage which subtract 1 if the divider is before the item (look at DividerOffsetProviderImpl). This is the problem I was talking about before. You can't access the side on which the divider is going to show so you can't know if the divider is before or after the item.

from recycler-view-divider.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.