}
binding.nextButton.setOnClickListener {

|
}
binding.nextButton.setOnClickListener {
|
bet | 6/12 | Sana | 17.12.2023 | Hajmi | 1,09 Mb. | | #121185 |
Bog'liq Matkarimov Sardor kurs ishi}
binding.nextButton.setOnClickListener {
binding.backButton.visibility = View.VISIBLE
if (index < texts.size) setData(texts[++index])
if (index == texts.size - 1) it.visibility = View.INVISIBLE
}
binding.backButton.setOnClickListener {
binding.nextButton.visibility = View.VISIBLE
if (index > 0) setData(texts[--index])
if (index == 0) it.visibility = View.INVISIBLE
}
}
private fun setData(text: String) {
binding.chipGroup.removeAllViews()
val words = text.split(" ")
trues = mutableListOf()
words.forEach {
trues.add(false)
val wordView = layoutInflater.inflate(R.layout.item_word, null)
val wordBinding = ItemWordBinding.bind(wordView)
wordBinding.wordView.text = it
wordView.setOnClickListener { currentWord ->
binding.chipGroup.forEach { word -> word.isSelected = false }
selectedView = ItemWordBinding.bind(currentWord)
selectedWord = selectedView?.wordView?.text.toString()
currentWord.isSelected = true
}
binding.chipGroup.addView(wordView)
}
}
private fun getWordType(word: String?): WordLineType {
return when (word?.lowercase(Locale.ROOT)) {
"men" -> WordLineType.ONE_LINE
"maktabda", "boraman" -> WordLineType.TWO_LINE
"o'qiyman", "testtesttesttesttesttesttesttesttest" -> WordLineType.WAVE_LINE
"maktabga" -> WordLineType.DASHED_LINE
else -> {
WordLineType.SPOT_LINE
}
}
}
private fun drawLine(wordBinding: ItemWordBinding?, wordLineType: WordLineType) {
wordBinding?.firstLineView?.visibility = View.GONE
wordBinding?.secondLineView?.visibility = View.GONE
wordBinding?.recyclerView?.visibility = View.GONE
when (wordLineType) {
WordLineType.ONE_LINE -> {
wordBinding?.firstLineView?.visibility = View.VISIBLE
wordBinding?.firstLineView?.background =
resources.getDrawable(R.drawable.shape_line)
}
WordLineType.TWO_LINE -> {
wordBinding?.firstLineView?.visibility = View.VISIBLE
wordBinding?.secondLineView?.visibility = View.VISIBLE
wordBinding?.firstLineView?.background =
resources.getDrawable(R.drawable.shape_line)
wordBinding?.secondLineView?.background =
resources.getDrawable(R.drawable.shape_line)
}
WordLineType.DASHED_LINE -> {
wordBinding?.firstLineView?.visibility = View.VISIBLE
wordBinding?.firstLineView?.background =
resources.getDrawable(R.drawable.shape_dashed_line)
}
WordLineType.WAVE_LINE -> {
wordBinding?.recyclerView?.visibility = View.VISIBLE
val waveLineAdapter = SimpleAdapter(R.layout.item_wave_line)
wordBinding?.recyclerView?.apply {
layoutManager = LinearLayoutManager(
this@GrammarActivity,
RecyclerView.HORIZONTAL,
false
)
adapter = waveLineAdapter
}
waveLineAdapter.onItemBind = { _, view ->
val itemBinding = ItemWaveLineBinding.bind(view)
itemBinding.lineView.background =
resources.getDrawable(R.drawable.ic_wave_line)
}
waveLineAdapter.setData(listOf(0, 0, 0, 0, 0))
}
else -> {
wordBinding?.firstLineView?.visibility = View.VISIBLE
wordBinding?.firstLineView?.background =
resources.getDrawable(R.drawable.shape_spot_line)
}
}
}
}
SettingsActivity.kt klass fayli kodi:
package com.example.mygrammar
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.mygrammar.databinding.ActivitySettingsBinding
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
}
}
SimpleAdapter.kt
Adapter klassimiz fayli kodi:
package com.example.mygrammar
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.recyclerview.widget.RecyclerView
open class SimpleAdapter(private val itemLayout: Int) : RecyclerView.Adapter>() {
var onItemBind: ((T, View) -> Unit)? = null
private var items: List = listOf()
fun setData(items: List) {
this.items = items
notifyDataSetChanged()
}
override fun getItemCount(): Int = items.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(parent.inflateView(itemLayout))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(items[position], onItemBind)
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: C, onItemBind: ((C, View) -> Unit)?) {
onItemBind?.invoke(item, itemView)
}
}
private fun ViewGroup.inflateView(@LayoutRes layout: Int): View {
return LayoutInflater.from(context).inflate(layout, this, false)
}
}
WordLineType.kt
So’zlarning turkumlari uchun enum klass fayli kodi:
package com.example.mygrammar
enum class WordLineType {
NO_LINE, ONE_LINE, TWO_LINE, DASHED_LINE, WAVE_LINE, SPOT_LINE
}
|
| |