Add EditText coloring

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-07-27 00:40:46 +02:00
parent 28aae00641
commit 0463a39bfb
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 31 additions and 4 deletions

View file

@ -26,10 +26,12 @@ import android.text.TextWatcher
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.R
import com.nextcloud.talk.databinding.PollCreateOptionsItemBinding
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.EmojiTextInputEditText
class PollCreateOptionViewHolder(
private val binding: PollCreateOptionsItemBinding
private val binding: PollCreateOptionsItemBinding,
private val viewThemeUtils: ViewThemeUtils
) : RecyclerView.ViewHolder(binding.root) {
lateinit var optionText: EmojiTextInputEditText
@ -48,6 +50,7 @@ class PollCreateOptionViewHolder(
}
binding.pollOptionTextEdit.setText(pollCreateOptionItem.pollOption)
viewThemeUtils.colorEditText(binding.pollOptionText)
if (focus) {
itemsListener.requestFocus(binding.pollOptionTextEdit)

View file

@ -24,9 +24,11 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.databinding.PollCreateOptionsItemBinding
import com.nextcloud.talk.ui.theme.ViewThemeUtils
class PollCreateOptionsAdapter(
private val clickListener: PollCreateOptionsItemListener
private val clickListener: PollCreateOptionsItemListener,
private val viewThemeUtils: ViewThemeUtils
) : RecyclerView.Adapter<PollCreateOptionViewHolder>() {
internal var list: ArrayList<PollCreateOptionItem> = ArrayList()
@ -34,7 +36,7 @@ class PollCreateOptionsAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PollCreateOptionViewHolder {
val itemBinding = PollCreateOptionsItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return PollCreateOptionViewHolder(itemBinding)
return PollCreateOptionViewHolder(itemBinding, viewThemeUtils)
}
override fun onBindViewHolder(holder: PollCreateOptionViewHolder, position: Int) {

View file

@ -89,7 +89,7 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
binding.pollCreateOptionsList.layoutManager = LinearLayoutManager(context)
adapter = PollCreateOptionsAdapter(this)
adapter = PollCreateOptionsAdapter(this, viewThemeUtils)
binding.pollCreateOptionsList.adapter = adapter
themeDialog()
@ -103,6 +103,8 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
viewThemeUtils.colorTextViewText(binding.pollOptions)
viewThemeUtils.colorTextViewText(binding.pollSettings)
viewThemeUtils.colorEditText(binding.pollCreateQuestion)
viewThemeUtils.colorMaterialButtonText(binding.pollAddOptionsItem)
// TODO button also needs a disabled state handling for colors
viewThemeUtils.colorMaterialButtonText(binding.pollDismiss)

View file

@ -25,9 +25,11 @@ import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.view.View
import android.widget.CheckBox
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
@ -211,6 +213,24 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme) {
}
}
fun colorEditText(editText: EditText) {
withElementColor(editText) { color ->
editText.setTextColor(color)
// TODO check API-level compatibility
//editText.background.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
editText.backgroundTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_focused),
intArrayOf(android.R.attr.state_focused)
),
intArrayOf(
Color.GRAY,
color
)
)
}
}
fun colorTextInputLayout(textInputLayout: TextInputLayout) {
withElementColor(textInputLayout) { color ->
// TODO calculate error color based on primary color, dark/light aware