Skip to content

Commit

Permalink
Merge pull request #70 from Trendyol/suggestionInputView/feature/inpu…
Browse files Browse the repository at this point in the history
…t_type_keyboard_state

Implement controll on keyboard for type input
  • Loading branch information
cifo19 authored Apr 2, 2021
2 parents 8575748 + 154743f commit 4de89aa
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ComponentVersions.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object ComponentVersions {

const val toolbarVersion = "2.0.4"
const val suggestionInputViewVersion = "1.0.12"
const val suggestionInputViewVersion = "1.0.13"
const val ratingBarVersion = "1.0.2"
const val imageSliderVersion = "1.0.8"
const val phoneNumberVersion = "1.0.2"
Expand Down
3 changes: 2 additions & 1 deletion libraries/suggestion-input-view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ To set width you can use `android:layout_width` attribute. To customize more you
| `app:inputSuffix` | `setInputSuffix(String)` | Suffix of input view's edit text | Empty String | app:inputSuffix="₺"|
| `android:inputType` | `` | Input type of input view's edit text input type | TYPE_TEXT_VARIATION_NORMAL | android:inputType="number"|
| `app:shouldShowSelectableItemError` | `shouldShowSelectableItemError(Boolean)` | Change suggestion item's background | false | app:shouldShowError="@{true}"|
| `app:inputHint` | | Hint of input view's edit text | Empty String | app:inputHint="Hint of input edit text"|
| `app:inputHint` | `setInputHint(String)` | Hint of input view's edit text | Empty String | app:inputHint="Hint of input edit text"|
| `app:showKeyboardByDefault` | | show keyboard or not by default for input view | true | app:showKeyboardByDefault="false"|

# Contributors
This library is maintained mainly by Trendyol Android Team members but also other Android lovers contributes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import android.text.TextWatcher
import android.transition.ChangeBounds
import android.transition.TransitionManager
import android.util.AttributeSet
import android.view.animation.AnticipateInterpolator
import android.view.inputmethod.EditorInfo
import android.widget.FrameLayout
import androidx.annotation.ColorInt
import androidx.annotation.Dimension
import androidx.constraintlayout.widget.ConstraintSet
import com.trendyol.suggestioninputview.databinding.ViewSuggestionSelectablesBinding
import android.view.animation.AnticipateInterpolator
import android.view.inputmethod.EditorInfo
import com.trendyol.suggestioninputview.databinding.ViewSuggestionInputBinding
import com.trendyol.suggestioninputview.databinding.ViewSuggestionSelectablesBinding

class SuggestionInputView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
Expand Down Expand Up @@ -72,6 +72,8 @@ class SuggestionInputView @JvmOverloads constructor(

private var hint: String = ""

private var showKeyboardByDefault: Boolean = true

private val bindingSelectables: ViewSuggestionSelectablesBinding =
inflate(R.layout.view_suggestion_selectables)
private val bindingInput: ViewSuggestionInputBinding =
Expand Down Expand Up @@ -147,6 +149,7 @@ class SuggestionInputView @JvmOverloads constructor(
EditorInfo.TYPE_TEXT_VARIATION_NORMAL
)
hint = getString(R.styleable.SuggestionInputView_inputHint) ?: ""
showKeyboardByDefault = getBoolean(R.styleable.SuggestionInputView_showKeyboardByDefault, true)
} finally {
recycle()
}
Expand Down Expand Up @@ -275,14 +278,7 @@ class SuggestionInputView @JvmOverloads constructor(
}

private fun onSuggestionItemClicked(suggestionInputItemViewState: SuggestionInputItemViewState) {
shouldShowSelectableItemError(false)
val itemType = suggestionInputItemViewState.type
if (itemType == SuggestionItemType.SELECTABLE) {
currentSelectedItem = mapItemViewStateToInputItem(suggestionInputItemViewState)
setSelectionToSelectableItem(suggestionInputItemViewState)
} else {
showInputView()
}
renderSelection(suggestionInputItemViewState)
}

private fun setSelectionToSelectableItem(selectableItem: SuggestionInputItemViewState) {
Expand Down Expand Up @@ -366,7 +362,7 @@ class SuggestionInputView @JvmOverloads constructor(
}

if (selectedItem != null) {
onSuggestionItemClicked(selectedItem)
renderSelection(selectedItem, showKeyboardByDefault)
}
}

Expand Down Expand Up @@ -411,16 +407,19 @@ class SuggestionInputView @JvmOverloads constructor(
): Boolean =
suggestionInputItemViewState.isSelected && suggestionInputItem.value.trim().isEmpty()

private fun showInputView() {
private fun showInputView(showKeyboard: Boolean) {
val constraintSet = ConstraintSet()
constraintSet.clone(bindingInput.constraintLayoutInput)
setTransition()
applyConstraintSet(constraintSet)
postDelayed({
bindingSelectables.editText.setText(getInputText())
bindingSelectables.editText.requestFocus()
bindingSelectables.editText.setSelection(getInputText().length)
showKeyboard()
val inputText = getInputText()
bindingSelectables.editText.setText(inputText)
bindingSelectables.editText.setSelection(inputText.length)
if (showKeyboard) {
bindingSelectables.editText.requestFocus()
showKeyboard()
}
}, 500)
}

Expand All @@ -434,6 +433,20 @@ class SuggestionInputView @JvmOverloads constructor(
return inputText
}

private fun renderSelection(
suggestionInputItemViewState: SuggestionInputItemViewState,
showKeyboard: Boolean = true
) {
shouldShowSelectableItemError(false)
val itemType = suggestionInputItemViewState.type
if (itemType == SuggestionItemType.SELECTABLE) {
currentSelectedItem = mapItemViewStateToInputItem(suggestionInputItemViewState)
setSelectionToSelectableItem(suggestionInputItemViewState)
} else {
showInputView(showKeyboard)
}
}

private fun showSelectableView() {
clearInputError()
val constraintSet = ConstraintSet()
Expand Down Expand Up @@ -555,6 +568,7 @@ class SuggestionInputView @JvmOverloads constructor(
}

companion object {

const val ID_FREE_TEXT = 192
}
}
6 changes: 4 additions & 2 deletions libraries/suggestion-input-view/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
<attr name="inputEditTextBackground" format="reference" />
<!-- input views's edit text suffix -->
<attr name="inputSuffix" format="string" />
<!-- input views's edit text hint-->
<attr name="inputHint" format="string"/>
<!-- input type for input view's edit text -->
<attr name="android:inputType" />
<!-- show keyboard or not by default for input view -->
<attr name="showKeyboardByDefault" format="boolean"/>
<!-- error background -->
<attr name="errorBackground" format="reference" />
<!-- hint of input edittext -->
<attr name="inputHint" format="string"/>
</declare-styleable>
</resources>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.trendyol.uicomponents

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.trendyol.suggestioninputview.Rule
import com.trendyol.suggestioninputview.SuggestionInputItem
Expand All @@ -27,7 +27,7 @@ class SuggestionInputViewActivity : AppCompatActivity() {
.notEqualsTo("0")
.errorMessage("0 giremezsin")
.build()
binding.suggestionInputView.setRuleSet(listOf(rule1,rule2))
binding.suggestionInputView.setRuleSet(listOf(rule1, rule2))
binding.suggestionInputView.setSuggestionItemClickListener { onSuggestionItemClicked(it) }
binding.suggestionInputView.setItems(createSuggestionInputItems())
binding.buttonLoad.setOnClickListener { onLoadClicked() }
Expand Down

0 comments on commit 4de89aa

Please sign in to comment.