fix: 修复搜索添加好友跳转出错问题
This commit is contained in:
parent
00e34df0fb
commit
910d26c0f4
@ -11,6 +11,9 @@ class ApplyAddFriendActivity : BaseActivity<ActivityApplyAddFriendBinding>() {
|
|||||||
|
|
||||||
private val contactViewModel: ContactViewModel by viewModels()
|
private val contactViewModel: ContactViewModel by viewModels()
|
||||||
|
|
||||||
|
private lateinit var contactId: String
|
||||||
|
private lateinit var contactNickname: String
|
||||||
|
|
||||||
override fun inflateBinding(): ActivityApplyAddFriendBinding =
|
override fun inflateBinding(): ActivityApplyAddFriendBinding =
|
||||||
ActivityApplyAddFriendBinding.inflate(layoutInflater)
|
ActivityApplyAddFriendBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
@ -18,16 +21,19 @@ class ApplyAddFriendActivity : BaseActivity<ActivityApplyAddFriendBinding>() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
setListener()
|
||||||
|
}
|
||||||
|
|
||||||
val contactId = intent.getStringExtra("contactId")
|
private fun setListener() {
|
||||||
|
|
||||||
binding.tvSendApply.setOnClickListener {
|
binding.tvSendApply.setOnClickListener {
|
||||||
sendContactRequest(contactId)
|
sendContactRequest(contactId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initData() {
|
override fun initData() {
|
||||||
|
contactId = intent.getStringExtra("contactId") ?: ""
|
||||||
|
contactNickname = intent.getStringExtra("contactNickname") ?: ""
|
||||||
|
binding.etRemark.setHint(contactNickname)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendContactRequest(contactId: String?) {
|
private fun sendContactRequest(contactId: String?) {
|
||||||
|
@ -45,11 +45,13 @@ class ApplyFriendsDetailActivity : BaseActivity<ActivityApplyFriendsDetailBindin
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setOnClick() {
|
private fun setOnClick() {
|
||||||
binding.rlSendMessage.setOnClickListener {
|
binding.tvAddContact.setOnClickListener {
|
||||||
val contactId = user?.username
|
val contactId = user?.username
|
||||||
contactId?.let {
|
contactId?.let {
|
||||||
val intent = Intent(this, ApplyAddFriendActivity::class.java)
|
val intent = Intent(this, ApplyAddFriendActivity::class.java).apply {
|
||||||
intent.putExtra("contactId", it)
|
putExtra("contactId", it)
|
||||||
|
putExtra("contactNickname", user?.nickname)
|
||||||
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,14 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import com.kaixed.kchat.data.local.box.ObjectBox.getBoxStore
|
import com.kaixed.kchat.data.DataBase
|
||||||
import com.kaixed.kchat.data.local.entity.Contact
|
import com.kaixed.kchat.data.local.entity.Contact
|
||||||
import com.kaixed.kchat.data.local.entity.Contact_
|
import com.kaixed.kchat.data.local.entity.Contact_
|
||||||
import com.kaixed.kchat.databinding.ActivityContactsDetailBinding
|
import com.kaixed.kchat.databinding.ActivityContactsDetailBinding
|
||||||
import com.kaixed.kchat.ui.base.BaseActivity
|
import com.kaixed.kchat.ui.base.BaseActivity
|
||||||
import io.objectbox.Box
|
|
||||||
|
|
||||||
class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
|
class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
|
||||||
|
|
||||||
private val contactBox: Box<Contact> by lazy { getBoxStore().boxFor(Contact::class.java) }
|
|
||||||
|
|
||||||
private var contactId: String? = null
|
private var contactId: String? = null
|
||||||
|
|
||||||
private var contactNickname: String? = null
|
private var contactNickname: String? = null
|
||||||
@ -94,7 +91,7 @@ class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getContactInfo(contactId: String): Contact {
|
private fun getContactInfo(contactId: String): Contact {
|
||||||
return contactBox
|
return DataBase.contactBox
|
||||||
.query(Contact_.username.equal(contactId))
|
.query(Contact_.username.equal(contactId))
|
||||||
.build()
|
.build()
|
||||||
.findFirst()!!
|
.findFirst()!!
|
||||||
|
@ -38,10 +38,56 @@ class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() {
|
|||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
initView()
|
initView()
|
||||||
|
|
||||||
setObserver()
|
setObserver()
|
||||||
|
setOnListener()
|
||||||
|
}
|
||||||
|
|
||||||
setOnClick()
|
private fun setOnListener() {
|
||||||
|
binding.etSearch.postDelayed({
|
||||||
|
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
imm.showSoftInput(binding.etSearch, InputMethodManager.SHOW_IMPLICIT)
|
||||||
|
}, 200)
|
||||||
|
|
||||||
|
binding.clSearchUser.setOnClickListener {
|
||||||
|
loadingDialog = LoadingDialogFragment.newInstance("正在搜索中...")
|
||||||
|
loadingDialog.showLoading(supportFragmentManager)
|
||||||
|
|
||||||
|
val username = binding.etSearch.text.toString()
|
||||||
|
searchUser(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.tvCancel.setOnClickListener {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
binding.clFriends.setOnClickListener {
|
||||||
|
val intent = Intent(this, ApplyFriendsDetailActivity::class.java).apply {
|
||||||
|
putExtra("user", userItem)
|
||||||
|
}
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.etSearch.requestFocus()
|
||||||
|
binding.etSearch.addTextChangedListener(afterTextChanged = {
|
||||||
|
it?.let {
|
||||||
|
binding.tvNothing.visibility = View.INVISIBLE
|
||||||
|
if (it.isEmpty()) {
|
||||||
|
binding.clFriends.visibility = View.INVISIBLE
|
||||||
|
binding.clSearchUser.visibility = View.INVISIBLE
|
||||||
|
} else {
|
||||||
|
binding.clSearchUser.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
val spannableString = SpannableString("搜索:$it")
|
||||||
|
val colorSpan = ForegroundColorSpan(Color.parseColor("#2BA245"))
|
||||||
|
|
||||||
|
spannableString.setSpan(
|
||||||
|
colorSpan, 3, it.length + 3,
|
||||||
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||||
|
)
|
||||||
|
binding.tvSearchContent.text = spannableString
|
||||||
|
}
|
||||||
|
isSearching = it.isNotEmpty()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setObserver() {
|
private fun setObserver() {
|
||||||
@ -73,61 +119,9 @@ class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() {
|
|||||||
override fun initData() {
|
override fun initData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setOnClick() {
|
|
||||||
binding.clFriends.setOnClickListener {
|
|
||||||
Intent(this, ApplyFriendsDetailActivity::class.java).apply {
|
|
||||||
putExtra("user", userItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
binding.clFriends.visibility = View.INVISIBLE
|
binding.clFriends.visibility = View.INVISIBLE
|
||||||
binding.tvTitle.visibility = View.INVISIBLE
|
binding.tvTitle.visibility = View.INVISIBLE
|
||||||
|
|
||||||
binding.etSearch.requestFocus()
|
|
||||||
binding.etSearch.addTextChangedListener(afterTextChanged = {
|
|
||||||
it?.let {
|
|
||||||
binding.tvNothing.visibility = View.INVISIBLE
|
|
||||||
if (it.isEmpty()) {
|
|
||||||
binding.clFriends.visibility = View.INVISIBLE
|
|
||||||
binding.clSearchUser.visibility = View.INVISIBLE
|
|
||||||
} else {
|
|
||||||
binding.clSearchUser.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
val spannableString = SpannableString("搜索:$it")
|
|
||||||
val colorSpan = ForegroundColorSpan(Color.parseColor("#2BA245"))
|
|
||||||
|
|
||||||
spannableString.setSpan(
|
|
||||||
colorSpan,
|
|
||||||
3,
|
|
||||||
it.length + 3,
|
|
||||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
||||||
)
|
|
||||||
binding.tvSearchContent.text = spannableString
|
|
||||||
}
|
|
||||||
isSearching = it.isNotEmpty()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
binding.etSearch.postDelayed({
|
|
||||||
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
|
||||||
imm.showSoftInput(binding.etSearch, InputMethodManager.SHOW_IMPLICIT)
|
|
||||||
}, 200)
|
|
||||||
|
|
||||||
binding.clSearchUser.setOnClickListener {
|
|
||||||
loadingDialog = LoadingDialogFragment.newInstance("正在搜索中...")
|
|
||||||
loadingDialog.showLoading(supportFragmentManager)
|
|
||||||
|
|
||||||
val username = binding.etSearch.text.toString()
|
|
||||||
searchUser(username)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.tvCancel.setOnClickListener {
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchUser(username: String) {
|
private fun searchUser(username: String) {
|
||||||
|
@ -69,11 +69,13 @@
|
|||||||
app:cardMaxElevation="0dp">
|
app:cardMaxElevation="0dp">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
android:id="@+id/et_remark"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#F7F7F7"
|
android:background="#F7F7F7"
|
||||||
android:hint="hh"
|
android:paddingHorizontal="12dp"
|
||||||
android:paddingHorizontal="12dp" />
|
android:textCursorDrawable="@drawable/cursor"
|
||||||
|
android:textSize="15sp" />
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,24 +178,18 @@
|
|||||||
android:layout_height="8dp"
|
android:layout_height="8dp"
|
||||||
android:background="#E5E5E5" />
|
android:background="#E5E5E5" />
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/rl_send_message"
|
<TextView
|
||||||
|
android:id="@+id/tv_add_contact"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:paddingStart="15dp"
|
android:background="@color/white"
|
||||||
tools:ignore="RtlSymmetry">
|
android:gravity="center"
|
||||||
|
android:text="添加到通讯录"
|
||||||
|
android:textColor="@color/normal"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:text="添加到通讯录"
|
|
||||||
android:textColor="@color/normal"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user