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:
interface MediaHelpers {
void media(String media);
void media(File media);
void media(Bitmap image);
void media(Uri media);
// and so on ...
}
Custom MediaHelpers might looks like this:
public final class PicassoMediaHelpers implements MediaHelpers {
private PicassoMediaHelpers() {
}
}
Gallery settings
Here is an example of how can look ScrollGalleryView configuration in new fluent API.
import static PicassoMediaHelpers.*
GalleryBuilder.from(R.id.scroll_gallery_view)
.withMedia(media(new File("path/to/image")))
.withMedia(media(new File("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