-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from TimerTiTi/147-daily-automation
close #147 daily automation
- Loading branch information
Showing
53 changed files
with
1,281 additions
and
347 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.titi.app.core.ui | ||
|
||
import android.content.res.Configuration | ||
|
||
fun Configuration.isTablet(): Boolean { | ||
val screenLayout = this.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK | ||
return screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE || | ||
screenLayout == Configuration.SCREENLAYOUT_SIZE_XLARGE | ||
} |
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
11 changes: 11 additions & 0 deletions
11
core/util/src/main/kotlin/com/titi/app/core/util/StringExtensions.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,11 @@ | ||
package com.titi.app.core.util | ||
|
||
import java.time.ZoneId | ||
import java.time.ZonedDateTime | ||
|
||
fun String.isAfterH(hour: Int): Boolean { | ||
val inputDateTime = ZonedDateTime.parse(this).withZoneSameInstant(ZoneId.systemDefault()) | ||
val currentDateTime = ZonedDateTime.now() | ||
|
||
return inputDateTime.dayOfMonth != currentDateTime.dayOfMonth && currentDateTime.hour >= hour | ||
} |
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
47 changes: 21 additions & 26 deletions
47
...n/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/AddMeasureTimeAtDailyUseCase.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 |
---|---|---|
@@ -1,44 +1,39 @@ | ||
package com.titi.app.doamin.daily.usecase | ||
|
||
import com.titi.app.core.util.getDailyDayWithHour | ||
import com.titi.app.data.daily.api.DailyRepository | ||
import com.titi.app.doamin.daily.mapper.toDomainModel | ||
import com.titi.app.doamin.daily.mapper.toRepositoryModel | ||
import com.titi.app.doamin.daily.model.Daily | ||
import com.titi.app.doamin.daily.model.TaskHistory | ||
import com.titi.app.doamin.daily.model.toUpdateDaily | ||
import java.time.LocalDate | ||
import java.time.ZoneId | ||
import java.time.ZoneOffset | ||
import javax.inject.Inject | ||
|
||
class AddMeasureTimeAtDailyUseCase @Inject constructor( | ||
private val dailyRepository: DailyRepository, | ||
) { | ||
suspend operator fun invoke(taskName: String, startTime: String, endTime: String) { | ||
val recentDaily = dailyRepository | ||
.getDateDaily( | ||
startDateTime = LocalDate.now() | ||
.atStartOfDay(ZoneId.systemDefault()) | ||
.withZoneSameInstant(ZoneOffset.UTC) | ||
.toString(), | ||
)?.toDomainModel() | ||
val timePair = getDailyDayWithHour(6) | ||
val recentDaily = dailyRepository.getDateDaily( | ||
startDateTime = timePair.first, | ||
endDateTime = timePair.second, | ||
)?.toDomainModel() ?: Daily() | ||
|
||
recentDaily?.let { daily -> | ||
val taskHistory = TaskHistory( | ||
startDate = startTime, | ||
endDate = endTime, | ||
) | ||
val taskHistory = TaskHistory( | ||
startDate = startTime, | ||
endDate = endTime, | ||
) | ||
|
||
val updateTaskHistories = daily.taskHistories?.toMutableMap()?.apply { | ||
this[taskName] = this[taskName] | ||
?.toMutableList() | ||
?.apply { add(taskHistory) } | ||
?: listOf(taskHistory) | ||
}?.toMap() | ||
?: mapOf(taskName to listOf(taskHistory)) | ||
val updateTaskHistories = recentDaily.taskHistories?.toMutableMap()?.apply { | ||
this[taskName] = this[taskName] | ||
?.toMutableList() | ||
?.apply { add(taskHistory) } | ||
?: listOf(taskHistory) | ||
}?.toMap() | ||
?: mapOf(taskName to listOf(taskHistory)) | ||
|
||
dailyRepository.upsert( | ||
daily.toUpdateDaily(updateTaskHistories).toRepositoryModel(), | ||
) | ||
} | ||
dailyRepository.upsert( | ||
recentDaily.toUpdateDaily(updateTaskHistories).toRepositoryModel(), | ||
) | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetLastDailyFlowUseCase.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetTodayDailyFlowUseCase.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,22 @@ | ||
package com.titi.app.doamin.daily.usecase | ||
|
||
import com.titi.app.core.util.getDailyDayWithHour | ||
import com.titi.app.data.daily.api.DailyRepository | ||
import com.titi.app.doamin.daily.mapper.toDomainModel | ||
import com.titi.app.doamin.daily.model.Daily | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class GetTodayDailyFlowUseCase @Inject constructor( | ||
private val dailyRepository: DailyRepository, | ||
) { | ||
operator fun invoke(): Flow<Daily> { | ||
val timePair = getDailyDayWithHour(6) | ||
|
||
return dailyRepository.getDateDailyFlow( | ||
startDateTime = timePair.first, | ||
endDateTime = timePair.second, | ||
).map { it?.toDomainModel() ?: Daily() } | ||
} | ||
} |
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
Oops, something went wrong.