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

Add detekt #5

Merged
merged 5 commits into from
Jan 10, 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
43 changes: 0 additions & 43 deletions .github/workflows/android_ci.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build Project

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Decode google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo "$GOOGLE_SERVICES_JSON" | base64 --decode > app/google-services.json

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Build gradle project
run: ./gradlew build
29 changes: 29 additions & 0 deletions .github/workflows/code_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Code Analysis

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
detekt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Decode google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo "$GOOGLE_SERVICES_JSON" | base64 --decode > app/google-services.json

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Run Detekt
run: ./gradlew detekt
29 changes: 29 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Unit Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Decode google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo "$GOOGLE_SERVICES_JSON" | base64 --decode > app/google-services.json

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Run Unit Tests
run: ./gradlew test
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import java.time.Instant
data class LaunchedEffectResult<T>(
val data: T,
val timestamp: Long = Instant.now().toEpochMilli()
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sealed class NativeText {
data class Multi(val text: List<NativeText>) : NativeText()
}

@Suppress("SpreadOperator")
fun NativeText.asString(context: Context): String {
return when (this) {
is NativeText.Arguments -> context.getString(id, *args.toTypedArray())
Expand All @@ -32,4 +33,4 @@ fun NativeText.asString(context: Context): String {
is NativeText.Simple -> text
is NativeText.Empty -> ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.grappim.hateitorrateit.core

import kotlinx.coroutines.flow.SharingStarted

private const val StopTimeoutMillis: Long = 5000
private const val STOP_TIMEOUT_MILLIS: Long = 5000

/**
* A [SharingStarted] meant to be used with a [StateFlow] to expose data to a view.
Expand All @@ -13,4 +13,4 @@ private const val StopTimeoutMillis: Long = 5000
* back, the latest value is replayed and the upstream flows are executed again. This is done to
* save resources when the app is in the background but let users switch between apps quickly.
*/
val WhileViewSubscribed: SharingStarted = SharingStarted.WhileSubscribed(StopTimeoutMillis)
val WhileViewSubscribed: SharingStarted = SharingStarted.WhileSubscribed(STOP_TIMEOUT_MILLIS)
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class SnackbarStateViewModelImpl : SnackbarStateViewModel {
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ sealed interface HomeNavDestination {
override val title: String = "Settings"
override val imageVector: ImageVector = PlatoIconType.Settings.imageVector
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ sealed interface RootNavDestinations {
override val route: String = "${PREFIX}?productId={$KEY_PRODUCT_ID}&index={$KEY_INDEX}"
fun getRouteWithUri(productId: String, index: Int) = "${PREFIX}?productId=$productId&index=$index"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ private class DevelopmentTree : Timber.DebugTree() {

private class ProductionTree : Timber.Tree() {

@Suppress("EmptyFunctionBlock")
override fun log(
priority: Int,
tag: String?,
message: String,
t: Throwable?
) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.grappim.hateitorrateit.model

import com.grappim.hateitorrateit.domain.ProductImageData

data class ProcuctDetailsImageUi(
data class ProductDetailsImageUi(
val filesUri: List<ProductImageData> = emptyList(),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class UiModelsMapper @Inject constructor(
)
}

suspend fun toProductDetailsImageUI(product: Product): ProcuctDetailsImageUi =
suspend fun toProductDetailsImageUI(product: Product): ProductDetailsImageUi =
withContext(ioDispatcher) {
ProcuctDetailsImageUi(
ProductDetailsImageUi(
filesUri = product.filesUri,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const val DETAILS_TOP_APP_BAR_TAG = "details_top_app_bar_tag"
const val DETAILS_EDIT_CONTENT_TAG = "details_edit_content_tag"
const val DETAILS_DEMONSTRATION_CONTENT_TAG = "details_demonstration_content_tag"

private const val TOP_APP_BAR_WEIGHT = 1.2f

@Composable
fun DetailsRoute(
viewModel: DetailsViewModel = hiltViewModel(),
Expand Down Expand Up @@ -138,7 +140,7 @@ private fun DetailsScreenContent(
TopAppBarContent(
modifier = Modifier
.fillMaxWidth()
.weight(1.2f),
.weight(TOP_APP_BAR_WEIGHT),
state = state,
onImageClicked = onImageClicked,
goBack = goBack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private fun RateOrHateScreenContent(
.fillMaxWidth()
.padding(
top = 12.dp,
bottom = 16.dp
bottom = 16.dp,
)
.padding(horizontal = 16.dp),
state = state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import com.grappim.hateitorrateit.ui.widgets.PlatoTopBar
const val CROSSFADE_TAG = "crossfade_tag"
const val CRASHLYTICS_TILE_TAG = "crashlytics_tile_tag"

private const val ANIMATION_DURATION = 500

@Composable
internal fun SettingsRoute(
goBack: () -> Unit,
Expand Down Expand Up @@ -117,7 +119,7 @@ fun TypeIcon(
Crossfade(
targetState = state.type,
label = "type_crossfade_icon",
animationSpec = tween(500),
animationSpec = tween(ANIMATION_DURATION),
) { type ->
Icon(
modifier = Modifier
Expand All @@ -137,7 +139,7 @@ fun CrashesIcon(
modifier = Modifier.testTag(CROSSFADE_TAG),
targetState = state.isCrashesCollectionEnabled,
label = "custom_switch_label",
animationSpec = tween(500),
animationSpec = tween(ANIMATION_DURATION),
) { enabled ->
val imageVector = if (enabled) {
PlatoIconType.CheckCircleOutline.imageVector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class SettingsViewState(
val onDismissDialog: () -> Unit,
val onCrashlyticsToggle: () -> Unit
) {
@Suppress("LongParameterList")
fun safeCopy(
isLoading: Boolean = this.isLoading,
type: HateRateType = this.type,
Expand Down
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@ plugins {
alias(libs.plugins.gms.googleServices) apply false
alias(libs.plugins.hilt.android) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.detekt)
}

subprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
}

detekt {
parallel = true
config.setFrom(rootProject.files("config/detekt/detekt.yml"))
allRules = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ class CoroutinesModule {
fun provideApplicationScope(
@DefaultDispatcher defaultDispatcher: CoroutineDispatcher
): CoroutineScope = CoroutineScope(SupervisorJob() + defaultDispatcher)
}
}
Loading