Skip to content
Snippets Groups Projects

Dev

Open Кирилл Шустов requested to merge dev into play-market
4 files
+ 97
38
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -3,30 +3,20 @@ package com.keepsoft_lib.mvp.ui.library.autotext
import android.animation.ArgbEvaluator
import android.animation.ObjectAnimator
import android.content.Context
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.*
import androidx.annotation.MainThread
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import com.keepsoft_lib.homebuh.HBApp
import androidx.lifecycle.*
import com.keepsoft_lib.homebuh.R
import com.keepsoft_lib.mvp.data.repository.DatabaseRepository
import com.keepsoft_lib.mvp.domain.models.CategoryModel
import com.keepsoft_lib.mvp.ui.library.powerspinner.powerspinner.contextDrawable
import kotlinx.android.synthetic.main.autotext_layout.view.*
import java.lang.Exception
import javax.inject.Inject
class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs), LifecycleObserver {
@@ -44,8 +34,8 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
var adapter = KeepSoftAutoTextAdapter(context, R.layout.item_autotext)
private val items = arrayListOf<CategoryModel>()
var isShowing: Boolean = false
private var isShowing: Boolean = false
private var delegate: Delegate? = null
init {
inflate(context, R.layout.autotext_layout, this)
@@ -65,9 +55,11 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
keepsoft_autotext.setText(categoryModel.category)
currentCategory = categoryModel
dismiss()
delegate?.itemSelected(categoryModel)
}
})
add_new.setOnClickListener {
delegate?.addClick(keepsoft_autotext.text.toString())
}
imageArrow.setOnClickListener {
@@ -79,21 +71,18 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
@MainThread
fun showOrDismiss() {
if (!this.isShowing) {
if (!this.isShowing)
show()
} else {
else
dismiss()
}
}
// override fun onDetachedFromWindow() {
// keepsoft_autotext.dismissDropDown()
// super.onDetachedFromWindow()
// }
private fun isExistCategory(text: String): Boolean {
for (item in items)
if (item.category.toLowerCase() == text.toLowerCase())
if (item.category.toLowerCase() == text.toLowerCase()) {
delegate?.itemSelected(item)
return true
}
return false
}
@@ -106,6 +95,32 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
dismiss()
}
fun attachDelegate(delegate: Delegate) {
this.delegate = delegate
}
private fun disabled() {
keepsoft_autotext.clearListSelection()
keepsoft_autotext.setText("")
keepsoft_autotext.isEnabled = false
showArrow()
imageArrow.isEnabled = false
}
private fun enabled() {
keepsoft_autotext.setText("")
keepsoft_autotext.isEnabled = true
imageArrow.isEnabled = true
showArrow()
}
override fun setEnabled(state: Boolean) {
if (state)
enabled()
else
disabled()
}
private fun showAddNew() {
if (add_new.visibility != View.VISIBLE) {
@@ -119,12 +134,19 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
if (s.isBlank())
adapter.updateItems("", items)
if (s.isNotBlank() && !isExistCategory(s))
if (s.isNotBlank() && !isExistCategory(s)) {
showAddNew()
// delegate?.itemSelected(getCategoryByText(s))
}
else
showArrow()
}
// private fun getCategoryByText(s: String): CategoryModel {
// for(item in items)
// // if(item.category)
// }
private fun filterList(text: String) {
val categories = arrayListOf<CategoryModel>()
@@ -189,7 +211,7 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
dismiss()
}
fun makeHide(view: ImageView) {
private fun makeHide(view: ImageView) {
val anim = AnimationUtils.loadAnimation(context, R.anim.zoom_out)
anim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationRepeat(animation: Animation?) {}
@@ -202,8 +224,12 @@ class KeepSoftAutoText(context: Context, attrs: AttributeSet) : LinearLayout(con
view.startAnimation(anim)
}
interface Delegate {
fun addClick(text: String)
fun itemSelected(currentCategory: CategoryModel)
}
fun makeShow(view: ImageView) {
private fun makeShow(view: ImageView) {
val anim = AnimationUtils.loadAnimation(context, R.anim.zoom_in)
anim.setAnimationListener(object : Animation.AnimationListener {
Loading