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

Convert samplestore app to Kotlin #1290

Merged
merged 2 commits into from
Aug 2, 2019
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ before_install:
- yes | sdkmanager "platforms;android-28"

script:
- ./gradlew :stripe:checkstyle :example:checkstyle :samplestore:checkstyle lint
- ./gradlew :stripe:checkstyle :example:checkstyle :samplestore:checkstyle :samplestore:ktlint lint
- ./gradlew clean test
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
jcenter()
google()
Expand All @@ -9,6 +10,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.5.0-rc02'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.6'
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
39 changes: 35 additions & 4 deletions samplestore/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

apply plugin: 'checkstyle'
assemble.dependsOn('lint')
check.dependsOn('checkstyle')

configurations {
ktlint
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
Expand Down Expand Up @@ -59,15 +65,15 @@ dependencies {
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'

/* Used for server calls */
implementation 'com.squareup.okio:okio:2.2.2'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.okio:okio:2.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.facebook.stetho:stetho:1.5.1'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'

/* Used to make Retrofit easier and GSON & Rx-compatible*/
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'

// Used to debug your Retrofit connections
// Do not upgrade as it will require increasing minSdkVersion to 21
Expand All @@ -78,4 +84,29 @@ dependencies {
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
// Optional, if you use support library fragments:
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

ktlint "com.pinterest:ktlint:0.33.0"
}

repositories {
mavenCentral()
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "src/**/*.kt"
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/pinterest/ktlint#usage for more
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
}

This file was deleted.

37 changes: 37 additions & 0 deletions samplestore/src/main/java/com/stripe/samplestore/ItemDivider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.stripe.samplestore

import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.support.annotation.DrawableRes
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView

/**
* Custom divider will be used in the list.
*/
internal class ItemDivider(
context: Context,
@DrawableRes resId: Int
) : RecyclerView.ItemDecoration() {

private val divider: Drawable = ContextCompat.getDrawable(context, resId)!!

override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val start = parent.paddingStart
val end = parent.width - parent.paddingEnd

val childCount = parent.childCount
for (i in 0 until childCount) {
val child = parent.getChildAt(i)

val params = child.layoutParams as RecyclerView.LayoutParams

val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight

divider.setBounds(start, top, end, bottom)
divider.draw(c)
}
}
}
Loading