Skip to content

Commit 911ee3e

Browse files
committed
disallow only previous in complex rules
1 parent 1f06104 commit 911ee3e

File tree

21 files changed

+1207
-16
lines changed

21 files changed

+1207
-16
lines changed

app/src/androidTest/java/com/example/util/simpletimetracker/ComplexRulesTest.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,41 @@ class ComplexRulesTest : BaseUiTest() {
394394
checkRunningRecord(byStartingAndCurrent3)
395395
}
396396

397+
@Test
398+
fun actionDisallowMultitaskingOnlyPreviousTypes() {
399+
val startingType = "startingType"
400+
val previousType = "previousType"
401+
val otherType = "otherType"
402+
403+
// Add data
404+
runBlocking { prefsInteractor.setAllowMultitasking(true) }
405+
testUtils.addActivity(startingType)
406+
testUtils.addActivity(previousType)
407+
testUtils.addActivity(otherType)
408+
Thread.sleep(1000)
409+
410+
testUtils.addComplexRule(
411+
action = ComplexRule.Action.DisallowMultitasking,
412+
actionDisallowOnlyPrevious = true,
413+
startingTypeNames = listOf(startingType),
414+
currentTypeNames = listOf(previousType),
415+
)
416+
417+
// Check
418+
clickOnViewWithText(previousType)
419+
clickOnViewWithText(otherType)
420+
checkRunningRecord(previousType)
421+
checkRunningRecord(otherType)
422+
clickOnViewWithText(startingType)
423+
424+
checkNoRunningRecord(previousType)
425+
checkRunningRecord(otherType)
426+
checkRunningRecord(startingType)
427+
428+
stopRunningRecord(otherType)
429+
stopRunningRecord(startingType)
430+
}
431+
397432
@Test
398433
fun assignTags() {
399434
val check1 = "check1"

core/src/main/java/com/example/util/simpletimetracker/core/base/BaseViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.example.util.simpletimetracker.core.base
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import com.example.util.simpletimetracker.core.extension.allowDiskRead
56
import kotlinx.coroutines.CoroutineScope
67
import kotlinx.coroutines.Job
78

@@ -16,6 +17,6 @@ abstract class BaseViewModel :
1617
override var delayDataLoad: Boolean = true
1718

1819
override fun getScope(): CoroutineScope {
19-
return viewModelScope
20+
return allowDiskRead { viewModelScope }
2021
}
2122
}

core/src/main/java/com/example/util/simpletimetracker/core/mapper/ComplexRuleViewDataMapper.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ class ComplexRuleViewDataMapper @Inject constructor(
106106
}
107107
val result = mutableListOf<ViewHolderType>()
108108
result += ComplexRuleElementTitleViewData(
109-
text = mapActionTitle(action),
109+
text = mapActionTitle(
110+
action = action,
111+
disallowOnlyPrevious = rule.actionDisallowOnlyPrevious,
112+
),
110113
)
111114
result += data.map {
112115
ListElementViewData(
@@ -151,15 +154,23 @@ class ComplexRuleViewDataMapper @Inject constructor(
151154

152155
fun mapActionTitle(
153156
action: ComplexRule.Action,
157+
disallowOnlyPrevious: Boolean,
154158
): String {
155-
return when (action) {
159+
val title = when (action) {
156160
is ComplexRule.Action.AllowMultitasking ->
157161
R.string.settings_allow_multitasking
158162
is ComplexRule.Action.DisallowMultitasking ->
159163
R.string.settings_disallow_multitasking
160164
is ComplexRule.Action.AssignTag ->
161165
R.string.change_complex_action_assign_tag
162166
}.let(resourceRepo::getString)
167+
168+
if (action is ComplexRule.Action.DisallowMultitasking && disallowOnlyPrevious) {
169+
val detail = resourceRepo.getString(R.string.complex_rules_action_disallow_only_previous_detail)
170+
return "$title ($detail)"
171+
}
172+
173+
return title
163174
}
164175

165176
private fun mapTypes(

core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class TestUtils @Inject constructor(
323323

324324
fun addComplexRule(
325325
action: ComplexRule.Action,
326+
actionDisallowOnlyPrevious: Boolean = false,
326327
assignTagNames: List<String> = emptyList(),
327328
startingTypeNames: List<String> = emptyList(),
328329
currentTypeNames: List<String> = emptyList(),
@@ -337,6 +338,7 @@ class TestUtils @Inject constructor(
337338
val data = ComplexRule(
338339
disabled = false,
339340
action = action,
341+
actionDisallowOnlyPrevious = actionDisallowOnlyPrevious,
340342
actionAssignTagIds = assignTagIds,
341343
conditionStartingTypeIds = getTypeIds(availableTypes, startingTypeNames),
342344
conditionCurrentTypeIds = getTypeIds(availableTypes, currentTypeNames),

0 commit comments

Comments
 (0)