优化UI
This commit is contained in:
@@ -50,7 +50,12 @@ class FamilySwitchAdapter(
|
|||||||
) : RecyclerView.ViewHolder(binding.root) {
|
) : RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(item: FamilyItem, isSelected: Boolean) {
|
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(
|
binding.root.setBackgroundColor(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ package com.example.defenseapplication.model
|
|||||||
|
|
||||||
data class FamilyItem(
|
data class FamilyItem(
|
||||||
val id: String,
|
val id: String,
|
||||||
val name: String
|
val name: String,
|
||||||
|
val role: String
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class FamilySwitchDialog(
|
|||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (response.code == 200 && response.data != null) {
|
if (response.code == 200 && response.data != null) {
|
||||||
familyBeanList = response.data.reversed()
|
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)
|
adapter.updateList(familyItems)
|
||||||
|
|
||||||
familyBeanList.firstOrNull()?.let {
|
familyBeanList.firstOrNull()?.let {
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package com.example.defenseapplication.view
|
|||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.Gravity
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
@@ -16,23 +17,28 @@ import com.example.defenseapplication.utils.LanguageUtil
|
|||||||
class LanguageDialog(
|
class LanguageDialog(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val onLanguageSelected: (String) -> Unit
|
private val onLanguageSelected: (String) -> Unit
|
||||||
) : Dialog(context) {
|
) : Dialog(context, R.style.BottomDialogStyle) {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
setContentView(R.layout.dialog_language)
|
setContentView(R.layout.dialog_language)
|
||||||
|
|
||||||
// 设置对话框宽度为屏幕宽度的80%
|
val window = window
|
||||||
window?.setLayout(
|
val params = window?.attributes
|
||||||
(context.resources.displayMetrics.widthPixels * 0.8).toInt(),
|
params?.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
params?.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||||
)
|
params?.gravity = Gravity.BOTTOM
|
||||||
|
window?.attributes = params
|
||||||
|
window?.setBackgroundDrawableResource(android.R.color.transparent)
|
||||||
|
window?.setDimAmount(0.5f)
|
||||||
|
|
||||||
initViews()
|
initViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun 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 tvChinese = findViewById<TextView>(R.id.tvChinese)
|
||||||
val tvEnglish = findViewById<TextView>(R.id.tvEnglish)
|
val tvEnglish = findViewById<TextView>(R.id.tvEnglish)
|
||||||
val tvCancel = findViewById<TextView>(R.id.tvCancel)
|
val tvCancel = findViewById<TextView>(R.id.tvCancel)
|
||||||
@@ -46,12 +52,12 @@ class LanguageDialog(
|
|||||||
tvEnglish.setTextColor(context.getColor(R.color.green))
|
tvEnglish.setTextColor(context.getColor(R.color.green))
|
||||||
}
|
}
|
||||||
|
|
||||||
tvChinese.setOnClickListener {
|
llChinese.setOnClickListener {
|
||||||
onLanguageSelected(LanguageUtil.LANGUAGE_CHINESE)
|
onLanguageSelected(LanguageUtil.LANGUAGE_CHINESE)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
tvEnglish.setOnClickListener {
|
llEnglish.setOnClickListener {
|
||||||
onLanguageSelected(LanguageUtil.LANGUAGE_ENGLISH)
|
onLanguageSelected(LanguageUtil.LANGUAGE_ENGLISH)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
app/src/main/res/drawable/chinexe.png
Normal file
BIN
app/src/main/res/drawable/chinexe.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable/english.png
Normal file
BIN
app/src/main/res/drawable/english.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -21,34 +21,66 @@
|
|||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="#EEEEEE" />
|
android:background="#EEEEEE" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/tvChinese"
|
android:id="@+id/llChinese"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="56dp"
|
android:layout_height="80dp"
|
||||||
android:gravity="center"
|
android:orientation="horizontal"
|
||||||
android:text="@string/chinese"
|
android:gravity="center_vertical"
|
||||||
android:textColor="@color/black"
|
android:paddingStart="16dp"
|
||||||
android:textSize="16sp"
|
android:paddingEnd="16dp"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true" />
|
android:focusable="true">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:src="@drawable/chinexe"
|
||||||
|
android:scaleType="centerInside" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvChinese"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/chinese"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:layout_marginStart="16dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="#EEEEEE" />
|
android:background="#EEEEEE" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/tvEnglish"
|
android:id="@+id/llEnglish"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="56dp"
|
android:layout_height="80dp"
|
||||||
android:gravity="center"
|
android:orientation="horizontal"
|
||||||
android:text="@string/english"
|
android:gravity="center_vertical"
|
||||||
android:textColor="@color/black"
|
android:paddingStart="16dp"
|
||||||
android:textSize="16sp"
|
android:paddingEnd="16dp"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true" />
|
android:focusable="true">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:src="@drawable/english"
|
||||||
|
android:scaleType="centerInside" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvEnglish"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/english"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:layout_marginStart="16dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -62,6 +62,8 @@
|
|||||||
<string name="profile">个人</string>
|
<string name="profile">个人</string>
|
||||||
<string name="admin_user">管理者</string>
|
<string name="admin_user">管理者</string>
|
||||||
<string name="normal_user">普通用户</string>
|
<string name="normal_user">普通用户</string>
|
||||||
|
<string name="my_family_admin">%s(管理员)</string>
|
||||||
|
<string name="family_member">%s(成员)</string>
|
||||||
|
|
||||||
<!-- Home Menu -->
|
<!-- Home Menu -->
|
||||||
<string name="my_devices">我的设备</string>
|
<string name="my_devices">我的设备</string>
|
||||||
|
|||||||
@@ -97,6 +97,8 @@
|
|||||||
<string name="switch_family">Switch Family</string>
|
<string name="switch_family">Switch Family</string>
|
||||||
<string name="current_family">Current Family</string>
|
<string name="current_family">Current Family</string>
|
||||||
<string name="my_family">My Family</string>
|
<string name="my_family">My Family</string>
|
||||||
|
<string name="my_family_admin">%s (Admin)</string>
|
||||||
|
<string name="family_member">%s (Member)</string>
|
||||||
<string name="add_family">Add Family</string>
|
<string name="add_family">Add Family</string>
|
||||||
<string name="family_name">Family Name</string>
|
<string name="family_name">Family Name</string>
|
||||||
<string name="enter_family_name">Enter family name</string>
|
<string name="enter_family_name">Enter family name</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user