From ab05bcc258f3f3bbe864eaae4a02bb4a4ee5a68b Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Thu, 11 Oct 2018 14:26:15 +0200 Subject: [PATCH 01/18] Scaffold sharedpreferences module - Attach to store implemetnation - Mock data currently being returned Some housekeeping. --- .../data-sharedpreferences/.gitignore | 1 + .../data-sharedpreferences/build.gradle | 106 ++++++++++++++++++ .../data-sharedpreferences/proguard-rules.pro | 21 ++++ .../ExampleInstrumentedTest.java | 26 +++++ .../src/main/AndroidManifest.xml | 2 + .../FrameworkLocalStorageImpl.kt | 6 +- .../mapper/SharedPrefMapper.kt | 6 + .../model/SharedPrefTransport.kt | 6 + .../src/main/res/values/strings.xml | 3 + .../sharedpreferences/ExampleUnitTest.java | 17 +++ .../presentation/build.gradle | 4 - transport-eta-android/settings.gradle | 2 +- .../transporteta/sms/SmsControllerImpl.kt | 5 + transport-eta-android/ui-mobile/build.gradle | 1 + .../ui/di/module/DataSourceModule.kt | 2 +- .../di/module/HomeFragmentBuildersModule.kt | 2 +- .../ui/home/favorite/FavoritesAdapter.kt | 4 +- .../ui/home/favorite/FavoritesFragment.kt | 31 ++--- 18 files changed, 222 insertions(+), 23 deletions(-) create mode 100644 transport-eta-android/data-sharedpreferences/.gitignore create mode 100644 transport-eta-android/data-sharedpreferences/build.gradle create mode 100644 transport-eta-android/data-sharedpreferences/proguard-rules.pro create mode 100644 transport-eta-android/data-sharedpreferences/src/androidTest/java/com/joaquimley/transporteta/sharedpreferences/ExampleInstrumentedTest.java create mode 100644 transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml rename transport-eta-android/{data/src/main/java/com/joaquimley/data/source => data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences}/FrameworkLocalStorageImpl.kt (74%) create mode 100644 transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt create mode 100644 transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt create mode 100644 transport-eta-android/data-sharedpreferences/src/main/res/values/strings.xml create mode 100644 transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java diff --git a/transport-eta-android/data-sharedpreferences/.gitignore b/transport-eta-android/data-sharedpreferences/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/.gitignore @@ -0,0 +1 @@ +/build diff --git a/transport-eta-android/data-sharedpreferences/build.gradle b/transport-eta-android/data-sharedpreferences/build.gradle new file mode 100644 index 0000000..21356a8 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/build.gradle @@ -0,0 +1,106 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion build_versions.target_sdk + defaultConfig { + minSdkVersion build_versions.min_sdk + targetSdkVersion build_versions.target_sdk + testInstrumentationRunner "com.joaquimley.transporteta.ui.test.TestRunner" + } + + packagingOptions { + exclude 'LICENSE.txt' + exclude 'META-INF/DEPENDENCIES' + exclude 'META-INF/ASL2.0' + exclude 'META-INF/NOTICE' + exclude 'META-INF/LICENSE' + } + + lintOptions { + quiet true + abortOnError false + ignoreWarnings true + disable 'InvalidPackage' //Some libraries have issues with this. + disable 'OldTargetApi' + // Lint gives this warning but SDK 20 would be Android L Beta. + disable 'IconDensities' //For testing purpose. This is safe to remove. + disable 'IconMissingDensityFolder' //For testing purpose. This is safe to remove. + } + + + dexOptions { + preDexLibraries true + } + + buildTypes { + debug { + testCoverageEnabled true + } + + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + flavorDimensions "environment" + productFlavors { + prod { + dimension "environment" + } + } + + /** + * Prevent shipping the mock flavor with release variant + * read more at: https://developer.android.com/studio/build/build-variants.html + */ + variantFilter { variant -> + def names = variant.flavors*.name + // To check for a certain build type, use variant.buildType.name == "" + if (names.contains("mock") && variant.buildType.name == "release") { + // Gradle ignores any variants that satisfy the conditions above. + setIgnore(true) + } + } +} + +// Module configuration +androidExtensions { + experimental = true +} + +dependencies { + // Module + implementation project(':data') + + // ACC + kapt deps.lifecycle.compiler + implementation deps.lifecycle.livedata + implementation deps.lifecycle.viewmodel + + // Javax + implementation deps.javax.inject + compileOnly deps.javax.annotation + // Rx + implementation deps.rx.java2 + implementation deps.rx.android + // Kotlin + implementation deps.kotlin.rx + implementation deps.kotlin.stdlib + + /*********** + * Testing * + ***********/ + + // Local unit tests + kaptTest deps.dagger.compiler + testImplementation deps.kotlin.junit + testImplementation deps.mockito.kotlin + testImplementation deps.mockito.inline + testImplementation deps.lifecycle.testing + // Resolve conflicts between main and local unit tests + testImplementation deps.androidx.annotation +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/proguard-rules.pro b/transport-eta-android/data-sharedpreferences/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/transport-eta-android/data-sharedpreferences/src/androidTest/java/com/joaquimley/transporteta/sharedpreferences/ExampleInstrumentedTest.java b/transport-eta-android/data-sharedpreferences/src/androidTest/java/com/joaquimley/transporteta/sharedpreferences/ExampleInstrumentedTest.java new file mode 100644 index 0000000..521ca2f --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/androidTest/java/com/joaquimley/transporteta/sharedpreferences/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.joaquimley.transporteta.sharedpreferences; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.joaquimley.transporteta.sharedpreferences.test", appContext.getPackageName()); + } +} diff --git a/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml b/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f495fe1 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/source/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt similarity index 74% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/source/FrameworkLocalStorageImpl.kt rename to transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index 75d6d18..f76e51d 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/source/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -1,6 +1,7 @@ -package com.joaquimley.data.source +package com.joaquimley.transporteta.sharedpreferences import com.joaquimley.data.model.TransportEntity +import com.joaquimley.data.source.FrameworkLocalStorage import io.reactivex.Completable import io.reactivex.Single @@ -19,7 +20,8 @@ class FrameworkLocalStorageImpl: FrameworkLocalStorage { override fun getAll(): Single> { val list = mutableListOf() - list.add(TransportEntity("hi", "mock",2, "el", true,"bus")) + list.add(TransportEntity("hi", "mock",2, "latestEta 12324", true,"bus")) + list.add(TransportEntity("there", "mock",23, "latestEta 123", true,"bus")) return Single.just(list) } diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt new file mode 100644 index 0000000..cb2d8f8 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt @@ -0,0 +1,6 @@ +package com.joaquimley.transporteta.sharedpreferences.mapper + +class SharedPrefMapper { + + // TODO +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt new file mode 100644 index 0000000..5630f72 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt @@ -0,0 +1,6 @@ +package com.joaquimley.transporteta.sharedpreferences.model + +class SharedPrefTransport { + + // TODO +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/res/values/strings.xml b/transport-eta-android/data-sharedpreferences/src/main/res/values/strings.xml new file mode 100644 index 0000000..9ae5e05 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + sharedprefernces + diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java new file mode 100644 index 0000000..031e2fa --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.joaquimley.transporteta.sharedpreferences; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/transport-eta-android/presentation/build.gradle b/transport-eta-android/presentation/build.gradle index 27527eb..11ded06 100644 --- a/transport-eta-android/presentation/build.gradle +++ b/transport-eta-android/presentation/build.gradle @@ -51,10 +51,6 @@ android { prod { dimension "environment" } - - mock { - dimension "environment" - } } /** diff --git a/transport-eta-android/settings.gradle b/transport-eta-android/settings.gradle index de9fbec..fec347b 100644 --- a/transport-eta-android/settings.gradle +++ b/transport-eta-android/settings.gradle @@ -1 +1 @@ -include ':ui-mobile', ':sms', ':presentation', ':domain', ':data' +include ':ui-mobile', ':sms', ':presentation', ':domain', ':data', ':data-sharedpreferences' diff --git a/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt b/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt index 22bde38..fa6172a 100644 --- a/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt +++ b/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt @@ -14,6 +14,11 @@ import javax.inject.Singleton @Singleton open class SmsControllerImpl @Inject constructor(private val smsBroadcastReceiver: SmsBroadcastReceiver) : SmsController { + + init { + smsBroadcastReceiver. + } + override fun dispose() { } diff --git a/transport-eta-android/ui-mobile/build.gradle b/transport-eta-android/ui-mobile/build.gradle index b03701c..3f0c2d0 100644 --- a/transport-eta-android/ui-mobile/build.gradle +++ b/transport-eta-android/ui-mobile/build.gradle @@ -82,6 +82,7 @@ dependencies { // Modules implementation project(':sms') implementation project(':data') + implementation project(':data-sharedpreferences') implementation project(':domain') implementation project(':presentation') // AndroidX diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt index eec217c..f5b82f6 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt @@ -1,7 +1,7 @@ package com.joaquimley.transporteta.ui.di.module import com.joaquimley.data.source.FrameworkLocalStorage -import com.joaquimley.data.source.FrameworkLocalStorageImpl +import com.joaquimley.transporteta.sharedpreferences.FrameworkLocalStorageImpl import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module import dagger.Provides diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt index e889af3..24cdb75 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt @@ -8,7 +8,7 @@ import dagger.android.ContributesAndroidInjector abstract class HomeFragmentBuildersModule { @ContributesAndroidInjector(modules = [ - HomeViewModelModule::class + ViewModelModule::class ]) abstract fun contributeFavouritesFragment(): FavoritesFragment } diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesAdapter.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesAdapter.kt index cd8974e..9d6ea11 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesAdapter.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesAdapter.kt @@ -1,5 +1,6 @@ package com.joaquimley.transporteta.ui.home.favorite +import android.util.Log import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.DiffUtil import android.view.LayoutInflater @@ -40,10 +41,11 @@ class FavoritesAdapter(private val clickListener: (TransportView) -> Unit) } fun setActionEnabledStatus(isEnabled: Boolean) { + Log.e("To remove", "Hi $isEnabled") // for (position in 0 until itemCount) { // getItem(position).isActionEnabled = isEnabled // } - notifyDataSetChanged() +// notifyDataSetChanged() } inner class ProgressViewHolder(view: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(view) diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt index 19a87bb..5ae14cf 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt @@ -12,7 +12,10 @@ import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE +import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_LONG import com.google.android.material.snackbar.Snackbar +import com.google.android.material.textfield.TextInputEditText import com.joaquimley.transporteta.R import com.joaquimley.transporteta.presentation.data.ResourceState import com.joaquimley.transporteta.presentation.home.favorite.FavoritesViewModelFactory @@ -31,8 +34,9 @@ class FavoritesFragment : Fragment() { // Inspiration for UI https://www.behance.net/gallery/69860023/Bust-app - @Inject lateinit var viewModelProvider: FavoritesViewModelFactory - private val viewModel by lazy { viewModelProvider.create()} + @Inject + lateinit var viewModelProvider: FavoritesViewModelFactory + private val viewModel by lazy { viewModelProvider.create() } private lateinit var adapter: FavoritesAdapter private lateinit var requestingSnackbar: Snackbar @@ -117,15 +121,15 @@ class FavoritesFragment : Fragment() { message_view?.setVisible(true) } else { message?.let { - com.google.android.material.snackbar.Snackbar.make(favorites_fragment_container, it, com.google.android.material.snackbar.Snackbar.LENGTH_LONG) - .setAction(R.string.action_retry) { viewModel.onRefresh() } + com.google.android.material.snackbar.Snackbar.make(favorites_fragment_container, it, LENGTH_LONG) + .setAction(R.string.action_retry) { _ -> viewModel.onRefresh() } .show() } } } private fun setupRequestSnackbar() { - requestingSnackbar = Snackbar.make(favorites_fragment_container, R.string.info_requesting, com.google.android.material.snackbar.Snackbar.LENGTH_INDEFINITE) + requestingSnackbar = Snackbar.make(favorites_fragment_container, R.string.info_requesting, LENGTH_INDEFINITE) requestingSnackbar.setAction(R.string.action_cancel) { viewModel.onEtaRequestCanceled() Toast.makeText(activity?.applicationContext, R.string.info_canceled, Toast.LENGTH_SHORT).show() @@ -165,22 +169,22 @@ class FavoritesFragment : Fragment() { val dialog = builder.create() dialog.show() - val busStopTitleEditText: com.google.android.material.textfield.TextInputEditText? = dialog.findViewById(R.id.favorite_title_edit_text) - val busStopCodeEditText: com.google.android.material.textfield.TextInputEditText? = dialog.findViewById(R.id.favorite_code_edit_text) - busStopCodeEditText?.onChange { - if (!TextUtils.isEmpty(it)) { +// val busStopTitleEditText: com.google.android.material.textfield.TextInputEditText? = dialog.findViewById(R.id.favorite_title_edit_text) + val busStopCodeEditText: TextInputEditText? = dialog.findViewById(R.id.favorite_code_edit_text) + busStopCodeEditText?.onChange { currentText -> + if (!TextUtils.isEmpty(currentText)) { busStopCodeEditText.error = null } } - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { _ -> if (TextUtils.isEmpty(busStopCodeEditText?.text)) { busStopCodeEditText?.error = getString(R.string.error_create_favorite_code_required) } } - context?.let { ContextCompat.getColor(it, R.color.colorLightGrey) }?.let { dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(it) } - dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener { + context?.let { context -> ContextCompat.getColor(context, R.color.colorLightGrey) }?.let { dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(it) } + dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener { _ -> dialog.dismiss() } @@ -188,7 +192,8 @@ class FavoritesFragment : Fragment() { } companion object { - @JvmStatic fun newInstance(): FavoritesFragment { + @JvmStatic + fun newInstance(): FavoritesFragment { val fragment = FavoritesFragment() // val args = Bundle() // fragment.arguments = args From 3f64e3d26261a2c7d5d0623bd8fbf396064f1fad Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Fri, 12 Oct 2018 08:39:26 +0200 Subject: [PATCH 02/18] Small configurations for CI Still not working, wanted to make mock work with debug but variants still compain. --- .../data-sharedpreferences/build.gradle | 7 +++++- .../presentation/build.gradle | 2 ++ transport-eta-android/sms/build.gradle | 22 ++++++++-------- .../transporteta/sms/SmsControllerImpl.kt | 2 +- transport-eta-android/ui-mobile/build.gradle | 25 +++++++++++++++---- .../di/module/TestFavoriteFragmentModule.kt | 4 +-- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/transport-eta-android/data-sharedpreferences/build.gradle b/transport-eta-android/data-sharedpreferences/build.gradle index 21356a8..d6d548a 100644 --- a/transport-eta-android/data-sharedpreferences/build.gradle +++ b/transport-eta-android/data-sharedpreferences/build.gradle @@ -4,6 +4,8 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { + publishNonDefault true + compileSdkVersion build_versions.target_sdk defaultConfig { minSdkVersion build_versions.min_sdk @@ -30,7 +32,6 @@ android { disable 'IconMissingDensityFolder' //For testing purpose. This is safe to remove. } - dexOptions { preDexLibraries true } @@ -48,6 +49,10 @@ android { flavorDimensions "environment" productFlavors { + mock { + dimension "environment" + } + prod { dimension "environment" } diff --git a/transport-eta-android/presentation/build.gradle b/transport-eta-android/presentation/build.gradle index 11ded06..80eba85 100644 --- a/transport-eta-android/presentation/build.gradle +++ b/transport-eta-android/presentation/build.gradle @@ -4,6 +4,8 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { + publishNonDefault true + compileSdkVersion build_versions.target_sdk defaultConfig { minSdkVersion build_versions.min_sdk diff --git a/transport-eta-android/sms/build.gradle b/transport-eta-android/sms/build.gradle index 9a03cad..59f60e0 100644 --- a/transport-eta-android/sms/build.gradle +++ b/transport-eta-android/sms/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { + publishNonDefault true + compileSdkVersion build_versions.target_sdk defaultConfig { minSdkVersion build_versions.min_sdk @@ -32,16 +34,16 @@ android { preDexLibraries true } -// buildTypes { -// debug { -// testCoverageEnabled true -// } -// -// release { -// minifyEnabled true -// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' -// } -// } + buildTypes { + debug { + testCoverageEnabled true + } + + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } flavorDimensions "environment" productFlavors { diff --git a/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt b/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt index fa6172a..3473a0b 100644 --- a/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt +++ b/transport-eta-android/sms/src/mock/java/com/joaquimley/transporteta/sms/SmsControllerImpl.kt @@ -16,7 +16,7 @@ import javax.inject.Singleton open class SmsControllerImpl @Inject constructor(private val smsBroadcastReceiver: SmsBroadcastReceiver) : SmsController { init { - smsBroadcastReceiver. + } override fun dispose() { diff --git a/transport-eta-android/ui-mobile/build.gradle b/transport-eta-android/ui-mobile/build.gradle index 3f0c2d0..06ad9e6 100644 --- a/transport-eta-android/ui-mobile/build.gradle +++ b/transport-eta-android/ui-mobile/build.gradle @@ -3,7 +3,6 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'androidx.navigation.safeargs' - android { compileSdkVersion build_versions.compile_sdk defaultConfig { @@ -47,7 +46,26 @@ android { ignoreWarnings true } + /** + * Prevent shipping the mock flavor with release variant + * https://developer.android.com/studio/build/build-variants.html + */ + variantFilter { variant -> + def names = variant.flavors*.name + // To check for a certain build type, use variant.buildType.name == "" + if (names.contains("mock") && variant.buildType.name == "release") { + // Gradle ignores any variants that satisfy the conditions above. + setIgnore(true) + } + } + buildTypes { + + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + debug { versionNameSuffix "-dev" applicationIdSuffix ".debug" @@ -55,13 +73,10 @@ android { testCoverageEnabled true } - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } } } + // Module configuration configurations.all { resolutionStrategy { diff --git a/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestFavoriteFragmentModule.kt b/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestFavoriteFragmentModule.kt index a9ba8a6..cf8c950 100644 --- a/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestFavoriteFragmentModule.kt +++ b/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestFavoriteFragmentModule.kt @@ -29,8 +29,8 @@ class TestFavoriteFragmentModule { // } @Provides - fun provideFavoritesViewModelFactory(smsController: SmsController): FavoritesViewModelFactory { - return FavoritesViewModelFactoryImpl(smsController) + fun provideFavoritesViewModelFactory(): FavoritesViewModelFactory { + return favoritesViewModelFactory // return favoritesViewModelFactory } From e442738de2d2a143abbd2f40aed68fbd5e49f810 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Fri, 12 Oct 2018 11:48:09 +0200 Subject: [PATCH 03/18] Test removing ViewModelModule --- transport-eta-android/data-sharedpreferences/build.gradle | 4 ---- transport-eta-android/data/build.gradle | 1 - transport-eta-android/presentation/build.gradle | 4 ---- transport-eta-android/sms/build.gradle | 2 -- .../ui/di/module/HomeFragmentBuildersModule.kt | 7 +++---- .../transporteta/ui/home/favorite/FavoritesFragment.kt | 6 ++---- 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/transport-eta-android/data-sharedpreferences/build.gradle b/transport-eta-android/data-sharedpreferences/build.gradle index d6d548a..40a8682 100644 --- a/transport-eta-android/data-sharedpreferences/build.gradle +++ b/transport-eta-android/data-sharedpreferences/build.gradle @@ -4,8 +4,6 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - publishNonDefault true - compileSdkVersion build_versions.target_sdk defaultConfig { minSdkVersion build_versions.min_sdk @@ -80,12 +78,10 @@ androidExtensions { dependencies { // Module implementation project(':data') - // ACC kapt deps.lifecycle.compiler implementation deps.lifecycle.livedata implementation deps.lifecycle.viewmodel - // Javax implementation deps.javax.inject compileOnly deps.javax.annotation diff --git a/transport-eta-android/data/build.gradle b/transport-eta-android/data/build.gradle index 1f65648..4172f0e 100644 --- a/transport-eta-android/data/build.gradle +++ b/transport-eta-android/data/build.gradle @@ -11,7 +11,6 @@ configurations.all { dependencies { // Modules implementation project(':domain') - // Javax implementation deps.javax.inject compileOnly deps.javax.annotation diff --git a/transport-eta-android/presentation/build.gradle b/transport-eta-android/presentation/build.gradle index 80eba85..84c7f2b 100644 --- a/transport-eta-android/presentation/build.gradle +++ b/transport-eta-android/presentation/build.gradle @@ -4,8 +4,6 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - publishNonDefault true - compileSdkVersion build_versions.target_sdk defaultConfig { minSdkVersion build_versions.min_sdk @@ -77,12 +75,10 @@ androidExtensions { dependencies { // Module implementation project(':domain') - // ACC kapt deps.lifecycle.compiler implementation deps.lifecycle.livedata implementation deps.lifecycle.viewmodel - // Javax implementation deps.javax.inject compileOnly deps.javax.annotation diff --git a/transport-eta-android/sms/build.gradle b/transport-eta-android/sms/build.gradle index 59f60e0..6da5a6b 100644 --- a/transport-eta-android/sms/build.gradle +++ b/transport-eta-android/sms/build.gradle @@ -3,8 +3,6 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - publishNonDefault true - compileSdkVersion build_versions.target_sdk defaultConfig { minSdkVersion build_versions.min_sdk diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt index 24cdb75..b9da176 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt @@ -2,13 +2,12 @@ package com.joaquimley.transporteta.ui.di.module import com.joaquimley.transporteta.ui.home.favorite.FavoritesFragment import dagger.Module -import dagger.android.ContributesAndroidInjector @Module abstract class HomeFragmentBuildersModule { - @ContributesAndroidInjector(modules = [ - ViewModelModule::class - ]) +// @ContributesAndroidInjector(modules = [ +// ViewModelModule::class +// ]) abstract fun contributeFavouritesFragment(): FavoritesFragment } diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt index 5ae14cf..63bf341 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesFragment.kt @@ -32,10 +32,7 @@ import javax.inject.Inject */ class FavoritesFragment : Fragment() { - // Inspiration for UI https://www.behance.net/gallery/69860023/Bust-app - - @Inject - lateinit var viewModelProvider: FavoritesViewModelFactory + @Inject lateinit var viewModelProvider: FavoritesViewModelFactory private val viewModel by lazy { viewModelProvider.create() } private lateinit var adapter: FavoritesAdapter @@ -47,6 +44,7 @@ class FavoritesFragment : Fragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): + // TODO Inspiration for UI https://www.behance.net/gallery/69860023/Bust-app View = inflater.inflate(R.layout.fragment_favourites, container, false) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { From 81bdb3d594778f657819f74d427a61c7fd7d5ece Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Fri, 12 Oct 2018 15:11:38 +0200 Subject: [PATCH 04/18] Ci why you no work? --- transport-eta-android/ui-mobile/build.gradle | 5 +++-- .../ui/di/module/HomeFragmentBuildersModule.kt | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/transport-eta-android/ui-mobile/build.gradle b/transport-eta-android/ui-mobile/build.gradle index 06ad9e6..21564d3 100644 --- a/transport-eta-android/ui-mobile/build.gradle +++ b/transport-eta-android/ui-mobile/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'androidx.navigation.safeargs' + android { compileSdkVersion build_versions.compile_sdk defaultConfig { @@ -95,11 +96,11 @@ androidExtensions { dependencies { // Modules + implementation project(':presentation') + implementation project(':domain') implementation project(':sms') implementation project(':data') implementation project(':data-sharedpreferences') - implementation project(':domain') - implementation project(':presentation') // AndroidX implementation deps.androidx.slice implementation deps.androidx.core_ktx diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt index b9da176..24cdb75 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt @@ -2,12 +2,13 @@ package com.joaquimley.transporteta.ui.di.module import com.joaquimley.transporteta.ui.home.favorite.FavoritesFragment import dagger.Module +import dagger.android.ContributesAndroidInjector @Module abstract class HomeFragmentBuildersModule { -// @ContributesAndroidInjector(modules = [ -// ViewModelModule::class -// ]) + @ContributesAndroidInjector(modules = [ + ViewModelModule::class + ]) abstract fun contributeFavouritesFragment(): FavoritesFragment } From d953bf836be493a421164d5a45a6b0dcf8e6acb0 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Fri, 12 Oct 2018 15:35:50 +0200 Subject: [PATCH 05/18] Fix lints on CI --- .../transporteta/ui/di/module/ActivityBindingModule.kt | 2 +- .../transporteta/ui/di/module/HomeFragmentBuildersModule.kt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt index d4e1fcf..08f3706 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt @@ -1,7 +1,7 @@ package com.joaquimley.transporteta.ui.di.module -import com.joaquimley.transporteta.ui.home.HomeActivity import com.joaquimley.transporteta.ui.di.scope.PerActivity +import com.joaquimley.transporteta.ui.home.HomeActivity import dagger.Module import dagger.android.ContributesAndroidInjector diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt index 24cdb75..86b1ad6 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt @@ -7,8 +7,6 @@ import dagger.android.ContributesAndroidInjector @Module abstract class HomeFragmentBuildersModule { - @ContributesAndroidInjector(modules = [ - ViewModelModule::class - ]) + @ContributesAndroidInjector abstract fun contributeFavouritesFragment(): FavoritesFragment } From fc0d1fd4e34305a54538acf212684064eaac3c81 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sat, 13 Oct 2018 01:36:30 +0200 Subject: [PATCH 06/18] Working stuff for CI --- .gitignore | 4 +++- .../transporteta/ui/di/module/TestActivityBindingModule.kt | 2 +- .../transporteta/ui/di/module/ActivityBindingModule.kt | 2 +- ...uildersModule.kt => HomeActivityFragmentBuildersModule.kt} | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) rename transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/{HomeFragmentBuildersModule.kt => HomeActivityFragmentBuildersModule.kt} (85%) diff --git a/.gitignore b/.gitignore index cf44778..8460e67 100644 --- a/.gitignore +++ b/.gitignore @@ -74,4 +74,6 @@ proguard/ *.iml # OS -.DS_Store \ No newline at end of file +.DS_Store +bitrise.yml +gradle.deps diff --git a/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestActivityBindingModule.kt b/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestActivityBindingModule.kt index 3ffbeea..403bcf9 100644 --- a/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestActivityBindingModule.kt +++ b/transport-eta-android/ui-mobile/src/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestActivityBindingModule.kt @@ -8,7 +8,7 @@ import dagger.android.ContributesAndroidInjector @Module abstract class TestActivityBindingModule { - @PerActivity // HomeFragmentBuildersModule::class + @PerActivity // HomeActivityFragmentBuildersModule::class @ContributesAndroidInjector(modules = [ TestFragmentActivityModule::class, TestFragmentsBuildersModule::class diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt index 08f3706..7861249 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt @@ -11,7 +11,7 @@ abstract class ActivityBindingModule { @PerActivity @ContributesAndroidInjector(modules = [ HomeActivityModule::class, - HomeFragmentBuildersModule::class + HomeActivityFragmentBuildersModule::class ]) abstract fun bindHomeActivity(): HomeActivity } \ No newline at end of file diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityFragmentBuildersModule.kt similarity index 85% rename from transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt rename to transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityFragmentBuildersModule.kt index 86b1ad6..c079fed 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeFragmentBuildersModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityFragmentBuildersModule.kt @@ -5,7 +5,7 @@ import dagger.Module import dagger.android.ContributesAndroidInjector @Module -abstract class HomeFragmentBuildersModule { +abstract class HomeActivityFragmentBuildersModule { @ContributesAndroidInjector abstract fun contributeFavouritesFragment(): FavoritesFragment From eafd9affdd8c9619ca2a775446fa866f0a20cc20 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sat, 13 Oct 2018 13:22:04 +0200 Subject: [PATCH 07/18] housekeeping mobile-ui/build.gradle Had to make some changtes while debuging CI fails. This change still makes sense IMO. #69 --- transport-eta-android/ui-mobile/build.gradle | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/transport-eta-android/ui-mobile/build.gradle b/transport-eta-android/ui-mobile/build.gradle index 21564d3..edbee11 100644 --- a/transport-eta-android/ui-mobile/build.gradle +++ b/transport-eta-android/ui-mobile/build.gradle @@ -23,6 +23,19 @@ android { missingDimensionStrategy 'environment', ['prod', 'mock'] } + /** + * Prevent shipping the mock flavor with release variant + * https://developer.android.com/studio/build/build-variants.html + */ + variantFilter { variant -> + def names = variant.flavors*.name + // To check for a certain build type, use variant.buildType.name == "" + if (names.contains("mock") && variant.buildType.name == "release") { + // Gradle ignores any variants that satisfy the conditions above. + setIgnore(true) + } + } + // Always show the result of every unit test, even if it passes. testOptions { execution 'ANDROID_TEST_ORCHESTRATOR' @@ -45,23 +58,10 @@ android { quiet true abortOnError false ignoreWarnings true - } - - /** - * Prevent shipping the mock flavor with release variant - * https://developer.android.com/studio/build/build-variants.html - */ - variantFilter { variant -> - def names = variant.flavors*.name - // To check for a certain build type, use variant.buildType.name == "" - if (names.contains("mock") && variant.buildType.name == "release") { - // Gradle ignores any variants that satisfy the conditions above. - setIgnore(true) - } + checkDependencies true } buildTypes { - release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' From dcc8c238096c9a26a9f63d7872d0d0d2e7fdfd76 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sat, 13 Oct 2018 18:43:53 +0200 Subject: [PATCH 08/18] Rename data package to include project name #69 --- .../sharedpreferences/FrameworkLocalStorageImpl.kt | 4 ++-- .../data/FavoritesRepositoryImpl.kt | 6 +++--- .../data/TransportRepositoryImpl.kt | 6 +++--- .../data/executor/ThreadExecutorImpl.kt | 2 +- .../data/mapper/DataTransportMapper.kt | 4 ++-- .../{ => transporteta}/data/model/TransportEntity.kt | 2 +- .../data/source/FrameworkLocalStorage.kt | 4 ++-- .../data/store/TransportDataStore.kt | 4 ++-- .../data/store/TransportDataStoreImpl.kt | 6 +++--- .../data/FavoritesRepositoryTest.kt | 12 ++++++------ .../data/TransportRepositoryTest.kt | 12 ++++++------ .../{ => transporteta}/data/factory/DataFactory.kt | 2 +- .../data/factory/TransportFactory.kt | 10 +++++----- .../data/mapper/DataTransportMapperTest.kt | 6 +++--- .../data/store/TransportDataStoreTest.kt | 11 +++++------ .../ui/di/module/ActivityBindingModule.kt | 4 ++-- .../transporteta/ui/di/module/AppModule.kt | 2 +- .../transporteta/ui/di/module/DataSourceModule.kt | 2 +- .../transporteta/ui/di/module/DataStoreModule.kt | 6 +++--- .../transporteta/ui/di/module/HomeActivityModule.kt | 8 +++++++- .../transporteta/ui/di/module/HomeViewModelModule.kt | 8 -------- .../transporteta/ui/di/module/MapperModule.kt | 2 +- .../transporteta/ui/di/module/RepositoryModule.kt | 8 ++++---- 23 files changed, 64 insertions(+), 67 deletions(-) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/FavoritesRepositoryImpl.kt (84%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/TransportRepositoryImpl.kt (88%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/executor/ThreadExecutorImpl.kt (97%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/mapper/DataTransportMapper.kt (85%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/model/TransportEntity.kt (79%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/source/FrameworkLocalStorage.kt (77%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/store/TransportDataStore.kt (89%) rename transport-eta-android/data/src/main/java/com/joaquimley/{ => transporteta}/data/store/TransportDataStoreImpl.kt (91%) rename transport-eta-android/data/src/test/java/com/joaquimley/{ => transporteta}/data/FavoritesRepositoryTest.kt (96%) rename transport-eta-android/data/src/test/java/com/joaquimley/{ => transporteta}/data/TransportRepositoryTest.kt (98%) rename transport-eta-android/data/src/test/java/com/joaquimley/{ => transporteta}/data/factory/DataFactory.kt (90%) rename transport-eta-android/data/src/test/java/com/joaquimley/{ => transporteta}/data/factory/TransportFactory.kt (83%) rename transport-eta-android/data/src/test/java/com/joaquimley/{ => transporteta}/data/mapper/DataTransportMapperTest.kt (92%) rename transport-eta-android/data/src/test/java/com/joaquimley/{ => transporteta}/data/store/TransportDataStoreTest.kt (97%) delete mode 100644 transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeViewModelModule.kt diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index f76e51d..6888c68 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -1,7 +1,7 @@ package com.joaquimley.transporteta.sharedpreferences -import com.joaquimley.data.model.TransportEntity -import com.joaquimley.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import io.reactivex.Completable import io.reactivex.Single diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/FavoritesRepositoryImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt similarity index 84% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/FavoritesRepositoryImpl.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt index 7950305..b64e23c 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/FavoritesRepositoryImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt @@ -1,7 +1,7 @@ -package com.joaquimley.data +package com.joaquimley.transporteta.data -import com.joaquimley.data.mapper.DataTransportMapper -import com.joaquimley.data.store.TransportDataStore +import com.joaquimley.transporteta.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.store.TransportDataStore import com.joaquimley.transporteta.domain.model.Transport import com.joaquimley.transporteta.domain.repository.FavoritesRepository import io.reactivex.Completable diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/TransportRepositoryImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt similarity index 88% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/TransportRepositoryImpl.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt index 4829009..77bbbbd 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/TransportRepositoryImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt @@ -1,7 +1,7 @@ -package com.joaquimley.data +package com.joaquimley.transporteta.data -import com.joaquimley.data.mapper.DataTransportMapper -import com.joaquimley.data.store.TransportDataStore +import com.joaquimley.transporteta.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.store.TransportDataStore import com.joaquimley.transporteta.domain.model.Transport import com.joaquimley.transporteta.domain.repository.TransportRepository import io.reactivex.Completable diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/executor/ThreadExecutorImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/executor/ThreadExecutorImpl.kt similarity index 97% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/executor/ThreadExecutorImpl.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/executor/ThreadExecutorImpl.kt index abc1864..db7bfc7 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/executor/ThreadExecutorImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/executor/ThreadExecutorImpl.kt @@ -1,4 +1,4 @@ -package com.joaquimley.data.executor +package com.joaquimley.transporteta.data.executor import com.joaquimley.transporteta.domain.executor.ThreadExecutor import java.util.concurrent.LinkedBlockingQueue diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/mapper/DataTransportMapper.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/mapper/DataTransportMapper.kt similarity index 85% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/mapper/DataTransportMapper.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/mapper/DataTransportMapper.kt index e262923..8b4065b 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/mapper/DataTransportMapper.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/mapper/DataTransportMapper.kt @@ -1,6 +1,6 @@ -package com.joaquimley.data.mapper +package com.joaquimley.transporteta.data.mapper -import com.joaquimley.data.model.TransportEntity +import com.joaquimley.transporteta.data.model.TransportEntity import com.joaquimley.transporteta.domain.model.Transport class DataTransportMapper { diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/model/TransportEntity.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/model/TransportEntity.kt similarity index 79% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/model/TransportEntity.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/model/TransportEntity.kt index c48dfb5..7e71c36 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/model/TransportEntity.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/model/TransportEntity.kt @@ -1,4 +1,4 @@ -package com.joaquimley.data.model +package com.joaquimley.transporteta.data.model data class TransportEntity(val id: String, val name: String, val code: Int, val latestEta: String, val isFavorite: Boolean = false, val type: String) diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/source/FrameworkLocalStorage.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/source/FrameworkLocalStorage.kt similarity index 77% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/source/FrameworkLocalStorage.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/source/FrameworkLocalStorage.kt index 2353160..c68cc6f 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/source/FrameworkLocalStorage.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/source/FrameworkLocalStorage.kt @@ -1,6 +1,6 @@ -package com.joaquimley.data.source +package com.joaquimley.transporteta.data.source -import com.joaquimley.data.model.TransportEntity +import com.joaquimley.transporteta.data.model.TransportEntity import io.reactivex.Completable import io.reactivex.Single diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStore.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStore.kt similarity index 89% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStore.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStore.kt index b057f34..fbd3400 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStore.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStore.kt @@ -1,6 +1,6 @@ -package com.joaquimley.data.store +package com.joaquimley.transporteta.data.store -import com.joaquimley.data.model.TransportEntity +import com.joaquimley.transporteta.data.model.TransportEntity import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Observable diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStoreImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt similarity index 91% rename from transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStoreImpl.kt rename to transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt index a844724..69a1abd 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStoreImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt @@ -1,7 +1,7 @@ -package com.joaquimley.data.store +package com.joaquimley.transporteta.data.store -import com.joaquimley.data.model.TransportEntity -import com.joaquimley.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Observable diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/data/FavoritesRepositoryTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/FavoritesRepositoryTest.kt similarity index 96% rename from transport-eta-android/data/src/test/java/com/joaquimley/data/FavoritesRepositoryTest.kt rename to transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/FavoritesRepositoryTest.kt index 1cd2311..c8232e1 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/data/FavoritesRepositoryTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/FavoritesRepositoryTest.kt @@ -1,10 +1,10 @@ -package com.joaquimley.data +package com.joaquimley.transporteta.data -import com.joaquimley.data.factory.DataFactory.Factory.randomUuid -import com.joaquimley.data.factory.TransportFactory -import com.joaquimley.data.mapper.DataTransportMapper -import com.joaquimley.data.model.TransportEntity -import com.joaquimley.data.store.TransportDataStore +import com.joaquimley.transporteta.data.factory.DataFactory.Factory.randomUuid +import com.joaquimley.transporteta.data.factory.TransportFactory +import com.joaquimley.transporteta.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.data.store.TransportDataStore import com.joaquimley.transporteta.domain.model.Transport import com.joaquimley.transporteta.domain.repository.FavoritesRepository import com.nhaarman.mockitokotlin2.* diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/data/TransportRepositoryTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/TransportRepositoryTest.kt similarity index 98% rename from transport-eta-android/data/src/test/java/com/joaquimley/data/TransportRepositoryTest.kt rename to transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/TransportRepositoryTest.kt index 50fbbe3..960e85a 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/data/TransportRepositoryTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/TransportRepositoryTest.kt @@ -1,10 +1,10 @@ -package com.joaquimley.data +package com.joaquimley.transporteta.data -import com.joaquimley.data.factory.DataFactory -import com.joaquimley.data.factory.TransportFactory -import com.joaquimley.data.mapper.DataTransportMapper -import com.joaquimley.data.model.TransportEntity -import com.joaquimley.data.store.TransportDataStore +import com.joaquimley.transporteta.data.factory.DataFactory +import com.joaquimley.transporteta.data.factory.TransportFactory +import com.joaquimley.transporteta.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.data.store.TransportDataStore import com.joaquimley.transporteta.domain.model.Transport import com.joaquimley.transporteta.domain.repository.TransportRepository import com.nhaarman.mockitokotlin2.* diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/data/factory/DataFactory.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/DataFactory.kt similarity index 90% rename from transport-eta-android/data/src/test/java/com/joaquimley/data/factory/DataFactory.kt rename to transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/DataFactory.kt index b1e18f5..44033b2 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/data/factory/DataFactory.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/DataFactory.kt @@ -1,4 +1,4 @@ -package com.joaquimley.data.factory +package com.joaquimley.transporteta.data.factory import java.util.concurrent.ThreadLocalRandom diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/data/factory/TransportFactory.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt similarity index 83% rename from transport-eta-android/data/src/test/java/com/joaquimley/data/factory/TransportFactory.kt rename to transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt index a2d8510..ed4169b 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/data/factory/TransportFactory.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt @@ -1,13 +1,13 @@ -package com.joaquimley.data.factory +package com.joaquimley.transporteta.data.factory -import com.joaquimley.data.factory.DataFactory.Factory.randomInt -import com.joaquimley.data.factory.DataFactory.Factory.randomUuid -import com.joaquimley.data.model.TransportEntity +import com.joaquimley.transporteta.data.factory.DataFactory.Factory.randomInt +import com.joaquimley.transporteta.data.factory.DataFactory.Factory.randomUuid +import com.joaquimley.transporteta.data.model.TransportEntity import com.joaquimley.transporteta.domain.model.Transport /** * Factory class for [Transport] related instances - */ +*/ class TransportFactory { companion object Factory { diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/data/mapper/DataTransportMapperTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/mapper/DataTransportMapperTest.kt similarity index 92% rename from transport-eta-android/data/src/test/java/com/joaquimley/data/mapper/DataTransportMapperTest.kt rename to transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/mapper/DataTransportMapperTest.kt index 007805f..d7998c0 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/data/mapper/DataTransportMapperTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/mapper/DataTransportMapperTest.kt @@ -1,7 +1,7 @@ -package com.joaquimley.data.mapper +package com.joaquimley.transporteta.data.mapper -import com.joaquimley.data.factory.TransportFactory -import com.joaquimley.data.model.TransportEntity +import com.joaquimley.transporteta.data.factory.TransportFactory +import com.joaquimley.transporteta.data.model.TransportEntity import com.joaquimley.transporteta.domain.model.Transport import org.junit.Before import org.junit.Test diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/data/store/TransportDataStoreTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt similarity index 97% rename from transport-eta-android/data/src/test/java/com/joaquimley/data/store/TransportDataStoreTest.kt rename to transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt index 5d6a00b..78380f0 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/data/store/TransportDataStoreTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt @@ -1,12 +1,11 @@ -package com.joaquimley.data.store +package com.joaquimley.transporteta.data.store -import com.joaquimley.data.factory.DataFactory -import com.joaquimley.data.factory.TransportFactory -import com.joaquimley.data.model.TransportEntity -import com.joaquimley.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.data.factory.DataFactory +import com.joaquimley.transporteta.data.factory.TransportFactory +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.nhaarman.mockitokotlin2.* import io.reactivex.Completable -import io.reactivex.Flowable import io.reactivex.Single import org.junit.After import org.junit.Before diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt index 7861249..9289534 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/ActivityBindingModule.kt @@ -10,8 +10,8 @@ abstract class ActivityBindingModule { @PerActivity @ContributesAndroidInjector(modules = [ - HomeActivityModule::class, - HomeActivityFragmentBuildersModule::class + HomeActivityModule::class +// HomeActivityFragmentBuildersModule::class ]) abstract fun bindHomeActivity(): HomeActivity } \ No newline at end of file diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt index 3d2cb8c..44bfda9 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt @@ -2,7 +2,7 @@ package com.joaquimley.transporteta.ui.di.module import android.app.Application import android.content.Context -import com.joaquimley.data.executor.ThreadExecutorImpl +import com.joaquimley.transporteta.data.executor.ThreadExecutorImpl import com.joaquimley.transporteta.domain.executor.PostExecutionThread import com.joaquimley.transporteta.domain.executor.ThreadExecutor import com.joaquimley.transporteta.ui.UiThread diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt index f5b82f6..7d3e381 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt @@ -1,6 +1,6 @@ package com.joaquimley.transporteta.ui.di.module -import com.joaquimley.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.joaquimley.transporteta.sharedpreferences.FrameworkLocalStorageImpl import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt index 8352495..496c591 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt @@ -1,8 +1,8 @@ package com.joaquimley.transporteta.ui.di.module -import com.joaquimley.data.source.FrameworkLocalStorage -import com.joaquimley.data.store.TransportDataStore -import com.joaquimley.data.store.TransportDataStoreImpl +import com.joaquimley.transporteta.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.data.store.TransportDataStore +import com.joaquimley.transporteta.data.store.TransportDataStoreImpl import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module import dagger.Provides diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityModule.kt index cd076a2..f68123b 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeActivityModule.kt @@ -1,6 +1,12 @@ package com.joaquimley.transporteta.ui.di.module +import com.joaquimley.transporteta.ui.home.favorite.FavoritesFragment import dagger.Module +import dagger.android.ContributesAndroidInjector @Module -class HomeActivityModule \ No newline at end of file +abstract class HomeActivityModule { + + @ContributesAndroidInjector + abstract fun contributeFavouritesFragment(): FavoritesFragment +} \ No newline at end of file diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeViewModelModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeViewModelModule.kt deleted file mode 100644 index 08ed6df..0000000 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/HomeViewModelModule.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.joaquimley.transporteta.ui.di.module - -import dagger.Module - -@Module -class HomeViewModelModule { - -} \ No newline at end of file diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt index 622c556..4092b83 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt @@ -1,6 +1,6 @@ package com.joaquimley.transporteta.ui.di.module -import com.joaquimley.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.mapper.DataTransportMapper import com.joaquimley.transporteta.presentation.mapper.PresentationTransportMapper import dagger.Module import dagger.Provides diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/RepositoryModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/RepositoryModule.kt index 574aebe..261b3eb 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/RepositoryModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/RepositoryModule.kt @@ -1,11 +1,11 @@ package com.joaquimley.transporteta.ui.di.module import com.joaquimley.transporteta.domain.repository.FavoritesRepository -import com.joaquimley.data.FavoritesRepositoryImpl +import com.joaquimley.transporteta.data.FavoritesRepositoryImpl import com.joaquimley.transporteta.domain.repository.TransportRepository -import com.joaquimley.data.TransportRepositoryImpl -import com.joaquimley.data.mapper.DataTransportMapper -import com.joaquimley.data.store.TransportDataStore +import com.joaquimley.transporteta.data.TransportRepositoryImpl +import com.joaquimley.transporteta.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.store.TransportDataStore import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module import dagger.Provides From 80670ed77685634c0a0540b594333f59d282edc4 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sat, 13 Oct 2018 18:56:54 +0200 Subject: [PATCH 09/18] Remove unecessary .gitignore from other packages Maintenece commit, not really related to this branch feature. --- transport-eta-android/data-sharedpreferences/.gitignore | 1 - transport-eta-android/presentation/.gitignore | 1 - transport-eta-android/sms/.gitignore | 1 - 3 files changed, 3 deletions(-) delete mode 100644 transport-eta-android/data-sharedpreferences/.gitignore delete mode 100644 transport-eta-android/presentation/.gitignore delete mode 100644 transport-eta-android/sms/.gitignore diff --git a/transport-eta-android/data-sharedpreferences/.gitignore b/transport-eta-android/data-sharedpreferences/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/transport-eta-android/data-sharedpreferences/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/transport-eta-android/presentation/.gitignore b/transport-eta-android/presentation/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/transport-eta-android/presentation/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/transport-eta-android/sms/.gitignore b/transport-eta-android/sms/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/transport-eta-android/sms/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build From c1804a1a08ad1dff7ae706b1bd80a6d1887b29b4 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sat, 13 Oct 2018 19:26:09 +0200 Subject: [PATCH 10/18] Manifest cleanup and format --- .../data-sharedpreferences/src/main/AndroidManifest.xml | 4 ++-- .../transporteta/data/factory/TransportFactory.kt | 2 +- .../transporteta/data/store/TransportDataStoreTest.kt | 6 +++--- .../presentation/src/main/AndroidManifest.xml | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml b/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml index f495fe1..80ec3c8 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml +++ b/transport-eta-android/data-sharedpreferences/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ - + diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt index ed4169b..575d89a 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/factory/TransportFactory.kt @@ -7,7 +7,7 @@ import com.joaquimley.transporteta.domain.model.Transport /** * Factory class for [Transport] related instances -*/ + */ class TransportFactory { companion object Factory { diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt index 78380f0..3f73d48 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt @@ -74,14 +74,14 @@ class TransportDataStoreTest { // TODO: Missing correct data returned test // @Test // fun getAllFavoritesReturnsCorrectData() { - // Assemble + // Assemble // val transportList = TransportFactory.makeTransportList(5, true) // val transportEntityList = TransportFactory.makeTransportEntityList(5, true) // robot.stubTransportMapperToModel(transportEntityList, transportList) // robot.stubDataStoreGetAllFavoritesSuccess(transportEntityList) - // Act + // Act // val returnedData = favoritesRepository.getAll().test() - // Assert + // Assert // returnedData.assertResult(transportList) // } diff --git a/transport-eta-android/presentation/src/main/AndroidManifest.xml b/transport-eta-android/presentation/src/main/AndroidManifest.xml index 1e6da03..be52634 100644 --- a/transport-eta-android/presentation/src/main/AndroidManifest.xml +++ b/transport-eta-android/presentation/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + From 0ccd9492a7198a299e70142c358121bf1e0bfe4f Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sun, 14 Oct 2018 22:03:59 +0200 Subject: [PATCH 11/18] Scaffold stuff for stream episode 17 Some basic ideas just so I know what I'm supposed to continue, a lot of TODOs so lint warns me. For #17 Ref #69 --- .../FrameworkLocalStorageImpl.kt | 67 ++++++++++++++-- .../mapper/SharedPrefMapper.kt | 6 -- .../mapper/SharedPrefTransportMapper.kt | 36 +++++++++ .../model/SharedPrefTransport.kt | 7 +- .../sharedpreferences/ExampleUnitTest.java | 17 ---- .../FrameworkLocalStorageTest.kt | 42 ++++++++++ .../mapper/SharedPrefTransportMapperTest.kt | 79 +++++++++++++++++++ .../data/FavoritesRepositoryImpl.kt | 7 +- .../data/TransportRepositoryImpl.kt | 9 ++- .../data/store/TransportDataStoreImpl.kt | 8 +- .../data/store/TransportDataStoreTest.kt | 40 +++++----- .../transporteta/ui/di/module/AppModule.kt | 2 + .../ui/di/module/DataSourceModule.kt | 6 +- .../ui/di/module/DataStoreModule.kt | 2 + .../ui/di/qualifier/AndroidContext.kt | 9 +++ 15 files changed, 276 insertions(+), 61 deletions(-) delete mode 100644 transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt create mode 100644 transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt delete mode 100644 transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java create mode 100644 transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt create mode 100644 transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt create mode 100644 transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/qualifier/AndroidContext.kt diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index 6888c68..2a364c3 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -1,11 +1,28 @@ package com.joaquimley.transporteta.sharedpreferences +import android.content.Context import com.joaquimley.transporteta.data.model.TransportEntity import com.joaquimley.transporteta.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper +import com.joaquimley.transporteta.sharedpreferences.model.SharedPrefTransport import io.reactivex.Completable import io.reactivex.Single +import io.reactivex.subjects.PublishSubject +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class FrameworkLocalStorageImpl @Inject constructor(private val context: Context, + private val sharedPrefTransportMapper: SharedPrefTransportMapper) : FrameworkLocalStorage { + + private val sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) + private val sharedPreferencesObservable: PublishSubject> = PublishSubject.create() + + init { + observeSharedPreferencesChanges() + loadAll() + } -class FrameworkLocalStorageImpl: FrameworkLocalStorage { override fun saveTransport(transportEntity: TransportEntity): Completable { return Completable.complete() } @@ -15,17 +32,57 @@ class FrameworkLocalStorageImpl: FrameworkLocalStorage { } override fun getTransport(transportEntityId: String): Single { - return Single.just(TransportEntity("hi", "mock",2, "el", true,"bus")) + return Single.just(TransportEntity("hi", "mock", 2, "el", true, "bus")) } override fun getAll(): Single> { val list = mutableListOf() - list.add(TransportEntity("hi", "mock",2, "latestEta 12324", true,"bus")) - list.add(TransportEntity("there", "mock",23, "latestEta 123", true,"bus")) + list.add(TransportEntity("hi", "mock", 2, "latestEta 12324", true, "bus")) + list.add(TransportEntity("there", "mock", 23, "latestEta 123", true, "bus")) return Single.just(list) } override fun clearAll(): Completable { return Completable.complete() } -} \ No newline at end of file + + private fun observeSharedPreferencesChanges() { + sharedPreferences.registerOnSharedPreferenceChangeListener { _, key -> + if (key != SHARED_PREFERENCES_LAST_UPDATED) { + sharedPreferencesObservable.onNext(loadAll()) + } + } + } + + private fun loadAll(): List { + val data = mutableListOf() + val sharedPrefTransport1 = sharedPreferences.getString(Slot.ONE.name, "") + val sharedPrefTransport2 = sharedPreferences.getString(Slot.TWO.name, "") + val sharedPrefTransport3 = sharedPreferences.getString(Slot.THREE.name, "") + // TODO + + + return data + } + + companion object { + private const val SHARED_PREFERENCES_NAME = "com.joaquimley.transporteta.sharedpreferences" + private const val SHARED_PREFERENCES_LAST_UPDATED = "sharedpreferences.last_updated" + } + + enum class Slot(name: String) { + ONE("transport_eta_fav_1"), + TWO("transport_eta_fav_2"), + THREE("transport_eta_fav_3") + } + + // TODO - Still not sure this is needed + /** + * Store and retrieve the last time data was cached + */ +//var lastUpdated: Long +// get() = sharedPreferences.getLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, 0) +// set(lastUpdated) = sharedPreferences.edit().putLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, lastUpdated).apply() +} + + diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt deleted file mode 100644 index cb2d8f8..0000000 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefMapper.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.joaquimley.transporteta.sharedpreferences.mapper - -class SharedPrefMapper { - - // TODO -} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt new file mode 100644 index 0000000..a52c6e2 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt @@ -0,0 +1,36 @@ +package com.joaquimley.transporteta.sharedpreferences.mapper + +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.sharedpreferences.model.SharedPrefTransport + +class SharedPrefTransportMapper { + +// fun toCacheString(from: SharedPrefTransport): String { +// // TODO +// } + +// fun fromCacheString(from: String): SharedPrefTransport { +// // TODO +// } + +// fun toSharedPref(from: List): List { + // TODO +// return from.map { toSharedPref(it) } +// } + +// fun toSharedPref(from: TransportEntity): SharedPrefTransport { +// +// TODO +// return SharedPrefTransport(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type>) +// } + +// fun toEntity(from: List): List { + // TODO +// return from.map { toEntity(it) } +// } + +// fun toEntity(from: SharedPrefTransport): TransportEntity { + // TODO +// return TransportEntity(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type) +// } +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt index 5630f72..bbbe397 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt @@ -1,6 +1,5 @@ package com.joaquimley.transporteta.sharedpreferences.model -class SharedPrefTransport { - - // TODO -} \ No newline at end of file +data class SharedPrefTransport(val id: String, val name: String, val code: Int, val latestEta: String, + val isFavorite: Boolean = false, val type: String, val lastUpdated: Long, + val slot: String) diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java deleted file mode 100644 index 031e2fa..0000000 --- a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.joaquimley.transporteta.sharedpreferences; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt new file mode 100644 index 0000000..49e6e15 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt @@ -0,0 +1,42 @@ +package com.joaquimley.transporteta.sharedpreferences + +import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper +import com.nhaarman.mockitokotlin2.mock +import org.junit.After +import org.junit.Test + +import org.junit.Before + + +// Roboeletric +class FrameworkLocalStorageTest { + + private val robot = Robot() + + // private val mockApplicationContext = mock() + private val mockMapper = mock() + + + @Before + fun setup() { + + } + + @After + fun tearDown() { + + } + + @Test + fun assertThisBoi() { + val sum = 4 + 4 + val result = 8 + assert(sum == result) + } + + + inner class Robot { + // TODO + } + +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt new file mode 100644 index 0000000..4c072e9 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt @@ -0,0 +1,79 @@ +package com.joaquimley.transporteta.sharedpreferences.mapper + +import com.joaquimley.transporteta.data.factory.TransportFactory +import com.joaquimley.transporteta.data.mapper.DataTransportMapper +import com.joaquimley.transporteta.data.model.TransportEntity +import org.junit.Before +import org.junit.Test + + +// TODO big because nothing has been tested or implemented ¯\_(ツ)_/¯¯ +class SharedPrefTransportMapperTest { + + private val robot = Robot() + private lateinit var mapper: SharedPrefTransportMapper + + @Before + fun setup() { + mapper = SharedPrefTransportMapper() + } + +// @Test +// fun fromModelToView() { +// // Assemble +// val stubbed = TransportFactory.makeTransport() +// // Act +// val mapped = mapper.toEntity(stubbed) +// // Assert +// assert(robot.areItemsTheSame(stubbed, mapped)) +// } +// +// @Test +// fun fromModelListToViewList() { +// // Assemble +// val stubbed = TransportFactory.makeTransportList(5) +// // Act +// val mapped = mapper.toEntity(stubbed) +// // Assert +// assert(robot.areItemsInListTheSame(stubbed, mapped)) +// } +// +// @Test +// fun fromViewToModel() { +// // Assemble +// val stubbed = TransportFactory.makeTransportEntity() +// // Act +// val mapped = mapper.toModel(stubbed) +// // Assert +// assert(robot.areItemsTheSame(mapped, stubbed)) +// } +// +// @Test +// fun fromViewListToModelList() { +// // Assemble +// val stubbed = TransportFactory.makeTransportEntityList(5) +// // Act +// val mapped = mapper.toModel(stubbed) +// // Assert +// assert(robot.areItemsInListTheSame(mapped, stubbed)) +// } + + inner class Robot { +// fun areItemsInListTheSame(transportList: List, transportViewList: List): Boolean { +// for (transport in transportList.withIndex()) { +// if (!areItemsTheSame(transportList[transport.index], transportViewList[transport.index])) { +// return false +// } +// } +// return true +// } +// +// fun areItemsTheSame(transport: Transport, transportView: TransportEntity): Boolean { +// return transport.id == transportView.id && +// transport.code == transportView.code && +// transport.latestEta == transportView.latestEta && +// transport.isFavorite == transportView.isFavorite && +// transport.type.equals(transportView.type) +// } + } +} diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt index b64e23c..2bafc06 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/FavoritesRepositoryImpl.kt @@ -6,9 +6,12 @@ import com.joaquimley.transporteta.domain.model.Transport import com.joaquimley.transporteta.domain.repository.FavoritesRepository import io.reactivex.Completable import io.reactivex.Flowable +import javax.inject.Inject +import javax.inject.Singleton -class FavoritesRepositoryImpl(private val transportDataStore: TransportDataStore, - private val mapper: DataTransportMapper) : FavoritesRepository { +@Singleton +class FavoritesRepositoryImpl @Inject constructor(private val transportDataStore: TransportDataStore, + private val mapper: DataTransportMapper) : FavoritesRepository { override fun markAsFavorite(transport: Transport): Completable { return transportDataStore.markAsFavorite(mapper.toEntity(transport)) diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt index 77bbbbd..63dc7c8 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/TransportRepositoryImpl.kt @@ -7,12 +7,15 @@ import com.joaquimley.transporteta.domain.repository.TransportRepository import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Observable +import javax.inject.Inject +import javax.inject.Singleton -class TransportRepositoryImpl(private val transportDataStore: TransportDataStore, - private val mapper: DataTransportMapper): TransportRepository { +@Singleton +class TransportRepositoryImpl @Inject constructor(private val transportDataStore: TransportDataStore, + private val mapper: DataTransportMapper) : TransportRepository { override fun requestTransportEta(transportCode: Int): Observable { - return transportDataStore.requestTransportEta(transportCode).map{ mapper.toModel(it)} + return transportDataStore.requestTransportEta(transportCode).map { mapper.toModel(it) } } override fun cancelTransportEtaRequest(transportCode: Int?): Completable { diff --git a/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt index 69a1abd..8fcd973 100644 --- a/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt +++ b/transport-eta-android/data/src/main/java/com/joaquimley/transporteta/data/store/TransportDataStoreImpl.kt @@ -5,8 +5,12 @@ import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Observable +import javax.inject.Inject +import javax.inject.Singleton -class TransportDataStoreImpl(private val frameworkLocalStorage: FrameworkLocalStorage): TransportDataStore { +@Singleton +class TransportDataStoreImpl @Inject constructor(private val frameworkLocalStorage: FrameworkLocalStorage) + : TransportDataStore { override fun markAsFavorite(transportEntity: TransportEntity): Completable { return Completable.error(NotImplementedError("Won't be ready for v1.0")) @@ -33,7 +37,7 @@ class TransportDataStoreImpl(private val frameworkLocalStorage: FrameworkLocalSt } override fun getTransport(transportEntityId: String): Observable { - return frameworkLocalStorage.getTransport(transportEntityId).toObservable() + return frameworkLocalStorage.getTransport(transportEntityId).toObservable() } override fun getAll(): Flowable> { diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt index 3f73d48..8bc003f 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt @@ -110,26 +110,26 @@ class TransportDataStoreTest { result.assertError(NotImplementedError::class.java) } - @Test - fun requestTransportEtaThrowsNotYetImplemented() { - // Assemble - - // Act - val result = transportDataStore.requestTransportEta(DataFactory.randomInt()).test() - // Assert - result.assertError(NotImplementedError::class.java) - } - - - @Test - fun cancelTransportEtaRequestThrowsNotYetImplemented() { - // Assemble - - // Act - val result = transportDataStore.cancelTransportEtaRequest(DataFactory.randomInt()).test() - // Assert - result.assertError(NotImplementedError::class.java) - } +// @Test +// fun requestTransportEtaThrowsNotYetImplemented() { +// // Assemble +// +// // Act +// val result = transportDataStore.requestTransportEta(DataFactory.randomInt()).test() +// // Assert +// result.assertError(NotImplementedError::class.java) +// } +// +// +// @Test +// fun cancelTransportEtaRequestThrowsNotYetImplemented() { +// // Assemble +// +// // Act +// val result = transportDataStore.cancelTransportEtaRequest(DataFactory.randomInt()).test() +// // Assert +// result.assertError(NotImplementedError::class.java) +// } /** diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt index 44bfda9..6d11b91 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/AppModule.kt @@ -10,6 +10,7 @@ import com.joaquimley.transporteta.ui.di.component.ControllerSubComponent import com.joaquimley.transporteta.ui.di.component.DataSubComponent import com.joaquimley.transporteta.ui.di.component.RepositorySubComponent import com.joaquimley.transporteta.ui.di.component.ViewModelSubComponent +import com.joaquimley.transporteta.ui.di.qualifier.AndroidContext import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module import dagger.Provides @@ -39,6 +40,7 @@ class AppModule { @Provides @PerApplication + @AndroidContext.ApplicationContext fun provideContext(app: Application): Context { return app } diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt index 7d3e381..52975b5 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt @@ -1,7 +1,9 @@ package com.joaquimley.transporteta.ui.di.module +import android.content.Context import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.joaquimley.transporteta.sharedpreferences.FrameworkLocalStorageImpl +import com.joaquimley.transporteta.ui.di.qualifier.AndroidContext import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module import dagger.Provides @@ -11,8 +13,8 @@ class DataSourceModule { @Provides @PerApplication - fun provideSharedPreferencesDataSource(): FrameworkLocalStorage { - return FrameworkLocalStorageImpl() + fun provideSharedPreferencesDataSource(@AndroidContext.ApplicationContext applicationContext: Context): FrameworkLocalStorage { + return FrameworkLocalStorageImpl(applicationContext) } // @Provides diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt index 496c591..92ad61d 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataStoreModule.kt @@ -1,8 +1,10 @@ package com.joaquimley.transporteta.ui.di.module +import android.content.Context import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.joaquimley.transporteta.data.store.TransportDataStore import com.joaquimley.transporteta.data.store.TransportDataStoreImpl +import com.joaquimley.transporteta.ui.di.qualifier.AndroidContext import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module import dagger.Provides diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/qualifier/AndroidContext.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/qualifier/AndroidContext.kt new file mode 100644 index 0000000..508ccda --- /dev/null +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/qualifier/AndroidContext.kt @@ -0,0 +1,9 @@ +package com.joaquimley.transporteta.ui.di.qualifier + +import javax.inject.Qualifier + +interface AndroidContext { + @Qualifier + @Retention(AnnotationRetention.RUNTIME) + annotation class ApplicationContext +} \ No newline at end of file From 2fc62900d7db3b862dd3ea66ad1663e46f11c433 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Sun, 14 Oct 2018 22:07:45 +0200 Subject: [PATCH 12/18] Housekeeping from previous commit --- .../FrameworkLocalStorageImpl.kt | 2 + .../data/store/TransportDataStoreTest.kt | 40 +++++++++---------- .../ui/di/module/DataSourceModule.kt | 6 ++- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index 2a364c3..12e967e 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -39,6 +39,8 @@ class FrameworkLocalStorageImpl @Inject constructor(private val context: Context val list = mutableListOf() list.add(TransportEntity("hi", "mock", 2, "latestEta 12324", true, "bus")) list.add(TransportEntity("there", "mock", 23, "latestEta 123", true, "bus")) + list.add(TransportEntity("world", "mock", 25, "latestEta 12454", true, "bus")) + list.add(TransportEntity("sup", "mock", 29, "latestEta 675", true, "bus")) return Single.just(list) } diff --git a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt index 8bc003f..3f73d48 100644 --- a/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt +++ b/transport-eta-android/data/src/test/java/com/joaquimley/transporteta/data/store/TransportDataStoreTest.kt @@ -110,26 +110,26 @@ class TransportDataStoreTest { result.assertError(NotImplementedError::class.java) } -// @Test -// fun requestTransportEtaThrowsNotYetImplemented() { -// // Assemble -// -// // Act -// val result = transportDataStore.requestTransportEta(DataFactory.randomInt()).test() -// // Assert -// result.assertError(NotImplementedError::class.java) -// } -// -// -// @Test -// fun cancelTransportEtaRequestThrowsNotYetImplemented() { -// // Assemble -// -// // Act -// val result = transportDataStore.cancelTransportEtaRequest(DataFactory.randomInt()).test() -// // Assert -// result.assertError(NotImplementedError::class.java) -// } + @Test + fun requestTransportEtaThrowsNotYetImplemented() { + // Assemble + + // Act + val result = transportDataStore.requestTransportEta(DataFactory.randomInt()).test() + // Assert + result.assertError(NotImplementedError::class.java) + } + + + @Test + fun cancelTransportEtaRequestThrowsNotYetImplemented() { + // Assemble + + // Act + val result = transportDataStore.cancelTransportEtaRequest(DataFactory.randomInt()).test() + // Assert + result.assertError(NotImplementedError::class.java) + } /** diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt index 52975b5..dec97fa 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt @@ -3,6 +3,7 @@ package com.joaquimley.transporteta.ui.di.module import android.content.Context import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.joaquimley.transporteta.sharedpreferences.FrameworkLocalStorageImpl +import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper import com.joaquimley.transporteta.ui.di.qualifier.AndroidContext import com.joaquimley.transporteta.ui.di.scope.PerApplication import dagger.Module @@ -13,8 +14,9 @@ class DataSourceModule { @Provides @PerApplication - fun provideSharedPreferencesDataSource(@AndroidContext.ApplicationContext applicationContext: Context): FrameworkLocalStorage { - return FrameworkLocalStorageImpl(applicationContext) + fun provideSharedPreferencesDataSource(@AndroidContext.ApplicationContext applicationContext: Context, + sharedPrefTransportMapper: SharedPrefTransportMapper): FrameworkLocalStorage { + return FrameworkLocalStorageImpl(applicationContext, sharedPrefTransportMapper) } // @Provides From 472d8bef993185ba9f60142ef9be98c77f74afab Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Mon, 15 Oct 2018 15:11:50 +0200 Subject: [PATCH 13/18] Fix typo in readme Changed the copy on the stream log section --- README.MD | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.MD b/README.MD index cfa90ee..bf5b5a6 100644 --- a/README.MD +++ b/README.MD @@ -28,8 +28,8 @@ An utility app using an SMS based service (or the web) to request a more precise ## Why 🤔 Since I'm always working on some side-projects, I decided to document the progress live on a coding stream, this way I'll force myself into completing, while giving something back to a community that already thought me so much. -## Stream log -##### Come and say Hi 👋, join me at [twitch.tv/joaquimley](http:twitch.tv/joaquimley): watch, help, and learn as I develop and make mistakes +## Stream PR log +##### Come and say Hi 👋 and be part of the develpoment live at [twitch.tv/joaquimley](http:twitch.tv/joaquimley) - Ep.1: https://github.com/JoaquimLey/transport-eta/tree/4642c5fd6af9de3b258b179d0a7a8c69195fa293 @@ -61,7 +61,7 @@ Since I'm always working on some side-projects, I decided to document the progre - Ep.15: https://github.com/JoaquimLey/transport-eta/pull/70 -- Ep.15: https://github.com/JoaquimLey/transport-eta/pull/74 +- Ep.16: https://github.com/JoaquimLey/transport-eta/pull/74 ## About the author @@ -92,7 +92,7 @@ Personal website: #### Important references -It would take substantially more time to setup this project without this reference projects +It would take substantially more time to setup this project without this reference projects, so a special thanks to: - https://github.com/bufferapp/clean-architecture-components-boilerplate From ec8b41c4bd6d63c778c5407292a54fbaa234c44b Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Tue, 16 Oct 2018 21:17:04 +0200 Subject: [PATCH 14/18] Include kotlinx.serialization experimental library for sharedPrefs This will be included in the stblib from Kotlin 1.3. #17, #69 --- README.MD | 7 ++-- transport-eta-android/build.gradle | 4 +- .../data-sharedpreferences/build.gradle | 2 + .../data-sharedpreferences/proguard-rules.pro | 17 ++++---- .../FrameworkLocalStorageImpl.kt | 23 +++++------ .../mapper/SharedPrefTransportMapper.kt | 39 ++++++++++--------- .../model/SharedPrefTransport.kt | 1 + transport-eta-android/versions.gradle | 6 ++- 8 files changed, 55 insertions(+), 44 deletions(-) diff --git a/README.MD b/README.MD index bf5b5a6..b10385e 100644 --- a/README.MD +++ b/README.MD @@ -2,12 +2,13 @@ - + # Transport ETA -[![License Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=true)](http://www.apache.org/licenses/LICENSE-2.0) + +![production version](https://img.shields.io/badge/playstore-unreleased-lightgrey.svg?style=true) ![minSdkVersion 19](https://img.shields.io/badge/minSdkVersion-19-yellow.svg?style=true) -![compileSdkVersion 27](https://img.shields.io/badge/compileSdkVersion-28-green.svg?style=true) +![compileSdkVersion 28](https://img.shields.io/badge/compileSdkVersion-28-green.svg?style=true) [![Build Status](https://app.bitrise.io/app/f75916759d698e6e/status.svg?token=nCaNQBZcMNPMckWWwn8Gxg&branch=develop)](https://app.bitrise.io/app/f75916759d698e6e) [![codecov](https://codecov.io/gh/JoaquimLey/transport-eta/branch/develop/graph/badge.svg)](https://codecov.io/gh/JoaquimLey/transport-eta) diff --git a/transport-eta-android/build.gradle b/transport-eta-android/build.gradle index 0a5d97a..b735135 100644 --- a/transport-eta-android/build.gradle +++ b/transport-eta-android/build.gradle @@ -4,12 +4,10 @@ buildscript { addRepos(repositories) dependencies { classpath deps.kotlin.plugin + classpath deps.kotlin.serialization_plugin classpath deps.navigation.safe_args classpath deps.android_gradle_plugin } - repositories { - google() - } } allprojects { diff --git a/transport-eta-android/data-sharedpreferences/build.gradle b/transport-eta-android/data-sharedpreferences/build.gradle index 40a8682..82ad0a5 100644 --- a/transport-eta-android/data-sharedpreferences/build.gradle +++ b/transport-eta-android/data-sharedpreferences/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlinx-serialization' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' @@ -90,6 +91,7 @@ dependencies { implementation deps.rx.android // Kotlin implementation deps.kotlin.rx + implementation deps.kotlin.serialization implementation deps.kotlin.stdlib /*********** diff --git a/transport-eta-android/data-sharedpreferences/proguard-rules.pro b/transport-eta-android/data-sharedpreferences/proguard-rules.pro index f1b4245..4902321 100644 --- a/transport-eta-android/data-sharedpreferences/proguard-rules.pro +++ b/transport-eta-android/data-sharedpreferences/proguard-rules.pro @@ -5,13 +5,6 @@ # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable @@ -19,3 +12,13 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +-keepattributes *Annotation*, InnerClasses +-dontnote kotlinx.serialization.SerializationKt +-keep,includedescriptorclasses class com.yourcompany.yourpackage.**$$serializer { *; } # <-- change package name to your app's +-keepclassmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's + *** Companion; +} +-keepclasseswithmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's + kotlinx.serialization.KSerializer serializer(...); +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index 12e967e..38dc8d9 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -12,11 +12,11 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class FrameworkLocalStorageImpl @Inject constructor(private val context: Context, - private val sharedPrefTransportMapper: SharedPrefTransportMapper) : FrameworkLocalStorage { +class FrameworkLocalStorageImpl @Inject constructor(context: Context, + private val mapper: SharedPrefTransportMapper) : FrameworkLocalStorage { private val sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) - private val sharedPreferencesObservable: PublishSubject> = PublishSubject.create() + private val sharedPreferencesObservable: PublishSubject> = PublishSubject.create() init { observeSharedPreferencesChanges() @@ -56,17 +56,18 @@ class FrameworkLocalStorageImpl @Inject constructor(private val context: Context } } - private fun loadAll(): List { - val data = mutableListOf() - val sharedPrefTransport1 = sharedPreferences.getString(Slot.ONE.name, "") - val sharedPrefTransport2 = sharedPreferences.getString(Slot.TWO.name, "") - val sharedPrefTransport3 = sharedPreferences.getString(Slot.THREE.name, "") - // TODO - - + private fun loadAll(): List { + val data = mutableListOf() + data.add(mapper.toEntity(get(Slot.ONE))) + data.add(mapper.toEntity(get(Slot.TWO))) + data.add(mapper.toEntity(get(Slot.THREE))) return data } + private fun get(key: Slot): SharedPrefTransport { + return mapper.fromCacheString(sharedPreferences.getString(key.name, "")) + } + companion object { private const val SHARED_PREFERENCES_NAME = "com.joaquimley.transporteta.sharedpreferences" private const val SHARED_PREFERENCES_LAST_UPDATED = "sharedpreferences.last_updated" diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt index a52c6e2..357a8b2 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt @@ -2,35 +2,36 @@ package com.joaquimley.transporteta.sharedpreferences.mapper import com.joaquimley.transporteta.data.model.TransportEntity import com.joaquimley.transporteta.sharedpreferences.model.SharedPrefTransport +import kotlinx.serialization.json.JSON class SharedPrefTransportMapper { -// fun toCacheString(from: SharedPrefTransport): String { -// // TODO -// } + fun toCacheString(from: SharedPrefTransport): String { + return JSON.stringify(from) + } -// fun fromCacheString(from: String): SharedPrefTransport { -// // TODO -// } + fun fromCacheString(from: String): SharedPrefTransport { + return JSON.parse(from) + } -// fun toSharedPref(from: List): List { + fun toSharedPref(from: List): List { // TODO -// return from.map { toSharedPref(it) } -// } + return from.map { toSharedPref(it) } + } + + fun toSharedPref(from: TransportEntity): SharedPrefTransport { -// fun toSharedPref(from: TransportEntity): SharedPrefTransport { -// // TODO -// return SharedPrefTransport(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type>) -// } + return SharedPrefTransport(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type, 1312, "") + } -// fun toEntity(from: List): List { + fun toEntity(from: List): List { // TODO -// return from.map { toEntity(it) } -// } + return from.map { toEntity(it) } + } -// fun toEntity(from: SharedPrefTransport): TransportEntity { + fun toEntity(from: SharedPrefTransport): TransportEntity { // TODO -// return TransportEntity(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type) -// } + return TransportEntity(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type) + } } \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt index bbbe397..da32d80 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt @@ -3,3 +3,4 @@ package com.joaquimley.transporteta.sharedpreferences.model data class SharedPrefTransport(val id: String, val name: String, val code: Int, val latestEta: String, val isFavorite: Boolean = false, val type: String, val lastUpdated: Long, val slot: String) + diff --git a/transport-eta-android/versions.gradle b/transport-eta-android/versions.gradle index f9624a0..fa8edf7 100644 --- a/transport-eta-android/versions.gradle +++ b/transport-eta-android/versions.gradle @@ -6,7 +6,8 @@ ext.deps = [:] def versions = [:] // Plugins -versions.kotlin = "1.2.51" +versions.kotlin = "1.2.60" +versions.kotlin_serialization = "0.6.1" versions.android_gradle_plugin = '3.3.0-alpha03' // Javax @@ -161,6 +162,8 @@ kotlin.test = "org.jetbrains.kotlin:kotlin-test:$versions.kotlin" kotlin.stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin" kotlin.junit = "org.jetbrains.kotlin:kotlin-test-junit:$versions.kotlin" kotlin.plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" +kotlin.serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$versions.kotlin_serialization" +kotlin.serialization_plugin = "org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:$versions.kotlin_serialization" deps.kotlin = kotlin def rx = [:] @@ -203,5 +206,6 @@ ext.app_version = app_version static def addRepos(RepositoryHandler handler) { handler.google() handler.jcenter() + handler.maven { url "https://kotlin.bintray.com/kotlinx" } } ext.addRepos = this.&addRepos \ No newline at end of file From 16d03c1c5a4ba88064dc4ba65e18cb905035e1a0 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Tue, 16 Oct 2018 22:34:58 +0200 Subject: [PATCH 15/18] Make SharedPrefTransport model @kotlinx.serialization.Serializable Also, fixes and issue where the String was default to which made the serialization fail: - https://github.com/Kotlin/kotlinx.serialization/issues/115 #17, #69 --- .../FrameworkLocalStorageImpl.kt | 36 +++++++++++-------- .../model/SharedPrefTransport.kt | 1 + .../ui/di/module/DataSourceModule.kt | 15 ++++++-- .../transporteta/ui/di/module/MapperModule.kt | 6 ++++ 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index 38dc8d9..973a9d1 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -1,6 +1,6 @@ package com.joaquimley.transporteta.sharedpreferences -import android.content.Context +import android.content.SharedPreferences import com.joaquimley.transporteta.data.model.TransportEntity import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper @@ -12,10 +12,9 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class FrameworkLocalStorageImpl @Inject constructor(context: Context, +class FrameworkLocalStorageImpl @Inject constructor(private val sharedPreferences: SharedPreferences, private val mapper: SharedPrefTransportMapper) : FrameworkLocalStorage { - private val sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) private val sharedPreferencesObservable: PublishSubject> = PublishSubject.create() init { @@ -24,7 +23,9 @@ class FrameworkLocalStorageImpl @Inject constructor(context: Context, } override fun saveTransport(transportEntity: TransportEntity): Completable { - return Completable.complete() + return Completable.fromAction { + saveToSharedPrefs(mapper.toSharedPref(transportEntity)) + } } override fun deleteTransport(transportEntityId: String): Completable { @@ -51,32 +52,37 @@ class FrameworkLocalStorageImpl @Inject constructor(context: Context, private fun observeSharedPreferencesChanges() { sharedPreferences.registerOnSharedPreferenceChangeListener { _, key -> if (key != SHARED_PREFERENCES_LAST_UPDATED) { - sharedPreferencesObservable.onNext(loadAll()) + loadAll() } } } - private fun loadAll(): List { + private fun loadAll() { val data = mutableListOf() - data.add(mapper.toEntity(get(Slot.ONE))) - data.add(mapper.toEntity(get(Slot.TWO))) - data.add(mapper.toEntity(get(Slot.THREE))) - return data + getFromSharedPrefs(Slot.ONE)?.let { data.add(mapper.toEntity(it)) } + getFromSharedPrefs(Slot.TWO)?.let { data.add(mapper.toEntity(it)) } + getFromSharedPrefs(Slot.THREE)?.let { data.add(mapper.toEntity(it)) } + sharedPreferencesObservable.onNext(data) + } + + private fun saveToSharedPrefs(sharedPrefTransport: SharedPrefTransport) { + // TODO } - private fun get(key: Slot): SharedPrefTransport { - return mapper.fromCacheString(sharedPreferences.getString(key.name, "")) + private fun getFromSharedPrefs(slot: Slot): SharedPrefTransport? { + sharedPreferences.getString(slot.name, null)?.let { + return mapper.fromCacheString(it) + } ?: return null } companion object { - private const val SHARED_PREFERENCES_NAME = "com.joaquimley.transporteta.sharedpreferences" private const val SHARED_PREFERENCES_LAST_UPDATED = "sharedpreferences.last_updated" } enum class Slot(name: String) { ONE("transport_eta_fav_1"), TWO("transport_eta_fav_2"), - THREE("transport_eta_fav_3") + THREE("transport_eta_fav_3"), } // TODO - Still not sure this is needed @@ -84,7 +90,7 @@ class FrameworkLocalStorageImpl @Inject constructor(context: Context, * Store and retrieve the last time data was cached */ //var lastUpdated: Long -// get() = sharedPreferences.getLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, 0) +// getFromSharedPrefs() = sharedPreferences.getLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, 0) // set(lastUpdated) = sharedPreferences.edit().putLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, lastUpdated).apply() } diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt index da32d80..c2d51d7 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/model/SharedPrefTransport.kt @@ -1,5 +1,6 @@ package com.joaquimley.transporteta.sharedpreferences.model +@kotlinx.serialization.Serializable data class SharedPrefTransport(val id: String, val name: String, val code: Int, val latestEta: String, val isFavorite: Boolean = false, val type: String, val lastUpdated: Long, val slot: String) diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt index dec97fa..d303bf2 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/DataSourceModule.kt @@ -1,6 +1,7 @@ package com.joaquimley.transporteta.ui.di.module import android.content.Context +import android.content.SharedPreferences import com.joaquimley.transporteta.data.source.FrameworkLocalStorage import com.joaquimley.transporteta.sharedpreferences.FrameworkLocalStorageImpl import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper @@ -12,11 +13,21 @@ import dagger.Provides @Module class DataSourceModule { + companion object { + private const val SHARED_PREFERENCES_NAME = "com.joaquimley.transporteta.sharedpreferences" + } + + @Provides + @PerApplication + fun provideSharedPreferences(@AndroidContext.ApplicationContext applicationContext: Context): SharedPreferences { + return applicationContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) + } + @Provides @PerApplication - fun provideSharedPreferencesDataSource(@AndroidContext.ApplicationContext applicationContext: Context, + fun provideSharedPreferencesDataSource(sharedPreferences: SharedPreferences, sharedPrefTransportMapper: SharedPrefTransportMapper): FrameworkLocalStorage { - return FrameworkLocalStorageImpl(applicationContext, sharedPrefTransportMapper) + return FrameworkLocalStorageImpl(sharedPreferences, sharedPrefTransportMapper) } // @Provides diff --git a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt index 4092b83..1d2053b 100644 --- a/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt +++ b/transport-eta-android/ui-mobile/src/main/java/com/joaquimley/transporteta/ui/di/module/MapperModule.kt @@ -2,12 +2,18 @@ package com.joaquimley.transporteta.ui.di.module import com.joaquimley.transporteta.data.mapper.DataTransportMapper import com.joaquimley.transporteta.presentation.mapper.PresentationTransportMapper +import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper import dagger.Module import dagger.Provides @Module class MapperModule { + @Provides + fun sharedPrefsTransportMapper(): SharedPrefTransportMapper { + return SharedPrefTransportMapper() + } + @Provides fun presentationTransportMapper(): PresentationTransportMapper { return PresentationTransportMapper() From 7b6fbf183c11015fbd0b014ae05b3597df359281 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Wed, 17 Oct 2018 20:08:00 +0200 Subject: [PATCH 16/18] SharedPrefMapper tests - Created necessary factory/mock data classes for the SharedPref module Named the mock classes with the SharedPref prefix for #66 #17 #69 --- .../mapper/SharedPrefTransportMapper.kt | 5 - .../factory/SharedPrefDataFactory.kt | 26 +++ .../factory/SharedPrefTransportFactory.kt | 47 ++++++ .../mapper/SharedPrefTransportMapperTest.kt | 152 +++++++++++------- 4 files changed, 169 insertions(+), 61 deletions(-) create mode 100644 transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefDataFactory.kt create mode 100644 transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt index 357a8b2..7214ba8 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapper.kt @@ -15,23 +15,18 @@ class SharedPrefTransportMapper { } fun toSharedPref(from: List): List { - // TODO return from.map { toSharedPref(it) } } fun toSharedPref(from: TransportEntity): SharedPrefTransport { - -// TODO return SharedPrefTransport(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type, 1312, "") } fun toEntity(from: List): List { - // TODO return from.map { toEntity(it) } } fun toEntity(from: SharedPrefTransport): TransportEntity { - // TODO return TransportEntity(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type) } } \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefDataFactory.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefDataFactory.kt new file mode 100644 index 0000000..56ff633 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefDataFactory.kt @@ -0,0 +1,26 @@ +package com.joaquimley.transporteta.sharedpreferences.factory + +import java.util.concurrent.ThreadLocalRandom + +/** + * Factory class for data instances + */ +class SharedPrefDataFactory { + + companion object Factory { + + fun randomInt(): Int { + return ThreadLocalRandom.current().nextInt(0, 1000 + 1) + } + + fun randomLong(): Long { + return randomInt().toLong() + } + + fun randomUuid(): String { + return java.util.UUID.randomUUID().toString() + } + + } + +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt new file mode 100644 index 0000000..ace39d2 --- /dev/null +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt @@ -0,0 +1,47 @@ +package com.joaquimley.transporteta.sharedpreferences.factory + +import com.joaquimley.transporteta.sharedpreferences.factory.SharedPrefDataFactory.Factory.randomInt +import com.joaquimley.transporteta.sharedpreferences.factory.SharedPrefDataFactory.Factory.randomLong +import com.joaquimley.transporteta.sharedpreferences.factory.SharedPrefDataFactory.Factory.randomUuid +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.sharedpreferences.FrameworkLocalStorageImpl +import com.joaquimley.transporteta.sharedpreferences.model.SharedPrefTransport + +/** + * Factory class for [SharedPrefTransport] related instances + */ +class SharedPrefTransportFactory { + + companion object Factory { + + fun makeSharedPrefTransportList(count: Int, isFavorite: Boolean = false, type: String = randomUuid()): List { + val transports = mutableListOf() + repeat(count) { + transports.add(makeSharedPrefTransport(isFavorite, type)) + } + return transports + } + + fun makeSharedPrefTransport(isFavorite: Boolean = false, type: String = "bus", code: Int = randomInt(), id: String = randomUuid(), slot: FrameworkLocalStorageImpl.Slot = FrameworkLocalStorageImpl.Slot.ONE): SharedPrefTransport { + return SharedPrefTransport(id, randomUuid(), code, randomUuid(), isFavorite, type, randomLong(), slot.name) + } + + fun makeSharedPrefTransportString(id: String = randomUuid(), transportName: String = randomUuid(), code: Int, latestEta: String, isFavorite: Boolean, type: String = "bus", lastUpdated: Long, slot: String = "ONE"): String { + return "{\"id\":\"$id\",\"name\":\"$transportName\",\"code\":$code,\"latestEta\":\"$latestEta\",\"isFavorite\":$isFavorite,\"type\":\"$type\",\"lastUpdated\":$lastUpdated,\"slot\":\"$slot\"}" + } + + fun makeTransportEntityList(count: Int, isFavorite: Boolean = false, type: String = randomUuid()): List { + val transports = mutableListOf() + repeat(count) { + transports.add(makeTransportEntity(isFavorite, type)) + } + return transports + } + + fun makeTransportEntity(isFavorite: Boolean = false, type: String = randomUuid(), code: Int = randomInt(), id: String = randomUuid()): TransportEntity { + return TransportEntity(id, randomUuid(), code, randomUuid(), isFavorite, type) + } + + } + +} \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt index ab5fb76..e7c403e 100644 --- a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/mapper/SharedPrefTransportMapperTest.kt @@ -1,9 +1,12 @@ package com.joaquimley.transporteta.sharedpreferences.mapper +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.sharedpreferences.factory.SharedPrefTransportFactory +import com.joaquimley.transporteta.sharedpreferences.model.SharedPrefTransport import org.junit.Before +import org.junit.Test -// TODO Nothing has been tested or implemented ¯\_(ツ)_/¯¯ class SharedPrefTransportMapperTest { private val robot = Robot() @@ -14,62 +17,99 @@ class SharedPrefTransportMapperTest { mapper = SharedPrefTransportMapper() } -// @Test -// fun fromModelToView() { -// // Assemble -// val stubbed = TransportFactory.makeTransport() -// // Act -// val mapped = mapper.toEntity(stubbed) -// // Assert -// assert(robot.areItemsTheSame(stubbed, mapped)) -// } -// -// @Test -// fun fromModelListToViewList() { -// // Assemble -// val stubbed = TransportFactory.makeTransportList(5) -// // Act -// val mapped = mapper.toEntity(stubbed) -// // Assert -// assert(robot.areItemsInListTheSame(stubbed, mapped)) -// } -// -// @Test -// fun fromViewToModel() { -// // Assemble -// val stubbed = TransportFactory.makeTransportEntity() -// // Act -// val mapped = mapper.toModel(stubbed) -// // Assert -// assert(robot.areItemsTheSame(mapped, stubbed)) -// } -// -// @Test -// fun fromViewListToModelList() { -// // Assemble -// val stubbed = TransportFactory.makeTransportEntityList(5) -// // Act -// val mapped = mapper.toModel(stubbed) -// // Assert -// assert(robot.areItemsInListTheSame(mapped, stubbed)) -// } + @Test + fun fromCacheStringToModel() { + // Assemble + val stubbedSharedPrefTransport = SharedPrefTransportFactory.makeSharedPrefTransport() + val stringCounterPart = SharedPrefTransportFactory.makeSharedPrefTransportString(stubbedSharedPrefTransport.id, stubbedSharedPrefTransport.name, + stubbedSharedPrefTransport.code, stubbedSharedPrefTransport.latestEta, stubbedSharedPrefTransport.isFavorite, + stubbedSharedPrefTransport.type, stubbedSharedPrefTransport.lastUpdated, stubbedSharedPrefTransport.slot) + // Act + val modelMappedFromString = mapper.fromCacheString(stringCounterPart) + + // Assert + assert(robot.areItemsTheSame(modelMappedFromString, stubbedSharedPrefTransport)) + } + + @Test + fun fromModelToCacheString() { + // Assemble + val stubbedSharedPrefTransport = SharedPrefTransportFactory.makeSharedPrefTransport() + val stringCounterPart = SharedPrefTransportFactory.makeSharedPrefTransportString(stubbedSharedPrefTransport.id, stubbedSharedPrefTransport.name, + stubbedSharedPrefTransport.code, stubbedSharedPrefTransport.latestEta, stubbedSharedPrefTransport.isFavorite, + stubbedSharedPrefTransport.type, stubbedSharedPrefTransport.lastUpdated, stubbedSharedPrefTransport.slot) + // Act + val mappedString = mapper.toCacheString(stubbedSharedPrefTransport) + + // Assert + assert(robot.areItemsTheSame(mappedString, stringCounterPart)) + } + + @Test + fun fromEntityToModel() { + // Assemble + val stubbed = SharedPrefTransportFactory.makeTransportEntity() + // Act + val mapped = mapper.toSharedPref(stubbed) + // Assert + assert(robot.areItemsTheSame(mapped, stubbed)) + } + + @Test + fun fromEntityListToModelList() { + // Assemble + val stubbed = SharedPrefTransportFactory.makeTransportEntityList(5) + // Act + val mapped = mapper.toSharedPref(stubbed) + // Assert + assert(robot.areItemsTheSame(mapped, stubbed)) + } + + @Test + fun fromModelToEntity() { + // Assemble + val stubbed = SharedPrefTransportFactory.makeSharedPrefTransport() + // Act + val mapped = mapper.toEntity(stubbed) + // Assert + assert(robot.areItemsTheSame(stubbed, mapped)) + } + + @Test + fun fromModelListToEntityList() { + // Assemble + val stubbed = SharedPrefTransportFactory.makeSharedPrefTransportList(5) + // Act + val mapped = mapper.toEntity(stubbed) + // Assert + assert(robot.areItemsTheSame(stubbed, mapped)) + } inner class Robot { -// fun areItemsInListTheSame(transportList: List, transportViewList: List): Boolean { -// for (transport in transportList.withIndex()) { -// if (!areItemsTheSame(transportList[transport.index], transportViewList[transport.index])) { -// return false -// } -// } -// return true -// } -// -// fun areItemsTheSame(transport: Transport, transportView: TransportEntity): Boolean { -// return transport.id == transportView.id && -// transport.code == transportView.code && -// transport.latestEta == transportView.latestEta && -// transport.isFavorite == transportView.isFavorite && -// transport.type.equals(transportView.type) -// } + + fun areItemsTheSame(sharedPrefTransportStringLeft: String, sharedPrefTransportStringRight: String): Boolean { + return sharedPrefTransportStringLeft == sharedPrefTransportStringRight + } + + fun areItemsTheSame(sharedPrefTransportLeft: SharedPrefTransport, sharedPrefTransportRight: SharedPrefTransport): Boolean { + return sharedPrefTransportLeft == sharedPrefTransportRight + } + + fun areItemsTheSame(sharedPrefTransport: SharedPrefTransport, transportEntity: TransportEntity): Boolean { + return sharedPrefTransport.id == transportEntity.id && + sharedPrefTransport.code == transportEntity.code && + sharedPrefTransport.latestEta == transportEntity.latestEta && + transportEntity.isFavorite == transportEntity.isFavorite && + sharedPrefTransport.type == transportEntity.type + } + + fun areItemsTheSame(sharedPrefTransportList: List, transportEntity: List): Boolean { + for (transport in sharedPrefTransportList.withIndex()) { + if (!areItemsTheSame(sharedPrefTransportList[transport.index], transportEntity[transport.index])) { + return false + } + } + return true + } } } From c2a90fe04e7b42830b6b2456266d6decd29be527 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Wed, 17 Oct 2018 21:46:42 +0200 Subject: [PATCH 17/18] Initial tests for FrameworkLocalStorageImpl Lacking SharedPreferences test setup - Will probably need to move all the Android test libs to androidx variant. #17 #69 --- .../data-sharedpreferences/build.gradle | 8 ++ .../FrameworkLocalStorageImpl.kt | 19 +-- .../FrameworkLocalStorageTest.kt | 128 ++++++++++++++++-- .../factory/SharedPrefTransportFactory.kt | 2 +- transport-eta-android/versions.gradle | 6 +- 5 files changed, 137 insertions(+), 26 deletions(-) diff --git a/transport-eta-android/data-sharedpreferences/build.gradle b/transport-eta-android/data-sharedpreferences/build.gradle index 82ad0a5..1314aba 100644 --- a/transport-eta-android/data-sharedpreferences/build.gradle +++ b/transport-eta-android/data-sharedpreferences/build.gradle @@ -12,6 +12,12 @@ android { testInstrumentationRunner "com.joaquimley.transporteta.ui.test.TestRunner" } + testOptions { + unitTests { + includeAndroidResources = true + } + } + packagingOptions { exclude 'LICENSE.txt' exclude 'META-INF/DEPENDENCIES' @@ -104,6 +110,8 @@ dependencies { testImplementation deps.mockito.kotlin testImplementation deps.mockito.inline testImplementation deps.lifecycle.testing + testImplementation deps.robolectric + // Resolve conflicts between main and local unit tests testImplementation deps.androidx.annotation } \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt index e98f199..81eae37 100644 --- a/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt +++ b/transport-eta-android/data-sharedpreferences/src/main/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageImpl.kt @@ -18,8 +18,8 @@ class FrameworkLocalStorageImpl @Inject constructor(private val sharedPreference private val sharedPreferencesObservable: PublishSubject> = PublishSubject.create() init { - observeSharedPreferencesChanges() loadAll() + observeSharedPreferencesChanges() } override fun saveTransport(transportEntity: TransportEntity): Completable { @@ -46,7 +46,9 @@ class FrameworkLocalStorageImpl @Inject constructor(private val sharedPreference } override fun clearAll(): Completable { - return Completable.complete() + return Completable.fromAction { + + } } private fun observeSharedPreferencesChanges() { @@ -66,7 +68,9 @@ class FrameworkLocalStorageImpl @Inject constructor(private val sharedPreference } private fun saveToSharedPrefs(sharedPrefTransport: SharedPrefTransport) { - // TODO + sharedPreferences.edit() + .putString(Slot.ONE.name, mapper.toCacheString(sharedPrefTransport)) + .apply() } private fun getFromSharedPrefs(slot: Slot): SharedPrefTransport? { @@ -84,13 +88,4 @@ class FrameworkLocalStorageImpl @Inject constructor(private val sharedPreference TWO("transport_eta_fav_2"), THREE("transport_eta_fav_3"), } - - // TODO - Still not sure this is needed - /** - * Store and retrieve the last time data was cached - */ -//var lastUpdated: Long -// getFromSharedPrefs() = sharedPreferences.getLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, 0) -// set(lastUpdated) = sharedPreferences.edit().putLong(FrameworkLocalStorageImpl.SHARED_PREFERENCES_LAST_UPDATED, lastUpdated).apply() } - diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt index 49e6e15..7839ac2 100644 --- a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/FrameworkLocalStorageTest.kt @@ -1,25 +1,40 @@ package com.joaquimley.transporteta.sharedpreferences +import android.content.SharedPreferences +import com.joaquimley.transporteta.data.model.TransportEntity +import com.joaquimley.transporteta.data.source.FrameworkLocalStorage +import com.joaquimley.transporteta.sharedpreferences.factory.SharedPrefDataFactory +import com.joaquimley.transporteta.sharedpreferences.factory.SharedPrefTransportFactory import com.joaquimley.transporteta.sharedpreferences.mapper.SharedPrefTransportMapper -import com.nhaarman.mockitokotlin2.mock +import com.joaquimley.transporteta.sharedpreferences.model.SharedPrefTransport +import com.nhaarman.mockitokotlin2.* import org.junit.After -import org.junit.Test - import org.junit.Before +import org.junit.Ignore +import org.junit.Test -// Roboeletric +//@RunWith(RobolectricTestRunner::class) class FrameworkLocalStorageTest { + + private val SHARED_PREFERENCES_NAME = "com.joaquimley.transporteta.sharedpreferences" + private val robot = Robot() - // private val mockApplicationContext = mock() +// private val robolectricSharedPreferences = RuntimeEnvironment.application.applicationContext +// .getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) + + private val mockSharedPreferences = mock() private val mockMapper = mock() + private lateinit var frameworkLocalStorage: FrameworkLocalStorage + @Before fun setup() { - + frameworkLocalStorage = FrameworkLocalStorageImpl(mockSharedPreferences, mockMapper) +// frameworkLocalStorage = FrameworkLocalStorageImpl(robolectricSharedPreferences, mockMapper) } @After @@ -28,15 +43,106 @@ class FrameworkLocalStorageTest { } @Test - fun assertThisBoi() { - val sum = 4 + 4 - val result = 8 - assert(sum == result) + fun allDataIsFetchedAtStartup() { + // Assemble + val modelStringOne = robot.stubSharedPrefGetFromSlotSuccess(slot = FrameworkLocalStorageImpl.Slot.ONE) + val modelStringTwo = robot.stubSharedPrefGetFromSlotSuccess(slot = FrameworkLocalStorageImpl.Slot.TWO) + val modelStringThree = robot.stubSharedPrefGetFromSlotSuccess(slot = FrameworkLocalStorageImpl.Slot.THREE) + + robot.stubMapperFromStringToModel(modelStringOne) + robot.stubMapperFromStringToModel(modelStringTwo) + robot.stubMapperFromStringToModel(modelStringThree) + + // Act + // Nothing <-> + // Assert + verify(mockSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.ONE.name, null) + verify(mockSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.TWO.name, null) + verify(mockSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.THREE.name, null) + + +// val modelStringOne = SharedPrefTransportFactory.makeSharedPrefTransportString() +// val modelStringTwo = SharedPrefTransportFactory.makeSharedPrefTransportString() +// val modelStringThree = SharedPrefTransportFactory.makeSharedPrefTransportString() + +// robot.stubMapperFromStringToModel(modelStringOne) +// robot.stubMapperFromStringToModel(modelStringTwo) +// robot.stubMapperFromStringToModel(modelStringThree) + // Act + // Nothing <-> + // Assert +// verify(robolectricSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.ONE.name, null) +// verify(robolectricSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.TWO.name, null) +// verify(robolectricSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.THREE.name, null) + } + + @Test + fun sharedPreferencesChangesAreObservedAtStartup() { + // Assemble + // Nothing <-> + + // Act + // Nothing <-> + + // Assert +// verify(robolectricSharedPreferences, times(1)).registerOnSharedPreferenceChangeListener(any()) + verify(mockSharedPreferences, times(1)).registerOnSharedPreferenceChangeListener(any()) + } + + @Test + @Ignore("Lacking SharedPreferences mocking/roboeletric") + fun saveTransportCompletes() { + // Assemble + val stubEntity = SharedPrefTransportFactory.makeTransportEntity() + // Act + val testObserver = frameworkLocalStorage.saveTransport(stubEntity).test() + // Assert + testObserver.assertComplete() + } + + @Test + @Ignore("Lacking SharedPreferences mocking/roboeletric") + fun saveTransportCallsCorrectMethodOnSharedPrefs() { + // Assemble + val stubEntity = SharedPrefTransportFactory.makeTransportEntity() + val stubModel = robot.stubMapperFromEntityToModel(stubEntity) + val stubbedString = robot.stubMapperFromModelToString(stubModel) + robot.stubSharedPrefGetFromSlotSuccess(stubbedString, FrameworkLocalStorageImpl.Slot.ONE) + // Act + frameworkLocalStorage.saveTransport(stubEntity) + // Assert +// verify(robolectricSharedPreferences, times(1)).edit().putString(any(), stubbedString).apply() + verify(mockSharedPreferences, times(1)).edit().putString(any(), stubbedString).apply() } inner class Robot { - // TODO + + + fun stubSharedPrefSaveToSlotSuccess(sharedPrefTransportString: String = SharedPrefTransportFactory.makeSharedPrefTransportString(), slot: FrameworkLocalStorageImpl.Slot): String { + whenever(mockSharedPreferences.edit().putString(slot.name, sharedPrefTransportString)).then { sharedPrefTransportString } + return sharedPrefTransportString + } + + fun stubSharedPrefGetFromSlotSuccess(sharedPrefTransportString: String = SharedPrefTransportFactory.makeSharedPrefTransportString(), slot: FrameworkLocalStorageImpl.Slot): String { + whenever(mockSharedPreferences.getString(slot.name, null)).then { sharedPrefTransportString } + return sharedPrefTransportString + } + + fun stubMapperFromModelToString(sharedPrefTransport: SharedPrefTransport = SharedPrefTransportFactory.makeSharedPrefTransport(), sharedPrefTransportString: String = SharedPrefDataFactory.randomUuid()): String { + whenever(mockMapper.toCacheString(sharedPrefTransport)).then { sharedPrefTransportString } + return sharedPrefTransportString + } + + fun stubMapperFromStringToModel(sharedPrefTransportString: String, sharedPrefTransport: SharedPrefTransport = SharedPrefTransportFactory.makeSharedPrefTransport()): SharedPrefTransport { + whenever(mockMapper.fromCacheString(sharedPrefTransportString)).then { sharedPrefTransport } + return sharedPrefTransport + } + + fun stubMapperFromEntityToModel(transportEntity: TransportEntity = SharedPrefTransportFactory.makeTransportEntity(), sharedPrefTransport: SharedPrefTransport = SharedPrefTransportFactory.makeSharedPrefTransport()): SharedPrefTransport { + whenever(mockMapper.toSharedPref(transportEntity)).then { sharedPrefTransport } + return sharedPrefTransport + } } } \ No newline at end of file diff --git a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt index ace39d2..9a26bf1 100644 --- a/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt +++ b/transport-eta-android/data-sharedpreferences/src/test/java/com/joaquimley/transporteta/sharedpreferences/factory/SharedPrefTransportFactory.kt @@ -26,7 +26,7 @@ class SharedPrefTransportFactory { return SharedPrefTransport(id, randomUuid(), code, randomUuid(), isFavorite, type, randomLong(), slot.name) } - fun makeSharedPrefTransportString(id: String = randomUuid(), transportName: String = randomUuid(), code: Int, latestEta: String, isFavorite: Boolean, type: String = "bus", lastUpdated: Long, slot: String = "ONE"): String { + fun makeSharedPrefTransportString(id: String = randomUuid(), transportName: String = randomUuid(), code: Int = randomInt(), latestEta: String = randomUuid(), isFavorite: Boolean = true, type: String = "bus", lastUpdated: Long = randomLong(), slot: String = "ONE"): String { return "{\"id\":\"$id\",\"name\":\"$transportName\",\"code\":$code,\"latestEta\":\"$latestEta\",\"isFavorite\":$isFavorite,\"type\":\"$type\",\"lastUpdated\":$lastUpdated,\"slot\":\"$slot\"}" } diff --git a/transport-eta-android/versions.gradle b/transport-eta-android/versions.gradle index fa8edf7..2080c72 100644 --- a/transport-eta-android/versions.gradle +++ b/transport-eta-android/versions.gradle @@ -61,7 +61,7 @@ versions.mockito = "2.19.1" versions.mockito_kotlin = "2.0.0-RC1" versions.atsl_rules = "1.0.1" versions.atsl_runner = "1.0.2" -versions.robolectric = "3.4.2" +versions.robolectric = "3.8" // "4.0-beta-2-SNAPSHOT" // "3.8" versions.dexmaker_linkedin = "2.19.0" versions.dexmaker_linkedin_inline = "2.19.0" @@ -149,6 +149,8 @@ atsl.rules = "com.android.support.test:rules:$versions.atsl_runner" atsl.orchestrator = "com.android.support.test:orchestrator:$versions.atsl_runner" deps.atsl = atsl +deps.robolectric = "org.robolectric:robolectric:$versions.robolectric" + def mockito = [:] mockito.core = "org.mockito:mockito-core:$versions.mockito" mockito.inline = "org.mockito:mockito-inline:$versions.mockito" @@ -178,7 +180,6 @@ dexmaker.linkedin = "com.linkedin.dexmaker:dexmaker-mockito:$versions.dexmaker_l dexmaker.linkedin_inline = "com.linkedin.dexmaker:dexmaker-mockito-inline:$versions.dexmaker_linkedin_inline" deps.dexmaker = dexmaker -deps.robolectric = "org.robolectric:robolectric:$versions.robolectric" deps.assertj = "org.assertj:assertj-core:$versions.assertj" deps.glide = "com.github.bumptech.glide:glide:$versions.glide" deps.constraint_layout = "com.android.support.constraint:constraint-layout:$versions.constraint_layout" @@ -207,5 +208,6 @@ static def addRepos(RepositoryHandler handler) { handler.google() handler.jcenter() handler.maven { url "https://kotlin.bintray.com/kotlinx" } + handler.maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } ext.addRepos = this.&addRepos \ No newline at end of file From 002bcc06795620f9e42dcfa24628f1bddcae47f0 Mon Sep 17 00:00:00 2001 From: Joaquim Ley Date: Wed, 17 Oct 2018 21:48:53 +0200 Subject: [PATCH 18/18] Include stream episode PR to README --- README.MD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.MD b/README.MD index b10385e..7325503 100644 --- a/README.MD +++ b/README.MD @@ -64,6 +64,8 @@ Since I'm always working on some side-projects, I decided to document the progre - Ep.16: https://github.com/JoaquimLey/transport-eta/pull/74 +- Ep.17: https://github.com/JoaquimLey/transport-eta/pull/81 + ## About the author Hi, my name is **Joaquim Ley**, I'm a Software Engineer (Android).