Adjust hide until date

pull/1052/head
Alex Baker 4 years ago
parent 783f1bde69
commit 598399e81e

@ -0,0 +1,31 @@
package org.tasks.ui.editviewmodel
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.data.Task
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.junit.Assert.assertEquals
import org.junit.Test
import org.tasks.injection.ProductionModule
import org.tasks.makers.TaskMaker
import org.tasks.makers.TaskMaker.HIDE_TYPE
import org.tasks.makers.TaskMaker.newTask
import org.tasks.time.DateTime
import java.util.concurrent.TimeUnit
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class DueDateTests : BaseTaskEditViewModelTest() {
@Test
fun adjustHideUntilWhenChangingDate() {
val task = newTask(
with(TaskMaker.DUE_TIME, DateTime(2020, 7, 14, 16, 30, 0, 0)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
setup(task)
val newDueDate = viewModel.dueDate!! + TimeUnit.DAYS.toMillis(1)
viewModel.dueDate = newDueDate
assertEquals(newDueDate, viewModel.hideUntil)
}
}

@ -89,12 +89,18 @@ class TaskEditViewModel @ViewModelInject constructor(
var dueDate: Long? = null var dueDate: Long? = null
get() = field ?: task?.dueDate ?: 0 get() = field ?: task?.dueDate ?: 0
set(value) { set(value) {
val oldDueDate = dueDate!!
field = when { field = when {
value == null -> null value == null -> null
value == 0L -> 0 value == 0L -> 0
hasDueTime(value) -> createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, value) hasDueTime(value) -> createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, value)
else -> createDueDate(Task.URGENCY_SPECIFIC_DAY, value) else -> createDueDate(Task.URGENCY_SPECIFIC_DAY, value)
} }
if (oldDueDate > 0) {
if (hideUntil!! > 0) {
hideUntil = if (field!! > 0) hideUntil!! + field!! - oldDueDate else 0
}
}
} }
var priority: Int? = null var priority: Int? = null

Loading…
Cancel
Save