fix: 修复退出登录数据未清除错误

This commit is contained in:
糕小菜 2024-12-29 10:54:03 +08:00
parent b6af7650d1
commit 6297f02054
8 changed files with 79 additions and 93 deletions

View File

@ -20,4 +20,11 @@ object DataBase {
val conversationBox: Box<Conversation> by lazy { getBoxStore().boxFor() } val conversationBox: Box<Conversation> by lazy { getBoxStore().boxFor() }
val userInfoBox: Box<UserInfo> by lazy { getBoxStore().boxFor() } val userInfoBox: Box<UserInfo> by lazy { getBoxStore().boxFor() }
fun cleanAllData() {
contactBox.removeAll()
messagesBox.removeAll()
conversationBox.removeAll()
userInfoBox.removeAll()
}
} }

View File

@ -5,11 +5,15 @@ 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.bumptech.glide.Glide
import com.kaixed.kchat.data.DataBase 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 com.kaixed.kchat.utils.ConstantsUtil.getAvatarUrl
import com.kaixed.kchat.utils.ConstantsUtil.getNickName
import com.kaixed.kchat.utils.ConstantsUtil.getUsername
class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() { class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
@ -17,6 +21,8 @@ class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
private var contactNickname: String? = null private var contactNickname: String? = null
private var isMine = false
companion object { companion object {
private const val TAG = "ContactsDetailActivity" private const val TAG = "ContactsDetailActivity"
} }
@ -37,10 +43,25 @@ class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
override fun initData() { override fun initData() {
contactId = intent.getStringExtra("contactId") contactId = intent.getStringExtra("contactId")
isMine = intent.getBooleanExtra("isMine", false)
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private fun updateContent() { 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 { val contact: Contact by lazy {
getContactInfo(contactId!!) getContactInfo(contactId!!)
} }
@ -63,7 +84,7 @@ class ContactsDetailActivity : BaseActivity<ActivityContactsDetailBinding>() {
} }
private fun setOnListener() { private fun setOnListener() {
binding.rlSendMessage.setOnClickListener { binding.tvSendMessage.setOnClickListener {
startActivity(Intent(this, ChatActivity::class.java).apply { startActivity(Intent(this, ChatActivity::class.java).apply {
putExtra("contactId", contactId) putExtra("contactId", contactId)
putExtra("contactNickname", contactId) putExtra("contactNickname", contactId)

View File

@ -17,6 +17,7 @@ import com.kaixed.kchat.data.model.search.SearchUser
import com.kaixed.kchat.databinding.ActivitySearchFriendsBinding import com.kaixed.kchat.databinding.ActivitySearchFriendsBinding
import com.kaixed.kchat.ui.base.BaseActivity import com.kaixed.kchat.ui.base.BaseActivity
import com.kaixed.kchat.ui.widget.LoadingDialogFragment import com.kaixed.kchat.ui.widget.LoadingDialogFragment
import com.kaixed.kchat.utils.ConstantsUtil.getUsername
import com.kaixed.kchat.viewmodel.ContactViewModel import com.kaixed.kchat.viewmodel.ContactViewModel
class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() { class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() {
@ -27,12 +28,14 @@ class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() {
private lateinit var loadingDialog: LoadingDialogFragment private lateinit var loadingDialog: LoadingDialogFragment
private val contactViewModel: ContactViewModel by viewModels()
private var isSearchedMine = false
override fun inflateBinding(): ActivitySearchFriendsBinding { override fun inflateBinding(): ActivitySearchFriendsBinding {
return ActivitySearchFriendsBinding.inflate(layoutInflater) return ActivitySearchFriendsBinding.inflate(layoutInflater)
} }
private val contactViewModel: ContactViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
enableEdgeToEdge() enableEdgeToEdge()
@ -60,9 +63,17 @@ class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() {
finish() finish()
} }
binding.clFriends.setOnClickListener { binding.clFriends.setOnClickListener {
val intent = Intent(this, ApplyFriendsDetailActivity::class.java).apply { val intent =
putExtra("user", userItem) 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) startActivity(intent)
} }
@ -94,10 +105,12 @@ class SearchFriendsActivity : BaseActivity<ActivitySearchFriendsBinding>() {
contactViewModel.searchContactResult.observe(this) { result -> contactViewModel.searchContactResult.observe(this) { result ->
result.onSuccess { result.onSuccess {
it?.let { it?.let {
isSearchedMine = it.username == getUsername()
if (LocalDatabase.isMyFriend(it.username)) { if (LocalDatabase.isMyFriend(it.username)) {
val username = it.username
val intent = val intent =
Intent(this, ContactsDetailActivity::class.java).apply { Intent(this, ContactsDetailActivity::class.java).apply {
putExtra("contactId", it.username) putExtra("contactId", username)
} }
startActivity(intent) startActivity(intent)
} else { } else {

View File

@ -129,9 +129,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), OnItemListener,
} }
private fun setOnClick() { private fun setOnClick() {
binding.ifvAvatar.setOnClickListener {
startActivity(Intent(context, TestActivity::class.java))
}
binding.ivSearch.setOnClickListener { binding.ivSearch.setOnClickListener {
val intent = Intent(context, SearchActivity::class.java) val intent = Intent(context, SearchActivity::class.java)
startActivity(intent) startActivity(intent)

View File

@ -1,8 +1,6 @@
package com.kaixed.kchat.ui.widget package com.kaixed.kchat.ui.widget
import android.app.Activity
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -10,15 +8,12 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.kaixed.kchat.R import com.kaixed.kchat.R
import com.kaixed.kchat.data.local.box.ObjectBox.getBoxStore import com.kaixed.kchat.data.DataBase
import com.kaixed.kchat.data.local.entity.Conversation
import com.kaixed.kchat.data.local.entity.Messages
import com.kaixed.kchat.databinding.BottomSheetLayoutBinding import com.kaixed.kchat.databinding.BottomSheetLayoutBinding
import com.kaixed.kchat.ui.activity.LoginActivity import com.kaixed.kchat.ui.activity.LoginActivity
import com.kaixed.kchat.utils.Constants.MMKV_USER_SESSION import com.kaixed.kchat.utils.Constants.MMKV_USER_SESSION
import com.kaixed.kchat.utils.Constants.USER_LOGIN_STATUS import com.kaixed.kchat.utils.Constants.USER_LOGIN_STATUS
import com.tencent.mmkv.MMKV import com.tencent.mmkv.MMKV
import io.objectbox.BoxStore
/** /**
* @Author: kaixed * @Author: kaixed
@ -30,9 +25,7 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() {
private val binding get() = _binding!! private val binding get() = _binding!!
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
container: ViewGroup?,
savedInstanceState: Bundle?
): View { ): View {
_binding = BottomSheetLayoutBinding.inflate(inflater, container, false) _binding = BottomSheetLayoutBinding.inflate(inflater, container, false)
return binding.root return binding.root
@ -50,14 +43,11 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() {
deleteAllUserData() deleteAllUserData()
activity?.finish() activity?.finish()
activity?.startActivity( activity?.startActivity(Intent(
Intent( activity, LoginActivity::class.java
activity, ).apply {
LoginActivity::class.java flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
).apply { })
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
)
} }
binding.tvCancel.setOnClickListener { binding.tvCancel.setOnClickListener {
@ -67,7 +57,6 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() {
binding.tvQuitApp.setOnClickListener { binding.tvQuitApp.setOnClickListener {
activity?.finishAffinity() activity?.finishAffinity()
} }
} }
private fun deleteAllUserData() { private fun deleteAllUserData() {
@ -76,11 +65,7 @@ class MyBottomSheetFragment : BottomSheetDialogFragment() {
MMKV.defaultMMKV().putBoolean(USER_LOGIN_STATUS, false) MMKV.defaultMMKV().putBoolean(USER_LOGIN_STATUS, false)
DataBase.cleanAllData()
val boxStore: BoxStore = getBoxStore()
boxStore.boxFor(Conversation::class.java).removeAll()
boxStore.boxFor(Messages::class.java).removeAll()
} }
override fun onDestroyView() { override fun onDestroyView() {

View File

@ -24,7 +24,7 @@ object ConstantsUtil {
private val defaultMMKV by lazy { MMKV.defaultMMKV() } private val defaultMMKV by lazy { MMKV.defaultMMKV() }
fun getKeyboardHeight(): Int = fun getKeyboardHeight(): Int =
commonDataMMKV.getInt(KEYBOARD_HEIGHT, KEYBOARD_DEFAULT_HEIGHT) defaultMMKV.getInt(KEYBOARD_HEIGHT, KEYBOARD_DEFAULT_HEIGHT)
fun getUsername(): String = fun getUsername(): String =
userSessionMMKV.getString(USERNAME_KEY, "") ?: "" userSessionMMKV.getString(USERNAME_KEY, "") ?: ""

View File

@ -135,6 +135,7 @@
</RelativeLayout> </RelativeLayout>
<com.kaixed.kchat.ui.widget.CustomItem <com.kaixed.kchat.ui.widget.CustomItem
android:id="@+id/ci_more"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:isTopDividerVisible="true" app:isTopDividerVisible="true"
@ -146,47 +147,30 @@
android:layout_height="8dp" android:layout_height="8dp"
android:background="#E5E5E5" /> android:background="#E5E5E5" />
<RelativeLayout <TextView
android:id="@+id/rl_send_message" android:id="@+id/tv_send_message"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:paddingStart="15dp" android:gravity="center"
tools:ignore="RtlSymmetry"> android:text="发消息"
android:textColor="@color/normal"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="发消息"
android:textColor="@color/normal"
android:textSize="16sp" />
</RelativeLayout>
<View <View
android:id="@+id/view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/divider_height" android:layout_height="@dimen/divider_height"
android:background="@color/gray" /> android:background="@color/gray" />
<RelativeLayout <TextView
android:id="@+id/rl_send_video_call" android:id="@+id/tv_video_call"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:paddingStart="15dp" android:gravity="center"
tools:ignore="RtlSymmetry"> android:text="音视频通话"
android:textColor="@color/normal"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="音视频通话"
android:textColor="@color/normal"
android:textSize="16sp" />
</RelativeLayout>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -9,40 +9,19 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="45dp">
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/ifv_avatar"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginVertical="10dp"
android:layout_marginStart="15dp"
android:src="@drawable/ic_avatar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:roundPercent="1" />
<TextView <TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:text="星联"
android:text="肤浅"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="15sp" android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@id/tv_signature" android:textStyle="bold"
app:layout_constraintStart_toEndOf="@id/ifv_avatar" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@id/ifv_avatar" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
<TextView app:layout_constraintTop_toTopOf="parent" />
android:id="@+id/tv_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="平安顺遂,喜乐无忧"
app:layout_constraintBottom_toBottomOf="@id/ifv_avatar"
app:layout_constraintStart_toStartOf="@id/tv_name"
app:layout_constraintTop_toBottomOf="@id/tv_name" />
<ImageView <ImageView
android:id="@+id/iv_search" android:id="@+id/iv_search"