Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mars885 committed Aug 18, 2020
1 parent 8937895 commit 7abb7d5
Showing 1 changed file with 173 additions and 1 deletion.
174 changes: 173 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,173 @@
Welcome!
# ValuePicker
An Android library that provides a simple and customizable ValuePicker.

[ ![Download](https://api.bintray.com/packages/mars885/maven/valuepicker/images/download.svg) ](https://bintray.com/mars885/maven/valuepicker/_latestVersion)
![](https://travis-ci.org/mars885/value-picker.svg?branch=master)
![](https://img.shields.io/badge/API-21%2B-orange.svg?style=flat)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Platform](https://img.shields.io/badge/platform-Android-green.svg)](http://developer.android.com/index.html)

## Contents

* [Demo](#demo-youtube)
* [Installation](#installation)
* [Usage](#usage)
* [Advanced Usage](#advanced-usage)
* [License](#license)

## Demo (YouTube)

<a href="https://www.youtube.com/watch?v=qzoZh3aYlcY">
<img src="/media/demo_thumbnail.png" width="200" height="422"/>
</a>

## Installation

1. Make sure that you've added the `jcenter()` repository to your top-level `build.gradle` file.

````groovy
buildscript {
//...
repositories {
//...
jcenter()
}
//...
}
````

2. Add the library dependency to your module-level `build.gradle` file.

````groovy
dependencies {
//...
implementation "com.paulrybitskyi.valuepicker:valuepicker:1.0.0"
//...
}
````

## Usage
Basic usage of the ValuePickerView involves two steps - declaring a widget inside the XML file of your choice and configuring it in one of the Kotlin/Java classes.

Let's see how we can do that by following the steps listed above:

1. Declaring a widget inside the XML file.

<details><summary><b>XML (click to expand)</b></summary>
<p>

````xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">

<!-- Other widgets here -->

<com.paulrybitskyi.valuepicker.ValuePickerView
android:id="@+id/valuePickerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:vpv_areDividersEnabled="true"
app:vpv_isInfiniteScrollEnabled="true"
app:vpv_maxVisibleItems="5"
app:vpv_textColor="@color/colorAccent"
app:vpv_dividerColor="@color/colorAccent"
app:vpv_flingSpeedFactor="0.3"
app:vpv_textSize="@dimen/date_picker_text_size"
app:vpv_textTypeface="@font/ubuntu_mono_bold"
app:vpv_divider="@drawable/custom_divider"
app:vpv_orientation="vertical"/>

</androidx.constraintlayout.widget.ConstraintLayout>
````
</p></details>

2. Configuring the widget in one of the Kotlin/Java classes.

<details><summary><b>Kotlin (click to expand)</b></summary>
<p>

````kotlin
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//...

with(valuePickerView) {
onItemSelectedListener = OnItemSelectedListener { item ->
// Do something with item
}

val pickerItems = getPickerItems()

items = pickerItems
setSelectedItem(pickerItems[2])
}
}


private fun getPickerItems(): List<Item> {
return mutableListOf<Item>().apply {
for(number in 1..100) {
add(
PickerItem(
id = number,
title = number.toString()
)
)
}
}
}
````

</p></details>

<details><summary><b>Java (click to expand)</b></summary>
<p>

````java
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

ValuePickerView valuePickerView = view.findViewById(R.id.valuePickerView);
valuePickerView.setOnItemSelectedListener((item) -> {
// Do something with item
});

final ArrayList<Item> pickerItems = getPickerItems();

valuePickerView.setItems(getPickerItems());
valuePickerView.setSelectedItem(pickerItems.get(2));
}


private ArrayList<Item> getPickerItems() {
final ArrayList<Item> pickerItems = new ArrayList<>(100);

for(int i = 1; i <= 100; i++) {
pickerItems.add(
new PickerItem(
i,
String.valueOf(i)
)
);
}

return pickerItems;
}
````

</p></details>

## Advanced Usage

See the [Sample app](https://github.com/mars885/value-picker/tree/master/sample/src/main/java/com/paulrybitskyi/sample/valuepicker).

## License

PersistentSearchView is licensed under the [Apache 2.0 License](LICENSE).

0 comments on commit 7abb7d5

Please sign in to comment.