-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add duplicate filter to records filter
- Loading branch information
Showing
44 changed files
with
598 additions
and
114 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
...example/util/simpletimetracker/domain/record/interactor/GetDuplicatedRecordsInteractor.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,76 @@ | ||
package com.example.util.simpletimetracker.domain.record.interactor | ||
|
||
import com.example.util.simpletimetracker.domain.record.extension.hasSameActivity | ||
import com.example.util.simpletimetracker.domain.record.model.Record | ||
import com.example.util.simpletimetracker.domain.record.model.RecordBase | ||
import com.example.util.simpletimetracker.domain.record.model.RecordsFilter | ||
import javax.inject.Inject | ||
|
||
class GetDuplicatedRecordsInteractor @Inject constructor() { | ||
|
||
fun execute( | ||
filters: List<RecordsFilter.DuplicationsItem>, | ||
records: List<RecordBase>, | ||
): Result { | ||
if (filters.isEmpty()) { | ||
return Result( | ||
original = emptyList(), | ||
duplications = emptyList(), | ||
) | ||
} | ||
val hasSameActivity = filters.hasSameActivity() | ||
|
||
data class Id( | ||
val typeId: Long, | ||
val timeStarted: Long, | ||
val timeEnded: Long, | ||
) | ||
|
||
val data = mutableMapOf<Id, MutableList<Record>>() | ||
val result = mutableListOf<Long>() | ||
val resultDuplications = mutableListOf<Long>() | ||
|
||
// Check duplications by adding to map with data class as key. | ||
records.forEach { record -> | ||
if (record !is Record) return@forEach | ||
val id = Id( | ||
typeId = if (hasSameActivity) { | ||
record.typeIds.firstOrNull() ?: return@forEach | ||
} else { | ||
0L | ||
}, | ||
// Times are always checked and should be in the list. | ||
timeStarted = record.timeStarted, | ||
timeEnded = record.timeEnded, | ||
) | ||
data[id] = data.getOrElse(key = id, defaultValue = { mutableListOf() }) | ||
.apply { add(record) } | ||
} | ||
|
||
data.forEach { (_, duplications) -> | ||
if (duplications.size < 2) return@forEach | ||
// This record will not be counted as duplication. | ||
val originalRecord = duplications.firstOrNull { | ||
it.tagIds.isNotEmpty() || | ||
it.comment.isNotEmpty() | ||
} ?: duplications.firstOrNull() | ||
duplications.forEach { record -> | ||
if (record.id == originalRecord?.id) { | ||
result += record.id | ||
} else { | ||
resultDuplications += record.id | ||
} | ||
} | ||
} | ||
|
||
return Result( | ||
original = result, | ||
duplications = resultDuplications, | ||
) | ||
} | ||
|
||
data class Result( | ||
val original: List<Long>, | ||
val duplications: List<Long>, | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ data class RecordsFilterButtonViewData( | |
|
||
enum class Type { | ||
INVERT_SELECTION, | ||
FILTER_DUPLICATES, | ||
} | ||
} |
Oops, something went wrong.