项目作者: stanbar

项目描述 :
Simple Android library that facilitates input validation
高级语言: Kotlin
项目地址: git://github.com/stanbar/Android-Prompter.git
创建时间: 2017-10-19T20:56:23Z
项目社区:https://github.com/stanbar/Android-Prompter

开源协议:

下载


Android-Prompter

Android library that facilitates input validation

Simple wrap your view with

  1. Prompter.showWithClick(yourView, supportFragmentManager)

and enjoy nice UX flow

All properties like inputType, hint/text, message or title will be taken from yourView or you can specify them manualy with

  1. Prompter.showWithClick(etPage, supportFragmentManager)
  2. .title("Jump to page")
  3. .message("Enter page you would like to jump to")
  4. .inputType(InputType.TYPE_CLASS_NUMBER)
  5. .showValue { book.currentPosition.toString() }
  6. .hintMode() //Current value will be displayed as hint
  7. .validate("Please enter page in range of [1, ${book.size}]"){ it.toInt() in 1..book.size }

By default empty values won’t pass validation process but you can change this with .allowEmpty()

You can even customize whole callback method (callbacks are called only when validation pass or is not specified)

  1. Prompter.showWithClick(etPage, supportFragmentManager)
  2. .setOnValueChangeListener {
  3. if (it.toInt() in 0..100)
  4. etPage.setText(newInt.toString())
  5. }

It’s worth to mention that setOnValueChangeListener overrides all listeners whereas addOnValueChangeListener appends to current list of listeners.
So:

  1. Prompter.showWithClick(etDouble, supportFragmentManager)
  2. .addOnValueChangeListener {
  3. Log.d(TAG, "A")
  4. }
  5. .addOnValueChangeListener {
  6. Log.d(TAG, "B")
  7. }
  8. .setOnValueChangeListener {
  9. Log.d(TAG, "C")
  10. }

will print only
D/Prompter: C

Sometimes you may want specify different View that prompt the dialog. In this case use Prompter.on() and trigger manually .show()

  1. val prompter = Prompter.on(tvPage, supportFragmentManager)
  2. .title("Jump to page")
  3. .validate("Please enter page in range of [1, ${book.size}]") {
  4. it.toInt() in 1..book.size
  5. }
  6. button1.setOnClickListener { prompter.show() }
  7. button2.setOnClickListener { prompter.show() }
  8. button3.setOnClickListener { prompter.show() }
  9. container.setOnClickListener { prompter.show() }

Usage:

Gradle

Step 1. Add the JitPack repository to your root build.gradle

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Step 2. Add the dependency

  1. dependencies {
  2. implementation 'com.github.stasbar:android-prompter:<enter_version_here>'
  3. }

Licenses

  1. Copyright 2017-2019 Stanislaw stasbar Baranski
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. __ __
  12. _____/ /_____ ______/ /_ ____ ______
  13. / ___/ __/ __ `/ ___/ __ \/ __ `/ ___/
  14. (__ ) /_/ /_/ (__ ) /_/ / /_/ / /
  15. /____/\__/\__,_/____/_.___/\__,_/_/
  16. stachu@stasbar.com