From 6297f02054b8b2047becf2ce0d561cebcd360113 Mon Sep 17 00:00:00 2001 From: kaixed Date: Sun, 29 Dec 2024 10:54:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=95=B0=E6=8D=AE=E6=9C=AA=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kaixed/kchat/data/DataBase.kt | 7 +++ .../ui/activity/ContactsDetailActivity.kt | 23 +++++++++- .../ui/activity/SearchFriendsActivity.kt | 25 ++++++++--- .../kaixed/kchat/ui/fragment/HomeFragment.kt | 3 -- .../kchat/ui/widget/MyBottomSheetFragment.kt | 31 ++++--------- .../com/kaixed/kchat/utils/ConstantsUtil.kt | 2 +- .../res/layout/activity_contacts_detail.xml | 44 ++++++------------- app/src/main/res/layout/fragment_home.xml | 37 ++++------------ 8 files changed, 79 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/com/kaixed/kchat/data/DataBase.kt b/app/src/main/java/com/kaixed/kchat/data/DataBase.kt index 581a2cf..41830b4 100644 --- a/app/src/main/java/com/kaixed/kchat/data/DataBase.kt +++ b/app/src/main/java/com/kaixed/kchat/data/DataBase.kt @@ -20,4 +20,11 @@ object DataBase { val conversationBox: Box by lazy { getBoxStore().boxFor() } val userInfoBox: Box by lazy { getBoxStore().boxFor() } + + fun cleanAllData() { + contactBox.removeAll() + messagesBox.removeAll() + conversationBox.removeAll() + userInfoBox.removeAll() + } } \ No newline at end of file diff --git a/app/src/main/java/com/kaixed/kchat/ui/activity/ContactsDetailActivity.kt b/app/src/main/java/com/kaixed/kchat/ui/activity/ContactsDetailActivity.kt index 744574c..2fa7825 100644 --- a/app/src/main/java/com/kaixed/kchat/ui/activity/ContactsDetailActivity.kt +++ b/app/src/main/java/com/kaixed/kchat/ui/activity/ContactsDetailActivity.kt @@ -5,11 +5,15 @@ import android.content.Intent import android.os.Bundle import android.view.View import androidx.activity.enableEdgeToEdge +import com.bumptech.glide.Glide 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.databinding.ActivityContactsDetailBinding import com.kaixed.kchat.ui.base.BaseActivity +import com.kaixed.kchat.utils.ConstantsUtil.getAvatarUrl +import com.kaixed.kchat.utils.ConstantsUtil.getNickName +import com.kaixed.kchat.utils.ConstantsUtil.getUsername class ContactsDetailActivity : BaseActivity() { @@ -17,6 +21,8 @@ class ContactsDetailActivity : BaseActivity() { private var contactNickname: String? = null + private var isMine = false + companion object { private const val TAG = "ContactsDetailActivity" } @@ -37,10 +43,25 @@ class ContactsDetailActivity : BaseActivity() { override fun initData() { contactId = intent.getStringExtra("contactId") + isMine = intent.getBooleanExtra("isMine", false) } @SuppressLint("SetTextI18n") private fun updateContent() { + if (isMine) { + binding.tvContactId.text = "星联号: ${getUsername()}" + Glide.with(this) + .load(getAvatarUrl()) + .into(binding.ifvAvatar) + binding.tvRemark.text = getNickName() + binding.ciPermission.visibility = View.GONE + binding.ciMore.visibility = View.GONE + binding.tvVideoCall.visibility = View.GONE + binding.view.visibility = View.GONE + binding.ctb.ivSetting.visibility = View.GONE + binding.ciSetRemarkAndLabel.visibility = View.GONE + return + } val contact: Contact by lazy { getContactInfo(contactId!!) } @@ -63,7 +84,7 @@ class ContactsDetailActivity : BaseActivity() { } private fun setOnListener() { - binding.rlSendMessage.setOnClickListener { + binding.tvSendMessage.setOnClickListener { startActivity(Intent(this, ChatActivity::class.java).apply { putExtra("contactId", contactId) putExtra("contactNickname", contactId) 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 6b51c62..16e1c6c 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 @@ -17,6 +17,7 @@ import com.kaixed.kchat.data.model.search.SearchUser import com.kaixed.kchat.databinding.ActivitySearchFriendsBinding import com.kaixed.kchat.ui.base.BaseActivity import com.kaixed.kchat.ui.widget.LoadingDialogFragment +import com.kaixed.kchat.utils.ConstantsUtil.getUsername import com.kaixed.kchat.viewmodel.ContactViewModel class SearchFriendsActivity : BaseActivity() { @@ -27,12 +28,14 @@ class SearchFriendsActivity : BaseActivity() { private lateinit var loadingDialog: LoadingDialogFragment + private val contactViewModel: ContactViewModel by viewModels() + + private var isSearchedMine = false + override fun inflateBinding(): ActivitySearchFriendsBinding { return ActivitySearchFriendsBinding.inflate(layoutInflater) } - private val contactViewModel: ContactViewModel by viewModels() - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() @@ -60,9 +63,17 @@ class SearchFriendsActivity : BaseActivity() { finish() } binding.clFriends.setOnClickListener { - val intent = Intent(this, ApplyFriendsDetailActivity::class.java).apply { - putExtra("user", userItem) - } + val intent = + if (isSearchedMine) { + Intent(this, ContactsDetailActivity::class.java).apply { + putExtra("isMine", getUsername() == userItem.username) + putExtra("contactId", userItem.username) + } + } else { + Intent(this, ApplyFriendsDetailActivity::class.java).apply { + putExtra("user", userItem) + } + } startActivity(intent) } @@ -94,10 +105,12 @@ class SearchFriendsActivity : BaseActivity() { contactViewModel.searchContactResult.observe(this) { result -> result.onSuccess { it?.let { + isSearchedMine = it.username == getUsername() if (LocalDatabase.isMyFriend(it.username)) { + val username = it.username val intent = Intent(this, ContactsDetailActivity::class.java).apply { - putExtra("contactId", it.username) + putExtra("contactId", username) } startActivity(intent) } else { diff --git a/app/src/main/java/com/kaixed/kchat/ui/fragment/HomeFragment.kt b/app/src/main/java/com/kaixed/kchat/ui/fragment/HomeFragment.kt index f3d9138..8ffee77 100644 --- a/app/src/main/java/com/kaixed/kchat/ui/fragment/HomeFragment.kt +++ b/app/src/main/java/com/kaixed/kchat/ui/fragment/HomeFragment.kt @@ -129,9 +129,6 @@ class HomeFragment : BaseFragment(), OnItemListener, } private fun setOnClick() { - binding.ifvAvatar.setOnClickListener { - startActivity(Intent(context, TestActivity::class.java)) - } binding.ivSearch.setOnClickListener { val intent = Intent(context, SearchActivity::class.java) startActivity(intent) diff --git a/app/src/main/java/com/kaixed/kchat/ui/widget/MyBottomSheetFragment.kt b/app/src/main/java/com/kaixed/kchat/ui/widget/MyBottomSheetFragment.kt index ca5b19e..803b224 100644 --- a/app/src/main/java/com/kaixed/kchat/ui/widget/MyBottomSheetFragment.kt +++ b/app/src/main/java/com/kaixed/kchat/ui/widget/MyBottomSheetFragment.kt @@ -1,8 +1,6 @@ package com.kaixed.kchat.ui.widget -import android.app.Activity -import android.content.Context import android.content.Intent import android.os.Bundle import android.view.LayoutInflater @@ -10,15 +8,12 @@ import android.view.View import android.view.ViewGroup import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.kaixed.kchat.R -import com.kaixed.kchat.data.local.box.ObjectBox.getBoxStore -import com.kaixed.kchat.data.local.entity.Conversation -import com.kaixed.kchat.data.local.entity.Messages +import com.kaixed.kchat.data.DataBase import com.kaixed.kchat.databinding.BottomSheetLayoutBinding import com.kaixed.kchat.ui.activity.LoginActivity import com.kaixed.kchat.utils.Constants.MMKV_USER_SESSION import com.kaixed.kchat.utils.Constants.USER_LOGIN_STATUS import com.tencent.mmkv.MMKV -import io.objectbox.BoxStore /** * @Author: kaixed @@ -30,9 +25,7 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() { private val binding get() = _binding!! override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { _binding = BottomSheetLayoutBinding.inflate(inflater, container, false) return binding.root @@ -50,14 +43,11 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() { deleteAllUserData() activity?.finish() - activity?.startActivity( - Intent( - activity, - LoginActivity::class.java - ).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - } - ) + activity?.startActivity(Intent( + activity, LoginActivity::class.java + ).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + }) } binding.tvCancel.setOnClickListener { @@ -67,7 +57,6 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() { binding.tvQuitApp.setOnClickListener { activity?.finishAffinity() } - } private fun deleteAllUserData() { @@ -76,11 +65,7 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() { MMKV.defaultMMKV().putBoolean(USER_LOGIN_STATUS, false) - - val boxStore: BoxStore = getBoxStore() - - boxStore.boxFor(Conversation::class.java).removeAll() - boxStore.boxFor(Messages::class.java).removeAll() + DataBase.cleanAllData() } override fun onDestroyView() { diff --git a/app/src/main/java/com/kaixed/kchat/utils/ConstantsUtil.kt b/app/src/main/java/com/kaixed/kchat/utils/ConstantsUtil.kt index 7c12a16..30407ef 100644 --- a/app/src/main/java/com/kaixed/kchat/utils/ConstantsUtil.kt +++ b/app/src/main/java/com/kaixed/kchat/utils/ConstantsUtil.kt @@ -24,7 +24,7 @@ object ConstantsUtil { private val defaultMMKV by lazy { MMKV.defaultMMKV() } fun getKeyboardHeight(): Int = - commonDataMMKV.getInt(KEYBOARD_HEIGHT, KEYBOARD_DEFAULT_HEIGHT) + defaultMMKV.getInt(KEYBOARD_HEIGHT, KEYBOARD_DEFAULT_HEIGHT) fun getUsername(): String = userSessionMMKV.getString(USERNAME_KEY, "") ?: "" diff --git a/app/src/main/res/layout/activity_contacts_detail.xml b/app/src/main/res/layout/activity_contacts_detail.xml index c7e954e..e6362c6 100644 --- a/app/src/main/res/layout/activity_contacts_detail.xml +++ b/app/src/main/res/layout/activity_contacts_detail.xml @@ -135,6 +135,7 @@ - - - - - - - + android:gravity="center" + android:text="发消息" + android:textColor="@color/normal" + android:textSize="16sp" /> - - - - - + android:gravity="center" + android:text="音视频通话" + android:textColor="@color/normal" + android:textSize="16sp" /> - - + android:layout_height="45dp"> - - + android:textSize="16sp" + android:textStyle="bold" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" />