Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/upgradelints #20

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ root = true
charset = utf-8

[*.{kt,kts}]
ktlint_code_style = android
ktlint_code_style = ktlint_official
ktlint_standard = enabled
ktlint_experimental = enabled

ktlint_standard_final-newline = disabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
Expand All @@ -12,3 +15,6 @@ ktlint_standard_import-ordering = disabled
ktlint_standard_chain-method-continuation = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_backing-property-naming = disabled

# disable for Jetpack Compose
ktlint_standard_function-naming = disabled
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ koin-annotation = "1.3.1"
koin-compose = "3.5.6"

# code check
kotlinter = "3.15.0"
slack-compose-lint = "1.2.0"
kotlinter = "4.3.0"
slack-compose-lint = "1.3.1"

# sql delight
sqldelight = "2.0.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import app.cash.sqldelight.driver.android.AndroidSqliteDriver
actual class DatabaseDriverFactory(
private val context: Context
) {
actual fun createDriver(): SqlDriver {
return AndroidSqliteDriver(
actual fun createDriver(): SqlDriver =
AndroidSqliteDriver(
schema = AppDatabase.Schema,
context = context,
name = "app_database.db"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
import org.koin.ksp.generated.module

val androidDatabaseModule = module {
single<SqlDriver> {
DatabaseDriverFactory(androidContext()).createDriver()
}
includes(
DatabaseModule().module,
DaoModule().module,
DataMapperModule().module
)
}
val androidDatabaseModule =
module {
single<SqlDriver> {
DatabaseDriverFactory(androidContext()).createDriver()
}
includes(
DatabaseModule().module,
DaoModule().module,
DataMapperModule().module
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import kotlinx.coroutines.Dispatchers
import org.koin.core.qualifier.named
import org.koin.dsl.module

val androidDispatcherModule = module {
includes(dispatcherModule)
factory<CoroutineDispatcher>(named("Main")) {
Dispatchers.Main
}
}
val androidDispatcherModule =
module {
includes(dispatcherModule)
factory<CoroutineDispatcher>(named("Main")) {
Dispatchers.Main
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import kotlinx.coroutines.flow.Flow

interface CategoryLocalDataSource {
suspend fun getCategoryById(id: Long): Category?

fun getCategories(): Flow<List<Category>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ class CategoryLocalDataSourceImpl(
@Named("Default") private val defaultDispatcher: CoroutineDispatcher,
appDatabase: AppDatabase
) : CategoryLocalDataSource {

private val queries = appDatabase.categoryQueries

override suspend fun getCategoryById(id: Long): Category? = withContext(ioDispatcher) {
queries.getCategoryById(id).executeAsOneOrNull()
}
override suspend fun getCategoryById(id: Long): Category? =
withContext(ioDispatcher) {
queries.getCategoryById(id).executeAsOneOrNull()
}

override fun getCategories(): Flow<List<Category>> {
return queries.getAllCategories().asFlow().mapToList(defaultDispatcher)
}
override fun getCategories(): Flow<List<Category>> = queries.getAllCategories().asFlow().mapToList(defaultDispatcher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import kotlinx.coroutines.flow.Flow

interface WorkoutLocalDataSource {
suspend fun getWorkoutsByCategoryId(id: Long): List<Workout>

suspend fun getWorkout(id: Long): Workout?

suspend fun updateInitialDate(initialDate: String)

suspend fun getInitialGeneratedWorkoutCounts(): Int

fun getWorkoutsFlow(categoryId: Long): Flow<List<Workout>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@ class WorkoutLocalDataSourceImpl(
@Named("Default") private val defaultDispatcher: CoroutineDispatcher,
appDatabase: AppDatabase
) : WorkoutLocalDataSource {

private val queries = appDatabase.workoutQueries

override suspend fun getWorkoutsByCategoryId(id: Long): List<Workout> =
withContext(ioDispatcher) {
queries.getWorkoutsByCategoryId(id).executeAsList()
}

override suspend fun getWorkout(id: Long): Workout? {
return queries.getWorkoutById(id).executeAsOneOrNull()
}
override suspend fun getWorkout(id: Long): Workout? = queries.getWorkoutById(id).executeAsOneOrNull()

override suspend fun updateInitialDate(initialDate: String) = withContext(ioDispatcher) {
queries.updateInitalCreateDate(initialDate, initialDate)
}
override suspend fun updateInitialDate(initialDate: String) =
withContext(ioDispatcher) {
queries.updateInitalCreateDate(initialDate, initialDate)
}

override suspend fun getInitialGeneratedWorkoutCounts(): Int {
return queries.getInitialGenerateWorkoutCounts().executeAsOneOrNull()?.toInt() ?: 0
}
override suspend fun getInitialGeneratedWorkoutCounts(): Int =
queries.getInitialGenerateWorkoutCounts().executeAsOneOrNull()?.toInt() ?: 0

override fun getWorkoutsFlow(categoryId: Long): Flow<List<Workout>> {
return queries.getWorkoutsByCategoryId(categoryId).asFlow().mapToList(defaultDispatcher)
}
override fun getWorkoutsFlow(categoryId: Long): Flow<List<Workout>> =
queries.getWorkoutsByCategoryId(categoryId).asFlow().mapToList(defaultDispatcher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import kotlinx.coroutines.flow.Flow

interface WorkoutRecordDataSource {
fun getWorkoutRecordDetails(workoutId: Long): Flow<List<RecordDetails>>

suspend fun insertRecordDetails(recordDetails: RecordDetails)

suspend fun updateRecordDetails(recordDetails: RecordDetails)

suspend fun deleteRecordDetails(id: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,44 @@ class WorkoutRecordDataSourceImpl(
@Named("Default") private val defaultDispatcher: CoroutineDispatcher,
appDatabase: AppDatabase
) : WorkoutRecordDataSource {

private val detailsQueries = appDatabase.recordDetailsQueries

override fun getWorkoutRecordDetails(workoutId: Long): Flow<List<RecordDetails>> {
return detailsQueries.getRecordDetails(workoutId).asFlow().mapToList(defaultDispatcher)
}

override suspend fun insertRecordDetails(
recordDetails: RecordDetails
) = withContext(ioDispatcher) {
detailsQueries.insertNewRecord(
id = null,
workoutId = recordDetails.workoutId,
createAt = recordDetails.createAt,
lastModified = recordDetails.createAt,
sportRecordTypeId = recordDetails.sportRecordTypeId,
weight = recordDetails.weight,
reps = recordDetails.reps,
time = recordDetails.time,
distance = recordDetails.distance
)
}

override suspend fun updateRecordDetails(
recordDetails: RecordDetails
) = withContext(ioDispatcher) {
if (recordDetails.id == RECORD_EMPTY_ID.toLong()) {
return@withContext
override fun getWorkoutRecordDetails(workoutId: Long): Flow<List<RecordDetails>> =
detailsQueries.getRecordDetails(workoutId).asFlow().mapToList(defaultDispatcher)

override suspend fun insertRecordDetails(recordDetails: RecordDetails) =
withContext(ioDispatcher) {
detailsQueries.insertNewRecord(
id = null,
workoutId = recordDetails.workoutId,
createAt = recordDetails.createAt,
lastModified = recordDetails.createAt,
sportRecordTypeId = recordDetails.sportRecordTypeId,
weight = recordDetails.weight,
reps = recordDetails.reps,
time = recordDetails.time,
distance = recordDetails.distance
)
}

detailsQueries.updateRecord(
id = recordDetails.id,
lastModified = recordDetails.lastModified,
weight = recordDetails.weight,
reps = recordDetails.reps,
time = recordDetails.time,
distance = recordDetails.distance
)
}
override suspend fun updateRecordDetails(recordDetails: RecordDetails) =
withContext(ioDispatcher) {
if (recordDetails.id == RECORD_EMPTY_ID.toLong()) {
return@withContext
}

detailsQueries.updateRecord(
id = recordDetails.id,
lastModified = recordDetails.lastModified,
weight = recordDetails.weight,
reps = recordDetails.reps,
time = recordDetails.time,
distance = recordDetails.distance
)
}

override suspend fun deleteRecordDetails(id: Long) = withContext(ioDispatcher) {
detailsQueries.deleteRecord(id)
}
override suspend fun deleteRecordDetails(id: Long) =
withContext(ioDispatcher) {
detailsQueries.deleteRecord(id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ import org.koin.core.annotation.Single

@Module
class DatabaseModule {

@Single
fun provideAppDatabase(sqlDriver: SqlDriver): AppDatabase {
return AppDatabase(sqlDriver)
}
fun provideAppDatabase(sqlDriver: SqlDriver): AppDatabase = AppDatabase(sqlDriver)

@Factory
fun provideDateTimeConverter(): DateTimeConverter {
return DateTimeConverter()
}
fun provideDateTimeConverter(): DateTimeConverter = DateTimeConverter()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

class DateTimeConverter {
fun provideCurrentMoment(): LocalDateTime = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())

fun provideCurrentMoment(): LocalDateTime {
return Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
}
fun provideNowTimeStamps(): String = toDatabaseDateTime(Clock.System.now())

fun provideNowTimeStamps(): String {
return toDatabaseDateTime(Clock.System.now())
}
fun toDatabaseDateTime(dateTime: Instant): String = dateTime.toString()

fun toDatabaseDateTime(dateTime: Instant): String {
return dateTime.toString()
}

fun toLocalDateTime(timeStamps: String): LocalDateTime {
return Instant.parse(timeStamps).toLocalDateTime(TimeZone.currentSystemDefault())
}
fun toLocalDateTime(timeStamps: String): LocalDateTime = Instant.parse(timeStamps).toLocalDateTime(TimeZone.currentSystemDefault())
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import org.koin.core.annotation.Factory

@Factory
class CategoryMapper : Mapper<Category, SportCategory> {
override fun map(input: Category): SportCategory {
return SportCategory(
override fun map(input: Category): SportCategory =
SportCategory(
id = input.id.toInt(),
name = input.name
)
}
}

@Factory
class CategoryListMapper(
private val mapper: CategoryMapper
) : NullableInputListMapper<Category, SportCategory> {
override fun map(input: List<Category>?): List<SportCategory> {
return input?.map { mapper.map(it) }.orEmpty()
}
override fun map(input: List<Category>?): List<SportCategory> = input?.map { mapper.map(it) }.orEmpty()
}
Loading
Loading