diff --git a/app/src/main/kotlin/cn/super12138/todo/logic/dao/ToDoRoom.kt b/app/src/main/kotlin/cn/super12138/todo/logic/dao/ToDoRoom.kt index 26dfe38..69cf07c 100644 --- a/app/src/main/kotlin/cn/super12138/todo/logic/dao/ToDoRoom.kt +++ b/app/src/main/kotlin/cn/super12138/todo/logic/dao/ToDoRoom.kt @@ -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 ) \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/logic/model/ToDo.kt b/app/src/main/kotlin/cn/super12138/todo/logic/model/ToDo.kt index b670c7b..10cc22d 100644 --- a/app/src/main/kotlin/cn/super12138/todo/logic/model/ToDo.kt +++ b/app/src/main/kotlin/cn/super12138/todo/logic/model/ToDo.kt @@ -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 -) - */ \ No newline at end of file +data class ToDo(val uuid: String, val content: String, val subject: String) \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoAdapter.kt b/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoAdapter.kt index 912845f..4ea1b2f 100644 --- a/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoAdapter.kt +++ b/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoAdapter.kt @@ -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, val viewModelStoreOwner: ViewModelStoreOwner) : RecyclerView.Adapter() { 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, 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, val viewModelStoreOwner: View todo.uuid, 0, todo.subject, - todo.context + todo.content ) ) progressViewModel.updateProgress() @@ -115,7 +114,7 @@ class ToDoAdapter(val todoList: MutableList, 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 } diff --git a/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragment.kt b/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragment.kt index 1ffcca6..4e0fa6e 100644 --- a/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragment.kt +++ b/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragment.kt @@ -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) }) } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/dialog_add_todo.xml b/app/src/main/res/layout/dialog_add_todo.xml index 5e35bb1..d35a0c4 100644 --- a/app/src/main/res/layout/dialog_add_todo.xml +++ b/app/src/main/res/layout/dialog_add_todo.xml @@ -10,7 +10,7 @@ android:orientation="vertical"> 无待办事项 撤销 该待办已删除 + 待办内容不能为空 设置 外观 深色模式 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4de340..2a3297b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,6 +33,7 @@ No tasks Undo This task has been deleted + Task content cannot be empty Settings Appearance