From 2433b124194205465a2720ba329d61344d8ecd49 Mon Sep 17 00:00:00 2001 From: Pedro Francisco de Sousa Neto Date: Mon, 5 Nov 2018 18:55:17 -0200 Subject: [PATCH] - Removing support for DuasLinhas - Using Spinnable as 'Alternativa' --- dataform/build.gradle | 1 + .../dataform/lib/adapter/AdapterCheckBox.kt | 4 +- .../lib/adapter/AdapterItemRemovivel.kt | 4 +- .../lib/adapter/AdapterRadioButton.kt | 4 +- .../lib/adapter/AdapterSpinnerSpinneable.kt | 45 ------------- .../adapter/viewholder/ViewHolderCheckBox.kt | 14 ++-- .../viewholder/ViewHolderItemRemovivel.kt | 19 +++--- .../viewholder/ViewHolderRadioButton.kt | 12 ++-- .../lib/domain/handlers/HandlerInputPopup.kt | 4 +- .../lib/extension/ExtensionSpinnable.kt | 11 ++++ .../lib/extension/ExtensionSpinner.kt | 64 ------------------- .../dataform/lib/interfaces/DuasLinhas.kt | 9 --- .../dataform/lib/interfaces/Spinnable.kt | 14 ---- .../redcode/dataform/lib/model/Alternativa.kt | 23 ------- .../br/redcode/dataform/lib/model/Campo.kt | 3 +- .../br/redcode/dataform/lib/model/Pergunta.kt | 3 +- .../br/redcode/dataform/lib/model/Resposta.kt | 8 +-- .../lib/model/payloads/AlternativaPayload.kt | 2 +- .../lib/ui/UIPerguntaListaItemRemovivel.kt | 33 ++++------ .../lib/ui/UIPerguntaMultiplaEscolha.kt | 10 +-- .../lib/ui/UIPerguntaObjetivaLista.kt | 10 +-- .../lib/ui/UIPerguntaObjetivaSpinner.kt | 25 +++----- sample/build.gradle | 1 + .../redcode/sample/activities/ActivityMain.kt | 12 ++-- .../br/redcode/sample/model/CustomObject.kt | 10 --- .../model/ExtensionFormularioDePerguntas.kt | 1 + sample/src/main/res/raw/perguntas.json | 4 +- sample/src/main/res/raw/perguntas_2.json | 8 +-- 28 files changed, 95 insertions(+), 263 deletions(-) delete mode 100644 dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterSpinnerSpinneable.kt create mode 100644 dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinnable.kt delete mode 100644 dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinner.kt delete mode 100644 dataform/src/main/java/br/redcode/dataform/lib/interfaces/DuasLinhas.kt delete mode 100644 dataform/src/main/java/br/redcode/dataform/lib/interfaces/Spinnable.kt delete mode 100644 dataform/src/main/java/br/redcode/dataform/lib/model/Alternativa.kt delete mode 100644 sample/src/main/java/br/redcode/sample/model/CustomObject.kt diff --git a/dataform/build.gradle b/dataform/build.gradle index 9c251bd..9583a7b 100644 --- a/dataform/build.gradle +++ b/dataform/build.gradle @@ -27,6 +27,7 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.google.android.material:material:1.0.0' + implementation 'com.github.pedrofsn:spinnable:1.0.4.1' implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' } diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterCheckBox.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterCheckBox.kt index c8b136b..5c29ddf 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterCheckBox.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterCheckBox.kt @@ -1,17 +1,17 @@ package br.redcode.dataform.lib.adapter import android.view.View +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.adapter.viewholder.ViewHolderCheckBox import br.redcode.dataform.lib.domain.AdapterGeneric import br.redcode.dataform.lib.interfaces.OnItemClickListener -import br.redcode.dataform.lib.model.Alternativa import br.redcode.dataform.lib.model.ConfiguracaoFormulario /** * Created by pedrofsn on 31/10/2017. */ -class AdapterCheckBox(override var myOnItemClickListener: OnItemClickListener?, val configuracaoFormulario: ConfiguracaoFormulario) : AdapterGeneric() { +class AdapterCheckBox(override var myOnItemClickListener: OnItemClickListener?, val configuracaoFormulario: ConfiguracaoFormulario) : AdapterGeneric() { override val layout: Int = R.layout.adapter_checkbox diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterItemRemovivel.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterItemRemovivel.kt index a641522..28b138e 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterItemRemovivel.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterItemRemovivel.kt @@ -1,17 +1,17 @@ package br.redcode.dataform.lib.adapter import android.view.View +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.adapter.viewholder.ViewHolderItemRemovivel import br.redcode.dataform.lib.domain.AdapterGeneric -import br.redcode.dataform.lib.interfaces.DuasLinhas import br.redcode.dataform.lib.interfaces.OnItemClickListener import br.redcode.dataform.lib.model.ConfiguracaoFormulario /** * Created by pedrofsn on 31/10/2017. */ -class AdapterItemRemovivel(override var myOnItemClickListener: OnItemClickListener?, val configuracao: ConfiguracaoFormulario) : AdapterGeneric() { +class AdapterItemRemovivel(override var myOnItemClickListener: OnItemClickListener?, val configuracao: ConfiguracaoFormulario) : AdapterGeneric() { override val layout: Int = R.layout.adapter_item_removivel diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterRadioButton.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterRadioButton.kt index 955dc8e..369a651 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterRadioButton.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterRadioButton.kt @@ -1,17 +1,17 @@ package br.redcode.dataform.lib.adapter import android.view.View +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.adapter.viewholder.ViewHolderRadioButton import br.redcode.dataform.lib.domain.AdapterGeneric import br.redcode.dataform.lib.interfaces.OnItemClickListener -import br.redcode.dataform.lib.model.Alternativa import br.redcode.dataform.lib.model.ConfiguracaoFormulario /** * Created by pedrofsn on 31/10/2017. */ -class AdapterRadioButton(override var myOnItemClickListener: OnItemClickListener?, val configuracao: ConfiguracaoFormulario) : AdapterGeneric() { +class AdapterRadioButton(override var myOnItemClickListener: OnItemClickListener?, val configuracao: ConfiguracaoFormulario) : AdapterGeneric() { override val layout: Int = R.layout.adapter_radiobutton diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterSpinnerSpinneable.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterSpinnerSpinneable.kt deleted file mode 100644 index d39bdf9..0000000 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/AdapterSpinnerSpinneable.kt +++ /dev/null @@ -1,45 +0,0 @@ -package br.redcode.dataform.lib.adapter - -import android.content.Context -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ArrayAdapter -import android.widget.TextView -import br.redcode.dataform.lib.R -import br.redcode.dataform.lib.interfaces.Spinnable - -/** - * Created by pedrofsn on 27/10/2017. - */ -class AdapterSpinnerSpinneable(mContext: Context, val mObjects: List, val textViewResourceId: Int = R.layout.adapter_spinner) : ArrayAdapter(mContext, textViewResourceId, mObjects) { - - override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View { - return getCustomView(position, parent) - } - - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - return getCustomView(position, parent) - } - - fun getCustomView(position: Int, parent: ViewGroup): View { - val inflater = LayoutInflater.from(context) - val row = inflater.inflate(textViewResourceId, parent, false) - val label = row.findViewById(android.R.id.text1) as TextView - label.text = getItem(position) - return row - } - - override fun getItem(position: Int): String? { - return (super.getItem(position) as Spinnable).getTexto() - } - - fun getSpinnable(position: Int): Spinnable { - return super.getItem(position) as Spinnable - } - - fun getSpinnables(): List { - return mObjects - } - -} \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderCheckBox.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderCheckBox.kt index 1ba846e..fbd30f8 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderCheckBox.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderCheckBox.kt @@ -2,29 +2,29 @@ package br.redcode.dataform.lib.adapter.viewholder import android.view.View import android.widget.CheckBox +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.domain.ViewHolderGeneric import br.redcode.dataform.lib.interfaces.OnItemClickListener -import br.redcode.dataform.lib.model.Alternativa import br.redcode.dataform.lib.model.ConfiguracaoFormulario /** * Created by pedrofsn on 31/10/2017. */ -class ViewHolderCheckBox(itemView: View) : ViewHolderGeneric(itemView) { +class ViewHolderCheckBox(itemView: View) : ViewHolderGeneric(itemView) { private lateinit var checkBox: CheckBox - fun popular(obj: Alternativa, click: OnItemClickListener?, configuracaoFormulario: ConfiguracaoFormulario) { + fun popular(obj: Spinnable, click: OnItemClickListener?, configuracaoFormulario: ConfiguracaoFormulario) { super.popular(obj, click) checkBox.isEnabled = configuracaoFormulario.editavel } - override fun popular(obj: Alternativa) { - checkBox = itemView.findViewById(R.id.checkBox) + override fun popular(obj: Spinnable) { + checkBox = itemView.findViewById(R.id.checkBox) - checkBox.text = obj.descricao - checkBox.isChecked = obj.selecionado + checkBox.text = obj.description + checkBox.isChecked = obj.selected } } \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderItemRemovivel.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderItemRemovivel.kt index 1c1bd9b..9578060 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderItemRemovivel.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderItemRemovivel.kt @@ -3,37 +3,34 @@ package br.redcode.dataform.lib.adapter.viewholder import android.view.View import android.widget.ImageView import android.widget.TextView +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.domain.ViewHolderGeneric import br.redcode.dataform.lib.extension.setTextOrHide -import br.redcode.dataform.lib.interfaces.DuasLinhas import br.redcode.dataform.lib.interfaces.OnItemClickListener import br.redcode.dataform.lib.model.ConfiguracaoFormulario /** * Created by pedrofsn on 31/10/2017. */ -class ViewHolderItemRemovivel(itemView: View) : ViewHolderGeneric(itemView) { +class ViewHolderItemRemovivel(itemView: View) : ViewHolderGeneric(itemView) { private lateinit var textViewLinha1: TextView - private lateinit var textViewLinha2: TextView private lateinit var imageViewRemoverItem: ImageView - override fun popular(obj: DuasLinhas) { - textViewLinha1 = itemView.findViewById(R.id.textViewLinha1) - textViewLinha2 = itemView.findViewById(R.id.textViewLinha2) - imageViewRemoverItem = itemView.findViewById(R.id.imageViewRemoverItem) + override fun popular(obj: Spinnable) { + textViewLinha1 = itemView.findViewById(R.id.textViewLinha1) + imageViewRemoverItem = itemView.findViewById(R.id.imageViewRemoverItem) - textViewLinha1.setTextOrHide(obj.getId()) - textViewLinha2.setTextOrHide(obj.getTexto()) + textViewLinha1.setTextOrHide(obj.description) } - override fun popular(obj: DuasLinhas, click: OnItemClickListener?) { + override fun popular(obj: Spinnable, click: OnItemClickListener?) { super.popular(obj, click) click?.let { imageViewRemoverItem.setOnClickListener { click.onItemClickListener(adapterPosition) } } } - fun popular(duasLinhas: DuasLinhas, myOnItemClickListener: OnItemClickListener?, configuracao: ConfiguracaoFormulario) { + fun popular(duasLinhas: Spinnable, myOnItemClickListener: OnItemClickListener?, configuracao: ConfiguracaoFormulario) { popular(duasLinhas, myOnItemClickListener) imageViewRemoverItem.visibility = if (configuracao.editavel) View.VISIBLE else View.GONE } diff --git a/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderRadioButton.kt b/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderRadioButton.kt index fe455f2..0259f7a 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderRadioButton.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/adapter/viewholder/ViewHolderRadioButton.kt @@ -2,27 +2,27 @@ package br.redcode.dataform.lib.adapter.viewholder import android.view.View import android.widget.RadioButton +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.domain.ViewHolderGeneric import br.redcode.dataform.lib.interfaces.OnItemClickListener -import br.redcode.dataform.lib.model.Alternativa import br.redcode.dataform.lib.model.ConfiguracaoFormulario /** * Created by pedrofsn on 31/10/2017. */ -class ViewHolderRadioButton(itemView: View) : ViewHolderGeneric(itemView) { +class ViewHolderRadioButton(itemView: View) : ViewHolderGeneric(itemView) { private lateinit var radioButton: RadioButton - override fun popular(obj: Alternativa) { + override fun popular(obj: Spinnable) { radioButton = itemView.findViewById(R.id.radioButton) - radioButton.text = obj.descricao - radioButton.isChecked = obj.selecionado + radioButton.text = obj.description + radioButton.isChecked = obj.selected } - fun popular(obj: Alternativa, click: OnItemClickListener?, configuracaoFormulario: ConfiguracaoFormulario) { + fun popular(obj: Spinnable, click: OnItemClickListener?, configuracaoFormulario: ConfiguracaoFormulario) { super.popular(obj, click) radioButton.isEnabled = configuracaoFormulario.editavel } diff --git a/dataform/src/main/java/br/redcode/dataform/lib/domain/handlers/HandlerInputPopup.kt b/dataform/src/main/java/br/redcode/dataform/lib/domain/handlers/HandlerInputPopup.kt index 9b6a3e5..2c31ed7 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/domain/handlers/HandlerInputPopup.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/domain/handlers/HandlerInputPopup.kt @@ -1,6 +1,6 @@ package br.redcode.dataform.lib.domain.handlers -import br.redcode.dataform.lib.interfaces.DuasLinhas +import br.com.redcode.spinnable.library.model.Spinnable /** * Created by pedrofsn on 13/11/2017. @@ -9,7 +9,7 @@ abstract class HandlerInputPopup { var idPergunta = -1 - open fun chamarPopup(idPergunta: Int, functionAdicionarItem: (idPergunta: Int, duasLinhas: DuasLinhas) -> Unit) { + open fun chamarPopup(idPergunta: Int, functionAdicionarItem: (idPergunta: Int, spinnable: Spinnable) -> Unit) { this.idPergunta = idPergunta } diff --git a/dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinnable.kt b/dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinnable.kt new file mode 100644 index 0000000..d7154a6 --- /dev/null +++ b/dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinnable.kt @@ -0,0 +1,11 @@ +package br.redcode.dataform.lib.extension + +import br.com.redcode.spinnable.library.model.Spinnable +import br.redcode.dataform.lib.model.payloads.AlternativaPayload + +/** + * Created by pedrofsn on 31/10/2017. + */ +fun Spinnable.toDTO(): AlternativaPayload { + return AlternativaPayload(id.toLong(), selected) +} \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinner.kt b/dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinner.kt deleted file mode 100644 index 86948f7..0000000 --- a/dataform/src/main/java/br/redcode/dataform/lib/extension/ExtensionSpinner.kt +++ /dev/null @@ -1,64 +0,0 @@ -package br.redcode.dataform.lib.extension - -import android.os.Handler -import android.widget.Spinner -import br.redcode.dataform.lib.R -import br.redcode.dataform.lib.adapter.AdapterSpinnerSpinneable -import br.redcode.dataform.lib.interfaces.Spinnable -import br.redcode.dataform.lib.utils.Constantes -import java.util.* - -/** - * Created by pedrofsn on 31/10/2017. - */ - -fun Spinner.setSpinnable(list: List, hasDefault: Boolean = false, id: String? = Constantes.STRING_VAZIA): AdapterSpinnerSpinneable { - val temp = ArrayList() - var adapterSpinner = AdapterSpinnerSpinneable(context, temp) - - if (list.isNotEmpty()) { - if (hasDefault) { - temp.add(object : Spinnable { - override fun getId(): String { - return Constantes.STRING_VAZIA - } - - override fun getTexto(): String { - return context.getString(R.string.selecione) - } - } as Spinnable) - } - - temp.addAll(list) - adapterSpinner = AdapterSpinnerSpinneable(context, temp) - adapter = adapterSpinner - - // Marcar item pré-selecionado - if (id?.isNotEmpty() == true) { - for (i in list.indices) { - val spinnable = list[i] - - if (id.equals(spinnable.getId(), ignoreCase = true)) { - Handler().postDelayed(Runnable { - val positionOfItem = if (hasDefault) { - i + 1 - } else { - i - } - - setSelection(positionOfItem, true) - }, 500) - - break - } - } - } - } - - return adapterSpinner -} - -fun Spinner.getSpinnableFromSpinner(spinnables: List): Spinnable? { - val textoSelecionado = selectedItem?.toString()?.trim() ?: Constantes.STRING_VAZIA - return if (textoSelecionado.isNotEmpty()) spinnables.firstOrNull { spinnable -> textoSelecionado == spinnable.getTexto().trim() } else null -} \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/interfaces/DuasLinhas.kt b/dataform/src/main/java/br/redcode/dataform/lib/interfaces/DuasLinhas.kt deleted file mode 100644 index 1aed7c2..0000000 --- a/dataform/src/main/java/br/redcode/dataform/lib/interfaces/DuasLinhas.kt +++ /dev/null @@ -1,9 +0,0 @@ -package br.redcode.dataform.lib.interfaces - -/** - * Created by pedrofsn on 13/11/2017. - */ -open class DuasLinhas(val linha1: String, val linha2: String, val auxiliar: Any? = null) : Spinnable { - override fun getId() = linha1 - override fun getTexto() = linha2 -} \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/interfaces/Spinnable.kt b/dataform/src/main/java/br/redcode/dataform/lib/interfaces/Spinnable.kt deleted file mode 100644 index 82c2c64..0000000 --- a/dataform/src/main/java/br/redcode/dataform/lib/interfaces/Spinnable.kt +++ /dev/null @@ -1,14 +0,0 @@ -package br.redcode.dataform.lib.interfaces - -import java.io.Serializable - -/** - * Created by pedrofsn on 31/10/2017. - */ -interface Spinnable : Serializable { - - fun getId(): String - - fun getTexto(): String - -} \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/model/Alternativa.kt b/dataform/src/main/java/br/redcode/dataform/lib/model/Alternativa.kt deleted file mode 100644 index 9b6c026..0000000 --- a/dataform/src/main/java/br/redcode/dataform/lib/model/Alternativa.kt +++ /dev/null @@ -1,23 +0,0 @@ -package br.redcode.dataform.lib.model - -import br.redcode.dataform.lib.interfaces.Spinnable -import br.redcode.dataform.lib.model.payloads.AlternativaPayload - -/** - * Created by pedrofsn on 31/10/2017. - */ -data class Alternativa( - @get:JvmName("getIdString") val id: String, - val descricao: String, - var selecionado: Boolean = false -) : Spinnable { - - override fun getId() = id - override fun getTexto(): String { - return descricao - } - - fun toDTO(): AlternativaPayload { - return AlternativaPayload(id.toLong(), selecionado) - } -} \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/model/Campo.kt b/dataform/src/main/java/br/redcode/dataform/lib/model/Campo.kt index 767e95c..4f95e8f 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/model/Campo.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/model/Campo.kt @@ -1,5 +1,6 @@ package br.redcode.dataform.lib.model +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.utils.Constantes import java.io.Serializable @@ -11,7 +12,7 @@ data class Campo( val descricao: String, val tipo: String, - val alternativas: List? = null + val alternativas: List? = null ) : Serializable { fun isTextoData(): Boolean { diff --git a/dataform/src/main/java/br/redcode/dataform/lib/model/Pergunta.kt b/dataform/src/main/java/br/redcode/dataform/lib/model/Pergunta.kt index d7c7e9e..d721228 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/model/Pergunta.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/model/Pergunta.kt @@ -1,5 +1,6 @@ package br.redcode.dataform.lib.model +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.utils.Constantes import br.redcode.dataform.lib.utils.Constantes.TIPO_PERGUNTA_IMAGEM_CAMERA_OU_GALERIA import br.redcode.dataform.lib.utils.Constantes.TIPO_PERGUNTA_IMAGEM_SOMENTE_CAMERA @@ -26,7 +27,7 @@ data class Pergunta( val tipo: String? = null, var limite: Limite? = null, - var alternativas: ArrayList? = null, + var alternativas: ArrayList? = null, var textoInformativo: String? = null, var configuracaoPergunta: HashMap? = null ) : Serializable { diff --git a/dataform/src/main/java/br/redcode/dataform/lib/model/Resposta.kt b/dataform/src/main/java/br/redcode/dataform/lib/model/Resposta.kt index 7a258d1..15c9fcc 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/model/Resposta.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/model/Resposta.kt @@ -1,6 +1,6 @@ package br.redcode.dataform.lib.model -import br.redcode.dataform.lib.interfaces.DuasLinhas +import br.com.redcode.spinnable.library.model.Spinnable import java.io.Serializable /** @@ -9,10 +9,10 @@ import java.io.Serializable data class Resposta( var idPergunta: Int? = null, var resposta: String? = null, - var respostas: ArrayList? = null, + var respostas: ArrayList? = null, - var alternativa: Alternativa? = null, - var alternativas: ArrayList? = null, + var alternativa: Spinnable? = null, + var alternativas: ArrayList? = null, var imagens: ArrayList? = null, var tag: String? = null ) : Serializable { diff --git a/dataform/src/main/java/br/redcode/dataform/lib/model/payloads/AlternativaPayload.kt b/dataform/src/main/java/br/redcode/dataform/lib/model/payloads/AlternativaPayload.kt index 85f6d23..a72191f 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/model/payloads/AlternativaPayload.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/model/payloads/AlternativaPayload.kt @@ -7,5 +7,5 @@ import java.io.Serializable */ data class AlternativaPayload( val id: Long, - var selecionado: Boolean = false + var selected: Boolean = false ) : Serializable \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaListaItemRemovivel.kt b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaListaItemRemovivel.kt index 883df83..15db8be 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaListaItemRemovivel.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaListaItemRemovivel.kt @@ -5,12 +5,12 @@ import android.view.View import android.widget.LinearLayout import android.widget.RelativeLayout import android.widget.TextView +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.R import br.redcode.dataform.lib.adapter.AdapterItemRemovivel import br.redcode.dataform.lib.domain.UIPerguntaGeneric import br.redcode.dataform.lib.domain.handlers.HandlerInputPopup import br.redcode.dataform.lib.extension.setCustomAdapter -import br.redcode.dataform.lib.interfaces.DuasLinhas import br.redcode.dataform.lib.interfaces.OnItemClickListener import br.redcode.dataform.lib.interfaces.Perguntavel import br.redcode.dataform.lib.model.ConfiguracaoFormulario @@ -21,7 +21,7 @@ import br.redcode.dataform.lib.model.Resposta /** * Created by pedrofsn on 31/10/2017. */ -class UIPerguntaListaItemRemovivel(val contextActivity: Context, pergunta: Pergunta, configuracao: ConfiguracaoFormulario, val handlerInputPopup: HandlerInputPopup) : UIPerguntaGeneric(contextActivity, R.layout.ui_pergunta_lista_item_removivel, pergunta, configuracao), Perguntavel { +class UIPerguntaListaItemRemovivel(private val contextActivity: Context, pergunta: Pergunta, configuracao: ConfiguracaoFormulario, private val handlerInputPopup: HandlerInputPopup) : UIPerguntaGeneric(contextActivity, R.layout.ui_pergunta_lista_item_removivel, pergunta, configuracao), Perguntavel { private lateinit var recyclerView: androidx.recyclerview.widget.RecyclerView private lateinit var textViewAndamento: TextView @@ -36,23 +36,23 @@ class UIPerguntaListaItemRemovivel(val contextActivity: Context, pergunta: Pergu override fun initView(view: View) { super.initView(view) - recyclerView = view.findViewById(R.id.recyclerView) - textViewAndamento = view.findViewById(R.id.textViewAndamento) - linearLayoutAdicionar = view.findViewById(R.id.linearLayoutAdicionar) - relativeLayout = view.findViewById(R.id.relativeLayout) + recyclerView = view.findViewById(R.id.recyclerView) + textViewAndamento = view.findViewById(R.id.textViewAndamento) + linearLayoutAdicionar = view.findViewById(R.id.linearLayoutAdicionar) + relativeLayout = view.findViewById(R.id.relativeLayout) } override fun populateView() { super.populateView() - recyclerView.setTag("ui_pergunta_" + pergunta.id + "_recyclerview") - textViewAndamento.setTag("ui_pergunta_" + pergunta.id + "_textview") - linearLayoutAdicionar.setTag("ui_pergunta_" + pergunta.id + "_linearlayout") + recyclerView.tag = "ui_pergunta_${pergunta.id}_recyclerview" + textViewAndamento.tag = "ui_pergunta_${pergunta.id}_textview" + linearLayoutAdicionar.tag = "ui_pergunta_${pergunta.id}_linearlayout" recyclerView.setCustomAdapter(adapter, true) - val functionAdicionarItem = { idPerguntaHandler: Int, duasLinhas: DuasLinhas -> + val functionAdicionarItem = { idPerguntaHandler: Int, spinnable: Spinnable -> if (configuracao.editavel && idPerguntaHandler == pergunta.id) { - adapter.adicionar(duasLinhas) + adapter.adicionar(spinnable) atualizarContador() } } @@ -89,14 +89,7 @@ class UIPerguntaListaItemRemovivel(val contextActivity: Context, pergunta: Pergu return resposta } - override fun isPreenchidoCorretamente(): Boolean { - val countItens = adapter.getLista().size - val isPreenchidoCorretamente = countItens >= pergunta.getLimiteMinimo() && countItens <= pergunta.getLimiteMaximo() - return isPreenchidoCorretamente - } - - override fun getMensagemErroPreenchimento(): String { - return String.format(contextActivity.getString(R.string.faltam_x_itens), (pergunta.getLimiteMaximo() - adapter.getLista().size)) - } + override fun isPreenchidoCorretamente() = adapter.getLista().size in pergunta.getLimiteMaximo()..pergunta.getLimiteMinimo() + override fun getMensagemErroPreenchimento() = String.format(contextActivity.getString(R.string.faltam_x_itens), (pergunta.getLimiteMaximo() - adapter.getLista().size)) } \ No newline at end of file diff --git a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaMultiplaEscolha.kt b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaMultiplaEscolha.kt index 75e40b2..2836a1b 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaMultiplaEscolha.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaMultiplaEscolha.kt @@ -40,8 +40,8 @@ class UIPerguntaMultiplaEscolha(val contextActivity: Context, pergunta: Pergunta pergunta.resposta?.alternativas?.let { for (alternativa in adapter.getLista()) { for (resposta in it) { - if (resposta.selecionado && resposta.id == alternativa.id) { - alternativa.selecionado = resposta.selecionado + if (resposta.selected && resposta.id == alternativa.id) { + alternativa.selected = resposta.selected } } } @@ -54,9 +54,9 @@ class UIPerguntaMultiplaEscolha(val contextActivity: Context, pergunta: Pergunta override fun onItemClickListener(position: Int) { if (configuracao.editavel) { pergunta.alternativas?.let { - val estado = it.get(position).selecionado + val estado = it.get(position).selected - it.get(position).selecionado = estado.not() + it.get(position).selected = estado.not() adapter.notifyDataSetChanged() } } @@ -75,7 +75,7 @@ class UIPerguntaMultiplaEscolha(val contextActivity: Context, pergunta: Pergunta } fun getQuantidadeAlternativasMarcadas(): Int { - return getResposta().alternativas?.filter { it.selecionado }?.size ?: 0 + return getResposta().alternativas?.filter { it.selected }?.size ?: 0 } override fun getMensagemErroPreenchimento(): String { diff --git a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaLista.kt b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaLista.kt index 83d353b..db69d05 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaLista.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaLista.kt @@ -40,9 +40,9 @@ class UIPerguntaObjetivaLista(val contextActivity: Context, pergunta: Pergunta, pergunta.resposta?.alternativa?.let { for (i in adapter.getLista().indices) { - if (it.selecionado && it.id == adapter.getLista().get(i).id) { + if (it.selected && it.id == adapter.getLista().get(i).id) { posicaoSelecionada = i - adapter.getLista().get(i).selecionado = true + adapter.getLista().get(i).selected = true adapter.notifyDataSetChanged() break } @@ -53,13 +53,13 @@ class UIPerguntaObjetivaLista(val contextActivity: Context, pergunta: Pergunta, override fun onItemClickListener(position: Int) { if (configuracao.editavel) { pergunta.alternativas?.let { - val estado = it.get(position).selecionado + val estado = it.get(position).selected for (alternativa in it) { - alternativa.selecionado = false + alternativa.selected = false } - it.get(position).selecionado = estado.not() + it.get(position).selected = estado.not() posicaoSelecionada = if (estado.not()) { position } else { diff --git a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaSpinner.kt b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaSpinner.kt index a1c36ca..c008be3 100644 --- a/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaSpinner.kt +++ b/dataform/src/main/java/br/redcode/dataform/lib/ui/UIPerguntaObjetivaSpinner.kt @@ -3,13 +3,12 @@ package br.redcode.dataform.lib.ui import android.content.Context import android.view.View import android.widget.Spinner +import br.com.redcode.spinnable.library.adapter.AdapterSpinneable +import br.com.redcode.spinnable.library.extensions_functions.getSpinnableFromSpinner +import br.com.redcode.spinnable.library.extensions_functions.setSpinnable import br.redcode.dataform.lib.R -import br.redcode.dataform.lib.adapter.AdapterSpinnerSpinneable import br.redcode.dataform.lib.domain.UIPerguntaGeneric -import br.redcode.dataform.lib.extension.getSpinnableFromSpinner -import br.redcode.dataform.lib.extension.setSpinnable import br.redcode.dataform.lib.interfaces.Perguntavel -import br.redcode.dataform.lib.model.Alternativa import br.redcode.dataform.lib.model.ConfiguracaoFormulario import br.redcode.dataform.lib.model.Pergunta import br.redcode.dataform.lib.model.Resposta @@ -20,8 +19,7 @@ import br.redcode.dataform.lib.model.Resposta class UIPerguntaObjetivaSpinner(val contextActivity: Context, pergunta: Pergunta, configuracao: ConfiguracaoFormulario) : UIPerguntaGeneric(contextActivity, R.layout.ui_pergunta_objetiva_spinner, pergunta, configuracao), Perguntavel { private lateinit var spinner: Spinner - - private lateinit var adapter: AdapterSpinnerSpinneable + private lateinit var adapter: AdapterSpinneable override fun initView(view: View) { super.initView(view) @@ -30,7 +28,7 @@ class UIPerguntaObjetivaSpinner(val contextActivity: Context, pergunta: Pergunta override fun populateView() { super.populateView() - spinner.setTag("ui_pergunta_" + pergunta.id + "_spinner") + spinner.tag = "ui_pergunta_${pergunta.id}_spinner" pergunta.alternativas?.let { val idPreSelecionado = pergunta.resposta?.alternativa?.id.toString() @@ -44,9 +42,9 @@ class UIPerguntaObjetivaSpinner(val contextActivity: Context, pergunta: Pergunta val spinnable = spinner.getSpinnableFromSpinner(adapter.getSpinnables()) val resposta = Resposta() - if (spinnable != null && spinnable is Alternativa) { + if (spinnable != null) { resposta.alternativa = spinnable - resposta.alternativa?.selecionado = true + resposta.alternativa?.selected = true } if (pergunta.resposta != null) resposta.tag = pergunta.resposta?.tag @@ -54,12 +52,7 @@ class UIPerguntaObjetivaSpinner(val contextActivity: Context, pergunta: Pergunta return resposta } - override fun isPreenchidoCorretamente(): Boolean { - return spinner.selectedItemPosition != 0 || spinner.visibility == View.GONE // TODO ver se comporta como no Java - } - - override fun getMensagemErroPreenchimento(): String { - return contextActivity.getString(R.string.selecione_ao_menos_uma_alternativa) - } + override fun isPreenchidoCorretamente() = spinner.selectedItemPosition != 0 || spinner.visibility == View.GONE + override fun getMensagemErroPreenchimento() = contextActivity.getString(R.string.selecione_ao_menos_uma_alternativa) } \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 5c0fb6b..f0b77d1 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -26,6 +26,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.anko:anko-commons:$anko_version" implementation 'com.google.android.material:material:1.0.0' + implementation 'com.github.pedrofsn:spinnable:1.0.4.1' implementation 'com.github.chrisbanes:PhotoView:2.1.3' implementation 'com.github.jkwiecien:EasyImage:2.1.0' implementation 'com.github.pedrofsn:easyglide:1.0.0' diff --git a/sample/src/main/java/br/redcode/sample/activities/ActivityMain.kt b/sample/src/main/java/br/redcode/sample/activities/ActivityMain.kt index d41fa7b..bc10292 100644 --- a/sample/src/main/java/br/redcode/sample/activities/ActivityMain.kt +++ b/sample/src/main/java/br/redcode/sample/activities/ActivityMain.kt @@ -4,21 +4,19 @@ import android.os.Bundle import android.view.View import android.widget.* import br.com.concrete.canarinho.watcher.CPFCNPJTextWatcher +import br.com.redcode.spinnable.library.model.Spinnable import br.redcode.dataform.lib.domain.handlers.HandlerInputPopup -import br.redcode.dataform.lib.interfaces.DuasLinhas import br.redcode.dataform.lib.model.FormularioDePerguntas import br.redcode.dataform.lib.ui.UIAgregadorPerguntas import br.redcode.sample.R import br.redcode.sample.dialogs.DialogCheckin import br.redcode.sample.domain.ActivityCapturarImagem import br.redcode.sample.interfaces.OnPosicaoCadastrada -import br.redcode.sample.model.CustomObject import br.redcode.sample.utils.JSONReader import br.redcode.sample.utils.Utils import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_main.* import org.jetbrains.anko.intentFor -import java.util.* class ActivityMain : ActivityCapturarImagem() { @@ -58,7 +56,7 @@ class ActivityMain : ActivityCapturarImagem() { private fun afterOnCreate() { val handlerInputPopup = object : HandlerInputPopup() { - override fun chamarPopup(idPergunta: Int, functionAdicionarItem: (idPergunta: Int, duasLinhas: DuasLinhas) -> Unit) { + override fun chamarPopup(idPergunta: Int, functionAdicionarItem: (idPergunta: Int, spinnable: Spinnable) -> Unit) { super.chamarPopup(idPergunta, functionAdicionarItem) abrirPopup(idPergunta, functionAdicionarItem) } @@ -100,14 +98,14 @@ class ActivityMain : ActivityCapturarImagem() { } } - private fun abrirPopup(idPergunta: Int, functionAdicionarItem: (idPergunta: Int, duasLinhas: DuasLinhas) -> Unit) { + private fun abrirPopup(idPergunta: Int, functionAdicionarItem: (idPergunta: Int, spinnable: Spinnable) -> Unit) { when (idPergunta) { 888 -> - functionAdicionarItem.invoke(idPergunta, DuasLinhas("Título", "Teste", auxiliar = Calendar.getInstance().toString())) + functionAdicionarItem.invoke(idPergunta, Spinnable("Título", "Teste"/*, auxiliar = Calendar.getInstance().toString()*/)) else -> { DialogCheckin.customShow(this@ActivityMain, object : OnPosicaoCadastrada { override fun onPosicaoCadastrada(latitude: String, longitude: String) { - val obj = CustomObject(latitude, longitude) + val obj = Spinnable(latitude, longitude) functionAdicionarItem.invoke(idPergunta, obj) } }) diff --git a/sample/src/main/java/br/redcode/sample/model/CustomObject.kt b/sample/src/main/java/br/redcode/sample/model/CustomObject.kt deleted file mode 100644 index 8c8a4b7..0000000 --- a/sample/src/main/java/br/redcode/sample/model/CustomObject.kt +++ /dev/null @@ -1,10 +0,0 @@ -package br.redcode.sample.model - -import br.redcode.dataform.lib.interfaces.DuasLinhas -import java.util.* - -/** - * Created by pedrofsn on 13/11/2017. - */ -open class CustomObject(val latitude: String, val longitude: String, val dataAtual: Date = Date()) - : DuasLinhas(latitude, longitude, dataAtual) \ No newline at end of file diff --git a/sample/src/main/java/br/redcode/sample/model/ExtensionFormularioDePerguntas.kt b/sample/src/main/java/br/redcode/sample/model/ExtensionFormularioDePerguntas.kt index c128e29..68ebbd5 100644 --- a/sample/src/main/java/br/redcode/sample/model/ExtensionFormularioDePerguntas.kt +++ b/sample/src/main/java/br/redcode/sample/model/ExtensionFormularioDePerguntas.kt @@ -1,5 +1,6 @@ package br.redcode.sample.model +import br.redcode.dataform.lib.extension.toDTO import br.redcode.dataform.lib.model.FormularioDePerguntas import br.redcode.dataform.lib.model.Pergunta import br.redcode.dataform.lib.model.payloads.RespostaPayload diff --git a/sample/src/main/res/raw/perguntas.json b/sample/src/main/res/raw/perguntas.json index fed6316..5cf32bb 100644 --- a/sample/src/main/res/raw/perguntas.json +++ b/sample/src/main/res/raw/perguntas.json @@ -52,7 +52,7 @@ "resposta": { "alternativa": { "id": "2", - "selecionado": true + "selected": true } } }, @@ -75,7 +75,7 @@ "alternativa": { "id": "1", "descricao": "yes", - "selecionado": true + "selected": true } } } diff --git a/sample/src/main/res/raw/perguntas_2.json b/sample/src/main/res/raw/perguntas_2.json index b53c26b..d379eec 100644 --- a/sample/src/main/res/raw/perguntas_2.json +++ b/sample/src/main/res/raw/perguntas_2.json @@ -87,7 +87,7 @@ "alternativa": { "id": "0", "descricao": "Masculino", - "selecionado": true + "selected": true } } }, @@ -119,12 +119,12 @@ { "id": "0", "descricao": "Coxinha", - "selecionado": true + "selected": true }, { "id": "1", "descricao": "Empadinha", - "selecionado": true + "selected": true } ] } @@ -192,7 +192,7 @@ "alternativa": { "id": "1", "descricao": "casado", - "selecionado": true + "selected": true } } },