mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Android style to validate form
This commit is contained in:
parent
99e8f9c6cd
commit
aaa772c749
4 changed files with 90 additions and 13 deletions
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2020 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.features.form
|
||||
|
||||
import android.widget.Button
|
||||
import androidx.annotation.StringRes
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import com.airbnb.epoxy.EpoxyModelWithHolder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.ClickListener
|
||||
import im.vector.app.core.epoxy.VectorEpoxyHolder
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
import im.vector.app.core.extensions.setTextOrHide
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_form_submit_button)
|
||||
abstract class FormSubmitButtonItem : EpoxyModelWithHolder<FormSubmitButtonItem.Holder>() {
|
||||
|
||||
@EpoxyAttribute
|
||||
var enabled: Boolean = true
|
||||
|
||||
@EpoxyAttribute
|
||||
var buttonTitle: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
@StringRes
|
||||
var buttonTitleId: Int? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var buttonClickListener: ClickListener? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
if (buttonTitleId != null) {
|
||||
holder.button.setText(buttonTitleId!!)
|
||||
} else {
|
||||
holder.button.setTextOrHide(buttonTitle)
|
||||
}
|
||||
|
||||
holder.button.isEnabled = enabled
|
||||
holder.button.onClick(buttonClickListener)
|
||||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
val button by bind<Button>(R.id.form_submit_button)
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ import im.vector.app.core.error.ErrorFormatter
|
|||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.discovery.settingsSectionTitleItem
|
||||
import im.vector.app.features.form.formEditTextItem
|
||||
import im.vector.app.features.form.formSubmitButtonItem
|
||||
import im.vector.app.features.form.formSwitchItem
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -139,6 +140,12 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
|
|||
listener?.setIsEncrypted(value)
|
||||
}
|
||||
}
|
||||
formSubmitButtonItem {
|
||||
id("submit")
|
||||
enabled(enableFormElement)
|
||||
buttonTitleId(R.string.room_creation_title)
|
||||
buttonClickListener { listener?.submit() }
|
||||
}
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
|
@ -148,5 +155,6 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
|
|||
fun setIsInRoomDirectory(isInRoomDirectory: Boolean)
|
||||
fun setIsEncrypted(isEncrypted: Boolean)
|
||||
fun retry()
|
||||
fun submit()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@ class CreateRoomFragment @Inject constructor(
|
|||
|
||||
override fun getLayoutResId() = R.layout.fragment_create_room
|
||||
|
||||
override fun getMenuRes() = R.menu.vector_room_creation
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
vectorBaseActivity.setSupportActionBar(createRoomToolbar)
|
||||
|
@ -59,17 +57,6 @@ class CreateRoomFragment @Inject constructor(
|
|||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_create_room -> {
|
||||
viewModel.handle(CreateRoomAction.Create)
|
||||
true
|
||||
}
|
||||
else ->
|
||||
super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
createRoomForm.configureWith(createRoomController)
|
||||
createRoomController.listener = this
|
||||
|
@ -95,6 +82,10 @@ class CreateRoomFragment @Inject constructor(
|
|||
viewModel.handle(CreateRoomAction.SetIsEncrypted(isEncrypted))
|
||||
}
|
||||
|
||||
override fun submit() {
|
||||
viewModel.handle(CreateRoomAction.Create)
|
||||
}
|
||||
|
||||
override fun retry() {
|
||||
Timber.v("Retry")
|
||||
viewModel.handle(CreateRoomAction.Create)
|
||||
|
|
18
vector/src/main/res/layout/item_form_submit_button.xml
Normal file
18
vector/src/main/res/layout/item_form_submit_button.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?riotx_background"
|
||||
android:minHeight="64dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/form_submit_button"
|
||||
style="@style/VectorButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginEnd="@dimen/alerter_activity_vertical_margin"
|
||||
tools:text="@string/auth_submit" />
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue