Giter VIP home page Giter VIP logo

Comments (17)

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

I actually think the default one should hide the last divider. Weird that the library didn't set it as such.
Updated now.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

Found the problem. It's related to the implementation of the method obtainStyledAttributes() which access getTheme(). The implementation of getTheme() is different between Application and Activity. That's why it wasn't working.
You can change the implementation of provideDividerBuilder() from this:

val result = RecyclerViewDivider.Builder(context)
obtainStyledAttributes(intArrayOf(android.R.attr.listDivider)).use { typedArray ->
    typedArray.getDrawable(0)?.let { result.drawable(it) }
}
return result

To this:

val result = RecyclerViewDivider.Builder(context)
// Invoke it on the Activity instead of the Application.
context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider)).use { typedArray ->
    typedArray.getDrawable(0)?.let { result.drawable(it) }
}
return result

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

And BTW yes, I think the method hideLastDivider() could become the default visibility. I didn't make it as default only following the theory "the default is most basic implementation", but I should have reasoned with "the default is the most common usage".

from recycler-view-divider.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

Why would the default be the basic implementation?
Also, you said I can call the default theming on the application class. Not on the Activity.
Now it's even more important to ditch the option to put it on the application class, and use more commonly used ways, like for Views.

There was actually a talk about Context by Google developers, when ApplicationContext isn't the good choice and that you should try to use the one of the Activity when possible.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

Why would the default be the basic implementation?

Cause I did this library 3 years ago and I thought it was a good choice, now I can see it's a mistake.

Also, you said I can call the default theming on the application class. Not on the Activity.

I said the library checks if the Application implements RecyclerViewDivider.BuilderProvider to pick the default configuration and I also said the Context passed in the method is the same of the in-place call of RecyclerViewDivider.with(Context), so in your case, the Activity.
If that wasn't clear, it can be I wasn't understood before.

Now it's even more important to ditch the option to put it on the application class, and use more commonly used ways, like for Views.
There was actually a talk about Context by Google developers, when ApplicationContext isn't the good choice and that you should try to use the one of the Activity when possible.

I haven't any other idea to give the user the possibility to specify a common dynamic configuration for all the dividers of the app if not using an interface on the Application. I'll add the theme attributes for a basic common customization, but they won't solve cases like:

RecyclerViewDivider.with(this)
    .drawableManager(object : DrawableManager {
        override fun itemDrawable(groupCount: Int, groupIndex: Int): Drawable {
            val color = if (groupCount % 2 == 0) Color.BLACK else Color.RED
            return ColorDrawable(color)
        }
    })
    .build()

from recycler-view-divider.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

I don't understand. You can provide both. If the user doesn't set a drawable, the default one is what you can have from the system.
After all, you already chose a default one...

Anyway, please just think about it. I think you can reach something like what Android provides for Views, attributes, and styles, while also allowing to customize at runtime.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

With:

I'll add the theme attributes for a basic common customization, but they won't solve cases like [...]

I meant to say that I'll use both, but that I can't remove the RecyclerViewDivider.BuilderProvider.

from recycler-view-divider.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

So you want to support 3 things that can override...
I think you are going too far. Could complicate things...

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

I have to think a bit if that's too far or not. BTW the theme attributes will be added anyway.

from recycler-view-divider.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

OK. I guess you are right. Sorry.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

No problem at all, your help is appreciated and the ideas we discussed about in the two issues are added to the milestone 4.x.
So thanks again, if anything else comes to your mind, don't hesitate to comment or open other issues.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

BTW I'm closing this issue since it can be solved using context.obtainStyledAttributes(). Check the milestone 4.x for what we've discussed about.

from recycler-view-divider.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

I don't understand what you mean.
Please consider using default style for dividers.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

I meant only to move this conversation to the related issues: #45 and #46
I'll implement all of this, just move the conversation on those issues since I'll refer to them for the milestone.

from recycler-view-divider.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 24, 2024

Oh ok.

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

Just released the version 3.2.0 which uses android:listDivider by default to get the divider's Drawable and other theme attributes (wiki).

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

It also hides the last divider by default.

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.