This commit is contained in:
2026-05-20 17:51:44 +08:00
parent 246b39ca1a
commit e6a3c1605f
9 changed files with 77 additions and 29 deletions

View File

@@ -50,7 +50,12 @@ class FamilySwitchAdapter(
) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: FamilyItem, isSelected: Boolean) {
binding.tvFamilyName.text = item.name
val displayName = if (item.role == "appadmin") {
binding.root.context.getString(R.string.my_family_admin, item.name)
} else {
binding.root.context.getString(R.string.family_member, item.name)
}
binding.tvFamilyName.text = displayName
binding.root.setBackgroundColor(
ContextCompat.getColor(

View File

@@ -2,5 +2,6 @@ package com.example.defenseapplication.model
data class FamilyItem(
val id: String,
val name: String
val name: String,
val role: String
)

View File

@@ -81,7 +81,7 @@ class FamilySwitchDialog(
withContext(Dispatchers.Main) {
if (response.code == 200 && response.data != null) {
familyBeanList = response.data.reversed()
val familyItems = familyBeanList.map { FamilyItem(it.id, it.parentName) }
val familyItems = familyBeanList.map { FamilyItem(it.id, it.parentName, it.role) }
adapter.updateList(familyItems)
familyBeanList.firstOrNull()?.let {

View File

@@ -3,8 +3,9 @@ package com.example.defenseapplication.view
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.LinearLayout
import android.widget.TextView
import com.example.defenseapplication.R
@@ -16,23 +17,28 @@ import com.example.defenseapplication.utils.LanguageUtil
class LanguageDialog(
context: Context,
private val onLanguageSelected: (String) -> Unit
) : Dialog(context) {
) : Dialog(context, R.style.BottomDialogStyle) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.dialog_language)
// 设置对话框宽度为屏幕宽度的80%
window?.setLayout(
(context.resources.displayMetrics.widthPixels * 0.8).toInt(),
LinearLayout.LayoutParams.WRAP_CONTENT
)
val window = window
val params = window?.attributes
params?.width = WindowManager.LayoutParams.MATCH_PARENT
params?.height = WindowManager.LayoutParams.WRAP_CONTENT
params?.gravity = Gravity.BOTTOM
window?.attributes = params
window?.setBackgroundDrawableResource(android.R.color.transparent)
window?.setDimAmount(0.5f)
initViews()
}
private fun initViews() {
val llChinese = findViewById<LinearLayout>(R.id.llChinese)
val llEnglish = findViewById<LinearLayout>(R.id.llEnglish)
val tvChinese = findViewById<TextView>(R.id.tvChinese)
val tvEnglish = findViewById<TextView>(R.id.tvEnglish)
val tvCancel = findViewById<TextView>(R.id.tvCancel)
@@ -46,12 +52,12 @@ class LanguageDialog(
tvEnglish.setTextColor(context.getColor(R.color.green))
}
tvChinese.setOnClickListener {
llChinese.setOnClickListener {
onLanguageSelected(LanguageUtil.LANGUAGE_CHINESE)
dismiss()
}
tvEnglish.setOnClickListener {
llEnglish.setOnClickListener {
onLanguageSelected(LanguageUtil.LANGUAGE_ENGLISH)
dismiss()
}