This design library intends to propose android widgets with enhanced capabilities. The widgets available are:
ValidationInputEditText
a TextInputEditText with text validationSwipeCallback
an ItemTouchHelper.Callback implementation to display background / icon on item swipe in RecyclerView
Design is available on Maven Central. To use in your project, simply add the following dependency to your app:
dependencies {
...
implementation 'com.github.jbvincey:design:3.0.2'
...
}
Design used to be available on JCenter under the package name com.jbvincey:design
.
Due to JCenter shutdown, the Design library has been migrated to Maven Central with a different package name com.github.jbvincey:design
.
If you were pulling the Design library from JCenter, make sure to add Maven Central repository in your configuration and to update the package name of Design library.
<android.support.design.widget.TextInputLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<com.jbvincey.design.widget.ValidationInputEditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:imeOptions="actionGo"
android:hint="@string/hint"
app:validationRegex="@string/validation_regex"
app:errorText="@string/validation_errortext"
app:validateTextOnEditorAction="true" />
</android.support.design.widget.TextInputLayout>
ValidationInputEditText
is intended to be used in a TextInputLayout
. If it has no TextInputLayout
parent, it will raise an Exception
.
3 custom attributes are available:
validationRegex
: a regular expression against whom the text will be checked on validation (can take a string or reference)errorText
: error text displayed when text does not match the regular expression defined above (can take a string or reference)validateTextOnEditorAction
: a boolean to define whether text should be checked on editor action (works with anyimeOptions
you set)
These attributes can also be defined programmatically.
Finally you can set a listener to perform action once text has been checked and is valid (here in Kotlin):
validationInputEditText.validationInputEditTextListener = ValidationInputEditTextListener {
//your action
}
Text is checked on editor action if you set validateTextOnEditorAction
to true. You can also trigger text validation with validateText()
method:
validationInputEditText.validateText()
Create your SwipeCallback
to pass it to an ItemTouchHelper
to be attached to a RecyclerView
:
val swipeCallbackModelStart = SwipeCallbackModel(
color,
drawableStart,
margin,
SwipeCallbackListener { _ -> Toast.makeText(context, "on item swiped start", Toast.LENGTH_SHORT).show() }
)
val swipeControllerModelEnd = SwipeCallbackModel(
color,
drawableEnd,
margin,
SwipeCallbackListener { _ -> Toast.makeText(context, "on item swiped end", Toast.LENGTH_SHORT).show() }
)
val itemTouchHelperCallback = SwipeCallback(swipeCallbackModelStart, swipeControllerModelEnd, context)
val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback).apply {
attachToRecyclerView(recyclerView)
}
SwipeCallback
constructor takes 2 optional SwipeCallbackModel
(one to swipe start and the other to swipe end) and a context.
If a SwipeCallbackModel
is null, the corresponding swipe (start or end) will be disabled.
SwipeCallbackModel
constructor takes 4 arguments:
backgroundColor
anInt
(@ColorInt
) defining the background color on swipeactionDrawable
aDrawable
defining the icon to display on swipeactionMargin
anInt
corresponding to the side margin for the iconswipeCallbackListener
aSwipeCallbackListener
where you can implement the action to do once item is swiped
Jean-Baptiste VINCEY, [email protected]
Copyright 2018 Jean-Baptiste VINCEY.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.