refactor PlayFragment.kt
1 parent c510921 commit 357d28972a5a557338c19de0b8ce3da6f984ac03
@lukas lukas authored on 18 Aug 2022
Showing 1 changed file
View
91
app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
setupSlider(binding.tempoSlider, 50, 150, 90) {
Rhythm.setTempo(it)
binding.tempoText.text = "tempo: ${it}bpm"
}
setupBeatIndicator()
Song.currentSong.stepCallback += {
Handler(Looper.getMainLooper()).post {
beatIndicators[Song.currentSong.indexBehind].isChecked = false
beatIndicators[Song.currentSong.index].isChecked = true
}
}
Song.currentSong.chordProgression.stepCallback += {
Handler(Looper.getMainLooper()).post { putChords() }
}
Song.currentSong.chordProgression.miniStepCallback += {
Handler(Looper.getMainLooper()).post { updateChordView() }
}
return binding.root
}
 
private fun setupBeatIndicator() {
val layout = RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.MATCH_PARENT
)
}
beatIndicators += child
binding.beatIndicator.addView(child)
}
Song.currentSong.stepCallback += {
Handler(Looper.getMainLooper()).post {
beatIndicators[Song.currentSong.indexBehind].isChecked = false
beatIndicators[Song.currentSong.index].isChecked = true
}
}
 
private fun updateChordView() {
if (chordDisplays.isEmpty()) {
putChords()
}
Song.currentSong.chordProgression.stepCallback += {
Handler(Looper.getMainLooper()).post {
putChords()
}
chordDisplays[Song.currentSong.chordProgression.currentItem.index].setBackgroundColor(
ContextCompat.getColor(
binding.root.context,
R.color.gray_400
)
)
if (Song.currentSong.chordProgression.currentItem.index == 0) {
return
}
Song.currentSong.chordProgression.miniStepCallback += {
Handler(Looper.getMainLooper()).post {
if (chordDisplays.isEmpty()) {
putChords()
}
chordDisplays[Song.currentSong.chordProgression.currentItem.index].setBackgroundColor(
ContextCompat.getColor(
binding.root.context,
R.color.gray_400
)
)
if (Song.currentSong.chordProgression.currentItem.index == 0) {
return@post
}
chordDisplays[Song.currentSong.chordProgression.currentItem.indexBehind].setBackgroundColor(
ContextCompat.getColor(
binding.root.context,
R.color.gray_600
)
)
}
}
return binding.root
chordDisplays[Song.currentSong.chordProgression.currentItem.indexBehind].setBackgroundColor(
ContextCompat.getColor(
binding.root.context,
R.color.gray_600
)
)
}
 
private fun setupSlider(
slider: SeekBar,
}
binding.phraseTable.isStretchAllColumns = true
}
 
external fun setMasterVolume(volume: Double)
private external fun setMasterVolume(volume: Double)
}