自定义弹窗view
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
package com.example.defenseapplication.adapter
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.example.defenseapplication.databinding.ItemMessageGroupTitleBinding
|
||||||
|
import com.example.defenseapplication.databinding.ItemMessageNoticeBinding
|
||||||
|
|
||||||
|
sealed class MessageListItem {
|
||||||
|
data class Header(val title: String) : MessageListItem()
|
||||||
|
data class Message(
|
||||||
|
val time: String,
|
||||||
|
val title: String,
|
||||||
|
val dateTime: String,
|
||||||
|
val unread: Boolean
|
||||||
|
) : MessageListItem()
|
||||||
|
}
|
||||||
|
|
||||||
|
class MessageListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
|
private val items = mutableListOf<MessageListItem>()
|
||||||
|
|
||||||
|
fun submitList(list: List<MessageListItem>) {
|
||||||
|
items.clear()
|
||||||
|
items.addAll(list)
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemViewType(position: Int): Int {
|
||||||
|
return when (items[position]) {
|
||||||
|
is MessageListItem.Header -> TYPE_HEADER
|
||||||
|
is MessageListItem.Message -> TYPE_MESSAGE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||||
|
return if (viewType == TYPE_HEADER) {
|
||||||
|
val binding = ItemMessageGroupTitleBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
HeaderViewHolder(binding)
|
||||||
|
} else {
|
||||||
|
val binding = ItemMessageNoticeBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
MessageViewHolder(binding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
|
when (holder) {
|
||||||
|
is HeaderViewHolder -> holder.bind(items[position] as MessageListItem.Header)
|
||||||
|
is MessageViewHolder -> holder.bind(items[position] as MessageListItem.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = items.size
|
||||||
|
|
||||||
|
private class HeaderViewHolder(private val binding: ItemMessageGroupTitleBinding) :
|
||||||
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
fun bind(item: MessageListItem.Header) {
|
||||||
|
binding.tvGroupTitle.text = item.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MessageViewHolder(private val binding: ItemMessageNoticeBinding) :
|
||||||
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
fun bind(item: MessageListItem.Message) {
|
||||||
|
binding.tvTime.text = item.time
|
||||||
|
binding.tvTitle.text = item.title
|
||||||
|
binding.tvDateTime.text = item.dateTime
|
||||||
|
binding.unreadDot.visibility = if (item.unread) View.VISIBLE else View.INVISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TYPE_HEADER = 0
|
||||||
|
private const val TYPE_MESSAGE = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
5
app/src/main/res/drawable/bg_detail_border.xml
Normal file
5
app/src/main/res/drawable/bg_detail_border.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="#E6FBF2" />
|
||||||
|
<corners android:radius="30dp" />
|
||||||
|
</shape>
|
||||||
8
app/src/main/res/drawable/bg_logout_button.xml
Normal file
8
app/src/main/res/drawable/bg_logout_button.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@android:color/transparent" />
|
||||||
|
<corners android:radius="6dp" />
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="#8F8F8F" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<gradient
|
||||||
|
android:angle="0"
|
||||||
|
android:endColor="#CFF3FF"
|
||||||
|
android:startColor="#E8DFEE" />
|
||||||
|
</shape>
|
||||||
7
app/src/main/res/drawable/bg_unread_dot.xml
Normal file
7
app/src/main/res/drawable/bg_unread_dot.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<size
|
||||||
|
android:width="8dp"
|
||||||
|
android:height="8dp" />
|
||||||
|
<solid android:color="#E75A6B" />
|
||||||
|
</shape>
|
||||||
12
app/src/main/res/layout/item_message_group_title.xml
Normal file
12
app/src/main/res/layout/item_message_group_title.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/tvGroupTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:textColor="#666666"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
tools:text="今天" />
|
||||||
75
app/src/main/res/layout/item_message_notice.xml
Normal file
75
app/src/main/res/layout/item_message_notice.xml
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:background="@drawable/round_bg"
|
||||||
|
android:minHeight="60dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="14dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="12dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#2B2B2B"
|
||||||
|
android:textSize="16dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:text="15:54" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTitle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="#2B2B2B"
|
||||||
|
android:textSize="16dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/tvTime"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/unreadDot"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvTime"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/tvTime"
|
||||||
|
tools:text="有人入侵" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvDateTime"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:textColor="#B2B2B2"
|
||||||
|
android:textSize="14dp"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/ivDetail"
|
||||||
|
app:layout_constraintStart_toStartOf="@id/tvTime"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvTime"
|
||||||
|
tools:text="2026-05-06 15:54:25" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/unreadDot"
|
||||||
|
android:layout_width="8dp"
|
||||||
|
android:layout_height="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:background="@drawable/bg_unread_dot"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/ivDetail"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/ivDetail"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/ivDetail" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ivDetail"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:background="@drawable/bg_detail_border"
|
||||||
|
android:padding="5dp"
|
||||||
|
android:src="@drawable/right_back"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user