适配中英文切换
This commit is contained in:
@@ -6,6 +6,7 @@ import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.adapter.AddDeviceAdapter
|
||||
import com.example.defenseapplication.adapter.Device
|
||||
import com.example.defenseapplication.databinding.AddDeviceActivityBinding
|
||||
@@ -32,8 +33,8 @@ class AddDeviceActivity : AppCompatActivity() {
|
||||
|
||||
private fun setupDeviceList() {
|
||||
val devices = listOf(
|
||||
Device("智能挂式防御机", "device1"),
|
||||
Device("智能防御机", "device2")
|
||||
Device(getString(R.string.smart_hanging_defense), "device1"),
|
||||
Device(getString(R.string.smart_defense_device), "device2")
|
||||
)
|
||||
|
||||
if (devices.isEmpty()) {
|
||||
|
||||
@@ -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())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.bumptech.glide.Glide
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.PersonalFragmentBinding
|
||||
import com.example.defenseapplication.personal.PersonalProfileActivity
|
||||
import com.example.defenseapplication.utils.LanguageUtil
|
||||
import com.example.defenseapplication.view.LanguageDialog
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
|
||||
class PersonalFragment : Fragment() {
|
||||
@@ -37,9 +39,36 @@ class PersonalFragment : Fragment() {
|
||||
val intent= Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
// 更新当前语言显示
|
||||
updateCurrentLanguageDisplay()
|
||||
// 语言设置点击事件
|
||||
binding.itemLanguage.setOnClickListener {
|
||||
showLanguageDialog()
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新当前语言显示
|
||||
*/
|
||||
private fun updateCurrentLanguageDisplay() {
|
||||
val currentLang = LanguageUtil.getCurrentLanguage(requireContext())
|
||||
binding.tvCurrentLanguage.text = LanguageUtil.getLanguageDisplayName(currentLang)
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示语言选择对话框
|
||||
*/
|
||||
private fun showLanguageDialog() {
|
||||
val dialog = LanguageDialog(requireContext()) { language ->
|
||||
LanguageUtil.switchLanguage(requireContext(), language)
|
||||
// 刷新当前页面以应用新语言
|
||||
requireActivity().recreate()
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null // 避免内存泄漏
|
||||
|
||||
Reference in New Issue
Block a user