Use view binding in chat activity
This commit is contained in:
@ -13,19 +13,21 @@ import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.*
|
||||
import com.tutpro.baresip.databinding.ActivityChatBinding
|
||||
|
||||
class ChatActivity : AppCompatActivity() {
|
||||
|
||||
internal lateinit var chatMessages: ArrayList<Message>
|
||||
internal lateinit var mlAdapter: MessageListAdapter
|
||||
internal lateinit var listView: ListView
|
||||
internal lateinit var newMessage: EditText
|
||||
internal lateinit var sendButton: ImageButton
|
||||
internal lateinit var imm: InputMethodManager
|
||||
internal lateinit var aor: String
|
||||
internal lateinit var peerUri: String
|
||||
internal lateinit var ua: UserAgent
|
||||
internal lateinit var messageResponseReceiver: BroadcastReceiver
|
||||
private lateinit var binding: ActivityChatBinding
|
||||
private lateinit var chatMessages: ArrayList<Message>
|
||||
private lateinit var mlAdapter: MessageListAdapter
|
||||
private lateinit var listView: ListView
|
||||
private lateinit var newMessage: EditText
|
||||
private lateinit var sendButton: ImageButton
|
||||
private lateinit var imm: InputMethodManager
|
||||
private lateinit var aor: String
|
||||
private lateinit var peerUri: String
|
||||
private lateinit var ua: UserAgent
|
||||
private lateinit var messageResponseReceiver: BroadcastReceiver
|
||||
|
||||
private var focus = false
|
||||
private var lastCall: Long = 0
|
||||
@ -33,7 +35,8 @@ class ChatActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_chat)
|
||||
binding = ActivityChatBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
@ -67,11 +70,11 @@ class ChatActivity : AppCompatActivity() {
|
||||
|
||||
title = String.format(getString(R.string.chat_with), chatPeer)
|
||||
|
||||
val headerView = findViewById(R.id.account) as TextView
|
||||
val headerView = binding.account
|
||||
val headerText = "${getString(R.string.account)} ${aor.substringAfter(":")}"
|
||||
headerView.text = headerText
|
||||
|
||||
listView = findViewById(R.id.messages) as ListView
|
||||
listView = binding.messages
|
||||
chatMessages = uaPeerMessages(aor, peerUri)
|
||||
mlAdapter = MessageListAdapter(this, chatMessages)
|
||||
listView.adapter = mlAdapter
|
||||
@ -124,7 +127,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
|
||||
newMessage = findViewById(R.id.text) as EditText
|
||||
newMessage = binding.text
|
||||
newMessage.setOnFocusChangeListener(View.OnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
@ -133,7 +136,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
|
||||
if (focus) newMessage.requestFocus()
|
||||
|
||||
sendButton = findViewById(R.id.sendButton) as ImageButton
|
||||
sendButton = binding.sendButton
|
||||
sendButton.setOnClickListener {
|
||||
val msgText = newMessage.text.toString()
|
||||
if (msgText.length > 0) {
|
||||
|
||||
@ -9,11 +9,13 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import com.tutpro.baresip.databinding.ActivityChatsBinding
|
||||
|
||||
import java.util.*
|
||||
|
||||
class ChatsActivity: AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityChatsBinding
|
||||
internal lateinit var uaMessages: ArrayList<Message>
|
||||
internal lateinit var listView: ListView
|
||||
internal lateinit var clAdapter: ChatListAdapter
|
||||
@ -24,15 +26,16 @@ class ChatsActivity: AppCompatActivity() {
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_chats)
|
||||
binding = ActivityChatsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
listView = findViewById(R.id.chats) as ListView
|
||||
plusButton = findViewById(R.id.plusButton) as ImageButton
|
||||
listView = binding.chats
|
||||
plusButton = binding.plusButton
|
||||
|
||||
aor = intent.extras!!.getString("aor")!!
|
||||
Utils.addActivity("chats,$aor")
|
||||
|
||||
val headerView = findViewById(R.id.account) as TextView
|
||||
val headerView = binding.account
|
||||
val headerText = "${getString(R.string.account)} ${aor.split(":")[1]}"
|
||||
headerView.text = headerText
|
||||
|
||||
@ -100,7 +103,7 @@ class ChatsActivity: AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
|
||||
peerUri = findViewById(R.id.peer) as AutoCompleteTextView
|
||||
peerUri = binding.peer
|
||||
peerUri.threshold = 2
|
||||
peerUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
Contact.contacts().map{Contact -> Contact.name}))
|
||||
|
||||
Reference in New Issue
Block a user