diff --git a/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyAddFriendActivity.kt b/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyAddFriendActivity.kt index 7e85ceb..086da38 100644 --- a/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyAddFriendActivity.kt +++ b/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyAddFriendActivity.kt @@ -11,6 +11,9 @@ class ApplyAddFriendActivity : BaseActivity() { private val contactViewModel: ContactViewModel by viewModels() + private lateinit var contactId: String + private lateinit var contactNickname: String + override fun inflateBinding(): ActivityApplyAddFriendBinding = ActivityApplyAddFriendBinding.inflate(layoutInflater) @@ -18,16 +21,19 @@ class ApplyAddFriendActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() + setListener() + } - val contactId = intent.getStringExtra("contactId") - + private fun setListener() { binding.tvSendApply.setOnClickListener { sendContactRequest(contactId) } } override fun initData() { - + contactId = intent.getStringExtra("contactId") ?: "" + contactNickname = intent.getStringExtra("contactNickname") ?: "" + binding.etRemark.setHint(contactNickname) } private fun sendContactRequest(contactId: String?) { diff --git a/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyFriendsDetailActivity.kt b/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyFriendsDetailActivity.kt index de521d6..8a94650 100644 --- a/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyFriendsDetailActivity.kt +++ b/app/src/main/java/com/kaixed/kchat/ui/activity/ApplyFriendsDetailActivity.kt @@ -45,11 +45,13 @@ class ApplyFriendsDetailActivity : BaseActivity() { - private val contactBox: Box by lazy { getBoxStore().boxFor(Contact::class.java) } - private var contactId: String? = null private var contactNickname: String? = null @@ -94,7 +91,7 @@ class ContactsDetailActivity : BaseActivity() { } private fun getContactInfo(contactId: String): Contact { - return contactBox + return DataBase.contactBox .query(Contact_.username.equal(contactId)) .build() .findFirst()!! diff --git a/app/src/main/java/com/kaixed/kchat/ui/activity/SearchFriendsActivity.kt b/app/src/main/java/com/kaixed/kchat/ui/activity/SearchFriendsActivity.kt index c3c6340..6b51c62 100644 --- a/app/src/main/java/com/kaixed/kchat/ui/activity/SearchFriendsActivity.kt +++ b/app/src/main/java/com/kaixed/kchat/ui/activity/SearchFriendsActivity.kt @@ -38,10 +38,56 @@ class SearchFriendsActivity : BaseActivity() { enableEdgeToEdge() initView() - 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() { @@ -73,61 +119,9 @@ class SearchFriendsActivity : BaseActivity() { override fun initData() { } - private fun setOnClick() { - binding.clFriends.setOnClickListener { - Intent(this, ApplyFriendsDetailActivity::class.java).apply { - putExtra("user", userItem) - } - - startActivity(intent) - } - } - private fun initView() { binding.clFriends.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) { diff --git a/app/src/main/res/layout/activity_apply_add_friend.xml b/app/src/main/res/layout/activity_apply_add_friend.xml index e60fa34..b647943 100644 --- a/app/src/main/res/layout/activity_apply_add_friend.xml +++ b/app/src/main/res/layout/activity_apply_add_friend.xml @@ -69,11 +69,13 @@ app:cardMaxElevation="0dp"> + android:paddingHorizontal="12dp" + android:textCursorDrawable="@drawable/cursor" + android:textSize="15sp" /> diff --git a/app/src/main/res/layout/activity_apply_friends_detail.xml b/app/src/main/res/layout/activity_apply_friends_detail.xml index d077a80..d333000 100644 --- a/app/src/main/res/layout/activity_apply_friends_detail.xml +++ b/app/src/main/res/layout/activity_apply_friends_detail.xml @@ -178,24 +178,18 @@ android:layout_height="8dp" android:background="#E5E5E5" /> - + android:background="@color/white" + android:gravity="center" + android:text="添加到通讯录" + android:textColor="@color/normal" + android:textSize="16sp" + android:textStyle="bold" /> - - - -