61 lines
2.1 KiB
Kotlin
61 lines
2.1 KiB
Kotlin
package com.example.defenseapplication.liveVideo
|
|
|
|
import android.os.Bundle
|
|
import android.widget.Toast
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.example.defenseapplication.R
|
|
import com.example.defenseapplication.adapter.AddLinkedUserAdapter
|
|
import com.example.defenseapplication.adapter.UserItem
|
|
import com.example.defenseapplication.databinding.AddLinkedUserActivityBinding
|
|
import com.gyf.immersionbar.ImmersionBar
|
|
//添加关联用户
|
|
class AddLinkedUserActivity : AppCompatActivity() {
|
|
private lateinit var binding: AddLinkedUserActivityBinding
|
|
private val selectedPhoneSet = mutableSetOf<String>()
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
binding = AddLinkedUserActivityBinding.inflate(layoutInflater)
|
|
setContentView(binding.root)
|
|
|
|
ImmersionBar.with(this)
|
|
.statusBarDarkFont(true)
|
|
.titleBar(binding.topBar)
|
|
.init()
|
|
|
|
initRecyclerView()
|
|
initListener()
|
|
}
|
|
|
|
private fun initRecyclerView() {
|
|
val mockData = listOf(
|
|
UserItem("王五", "13566666666"),
|
|
UserItem("赵六", "15733333333")
|
|
)
|
|
|
|
binding.rvAddLinkedUser.layoutManager = LinearLayoutManager(this)
|
|
binding.rvAddLinkedUser.adapter =
|
|
AddLinkedUserAdapter(mockData, selectedPhoneSet) { phone, isChecked ->
|
|
if (isChecked) {
|
|
selectedPhoneSet.add(phone)
|
|
} else {
|
|
selectedPhoneSet.remove(phone)
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun initListener() {
|
|
binding.btnAddLinkedUser.setOnClickListener {
|
|
if (selectedPhoneSet.isEmpty()) {
|
|
Toast.makeText(this, getString(R.string.please_select_at_least_one_user), Toast.LENGTH_SHORT).show()
|
|
} else {
|
|
val message = getString(R.string.selected_users_voice, selectedPhoneSet.size)
|
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
|
}
|
|
}
|
|
binding.ivBack.setOnClickListener {
|
|
finish()
|
|
}
|
|
}
|
|
} |