Add detail information view of tasks
This commit is contained in:
parent
0bfc7f5933
commit
98a78dd717
12 changed files with 181 additions and 15 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
package cn.super12138.todo.logic.model
|
package cn.super12138.todo.logic.model
|
||||||
|
|
||||||
data class ToDo(val uuid: String, val content: String, val subject: String) {
|
data class ToDo(val uuid: String, val state:Int, val content: String, val subject: String) {
|
||||||
var isAnimated = false
|
var isAnimated = false
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ class AllTasksActivity : BaseActivity() {
|
||||||
|
|
||||||
val layoutManager = LinearLayoutManager(ToDoApplication.context)
|
val layoutManager = LinearLayoutManager(ToDoApplication.context)
|
||||||
binding.allTasksList.layoutManager = layoutManager
|
binding.allTasksList.layoutManager = layoutManager
|
||||||
val adapter = AllTasksAdapter(viewModel.todoListAll)
|
val adapter = AllTasksAdapter(viewModel.todoListAll, supportFragmentManager)
|
||||||
binding.allTasksList.adapter = adapter
|
binding.allTasksList.adapter = adapter
|
||||||
|
|
||||||
FastScrollerBuilder(binding.allTasksList).apply {
|
FastScrollerBuilder(binding.allTasksList).apply {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.logic.model.ToDo
|
import cn.super12138.todo.logic.model.ToDo
|
||||||
|
|
||||||
class AllTasksAdapter(private val todoList: MutableList<ToDo>) :
|
class AllTasksAdapter(private val todoList: MutableList<ToDo>,
|
||||||
|
private val fragmentManager: FragmentManager) :
|
||||||
RecyclerView.Adapter<AllTasksAdapter.ViewHolder>() {
|
RecyclerView.Adapter<AllTasksAdapter.ViewHolder>() {
|
||||||
|
|
||||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
@ -27,6 +29,18 @@ class AllTasksAdapter(private val todoList: MutableList<ToDo>) :
|
||||||
val todo = todoList[position]
|
val todo = todoList[position]
|
||||||
holder.todoContext.text = todo.content
|
holder.todoContext.text = todo.content
|
||||||
holder.todoSubject.text = todo.subject
|
holder.todoSubject.text = todo.subject
|
||||||
|
|
||||||
|
|
||||||
|
holder.itemView.setOnClickListener {
|
||||||
|
val infoBottomSheet = InfoBottomSheet.newInstance(
|
||||||
|
todo.content,
|
||||||
|
todo.subject,
|
||||||
|
todo.state,
|
||||||
|
todo.uuid
|
||||||
|
)
|
||||||
|
infoBottomSheet.show(fragmentManager, InfoBottomSheet.TAG)
|
||||||
|
}
|
||||||
|
|
||||||
if (!todo.isAnimated) {
|
if (!todo.isAnimated) {
|
||||||
holder.itemView.alpha = 0f
|
holder.itemView.alpha = 0f
|
||||||
holder.itemView.animate().alpha(1f).duration = 200
|
holder.itemView.animate().alpha(1f).duration = 200
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class AllTasksViewModel : ViewModel() {
|
||||||
val todos = Repository.getAll()
|
val todos = Repository.getAll()
|
||||||
var count = 0
|
var count = 0
|
||||||
for (todo in todos) {
|
for (todo in todos) {
|
||||||
todoListAll.add(ToDo(todo.uuid, todo.content, todo.subject))
|
todoListAll.add(ToDo(todo.uuid, todo.state, todo.content, todo.subject))
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
package cn.super12138.todo.views.all
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import cn.super12138.todo.R
|
||||||
|
import cn.super12138.todo.ToDoApplication
|
||||||
|
import cn.super12138.todo.databinding.BottomSheetInfoBinding
|
||||||
|
import cn.super12138.todo.logic.Repository
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
|
||||||
|
class InfoBottomSheet : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
|
private lateinit var binding: BottomSheetInfoBinding
|
||||||
|
private lateinit var todoContent: String
|
||||||
|
private lateinit var todoSubject: String
|
||||||
|
private var todoState: Int = 0
|
||||||
|
private lateinit var todoUUID: String
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "InfoBtmSheet"
|
||||||
|
fun newInstance(
|
||||||
|
todoContent: String,
|
||||||
|
todoSubject: String,
|
||||||
|
todoState: Int,
|
||||||
|
todoUUID: String
|
||||||
|
) = InfoBottomSheet().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
putString("todoContent", todoContent)
|
||||||
|
putString("todoSubject", todoSubject)
|
||||||
|
putInt("todoState", todoState)
|
||||||
|
putString("todoUUID", todoUUID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
arguments?.let {
|
||||||
|
todoContent = it.getString("todoContent", "")
|
||||||
|
todoSubject = it.getString("todoSubject", "")
|
||||||
|
todoState = it.getInt("todoState", 0)
|
||||||
|
todoUUID = it.getString("todoUUID", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View {
|
||||||
|
binding = BottomSheetInfoBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
@androidx.annotation.OptIn(com.google.android.material.badge.ExperimentalBadgeUtils::class)
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val bottomSheetDialog = dialog as BottomSheetDialog
|
||||||
|
bottomSheetDialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
bottomSheetDialog.dismissWithAnimation = true
|
||||||
|
|
||||||
|
binding.todoContentInfo.text = todoContent
|
||||||
|
binding.todoSubjectInfo.text = String.format(getString(R.string.info_subject), todoSubject)
|
||||||
|
if (todoState == 0) {
|
||||||
|
binding.todoState.text = getString(R.string.info_state_complete)
|
||||||
|
} else {
|
||||||
|
binding.todoState.text = getString(R.string.info_state_incomplete)
|
||||||
|
}
|
||||||
|
if (Repository.getPreferenceBoolean(ToDoApplication.context, "dev_mode", false)) {
|
||||||
|
binding.todoUuid.apply {
|
||||||
|
visibility = View.VISIBLE
|
||||||
|
text = String.format(getString(R.string.info_uuid), todoUUID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,7 +27,6 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: View
|
||||||
val delToDoBtn: Button = view.findViewById(R.id.delete_item_btn)
|
val delToDoBtn: Button = view.findViewById(R.id.delete_item_btn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val progressViewModel =
|
val progressViewModel =
|
||||||
ViewModelProvider(viewModelStoreOwner).get(ProgressFragmentViewModel::class.java)
|
ViewModelProvider(viewModelStoreOwner).get(ProgressFragmentViewModel::class.java)
|
||||||
|
|
@ -91,7 +90,7 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: View
|
||||||
if (todoList.size + 1 > 0) {
|
if (todoList.size + 1 > 0) {
|
||||||
todoViewModel.emptyTipVis.value = View.GONE
|
todoViewModel.emptyTipVis.value = View.GONE
|
||||||
}
|
}
|
||||||
todoList.add(ToDo(todo.uuid, todo.content, todo.subject))
|
todoList.add(ToDo(todo.uuid,0 , todo.content, todo.subject))
|
||||||
|
|
||||||
todoViewModel.refreshData.value = 1
|
todoViewModel.refreshData.value = 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import java.util.UUID
|
||||||
class ToDoFragment : Fragment() {
|
class ToDoFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTodoBinding
|
private lateinit var binding: FragmentTodoBinding
|
||||||
private lateinit var ToDoDialogBinding: DialogAddTodoBinding
|
private lateinit var toDoDialogBinding: DialogAddTodoBinding
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
|
@ -74,19 +74,19 @@ class ToDoFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.addItem.setOnClickListener {
|
binding.addItem.setOnClickListener {
|
||||||
ToDoDialogBinding = DialogAddTodoBinding.inflate(layoutInflater)
|
toDoDialogBinding = DialogAddTodoBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
activity?.let { it1 ->
|
activity?.let { it1 ->
|
||||||
val dialog = MaterialAlertDialogBuilder(it1)
|
val dialog = MaterialAlertDialogBuilder(it1)
|
||||||
.setTitle(R.string.add_task)
|
.setTitle(R.string.add_task)
|
||||||
.setView(ToDoDialogBinding.root)
|
.setView(toDoDialogBinding.root)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
val todoContent = ToDoDialogBinding.todoContent.editText?.text.toString()
|
val todoContent = toDoDialogBinding.todoContent.editText?.text.toString()
|
||||||
if (todoContent.isEmpty()) {
|
if (todoContent.isEmpty()) {
|
||||||
ToDoDialogBinding.todoContent.error =
|
toDoDialogBinding.todoContent.error =
|
||||||
getString(R.string.content_cannot_be_empty)
|
getString(R.string.content_cannot_be_empty)
|
||||||
} else {
|
} else {
|
||||||
if (todoContent == "/DEV_MODE") {
|
if (todoContent == "/DEV_MODE") {
|
||||||
|
|
@ -104,7 +104,7 @@ class ToDoFragment : Fragment() {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
} else {
|
} else {
|
||||||
val randomUUID = UUID.randomUUID().toString()
|
val randomUUID = UUID.randomUUID().toString()
|
||||||
val todoSubject = when (ToDoDialogBinding.todoSubject.checkedChipId) {
|
val todoSubject = when (toDoDialogBinding.todoSubject.checkedChipId) {
|
||||||
R.id.subject_chinese -> getString(R.string.subject_chinese)
|
R.id.subject_chinese -> getString(R.string.subject_chinese)
|
||||||
R.id.subject_math -> getString(R.string.subject_math)
|
R.id.subject_math -> getString(R.string.subject_math)
|
||||||
R.id.subject_english -> getString(R.string.subject_english)
|
R.id.subject_english -> getString(R.string.subject_english)
|
||||||
|
|
@ -124,7 +124,7 @@ class ToDoFragment : Fragment() {
|
||||||
|
|
||||||
// 添加到RecyclerView
|
// 添加到RecyclerView
|
||||||
todoList.add(
|
todoList.add(
|
||||||
ToDo(randomUUID, todoContent, todoSubject)
|
ToDo(randomUUID, 0, todoContent, todoSubject)
|
||||||
)
|
)
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@ class ToDoFragmentViewModel : ViewModel() {
|
||||||
loadToDos()
|
loadToDos()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadToDos(){
|
private fun loadToDos() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val todos = Repository.getAllUncomplete()
|
val todos = Repository.getAllUncomplete()
|
||||||
var count = 0
|
var count = 0
|
||||||
for (todo in todos) {
|
for (todo in todos) {
|
||||||
todoList.add(ToDo(todo.uuid, todo.content, todo.subject))
|
todoList.add(ToDo(todo.uuid, todo.state, todo.content, todo.subject))
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|
|
||||||
61
app/src/main/res/layout/bottom_sheet_info.xml
Normal file
61
app/src/main/res/layout/bottom_sheet_info.xml
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
|
||||||
|
android:id="@+id/drag_handle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
android:id="@+id/scroll_content_info"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="40dp"
|
||||||
|
android:layout_marginRight="40dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/todo_content_info"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="测试"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="25sp" />
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/todo_uuid"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/todo_subject_info"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/todo_state"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="45dp"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
style="?attr/materialCardViewElevatedStyle"
|
style="?attr/materialCardViewElevatedStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
android:layout_height="80dp"
|
android:layout_height="80dp"
|
||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
|
|
|
||||||
|
|
@ -64,4 +64,8 @@
|
||||||
<string name="view_all_tasks_label">查看全部待办</string>
|
<string name="view_all_tasks_label">查看全部待办</string>
|
||||||
<string name="all_tasks_label">全部代办</string>
|
<string name="all_tasks_label">全部代办</string>
|
||||||
<string name="view_all_tasks_summary">查看包含已完成的待办在内的全部待办</string>
|
<string name="view_all_tasks_summary">查看包含已完成的待办在内的全部待办</string>
|
||||||
|
<string name="info_subject">学科:%s</string>
|
||||||
|
<string name="info_state_complete">状态:已完成</string>
|
||||||
|
<string name="info_state_incomplete">状态:未完成</string>
|
||||||
|
<string name="info_uuid">UUID:%s</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -64,4 +64,8 @@
|
||||||
<string name="view_all_tasks_label">View all tasks</string>
|
<string name="view_all_tasks_label">View all tasks</string>
|
||||||
<string name="all_tasks_label">All tasks</string>
|
<string name="all_tasks_label">All tasks</string>
|
||||||
<string name="view_all_tasks_summary">View all tasks including those that have been checked as completed</string>
|
<string name="view_all_tasks_summary">View all tasks including those that have been checked as completed</string>
|
||||||
|
<string name="info_subject">Subject: %s</string>
|
||||||
|
<string name="info_state_complete">State: complete</string>
|
||||||
|
<string name="info_state_incomplete">State: incomplete</string>
|
||||||
|
<string name="info_uuid">UUID: %s</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in a new issue