Skip to content

Commit

Permalink
Merge pull request #38
Browse files Browse the repository at this point in the history
Add caching for home page
  • Loading branch information
Jacob3075 authored Oct 16, 2022
2 parents 3e6018e + 26f1166 commit 0273bd1
Show file tree
Hide file tree
Showing 64 changed files with 1,071 additions and 682 deletions.
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/dictionaries/jacob.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.legacy:legacy-support-v4:1.0.0")

implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

// Compose
implementation("androidx.compose.ui:ui:1.2.1")

implementation("com.google.android.material:material:1.7.0-rc01")
implementation("androidx.compose.material3:material3:1.0.0-rc01")
implementation("androidx.compose.ui:ui-tooling-preview:1.2.1")
Expand Down
16 changes: 14 additions & 2 deletions buildSrc/src/main/kotlin/wakatimeapp.android.feature.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
id("org.jetbrains.kotlin.kapt")
id("dagger.hilt.android.plugin")
id("org.jetbrains.kotlin.plugin.serialization")
id("de.mannodermaus.android-junit5")
id("com.google.devtools.ksp")

id("wakatimeapp.detekt")
}
Expand Down Expand Up @@ -49,6 +51,7 @@ dependencies {

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.5.1")
Expand All @@ -75,7 +78,16 @@ 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")
}

kapt {
correctErrorTypes = true
}
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/wakatimeapp.android.library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")

implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

// Hilt
implementation("com.google.dagger:hilt-android:2.43.1")
kapt("com.google.dagger:hilt-android-compiler:2.43.1")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jacob.wakatimeapp.core.common
package com.jacob.wakatimeapp.core.common // ktlint-disable filename

import java.time.LocalDate
import java.time.format.TextStyle.SHORT
import java.util.*
import java.util.Locale
import kotlinx.datetime.LocalDate

fun LocalDate.getDisplayNameForDay(): String =
dayOfWeek.getDisplayName(SHORT, Locale.getDefault())
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import androidx.datastore.preferences.core.stringPreferencesKey
import com.jacob.wakatimeapp.core.models.UserDetails
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.Json.Default
import net.openid.appauth.AuthState

class AuthDataStore @Inject constructor(
Expand All @@ -20,9 +20,9 @@ class AuthDataStore @Inject constructor(
) {
fun getUserDetails(): Flow<UserDetails> =
dataStore.data.map { preferences ->
preferences[KEY_USER_DETAILS]?.let(Default::decodeFromString)
?: error("SHOULD NOT HAPPEN")
preferences[KEY_USER_DETAILS]?.let<String, UserDetails>(json::decodeFromString)
}
.filterNotNull()

suspend fun updateUserDetails(userDetails: UserDetails) {
dataStore.edit {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jacob.wakatimeapp.core.common.data.dtos

import kotlinx.serialization.Serializable

@Serializable
class DependencyDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.jacob.wakatimeapp.core.common.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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jacob.wakatimeapp.core.common.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,
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jacob.wakatimeapp.core.models

import java.time.LocalDate
import kotlinx.datetime.LocalDate

data class DailyStats(
val timeSpent: Time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package com.jacob.wakatimeapp.core.models

import timber.log.Timber

sealed class Error : Exception() {
abstract override val message: String
sealed class Error {
abstract val message: String
open val exception: Throwable? = null

sealed class DomainError : Error() {
data class InvalidData(override val message: String) : DomainError()
Expand All @@ -14,7 +15,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() {
Expand All @@ -32,15 +33,20 @@ 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
}
}

sealed class DatabaseError : Error() {
data class EmptyCache(override val message: String) : DatabaseError()
data class UnknownError(override val message: String, override val exception: Throwable) :
DatabaseError()
}

data class UnknownError(override val message: String, val error: Throwable? = null) : Error()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.jacob.wakatimeapp.core.models

import kotlinx.serialization.Serializable

@Serializable
data class Project(
val time: Time,
val name: String,
Expand Down
Loading

0 comments on commit 0273bd1

Please sign in to comment.