You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's time to provide a new fluent API for the ScrollGalleryView library which should significantly increase flexibility of gallery creation and initialization. Currently, the development of new API is going in separate fluent-api branch, so if you have some ideas how to make API more flexible - PR is welcome, or just leave a comment with your suggestions. Here I have tried to provide a simple sketch of API.
Key API features
Get rid of ordered method invocation during gallery initialization.
Support flexible step-by-step gallery initialization.
Provide a new way to add media to your gallery (using static imports or interface).
Unclear points
The place where we should check parameters which would be passed into GalleryBuilder (for now it's .build() method).
So, .media() method should support image loading from different sources, but at the same time it should use custom MediaLoader provided by external dependencies such as picasso-loader.
The GalleryBuilder class should provide a bunch of overloaded .media() methods for loading images from different sources such as file, url, uri, etc. Also .media() method should recognize by url if it's image or video (I think it's can be done by extension in the end of url).
For now all fluent API code can be found in com.veinhorn.scrollgalleryview.builder package. I'm going to keep it away from ScrollGalleryView class to abstract from gallery representation. If you think there are any reasons to add some kind of static method in ScrollGalleryView to obtain new builder instance - just leave a comment with your arguments.
Adding media
Using Java static imports
Each custom MediaLoader (for example picasso-loader) should provide implementation of MediaHelpers interface, then you can use Java static imports feature to bring this methods into your app scope:
importstaticPicassoMediaHelpers.*
GalleryBuilder.from(R.id.scroll_gallery_view)
.withMedia(media(newFile("path/to/image")))
.withMedia(media(newFile("folder with images")))
.withMedia(media("<uri>"))
.withMedia(media("<bitmap>"))
.build();
MediaHelpers interface might looks like this:
interfaceMediaHelpers {
voidmedia(Stringmedia);
voidmedia(Filemedia);
voidmedia(Bitmapimage);
voidmedia(Urimedia);
// and so on ...
}
Here is an example of how can look ScrollGalleryView configuration in new fluent API.
importstaticPicassoMediaHelpers.*
GalleryBuilder.from(R.id.scroll_gallery_view)
.withMedia(media(newFile("path/to/image")))
.withMedia(media(newFile("folder with images")))
// more media invocations here
.settings(
// specify gallery settings here
)
.build();
It's time to provide a new fluent API for the ScrollGalleryView library which should significantly increase flexibility of gallery creation and initialization. Currently, the development of new API is going in separate fluent-api branch, so if you have some ideas how to make API more flexible - PR is welcome, or just leave a comment with your suggestions. Here I have tried to provide a simple sketch of API.
Key API features
Unclear points
.build()
method).Gallery initialization
Pass view id to
.from()
Pass inflated view to
.from()
It's can be usefull when you use libraries such as Butterknife to bind views.
So,
.media()
method should support image loading from different sources, but at the same time it should use custom MediaLoader provided by external dependencies such as picasso-loader.The
GalleryBuilder
class should provide a bunch of overloaded.media()
methods for loading images from different sources such as file, url, uri, etc. Also.media()
method should recognize by url if it's image or video (I think it's can be done by extension in the end of url).For now all fluent API code can be found in
com.veinhorn.scrollgalleryview.builder
package. I'm going to keep it away from ScrollGalleryView class to abstract from gallery representation. If you think there are any reasons to add some kind of static method in ScrollGalleryView to obtain new builder instance - just leave a comment with your arguments.Adding media
Using Java static imports
Each custom MediaLoader (for example picasso-loader) should provide implementation of
MediaHelpers
interface, then you can use Java static imports feature to bring this methods into your app scope:MediaHelpers
interface might looks like this:Custom
MediaHelpers
might looks like this:Gallery settings
Here is an example of how can look ScrollGalleryView configuration in new fluent API.
Additional info
Java static imports
Even more about static imports
Fluent interface
DSL
About DSLs in Java
The text was updated successfully, but these errors were encountered: