Skip to content

Commit

Permalink
Add detail information view of tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Super12138 committed Feb 21, 2024
1 parent 0bfc7f5 commit 98a78dd
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/cn/super12138/todo/logic/model/ToDo.kt
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToDo>) :
class AllTasksAdapter(private val todoList: MutableList<ToDo>,
private val fragmentManager: FragmentManager) :
RecyclerView.Adapter<AllTasksAdapter.ViewHolder>() {

inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
Expand All @@ -27,6 +29,18 @@ class AllTasksAdapter(private val todoList: MutableList<ToDo>) :
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, 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)
Expand Down Expand Up @@ -91,7 +90,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.content, todo.subject))
todoList.add(ToDo(todo.uuid,0 , todo.content, todo.subject))

todoViewModel.refreshData.value = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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") {
Expand All @@ -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)
Expand All @@ -124,7 +124,7 @@ class ToDoFragment : Fragment() {

// 添加到RecyclerView
todoList.add(
ToDo(randomUUID, todoContent, todoSubject)
ToDo(randomUUID, 0, todoContent, todoSubject)
)

lifecycleScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
61 changes: 61 additions & 0 deletions app/src/main/res/layout/bottom_sheet_info.xml
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions app/src/main/res/layout/item_all_tasks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/materialCardViewElevatedStyle"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@
<string name="view_all_tasks_label">查看全部待办</string>
<string name="all_tasks_label">全部代办</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>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@
<string name="view_all_tasks_label">View 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="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>

0 comments on commit 98a78dd

Please sign in to comment.