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
723f7cc3
Commit
723f7cc3
authored
May 10, 2021
by
Valere
Browse files
VectorEpoxyHolder Form Ext
parent
80366ee9
Changes
9
Hide whitespace changes
Inline
Side-by-side
vector/src/main/java/im/vector/app/core/epoxy/VectorEpoxyFormExt.kt
0 → 100644
View file @
723f7cc3
/*
* Copyright (c) 2021 New Vector Ltd
*
* 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.
*/
package
im.vector.app.core.epoxy
import
android.widget.CompoundButton
import
com.google.android.material.switchmaterial.SwitchMaterial
import
com.google.android.material.textfield.TextInputEditText
fun
VectorEpoxyHolder
.
setValueOnce
(
textInputEditText
:
TextInputEditText
,
value
:
String
?)
{
if
(
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
{
textInputEditText
.
setText
(
value
)
}
}
fun
VectorEpoxyHolder
.
setValueOnce
(
switchView
:
SwitchMaterial
,
switchChecked
:
Boolean
,
listener
:
CompoundButton
.
OnCheckedChangeListener
)
{
if
(
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
{
switchView
.
isChecked
=
switchChecked
switchView
.
setOnCheckedChangeListener
(
listener
)
}
}
vector/src/main/java/im/vector/app/core/extensions/EditText.kt
View file @
723f7cc3
...
...
@@ -23,9 +23,7 @@ import android.view.View
import
android.view.inputmethod.EditorInfo
import
android.widget.EditText
import
androidx.annotation.DrawableRes
import
com.google.android.material.textfield.TextInputEditText
import
im.vector.app.R
import
im.vector.app.core.epoxy.VectorEpoxyHolder
import
im.vector.app.core.platform.SimpleTextWatcher
fun
EditText
.
setupAsSearch
(
@DrawableRes
searchIconRes
:
Int
=
R
.
drawable
.
ic_search
,
...
...
@@ -59,17 +57,3 @@ fun EditText.setupAsSearch(@DrawableRes searchIconRes: Int = R.drawable.ic_searc
return
@OnTouchListener
false
})
}
/**
* Set the initial value of the textEdit.
* Avoids issue with two way bindings, the value is only set the first time
*/
fun
TextInputEditText
.
setValueOnce
(
value
:
String
?,
holder
:
VectorEpoxyHolder
)
{
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
{
setText
(
value
)
}
}
vector/src/main/java/im/vector/app/features/form/FormEditTextItem.kt
View file @
723f7cc3
...
...
@@ -27,7 +27,7 @@ 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.e
xtensions
.setValueOnce
import
im.vector.app.core.e
poxy
.setValueOnce
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_text_input
)
...
...
@@ -76,7 +76,7 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
holder
.
textInputLayout
.
error
=
errorMessage
holder
.
textInputLayout
.
endIconMode
=
endIconMode
?:
TextInputLayout
.
END_ICON_NONE
holder
.
textInputEditText
.
setValueOnce
(
value
,
holder
)
holder
.
setValueOnce
(
holder
.
textInputEditText
,
value
)
holder
.
textInputEditText
.
isEnabled
=
enabled
inputType
?.
let
{
holder
.
textInputEditText
.
inputType
=
it
}
...
...
vector/src/main/java/im/vector/app/features/form/FormEditTextWithButtonItem.kt
View file @
723f7cc3
...
...
@@ -26,7 +26,7 @@ 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.e
xtensions
.setValueOnce
import
im.vector.app.core.e
poxy
.setValueOnce
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_text_input_with_button
)
...
...
@@ -61,7 +61,7 @@ abstract class FormEditTextWithButtonItem : VectorEpoxyModel<FormEditTextWithBut
holder
.
textInputLayout
.
isEnabled
=
enabled
holder
.
textInputLayout
.
hint
=
hint
holder
.
textInputEditText
.
setValueOnce
(
value
,
holder
)
holder
.
setValueOnce
(
holder
.
textInputEditText
,
value
)
holder
.
textInputEditText
.
isEnabled
=
enabled
...
...
vector/src/main/java/im/vector/app/features/form/FormMultiLineEditTextItem.kt
View file @
723f7cc3
...
...
@@ -27,7 +27,7 @@ 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.e
xtensions
.setValueOnce
import
im.vector.app.core.e
poxy
.setValueOnce
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_multiline_text_input
)
...
...
@@ -76,7 +76,7 @@ abstract class FormMultiLineEditTextItem : VectorEpoxyModel<FormMultiLineEditTex
holder
.
textInputEditText
.
textSize
=
textSizeSp
?.
toFloat
()
?:
14f
holder
.
textInputEditText
.
minLines
=
minLines
holder
.
textInputEditText
.
setValueOnce
(
value
,
holder
)
holder
.
setValueOnce
(
holder
.
textInputEditText
,
value
)
holder
.
textInputEditText
.
isEnabled
=
enabled
...
...
vector/src/main/java/im/vector/app/features/form/FormSwitchItem.kt
View file @
723f7cc3
...
...
@@ -25,6 +25,7 @@ import com.google.android.material.switchmaterial.SwitchMaterial
import
im.vector.app.R
import
im.vector.app.core.epoxy.VectorEpoxyHolder
import
im.vector.app.core.epoxy.VectorEpoxyModel
import
im.vector.app.core.epoxy.setValueOnce
import
im.vector.app.core.extensions.setTextOrHide
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_form_switch
)
...
...
@@ -61,16 +62,10 @@ abstract class FormSwitchItem : VectorEpoxyModel<FormSwitchItem.Holder>() {
holder
.
switchView
.
isEnabled
=
enabled
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
.
setValueOnce
(
holder
.
switchView
,
switchChecked
)
{
_
,
isChecked
->
listener
?.
invoke
(
isChecked
)
}
holder
.
divider
.
isVisible
=
showDivider
}
...
...
vector/src/main/java/im/vector/app/features/roomdirectory/createroom/RoomAliasEditItem.kt
View file @
723f7cc3
...
...
@@ -27,7 +27,7 @@ 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.e
xtensions
.setValueOnce
import
im.vector.app.core.e
poxy
.setValueOnce
import
im.vector.app.core.platform.SimpleTextWatcher
@EpoxyModelClass
(
layout
=
R
.
layout
.
item_room_alias_text_input
)
...
...
@@ -62,7 +62,7 @@ abstract class RoomAliasEditItem : VectorEpoxyModel<RoomAliasEditItem.Holder>()
holder
.
textInputLayout
.
isEnabled
=
enabled
holder
.
textInputLayout
.
error
=
errorMessage
holder
.
textInputEditText
.
setValueOnce
(
value
,
holder
)
holder
.
setValueOnce
(
holder
.
textInputEditText
,
value
)
holder
.
textInputEditText
.
isEnabled
=
enabled
holder
.
textInputEditText
.
addTextChangedListener
(
onTextChangeListener
)
holder
.
homeServerText
.
text
=
homeServer
...
...
vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewState.kt
View file @
723f7cc3
...
...
@@ -70,24 +70,24 @@ data class RoomSettingsViewState(
)
{
fun
hasChanged
()
=
newJoinRules
!=
null
||
newGuestAccess
!=
null
}
}
fun
RoomSettingsViewState
.
getJoinRuleWording
(
stringProvider
:
StringProvider
):
String
{
return
when
(
val
joinRule
=
newRoomJoinRules
.
newJoinRules
?:
currentRoomJoinRules
)
{
RoomJoinRules
.
INVITE
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_private_title
)
}
RoomJoinRules
.
PUBLIC
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_public_title
)
}
RoomJoinRules
.
KNOCK
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_entry_knock
)
}
RoomJoinRules
.
RESTRICTED
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_restricted_title
)
}
else
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_entry_unknown
,
joinRule
.
value
)
fun
getJoinRuleWording
(
stringProvider
:
StringProvider
):
String
{
return
when
(
val
joinRule
=
newRoomJoinRules
.
newJoinRules
?:
currentRoomJoinRules
)
{
RoomJoinRules
.
INVITE
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_private_title
)
}
RoomJoinRules
.
PUBLIC
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_public_title
)
}
RoomJoinRules
.
KNOCK
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_entry_knock
)
}
RoomJoinRules
.
RESTRICTED
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_restricted_title
)
}
else
->
{
stringProvider
.
getString
(
R
.
string
.
room_settings_room_access_entry_unknown
,
joinRule
.
value
)
}
}
}
}
vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsController.kt
View file @
723f7cc3
...
...
@@ -28,7 +28,6 @@ import im.vector.app.features.form.formMultiLineEditTextItem
import
im.vector.app.features.form.formSwitchItem
import
im.vector.app.features.home.AvatarRenderer
import
im.vector.app.features.roomprofile.settings.RoomSettingsViewState
import
im.vector.app.features.roomprofile.settings.getJoinRuleWording
import
im.vector.app.features.settings.VectorPreferences
import
org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import
org.matrix.android.sdk.api.util.toMatrixItem
...
...
Write
Preview
Supports
Markdown
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