Utilize TextWatcher KTX extensions
This commit is contained in:
parent
eac16c64e4
commit
3a84650cd1
4 changed files with 28 additions and 58 deletions
|
@ -22,12 +22,11 @@ import android.graphics.Color
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.transition.Slide
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.databinding.ActivityAlbumTagEditorBinding
|
||||
|
@ -50,7 +49,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
|
|||
import org.jaudiotagger.tag.FieldKey
|
||||
import java.util.*
|
||||
|
||||
class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBinding>(), TextWatcher {
|
||||
class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBinding>() {
|
||||
|
||||
override val bindingInflater: (LayoutInflater) -> ActivityAlbumTagEditorBinding =
|
||||
ActivityAlbumTagEditorBinding::inflate
|
||||
|
@ -91,10 +90,10 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
|
|||
binding.albumTitleContainer.setTint(false)
|
||||
binding.albumArtistContainer.setTint(false)
|
||||
|
||||
binding.albumText.appHandleColor().addTextChangedListener(this)
|
||||
binding.albumArtistText.appHandleColor().addTextChangedListener(this)
|
||||
binding.genreTitle.appHandleColor().addTextChangedListener(this)
|
||||
binding.yearTitle.appHandleColor().addTextChangedListener(this)
|
||||
binding.albumText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.albumArtistText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.genreTitle.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.yearTitle.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
}
|
||||
|
||||
private fun fillViewsWithFileTags() {
|
||||
|
@ -198,17 +197,6 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
|
|||
MusicUtil.getSongFileUri(it.id)
|
||||
}
|
||||
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
dataChanged()
|
||||
}
|
||||
|
||||
override fun setColors(color: Int) {
|
||||
super.setColors(color)
|
||||
saveFab.backgroundTintList = ColorStateList.valueOf(color)
|
||||
|
|
|
@ -23,11 +23,10 @@ import android.graphics.Color
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.databinding.ActivitySongTagEditorBinding
|
||||
|
@ -50,7 +49,7 @@ import org.jaudiotagger.tag.FieldKey
|
|||
import org.koin.android.ext.android.inject
|
||||
import java.util.*
|
||||
|
||||
class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>(), TextWatcher {
|
||||
class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>() {
|
||||
|
||||
override val bindingInflater: (LayoutInflater) -> ActivitySongTagEditorBinding =
|
||||
ActivitySongTagEditorBinding::inflate
|
||||
|
@ -83,16 +82,16 @@ class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>
|
|||
binding.discNumberContainer.setTint(false)
|
||||
binding.lyricsContainer.setTint(false)
|
||||
|
||||
binding.songText.appHandleColor().addTextChangedListener(this)
|
||||
binding.albumText.appHandleColor().addTextChangedListener(this)
|
||||
binding.albumArtistText.appHandleColor().addTextChangedListener(this)
|
||||
binding.artistText.appHandleColor().addTextChangedListener(this)
|
||||
binding.genreText.appHandleColor().addTextChangedListener(this)
|
||||
binding.yearText.appHandleColor().addTextChangedListener(this)
|
||||
binding.trackNumberText.appHandleColor().addTextChangedListener(this)
|
||||
binding.discNumberText.appHandleColor().addTextChangedListener(this)
|
||||
binding.lyricsText.appHandleColor().addTextChangedListener(this)
|
||||
binding.songComposerText.appHandleColor().addTextChangedListener(this)
|
||||
binding.songText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.albumText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.albumArtistText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.artistText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.genreText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.yearText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.trackNumberText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.discNumberText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.lyricsText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
binding.songComposerText.appHandleColor().doAfterTextChanged { dataChanged() }
|
||||
}
|
||||
|
||||
private fun fillViewsWithFileTags() {
|
||||
|
@ -205,16 +204,6 @@ class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>
|
|||
})
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
dataChanged()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = SongTagEditorActivity::class.java.simpleName
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -303,9 +304,9 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
|
|||
|
||||
private fun hideVolumeIfAvailable() {
|
||||
if (PreferenceUtil.isVolumeVisibilityMode) {
|
||||
childFragmentManager.beginTransaction()
|
||||
.replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance())
|
||||
.commit()
|
||||
childFragmentManager.commit {
|
||||
replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance())
|
||||
}
|
||||
childFragmentManager.executePendingTransactions()
|
||||
volumeFragment =
|
||||
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as VolumeFragment?
|
||||
|
|
|
@ -20,13 +20,12 @@ import android.content.Intent
|
|||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.speech.RecognizerIntent
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.view.*
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.TransitionManager
|
||||
|
@ -51,7 +50,7 @@ import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEvent
|
|||
import java.util.*
|
||||
|
||||
|
||||
class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWatcher,
|
||||
class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search),
|
||||
ChipGroup.OnCheckedStateChangeListener {
|
||||
companion object {
|
||||
const val QUERY = "query"
|
||||
|
@ -81,7 +80,10 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
|
|||
searchAdapter.swapDataSet(listOf())
|
||||
}
|
||||
binding.searchView.apply {
|
||||
addTextChangedListener(this@SearchFragment)
|
||||
doAfterTextChanged {
|
||||
if (!it.isNullOrEmpty())
|
||||
search(it.toString())
|
||||
}
|
||||
focusAndShowKeyboard()
|
||||
}
|
||||
binding.keyboardPopup.apply {
|
||||
|
@ -171,16 +173,6 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
|
|||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(newText: Editable?) {
|
||||
if (!newText.isNullOrEmpty()) search(newText.toString())
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
}
|
||||
|
||||
private fun search(query: String) {
|
||||
this.query = query
|
||||
TransitionManager.beginDelayedTransition(binding.appBarLayout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue