This commit is contained in:
itgaojian163 2024-11-15 17:51:25 +08:00
parent 7a533c126c
commit 1ad30ca2b2
9 changed files with 126 additions and 13 deletions

View File

@ -23,7 +23,10 @@ android {
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
@ -51,6 +54,7 @@ dependencies {
implementation(project(":baselib"))
implementation(project(":medialib"))
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)

View File

@ -2,11 +2,12 @@ package com.tenlionsoft.aimz_k.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import java.io.Serializable
@Entity(tableName = "db_msg")
@Entity(tableName = "db_msg", indices = [Index(value = ["loginUserId", "timestamp"])])
data class MsgBean(
@PrimaryKey(autoGenerate = true)
var id: Long = 0,

View File

@ -2,10 +2,11 @@ package com.tenlionsoft.aimz_k.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import java.io.Serializable
@Entity(tableName = "db_category")
@Entity(tableName = "db_category", indices = [Index(value = ["loginUserId", "timestamp"])])
data class MsgCategoryBean(
@PrimaryKey(autoGenerate = true)
var id: Long = 0,

View File

@ -19,7 +19,7 @@ class LoginActivity : BaseActivity() {
override fun bindView() {
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_login)
mBinding.loginModel = loginPageViewModel;
mBinding.loginModel = loginPageViewModel
mBinding.lifecycleOwner = this
loginPageViewModel.showLoadDialog.observe(this) {
if (it) {
@ -30,12 +30,12 @@ class LoginActivity : BaseActivity() {
.setMessage("登陆中...")
.create()
mLoading!!.show()
mBinding.btnLogin.isEnabled = false;
mBinding.btnLogin.isEnabled = false
} else {
//隐藏loading
mLoading?.dismiss()
mLoading = null
mBinding.btnLogin.isEnabled = true;
mBinding.btnLogin.isEnabled = true
}
}
loginPageViewModel.isLoginSuccess.observe(this) {

View File

@ -29,6 +29,7 @@ import com.tenlionsoft.baselib.utils.LogUtils
import com.tenlionsoft.baselib.utils.ToastUtils
import com.tenlionsoft.baselib.widget.CenterProgressUpdateView
import com.tenlionsoft.baselib.widget.FadePageTransformer
import pl.com.salsoft.sqlitestudioremote.SQLiteStudioService
import java.io.File
/**
@ -170,8 +171,6 @@ class MainActivity : BaseActivity() {
}
fun setOnSocketListener(onSocketConnectListener: OnSocketConnectListener) {
this.onSocketConnectListener = onSocketConnectListener
}

View File

@ -9,6 +9,7 @@ import com.hjq.permissions.XXPermissions
import com.tenlionsoft.aimz_k.R
import com.tenlionsoft.aimz_k.dao.DbManager
import com.tenlionsoft.aimz_k.databinding.ActivitySplashBinding
import com.tenlionsoft.aimz_k.model.ReplyBean
import com.tenlionsoft.baselib.base.BaseActivity
import com.tenlionsoft.baselib.utils.SpUtils
import com.tenlionsoft.baselib.utils.ToastUtils
@ -36,8 +37,31 @@ class SplashActivity : BaseActivity() {
withContext(Dispatchers.IO) {
val msgDao = DbManager.db.msgDao()
val cDao = DbManager.db.categoryDao()
val rDao = DbManager.db.replayDao()
msgDao.queryContent("", SpUtils.getId())
cDao.getAllCategory()
if (rDao.getAllReply().size <= 0) {
val replayList = arrayListOf(
ReplyBean(
content = "您好,很高兴为您服务!请问有什么可以帮到您的呢?",
remark = ""
),
ReplyBean(
content = "感谢您的咨询,希望我的回答对您有所帮助,祝您生活愉快!",
remark = ""
),
ReplyBean(
content = "希望您每天都有好心情,拜拜!",
remark = ""
),
ReplyBean(
content = "请参考操作手册.",
remark = ""
)
)
rDao.insertAll(replayList)
}
}
Timer().schedule(object : TimerTask() {
override fun run() {
@ -52,7 +76,7 @@ class SplashActivity : BaseActivity() {
}, 500)
}
} else {
ToastUtils.error("授权管理文件权限,无法使用软件")
ToastUtils.error("授权管理文件权限,无法使用软件")
}
}

View File

@ -205,6 +205,7 @@ class SocketService : Service(), WsManager.MsgCallBack {
private suspend fun disposeUserInfo(msgBean: MsgBean) {
withContext(Dispatchers.IO) {
val isExist = userMap.any { it.key == msgBean.receiverId }
// val isExist = userMap.contactsKey(msgBean.receiverId)
if (isExist) {
val userInfoBean = userMap[msgBean.receiverId]
//更新数据库
@ -253,6 +254,44 @@ class SocketService : Service(), WsManager.MsgCallBack {
}
}
private suspend fun disposeUser(msgBean: MsgBean){
val lId = SpUtils.getId() // 登录人id
val msgId = msgBean.messageId!!
val sNickName = SpUtils.getNickName()
val sAvatar = SpUtils.getAvatar()
val userInfo = when {
userMap.containsKey(msgBean.receiverId) -> {
// 从缓存获取用户信息
userMap[msgBean.receiverId]
}
else -> {
// 从网络获取用户信息并缓存
val userBean = doGetUserInfo(msgId, msgBean.receiverId!!)
if (userBean != null) {
userMap[msgBean.receiverId!!] = userBean
}
userBean
}
}
// 更新数据库
val nickName = userInfo?.nickname ?: ""
val avatar = userInfo?.avatar ?: ""
val categoryLine = cDao.updateInByMsgId(nickName, avatar, msgId, lId)
val msgLine = msgDao.updateUserInfoByMessageId(
sAvatar, sNickName, avatar, nickName, msgId, lId
)
val source = if (userInfo != null) {
if (userMap.containsKey(msgBean.receiverId)) "本地获取" else "网络获取"
} else {
"网络中未获取到"
}
Log.e("SocketService", "更新头像:${source} MSG=${msgLine}===Category:${categoryLine}")
}
private fun sendRefresh() {
Log.e("SocketService", "sendRefresh:通知页面刷新")
val intent = Intent(ProjectConfig.A_S_UPDATE_INFO)

View File

@ -20,15 +20,14 @@ import okhttp3.RequestBody.Companion.toRequestBody
class LoginPageViewModel : BaseViewModel() {
var userName: String = "yyy"
var userPwd: String = "123456"
var userName: String = SpUtils.getUserName()
var userPwd: String = SpUtils.getPassword()
val isLoginSuccess = MutableLiveData<Boolean>()
private val gson = Gson()
private val retrofitClient = RetrofitClient.getInstance(App.context)
private val userApi = retrofitClient.create(BaseApi::class.java)
fun onUserNameChange(s: CharSequence, start: Int, before: Int, count: Int) {
this.userName = s.toString();
}

View File

@ -2,6 +2,8 @@ package com.tenlionsoft.baselib.base
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
@ -14,7 +16,7 @@ import kotlin.system.exitProcess
abstract class BaseActivity : DataBindingActivity() {
fun reStartApp(){
fun reStartApp() {
SpUtils.removeAll()
val broadcast = Intent()
broadcast.setAction(ProjectConfig.A_S_LOGOUT)
@ -46,6 +48,50 @@ abstract class BaseActivity : DataBindingActivity() {
}, 100)
}
fun safeExitApp() {
try {
// Clear all user data
SpUtils.removeAll()
// Send broadcast to stop services
val broadcast = Intent()
broadcast.action = ProjectConfig.A_S_LOGOUT
sendBroadcast(broadcast)
// Finish all activities
finishAffinity()
// Kill the process
android.os.Process.killProcess(android.os.Process.myPid())
// Exit the app
exitProcess(0)
} catch (e: Exception) {
e.printStackTrace()
// Fallback to force exit if safe exit fails
exitProcess(1)
}
}
fun setStatusBarStyle(transparent: Boolean) {
val window = window
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Add flag to make status bar drawable
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
if (transparent) {
// Set transparent status bar
window.statusBarColor = Color.TRANSPARENT
// Set dark status bar icons
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
// Set black status bar
window.statusBarColor = Color.BLACK
// Set light status bar icons
window.decorView.systemUiVisibility = 0
}
}
}
fun setStatusBarColor(dark: Boolean) {
val window = window
if (dark) {