-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
77 changed files
with
1,170 additions
and
289 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...om/example/util/simpletimetracker/core/interactor/ActivitySuggestionViewDataInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.util.simpletimetracker.core.interactor | ||
|
||
import com.example.util.simpletimetracker.core.mapper.RecordTypeViewDataMapper | ||
import com.example.util.simpletimetracker.domain.activitySuggestion.interactor.GetCurrentActivitySuggestionsInteractor | ||
import com.example.util.simpletimetracker.domain.record.model.RunningRecord | ||
import com.example.util.simpletimetracker.domain.recordType.model.RecordType | ||
import com.example.util.simpletimetracker.domain.recordType.model.RecordTypeGoal | ||
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType | ||
import com.example.util.simpletimetracker.feature_base_adapter.recordTypeSuggestion.RecordTypeSuggestionViewData | ||
import javax.inject.Inject | ||
|
||
class ActivitySuggestionViewDataInteractor @Inject constructor( | ||
private val getCurrentActivitySuggestionsInteractor: GetCurrentActivitySuggestionsInteractor, | ||
private val recordTypeViewDataMapper: RecordTypeViewDataMapper, | ||
) { | ||
|
||
suspend fun getSuggestionsViewData( | ||
recordTypesMap: Map<Long, RecordType>, | ||
goals: Map<Long, List<RecordTypeGoal>>, | ||
runningRecords: List<RunningRecord>, | ||
allDailyCurrents: Map<Long, GetCurrentRecordsDurationInteractor.Result>, | ||
completeTypeIds: Set<Long>, | ||
numberOfCards: Int, | ||
isDarkTheme: Boolean, | ||
): List<ViewHolderType> { | ||
val suggestionTypes = getCurrentActivitySuggestionsInteractor.execute( | ||
recordTypesMap = recordTypesMap, | ||
runningRecords = runningRecords, | ||
) | ||
|
||
return suggestionTypes.map { recordType -> | ||
recordTypeViewDataMapper.map( | ||
recordType = recordType, | ||
numberOfCards = numberOfCards, | ||
isDarkTheme = isDarkTheme, | ||
checkState = recordTypeViewDataMapper.mapGoalCheckmark( | ||
type = recordType, | ||
goals = goals, | ||
allDailyCurrents = allDailyCurrents, | ||
), | ||
isComplete = recordType.id in completeTypeIds, | ||
).let { | ||
RecordTypeSuggestionViewData(it) | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...n/java/com/example/util/simpletimetracker/core/mapper/ActivitySuggestionViewDataMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.example.util.simpletimetracker.core.mapper | ||
|
||
import com.example.util.simpletimetracker.domain.activitySuggestion.model.ActivitySuggestion | ||
import com.example.util.simpletimetracker.domain.recordType.model.RecordType | ||
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType | ||
import com.example.util.simpletimetracker.feature_base_adapter.activitySuggestion.ActivitySuggestionViewData | ||
import com.example.util.simpletimetracker.feature_base_adapter.listElement.ListElementViewData | ||
import javax.inject.Inject | ||
|
||
class ActivitySuggestionViewDataMapper @Inject constructor( | ||
private val iconMapper: IconMapper, | ||
private val colorMapper: ColorMapper, | ||
) { | ||
|
||
fun mapSuggestionFiltered( | ||
suggestion: ActivitySuggestion, | ||
isDarkTheme: Boolean, | ||
typesMap: Map<Long, RecordType>, | ||
typesOrder: List<Long>, | ||
isFiltered: Boolean, | ||
): ActivitySuggestionViewData { | ||
val activityItems = mapTypes( | ||
typeIds = listOf(suggestion.forTypeId).toSet(), | ||
isDarkTheme = isDarkTheme, | ||
typesMap = typesMap, | ||
typesOrder = typesOrder, | ||
) | ||
val suggestionItems = mapTypes( | ||
typeIds = suggestion.suggestionIds.toSet(), | ||
isDarkTheme = isDarkTheme, | ||
typesMap = typesMap, | ||
typesOrder = typesOrder, | ||
) | ||
|
||
return ActivitySuggestionViewData( | ||
id = suggestion.id, | ||
activity = activityItems, | ||
suggestions = suggestionItems, | ||
color = if (isFiltered) { | ||
colorMapper.toInactiveColor(isDarkTheme) | ||
} else { | ||
colorMapper.toActiveColor(isDarkTheme) | ||
}, | ||
) | ||
} | ||
|
||
private fun mapTypes( | ||
typeIds: Set<Long>, | ||
isDarkTheme: Boolean, | ||
typesMap: Map<Long, RecordType>, | ||
typesOrder: List<Long>, | ||
): List<ViewHolderType> { | ||
val data = typeIds | ||
.sortedBy { typesOrder.indexOf(it) } | ||
.mapNotNull { typesMap[it] } | ||
if (data.isEmpty()) return emptyList() | ||
|
||
val result = mutableListOf<ViewHolderType>() | ||
result += data.map { | ||
ListElementViewData( | ||
text = it.name, | ||
icon = iconMapper.mapIcon(it.icon), | ||
color = colorMapper.mapToColorInt( | ||
color = it.color, | ||
isDarkTheme = isDarkTheme, | ||
), | ||
) | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...il/simpletimetracker/domain/activitySuggestion/interactor/ActivitySuggestionInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.example.util.simpletimetracker.domain.activitySuggestion.interactor | ||
|
||
import com.example.util.simpletimetracker.domain.activitySuggestion.model.ActivitySuggestion | ||
import com.example.util.simpletimetracker.domain.activitySuggestion.repo.ActivitySuggestionRepo | ||
import javax.inject.Inject | ||
|
||
class ActivitySuggestionInteractor @Inject constructor( | ||
private val activitySuggestionRepo: ActivitySuggestionRepo, | ||
) { | ||
|
||
suspend fun getAll(): List<ActivitySuggestion> { | ||
return activitySuggestionRepo.getAll() | ||
} | ||
|
||
suspend fun get(id: Long): ActivitySuggestion? { | ||
return activitySuggestionRepo.get(id) | ||
} | ||
|
||
suspend fun getByTypeId(id: Long): List<ActivitySuggestion> { | ||
return activitySuggestionRepo.getByTypeId(id) | ||
} | ||
|
||
suspend fun add(data: List<ActivitySuggestion>) { | ||
activitySuggestionRepo.add(data) | ||
} | ||
|
||
suspend fun remove(ids: List<Long>) { | ||
activitySuggestionRepo.remove(ids) | ||
} | ||
|
||
suspend fun removeTypeId(id: Long) { | ||
val idsToRemove = mutableListOf<Long>() | ||
val suggestionsToChange = mutableListOf<ActivitySuggestion>() | ||
|
||
getAll().forEach { suggestion -> | ||
if (suggestion.forTypeId == id) { | ||
idsToRemove += suggestion.id | ||
return@forEach | ||
} | ||
if (id in suggestion.suggestionIds) { | ||
val newSuggestions = suggestion.suggestionIds | ||
.toMutableList() | ||
.apply { removeAll { it == id } } | ||
suggestionsToChange += suggestion.copy( | ||
suggestionIds = newSuggestions, | ||
) | ||
} | ||
} | ||
|
||
remove(idsToRemove) | ||
add(suggestionsToChange) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...metracker/domain/activitySuggestion/interactor/GetCurrentActivitySuggestionsInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.example.util.simpletimetracker.domain.activitySuggestion.interactor | ||
|
||
import com.example.util.simpletimetracker.domain.record.interactor.RecordInteractor | ||
import com.example.util.simpletimetracker.domain.record.model.RunningRecord | ||
import com.example.util.simpletimetracker.domain.recordType.model.RecordType | ||
import javax.inject.Inject | ||
|
||
class GetCurrentActivitySuggestionsInteractor @Inject constructor( | ||
private val recordInteractor: RecordInteractor, | ||
private val activitySuggestionInteractor: ActivitySuggestionInteractor, | ||
) { | ||
|
||
suspend fun execute( | ||
recordTypesMap: Map<Long, RecordType>, | ||
runningRecords: List<RunningRecord>, | ||
): List<RecordType> { | ||
return execute(runningRecords).mapNotNull { typeId -> | ||
recordTypesMap[typeId]?.takeIf { !it.hidden } | ||
} | ||
} | ||
|
||
private suspend fun execute( | ||
runningRecords: List<RunningRecord>, | ||
): List<Long> { | ||
val currentOrLast = runningRecords.minByOrNull { it.timeStarted } | ||
?: recordInteractor.getAllPrev(System.currentTimeMillis()).firstOrNull() | ||
|
||
val currentOrLastTypeId = currentOrLast?.typeIds?.firstOrNull() | ||
|
||
return currentOrLastTypeId | ||
?.let { activitySuggestionInteractor.getByTypeId(it) } | ||
?.firstOrNull() | ||
?.suggestionIds | ||
.orEmpty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.