Use TextView.doOnTextChanged() extension.

This commit is contained in:
Isira Seneviratne 2020-10-17 17:31:50 +05:30
parent 293e2ff5e3
commit 03d99887c5
1 changed files with 10 additions and 20 deletions

View File

@ -3,9 +3,7 @@ package org.schabi.newpipe.local.subscription.dialog
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.text.Editable
import android.text.TextUtils import android.text.TextUtils
import android.text.TextWatcher
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -15,6 +13,7 @@ import androidx.core.content.getSystemService
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
@ -194,16 +193,11 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
} }
group_name_input_container.error = null group_name_input_container.error = null
group_name_input.addTextChangedListener(object : TextWatcher { group_name_input.doOnTextChanged { text, _, _, _ ->
override fun afterTextChanged(s: Editable?) {} if (group_name_input_container.isErrorEnabled && !text.isNullOrBlank()) {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (group_name_input_container.isErrorEnabled && !s.isNullOrBlank()) {
group_name_input_container.error = null group_name_input_container.error = null
} }
} }
})
confirm_button.setOnClickListener { handlePositiveButton() } confirm_button.setOnClickListener { handlePositiveButton() }
@ -245,15 +239,11 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
} }
} }
toolbar_search_edit_text.addTextChangedListener(object : TextWatcher { toolbar_search_edit_text.doOnTextChanged { _, _, _, _ ->
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit
override fun afterTextChanged(s: Editable) = Unit
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
val newQuery: String = toolbar_search_edit_text.text.toString() val newQuery: String = toolbar_search_edit_text.text.toString()
subscriptionsCurrentSearchQuery = newQuery subscriptionsCurrentSearchQuery = newQuery
viewModel.filterSubscriptionsBy(newQuery) viewModel.filterSubscriptionsBy(newQuery)
} }
})
subscriptionGroupAdapter.setOnItemClickListener(subscriptionPickerItemListener) subscriptionGroupAdapter.setOnItemClickListener(subscriptionPickerItemListener)
} }