diff --git a/app/build.gradle b/app/build.gradle index 323f641..af54686 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,21 +3,15 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' -kotlin { - experimental { - coroutines "enable" - } -} - android { - compileSdkVersion Vers.androidCompileSdk + compileSdkVersion 28 defaultConfig { applicationId "com.elpassion.crweather" - minSdkVersion Vers.androidMinSdk - targetSdkVersion Vers.androidTargetSdk + minSdkVersion 19 + targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner Vers.androidTestRunnerClass + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -27,29 +21,39 @@ android { } } -repositories { - mavenCentral() -} - dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation Deps.kotlinStdlib7 - implementation Deps.kotlinxCoroutinesCore - implementation Deps.kotlinxCoroutinesAndroid - implementation Deps.androidSupportAppcompat - implementation Deps.androidSupportV4 - implementation Deps.androidSupportDesign - implementation Deps.androidSupportRecyclerview - implementation Deps.androidSupportCardview - implementation Deps.androidSupportConstraint - implementation Deps.androidArchLifecycleExtensions - implementation Deps.retrofit - implementation Deps.retrofitMoshi - implementation Deps.okhttpLogging - kapt Deps.androidArchLifecycleCompiler - testImplementation Deps.junit - androidTestImplementation(Deps.androidEspresso, { - exclude group: 'com.android.support', module: 'support-annotations' - }) -} + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + + //card view + implementation "com.android.support:cardview-v7:28.0.0" + + //rxbinding + implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1' + implementation 'com.jakewharton.rxbinding2:rxbinding-support-v4:2.1.1' + implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.1.1' + implementation 'com.jakewharton.rxbinding2:rxbinding-design:2.1.1' + implementation 'com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:2.1.1' + implementation 'com.jakewharton.rxbinding2:rxbinding-leanback-v17:2.1.1' + + // multidex + implementation 'com.android.support:multidex:1.0.3' + + // LiveData + ViewModel + implementation "android.arch.lifecycle:extensions:1.1.1" + + //retrofit + implementation 'com.squareup.retrofit2:retrofit:2.4.0' + api 'com.squareup.retrofit2:converter-gson:2.4.0' + implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' + implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0' + implementation "com.squareup.retrofit2:converter-moshi:2.4.0" + //coroutine + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' +} \ No newline at end of file diff --git a/app/src/main/java/com/elpassion/crweather/CommonUtils.kt b/app/src/main/java/com/elpassion/crweather/CommonUtils.kt index 509c153..89706e8 100644 --- a/app/src/main/java/com/elpassion/crweather/CommonUtils.kt +++ b/app/src/main/java/com/elpassion/crweather/CommonUtils.kt @@ -1,13 +1,17 @@ package com.elpassion.crweather -import kotlinx.coroutines.experimental.CancellableContinuation -import kotlinx.coroutines.experimental.suspendCancellableCoroutine +import kotlinx.coroutines.CancellableContinuation +import kotlinx.coroutines.suspendCancellableCoroutine import retrofit2.Call import retrofit2.Callback import retrofit2.Response -import java.util.ArrayList +import java.util.* +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException -@Suppress("unused") val Any?.unit get() = Unit +@Suppress("unused") +val Any?.unit + get() = Unit operator fun StringBuilder.plusAssign(string: String) = append(string).unit @@ -26,8 +30,8 @@ suspend fun Call.await(): T = suspendCancellableCoroutine { continuation continuation.invokeOnCancellation { cancel() } val callback = object : Callback { - override fun onFailure(call: Call, t: Throwable) = continuation.tryToResume { throw t } - override fun onResponse(call: Call, response: Response) = continuation.tryToResume { + override fun onFailure(call: Call, t: Throwable) = continuation.invokeOnCancellation { throw t } + override fun onResponse(call: Call, response: Response) = continuation.tryResume { response.isSuccessful || throw IllegalStateException("Http error ${response.code()}") response.body() ?: throw IllegalStateException("Response body is null") } @@ -36,9 +40,10 @@ suspend fun Call.await(): T = suspendCancellableCoroutine { continuation enqueue(callback) } -private inline fun CancellableContinuation.tryToResume(getter: () -> T) { - isActive || return - try { resume(getter()) } - catch (exception: Throwable) { resumeWithException(exception) } +private fun CancellableContinuation.tryResume(getter: () -> T) { + try { + resume(getter()) + } catch (exception: Throwable) { + resumeWithException(exception) + } } - diff --git a/build.gradle b/build.gradle index 98d3f25..7ce94ea 100644 --- a/build.gradle +++ b/build.gradle @@ -1,23 +1,29 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.0' + ext.roomVersion = '1.1.1' + ext.archLifecycleVersion = '1.1.1' repositories { + google() jcenter() - maven { url 'https://maven.google.com' } } dependencies { - classpath Deps.kotlinGradlePlugin - classpath Deps.androidGradlePlugin + classpath 'com.android.tools.build:gradle:3.2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files } } allprojects { repositories { - jcenter() google() + jcenter() } } task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/buildSrc b/buildSrc deleted file mode 120000 index b6efd12..0000000 --- a/buildSrc +++ /dev/null @@ -1 +0,0 @@ -deps.kt/buildSrc \ No newline at end of file