Skip to content

Commit

Permalink
chore: ktlint (#27)
Browse files Browse the repository at this point in the history
* chore: setup ktlint

* refactor: move test to correct package
  • Loading branch information
adrielcafe authored Oct 20, 2019
1 parent 3be8890 commit 9e3b205
Show file tree
Hide file tree
Showing 30 changed files with 94 additions and 88 deletions.
5 changes: 5 additions & 0 deletions android-module.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "org.jlleitschuh.gradle.ktlint"

repositories {
mavenCentral()
Expand Down Expand Up @@ -84,6 +85,10 @@ androidExtensions {
experimental = true
}

ktlint {
android = true
}

configurations.all {
resolutionStrategy {
forcedModules = AndroidModule.main.toArray()
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
mavenLocal()
google()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url 'https://kotlin.bintray.com/kotlinx' }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://dl.bintray.com/android/android-tools' }
maven { url 'https://plugins.gradle.org/m2/' }
jcenter()
}

dependencies {
classpath BuildPlugins.androidGradlePlugin
classpath BuildPlugins.kotlinGradlePlugin
classpath BuildPlugins.kotlinxSerializiationPlugin
classpath BuildPlugins.ktlint
}
}

Expand All @@ -39,4 +39,4 @@ allprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
5 changes: 3 additions & 2 deletions buildSrc/src/main/java/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ object Versions {
const val kotlin = "1.3.50"
const val androidGradleSupport = "3.5.1"
const val gmsSupport = "4.3.2"
const val ktlint = "9.0.0"

const val okhttp4 = "4.2.1"
const val retrofit2 = "2.6.2"
Expand Down Expand Up @@ -92,8 +93,8 @@ object BuildPlugins {

val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.androidGradleSupport}"
val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
val kotlinxSerializiationPlugin =
"org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}"
val kotlinxSerializiationPlugin = "org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}"
val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlint}"

val gmsPlugin = "com.google.gms:google-services:${Versions.gmsSupport}"
val firebaseCrashlytics = "io.fabric.tools:gradle:${Versions.fabric}"
Expand Down
1 change: 0 additions & 1 deletion data/src/main/java/com/jcaique/data/di/injection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.singleton


private val interceptors =
listOf(HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import com.jcaique.domain.errors.GatewayIntegrationIssues
import retrofit2.HttpException

internal object HttpErrorHandler : ErrorTransformer {
override suspend fun transform(incoming: Throwable): Throwable = when(incoming){
override suspend fun transform(incoming: Throwable): Throwable = when (incoming) {
is HttpException -> handleHttpError(incoming.code())
else -> incoming
}

private fun handleHttpError(code: Int): Throwable = when(code){
private fun handleHttpError(code: Int): Throwable = when (code) {
404 -> GatewayIntegrationIssues.NotFound
in 400..499 -> GatewayIntegrationIssues.ClientIssue
else -> GatewayIntegrationIssues.ServerIssue
in 400..499 -> GatewayIntegrationIssues.ClientIssue
else -> GatewayIntegrationIssues.ServerIssue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ internal object OkHttpClientProvider {
}
}
.build()

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import kotlinx.serialization.Serializable

@Serializable
internal data class DialectResponse(
val slug: String,
val dialect: String,
val meanings: List<String>,
val examples: List<String>
val slug: String,
val dialect: String,
val meanings: List<String>,
val examples: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
internal data class RegionResponse(
val name: String,
val total: Int
val name: String,
val total: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import retrofit2.http.Query
internal interface DialetusGateway {

@GET("regions")
suspend fun fetchRegions() : List<RegionResponse>
suspend fun fetchRegions(): List<RegionResponse>

@GET("regions/{region}/dialects")
suspend fun getDialectsBy(@Path("region") region: String) : List<DialectResponse>
suspend fun getDialectsBy(@Path("region") region: String): List<DialectResponse>

@GET("search")
suspend fun searchDialects(@Query("q") query: String) : Map<String, List<DialectResponse>>
suspend fun searchDialects(@Query("q") query: String): Map<String, List<DialectResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import com.jcaique.domain.models.Dialect
import com.jcaique.domain.models.DialectSlug

internal class DialectsInfrastructure(private val api: DialetusGateway) : DialectsService {



override suspend fun getDialectsBy(region: String): List<Dialect> = executionHandler {
api.getDialectsBy(region)
.map(DialectsMapper::toDomain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.jcaique.domain.regions.RegionsService
internal class RegionsInfrastructure(private val api: DialetusGateway) : RegionsService {

override suspend fun fetchRegions(): List<Region> = executionHandler {
api.fetchRegions() .map { RegionsMapper.toDomain(it) }
api.fetchRegions().map { RegionsMapper.toDomain(it) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class RegionsInfrastructureTest {
private lateinit var service: RegionsService

@Before
fun setup(){
fun setup() {
service = RegionsInfrastructure(scenario.api)
}

@Test
fun `should fetch regions`(){
fun `should fetch regions`() {

scenario.defineScenario(
status = 200,
Expand All @@ -48,7 +48,7 @@ class RegionsInfrastructureTest {
name = "paulistes",
total = 16
),
Region (
Region(
name = "pernambuques",
total = 17
),
Expand All @@ -59,6 +59,5 @@ class RegionsInfrastructureTest {
)

assertThat(execution).isEqualTo(expected)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.jcaique.domain.models.Dialect
import com.jcaique.domain.models.DialectSlug

interface DialectsService {
suspend fun getDialectsBy(region: String) : List<Dialect>
suspend fun searchDialects(query: String) : Map<DialectSlug, List<Dialect>>

suspend fun getDialectsBy(region: String): List<Dialect>

suspend fun searchDialects(query: String): Map<DialectSlug, List<Dialect>>
}
9 changes: 4 additions & 5 deletions domain/src/main/java/com/jcaique/domain/models/Dialect.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.jcaique.domain.models

data class Dialect(
val slug: String,
val dialect: String,
val meanings: List<String>,
val examples: List<String>
val slug: String,
val dialect: String,
val meanings: List<String>,
val examples: List<String>
)

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.jcaique.domain.models.Region

interface RegionsService {

suspend fun fetchRegions() : List<Region>
suspend fun fetchRegions(): List<Region>
}
3 changes: 2 additions & 1 deletion kotlin-module.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'kotlin'
apply plugin: "org.jlleitschuh.gradle.ktlint"

repositories {
mavenCentral()
Expand All @@ -10,4 +11,4 @@ compileKotlin {
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.jcaique.presentation

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ val presentationModule = Kodein.Module(name = "presentation") {
dispatcher = instance()
)
)

RegionsViewModel(
service = instance(),
machine = stateMachine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.jcaique.presentation.R
import kotlinx.android.synthetic.main.item_region.view.*

internal class RegionAdapter(
private val presentation: RegionsPresentation
private val presentation: RegionsPresentation
) : RecyclerView.Adapter<RegionHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RegionHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import com.jcaique.presentation.utils.DividerItemDecoration
import com.jcaique.presentation.utils.dataflow.UserInteraction.OpenedScreen
import com.jcaique.presentation.utils.dataflow.UserInteraction.RequestedFreshContent
import com.jcaique.presentation.utils.dataflow.ViewState
import com.jcaique.presentation.utils.dataflow.ViewState.*
import com.jcaique.presentation.utils.dataflow.ViewState.Failed
import com.jcaique.presentation.utils.dataflow.ViewState.Loading
import com.jcaique.presentation.utils.dataflow.ViewState.Success
import com.jcaique.presentation.utils.selfInject
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.error_state_layout.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.jcaique.presentation.utils.dataflow.UnsupportedUserInteraction
import com.jcaique.presentation.utils.dataflow.UserInteraction

internal class RegionsViewModel(
private val service: RegionsService,
private val machine: StateMachine<RegionsPresentation>
private val service: RegionsService,
private val machine: StateMachine<RegionsPresentation>
) : ViewModel() {

fun bind() = machine.states()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ internal class DividerItemDecoration(context: Context, orientation: Int = Linear
if (mDivider == null) {
Log.w(
TAG,
"@android:attr/listDivider was not set in the theme used for this " + "DividerItemDecoration. " +
"@android:attr/listDivider was not set in the theme used for this " +
"DividerItemDecoration. " +
"Please set that attribute all call setDrawable()"
)
}
Expand All @@ -51,7 +52,9 @@ internal class DividerItemDecoration(context: Context, orientation: Int = Linear
* @param orientation [.HORIZONTAL] or [.VERTICAL]
*/
private fun setOrientation(orientation: Int) {
require(!(orientation != HORIZONTAL && orientation != VERTICAL)) { "Invalid orientation. It should be either HORIZONTAL or VERTICAL" }
require(!(orientation != HORIZONTAL && orientation != VERTICAL)) {
"Invalid orientation. It should be either HORIZONTAL or VERTICAL"
}
mOrientation = orientation
}

Expand All @@ -65,18 +68,18 @@ internal class DividerItemDecoration(context: Context, orientation: Int = Linear
}

override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
if (mDivider == null) {
outRect.set(0, 0, 0, 0)
return
}
when(mOrientation == VERTICAL) {
when (mOrientation == VERTICAL) {
true -> outRect.set(0, 0, 0, mDivider!!.intrinsicHeight)
false-> outRect.set(0, 0, mDivider!!.intrinsicWidth, 0)
false -> outRect.set(0, 0, mDivider!!.intrinsicWidth, 0)
}
}

Expand Down Expand Up @@ -117,11 +120,11 @@ internal class DividerItemDecoration(context: Context, orientation: Int = Linear
}

private fun drawVerticalChild(
canvas: Canvas,
view: View,
parent: RecyclerView,
left: Int,
right: Int
canvas: Canvas,
view: View,
parent: RecyclerView,
left: Int,
right: Int
) {
parent.getDecoratedBoundsWithMargins(view, mBounds)

Expand Down Expand Up @@ -158,11 +161,11 @@ internal class DividerItemDecoration(context: Context, orientation: Int = Linear
}

private fun drawHorizontalChild(
canvas: Canvas,
view: View,
parent: RecyclerView,
top: Int,
bottom: Int
canvas: Canvas,
view: View,
parent: RecyclerView,
top: Int,
bottom: Int
) {
parent.layoutManager?.getDecoratedBoundsWithMargins(view, mBounds)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.flow.asFlow

internal class CommandsProcessor(
private val executor: TaskExecutor
private val executor: TaskExecutor
) {

private val broadcaster = ConflatedBroadcastChannel<ViewCommand>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jcaique.presentation.utils.dataflow

internal class StateMachine<T>(
private val container: StateContainer<T>,
private val executor: TaskExecutor
private val container: StateContainer<T>,
private val executor: TaskExecutor
) {

fun states() = container.observableStates()
Expand Down
Loading

0 comments on commit 9e3b205

Please sign in to comment.