@@ -86,22 +86,28 @@ class HomeFragment : Fragment() {
86
86
// Update tasks and posts list when a task is done
87
87
if (intent.getStringExtra(" content" ) == " taskDone"
88
88
&& ::tasks.isInitialized) {
89
+ val taskId = intent.getStringExtra(" taskId" )
89
90
val postId = intent.getStringExtra(" postId" )
90
91
91
92
// If tasks list contains this, notify tasks aapter
92
- val taskIndex = tasks.indexOfFirst { it.id_post == postId }
93
+ val taskIndex = tasks.indexOfFirst { it.taskId == taskId }
93
94
if (taskIndex != - 1 ) {
94
95
tasksRecycler.adapter?.notifyItemChanged(taskIndex)
95
96
} else if (! intent.getBooleanExtra(" isDone" , true )) {
96
- // Add task to the top of the list if it is not done and wasn't there before
97
- tasks.add(0 , TasksDb .getInstance().getByPostId(postId).first())
98
- tasksRecycler.adapter?.notifyItemInserted(0 )
99
- tasksRecycler.adapter?.notifyItemRemoved(5 )
97
+ val taskToAdd = TasksDb .getInstance().getByTaskId(taskId).firstOrNull()
98
+ if (taskToAdd != null ) {
99
+ // Add task to the top of the list if it is not done and wasn't there before
100
+ tasks.add(0 , taskToAdd)
101
+ tasksRecycler.adapter?.notifyItemInserted(0 )
102
+ tasksRecycler.adapter?.notifyItemRemoved(5 )
103
+ }
100
104
}
101
105
102
- // If posts list contains this, notify it
103
- val postIndex = posts.indexOfFirst { it.postId == postId }
104
- if (postIndex != - 1 ) unreadPostsRecycler.adapter?.notifyItemChanged(postIndex)
106
+ if (postId != null ) {
107
+ // If posts list contains this, notify it
108
+ val postIndex = posts.indexOfFirst { it.postId == postId }
109
+ if (postIndex != - 1 ) unreadPostsRecycler.adapter?.notifyItemChanged(postIndex)
110
+ }
105
111
}
106
112
}
107
113
}
@@ -207,17 +213,16 @@ class HomeFragment : Fragment() {
207
213
tasks,
208
214
6 ,
209
215
onClick = {
210
- // Show single post bottom sheet
211
- PostSheet (
212
- PostsDb .getInstance().getByPostId(it)
213
- ).show(parentFragmentManager, " post" )
216
+ // Show single task bottom sheet
217
+ TaskSheet (it).show(parentFragmentManager, " task" )
214
218
},
215
219
onTaskCheckedChanged = AttachmentManager ().onTaskCheckedChanged(requireActivity()) { task, isDone ->
216
220
if (isDone) {
217
221
// Update tasks dataset
218
222
val index = tasks.indexOfFirst { it.taskId == task.taskId }
219
223
tasks.removeAt(index)
220
224
tasksRecycler.adapter?.notifyItemRemoved(index)
225
+ if (tasks.size < 6 ) (tasksRecycler.adapter as CompactTasksAdapter )
221
226
// Update overflow counter
222
227
if (tasksOverflow > 0 ) {
223
228
tasksOverflow--
0 commit comments