GithubHelp home page GithubHelp logo

Initialization thoughts. about superslim HOT 11 CLOSED

tonicartos avatar tonicartos commented on September 28, 2024
Initialization thoughts.

from superslim.

Comments (11)

TonicArtos avatar TonicArtos commented on September 28, 2024

updated

So I have some of my own ideas on this too, I've added them below, but first I'd like to ask for a clarification.

How should your proposal handle multiple configurations of the same SLM?

Okay, on to my thoughts.

I have actually been thinking about this lots. First, this was because I wanted to move SLM referencing and configuration to only the first item in the section. I remember there was some technical reason why I couldn't, but I can't remember it right now and I forgot to write it down, so I guess it warrants another look.

I completely agree with the issue of verbosity and boilerplate in initialisation. My thoughts actually turned to an idea of adding enum options to the sectionManager attr. This has also included adding pass through attrs for SLM configuration through attrs too.

For example, configuration for using grid layout on content items:

<!-- TextView as a section header. -->
<TextView
    app:slm_sectionManager="grid"
    app:slm_grid_numColumns="4"
    app:slm_grid_minimumColumnWidth="96dp"
    />

or linear layout:

<TextView
    app:slm_sectionManager="linear"
    />

This would also mean configuration through layout params:

GridSLM.LayoutParams params = 
    new GridSLM.LayoutParams(viewHolder.getLayoutParams());
params.setSLM(GridSLM.TAG);
params.setColumnWidthResId(R.dimen.minumum_column_width);
// or
params.setNumColumns(4);

For custom SLMs there still needs to be a key to identify them. Perhaps an SLM could be registered against a String value to make identification easy, or the documentation can encourage people to use R.integer.my_slm_id, or perhaps R.id.my_slm.

XML for custom SLMs could look like this:

<TextView
    app:slm_sectionManager="@+id/my_slm"
    />

and initialisation:

LayoutManager layoutManager;
layoutManager = LayoutManager.addSLM(R.id.my_slm, new MySLM()).build();

or

layoutManager = new LayoutManager();
layoutManager.addSLM(R.id.my_slm, new MySLM());
recyclerView.setLayoutManager(layoutManager);

configuring layout params:

LayoutManager.LayoutParams params = viewHolder.getLayoutParams();
params.setSLM(R.id.my_slm);

from superslim.

TonicArtos avatar TonicArtos commented on September 28, 2024

Ah yes, I just looked through the code and I've rediscovered why the section manager needs to be referenced, and configured, in every item. The entry points for calculating the scroll indicator values don't provide the recycler so I can't get the first item of a section if it isn't current displayed.

However, I guess I can get around it by caching section data. Now that I think about it, it seems feasible. #42.

from superslim.

PatrickDattilio avatar PatrickDattilio commented on September 28, 2024

I like the enum, very straightforward. Perhaps add an abstract enum to SectionLayoutManager, forcing all SLM's to implement/extend the enum themselves. I haven't written much in terms of custom xml tags, but would this allow us to do the following?

<TextView
    app:slm_sectionManager="myEnum"
    />

from superslim.

TonicArtos avatar TonicArtos commented on September 28, 2024

That would be nice, unfortunately the enums are defined here https://github.com/TonicArtos/SuperSLiM/blob/master/library/src/main/res/values/attrs.xml

from superslim.

TonicArtos avatar TonicArtos commented on September 28, 2024

I can do something like

<attr name="slm_sectionManager" format="enum|string|reference" />

but I think enum|reference is good. I'll experiment when I look at it.

from superslim.

PatrickDattilio avatar PatrickDattilio commented on September 28, 2024

Ah I see. I like your idea of registering a String, a set id reminds me of the unintuitive @id/android:list for ListFragments.

from superslim.

TonicArtos avatar TonicArtos commented on September 28, 2024

Well, enum|string will make the interface look the same for custom layouts as for the internal ones, but you need to addSLM("myslm", new MySLM()).

from superslim.

PatrickDattilio avatar PatrickDattilio commented on September 28, 2024

Oh nice! That looks perfect to me.

from superslim.

TonicArtos avatar TonicArtos commented on September 28, 2024

It does look pretty good.

from superslim.

PatrickDattilio avatar PatrickDattilio commented on September 28, 2024

This might be a good candidate for 3.0, as the layoutId->sectionManager is an API breaking change.

from superslim.

TonicArtos avatar TonicArtos commented on September 28, 2024

I am going straight to 0.4.

from superslim.

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.