From ec3aa0100b8674a76d78ca7841b3bf940482e7eb Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Fri, 7 Oct 2022 13:46:32 +0530 Subject: [PATCH 01/32] WTA #31: Moved HomePageNetworkData to separate file and moved common error handling logic. --- .../jacob/wakatimeapp/core/models/Error.kt | 5 +- .../wakatimeapp/home/data/HomePageAPI.kt | 26 ------- .../home/data/HomePageNetworkData.kt | 67 +++++++++++++++++++ .../home/usecases/GetDailyStatsUC.kt | 26 +------ .../home/usecases/GetLast7DaysStatsUC.kt | 33 +-------- 5 files changed, 70 insertions(+), 87 deletions(-) create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt index beeb9812..2993a9e6 100644 --- a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt @@ -14,7 +14,7 @@ sealed class Error : Exception() { abstract val statusCode: Int data class NoConnection(override val message: String) : NetworkErrors() { - override val statusCode = SERVICE_UNAVAILABLE + override val statusCode = -1 } data class GenericError(override val message: String) : NetworkErrors() { @@ -32,15 +32,12 @@ sealed class Error : Exception() { fun create(message: String, code: Int? = null): NetworkErrors = when (code) { null -> GenericError(message) in 400..499 -> ClientError(message, code) - SERVICE_UNAVAILABLE -> NoConnection(message) in 500..599 -> ServerError(message, code) else -> { Timber.e("Unknown error code: $code, message: $message") TODO("Handle this case") } } - - private const val SERVICE_UNAVAILABLE = 503 } } } diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt index 61a7d976..a9467150 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt @@ -1,13 +1,8 @@ package com.jacob.wakatimeapp.home.data -import com.jacob.wakatimeapp.core.common.auth.AuthTokenProvider import com.jacob.wakatimeapp.home.data.dtos.AllTimeDataDTO import com.jacob.wakatimeapp.home.data.dtos.GetDailyStatsResDTO import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO -import javax.inject.Inject -import javax.inject.Singleton -import kotlinx.coroutines.flow.first -import kotlinx.coroutines.runBlocking import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Header @@ -22,24 +17,3 @@ interface HomePageAPI { @GET("/api/v1/users/current/summaries?range=last_7_days") suspend fun getLast7DaysStats(@Header("Authorization") token: String): Response } - -@Singleton -class HomePageNetworkData @Inject constructor( - private val authTokenProvider: AuthTokenProvider, - private val homePageAPI: HomePageAPI, -) { - private val token: String - get() = runBlocking { - authTokenProvider.getFreshToken() - .first() - } - - suspend fun getLast7DaysStats(): Response = - homePageAPI.getLast7DaysStats("Bearer $token") - - suspend fun getStatsForToday(): Response = - homePageAPI.getStatsForToday("Bearer $token") - - suspend fun getData(): Response = - homePageAPI.getData("Bearer $token") -} diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt new file mode 100644 index 00000000..86063a73 --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt @@ -0,0 +1,67 @@ +package com.jacob.wakatimeapp.home.data + +import arrow.core.Either +import arrow.core.left +import arrow.core.right +import com.jacob.wakatimeapp.core.common.auth.AuthTokenProvider +import com.jacob.wakatimeapp.core.models.Error +import com.jacob.wakatimeapp.core.models.Error.NetworkErrors +import com.jacob.wakatimeapp.home.data.dtos.AllTimeDataDTO +import com.jacob.wakatimeapp.home.data.dtos.GetDailyStatsResDTO +import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO +import com.jacob.wakatimeapp.home.data.mappers.toModel +import java.net.UnknownHostException +import javax.inject.Inject +import javax.inject.Singleton +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import retrofit2.Response +import timber.log.Timber + +@Singleton +class HomePageNetworkData @Inject constructor( + private val authTokenProvider: AuthTokenProvider, + private val homePageAPI: HomePageAPI, +) { + private val token: String + get() = runBlocking { + authTokenProvider.getFreshToken() + .first() + } + + suspend fun getLast7DaysStats() = Either.catchAndFlatten { + homePageAPI.getLast7DaysStats("Bearer $token") + .checkResponse() + .map(GetLast7DaysStatsResDTO::toModel) + } + .mapLeft(::handleNetworkException) + + suspend fun getStatsForToday() = Either.catchAndFlatten { + homePageAPI.getStatsForToday("Bearer $token") + .checkResponse() + .map(GetDailyStatsResDTO::toModel) + } + .mapLeft(::handleNetworkException) + + suspend fun getData() = Either.catchAndFlatten { + homePageAPI.getData("Bearer $token") + .checkResponse() + .map(AllTimeDataDTO::toString) + } + .mapLeft(::handleNetworkException) +} + +private fun Response.checkResponse(): Either = if (isSuccessful) { + body()!!.right() +} else { + NetworkErrors.create(message(), code()) + .left() +} + +private fun handleNetworkException(exception: Throwable): Error { + Timber.e(exception.toString()) + return when (exception) { + is UnknownHostException -> NetworkErrors.NoConnection("No internet connection") + else -> NetworkErrors.create(exception.message!!) + } +} diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt index 99184d1e..1b8ed78c 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt @@ -1,36 +1,12 @@ package com.jacob.wakatimeapp.home.usecases -import arrow.core.Either -import arrow.core.left -import arrow.core.right -import com.jacob.wakatimeapp.core.models.DailyStats -import com.jacob.wakatimeapp.core.models.Error -import com.jacob.wakatimeapp.core.models.Error.NetworkErrors import com.jacob.wakatimeapp.home.data.HomePageNetworkData -import com.jacob.wakatimeapp.home.data.dtos.GetDailyStatsResDTO -import com.jacob.wakatimeapp.home.data.mappers.toModel import javax.inject.Inject import javax.inject.Singleton -import timber.log.Timber @Singleton class GetDailyStatsUC @Inject constructor( private val homePageNetworkData: HomePageNetworkData, ) { - suspend operator fun invoke(): Either = Either.catchAndFlatten { - val statsForTodayResponse = homePageNetworkData.getStatsForToday() - if (!statsForTodayResponse.isSuccessful) return@catchAndFlatten NetworkErrors.create( - statsForTodayResponse.message(), - statsForTodayResponse.code() - ) - .left() - - statsForTodayResponse.body()!! - .run(GetDailyStatsResDTO::toModel) - .right() - } - .mapLeft { - Timber.e(it.message) - NetworkErrors.create(it.message!!) - } + suspend operator fun invoke() = homePageNetworkData.getStatsForToday() } diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt index 2143e890..aeb70d14 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt @@ -1,43 +1,12 @@ package com.jacob.wakatimeapp.home.usecases -import arrow.core.Either -import arrow.core.left -import arrow.core.right -import com.jacob.wakatimeapp.core.models.Error -import com.jacob.wakatimeapp.core.models.Error.NetworkErrors -import com.jacob.wakatimeapp.core.models.WeeklyStats import com.jacob.wakatimeapp.home.data.HomePageNetworkData -import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO -import com.jacob.wakatimeapp.home.data.mappers.toModel -import java.net.UnknownHostException import javax.inject.Inject import javax.inject.Singleton -import timber.log.Timber @Singleton class GetLast7DaysStatsUC @Inject constructor( private val homePageNetworkData: HomePageNetworkData, ) { - suspend operator fun invoke(): Either = Either.catchAndFlatten { - val statsForTodayResponse = homePageNetworkData.getLast7DaysStats() - - if (!statsForTodayResponse.isSuccessful) { - return@catchAndFlatten NetworkErrors.create( - statsForTodayResponse.message(), - statsForTodayResponse.code() - ) - .left() - } - - statsForTodayResponse.body()!! - .run(GetLast7DaysStatsResDTO::toModel) - .right() - } - .mapLeft { - Timber.e(it.toString()) - when (it) { - is UnknownHostException -> NetworkErrors.NoConnection("No internet connection") - else -> NetworkErrors.create(it.message!!) - } - } + suspend operator fun invoke() = homePageNetworkData.getLast7DaysStats() } From efc8193f7a854811cb53a1ed048bae7e0301893b Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Fri, 7 Oct 2022 14:23:33 +0530 Subject: [PATCH 02/32] WTA #31: Moved GetLast7DaysStatsResDTO dtos to separate files. --- .idea/dictionaries/jacob.xml | 1 + .../com/jacob/wakatimeapp/core/models/Time.kt | 4 +- .../wakatimeapp/core/models/WeeklyStats.kt | 2 +- .../wakatimeapp/home/data/dtos/CategoryDTO.kt | 17 +++ .../home/data/dtos/DependencyDTO.kt | 6 + .../wakatimeapp/home/data/dtos/EditorDTO.kt | 17 +++ .../home/data/dtos/GetLast7DaysStatsResDTO.kt | 121 ++---------------- .../home/data/dtos/GrandTotalDTO.kt | 14 ++ .../wakatimeapp/home/data/dtos/LanguageDTO.kt | 17 +++ .../wakatimeapp/home/data/dtos/MachineDTO.kt | 18 +++ .../home/data/dtos/OperatingSystemDTO.kt | 17 +++ .../wakatimeapp/home/data/dtos/ProjectDTO.kt | 21 +++ .../wakatimeapp/home/data/dtos/RangeDTO.kt | 12 ++ .../data/mappers/GetWeeklyStatsResMapper.kt | 27 ++-- 14 files changed, 172 insertions(+), 122 deletions(-) create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt diff --git a/.idea/dictionaries/jacob.xml b/.idea/dictionaries/jacob.xml index 01933ce0..2e5ef517 100644 --- a/.idea/dictionaries/jacob.xml +++ b/.idea/dictionaries/jacob.xml @@ -4,6 +4,7 @@ arturbosch bosco buildlogic + dtos ktlint snackbar waka diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt index a8fc7044..65cefa75 100644 --- a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt @@ -29,8 +29,8 @@ data class Time( ) } - fun createFrom(timeString: String, decimal: String): Time { - val (hours, minutes) = timeString.split(":") + fun createFrom(digialString: String, decimal: String): Time { + val (hours, minutes) = digialString.split(":") .map(String::toInt) return Time(hours, minutes, decimal.toFloat()) } diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/WeeklyStats.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/WeeklyStats.kt index 4634d936..b1aa645b 100644 --- a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/WeeklyStats.kt +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/WeeklyStats.kt @@ -1,7 +1,7 @@ package com.jacob.wakatimeapp.core.models data class WeeklyStats( - val totalTime: com.jacob.wakatimeapp.core.models.Time, + val totalTime: Time, val dailyStats: List, val range: StatsRange, val todaysStats: DailyStats = dailyStats.last(), diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt new file mode 100644 index 00000000..cad8fd91 --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt @@ -0,0 +1,17 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class CategoryDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val name: String, + val percent: Double, + val seconds: Int, + val text: String, + @SerialName("total_seconds") val totalSeconds: Double, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt new file mode 100644 index 00000000..c70d70eb --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt @@ -0,0 +1,6 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.Serializable + +@Serializable +class DependencyDTO diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt new file mode 100644 index 00000000..a35f30bc --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt @@ -0,0 +1,17 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class EditorDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val name: String, + val percent: Double, + val seconds: Int, + val text: String, + @SerialName("total_seconds") val totalSeconds: Double, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt index acdcde86..c91c6ea0 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt @@ -20,115 +20,14 @@ data class GetLast7DaysStatsResDTO( @Serializable data class Data( - val categories: List, - val dependencies: List, - val editors: List, - val languages: List, - val machines: List, - val projects: List, - val range: Range, - @SerialName("operating_systems") val operatingSystems: List, - @SerialName("grand_total") val grandTotal: GrandTotal, - ) { - @Serializable - data class Category( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Editor( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class GrandTotal( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Language( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Machine( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("machine_name_id") val machineNameId: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class OperatingSystem( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Project( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Range( - val date: String, - val end: String, - val start: String, - val text: String, - val timezone: String, - ) - - @Serializable - class Dependency - } + val categories: List, + val dependencies: List, + val editors: List, + val languages: List, + val machines: List, + val projects: List, + val range: RangeDTO, + @SerialName("operating_systems") val operatingSystems: List, + @SerialName("grand_total") val grandTotal: GrandTotalDTO, + ) } diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt new file mode 100644 index 00000000..77a459e4 --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt @@ -0,0 +1,14 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class GrandTotalDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val text: String, + @SerialName("total_seconds") val totalSeconds: Double, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt new file mode 100644 index 00000000..0bea20bf --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt @@ -0,0 +1,17 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class LanguageDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val name: String, + val percent: Double, + val seconds: Int, + val text: String, + @SerialName("total_seconds") val totalSeconds: Double, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt new file mode 100644 index 00000000..181ab45d --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt @@ -0,0 +1,18 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class MachineDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val name: String, + val percent: Double, + val seconds: Int, + val text: String, + @SerialName("machine_name_id") val machineNameId: String, + @SerialName("total_seconds") val totalSeconds: Double, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt new file mode 100644 index 00000000..69316fd3 --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt @@ -0,0 +1,17 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class OperatingSystemDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val name: String, + val percent: Double, + val seconds: Int, + val text: String, + @SerialName("total_seconds") val totalSeconds: Double, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt new file mode 100644 index 00000000..53481e85 --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt @@ -0,0 +1,21 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ProjectDTO( + val decimal: String, + val digital: String, + val hours: Int, + val minutes: Int, + val name: String, + val percent: Double, + val seconds: Int, + val text: String, + @SerialName("total_seconds") val totalSeconds: Double, +) { + + fun isUnknownProject() = + name == "Unknown Project" +} diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt new file mode 100644 index 00000000..55a67f3c --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt @@ -0,0 +1,12 @@ +package com.jacob.wakatimeapp.home.data.dtos + +import kotlinx.serialization.Serializable + +@Serializable +data class RangeDTO( + val date: String, + val end: String, + val start: String, + val text: String, + val timezone: String, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt index 8a8b6ddf..08a81f4c 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt @@ -1,13 +1,21 @@ package com.jacob.wakatimeapp.home.data.mappers // ktlint-disable filename -import com.jacob.wakatimeapp.core.models.* +import com.jacob.wakatimeapp.core.models.DailyStats import com.jacob.wakatimeapp.core.models.Project +import com.jacob.wakatimeapp.core.models.StatsRange +import com.jacob.wakatimeapp.core.models.Time +import com.jacob.wakatimeapp.core.models.WeeklyStats +import com.jacob.wakatimeapp.home.data.dtos.EditorDTO import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO.Data -import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO.Data.* +import com.jacob.wakatimeapp.home.data.dtos.LanguageDTO +import com.jacob.wakatimeapp.home.data.dtos.OperatingSystemDTO +import com.jacob.wakatimeapp.home.data.dtos.ProjectDTO import java.text.SimpleDateFormat import java.time.LocalDate -import java.util.* +import java.util.Date +import java.util.Locale +import java.util.TimeZone fun GetLast7DaysStatsResDTO.toModel() = WeeklyStats( totalTime = Time.createFrom(cumulativeTotal.digital, cumulativeTotal.decimal), @@ -20,12 +28,15 @@ fun GetLast7DaysStatsResDTO.toModel() = WeeklyStats( private fun getDailyStatsFromDto(data: List) = data.map { DailyStats( - timeSpent = Time.createFrom(it.grandTotal.digital, it.grandTotal.decimal), - mostUsedEditor = it.editors.maxByOrNull(Editor::percent)?.name ?: "NA", - mostUsedLanguage = it.languages.maxByOrNull(Language::percent)?.name ?: "NA", - mostUsedOs = it.operatingSystems.maxByOrNull(OperatingSystem::percent)?.name ?: "NA", + timeSpent = Time.createFrom( + digialString = it.grandTotal.digital, + decimal = it.grandTotal.decimal + ), + mostUsedEditor = it.editors.maxByOrNull(EditorDTO::percent)?.name ?: "NA", + mostUsedLanguage = it.languages.maxByOrNull(LanguageDTO::percent)?.name ?: "NA", + mostUsedOs = it.operatingSystems.maxByOrNull(OperatingSystemDTO::percent)?.name ?: "NA", date = LocalDate.parse(it.range.date), - projectsWorkedOn = it.projects.filterNot { project -> project.name == "Unknown Project" } + projectsWorkedOn = it.projects.filterNot(ProjectDTO::isUnknownProject) .map { project -> Project( Time( From da76b376ec8e5db36daacaa9a139aee5abf434cc Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Fri, 7 Oct 2022 14:43:52 +0530 Subject: [PATCH 03/32] WTA #31: Moved dtos and updated mappers. --- .idea/dictionaries/jacob.xml | 1 + .../core/common}/data/dtos/CategoryDTO.kt | 2 +- .../common/data/dtos/CumulativeTotalDTO.kt | 11 ++ .../core/common}/data/dtos/DependencyDTO.kt | 2 +- .../core/common}/data/dtos/EditorDTO.kt | 2 +- .../core/common}/data/dtos/GrandTotalDTO.kt | 2 +- .../core/common}/data/dtos/LanguageDTO.kt | 2 +- .../core/common}/data/dtos/MachineDTO.kt | 2 +- .../common}/data/dtos/OperatingSystemDTO.kt | 2 +- .../core/common}/data/dtos/ProjectDTO.kt | 2 +- .../core/common}/data/dtos/RangeDTO.kt | 2 +- .../common/data/mappers/ProjectDtoMapper.kt | 15 ++ .../home/data/dtos/GetDailyStatsResDTO.kt | 141 +++--------------- .../home/data/dtos/GetLast7DaysStatsResDTO.kt | 19 ++- .../data/mappers/GetDailyStatsResMapper.kt | 20 +-- .../data/mappers/GetWeeklyStatsResMapper.kt | 33 ++-- 16 files changed, 82 insertions(+), 176 deletions(-) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/CategoryDTO.kt (87%) create mode 100644 core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/DependencyDTO.kt (60%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/EditorDTO.kt (87%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/GrandTotalDTO.kt (85%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/LanguageDTO.kt (87%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/MachineDTO.kt (89%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/OperatingSystemDTO.kt (87%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/ProjectDTO.kt (89%) rename {home/src/main/java/com/jacob/wakatimeapp/home => core/common/src/main/java/com/jacob/wakatimeapp/core/common}/data/dtos/RangeDTO.kt (78%) create mode 100644 core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ProjectDtoMapper.kt diff --git a/.idea/dictionaries/jacob.xml b/.idea/dictionaries/jacob.xml index 2e5ef517..07213657 100644 --- a/.idea/dictionaries/jacob.xml +++ b/.idea/dictionaries/jacob.xml @@ -4,6 +4,7 @@ arturbosch bosco buildlogic + cummulative dtos ktlint snackbar diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CategoryDTO.kt similarity index 87% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CategoryDTO.kt index cad8fd91..760d2bdd 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/CategoryDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CategoryDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt new file mode 100644 index 00000000..579ddef3 --- /dev/null +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt @@ -0,0 +1,11 @@ +package com.jacob.wakatimeapp.core.common.data.dtos + +import kotlinx.serialization.Serializable + +@Serializable +data class CumulativeTotalDTO( + val decimal: String, + val digital: String, + val seconds: Double, + val text: String, +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/DependencyDTO.kt similarity index 60% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/DependencyDTO.kt index c70d70eb..bbd73b08 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/DependencyDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/DependencyDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/EditorDTO.kt similarity index 87% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/EditorDTO.kt index a35f30bc..17909d5b 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/EditorDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/EditorDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt similarity index 85% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt index 77a459e4..bffe2240 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GrandTotalDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/LanguageDTO.kt similarity index 87% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/LanguageDTO.kt index 0bea20bf..f9d1a0f9 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/LanguageDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/LanguageDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/MachineDTO.kt similarity index 89% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/MachineDTO.kt index 181ab45d..09c9f57a 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/MachineDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/MachineDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/OperatingSystemDTO.kt similarity index 87% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/OperatingSystemDTO.kt index 69316fd3..d27c9e6e 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/OperatingSystemDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/OperatingSystemDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ProjectDTO.kt similarity index 89% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ProjectDTO.kt index 53481e85..0e970450 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/ProjectDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ProjectDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/RangeDTO.kt similarity index 78% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/RangeDTO.kt index 55a67f3c..ddf793d0 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/RangeDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/RangeDTO.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data.dtos +package com.jacob.wakatimeapp.core.common.data.dtos import kotlinx.serialization.Serializable diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ProjectDtoMapper.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ProjectDtoMapper.kt new file mode 100644 index 00000000..3a1fa239 --- /dev/null +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ProjectDtoMapper.kt @@ -0,0 +1,15 @@ +package com.jacob.wakatimeapp.core.common.data.mappers // ktlint-disable filename + +import com.jacob.wakatimeapp.core.common.data.dtos.ProjectDTO +import com.jacob.wakatimeapp.core.models.Project +import com.jacob.wakatimeapp.core.models.Time + +fun ProjectDTO.toModel() = Project( + time = Time( + hours = hours, + minutes = minutes, + decimal = decimal.toFloat() + ), + name = name, + percent = percent +) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetDailyStatsResDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetDailyStatsResDTO.kt index d133dec7..f56cc6f4 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetDailyStatsResDTO.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetDailyStatsResDTO.kt @@ -1,5 +1,15 @@ package com.jacob.wakatimeapp.home.data.dtos +import com.jacob.wakatimeapp.core.common.data.dtos.CategoryDTO +import com.jacob.wakatimeapp.core.common.data.dtos.CumulativeTotalDTO +import com.jacob.wakatimeapp.core.common.data.dtos.DependencyDTO +import com.jacob.wakatimeapp.core.common.data.dtos.EditorDTO +import com.jacob.wakatimeapp.core.common.data.dtos.GrandTotalDTO +import com.jacob.wakatimeapp.core.common.data.dtos.LanguageDTO +import com.jacob.wakatimeapp.core.common.data.dtos.MachineDTO +import com.jacob.wakatimeapp.core.common.data.dtos.OperatingSystemDTO +import com.jacob.wakatimeapp.core.common.data.dtos.ProjectDTO +import com.jacob.wakatimeapp.core.common.data.dtos.RangeDTO import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -8,127 +18,18 @@ data class GetDailyStatsResDTO( val data: List, val end: String, val start: String, - @SerialName("cummulative_total") val cumulativeTotal: CumulativeTotal, + @SerialName("cummulative_total") val cumulativeTotal: CumulativeTotalDTO, ) { - @Serializable - data class CumulativeTotal( - val decimal: String, - val digital: String, - val seconds: Double, - val text: String, - ) - @Serializable data class Data( - val categories: List, - val dependencies: List, - val editors: List, - val languages: List, - val machines: List, - val projects: List, - val range: Range, - @SerialName("grand_total") val grandTotal: GrandTotal, - @SerialName("operating_systems") val operatingSystems: List, - ) { - @Serializable - data class Category( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Editor( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class GrandTotal( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Language( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Machine( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("machine_name_id") val machineNameId: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class OperatingSystem( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Project( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - - @Serializable - data class Range( - val date: String, - val end: String, - val start: String, - val text: String, - val timezone: String, - ) - - @Serializable - class Dependency - } + val categories: List, + val dependencies: List, + val editors: List, + val languages: List, + val machines: List, + val projects: List, + val range: RangeDTO, + @SerialName("grand_total") val grandTotal: GrandTotalDTO, + @SerialName("operating_systems") val operatingSystems: List, + ) } diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt index c91c6ea0..ee7f15b8 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/dtos/GetLast7DaysStatsResDTO.kt @@ -1,5 +1,15 @@ package com.jacob.wakatimeapp.home.data.dtos +import com.jacob.wakatimeapp.core.common.data.dtos.CategoryDTO +import com.jacob.wakatimeapp.core.common.data.dtos.CumulativeTotalDTO +import com.jacob.wakatimeapp.core.common.data.dtos.DependencyDTO +import com.jacob.wakatimeapp.core.common.data.dtos.EditorDTO +import com.jacob.wakatimeapp.core.common.data.dtos.GrandTotalDTO +import com.jacob.wakatimeapp.core.common.data.dtos.LanguageDTO +import com.jacob.wakatimeapp.core.common.data.dtos.MachineDTO +import com.jacob.wakatimeapp.core.common.data.dtos.OperatingSystemDTO +import com.jacob.wakatimeapp.core.common.data.dtos.ProjectDTO +import com.jacob.wakatimeapp.core.common.data.dtos.RangeDTO import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -8,15 +18,8 @@ data class GetLast7DaysStatsResDTO( val data: List, val end: String, val start: String, - @SerialName("cummulative_total") val cumulativeTotal: CumulativeTotal, + @SerialName("cummulative_total") val cumulativeTotal: CumulativeTotalDTO, ) { - @Serializable - data class CumulativeTotal( - val decimal: String, - val digital: String, - val seconds: Double, - val text: String, - ) @Serializable data class Data( diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetDailyStatsResMapper.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetDailyStatsResMapper.kt index 4fa0372e..742196ab 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetDailyStatsResMapper.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetDailyStatsResMapper.kt @@ -1,32 +1,18 @@ package com.jacob.wakatimeapp.home.data.mappers // ktlint-disable filename +import com.jacob.wakatimeapp.core.common.data.dtos.ProjectDTO +import com.jacob.wakatimeapp.core.common.data.mappers.toModel import com.jacob.wakatimeapp.core.models.DailyStats -import com.jacob.wakatimeapp.core.models.Project import com.jacob.wakatimeapp.core.models.Time import com.jacob.wakatimeapp.home.data.dtos.GetDailyStatsResDTO -import com.jacob.wakatimeapp.home.data.dtos.GetDailyStatsResDTO.Data import java.time.LocalDate import java.time.format.DateTimeFormatter fun GetDailyStatsResDTO.toModel() = DailyStats( timeSpent = Time.createFrom(cumulativeTotal.digital, cumulativeTotal.decimal), - projectsWorkedOn = getProjectsFromDto(data.first()), + projectsWorkedOn = data.first().projects.map(ProjectDTO::toModel), mostUsedLanguage = "", mostUsedEditor = "", mostUsedOs = "", date = LocalDate.parse(data.first().range.date, DateTimeFormatter.ISO_DATE) ) - -private fun getProjectsFromDto(data: Data) = data.run { - projects.map { project -> - Project( - Time( - project.hours, - project.minutes, - project.decimal.toFloat() - ), - project.name, - project.percent - ) - } -} diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt index 08a81f4c..aa25b2c5 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/GetWeeklyStatsResMapper.kt @@ -1,19 +1,18 @@ package com.jacob.wakatimeapp.home.data.mappers // ktlint-disable filename +import com.jacob.wakatimeapp.core.common.data.dtos.EditorDTO +import com.jacob.wakatimeapp.core.common.data.dtos.LanguageDTO +import com.jacob.wakatimeapp.core.common.data.dtos.OperatingSystemDTO +import com.jacob.wakatimeapp.core.common.data.dtos.ProjectDTO +import com.jacob.wakatimeapp.core.common.data.mappers.toModel import com.jacob.wakatimeapp.core.models.DailyStats -import com.jacob.wakatimeapp.core.models.Project import com.jacob.wakatimeapp.core.models.StatsRange import com.jacob.wakatimeapp.core.models.Time import com.jacob.wakatimeapp.core.models.WeeklyStats -import com.jacob.wakatimeapp.home.data.dtos.EditorDTO import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO import com.jacob.wakatimeapp.home.data.dtos.GetLast7DaysStatsResDTO.Data -import com.jacob.wakatimeapp.home.data.dtos.LanguageDTO -import com.jacob.wakatimeapp.home.data.dtos.OperatingSystemDTO -import com.jacob.wakatimeapp.home.data.dtos.ProjectDTO import java.text.SimpleDateFormat import java.time.LocalDate -import java.util.Date import java.util.Locale import java.util.TimeZone @@ -37,22 +36,12 @@ private fun getDailyStatsFromDto(data: List) = data.map { mostUsedOs = it.operatingSystems.maxByOrNull(OperatingSystemDTO::percent)?.name ?: "NA", date = LocalDate.parse(it.range.date), projectsWorkedOn = it.projects.filterNot(ProjectDTO::isUnknownProject) - .map { project -> - Project( - Time( - project.hours, - project.minutes, - project.decimal.toFloat() - ), - project.name, - project.percent - ) - } + .map(ProjectDTO::toModel) ) } -private fun parseDate(dateTimeString: String): Date { - val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US) - sdf.timeZone = TimeZone.getTimeZone("GMT") - return sdf.parse(dateTimeString)!! -} +private fun parseDate(dateTimeString: String) = + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).apply { + timeZone = TimeZone.getTimeZone("GMT") + } + .parse(dateTimeString)!! From 7d70976dd52076e0315642ca123470bc0e3a6b5b Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sat, 8 Oct 2022 12:21:24 +0530 Subject: [PATCH 04/32] WTA #31: Moved network data sources to separate package and added HomePageCache. --- home/build.gradle.kts | 2 + .../jacob/wakatimeapp/home/HomePageModule.kt | 2 +- .../home/data/local/HomePageCache.kt | 47 +++++++++++++++++++ .../home/data/{ => network}/HomePageAPI.kt | 2 +- .../data/{ => network}/HomePageNetworkData.kt | 2 +- 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 home/src/main/java/com/jacob/wakatimeapp/home/data/local/HomePageCache.kt rename home/src/main/java/com/jacob/wakatimeapp/home/data/{ => network}/HomePageAPI.kt (94%) rename home/src/main/java/com/jacob/wakatimeapp/home/data/{ => network}/HomePageNetworkData.kt (97%) diff --git a/home/build.gradle.kts b/home/build.gradle.kts index 0e139c53..e70b7b0e 100644 --- a/home/build.gradle.kts +++ b/home/build.gradle.kts @@ -6,6 +6,8 @@ dependencies { // Image Loading, Charts, Lottie Animations implementation("io.coil-kt:coil-compose:2.1.0") implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") + + implementation("androidx.datastore:datastore-preferences:1.0.0") } android { namespace = "com.jacob.wakatimeapp.home" diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/HomePageModule.kt b/home/src/main/java/com/jacob/wakatimeapp/home/HomePageModule.kt index 293051a9..760d5506 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/HomePageModule.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/HomePageModule.kt @@ -1,6 +1,6 @@ package com.jacob.wakatimeapp.home -import com.jacob.wakatimeapp.home.data.HomePageAPI +import com.jacob.wakatimeapp.home.data.network.HomePageAPI import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/local/HomePageCache.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/local/HomePageCache.kt new file mode 100644 index 00000000..3f480d4a --- /dev/null +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/local/HomePageCache.kt @@ -0,0 +1,47 @@ +package com.jacob.wakatimeapp.home.data.local + +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.longPreferencesKey +import com.jacob.wakatimeapp.core.models.WeeklyStats +import java.time.Instant +import javax.inject.Inject +import javax.inject.Singleton +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map +import kotlinx.serialization.json.Json + +@Singleton +class HomePageCache @Inject constructor( + private val dataStore: DataStore, + private val json: Json, +) { + + suspend fun getLastRequestTime(): Instant = dataStore.data.map { + val value = it[KEY_LAST_REQUEST_TIME] + value?.let(Instant::ofEpochMilli) ?: Instant.MIN + } + .catch { Instant.MIN } + .first() + + suspend fun updateLastRequestTime(time: Instant = Instant.now()) { + dataStore.edit { + it[KEY_LAST_REQUEST_TIME] = time.toEpochMilli() + } + } + + suspend fun getCachedData(): Flow { + TODO() + } + + suspend fun updateCache(weeklyStats: WeeklyStats) { + TODO("Not yet implemented") + } + + companion object { + private val KEY_LAST_REQUEST_TIME = longPreferencesKey("KEY_LAST_REQUEST_TIME") + } +} diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/network/HomePageAPI.kt similarity index 94% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt rename to home/src/main/java/com/jacob/wakatimeapp/home/data/network/HomePageAPI.kt index a9467150..70d8dbea 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageAPI.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/network/HomePageAPI.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data +package com.jacob.wakatimeapp.home.data.network import com.jacob.wakatimeapp.home.data.dtos.AllTimeDataDTO import com.jacob.wakatimeapp.home.data.dtos.GetDailyStatsResDTO diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt b/home/src/main/java/com/jacob/wakatimeapp/home/data/network/HomePageNetworkData.kt similarity index 97% rename from home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt rename to home/src/main/java/com/jacob/wakatimeapp/home/data/network/HomePageNetworkData.kt index 86063a73..06e6a9f2 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/data/HomePageNetworkData.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/data/network/HomePageNetworkData.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.data +package com.jacob.wakatimeapp.home.data.network import arrow.core.Either import arrow.core.left From 718d65078bc9b927381a9ea0f15bd6fd0f4da4bf Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sat, 8 Oct 2022 12:24:49 +0530 Subject: [PATCH 05/32] WTA #31: Updated GetLast7DaysStatsUC to handle getting data from cache. --- .idea/dictionaries/jacob.xml | 1 + .../jacob/wakatimeapp/core/models/Error.kt | 4 + .../home/usecases/GetDailyStatsUC.kt | 2 +- .../home/usecases/GetLast7DaysStatsUC.kt | 96 ++++++++++++++++++- 4 files changed, 100 insertions(+), 3 deletions(-) diff --git a/.idea/dictionaries/jacob.xml b/.idea/dictionaries/jacob.xml index 07213657..d92947ab 100644 --- a/.idea/dictionaries/jacob.xml +++ b/.idea/dictionaries/jacob.xml @@ -7,6 +7,7 @@ cummulative dtos ktlint + mins snackbar waka wakatime diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt index 2993a9e6..a8b1e5a8 100644 --- a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Error.kt @@ -40,4 +40,8 @@ sealed class Error : Exception() { } } } + + data class UnknownError(val error: Throwable) : Error() { + override val message: String = error.message!! + } } diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt index 1b8ed78c..28185885 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetDailyStatsUC.kt @@ -1,6 +1,6 @@ package com.jacob.wakatimeapp.home.usecases -import com.jacob.wakatimeapp.home.data.HomePageNetworkData +import com.jacob.wakatimeapp.home.data.network.HomePageNetworkData import javax.inject.Inject import javax.inject.Singleton diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt index aeb70d14..aa577dcc 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUC.kt @@ -1,12 +1,104 @@ package com.jacob.wakatimeapp.home.usecases -import com.jacob.wakatimeapp.home.data.HomePageNetworkData +import arrow.core.Either +import arrow.core.left +import arrow.core.right +import com.jacob.wakatimeapp.core.models.Error +import com.jacob.wakatimeapp.core.models.WeeklyStats +import com.jacob.wakatimeapp.home.data.local.HomePageCache +import com.jacob.wakatimeapp.home.data.network.HomePageNetworkData +import java.time.Duration +import java.time.Instant +import java.time.temporal.ChronoUnit import javax.inject.Inject import javax.inject.Singleton +import kotlin.coroutines.CoroutineContext +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.FlowCollector +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.emitAll +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map @Singleton class GetLast7DaysStatsUC @Inject constructor( + dispatcher: CoroutineContext = Dispatchers.IO, private val homePageNetworkData: HomePageNetworkData, + private val homePageCache: HomePageCache, ) { - suspend operator fun invoke() = homePageNetworkData.getLast7DaysStats() + private val ioScope = CoroutineScope(dispatcher) + + /** + * Gets the stats for the last 7 days from the cache if the last request was made within the + * last 15 minutes, otherwise it will fetch the data from the network and update the cache. + * + * If the latest value in the cache is from the previous day, it will fetch the data from the + * network and not show the cached data. + * + * Data is always sent from the database, network data is sent to the db which then sends to + * the UI + * + * @return A flow of either a [WeeklyStats] or an [Error] + */ + operator fun invoke(): Flow> = flow { + /* + * (1) (2) (3) + ----------|-----------------------------------------------|-------------------|--- + start of day 15 mins aga now + * + * check if last request falls in (1), if it does make request and update cache + * if it falls in (2) or (3) then get data from cache, + * if its in (1) or (3) return. + * if its in (2) then make request and update cache + */ + val lastRequestTime = homePageCache.getLastRequestTime() + + if (lastRequestTime.isPreviousDay()) makeRequestAndUpdateCache() + + homePageCache.getCachedData() + .map { it.right() } + .catch { throwable -> + Error.UnknownError(throwable) + .left() + .let { emit(it) } + } + .let { emitAll(it) } + + if (lastRequestTime.isLessThan15Mins()) return@flow + if (lastRequestTime.isPreviousDay()) return@flow + + makeRequestAndUpdateCache() + } + + private suspend fun FlowCollector>.makeRequestAndUpdateCache() { + homePageNetworkData.getLast7DaysStats() + .tap { it.updateCaches() } + .tapLeft { emit(it.left()) } + } + + private fun Instant.isPreviousDay(): Boolean { + val startOfDay = Instant.now() + .plus(1, ChronoUnit.DAYS) + .truncatedTo(ChronoUnit.DAYS) + + return isBefore(startOfDay) + } + + private fun Instant.isLessThan15Mins(): Boolean { + val minutesBetweenLastRequest = Duration.between(this, Instant.now()) + .toMinutes() + return minutesBetweenLastRequest < 15 + } + + private suspend fun WeeklyStats.updateCaches() { + listOf( + ioScope.async { homePageCache.updateCache(this@updateCaches) }, + ioScope.async { homePageCache.updateLastRequestTime() }, + ) + .awaitAll() + } } From 4898d28e6976a18b213f851b4db3f41b63edcde7 Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sat, 8 Oct 2022 12:37:46 +0530 Subject: [PATCH 06/32] WTA #31: Fixed HomePageViewModel. --- .../wakatimeapp/home/ui/HomePageViewModel.kt | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePageViewModel.kt b/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePageViewModel.kt index 62e6dc26..85578ae2 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePageViewModel.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePageViewModel.kt @@ -6,14 +6,15 @@ import androidx.lifecycle.viewModelScope import arrow.core.Either.Left import arrow.core.Either.Right import com.jacob.wakatimeapp.core.common.auth.AuthDataStore +import com.jacob.wakatimeapp.home.ui.HomePageViewState.Error import com.jacob.wakatimeapp.home.ui.HomePageViewState.Loaded import com.jacob.wakatimeapp.home.usecases.GetLast7DaysStatsUC import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import kotlin.coroutines.CoroutineContext -import kotlinx.coroutines.async import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch @@ -28,25 +29,20 @@ class HomePageViewModel @Inject constructor( private val _homePageState = MutableStateFlow(HomePageViewState.Loading) val homePageState = _homePageState.asStateFlow() + private val userDetailsFlow = authDataStore.getUserDetails() + .distinctUntilChanged() init { viewModelScope.launch(ioDispatcher) { - val deferredResult = async { getLast7DaysStatsUC() } - - authDataStore.getUserDetails() - .distinctUntilChanged() - .collect { userDetails -> - when (val result = deferredResult.await()) { - is Right -> _homePageState.value = Loaded( - result.value, - userDetails - ) - - is Left -> - _homePageState.value = - result.value.message.let(HomePageViewState::Error) - } + combine( + getLast7DaysStatsUC(), + userDetailsFlow, + ) { either, userDetails -> + when (either) { + is Left -> Error(either.value.message) + is Right -> Loaded(contentData = either.value, userDetails = userDetails) } + }.collect { _homePageState.value = it } } } } From 9c74bd059b183b31d01b6d82a3356c8db7b2e08e Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sat, 8 Oct 2022 13:51:05 +0530 Subject: [PATCH 07/32] WTA #31: Added dependencies and setup for testing. --- build.gradle.kts | 1 + .../src/main/kotlin/wakatimeapp.android.feature.gradle | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e544ce4c..4438f1ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,7 @@ buildscript { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10") classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.2") classpath("com.google.dagger:hilt-android-gradle-plugin:2.42") + classpath("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1") } } diff --git a/buildSrc/src/main/kotlin/wakatimeapp.android.feature.gradle b/buildSrc/src/main/kotlin/wakatimeapp.android.feature.gradle index 466ada5a..7232585a 100644 --- a/buildSrc/src/main/kotlin/wakatimeapp.android.feature.gradle +++ b/buildSrc/src/main/kotlin/wakatimeapp.android.feature.gradle @@ -4,6 +4,7 @@ plugins { id("org.jetbrains.kotlin.kapt") id("dagger.hilt.android.plugin") id("org.jetbrains.kotlin.plugin.serialization") + id("de.mannodermaus.android-junit5") id("wakatimeapp.detekt") } @@ -75,7 +76,12 @@ dependencies { implementation("io.arrow-kt:arrow-core:1.0.1") // Base testing dependencies - testImplementation("junit:junit:4.13.2") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") + testImplementation("io.mockk:mockk:1.13.2") + testImplementation("io.kotest:kotest-assertions-core:5.5.0") + androidTestImplementation("androidx.test.ext:junit:1.1.3") - androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0") + + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2") } From 9f0fbd6683e484192b55332a2c2ac3f858357ce4 Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sun, 9 Oct 2022 22:18:59 +0530 Subject: [PATCH 08/32] WTA #31: Removed tests from other modules. --- .../wakatimeapp/core/models/ExampleUnitTest.kt | 16 ---------------- .../jacob/wakatimeapp/core/ui/ExampleUnitTest.kt | 16 ---------------- .../jacob/wakatimeapp/details/ExampleUnitTest.kt | 16 ---------------- .../jacob/wakatimeapp/home/ExampleUnitTest.kt | 16 ---------------- .../jacob/wakatimeapp/login/ExampleUnitTest.kt | 16 ---------------- 5 files changed, 80 deletions(-) delete mode 100644 core/models/src/test/java/com/jacob/wakatimeapp/core/models/ExampleUnitTest.kt delete mode 100644 core/ui/src/test/java/com/jacob/wakatimeapp/core/ui/ExampleUnitTest.kt delete mode 100644 details/src/test/java/com/jacob/wakatimeapp/details/ExampleUnitTest.kt delete mode 100644 home/src/test/java/com/jacob/wakatimeapp/home/ExampleUnitTest.kt delete mode 100644 login/src/test/java/com/jacob/wakatimeapp/login/ExampleUnitTest.kt diff --git a/core/models/src/test/java/com/jacob/wakatimeapp/core/models/ExampleUnitTest.kt b/core/models/src/test/java/com/jacob/wakatimeapp/core/models/ExampleUnitTest.kt deleted file mode 100644 index 1c65df70..00000000 --- a/core/models/src/test/java/com/jacob/wakatimeapp/core/models/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.jacob.wakatimeapp.core.models - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/core/ui/src/test/java/com/jacob/wakatimeapp/core/ui/ExampleUnitTest.kt b/core/ui/src/test/java/com/jacob/wakatimeapp/core/ui/ExampleUnitTest.kt deleted file mode 100644 index 491a0b42..00000000 --- a/core/ui/src/test/java/com/jacob/wakatimeapp/core/ui/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.jacob.wakatimeapp.core.ui - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/details/src/test/java/com/jacob/wakatimeapp/details/ExampleUnitTest.kt b/details/src/test/java/com/jacob/wakatimeapp/details/ExampleUnitTest.kt deleted file mode 100644 index 8aefcac3..00000000 --- a/details/src/test/java/com/jacob/wakatimeapp/details/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.jacob.wakatimeapp.details - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/home/src/test/java/com/jacob/wakatimeapp/home/ExampleUnitTest.kt b/home/src/test/java/com/jacob/wakatimeapp/home/ExampleUnitTest.kt deleted file mode 100644 index 3b096eb4..00000000 --- a/home/src/test/java/com/jacob/wakatimeapp/home/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.jacob.wakatimeapp.home - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/login/src/test/java/com/jacob/wakatimeapp/login/ExampleUnitTest.kt b/login/src/test/java/com/jacob/wakatimeapp/login/ExampleUnitTest.kt deleted file mode 100644 index 95e1791e..00000000 --- a/login/src/test/java/com/jacob/wakatimeapp/login/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.jacob.wakatimeapp.login - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} From b2b7a6b1fe09fa8d79c32bba6bf19b722a372f81 Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sun, 9 Oct 2022 22:20:10 +0530 Subject: [PATCH 09/32] WTA #31: Added some tests for GetLast7DaysStatsUC. --- .idea/ktlint.xml | 1 + .../home/usecases/GetLast7DaysStatsUCTest.kt | 198 ++++++++++++++++++ tools/detekt-config.yml | 2 + 3 files changed, 201 insertions(+) create mode 100644 home/src/test/java/com/jacob/wakatimeapp/home/usecases/GetLast7DaysStatsUCTest.kt diff --git a/.idea/ktlint.xml b/.idea/ktlint.xml index 0b40c9bc..24d7ab69 100644 --- a/.idea/ktlint.xml +++ b/.idea/ktlint.xml @@ -8,6 +8,7 @@