From c2e36238e9fc55982f31c6e303659bd07e5d16ac Mon Sep 17 00:00:00 2001 From: razeeman Date: Sat, 18 Jan 2025 16:50:05 +0300 Subject: [PATCH] fix partial data restore for existing data --- .../ChangeRunningRecordTest.kt | 2 +- .../util/simpletimetracker/GoalsDaysOfWeek.kt | 2 +- .../util/simpletimetracker/GoalsTestUtils.kt | 4 +-- .../util/simpletimetracker/StartRecordTest.kt | 2 +- .../core/interactor/RecordFilterInteractor.kt | 2 +- .../core/mapper/DayOfWeekViewDataMapper.kt | 4 +-- .../simpletimetracker/core/utils/TestUtils.kt | 2 +- .../ActivityFilterDataLocalMapper.kt | 8 ++++-- .../activityFilter/ActivityFilterRepoImpl.kt | 2 +- .../ActivitySuggestionDataLocalMapper.kt | 8 ++++-- .../ActivitySuggestionRepoImpl.kt | 2 +- .../backup/BackupPartialRepoImpl.kt | 28 +++++++++++++++---- .../data_local/backup/BackupRepoImpl.kt | 8 +++--- .../data_local/base/PrefsUtils.kt | 14 ---------- .../data_local/category/CategoryRepoImpl.kt | 2 +- .../category/RecordTypeCategoryRepoImpl.kt | 2 +- .../complexRule/ComplexRuleDataLocalMapper.kt | 2 +- .../complexRule/ComplexRuleRepoImpl.kt | 2 +- .../daysOfWeek/DaysOfWeekDataLocalMapper.kt | 6 ++-- .../favourite/FavouriteIconRepoImpl.kt | 2 +- .../record/RunningRecordRepoImpl.kt | 4 +-- .../data_local/recordTag/RecordTagRepoImpl.kt | 2 +- .../RecordTypeToDefaultTagRepoImpl.kt | 2 +- .../recordTag/RecordTypeToTagRepoImpl.kt | 2 +- .../recordType/RecordTypeGoalRepoImpl.kt | 4 +-- .../recordType/RecordTypeRepoImpl.kt | 2 +- .../interactor/ActivityFilterInteractor.kt | 2 +- .../activityFilter/model/ActivityFilter.kt | 2 +- .../ActivitySuggestionInteractor.kt | 2 +- ...GetCurrentActivitySuggestionsInteractor.kt | 3 +- .../model/ActivitySuggestion.kt | 2 +- .../domain/extension/CollectionExtensions.kt | 12 ++++++++ .../extension/RecordsFilterExtensions.kt | 3 +- .../domain/recordType/model/RecordTypeGoal.kt | 2 +- .../ChangeActivityFilterViewDataInteractor.kt | 2 +- .../ChangeActivityFilterViewModel.kt | 10 +++---- .../ChangeComplexRuleViewDataInteractor.kt | 2 +- .../delegate/GoalsViewModelDelegateImpl.kt | 12 ++++---- .../mapper/GoalsViewDataMapper.kt | 4 +-- .../viewData/ChangeRecordTypeGoalsState.kt | 2 +- .../viewModel/ChangeRecordTypeViewModel.kt | 2 +- ...icationActivitySwitchControlsInteractor.kt | 1 + .../viewModel/PartialRestoreViewModel.kt | 4 +-- .../ActivitySuggestionsCalculateInteractor.kt | 4 +-- .../ActivitySuggestionsViewDataInteractor.kt | 2 +- .../viewModel/ActivitySuggestionsViewModel.kt | 10 +++---- 46 files changed, 115 insertions(+), 88 deletions(-) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRunningRecordTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRunningRecordTest.kt index ea45aa8d3..4ab2efc9f 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRunningRecordTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRunningRecordTest.kt @@ -70,7 +70,7 @@ class ChangeRunningRecordTest : BaseUiTest() { range = RecordTypeGoal.Range.Session, type = RecordTypeGoal.Type.Duration(firstGoalTime), subtype = RecordTypeGoal.Subtype.Goal, - daysOfWeek = emptyList(), + daysOfWeek = emptySet(), ), ), ) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt index e67ec0b25..55f09bf56 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt @@ -16,7 +16,7 @@ import com.example.util.simpletimetracker.GoalsTestUtils.checkRunningGoal import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsGoal import com.example.util.simpletimetracker.GoalsTestUtils.checkTypeMark import com.example.util.simpletimetracker.core.R -import com.example.util.simpletimetracker.data_local.base.removeIf +import com.example.util.simpletimetracker.domain.extension.removeIf import com.example.util.simpletimetracker.utils.BaseUiTest import com.example.util.simpletimetracker.utils.NavUtils import com.example.util.simpletimetracker.utils.checkViewDoesNotExist diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt index 57b0e1810..226c91457 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt @@ -219,7 +219,7 @@ object GoalsTestUtils { range = range, type = RecordTypeGoal.Type.Duration(duration), subtype = RecordTypeGoal.Subtype.Goal, - daysOfWeek = DayOfWeek.entries, + daysOfWeek = DayOfWeek.entries.toSet(), ) } @@ -240,7 +240,7 @@ object GoalsTestUtils { range = range, type = RecordTypeGoal.Type.Count(count), subtype = RecordTypeGoal.Subtype.Goal, - daysOfWeek = DayOfWeek.entries, + daysOfWeek = DayOfWeek.entries.toSet(), ) } diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/StartRecordTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/StartRecordTest.kt index a7a2e84cd..5b5470304 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/StartRecordTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/StartRecordTest.kt @@ -50,7 +50,7 @@ class StartRecordTest : BaseUiTest() { range = RecordTypeGoal.Range.Session, type = RecordTypeGoal.Type.Duration(firstGoalTime), subtype = RecordTypeGoal.Subtype.Goal, - daysOfWeek = emptyList(), + daysOfWeek = emptySet(), ), ), ) diff --git a/core/src/main/java/com/example/util/simpletimetracker/core/interactor/RecordFilterInteractor.kt b/core/src/main/java/com/example/util/simpletimetracker/core/interactor/RecordFilterInteractor.kt index f119556d9..109fa1878 100644 --- a/core/src/main/java/com/example/util/simpletimetracker/core/interactor/RecordFilterInteractor.kt +++ b/core/src/main/java/com/example/util/simpletimetracker/core/interactor/RecordFilterInteractor.kt @@ -109,7 +109,7 @@ class RecordFilterInteractor @Inject constructor( val filteredTaggedIds: List = filteredTagItems.getTaggedIds() val filteredUntagged: Boolean = filteredTagItems.hasUntaggedItem() val manuallyFilteredIds: Map = filters.getManuallyFilteredRecordIds() - val daysOfWeek: List = filters.getDaysOfWeek() + val daysOfWeek: Set = filters.getDaysOfWeek() val timeOfDay: Range? = filters.getTimeOfDay() val durations: List = filters.getDuration()?.let(::listOf).orEmpty() val duplicationItems: List = filters.getDuplicationItems() diff --git a/core/src/main/java/com/example/util/simpletimetracker/core/mapper/DayOfWeekViewDataMapper.kt b/core/src/main/java/com/example/util/simpletimetracker/core/mapper/DayOfWeekViewDataMapper.kt index d09eae5c1..4c3031353 100644 --- a/core/src/main/java/com/example/util/simpletimetracker/core/mapper/DayOfWeekViewDataMapper.kt +++ b/core/src/main/java/com/example/util/simpletimetracker/core/mapper/DayOfWeekViewDataMapper.kt @@ -11,12 +11,12 @@ class DayOfWeekViewDataMapper @Inject constructor( ) { fun mapViewData( - selectedDaysOfWeek: List, + selectedDaysOfWeek: Set, isDarkTheme: Boolean, width: DayOfWeekViewData.Width, paddingHorizontalDp: Int, ): List { - return DayOfWeek.values().map { + return DayOfWeek.entries.map { val selected = it in selectedDaysOfWeek DayOfWeekViewData( dayOfWeek = it, diff --git a/core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt b/core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt index eb173c341..42e972faa 100644 --- a/core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt +++ b/core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt @@ -257,7 +257,7 @@ class TestUtils @Inject constructor( availableCategories.firstOrNull { it.name == name }?.id } } - } + }.toSet() val data = ActivityFilter( selectedIds = selectedIds, diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterDataLocalMapper.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterDataLocalMapper.kt index de5485321..ae15f5ca5 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterDataLocalMapper.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterDataLocalMapper.kt @@ -9,7 +9,10 @@ class ActivityFilterDataLocalMapper @Inject constructor() { fun map(dbo: ActivityFilterDBO): ActivityFilter { return ActivityFilter( id = dbo.id, - selectedIds = dbo.selectedIds.split(',').mapNotNull(String::toLongOrNull), + selectedIds = dbo.selectedIds + .split(',') + .mapNotNull(String::toLongOrNull) + .toSet(), type = when (dbo.type) { 0L -> ActivityFilter.Type.Activity 1L -> ActivityFilter.Type.Category @@ -27,7 +30,8 @@ class ActivityFilterDataLocalMapper @Inject constructor() { fun map(domain: ActivityFilter): ActivityFilterDBO { return ActivityFilterDBO( id = domain.id, - selectedIds = domain.selectedIds.joinToString(separator = ","), + selectedIds = domain.selectedIds + .joinToString(separator = ","), type = when (domain.type) { is ActivityFilter.Type.Activity -> 0L is ActivityFilter.Type.Category -> 1L diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterRepoImpl.kt index 9b40d3fe3..0de88bb53 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activityFilter/ActivityFilterRepoImpl.kt @@ -1,9 +1,9 @@ package com.example.util.simpletimetracker.data_local.activityFilter import com.example.util.simpletimetracker.data_local.base.withLockedCache -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.domain.activityFilter.model.ActivityFilter import com.example.util.simpletimetracker.domain.activityFilter.repo.ActivityFilterRepo +import com.example.util.simpletimetracker.domain.extension.removeIf import kotlinx.coroutines.sync.Mutex import javax.inject.Inject import javax.inject.Singleton diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionDataLocalMapper.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionDataLocalMapper.kt index 88b02ee5d..d4acef234 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionDataLocalMapper.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionDataLocalMapper.kt @@ -9,7 +9,10 @@ class ActivitySuggestionDataLocalMapper @Inject constructor() { return ActivitySuggestion( id = dbo.id, forTypeId = dbo.forTypeId, - suggestionIds = dbo.suggestionIds.split(',').mapNotNull(String::toLongOrNull), + suggestionIds = dbo.suggestionIds + .split(',') + .mapNotNull(String::toLongOrNull) + .toSet(), ) } @@ -17,7 +20,8 @@ class ActivitySuggestionDataLocalMapper @Inject constructor() { return ActivitySuggestionDBO( id = domain.id, forTypeId = domain.forTypeId, - suggestionIds = domain.suggestionIds.joinToString(separator = ","), + suggestionIds = domain.suggestionIds + .joinToString(separator = ","), ) } } \ No newline at end of file diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionRepoImpl.kt index 3b5b0d4f3..1a93c51be 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/activitySuggestion/ActivitySuggestionRepoImpl.kt @@ -1,9 +1,9 @@ package com.example.util.simpletimetracker.data_local.activitySuggestion -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.data_local.base.withLockedCache import com.example.util.simpletimetracker.domain.activitySuggestion.model.ActivitySuggestion import com.example.util.simpletimetracker.domain.activitySuggestion.repo.ActivitySuggestionRepo +import com.example.util.simpletimetracker.domain.extension.removeIf import kotlinx.coroutines.sync.Mutex import javax.inject.Inject import javax.inject.Singleton diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupPartialRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupPartialRepoImpl.kt index 662fcb637..103d7220c 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupPartialRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupPartialRepoImpl.kt @@ -155,6 +155,7 @@ class BackupPartialRepoImpl @Inject constructor( params.data.activityFilters.values.getNotExistingValues().forEach { activityFilter -> val newTypeIds = activityFilter.selectedIds .mapNotNull { originalTypeIdToAddedId[it] } + .toSet() activityFilter.copy( id = 0, selectedIds = newTypeIds, @@ -210,7 +211,7 @@ class BackupPartialRepoImpl @Inject constructor( originalTypeIdToAddedId[it] }.takeIf { it.isNotEmpty() - } ?: return@forEach + }?.toSet() ?: return@forEach // Remove already existing suggestions for this typeId // to avoid duplications. activitySuggestionRepo.getByTypeId(newForTypeId) @@ -384,7 +385,7 @@ class BackupPartialRepoImpl @Inject constructor( } else { it } - } + }.toSet() item.copy( selectedIds = newTypeIds, ) @@ -441,7 +442,7 @@ class BackupPartialRepoImpl @Inject constructor( ?: return@mapNotNull null val newSuggestionIds = item.suggestionIds.mapNotNull { originalTypeIdToExistingId[it] - } + }.toSet() item.copy( forTypeId = newForTypeId, suggestionIds = newSuggestionIds, @@ -479,6 +480,18 @@ class BackupPartialRepoImpl @Inject constructor( ) } + @Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_ANY") + private fun getCleanItem( + value: T, + ): T { + return when (value) { + is RecordType -> value.copy(hidden = false) + is RecordTag -> value.copy(archived = false) + is ComplexRule -> value.copy(disabled = false) + else -> value + } as T + } + @Suppress("UNCHECKED_CAST") private fun getIdData( value: T?, @@ -508,13 +521,18 @@ class BackupPartialRepoImpl @Inject constructor( currentData: List, ): ReadData { if (dataFromFile.isEmpty()) return ReadData(emptyList(), emptyMap()) + val idData = getIdData(dataFromFile.firstOrNull()) val replaceId: T.(Long) -> T = { id -> idData.idSetter(this, id) } val id: T.() -> Long = { idData.idGetter(this) } - val currentDataClean: Map = currentData.associate { it.replaceId(0) to it.id() } + val clean: T.() -> T = { getCleanItem(this) } + + val currentDataClean: Map = currentData.associate { + it.replaceId(0).clean() to it.id() + } val originalIdsToExistingId = mutableMapOf() val list = dataFromFile.map { item -> - val cleanItem = item.replaceId(0) + val cleanItem = item.replaceId(0).clean() val existingId = currentDataClean[cleanItem] val itemId = item.id() if (itemId != 0L) { diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupRepoImpl.kt index 2cbbad90f..614c28494 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/backup/BackupRepoImpl.kt @@ -545,7 +545,7 @@ class BackupRepoImpl @Inject constructor( is ComplexRule.Action.AssignTag -> 2L }.toString() val daysOfWeekString = daysOfWeekDataLocalMapper - .mapDaysOfWeek(complexRule.conditionDaysOfWeek.toList()) + .mapDaysOfWeek(complexRule.conditionDaysOfWeek) return String.format( "$ROW_COMPLEX_RULE\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", @@ -577,7 +577,7 @@ class BackupRepoImpl @Inject constructor( val weeklyGoalTime = parts.getOrNull(9)?.toLongOrNull().orZero() val monthlyGoalTime = parts.getOrNull(10)?.toLongOrNull().orZero() // Didn't exist when goal time was in type db, no need to migrate. - val daysOfWeek = DayOfWeek.entries + val daysOfWeek = DayOfWeek.entries.toSet() val subtype = RecordTypeGoal.Subtype.Goal val goalTimes = mutableListOf().apply { @@ -719,7 +719,7 @@ class BackupRepoImpl @Inject constructor( return ActivityFilter( id = parts.getOrNull(1)?.toLongOrNull().orZero(), selectedIds = parts.getOrNull(2)?.split(",") - ?.mapNotNull { it.toLongOrNull() }.orEmpty(), + ?.mapNotNull { it.toLongOrNull() }.orEmpty().toSet(), type = parts.getOrNull(3)?.toLongOrNull()?.let { when (it) { 0L -> ActivityFilter.Type.Activity @@ -825,7 +825,7 @@ class BackupRepoImpl @Inject constructor( id = parts.getOrNull(1)?.toLongOrNull().orZero(), forTypeId = parts.getOrNull(2)?.toLongOrNull().orZero(), suggestionIds = parts.getOrNull(3)?.split(",") - ?.mapNotNull { it.toLongOrNull() }.orEmpty(), + ?.mapNotNull { it.toLongOrNull() }.orEmpty().toSet(), ) } diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/base/PrefsUtils.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/base/PrefsUtils.kt index aff563f14..563260184 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/base/PrefsUtils.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/base/PrefsUtils.kt @@ -108,17 +108,3 @@ internal inline fun logDataAccess(logMessage: String) { internal inline fun logPrefsDataAccess(logMessage: String) { logDataAccessInternal("$LOG_MESSAGE_PREFS_PREFIX $logMessage") } - -/** - * Produces a new list from original list by removing elements satisfying filter block. - */ -inline fun List.removeIf(crossinline filter: (T) -> Boolean): List { - return this.toMutableList().apply { removeAll { filter(it) } } -} - -/** - * Produces a new list from original list by replacing elements satisfying filter block with new element. - */ -inline fun List.replaceWith(new: T, crossinline filter: (T) -> Boolean): List { - return this.removeIf(filter).toMutableList().apply { add(new) } -} \ No newline at end of file diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/CategoryRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/CategoryRepoImpl.kt index be18e78de..2d639d1da 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/CategoryRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/CategoryRepoImpl.kt @@ -1,9 +1,9 @@ package com.example.util.simpletimetracker.data_local.category import com.example.util.simpletimetracker.data_local.base.withLockedCache -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.domain.category.model.Category import com.example.util.simpletimetracker.domain.category.repo.CategoryRepo +import com.example.util.simpletimetracker.domain.extension.removeIf import kotlinx.coroutines.sync.Mutex import javax.inject.Inject import javax.inject.Singleton diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/RecordTypeCategoryRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/RecordTypeCategoryRepoImpl.kt index 8df32d3a7..6902ed461 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/RecordTypeCategoryRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/category/RecordTypeCategoryRepoImpl.kt @@ -1,9 +1,9 @@ package com.example.util.simpletimetracker.data_local.category -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.data_local.base.withLockedCache import com.example.util.simpletimetracker.domain.category.model.RecordTypeCategory import com.example.util.simpletimetracker.domain.category.repo.RecordTypeCategoryRepo +import com.example.util.simpletimetracker.domain.extension.removeIf import kotlinx.coroutines.sync.Mutex import javax.inject.Inject import javax.inject.Singleton diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleDataLocalMapper.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleDataLocalMapper.kt index f0f1fe451..8808056bd 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleDataLocalMapper.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleDataLocalMapper.kt @@ -30,7 +30,7 @@ class ComplexRuleDataLocalMapper @Inject constructor( conditionStartingTypeIds = mapIds(domain.conditionStartingTypeIds), conditionCurrentTypeIds = mapIds(domain.conditionCurrentTypeIds), conditionDaysOfWeek = daysOfWeekDataLocalMapper - .mapDaysOfWeek(domain.conditionDaysOfWeek.toList()), + .mapDaysOfWeek(domain.conditionDaysOfWeek), ) } diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleRepoImpl.kt index 5bbcc3b87..ab3dbbb3e 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/complexRule/ComplexRuleRepoImpl.kt @@ -1,9 +1,9 @@ package com.example.util.simpletimetracker.data_local.complexRule -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.data_local.base.withLockedCache import com.example.util.simpletimetracker.domain.complexRule.model.ComplexRule import com.example.util.simpletimetracker.domain.complexRule.repo.ComplexRuleRepo +import com.example.util.simpletimetracker.domain.extension.removeIf import kotlinx.coroutines.sync.Mutex import javax.inject.Inject import javax.inject.Singleton diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/daysOfWeek/DaysOfWeekDataLocalMapper.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/daysOfWeek/DaysOfWeekDataLocalMapper.kt index f4ee567ac..c9879e98a 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/daysOfWeek/DaysOfWeekDataLocalMapper.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/daysOfWeek/DaysOfWeekDataLocalMapper.kt @@ -5,7 +5,7 @@ import javax.inject.Inject class DaysOfWeekDataLocalMapper @Inject constructor() { - fun mapDaysOfWeek(dbo: String): List { + fun mapDaysOfWeek(dbo: String): Set { return daysOfWeek.mapIndexedNotNull { index, dayOfWeek -> when (dbo.getOrNull(index)) { // Selected days are marked with 1, days that are not selected - with 0, @@ -15,10 +15,10 @@ class DaysOfWeekDataLocalMapper @Inject constructor() { '0' -> null else -> null } - } + }.toSet() } - fun mapDaysOfWeek(domain: List): String { + fun mapDaysOfWeek(domain: Set): String { return daysOfWeek.map { dayOfWeek -> if (dayOfWeek in domain) '1' else '0' }.joinToString(separator = "") diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/favourite/FavouriteIconRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/favourite/FavouriteIconRepoImpl.kt index a00c3e42b..eece133bc 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/favourite/FavouriteIconRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/favourite/FavouriteIconRepoImpl.kt @@ -1,7 +1,7 @@ package com.example.util.simpletimetracker.data_local.favourite -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.data_local.base.withLockedCache +import com.example.util.simpletimetracker.domain.extension.removeIf import com.example.util.simpletimetracker.domain.favourite.model.FavouriteIcon import com.example.util.simpletimetracker.domain.favourite.repo.FavouriteIconRepo import kotlinx.coroutines.sync.Mutex diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/record/RunningRecordRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/record/RunningRecordRepoImpl.kt index c7a598485..0e67e0d51 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/record/RunningRecordRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/record/RunningRecordRepoImpl.kt @@ -1,10 +1,10 @@ package com.example.util.simpletimetracker.data_local.record import com.example.util.simpletimetracker.data_local.base.logDataAccess -import com.example.util.simpletimetracker.data_local.base.removeIf -import com.example.util.simpletimetracker.data_local.base.replaceWith import com.example.util.simpletimetracker.data_local.base.withLockedCache import com.example.util.simpletimetracker.domain.extension.dropMillis +import com.example.util.simpletimetracker.domain.extension.removeIf +import com.example.util.simpletimetracker.domain.extension.replaceWith import com.example.util.simpletimetracker.domain.record.model.RunningRecord import com.example.util.simpletimetracker.domain.record.repo.RunningRecordRepo import kotlinx.coroutines.sync.Mutex diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTagRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTagRepoImpl.kt index 9a31ef452..5bb40fd33 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTagRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTagRepoImpl.kt @@ -1,7 +1,7 @@ package com.example.util.simpletimetracker.data_local.recordTag import com.example.util.simpletimetracker.data_local.base.withLockedCache -import com.example.util.simpletimetracker.data_local.base.removeIf +import com.example.util.simpletimetracker.domain.extension.removeIf import com.example.util.simpletimetracker.domain.recordTag.model.RecordTag import com.example.util.simpletimetracker.domain.recordTag.repo.RecordTagRepo import kotlinx.coroutines.sync.Mutex diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToDefaultTagRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToDefaultTagRepoImpl.kt index dbf2d5a71..e2f5ef23a 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToDefaultTagRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToDefaultTagRepoImpl.kt @@ -1,7 +1,7 @@ package com.example.util.simpletimetracker.data_local.recordTag -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.data_local.base.withLockedCache +import com.example.util.simpletimetracker.domain.extension.removeIf import com.example.util.simpletimetracker.domain.recordTag.model.RecordTypeToDefaultTag import com.example.util.simpletimetracker.domain.recordTag.repo.RecordTypeToDefaultTagRepo import kotlinx.coroutines.sync.Mutex diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToTagRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToTagRepoImpl.kt index a75f9f57e..959ce1c3a 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToTagRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordTag/RecordTypeToTagRepoImpl.kt @@ -1,7 +1,7 @@ package com.example.util.simpletimetracker.data_local.recordTag -import com.example.util.simpletimetracker.data_local.base.removeIf import com.example.util.simpletimetracker.data_local.base.withLockedCache +import com.example.util.simpletimetracker.domain.extension.removeIf import com.example.util.simpletimetracker.domain.recordTag.model.RecordTypeToTag import com.example.util.simpletimetracker.domain.recordTag.repo.RecordTypeToTagRepo import kotlinx.coroutines.sync.Mutex diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeGoalRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeGoalRepoImpl.kt index e3dac6b64..ed6eb4743 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeGoalRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeGoalRepoImpl.kt @@ -1,9 +1,9 @@ package com.example.util.simpletimetracker.data_local.recordType import com.example.util.simpletimetracker.data_local.base.logDataAccess -import com.example.util.simpletimetracker.data_local.base.removeIf -import com.example.util.simpletimetracker.data_local.base.replaceWith import com.example.util.simpletimetracker.data_local.base.withLockedCache +import com.example.util.simpletimetracker.domain.extension.removeIf +import com.example.util.simpletimetracker.domain.extension.replaceWith import com.example.util.simpletimetracker.domain.recordType.model.RecordTypeGoal import com.example.util.simpletimetracker.domain.recordType.model.RecordTypeGoal.IdData import com.example.util.simpletimetracker.domain.recordType.repo.RecordTypeGoalRepo diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeRepoImpl.kt index f08b7819e..bec78f0e7 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/recordType/RecordTypeRepoImpl.kt @@ -1,7 +1,7 @@ package com.example.util.simpletimetracker.data_local.recordType import com.example.util.simpletimetracker.data_local.base.withLockedCache -import com.example.util.simpletimetracker.data_local.base.removeIf +import com.example.util.simpletimetracker.domain.extension.removeIf import com.example.util.simpletimetracker.domain.recordType.model.RecordType import com.example.util.simpletimetracker.domain.recordType.repo.RecordTypeRepo import kotlinx.coroutines.sync.Mutex diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/interactor/ActivityFilterInteractor.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/interactor/ActivityFilterInteractor.kt index f819ff6be..7c3bd01f4 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/interactor/ActivityFilterInteractor.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/interactor/ActivityFilterInteractor.kt @@ -41,7 +41,7 @@ class ActivityFilterInteractor @Inject constructor( getByTypeId(id).forEach { filter -> val newFilter = filter.copy( selectedIds = filter.selectedIds - .toMutableList() + .toMutableSet() .apply { removeAll { it == id } }, ) add(newFilter) diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/model/ActivityFilter.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/model/ActivityFilter.kt index 54f165376..c3c7a757f 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/model/ActivityFilter.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/activityFilter/model/ActivityFilter.kt @@ -4,7 +4,7 @@ import com.example.util.simpletimetracker.domain.color.model.AppColor data class ActivityFilter( val id: Long = 0, - val selectedIds: List, + val selectedIds: Set, val type: Type, val name: String, val color: AppColor, diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/ActivitySuggestionInteractor.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/ActivitySuggestionInteractor.kt index a9944905e..49989d7b0 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/ActivitySuggestionInteractor.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/ActivitySuggestionInteractor.kt @@ -39,7 +39,7 @@ class ActivitySuggestionInteractor @Inject constructor( } if (id in suggestion.suggestionIds) { val newSuggestions = suggestion.suggestionIds - .toMutableList() + .toMutableSet() .apply { removeAll { it == id } } suggestionsToChange += suggestion.copy( suggestionIds = newSuggestions, diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/GetCurrentActivitySuggestionsInteractor.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/GetCurrentActivitySuggestionsInteractor.kt index 85b7b1ba2..9541a321d 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/GetCurrentActivitySuggestionsInteractor.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/interactor/GetCurrentActivitySuggestionsInteractor.kt @@ -35,7 +35,7 @@ class GetCurrentActivitySuggestionsInteractor @Inject constructor( private suspend fun execute( runningRecords: List, - ): List { + ): Set { val currentOrLast = runningRecords.minByOrNull { it.timeStarted } ?: recordInteractor.getAllPrev(System.currentTimeMillis()).firstOrNull() @@ -46,5 +46,6 @@ class GetCurrentActivitySuggestionsInteractor @Inject constructor( ?.firstOrNull() ?.suggestionIds .orEmpty() + .toSet() } } \ No newline at end of file diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/model/ActivitySuggestion.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/model/ActivitySuggestion.kt index 9f08b69d4..a6e239d10 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/model/ActivitySuggestion.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/activitySuggestion/model/ActivitySuggestion.kt @@ -3,5 +3,5 @@ package com.example.util.simpletimetracker.domain.activitySuggestion.model data class ActivitySuggestion( val id: Long = 0, val forTypeId: Long, - val suggestionIds: List, + val suggestionIds: Set, ) \ No newline at end of file diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/extension/CollectionExtensions.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/extension/CollectionExtensions.kt index 306333364..5cb321493 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/extension/CollectionExtensions.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/extension/CollectionExtensions.kt @@ -17,4 +17,16 @@ fun MutableMap.addOrRemove(item: T, value: U) { operator fun MutableCollection.plusAssign(element: T?) { if (element != null) this.add(element) +} + +inline fun List.removeIf(crossinline filter: (T) -> Boolean): List { + return this.toMutableList().apply { removeAll { filter(it) } } +} + +inline fun Set.removeIf(crossinline filter: (T) -> Boolean): Set { + return this.toMutableSet().apply { removeAll { filter(it) } } +} + +inline fun List.replaceWith(new: T, crossinline filter: (T) -> Boolean): List { + return this.removeIf(filter).toMutableList().apply { add(new) } } \ No newline at end of file diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/record/extension/RecordsFilterExtensions.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/record/extension/RecordsFilterExtensions.kt index 15eda6b9b..2b33ecd63 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/record/extension/RecordsFilterExtensions.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/record/extension/RecordsFilterExtensions.kt @@ -89,10 +89,11 @@ fun List.getManuallyFilteredRecordIds(): Map { .associateWith { true } } -fun List.getDaysOfWeek(): List { +fun List.getDaysOfWeek(): Set { return filterIsInstance() .map(RecordsFilter.DaysOfWeek::items) .flatten() + .toSet() } fun List.getTimeOfDay(): Range? { diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/recordType/model/RecordTypeGoal.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/recordType/model/RecordTypeGoal.kt index 5b33b9c4e..efdf45ffb 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/recordType/model/RecordTypeGoal.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/recordType/model/RecordTypeGoal.kt @@ -8,7 +8,7 @@ data class RecordTypeGoal( val range: Range, val type: Type, val subtype: Subtype, - val daysOfWeek: List, + val daysOfWeek: Set, ) { sealed interface IdData { diff --git a/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/interactor/ChangeActivityFilterViewDataInteractor.kt b/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/interactor/ChangeActivityFilterViewDataInteractor.kt index e14f0053d..a9687d6fc 100644 --- a/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/interactor/ChangeActivityFilterViewDataInteractor.kt +++ b/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/interactor/ChangeActivityFilterViewDataInteractor.kt @@ -24,7 +24,7 @@ class ChangeActivityFilterViewDataInteractor @Inject constructor( suspend fun getTypesViewData( type: ActivityFilter.Type, - selectedIds: List, + selectedIds: Set, ): ChangeActivityFilterTypesViewData { val numberOfCards = prefsInteractor.getNumberOfCards() val isDarkTheme = prefsInteractor.getDarkMode() diff --git a/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/viewModel/ChangeActivityFilterViewModel.kt b/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/viewModel/ChangeActivityFilterViewModel.kt index 35f36f96d..7994c8593 100644 --- a/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/viewModel/ChangeActivityFilterViewModel.kt +++ b/features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/viewModel/ChangeActivityFilterViewModel.kt @@ -87,13 +87,13 @@ class ChangeActivityFilterViewModel @Inject constructor( val keyboardVisibility: LiveData by lazy { MutableLiveData(filterId == 0L) } private val filterId: Long get() = (extra as? ChangeActivityFilterParams.Change)?.id.orZero() - private val newSelectedIds: List + private val newSelectedIds: Set get() = when (newType) { is ActivityFilter.Type.Activity -> newTypeIds is ActivityFilter.Type.Category -> newCategoryIds } - private var newTypeIds: MutableList = mutableListOf() - private var newCategoryIds: MutableList = mutableListOf() + private var newTypeIds: MutableSet = mutableSetOf() + private var newCategoryIds: MutableSet = mutableSetOf() private var newType: ActivityFilter.Type = ActivityFilter.Type.Activity private var newName: String = "" private var wasSelected: Boolean = true @@ -231,10 +231,10 @@ class ChangeActivityFilterViewModel @Inject constructor( activityFilterInteractor.get(filterId)?.let { when (it.type) { is ActivityFilter.Type.Activity -> { - newTypeIds = it.selectedIds.toMutableList() + newTypeIds = it.selectedIds.toMutableSet() } is ActivityFilter.Type.Category -> { - newCategoryIds = it.selectedIds.toMutableList() + newCategoryIds = it.selectedIds.toMutableSet() } } newType = it.type diff --git a/features/feature_change_complex_rule/src/main/java/com/example/util/simpletimetracker/feature_change_complex_rule/interactor/ChangeComplexRuleViewDataInteractor.kt b/features/feature_change_complex_rule/src/main/java/com/example/util/simpletimetracker/feature_change_complex_rule/interactor/ChangeComplexRuleViewDataInteractor.kt index c16640cb2..3a8786606 100644 --- a/features/feature_change_complex_rule/src/main/java/com/example/util/simpletimetracker/feature_change_complex_rule/interactor/ChangeComplexRuleViewDataInteractor.kt +++ b/features/feature_change_complex_rule/src/main/java/com/example/util/simpletimetracker/feature_change_complex_rule/interactor/ChangeComplexRuleViewDataInteractor.kt @@ -106,7 +106,7 @@ class ChangeComplexRuleViewDataInteractor @Inject constructor( ): ChangeComplexRuleTypesChooserViewData { val isDarkTheme = prefsInteractor.getDarkMode() val viewData = dayOfWeekViewDataMapper.mapViewData( - selectedDaysOfWeek = daysOfWeek.toList(), + selectedDaysOfWeek = daysOfWeek, isDarkTheme = isDarkTheme, width = DayOfWeekViewData.Width.MatchParent, paddingHorizontalDp = 2, diff --git a/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/delegate/GoalsViewModelDelegateImpl.kt b/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/delegate/GoalsViewModelDelegateImpl.kt index 837f71849..b8848eac0 100644 --- a/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/delegate/GoalsViewModelDelegateImpl.kt +++ b/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/delegate/GoalsViewModelDelegateImpl.kt @@ -127,7 +127,7 @@ class GoalsViewModelDelegateImpl @Inject constructor( override fun onDayOfWeekClick(data: DayOfWeekViewData) { val current = newGoalsState.daysOfWeek - val new = current.toMutableList().apply { addOrRemove(data.dayOfWeek) } + val new = current.toMutableSet().apply { addOrRemove(data.dayOfWeek) } newGoalsState = newGoalsState.copy(daysOfWeek = new) updateGoalsViewData() } @@ -145,7 +145,7 @@ class GoalsViewModelDelegateImpl @Inject constructor( goalId: Long, state: ChangeRecordTypeGoalsState.GoalState, goalRange: RecordTypeGoal.Range, - daysOfWeek: List, + daysOfWeek: Set, ) { val type = state.type val goalType = state.subtype @@ -169,7 +169,7 @@ class GoalsViewModelDelegateImpl @Inject constructor( goalId = goals.getSession()?.id.orZero(), state = newGoalsState.session, goalRange = RecordTypeGoal.Range.Session, - daysOfWeek = emptyList(), + daysOfWeek = emptySet(), ) processGoal( goalId = goals.getDaily()?.id.orZero(), @@ -181,13 +181,13 @@ class GoalsViewModelDelegateImpl @Inject constructor( goalId = goals.getWeekly()?.id.orZero(), state = newGoalsState.weekly, goalRange = RecordTypeGoal.Range.Weekly, - daysOfWeek = emptyList(), + daysOfWeek = emptySet(), ) processGoal( goalId = goals.getMonthly()?.id.orZero(), state = newGoalsState.monthly, goalRange = RecordTypeGoal.Range.Monthly, - daysOfWeek = emptyList(), + daysOfWeek = emptySet(), ) } @@ -211,7 +211,7 @@ class GoalsViewModelDelegateImpl @Inject constructor( daily = goals.getDaily()?.let(::mapState) ?: defaultGoal, weekly = goals.getWeekly()?.let(::mapState) ?: defaultGoal, monthly = goals.getMonthly()?.let(::mapState) ?: defaultGoal, - daysOfWeek = goals.getDaily()?.daysOfWeek ?: DayOfWeek.entries, + daysOfWeek = goals.getDaily()?.daysOfWeek ?: DayOfWeek.entries.toSet(), ) updateGoalsViewData() diff --git a/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/mapper/GoalsViewDataMapper.kt b/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/mapper/GoalsViewDataMapper.kt index 1ebaa57e1..0236380ea 100644 --- a/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/mapper/GoalsViewDataMapper.kt +++ b/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/mapper/GoalsViewDataMapper.kt @@ -83,7 +83,7 @@ class GoalsViewDataMapper @Inject constructor( daily = getDefaultGoal(), weekly = getDefaultGoal(), monthly = getDefaultGoal(), - daysOfWeek = DayOfWeek.entries, + daysOfWeek = DayOfWeek.entries.toSet(), ) } @@ -157,7 +157,7 @@ class GoalsViewDataMapper @Inject constructor( private fun mapDaysOfWeekViewData( goal: RecordTypeGoal.Type, - selectedDaysOfWeek: List, + selectedDaysOfWeek: Set, isDarkTheme: Boolean, ): List { if (goal.value == 0L) return emptyList() diff --git a/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/viewData/ChangeRecordTypeGoalsState.kt b/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/viewData/ChangeRecordTypeGoalsState.kt index fb038a98f..45fa26f4e 100644 --- a/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/viewData/ChangeRecordTypeGoalsState.kt +++ b/features/feature_change_goals/src/main/java/com/example/util/simpletimetracker/feature_change_goals/viewData/ChangeRecordTypeGoalsState.kt @@ -8,7 +8,7 @@ data class ChangeRecordTypeGoalsState( val daily: GoalState, val weekly: GoalState, val monthly: GoalState, - val daysOfWeek: List, + val daysOfWeek: Set, ) { data class GoalState( diff --git a/features/feature_change_record_type/src/main/java/com/example/util/simpletimetracker/feature_change_record_type/viewModel/ChangeRecordTypeViewModel.kt b/features/feature_change_record_type/src/main/java/com/example/util/simpletimetracker/feature_change_record_type/viewModel/ChangeRecordTypeViewModel.kt index f36f85d7a..86eee900a 100644 --- a/features/feature_change_record_type/src/main/java/com/example/util/simpletimetracker/feature_change_record_type/viewModel/ChangeRecordTypeViewModel.kt +++ b/features/feature_change_record_type/src/main/java/com/example/util/simpletimetracker/feature_change_record_type/viewModel/ChangeRecordTypeViewModel.kt @@ -308,7 +308,7 @@ class ChangeRecordTypeViewModel @Inject constructor( goalsViewModelDelegate.saveGoals(RecordTypeGoal.IdData.Type(addedId)) activityFilterInteractor.getByTypeId(recordTypeId).forEach { filter -> val newFilter = filter.copy( - selectedIds = (filter.selectedIds + addedId).toSet().toList(), + selectedIds = (filter.selectedIds + addedId).toSet(), ) activityFilterInteractor.add(newFilter) } diff --git a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/interactor/GetNotificationActivitySwitchControlsInteractor.kt b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/interactor/GetNotificationActivitySwitchControlsInteractor.kt index 671be9d7e..85b35d5c6 100644 --- a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/interactor/GetNotificationActivitySwitchControlsInteractor.kt +++ b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/interactor/GetNotificationActivitySwitchControlsInteractor.kt @@ -90,6 +90,7 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor( data: List, ): List { if (data.isEmpty()) return data + if (data.size % TYPES_LIST_SIZE == 0) return data val emptyCount = TYPES_LIST_SIZE - (data.size % TYPES_LIST_SIZE) val emptyData = List(emptyCount) { NotificationControlsParams.Type.Empty } return data + emptyData diff --git a/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/partialRestore/viewModel/PartialRestoreViewModel.kt b/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/partialRestore/viewModel/PartialRestoreViewModel.kt index 10e7d70d2..19a30cc26 100644 --- a/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/partialRestore/viewModel/PartialRestoreViewModel.kt +++ b/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/partialRestore/viewModel/PartialRestoreViewModel.kt @@ -163,7 +163,7 @@ class PartialRestoreViewModel @Inject constructor( is ActivityFilter.Type.Activity -> it in typesIds is ActivityFilter.Type.Category -> it in categoriesIds } - } + }.toSet() val newData = item.data.copy(selectedIds = newIds) item.copy(data = newData) } @@ -199,7 +199,7 @@ class PartialRestoreViewModel @Inject constructor( it in typesIds }.takeIf { it.isNotEmpty() - } ?: return@mapNotNull null + }?.toSet() ?: return@mapNotNull null val newData = item.data.copy(suggestionIds = newIds) id to item.copy(data = newData) }.toMap() diff --git a/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsCalculateInteractor.kt b/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsCalculateInteractor.kt index 72568fa9d..7049072da 100644 --- a/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsCalculateInteractor.kt +++ b/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsCalculateInteractor.kt @@ -37,14 +37,14 @@ class ActivitySuggestionsCalculateInteractor @Inject constructor( ?: return@mapNotNull null Result( typeId = typeId, - suggestions = thisTypeSuggestions.map { it.typeId }, + suggestions = thisTypeSuggestions.map { it.typeId }.toSet(), ) } } data class Result( val typeId: Long, - val suggestions: List, + val suggestions: Set, ) companion object { diff --git a/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsViewDataInteractor.kt b/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsViewDataInteractor.kt index 7e83e7dbd..dd17fb7d2 100644 --- a/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsViewDataInteractor.kt +++ b/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/interactor/ActivitySuggestionsViewDataInteractor.kt @@ -27,7 +27,7 @@ class ActivitySuggestionsViewDataInteractor @Inject constructor( ) { suspend fun getViewData( - suggestionsMap: Map>, + suggestionsMap: Map>, ): List { val isDarkTheme = prefsInteractor.getDarkMode() val recordTypes = recordTypeInteractor.getAll().filter { !it.hidden } diff --git a/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/viewModel/ActivitySuggestionsViewModel.kt b/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/viewModel/ActivitySuggestionsViewModel.kt index ecdc8602d..674939a42 100644 --- a/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/viewModel/ActivitySuggestionsViewModel.kt +++ b/features/feature_suggestions/src/main/java/com/example/util/simpletimetracker/feature_suggestions/viewModel/ActivitySuggestionsViewModel.kt @@ -38,7 +38,7 @@ class ActivitySuggestionsViewModel @Inject constructor( listOf(LoaderViewData()).also { initialize() } } - private var suggestions: Map> = emptyMap() + private var suggestions: Map> = emptyMap() private var selectingSuggestionsForTypeId: Long = 0L fun onTypesSelected(typeIds: List, tag: String?) = viewModelScope.launch { @@ -51,7 +51,7 @@ class ActivitySuggestionsViewModel @Inject constructor( ACTIVITY_SUGGESTIONS_SUGGESTION_SELECTION_TAG -> { onSuggestionsForTypeChanged( forTypeId = selectingSuggestionsForTypeId, - newSuggestions = typeIds, + newSuggestions = typeIds.toSet(), ) } } @@ -69,7 +69,7 @@ class ActivitySuggestionsViewModel @Inject constructor( title = resourceRepo.getString(R.string.change_record_message_choose_type), subtitle = "", type = TypesSelectionDialogParams.Type.Activity, - selectedTypeIds = suggestions[forTypeId].orEmpty(), + selectedTypeIds = suggestions[forTypeId].orEmpty().toList(), isMultiSelectAvailable = true, idsShouldBeVisible = emptyList(), showHints = true, @@ -130,7 +130,7 @@ class ActivitySuggestionsViewModel @Inject constructor( .filter { it.id.forTypeId == forTypeId } val newSuggestions = suggestions[forTypeId].orEmpty().sortedBy { suggestionId -> newOrder.indexOfFirst { it.id.suggestionTypeId == suggestionId } - } + }.toSet() suggestions = suggestions.toMutableMap().apply { put(forTypeId, newSuggestions) } @@ -170,7 +170,7 @@ class ActivitySuggestionsViewModel @Inject constructor( private suspend fun onSuggestionsForTypeChanged( forTypeId: Long, - newSuggestions: List, + newSuggestions: Set, ) { suggestions = suggestions.toMutableMap().apply { put(forTypeId, newSuggestions)