适配中英文切换
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.example.defenseapplication.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
@@ -13,6 +14,7 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.adapter.DeviceAdapter
|
||||
import com.example.defenseapplication.adapter.DeviceUi
|
||||
import com.example.defenseapplication.adapter.FamilyAdapter
|
||||
@@ -28,24 +30,32 @@ class HomeMenuFragment : Fragment() {
|
||||
private val deviceAdapter by lazy { DeviceAdapter(::onDeviceClicked) }
|
||||
|
||||
private var isFamilyExpanded = false
|
||||
private var currentFamily = "我的家庭"
|
||||
private lateinit var currentFamily: String
|
||||
|
||||
private val familyList = listOf("我的家庭", "工作室", "父母家")
|
||||
private val familyDeviceMap = mapOf(
|
||||
"我的家庭" to listOf(
|
||||
DeviceUi("智能挂式防御机", true),
|
||||
DeviceUi("智能防御机", false),
|
||||
DeviceUi("智能轨道防御机", false)
|
||||
),
|
||||
"工作室" to listOf(
|
||||
DeviceUi("走廊防御机", true),
|
||||
DeviceUi("门禁防御机", true)
|
||||
),
|
||||
"父母家" to listOf(
|
||||
DeviceUi("客厅防御机", false),
|
||||
DeviceUi("阳台防御机", true)
|
||||
private val familyList: List<String> by lazy {
|
||||
listOf(
|
||||
getString(R.string.my_family_home),
|
||||
getString(R.string.workshop),
|
||||
getString(R.string.parents_home)
|
||||
)
|
||||
)
|
||||
}
|
||||
private val familyDeviceMap: Map<String, List<DeviceUi>> by lazy {
|
||||
mapOf(
|
||||
getString(R.string.my_family_home) to listOf(
|
||||
DeviceUi(getString(R.string.smart_hanging_defense), true),
|
||||
DeviceUi(getString(R.string.smart_defense_device), false),
|
||||
DeviceUi(getString(R.string.smart_rail_defense), false)
|
||||
),
|
||||
getString(R.string.workshop) to listOf(
|
||||
DeviceUi(getString(R.string.corridor_defense), true),
|
||||
DeviceUi(getString(R.string.door_defense), true)
|
||||
),
|
||||
getString(R.string.parents_home) to listOf(
|
||||
DeviceUi(getString(R.string.living_room_defense), false),
|
||||
DeviceUi(getString(R.string.balcony_defense), true)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -81,6 +91,7 @@ class HomeMenuFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
currentFamily = familyList.first()
|
||||
binding.rvFamilyList.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.rvFamilyList.adapter = familyAdapter
|
||||
familyAdapter.submitList(familyList, currentFamily)
|
||||
@@ -133,7 +144,7 @@ class HomeMenuFragment : Fragment() {
|
||||
private fun onDeviceClicked(device: DeviceUi) {
|
||||
if (device.isOnline) return
|
||||
showDefenseDialog(
|
||||
config = DefenseDialogs.deviceOfflineConfig()
|
||||
config = DefenseDialogs.deviceOfflineConfig(requireContext())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user