Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

migrate to AndroidX and other dependencies update #6

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
// Kotlin
Expand All @@ -27,6 +28,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
}

group = 'org.koin'
Expand Down
63 changes: 32 additions & 31 deletions examples/android-weather-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}

apply from: '../../gradle/versions-examples.gradle'

Expand All @@ -16,7 +17,7 @@ android {
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// used by Room, to test migrations
javaCompileOptions {
Expand All @@ -27,7 +28,7 @@ android {
}
}
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
buildTypes {
release {
Expand All @@ -43,57 +44,57 @@ android {
androidTest.assets.srcDirs +=
files("$projectDir/schemas".toString())
}
buildFeatures {
viewBinding true
}
}

dependencies {
// Android Support
implementation "com.android.support:appcompat-v7:$support_lib_version"
implementation "com.android.support:support-v4:$support_lib_version"
implementation "com.android.support:design:$support_lib_version"
// AndroidX
implementation "androidx.appcompat:appcompat:1.3.1"
implementation "androidx.appcompat:appcompat-resources:1.3.1"

// Android Test
testImplementation "junit:junit:$junit_version"
testImplementation "org.mockito:mockito-inline:$mockito_version"
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestUtil 'com.android.support.test:orchestrator:1.0.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestUtil 'androidx.test:orchestrator:1.4.0'

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// Anko
implementation "org.jetbrains.anko:anko-commons:$anko_version"
// Koin
implementation "org.koin:koin-android-viewmodel:$koin_version"
testImplementation "org.koin:koin-test:$koin_version"
androidTestImplementation "org.koin:koin-test:$koin_version"
implementation "io.insert-koin:koin-android:$koin_version"
testImplementation "io.insert-koin:koin-test:$koin_version"
androidTestImplementation "io.insert-koin:koin-test:$koin_version"

// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$android_arch_version"
testImplementation "android.arch.core:core-testing:$android_arch_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
testImplementation "androidx.arch.core:core-testing:$arch_version"

// Room
implementation "android.arch.persistence.room:runtime:$room_version"
implementation "android.arch.persistence.room:rxjava2:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
testImplementation "android.arch.persistence.room:testing:$room_version"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava3:$room_version"
kapt "androidx.room:room-compiler:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
testImplementation "androidx.room:room-testing:$room_version"

// UI
implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
implementation 'com.joanzapata.iconify:android-iconify-weathericons:2.2.2'

// Gson
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.code.gson:gson:2.8.8'

// Networking
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava3:$retrofit_version"
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"

// Rx
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation "io.reactivex.rxjava3:rxjava:$rxjava_version"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

// Canary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leak_canary_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package fr.ekito.myweatherapp

import android.support.test.runner.AndroidJUnit4
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import fr.ekito.myweatherapp.data.WeatherDataSource
import fr.ekito.myweatherapp.data.room.WeatherDAO
import fr.ekito.myweatherapp.data.room.WeatherDatabase
import fr.ekito.myweatherapp.data.room.WeatherEntity
import fr.ekito.myweatherapp.domain.ext.getDailyForecasts
import fr.ekito.myweatherapp.domain.ext.getLocation
import junit.framework.Assert
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.core.context.loadKoinModules
import org.koin.core.context.stopKoin
import org.koin.test.KoinTest
import org.koin.test.inject
import java.util.Date
import java.util.*

@RunWith(AndroidJUnit4::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class WeatherDAOTest : KoinTest {

val weatherDatabase: WeatherDatabase by inject()
val weatherWebDatasource: WeatherDataSource by inject()
val weatherDAO: WeatherDAO by inject()
private val weatherDatabase: WeatherDatabase by inject()
private val weatherWebDatasource: WeatherDataSource by inject()
private val weatherDAO: WeatherDAO by inject()

@Before()
@Before
fun before() {
loadKoinModules(roomTestModule)
}
Expand All @@ -48,7 +48,7 @@ class WeatherDAOTest : KoinTest {

val requestedEntities = ids.map { weatherDAO.findWeatherById(it).blockingGet() }

Assert.assertEquals(entities, requestedEntities)
assertEquals(entities, requestedEntities)
}

@Test
Expand All @@ -65,7 +65,7 @@ class WeatherDAOTest : KoinTest {

val resultList = weatherDAO.findAllBy(locationTlse, dateToulouse).blockingGet()

Assert.assertEquals(weatherToulouse, resultList)
assertEquals(weatherToulouse, resultList)
}

@Test
Expand All @@ -88,7 +88,7 @@ class WeatherDAOTest : KoinTest {
val result: WeatherEntity = weatherDAO.findLatestWeather().blockingGet().first()
val resultList = weatherDAO.findAllBy(result.location, result.date).blockingGet()

Assert.assertEquals(weatherToulouse, resultList)
assertEquals(weatherToulouse, resultList)
}

private fun getWeatherAsEntities(
Expand All @@ -97,7 +97,7 @@ class WeatherDAOTest : KoinTest {
): List<WeatherEntity> {
return weatherWebDatasource.geocode(locationParis)
.map { it.getLocation() }
.flatMap { weatherWebDatasource.weather(it.lat, it.lng, "EN") }
.flatMap { weatherWebDatasource.weather(it?.lat, it?.lng, "EN") }
.map { it.getDailyForecasts(locationParis) }
.map { list -> list.map { WeatherEntity.from(it, dateParis) } }
.blockingGet()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package fr.ekito.myweatherapp

import android.support.test.runner.AndroidJUnit4
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import fr.ekito.myweatherapp.domain.repository.DailyForecastRepository
import junit.framework.Assert
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -12,12 +12,12 @@ import org.koin.core.context.stopKoin
import org.koin.test.KoinTest
import org.koin.test.inject

@RunWith(AndroidJUnit4::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class WeatherRepositoryTest : KoinTest {

private val weatherRepository: DailyForecastRepository by inject()

@Before()
@Before
fun before() {
loadKoinModules(roomTestModule)
}
Expand All @@ -31,7 +31,7 @@ class WeatherRepositoryTest : KoinTest {
fun testGetDefault() {
val defaultWeather = weatherRepository.getWeather().blockingGet()
val defaultWeather2 = weatherRepository.getWeather().blockingGet()
Assert.assertEquals(defaultWeather, defaultWeather2)
assertEquals(defaultWeather, defaultWeather2)
}

@Test
Expand All @@ -40,7 +40,7 @@ class WeatherRepositoryTest : KoinTest {

val result = defaultWeather.first()
val first = weatherRepository.getWeatherDetail(result.id).blockingGet()
Assert.assertEquals(result, first)
assertEquals(result, first)
}

@Test
Expand All @@ -49,6 +49,6 @@ class WeatherRepositoryTest : KoinTest {
weatherRepository.getWeather("London").blockingGet()
val toulouse = weatherRepository.getWeather("Toulouse").blockingGet()
val defaultWeather3 = weatherRepository.getWeather().blockingGet()
Assert.assertEquals(defaultWeather3, toulouse)
assertEquals(defaultWeather3, toulouse)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package fr.ekito.myweatherapp

import android.arch.persistence.room.Room
import androidx.room.Room
import fr.ekito.myweatherapp.data.room.WeatherDatabase
import org.koin.dsl.module

// Room In memroy database
val roomTestModule = module(override = true) {
// Room In memory database
val roomTestModule = module {
single {
Room.inMemoryDatabaseBuilder(get(), WeatherDatabase::class.java)
.allowMainThreadQueries()
Expand Down
3 changes: 2 additions & 1 deletion examples/android-weather-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="fr.ekito.myweatherapp.view.splash.SplashActivity">
<activity android:name="fr.ekito.myweatherapp.view.splash.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.joanzapata.iconify.Iconify
import com.joanzapata.iconify.fonts.WeathericonsModule
import fr.ekito.myweatherapp.di.roomWeatherApp
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidFileProperties
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
Expand All @@ -19,13 +20,12 @@ class MainApplication : Application() {

// start Koin context
startKoin {
fileProperties()
androidLogger(Level.DEBUG)
androidContext(this@MainApplication)
androidFileProperties()
modules(roomWeatherApp)
}

Iconify
.with(WeathericonsModule())
Iconify.with(WeathericonsModule())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.ekito.myweatherapp.data

import fr.ekito.myweatherapp.data.json.Geocode
import fr.ekito.myweatherapp.data.json.Weather
import io.reactivex.Single
import io.reactivex.rxjava3.core.Single
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package fr.ekito.myweatherapp.data.json

import java.util.*

data class AddressComponent(
val long_name: String? = null,
val short_name: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package fr.ekito.myweatherapp.data.json

import java.util.*

data class Avewind(
val mph: Int? = null,
val kph: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import java.io.InputStreamReader
*/
class AndroidJsonReader(val application: Application) : BaseReader() {

override fun getAllFiles(): List<String> = application.assets.list("json").toList()
override fun getAllFiles(): List<String> = application.assets.list("json")!!.toList()

override fun readJsonFile(jsonFile: String): String {
val buf = StringBuilder()
val json = application.assets.open("json/" + jsonFile)
val json = application.assets.open("json/$jsonFile")
BufferedReader(InputStreamReader(json, "UTF-8"))
.use {
val list = it.lineSequence().toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package fr.ekito.myweatherapp.data.local
import fr.ekito.myweatherapp.data.WeatherDataSource
import fr.ekito.myweatherapp.data.json.Geocode
import fr.ekito.myweatherapp.data.json.Weather
import io.reactivex.Single
import io.reactivex.rxjava3.core.Single
import java.util.Locale
import java.util.concurrent.TimeUnit

/**
* Read json files and render weather date
*/
class FileDataSource(val jsonReader: JsonReader, val delayed: Boolean) :
class FileDataSource(private val jsonReader: JsonReader, private val delayed: Boolean) :
WeatherDataSource {

private val cities by lazy { jsonReader.getAllLocations() }
Expand All @@ -23,7 +24,7 @@ class FileDataSource(val jsonReader: JsonReader, val delayed: Boolean) :

override fun geocode(address: String): Single<Geocode> {
val single = Single.create<Geocode> { s ->
val addressToLC = address.toLowerCase()
val addressToLC = address.lowercase(Locale.getDefault())
val geocode = if (isKnownCity(addressToLC)) {
jsonReader.getGeocode(addressToLC)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.ekito.myweatherapp.data.room

import android.arch.persistence.room.TypeConverter
import java.util.*
import androidx.room.TypeConverter
import java.util.Date

class Converters {
@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package fr.ekito.myweatherapp.data.room

import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.Query
import io.reactivex.Single
import java.util.*
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import io.reactivex.rxjava3.core.Single
import java.util.Date

@Dao
interface WeatherDAO {
Expand Down
Loading