Skip to content

Commit e1d6522

Browse files
committed
remove default types repeating by repeat button on main tab
1 parent badb921 commit e1d6522

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

core/src/main/java/com/example/util/simpletimetracker/core/interactor/RecordRepeatInteractor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.example.util.simpletimetracker.domain.prefs.interactor.PrefsInteracto
77
import com.example.util.simpletimetracker.domain.record.interactor.RecordInteractor
88
import com.example.util.simpletimetracker.domain.record.interactor.RunningRecordInteractor
99
import com.example.util.simpletimetracker.domain.record.model.RepeatButtonType
10+
import com.example.util.simpletimetracker.domain.recordType.interactor.RecordTypeInteractor
11+
import com.example.util.simpletimetracker.domain.recordType.model.RecordType
1012
import com.example.util.simpletimetracker.navigation.Router
1113
import com.example.util.simpletimetracker.navigation.params.notification.SnackBarParams
1214
import com.example.util.simpletimetracker.navigation.params.notification.ToastParams
@@ -15,6 +17,7 @@ import javax.inject.Inject
1517
// Repeats previous record, if any.
1618
class RecordRepeatInteractor @Inject constructor(
1719
private val recordInteractor: RecordInteractor,
20+
private val recordTypeInteractor: RecordTypeInteractor,
1821
private val runningRecordInteractor: RunningRecordInteractor,
1922
private val addRunningRecordMediator: AddRunningRecordMediator,
2023
private val prefsInteractor: PrefsInteractor,
@@ -48,15 +51,22 @@ class RecordRepeatInteractor @Inject constructor(
4851
messageShower: (messageResId: Int) -> Unit,
4952
): ActionResult {
5053
val type = prefsInteractor.getRepeatButtonType()
54+
val defaultTypeIds = recordTypeInteractor.getAll()
55+
.filter { it.defaultDuration != 0L }
56+
.map(RecordType::id)
5157

5258
// TODO repeat several records?
5359
val prevRecord = recordInteractor.getPrev(
5460
timeStarted = System.currentTimeMillis(),
61+
ignoreTypeIds = defaultTypeIds,
5562
).let {
5663
when (type) {
5764
is RepeatButtonType.RepeatLast -> it
5865
is RepeatButtonType.RepeatBeforeLast -> if (it != null) {
59-
recordInteractor.getPrev(timeStarted = it.timeEnded - 1)
66+
recordInteractor.getPrev(
67+
timeStarted = it.timeEnded - 1,
68+
ignoreTypeIds = defaultTypeIds,
69+
)
6070
} else {
6171
null
6272
}

data_local/src/main/java/com/example/util/simpletimetracker/data_local/record/RecordDao.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ interface RecordDao {
5050
suspend fun getFromRangeByType(typesIds: List<Long>, start: Long, end: Long): List<RecordWithRecordTagsDBO>
5151

5252
@Transaction
53-
@Query("SELECT * FROM records WHERE time_ended <= :timeStarted ORDER BY time_ended DESC LIMIT 1")
54-
suspend fun getPrev(timeStarted: Long): RecordWithRecordTagsDBO?
53+
@Query("SELECT * FROM records " +
54+
"WHERE time_ended <= :timeStarted AND type_id NOT IN (:ignoreTypeIds) " +
55+
"ORDER BY time_ended DESC LIMIT 1")
56+
suspend fun getPrev(timeStarted: Long, ignoreTypeIds: List<Long>): RecordWithRecordTagsDBO?
5557

5658
@Transaction
5759
@Query("SELECT * FROM records WHERE time_started >= :timeEnded ORDER BY time_started ASC LIMIT 1")

data_local/src/main/java/com/example/util/simpletimetracker/data_local/record/RecordRepoImpl.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ class RecordRepoImpl @Inject constructor(
106106
)
107107
}
108108

109-
override suspend fun getPrev(timeStarted: Long): Record? = withContext(Dispatchers.IO) {
109+
override suspend fun getPrev(
110+
timeStarted: Long,
111+
ignoreTypeIds: List<Long>,
112+
): Record? = withContext(Dispatchers.IO) {
110113
logDataAccess("getPrev")
111-
recordDao.getPrev(timeStarted)?.let(::mapItem)
114+
recordDao.getPrev(timeStarted, ignoreTypeIds)?.let(::mapItem)
112115
}
113116

114117
override suspend fun getNext(timeEnded: Long): Record? = withContext(Dispatchers.IO) {

domain/src/main/java/com/example/util/simpletimetracker/domain/record/interactor/RecordInteractor.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ class RecordInteractor @Inject constructor(
4545
return recordRepo.get(id)
4646
}
4747

48-
suspend fun getPrev(timeStarted: Long): Record? {
49-
return recordRepo.getPrev(timeStarted)
48+
suspend fun getPrev(
49+
timeStarted: Long,
50+
ignoreTypeIds: List<Long> = emptyList(),
51+
): Record? {
52+
return recordRepo.getPrev(timeStarted, ignoreTypeIds)
5053
}
5154

5255
// Can return several records ended at the same time.

domain/src/main/java/com/example/util/simpletimetracker/domain/record/repo/RecordRepo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface RecordRepo {
2525

2626
suspend fun getFromRangeByType(typeIds: List<Long>, range: Range): List<Record>
2727

28-
suspend fun getPrev(timeStarted: Long): Record?
28+
suspend fun getPrev(timeStarted: Long, ignoreTypeIds: List<Long> = emptyList()): Record?
2929

3030
suspend fun getNext(timeEnded: Long): Record?
3131

0 commit comments

Comments
 (0)