Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neil Alexander
element-android
Commits
5be3faf9
Commit
5be3faf9
authored
May 10, 2021
by
Valere
Browse files
Epoxy Form fixes
parent
e6d4f9a1
Changes
8
Hide whitespace changes
Inline
Side-by-side
vector/src/main/java/im/vector/app/core/extensions/EditText.kt
View file @
5be3faf9
...
...
@@ -57,15 +57,3 @@ fun EditText.setupAsSearch(@DrawableRes searchIconRes: Int = R.drawable.ic_searc
return
@OnTouchListener
false
})
}
/**
* Update the edit text value, only if necessary and move the cursor to the end of the text
*/
fun
EditText
.
setTextSafe
(
value
:
String
?)
{
if
(
value
!=
null
&&
text
.
toString
()
!=
value
)
{
setText
(
value
)
// To fix jumping cursor to the start https://github.com/airbnb/epoxy/issues/426
// Note: there is still a known bug if deleting char in the middle of the text, by long pressing on the backspace button.
setSelection
(
value
.
length
)
}
}
vector/src/main/java/im/vector/app/features/form/FormEditTextItem.kt
View file @
5be3faf9
...
...
@@ -27,7 +27,6 @@ import com.google.android.material.textfield.TextInputLayout
import
im.vector.app.R
import
im.vector.app.core.epoxy.VectorEpoxyHolder
import
im.vector.app.core.epoxy.VectorEpoxyModel
import
im.vector.app.core.extensions.setTextSafe
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_text_input
)
...
...
@@ -60,7 +59,7 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
@EpoxyAttribute
var
endIconMode
:
Int
?
=
null
@EpoxyAttribute
@EpoxyAttribute
(
EpoxyAttribute
.
Option
.
DoNotHash
)
var
onTextChange
:
((
String
)
->
Unit
)?
=
null
private
val
onTextChangeListener
=
object
:
SimpleTextWatcher
()
{
...
...
@@ -76,8 +75,13 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
holder
.
textInputLayout
.
error
=
errorMessage
holder
.
textInputLayout
.
endIconMode
=
endIconMode
?:
TextInputLayout
.
END_ICON_NONE
// Update only if text is different and value is not null
holder
.
textInputEditText
.
setTextSafe
(
value
)
if
(
holder
.
view
.
isAttachedToWindow
)
{
// the view is attached to the window
// So it is a rebind of new data and you could ignore it assuming this is text that was already inputted into the view.
// Downside is if you ever wanted to programmatically change the content of the edit text while it is on screen you would not be able to
}
else
{
holder
.
textInputEditText
.
setText
(
value
)
}
holder
.
textInputEditText
.
isEnabled
=
enabled
inputType
?.
let
{
holder
.
textInputEditText
.
inputType
=
it
}
holder
.
textInputEditText
.
isSingleLine
=
singleLine
?:
false
...
...
vector/src/main/java/im/vector/app/features/form/FormEditTextWithButtonItem.kt
View file @
5be3faf9
...
...
@@ -26,7 +26,6 @@ import com.google.android.material.textfield.TextInputLayout
import
im.vector.app.R
import
im.vector.app.core.epoxy.VectorEpoxyHolder
import
im.vector.app.core.epoxy.VectorEpoxyModel
import
im.vector.app.core.extensions.setTextSafe
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_text_input_with_button
)
...
...
@@ -61,8 +60,12 @@ abstract class FormEditTextWithButtonItem : VectorEpoxyModel<FormEditTextWithBut
holder
.
textInputLayout
.
isEnabled
=
enabled
holder
.
textInputLayout
.
hint
=
hint
// Update only if text is different
holder
.
textInputEditText
.
setTextSafe
(
value
)
if
(
holder
.
view
.
isAttachedToWindow
)
{
// the view is attached to the window
// So it is a rebind of new data and you could ignore it assuming this is text that was already inputted into the view.
}
else
{
holder
.
textInputEditText
.
setText
(
value
)
}
holder
.
textInputEditText
.
isEnabled
=
enabled
holder
.
textInputEditText
.
addTextChangedListener
(
onTextChangeListener
)
...
...
vector/src/main/java/im/vector/app/features/form/FormEditableSquareAvatarItem.kt
View file @
5be3faf9
...
...
@@ -83,7 +83,6 @@ abstract class FormEditableSquareAvatarItem : EpoxyModelWithHolder<FormEditableS
override
fun
unbind
(
holder
:
Holder
)
{
avatarRenderer
?.
clear
(
holder
.
image
)
GlideApp
.
with
(
holder
.
image
).
clear
(
holder
.
image
)
super
.
unbind
(
holder
)
}
...
...
vector/src/main/java/im/vector/app/features/form/FormMultiLineEditTextItem.kt
View file @
5be3faf9
...
...
@@ -27,7 +27,6 @@ import com.google.android.material.textfield.TextInputLayout
import
im.vector.app.R
import
im.vector.app.core.epoxy.VectorEpoxyHolder
import
im.vector.app.core.epoxy.VectorEpoxyModel
import
im.vector.app.core.extensions.setTextSafe
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_multiline_text_input
)
...
...
@@ -57,7 +56,7 @@ abstract class FormMultiLineEditTextItem : VectorEpoxyModel<FormMultiLineEditTex
@EpoxyAttribute
var
typeFace
:
Typeface
=
Typeface
.
DEFAULT
@EpoxyAttribute
@EpoxyAttribute
(
EpoxyAttribute
.
Option
.
DoNotHash
)
var
onTextChange
:
((
String
)
->
Unit
)?
=
null
private
val
onTextChangeListener
=
object
:
SimpleTextWatcher
()
{
...
...
@@ -77,7 +76,12 @@ abstract class FormMultiLineEditTextItem : VectorEpoxyModel<FormMultiLineEditTex
holder
.
textInputEditText
.
minLines
=
minLines
// Update only if text is different and value is not null
holder
.
textInputEditText
.
setTextSafe
(
value
)
if
(
holder
.
view
.
isAttachedToWindow
)
{
// the view is attached to the window
// So it is a rebind of new data and you could ignore it assuming this is text that was already inputted into the view.
}
else
{
holder
.
textInputEditText
.
setText
(
value
)
}
holder
.
textInputEditText
.
isEnabled
=
enabled
holder
.
textInputEditText
.
addTextChangedListener
(
onTextChangeListener
)
...
...
vector/src/main/java/im/vector/app/features/form/FormSwitchItem.kt
View file @
5be3faf9
...
...
@@ -40,7 +40,7 @@ abstract class FormSwitchItem : VectorEpoxyModel<FormSwitchItem.Holder>() {
var
switchChecked
:
Boolean
=
false
@EpoxyAttribute
var
title
:
String
?
=
null
var
title
:
CharSequence
?
=
null
@EpoxyAttribute
var
summary
:
String
?
=
null
...
...
@@ -61,10 +61,15 @@ abstract class FormSwitchItem : VectorEpoxyModel<FormSwitchItem.Holder>() {
holder
.
switchView
.
isEnabled
=
enabled
holder
.
switchView
.
setOnCheckedChangeListener
(
null
)
holder
.
switchView
.
isChecked
=
switchChecked
holder
.
switchView
.
setOnCheckedChangeListener
{
_
,
isChecked
->
listener
?.
invoke
(
isChecked
)
if
(
holder
.
view
.
isAttachedToWindow
)
{
// the view is attached to the window
// So it is a rebind of new data and you could ignore it assuming this is value that was already inputted into the view.
}
else
{
holder
.
switchView
.
setOnCheckedChangeListener
(
null
)
holder
.
switchView
.
isChecked
=
switchChecked
holder
.
switchView
.
setOnCheckedChangeListener
{
_
,
isChecked
->
listener
?.
invoke
(
isChecked
)
}
}
holder
.
divider
.
isVisible
=
showDivider
}
...
...
vector/src/main/java/im/vector/app/features/roomdirectory/createroom/RoomAliasEditItem.kt
View file @
5be3faf9
...
...
@@ -27,7 +27,6 @@ import com.google.android.material.textfield.TextInputLayout
import
im.vector.app.R
import
im.vector.app.core.epoxy.VectorEpoxyHolder
import
im.vector.app.core.epoxy.VectorEpoxyModel
import
im.vector.app.core.extensions.setTextSafe
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_room_alias_text_input
)
...
...
@@ -62,8 +61,12 @@ abstract class RoomAliasEditItem : VectorEpoxyModel<RoomAliasEditItem.Holder>()
holder
.
textInputLayout
.
isEnabled
=
enabled
holder
.
textInputLayout
.
error
=
errorMessage
// Update only if text is different and value is not null
holder
.
textInputEditText
.
setTextSafe
(
value
)
if
(
holder
.
view
.
isAttachedToWindow
)
{
// the view is attached to the window
// So it is a rebind of new data and you could ignore it assuming this is text that was already inputted into the view.
}
else
{
holder
.
textInputEditText
.
setText
(
value
)
}
holder
.
textInputEditText
.
isEnabled
=
enabled
holder
.
textInputEditText
.
addTextChangedListener
(
onTextChangeListener
)
holder
.
homeServerText
.
text
=
homeServer
...
...
vector/src/main/res/layout/item_form_switch.xml
View file @
5be3faf9
...
...
@@ -50,7 +50,7 @@
android:id=
"@+id/formSwitchDivider"
android:layout_width=
"0dp"
android:layout_height=
"1dp"
android:background=
"?
riotx_header_panel_border_mobile
"
android:background=
"?
vctr_list_divider_color
"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment