Pillar for Android
This library provides a small but commonly used components in Android development.
The packages can also be mixed and matched.
To get started, add whichever packages below that interest you in your app build.gradle
:
def pillarVersion = '0.3.2' //or any current version
compile "com.baseconfig.pillar:utils:$pillarVersion"
compile "com.baseconfig.pillar:materials:$pillarVersion"
compile "com.baseconfig.pillar:databinding:$pillarVersion"
Components
Utils
Package: utils
-> compile "com.baseconfig.pillar:utils:$version"
ContextUtils
for pixels and dp unit conversionContextUtils.getPixels(Context context, int dp)
NetworkUtils
for checking internet connectionNetworkUtils.isConnected(Context context)
RecyclerViewUtils
for simple RecyclerView's ItemDecorationsrecyclerView.addItemDecoration(new RecyclerViewUtils.VerticalItemDecoration(context, 8f)); //8dp
Materials
Package: materials
-> compile "com.baseconfig.pillar:materials:$version"
- Official Material Design colors, prefixed with
pmc
android:tint="@color/pmc_blue_A400"
- Utility colors, prefixed with
pcc
android:background="@color/pcc_shadow_32" //black with 32% transparency android:background="@color/pcc_highlight_25" //white with 25% transparency
Databinding
Package: databinding
-> compile "com.baseconfig.pillar:databinding:$version"
BindingItemAdapter<T>
Generic RecyclerView adapter where T is your model object.public class PersonAdapter extends BindingItemAdapter<Person> { @Override public BindingHolder<? extends ViewDataBinding> onCreateBindingHolder(LayoutInflater inflater, ViewGroup parent, int viewType) { // This can be inlined but just for the sake of visibility ViewDataBinding vdb = DataBindingUtil.inflate(inflater, R.layout.item_person, parent, false) return new BindingHolder<>(vdb); //BindingHolder<T> is provided by this library } @Override public void onBind(BindingHolder<? extends ViewDataBinding> holder, Person item, int position) { // For below, you can just directly cast to the class generated by Android databinding. // However if you have multiple viewTypes, the example below show its usefulness // since you can just check which generated binding was returned and bind accordingly. ViewDataBinding binding = holder.getBinding(); if (binding instanceof ItemNovelBinding) { ItemNovelBinding b = (ItemNovelBinding) binding; b.itemTitle.setText(item.getName()); } } } ... then ... List<Person> list = ... adapter = new PersonAdapter(); adapter.setCollection(list) //if init in onCreate //OR adapter.updateList(newList, diffUtilCallback) //if adapter init later in the UI lifecycle //optional helper to directly add on click listener to each list item ItemClickSupport.addTo(recyclerView).setOnItemClickListener( ... )
All components are provided as AAR libraries distributed via jCenter.
Contributing
While pull request are greatly welcomed, please keep in mind the library are meant to be as a small set of utility classes and methods that is ubiquitously used within Android development.
Building
- Import from git, sync Gradle, and run Gradle build.
- For testing locally:
gradle clean build install
(or the wrappergradlew
. Android Studio Gradle tool window also works).- add
mavenLocal()
in rootbuild.gradle
dependencies:
allprojects { repositories { ... mavenLocal() } }
- Change the library version in
constants.gradle
- Test implementation in separate module or project with the given gradle dependencies substituted with your own version
Note: Javadoc errors are ignored for now.
License
This library is provided under the MIT License.