From 98a78dd7177aabd65b371a59ff499196e8c76095 Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:18:12 +0800 Subject: [PATCH] Add detail information view of tasks --- .../cn/super12138/todo/logic/model/ToDo.kt | 2 +- .../todo/views/all/AllTasksActivity.kt | 2 +- .../todo/views/all/AllTasksAdapter.kt | 16 +++- .../todo/views/all/AllTasksViewModel.kt | 2 +- .../todo/views/all/InfoBottomSheet.kt | 82 +++++++++++++++++++ .../super12138/todo/views/todo/ToDoAdapter.kt | 3 +- .../todo/views/todo/ToDoFragment.kt | 14 ++-- .../todo/views/todo/ToDoFragmentViewModel.kt | 4 +- app/src/main/res/layout/bottom_sheet_info.xml | 61 ++++++++++++++ app/src/main/res/layout/item_all_tasks.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + 12 files changed, 181 insertions(+), 15 deletions(-) create mode 100644 app/src/main/kotlin/cn/super12138/todo/views/all/InfoBottomSheet.kt create mode 100644 app/src/main/res/layout/bottom_sheet_info.xml 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 b64f421..4c900ed 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,5 +1,5 @@ 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 } \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksActivity.kt b/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksActivity.kt index 7531df6..a65dff3 100644 --- a/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksActivity.kt +++ b/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksActivity.kt @@ -34,7 +34,7 @@ class AllTasksActivity : BaseActivity() { val layoutManager = LinearLayoutManager(ToDoApplication.context) binding.allTasksList.layoutManager = layoutManager - val adapter = AllTasksAdapter(viewModel.todoListAll) + val adapter = AllTasksAdapter(viewModel.todoListAll, supportFragmentManager) binding.allTasksList.adapter = adapter FastScrollerBuilder(binding.allTasksList).apply { diff --git a/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksAdapter.kt b/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksAdapter.kt index bc4f28f..21fb946 100644 --- a/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksAdapter.kt +++ b/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksAdapter.kt @@ -4,11 +4,13 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import cn.super12138.todo.R import cn.super12138.todo.logic.model.ToDo -class AllTasksAdapter(private val todoList: MutableList) : +class AllTasksAdapter(private val todoList: MutableList, + private val fragmentManager: FragmentManager) : RecyclerView.Adapter() { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { @@ -27,6 +29,18 @@ class AllTasksAdapter(private val todoList: MutableList) : val todo = todoList[position] holder.todoContext.text = todo.content 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) { holder.itemView.alpha = 0f holder.itemView.animate().alpha(1f).duration = 200 diff --git a/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksViewModel.kt b/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksViewModel.kt index d833540..1f380d0 100644 --- a/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksViewModel.kt +++ b/app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksViewModel.kt @@ -21,7 +21,7 @@ class AllTasksViewModel : ViewModel() { val todos = Repository.getAll() var count = 0 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++ } if (count == 0) { diff --git a/app/src/main/kotlin/cn/super12138/todo/views/all/InfoBottomSheet.kt b/app/src/main/kotlin/cn/super12138/todo/views/all/InfoBottomSheet.kt new file mode 100644 index 0000000..dcc6f55 --- /dev/null +++ b/app/src/main/kotlin/cn/super12138/todo/views/all/InfoBottomSheet.kt @@ -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) + } + } + } +} \ 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 1d13f46..3eec8a9 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 @@ -27,7 +27,6 @@ class ToDoAdapter(val todoList: MutableList, val viewModelStoreOwner: View val delToDoBtn: Button = view.findViewById(R.id.delete_item_btn) } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val progressViewModel = ViewModelProvider(viewModelStoreOwner).get(ProgressFragmentViewModel::class.java) @@ -91,7 +90,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.content, todo.subject)) + todoList.add(ToDo(todo.uuid,0 , todo.content, todo.subject)) todoViewModel.refreshData.value = 1 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 6f1c8ee..3e3dbff 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 @@ -28,7 +28,7 @@ import java.util.UUID class ToDoFragment : Fragment() { private lateinit var binding: FragmentTodoBinding - private lateinit var ToDoDialogBinding: DialogAddTodoBinding + private lateinit var toDoDialogBinding: DialogAddTodoBinding override fun onCreateView( inflater: LayoutInflater, @@ -74,19 +74,19 @@ class ToDoFragment : Fragment() { } binding.addItem.setOnClickListener { - ToDoDialogBinding = DialogAddTodoBinding.inflate(layoutInflater) + toDoDialogBinding = DialogAddTodoBinding.inflate(layoutInflater) activity?.let { it1 -> val dialog = MaterialAlertDialogBuilder(it1) .setTitle(R.string.add_task) - .setView(ToDoDialogBinding.root) + .setView(toDoDialogBinding.root) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .show() dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val todoContent = ToDoDialogBinding.todoContent.editText?.text.toString() + val todoContent = toDoDialogBinding.todoContent.editText?.text.toString() if (todoContent.isEmpty()) { - ToDoDialogBinding.todoContent.error = + toDoDialogBinding.todoContent.error = getString(R.string.content_cannot_be_empty) } else { if (todoContent == "/DEV_MODE") { @@ -104,7 +104,7 @@ class ToDoFragment : Fragment() { dialog.dismiss() } else { 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_math -> getString(R.string.subject_math) R.id.subject_english -> getString(R.string.subject_english) @@ -124,7 +124,7 @@ class ToDoFragment : Fragment() { // 添加到RecyclerView todoList.add( - ToDo(randomUUID, todoContent, todoSubject) + ToDo(randomUUID, 0, todoContent, todoSubject) ) lifecycleScope.launch { diff --git a/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragmentViewModel.kt b/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragmentViewModel.kt index 7d315b3..57f96a4 100644 --- a/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragmentViewModel.kt +++ b/app/src/main/kotlin/cn/super12138/todo/views/todo/ToDoFragmentViewModel.kt @@ -17,12 +17,12 @@ class ToDoFragmentViewModel : ViewModel() { loadToDos() } - private fun loadToDos(){ + private fun loadToDos() { viewModelScope.launch { val todos = Repository.getAllUncomplete() var count = 0 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++ } if (count == 0) { diff --git a/app/src/main/res/layout/bottom_sheet_info.xml b/app/src/main/res/layout/bottom_sheet_info.xml new file mode 100644 index 0000000..9488d67 --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet_info.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_all_tasks.xml b/app/src/main/res/layout/item_all_tasks.xml index 4376940..f6cd093 100644 --- a/app/src/main/res/layout/item_all_tasks.xml +++ b/app/src/main/res/layout/item_all_tasks.xml @@ -2,6 +2,8 @@ 查看全部待办 全部代办 查看包含已完成的待办在内的全部待办 + 学科:%s + 状态:已完成 + 状态:未完成 + UUID:%s \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5f97e5..d91a7de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,4 +64,8 @@ View all tasks All tasks View all tasks including those that have been checked as completed + Subject: %s + State: complete + State: incomplete + UUID: %s \ No newline at end of file