Skip to content

Commit

Permalink
Fixed reminded task may shows incorrect task
Browse files Browse the repository at this point in the history
[Change dropWhile to filter for fix reminded task list issue]
  • Loading branch information
Z-Siqi committed Sep 28, 2024
1 parent 1f0ce40 commit 103d395
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class TaskLayoutViewModel : ViewModel() {
val listState: StateFlow<ListData> = _listState.asStateFlow()
fun updateListState(init: Boolean = false) = viewModelScope.launch {
_listState.update { lists ->
val remindedList = MainActivity.taskDatabase.taskDao().getIsRemindedList().dropWhile {
val remindedList = MainActivity.taskDatabase.taskDao().getIsRemindedList().filter {
val parts = it.reminder?.split(":")
val timeMillisData = if (parts?.size!! >= 2) parts[1].toLong() else -1L
if (timeMillisData == -1L) Log.e("LoadingList", "Task reminder data error!")
!(timeMillisData != -1L && timeMillisData < System.currentTimeMillis())
timeMillisData != -1L && timeMillisData < System.currentTimeMillis()
}
lists.copy(
item = MainActivity.taskDatabase.taskDao().getAll(withoutHistory = 1),
Expand Down Expand Up @@ -145,15 +145,11 @@ class TaskLayoutViewModel : ViewModel() {
viewModelScope.launch {
if (id != -1) MainActivity.taskDatabase.taskDao().deleteReminder(id)
if (autoDel) for (data in _listState.value.isRemindedItem) {
data.reminder?.let {
val parts = it.split(":")
if (parts.size >= 2) {
parts[0]
val time = parts[1].toLong()
if (time < System.currentTimeMillis() - 43200000) {
MainActivity.taskDatabase.taskDao().deleteReminder(data.id)
}
}
val parts = data.reminder?.split(":")
val timeMillisData = if (parts?.size!! >= 2) parts[1].toLong() else -1L
val delReminderTime = timeMillisData < System.currentTimeMillis() - 43200000
if (timeMillisData != -1L && delReminderTime) {
MainActivity.taskDatabase.taskDao().deleteReminder(data.id)
}
}
updateListState()
Expand Down

0 comments on commit 103d395

Please sign in to comment.