Add empty check in content of the task
This commit is contained in:
parent
df53280b2d
commit
254d45a02e
8 changed files with 29 additions and 35 deletions
|
|
@ -8,12 +8,12 @@ import androidx.room.PrimaryKey
|
|||
* @param uuid String 待办的uuid
|
||||
* @param state Int 待办的完成状态,0表示未完成,1表示完成
|
||||
* @param subject String 待办的学科
|
||||
* @param context String 待办的内容
|
||||
* @param content String 待办的内容
|
||||
*/
|
||||
@Entity(tableName = "todo")
|
||||
data class ToDoRoom(
|
||||
@PrimaryKey @ColumnInfo(name = "uuid") val uuid: String,
|
||||
@ColumnInfo(name = "state") val state: Int,
|
||||
@ColumnInfo(name = "subject") val subject: String,
|
||||
@ColumnInfo(name = "context") val context: String
|
||||
@ColumnInfo(name = "content") val content: String
|
||||
)
|
||||
|
|
@ -1,19 +1,3 @@
|
|||
package cn.super12138.todo.logic.model
|
||||
|
||||
data class ToDo(val uuid: String, val context: String, val subject: String)
|
||||
|
||||
/*
|
||||
package cn.super12138.todo.logic.model
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "todo")
|
||||
data class ToDo (
|
||||
@PrimaryKey @ColumnInfo(name = "uuid") val uuid: String,
|
||||
@ColumnInfo(name = "state") val state: Int,
|
||||
@ColumnInfo(name = "subject") val subject: String,
|
||||
@ColumnInfo(name = "context") val context: String
|
||||
)
|
||||
*/
|
||||
data class ToDo(val uuid: String, val content: String, val subject: String)
|
||||
|
|
@ -15,14 +15,13 @@ import cn.super12138.todo.logic.model.ToDo
|
|||
import cn.super12138.todo.views.progress.ProgressFragmentViewModel
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: ViewModelStoreOwner) :
|
||||
RecyclerView.Adapter<ToDoAdapter.ViewHolder>() {
|
||||
|
||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val todoContext: TextView = view.findViewById(R.id.todo_context)
|
||||
val todoContext: TextView = view.findViewById(R.id.todo_content)
|
||||
val todoSubject: TextView = view.findViewById(R.id.todo_subject)
|
||||
val checkToDoBtn: Button = view.findViewById(R.id.check_item_btn)
|
||||
val delToDoBtn: Button = view.findViewById(R.id.delete_item_btn)
|
||||
|
|
@ -92,7 +91,7 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: View
|
|||
if (todoList.size + 1 > 0) {
|
||||
todoViewModel.emptyTipVis.value = View.GONE
|
||||
}
|
||||
todoList.add(ToDo(todo.uuid, todo.context, todo.subject))
|
||||
todoList.add(ToDo(todo.uuid, todo.content, todo.subject))
|
||||
|
||||
todoViewModel.refreshData.value = 1
|
||||
|
||||
|
|
@ -102,7 +101,7 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: View
|
|||
todo.uuid,
|
||||
0,
|
||||
todo.subject,
|
||||
todo.context
|
||||
todo.content
|
||||
)
|
||||
)
|
||||
progressViewModel.updateProgress()
|
||||
|
|
@ -115,7 +114,7 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: View
|
|||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val todo = todoList[position]
|
||||
holder.todoContext.text = todo.context
|
||||
holder.todoContext.text = todo.content
|
||||
holder.todoSubject.text = todo.subject
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
|
@ -64,7 +65,7 @@ class ToDoFragment : Fragment() {
|
|||
val todos = Repository.getAllUncomplete()
|
||||
var count = 0
|
||||
for (todo in todos) {
|
||||
todoList.add(ToDo(todo.uuid, todo.context, todo.subject))
|
||||
todoList.add(ToDo(todo.uuid, todo.content, todo.subject))
|
||||
count++
|
||||
}
|
||||
if (count == 0) {
|
||||
|
|
@ -82,12 +83,19 @@ class ToDoFragment : Fragment() {
|
|||
ToDoDialogBinding = DialogAddTodoBinding.inflate(layoutInflater)
|
||||
|
||||
activity?.let { it1 ->
|
||||
MaterialAlertDialogBuilder(it1)
|
||||
val dialog = MaterialAlertDialogBuilder(it1)
|
||||
.setTitle(R.string.add_task)
|
||||
.setView(ToDoDialogBinding.root)
|
||||
.setPositiveButton(R.string.ok) { dialog, which ->
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val todoContent = ToDoDialogBinding.todoContent.editText?.text.toString()
|
||||
if (todoContent.isEmpty()) {
|
||||
ToDoDialogBinding.todoContent.error =
|
||||
getString(R.string.content_cannot_be_empty)
|
||||
} else {
|
||||
val randomUUID = UUID.randomUUID().toString()
|
||||
val todoContext = ToDoDialogBinding.todoContext.editText?.text.toString()
|
||||
val todoSubject = when (ToDoDialogBinding.todoSubject.checkedChipId) {
|
||||
R.id.subject_chinese -> "语文"
|
||||
R.id.subject_math -> "数学"
|
||||
|
|
@ -107,7 +115,7 @@ class ToDoFragment : Fragment() {
|
|||
|
||||
// 添加到RecyclerView
|
||||
todoList.add(
|
||||
ToDo(randomUUID, todoContext, todoSubject)
|
||||
ToDo(randomUUID, todoContent, todoSubject)
|
||||
)
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
|
@ -116,16 +124,16 @@ class ToDoFragment : Fragment() {
|
|||
randomUUID,
|
||||
0,
|
||||
todoSubject,
|
||||
todoContext
|
||||
todoContent
|
||||
)
|
||||
)
|
||||
progressViewModel.updateProgress()
|
||||
}
|
||||
|
||||
binding.todoList.adapter?.notifyItemInserted(todoList.size + 1)
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,4 +187,4 @@ class ToDoFragment : Fragment() {
|
|||
binding.todoList.adapter?.notifyItemInserted(todoList.size + 1)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/todo_context"
|
||||
android:id="@+id/todo_content"
|
||||
style="?attr/textInputFilledExposedDropdownMenuStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="?attr/materialCardViewElevatedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
|
|
@ -21,7 +22,7 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/todo_context"
|
||||
android:id="@+id/todo_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
<string name="no_tasks">无待办事项</string>
|
||||
<string name="delete_undo">撤销</string>
|
||||
<string name="task_deleted">该待办已删除</string>
|
||||
<string name="content_cannot_be_empty">待办内容不能为空</string>
|
||||
<string name="settings_label">设置</string>
|
||||
<string name="appearance">外观</string>
|
||||
<string name="dark_mode">深色模式</string>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
<string name="no_tasks">No tasks</string>
|
||||
<string name="delete_undo">Undo</string>
|
||||
<string name="task_deleted">This task has been deleted</string>
|
||||
<string name="content_cannot_be_empty">Task content cannot be empty</string>
|
||||
<!--Settings-->
|
||||
<string name="settings_label">Settings</string>
|
||||
<string name="appearance">Appearance</string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue