Skip to content

Commit

Permalink
Adicionado input text com opções
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonatan Sabadi authored and Jhonatan Sabadi committed Jul 30, 2020
1 parent 42483e5 commit de6cdef
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ open class BaseDialog(
showBothButtons()
customView.actionButtonDialog?.text = title.toUpperCase()
customView.actionButtonDialog?.setOnClickListener {
dialog.dismiss()
callback(dialog)
}
}
Expand All @@ -174,6 +175,7 @@ open class BaseDialog(
showBothButtons()
customView.neutralButtonDialog?.text = title.toUpperCase()
customView.neutralButtonDialog?.setOnClickListener {
dialog.dismiss()
callback(dialog)
}
}
Expand All @@ -188,7 +190,7 @@ open class BaseDialog(
}
}

private fun showBothButtons() {
internal fun showBothButtons() {
customView.groupActinButtonDialog?.visibility = View.VISIBLE
customView.okButtonDialog?.visibility = View.GONE
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package jhonatan.sabadi.android_dialog.dialog

import android.app.Activity
import android.app.AlertDialog
import android.text.InputType
import android.text.method.TransformationMethod
import android.view.View
import com.airbnb.lottie.LottieDrawable
import com.google.android.material.textfield.TextInputEditText
import jhonatan.sabadi.android_dialog.R
import kotlinx.android.synthetic.main.base_dialog_actions.view.*
import kotlinx.android.synthetic.main.edit_text_dialog.view.*
import kotlinx.android.synthetic.main.lottie_dialog.view.*

class EditTextDialog(
activity: Activity
) : BaseDialog(activity, R.layout.edit_text_dialog) {

//
// fun setInputType(inputType: Int) {
// customView.inputText.inputType = inputType
// }
//
// var hint: String
// get() = ""
// set(value) {
// customView.inputText.hint = value
// }

var customInputText: View = customView.inputText.rootView
fun setInputType(inputType: Int) {
customView.inputText.inputType = inputType
}

var hint: String
get() = ""
set(value) {
customView.inputTextLayout.hint = value
}

fun resultActionButton(title: String = "YES", callback: (dialog: AlertDialog, result: String) -> Unit) {
showBothButtons()
customView.actionButtonDialog?.text = title.toUpperCase()
customView.actionButtonDialog?.setOnClickListener {
dialog.dismiss()
callback(dialog, customView.inputText.text.toString())
}
}


}

Expand Down
13 changes: 8 additions & 5 deletions android-dialog/src/main/res/layout/edit_text_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
android:scaleType="centerCrop"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand All @@ -58,34 +59,36 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/include3">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/inputText"
android:hint="hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
android:inputType="text" />

</com.google.android.material.textfield.TextInputLayout>

<include
android:id="@+id/include3"
layout="@layout/base_dialog"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lottieDialog" />
app:layout_constraintTop_toBottomOf="@+id/imageDialog" />

<include
android:id="@+id/include2"
layout="@layout/base_dialog_actions"
android:layout_width="0dp"
android:layout_marginTop="8dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/inputTextLayout" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jhonatan.sabadi.androiddialogexample

import android.os.Bundle
import android.text.InputType
import android.text.SpannableStringBuilder
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -20,7 +21,11 @@ class MainActivity : AppCompatActivity() {
editTextButton.setOnClickListener {
editTextDialog {
title = "teste"
actionButton("teste") {}
setInputType(InputType.TYPE_CLASS_NUMBER)
hint = "Digite um número"
resultActionButton { dialog, result ->
Toast.makeText(this@MainActivity, result, Toast.LENGTH_SHORT).show()
}
}
}

Expand Down

0 comments on commit de6cdef

Please sign in to comment.