自定义告警弹窗
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.example.defenseapplication.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
@@ -16,13 +17,15 @@ import com.example.defenseapplication.adapter.DeviceAdapter
|
||||
import com.example.defenseapplication.adapter.DeviceUi
|
||||
import com.example.defenseapplication.adapter.FamilyAdapter
|
||||
import com.example.defenseapplication.databinding.HomeMenuFragmentBinding
|
||||
import com.example.defenseapplication.view.DefenseDialogs
|
||||
import com.example.defenseapplication.view.showDefenseDialog
|
||||
|
||||
class HomeMenuFragment : Fragment() {
|
||||
// ViewBinding
|
||||
private var _binding: HomeMenuFragmentBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private val familyAdapter by lazy { FamilyAdapter(::onFamilySelected) }
|
||||
private val deviceAdapter by lazy { DeviceAdapter() }
|
||||
private val deviceAdapter by lazy { DeviceAdapter(::onDeviceClicked) }
|
||||
|
||||
private var isFamilyExpanded = false
|
||||
private var currentFamily = "我的家庭"
|
||||
@@ -63,6 +66,10 @@ class HomeMenuFragment : Fragment() {
|
||||
startColor = Color.parseColor("#EBDCED"),
|
||||
endColor = Color.parseColor("#CAF4FF")
|
||||
)
|
||||
binding.message.setOnClickListener {
|
||||
val intent = Intent(requireContext(), MessageActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
@@ -115,6 +122,13 @@ class HomeMenuFragment : Fragment() {
|
||||
deviceAdapter.submitList(familyDeviceMap[currentFamily].orEmpty())
|
||||
}
|
||||
|
||||
private fun onDeviceClicked(device: DeviceUi) {
|
||||
if (device.isOnline) return
|
||||
showDefenseDialog(
|
||||
config = DefenseDialogs.deviceOfflineConfig()
|
||||
)
|
||||
}
|
||||
|
||||
private fun dpToPx(dp: Int): Int {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.example.defenseapplication.home
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.example.defenseapplication.adapter.MessageListAdapter
|
||||
import com.example.defenseapplication.adapter.MessageListItem
|
||||
import com.example.defenseapplication.databinding.MessageActivityBinding
|
||||
|
||||
class MessageActivity : AppCompatActivity() {
|
||||
private lateinit var binding: MessageActivityBinding
|
||||
private val messageAdapter by lazy { MessageListAdapter() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
binding = MessageActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.main) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
initView()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
binding.ivBack.setOnClickListener { finish() }
|
||||
binding.rvMessageList.layoutManager = LinearLayoutManager(this)
|
||||
binding.rvMessageList.adapter = messageAdapter
|
||||
messageAdapter.submitList(buildMockData())
|
||||
}
|
||||
|
||||
private fun buildMockData(): List<MessageListItem> {
|
||||
return listOf(
|
||||
MessageListItem.Header("今天"),
|
||||
MessageListItem.Message(
|
||||
time = "15:54",
|
||||
title = "有人入侵",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = true
|
||||
),
|
||||
MessageListItem.Message(
|
||||
time = "12:54",
|
||||
title = "有人入侵",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = true
|
||||
),
|
||||
MessageListItem.Message(
|
||||
time = "11:54",
|
||||
title = "有人入侵",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = true
|
||||
),
|
||||
MessageListItem.Header("05-05"),
|
||||
MessageListItem.Message(
|
||||
time = "15:54",
|
||||
title = "设备故障",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = false
|
||||
),
|
||||
MessageListItem.Message(
|
||||
time = "08:07",
|
||||
title = "设备离线",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = false
|
||||
),
|
||||
MessageListItem.Message(
|
||||
time = "08:07",
|
||||
title = "到期提醒",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = false
|
||||
),
|
||||
MessageListItem.Message(
|
||||
time = "11:54",
|
||||
title = "有人入侵",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = false
|
||||
),
|
||||
MessageListItem.Message(
|
||||
time = "11:54",
|
||||
title = "有人入侵",
|
||||
dateTime = "2026-05-06 15:54:25",
|
||||
unread = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.example.defenseapplication.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.bumptech.glide.Glide
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.PersonalFragmentBinding
|
||||
import com.example.defenseapplication.personal.PersonalProfileActivity
|
||||
|
||||
class PersonalFragment : Fragment() {
|
||||
// ViewBinding
|
||||
@@ -19,6 +22,14 @@ class PersonalFragment : Fragment() {
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = PersonalFragmentBinding.inflate(inflater, container, false)
|
||||
Glide.with(this)
|
||||
.load(R.mipmap.ic_launcher_round)
|
||||
.circleCrop()
|
||||
.into(binding.ivAvatar)
|
||||
binding.headerLayout.setOnClickListener {
|
||||
val intent= Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user