diff --git a/app/src/androidTest/java/org/tasks/ui/editviewmodel/DueDateTests.kt b/app/src/androidTest/java/org/tasks/ui/editviewmodel/DueDateTests.kt new file mode 100644 index 000000000..04d5b53a1 --- /dev/null +++ b/app/src/androidTest/java/org/tasks/ui/editviewmodel/DueDateTests.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/ui/TaskEditViewModel.kt b/app/src/main/java/org/tasks/ui/TaskEditViewModel.kt index f6788d7fe..a950948f8 100644 --- a/app/src/main/java/org/tasks/ui/TaskEditViewModel.kt +++ b/app/src/main/java/org/tasks/ui/TaskEditViewModel.kt @@ -89,12 +89,18 @@ class TaskEditViewModel @ViewModelInject constructor( var dueDate: Long? = null get() = field ?: task?.dueDate ?: 0 set(value) { + val oldDueDate = dueDate!! field = when { value == null -> null value == 0L -> 0 hasDueTime(value) -> createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, 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