From 4c257910a6603dce454238c97337274476a1bdbb Mon Sep 17 00:00:00 2001 From: Guillaume M Date: Fri, 28 Jun 2019 15:27:24 +0100 Subject: [PATCH] improve naming to follow kotlin convensions --- .../freshdroid/mymonzo/MyMonzoApplication.kt | 6 +- .../splashscreen/network/ApiSplashScreen.kt | 6 +- .../viewmodels/SplashScreenViewModel.kt | 25 ++++--- .../views/SplashScreenActivity.kt | 18 ++--- .../mymonzo/MyMonzoApplicationTest.kt | 2 - .../mymonzo/MyMonzoRobolectricTestCase.kt | 10 +-- .../core/extensions/BaseActivityExtension.kt | 2 +- .../core/extensions/BaseFragmentExtension.kt | 2 +- .../mymonzo/core/network/ApiCore.kt | 4 +- .../mymonzo/core/network/ApiEndpoint.kt | 3 +- .../mymonzo/core/network/ErrorEnvelope.kt | 4 +- .../mymonzo/core/network/HttpVerb.kt | 4 +- .../core/network/exceptions/ApiException.kt | 4 +- .../network/exceptions/ResponseException.kt | 4 +- .../ApiMonzoRequestInterceptor.kt | 8 +-- .../core/preferences/BooleanPreference.kt | 14 ++-- .../mymonzo/core/preferences/IntPreference.kt | 14 ++-- .../core/preferences/LongPreference.kt | 14 ++-- .../core/preferences/StringPreference.kt | 14 ++-- .../io/freshdroid/mymonzo/core/rx/RxBus.kt | 6 +- .../core/rx/operators/ApiErrorOperator.kt | 6 +- .../CombineLatestPairTransformer.kt | 4 +- .../transformers/NeverApiErrorTransformer.kt | 6 +- .../rx/transformers/NeverErrorTransformer.kt | 4 +- .../rx/transformers/TakeWhenTransformer.kt | 4 +- .../core/rx/transformers/Transformers.kt | 2 +- .../mymonzo/core/ui/BaseActivity.kt | 6 +- .../mymonzo/core/ui/BaseArrayAdapter.kt | 28 ++++---- .../mymonzo/core/ui/BaseViewHolder.kt | 8 +-- .../mymonzo/core/ui/RecyclerViewPaginator.kt | 20 +++--- .../mymonzo/core/user/CurrentUser.kt | 34 ++++----- .../core/viewmodel/ActivityViewModel.kt | 12 ++-- .../core/viewmodel/FragmentViewModel.kt | 12 ++-- .../mymonzo/home/viewmodels/HomeViewModel.kt | 48 ++++++------- .../home/views/BottomNavigationItemView.kt | 12 ++-- .../home/views/BottomNavigationView.kt | 72 +++++++++---------- .../mymonzo/home/views/HomeActivity.kt | 24 +++---- .../home/MyMonzoRobolectricTestCase.kt | 10 +-- 38 files changed, 239 insertions(+), 237 deletions(-) diff --git a/app/src/main/java/io/freshdroid/mymonzo/MyMonzoApplication.kt b/app/src/main/java/io/freshdroid/mymonzo/MyMonzoApplication.kt index a774dc0..282fa86 100644 --- a/app/src/main/java/io/freshdroid/mymonzo/MyMonzoApplication.kt +++ b/app/src/main/java/io/freshdroid/mymonzo/MyMonzoApplication.kt @@ -16,7 +16,7 @@ import timber.log.Timber open class MyMonzoApplication : MultiDexApplication(), LifecycleObserver { - private val coreComponent: CoreComponent by lazy { + private val _coreComponent: CoreComponent by lazy { DaggerCoreComponent.builder() .coreModule(CoreModule(this)) .build() @@ -26,10 +26,10 @@ open class MyMonzoApplication : MultiDexApplication(), LifecycleObserver { companion object { @JvmStatic - fun coreComponent(context: Context) = (context.applicationContext as MyMonzoApplication).coreComponent + fun coreComponent(context: Context) = (context.applicationContext as MyMonzoApplication)._coreComponent } - fun coreComponent(): CoreComponent = coreComponent + fun coreComponent(): CoreComponent = _coreComponent protected open fun isInUnitTests(): Boolean { return false diff --git a/app/src/main/java/io/freshdroid/mymonzo/splashscreen/network/ApiSplashScreen.kt b/app/src/main/java/io/freshdroid/mymonzo/splashscreen/network/ApiSplashScreen.kt index eb239ca..7bd7cbd 100644 --- a/app/src/main/java/io/freshdroid/mymonzo/splashscreen/network/ApiSplashScreen.kt +++ b/app/src/main/java/io/freshdroid/mymonzo/splashscreen/network/ApiSplashScreen.kt @@ -6,6 +6,6 @@ import io.freshdroid.mymonzo.core.network.HttpTransitionFactoryType import javax.inject.Inject class ApiSplashScreen @Inject constructor( - private val httpTransitionFactory: HttpTransitionFactoryType, - private val moshi: Moshi -) : ApiCore(moshi), ApiSplashScreenType \ No newline at end of file + private val _httpTransitionFactory: HttpTransitionFactoryType, + private val _moshi: Moshi +) : ApiCore(_moshi), ApiSplashScreenType \ No newline at end of file diff --git a/app/src/main/java/io/freshdroid/mymonzo/splashscreen/viewmodels/SplashScreenViewModel.kt b/app/src/main/java/io/freshdroid/mymonzo/splashscreen/viewmodels/SplashScreenViewModel.kt index 6c4d761..d693d6a 100644 --- a/app/src/main/java/io/freshdroid/mymonzo/splashscreen/viewmodels/SplashScreenViewModel.kt +++ b/app/src/main/java/io/freshdroid/mymonzo/splashscreen/viewmodels/SplashScreenViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider import com.uber.autodispose.autoDisposable +import io.freshdroid.mymonzo.core.BuildConfig import io.freshdroid.mymonzo.core.rx.Irrelevant import io.freshdroid.mymonzo.core.viewmodel.ActivityViewModel import io.freshdroid.mymonzo.navigation.ApplicationMap @@ -22,20 +23,22 @@ class SplashScreenViewModel( scopeProvider: AndroidLifecycleScopeProvider ) : ActivityViewModel(), SplashScreenViewModelInputs, SplashScreenViewModelOutputs, SplashScreenViewModelErrors { - private val mFakeLoading = PublishSubject.create() - private val mLaunchNextActivity = PublishSubject.create() + private val _fakeLoading = PublishSubject.create() + private val _launchNextActivity = PublishSubject.create() - private val mScheduler = environment.scheduler + private val _currentUser = environment.currentUser + private val _scheduler = environment.scheduler val inputs: SplashScreenViewModelInputs = this val outputs: SplashScreenViewModelOutputs = this val errors: SplashScreenViewModelErrors = this init { - mFakeLoading - .delay(1000, TimeUnit.MILLISECONDS, mScheduler) + _fakeLoading + .doOnNext { _currentUser.setAccessToken(BuildConfig.USER_TOKEN) } + .delay(1000, TimeUnit.MILLISECONDS, _scheduler) .autoDisposable(scopeProvider) - .subscribe { mLaunchNextActivity.onNext(Uri.parse(ApplicationMap.Home.FEED)) } + .subscribe { _launchNextActivity.onNext(Uri.parse(ApplicationMap.Home.FEED)) } } override fun onCleared() { @@ -46,20 +49,20 @@ class SplashScreenViewModel( // INPUTS override fun fakeLoading() { - mFakeLoading.onNext(Irrelevant.INSTANCE) + _fakeLoading.onNext(Irrelevant.INSTANCE) } // OUTPUTS - override fun launchNextActivity(): Observable = mLaunchNextActivity + override fun launchNextActivity(): Observable = _launchNextActivity @Suppress("UNCHECKED_CAST") class Factory( - private val environment: SplashScreenEnvironment, - private val scopeProvider: AndroidLifecycleScopeProvider + private val _environment: SplashScreenEnvironment, + private val _scopeProvider: AndroidLifecycleScopeProvider ) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { - return SplashScreenViewModel(environment, scopeProvider) as T + return SplashScreenViewModel(_environment, _scopeProvider) as T } } diff --git a/app/src/main/java/io/freshdroid/mymonzo/splashscreen/views/SplashScreenActivity.kt b/app/src/main/java/io/freshdroid/mymonzo/splashscreen/views/SplashScreenActivity.kt index 73ae789..fa56945 100644 --- a/app/src/main/java/io/freshdroid/mymonzo/splashscreen/views/SplashScreenActivity.kt +++ b/app/src/main/java/io/freshdroid/mymonzo/splashscreen/views/SplashScreenActivity.kt @@ -3,11 +3,11 @@ package io.freshdroid.mymonzo.splashscreen.views import android.os.Bundle import androidx.lifecycle.ViewModelProviders import com.uber.autodispose.autoDisposable +import io.freshdroid.mymonzo.R import io.freshdroid.mymonzo.core.extensions.launchIntent import io.freshdroid.mymonzo.core.rx.transformers.Transformers.observeForUI import io.freshdroid.mymonzo.core.ui.BaseActivity import io.freshdroid.mymonzo.core.ui.TransitionUtils.fadeIn -import io.freshdroid.mymonzo.R import io.freshdroid.mymonzo.coreComponent import io.freshdroid.mymonzo.navigation.UriResolver import io.freshdroid.mymonzo.splashscreen.di.SplashScreenComponentManager @@ -15,28 +15,28 @@ import io.freshdroid.mymonzo.splashscreen.viewmodels.SplashScreenViewModel class SplashScreenActivity : BaseActivity() { - private val component by lazy { + private val _component by lazy { SplashScreenComponentManager.splashScreenComponent(coreComponent()) } - private val viewModelFactory by lazy { - SplashScreenViewModel.Factory(component.environment(), scopeProvider) + private val _viewModelFactory by lazy { + SplashScreenViewModel.Factory(_component.environment(), scopeProvider) } - private val viewModel by lazy { - ViewModelProviders.of(this, viewModelFactory).get(SplashScreenViewModel::class.java) + private val _viewModel by lazy { + ViewModelProviders.of(this, _viewModelFactory).get(SplashScreenViewModel::class.java) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash_screen) - viewModel.outputs.launchNextActivity() + _viewModel.outputs.launchNextActivity() .compose(observeForUI()) .map(UriResolver::resolve) .autoDisposable(scopeProvider) .subscribe { this.launchIntent(it, fadeIn()) } - viewModel.intent(intent) - viewModel.inputs.fakeLoading() + _viewModel.intent(intent) + _viewModel.inputs.fakeLoading() } } \ No newline at end of file diff --git a/app/src/test/java/io/freshdroid/mymonzo/MyMonzoApplicationTest.kt b/app/src/test/java/io/freshdroid/mymonzo/MyMonzoApplicationTest.kt index 3e459e5..9e65838 100644 --- a/app/src/test/java/io/freshdroid/mymonzo/MyMonzoApplicationTest.kt +++ b/app/src/test/java/io/freshdroid/mymonzo/MyMonzoApplicationTest.kt @@ -1,7 +1,5 @@ package io.freshdroid.mymonzo -import io.freshdroid.mymonzo.MyMonzoApplication - internal class MyMonzoApplicationTest : MyMonzoApplication() { override fun isInUnitTests(): Boolean = true diff --git a/app/src/test/java/io/freshdroid/mymonzo/MyMonzoRobolectricTestCase.kt b/app/src/test/java/io/freshdroid/mymonzo/MyMonzoRobolectricTestCase.kt index 28d7a74..fadaa4c 100644 --- a/app/src/test/java/io/freshdroid/mymonzo/MyMonzoRobolectricTestCase.kt +++ b/app/src/test/java/io/freshdroid/mymonzo/MyMonzoRobolectricTestCase.kt @@ -14,15 +14,15 @@ import org.robolectric.annotation.Config @Config(application = MyMonzoApplicationTest::class) internal abstract class MyMonzoRobolectricTestCase : TestCase() { - private var mApplication: MyMonzoApplicationTest? = null + private var _application: MyMonzoApplicationTest? = null protected fun application(): MyMonzoApplicationTest { - if (mApplication != null) { - return mApplication as MyMonzoApplicationTest + if (_application != null) { + return _application as MyMonzoApplicationTest } - mApplication = ApplicationProvider.getApplicationContext() as MyMonzoApplicationTest - return mApplication as MyMonzoApplicationTest + _application = ApplicationProvider.getApplicationContext() as MyMonzoApplicationTest + return _application as MyMonzoApplicationTest } protected fun context(): Context { diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseActivityExtension.kt b/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseActivityExtension.kt index 3b4cbdc..2b3700c 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseActivityExtension.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseActivityExtension.kt @@ -13,7 +13,7 @@ import io.freshdroid.mymonzo.core.ui.TransitionUtils.slideInRight import io.freshdroid.mymonzo.core.ui.TransitionUtils.transition fun BaseActivity.showToastApiError(errorEnvelope: ErrorEnvelope, length: Int = Toast.LENGTH_LONG) { - errorEnvelope.error?.let { Toast.makeText(this, it, length).show() } + errorEnvelope.message?.let { Toast.makeText(this, it, length).show() } } fun BaseActivity.showToastError(@StringRes messageResource: Int, length: Int = Toast.LENGTH_LONG) { diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseFragmentExtension.kt b/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseFragmentExtension.kt index 95d351c..8470bdc 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseFragmentExtension.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/extensions/BaseFragmentExtension.kt @@ -8,7 +8,7 @@ import io.freshdroid.mymonzo.core.network.ErrorEnvelope import io.freshdroid.mymonzo.core.ui.BaseFragment fun BaseFragment.showToastApiError(errorEnvelope: ErrorEnvelope) { - activity?.let { errorEnvelope.error?.let { Toast.makeText(activity, it, Toast.LENGTH_LONG).show() } } + activity?.let { errorEnvelope.message?.let { Toast.makeText(activity, it, Toast.LENGTH_LONG).show() } } } fun BaseFragment.showToastError(@StringRes messageResource: Int) { diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiCore.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiCore.kt index f6f63e1..e19ddd5 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiCore.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiCore.kt @@ -5,11 +5,11 @@ import io.freshdroid.mymonzo.core.rx.operators.ApiErrorOperator import io.freshdroid.mymonzo.core.rx.operators.Operators open class ApiCore( - private val moshi: Moshi + private val _moshi: Moshi ) { fun apiErrorOperator(): ApiErrorOperator { - return Operators.apiError(moshi) + return Operators.apiError(_moshi) } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiEndpoint.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiEndpoint.kt index 23e40b3..8e29754 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiEndpoint.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/ApiEndpoint.kt @@ -2,7 +2,8 @@ package io.freshdroid.mymonzo.core.network import io.freshdroid.mymonzo.core.BuildConfig -internal enum class ApiEndpoint( + +enum class ApiEndpoint( val url: String ) { MONZO(BuildConfig.BASE_URL) diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/ErrorEnvelope.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/ErrorEnvelope.kt index 9c3d171..f8ebbff 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/ErrorEnvelope.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/ErrorEnvelope.kt @@ -6,8 +6,8 @@ import io.freshdroid.mymonzo.core.network.exceptions.ApiException @JsonClass(generateAdapter = true) data class ErrorEnvelope( - @Json(name = "error") val error: String? = null, - @Json(name = "code") val code: Int = -1 + @Json(name = "message") val message: String? = null, + val responseCode: Int = -1 ) { companion object { fun fromThrowable(t: Throwable): ErrorEnvelope? { diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/HttpVerb.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/HttpVerb.kt index 69c49e9..f36a6c4 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/HttpVerb.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/HttpVerb.kt @@ -1,7 +1,7 @@ package io.freshdroid.mymonzo.core.network enum class HttpVerb( - private val tag: String + private val _tag: String ) { GET("GET"), @@ -12,7 +12,7 @@ enum class HttpVerb( companion object { @JvmStatic - fun protocolFromTag(tag: String): HttpVerb { + fun verbFromTag(tag: String): HttpVerb { return when (tag.toUpperCase()) { "GET" -> GET "POST" -> POST diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ApiException.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ApiException.kt index cc8eddd..71c3d40 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ApiException.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ApiException.kt @@ -4,10 +4,10 @@ import io.freshdroid.mymonzo.core.network.ErrorEnvelope import retrofit2.Response open class ApiException( - private val errorEnvelope: ErrorEnvelope, + private val _errorEnvelope: ErrorEnvelope, response: Response<*> ) : ResponseException(response) { - fun errorEnvelope(): ErrorEnvelope = errorEnvelope + fun errorEnvelope(): ErrorEnvelope = _errorEnvelope } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ResponseException.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ResponseException.kt index 9325c8d..4638a3b 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ResponseException.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/exceptions/ResponseException.kt @@ -3,9 +3,9 @@ package io.freshdroid.mymonzo.core.network.exceptions import retrofit2.Response open class ResponseException( - private val response: Response<*> + private val _response: Response<*> ) : RuntimeException() { - fun response(): Response<*> = response + fun response(): Response<*> = _response } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/network/interceptors/ApiMonzoRequestInterceptor.kt b/core/src/main/java/io/freshdroid/mymonzo/core/network/interceptors/ApiMonzoRequestInterceptor.kt index f185a36..4435eb8 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/network/interceptors/ApiMonzoRequestInterceptor.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/network/interceptors/ApiMonzoRequestInterceptor.kt @@ -11,8 +11,8 @@ import javax.inject.Inject internal const val ANDROID_DEVICE_TYPE_STRING = "android" internal class ApiMonzoRequestInterceptor @Inject constructor( - private val locale: Locale, - private val currentUser: CurrentUserType + private val _locale: Locale, + private val _currentUser: CurrentUserType ) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { @@ -24,9 +24,9 @@ internal class ApiMonzoRequestInterceptor @Inject constructor( .header("User-Agent", ANDROID_DEVICE_TYPE_STRING) .header("X-Agent-Version", BuildConfig.VERSION_CODE.toString()) .header("Accept", "application/json") - .header("Accept-Language", locale.language) + .header("Accept-Language", _locale.language) - requestBuilder = addHeaderIfNotNull(requestBuilder, currentUser.getAccessToken(), "Authorization") + requestBuilder = addHeaderIfNotNull(requestBuilder, "Bearer ${_currentUser.getAccessToken()}", "Authorization") return requestBuilder.build() } diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/BooleanPreference.kt b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/BooleanPreference.kt index 2dc816d..d7dd98b 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/BooleanPreference.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/BooleanPreference.kt @@ -4,25 +4,25 @@ import android.content.SharedPreferences import javax.inject.Inject class BooleanPreference @Inject constructor( - private val sharedPreferences: SharedPreferences, - private val key: String, - private val defaultValue: Boolean = false + private val _sharedPreferences: SharedPreferences, + private val _key: String, + private val _defaultValue: Boolean = false ): BooleanPreferenceType { override fun get(): Boolean { - return sharedPreferences.getBoolean(key, defaultValue) + return _sharedPreferences.getBoolean(_key, _defaultValue) } override fun isSet(): Boolean { - return sharedPreferences.contains(key) + return _sharedPreferences.contains(_key) } override fun set(value: Boolean) { - sharedPreferences.edit().putBoolean(key, value).apply() + _sharedPreferences.edit().putBoolean(_key, value).apply() } override fun delete() { - sharedPreferences.edit().remove(key).apply() + _sharedPreferences.edit().remove(_key).apply() } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/IntPreference.kt b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/IntPreference.kt index 984b36f..86c1e1c 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/IntPreference.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/IntPreference.kt @@ -4,25 +4,25 @@ import android.content.SharedPreferences import javax.inject.Inject class IntPreference @Inject constructor( - private val sharedPreferences: SharedPreferences, - private val key: String, - private val defaultValue: Int = 0 + private val _sharedPreferences: SharedPreferences, + private val _key: String, + private val _defaultValue: Int = 0 ) : IntPreferenceType { override fun get(): Int { - return sharedPreferences.getInt(key, defaultValue) + return _sharedPreferences.getInt(_key, _defaultValue) } override fun isSet(): Boolean { - return sharedPreferences.contains(key) + return _sharedPreferences.contains(_key) } override fun set(value: Int) { - sharedPreferences.edit().putInt(key, value).apply() + _sharedPreferences.edit().putInt(_key, value).apply() } override fun delete() { - sharedPreferences.edit().remove(key).apply() + _sharedPreferences.edit().remove(_key).apply() } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/LongPreference.kt b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/LongPreference.kt index 48cf4c3..6e6d06c 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/LongPreference.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/LongPreference.kt @@ -4,25 +4,25 @@ import android.content.SharedPreferences import javax.inject.Inject class LongPreference @Inject constructor( - private val sharedPreferences: SharedPreferences, - private val key: String, - private val defaultValue: Long = 0 + private val _sharedPreferences: SharedPreferences, + private val _key: String, + private val _defaultValue: Long = 0 ) : LongPreferenceType { override fun get(): Long { - return sharedPreferences.getLong(key, defaultValue) + return _sharedPreferences.getLong(_key, _defaultValue) } override fun isSet(): Boolean { - return sharedPreferences.contains(key) + return _sharedPreferences.contains(_key) } override fun set(value: Long) { - sharedPreferences.edit().putLong(key, value).apply() + _sharedPreferences.edit().putLong(_key, value).apply() } override fun delete() { - sharedPreferences.edit().remove(key).apply() + _sharedPreferences.edit().remove(_key).apply() } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/StringPreference.kt b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/StringPreference.kt index 7dc4e3d..0e4cc39 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/preferences/StringPreference.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/preferences/StringPreference.kt @@ -4,25 +4,25 @@ import android.content.SharedPreferences import javax.inject.Inject class StringPreference @Inject constructor( - private val sharedPreferences: SharedPreferences, - private val key: String, - private val defaultValue: String? = null + private val _sharedPreferences: SharedPreferences, + private val _key: String, + private val _defaultValue: String? = null ) : StringPreferenceType { override fun get(): String? { - return sharedPreferences.getString(key, defaultValue) + return _sharedPreferences.getString(_key, _defaultValue) } override fun isSet(): Boolean { - return sharedPreferences.contains(key) + return _sharedPreferences.contains(_key) } override fun set(value: String) { - sharedPreferences.edit().putString(key, value).apply() + _sharedPreferences.edit().putString(_key, value).apply() } override fun delete() { - sharedPreferences.edit().remove(key).apply() + _sharedPreferences.edit().remove(_key).apply() } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/RxBus.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/RxBus.kt index 2125199..c74e823 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/RxBus.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/RxBus.kt @@ -5,12 +5,12 @@ import io.reactivex.subjects.PublishSubject class RxBus : RxBusType { - private val mPublisher = PublishSubject.create() + private val _publisher = PublishSubject.create() override fun publish(event: Any) { - mPublisher.onNext(event) + _publisher.onNext(event) } - override fun toObservable(eventType: Class): Observable = mPublisher.ofType(eventType) + override fun toObservable(eventType: Class): Observable = _publisher.ofType(eventType) } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/operators/ApiErrorOperator.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/operators/ApiErrorOperator.kt index 5c25abd..f132919 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/operators/ApiErrorOperator.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/operators/ApiErrorOperator.kt @@ -10,7 +10,7 @@ import io.reactivex.disposables.Disposable import retrofit2.Response class ApiErrorOperator( - private val moshi: Moshi + private val _moshi: Moshi ) : ObservableOperator> { override fun apply(observer: Observer): Observer> { @@ -27,11 +27,11 @@ class ApiErrorOperator( override fun onNext(response: Response) { if (!response.isSuccessful) { try { - val adapter = moshi.adapter(ErrorEnvelope::class.java) + val adapter = _moshi.adapter(ErrorEnvelope::class.java) val envelope = adapter.fromJson(response.errorBody()?.string() ?: "{}") if (envelope != null) { - val envelopeWithCodeError = envelope.copy(code = response.code()) + val envelopeWithCodeError = envelope.copy(responseCode = response.code()) observer.onError(ApiException(envelopeWithCodeError, response)) } else { observer.onError(ResponseException(response)) diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/CombineLatestPairTransformer.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/CombineLatestPairTransformer.kt index 7728d34..39d82a7 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/CombineLatestPairTransformer.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/CombineLatestPairTransformer.kt @@ -6,11 +6,11 @@ import io.reactivex.ObservableTransformer import io.reactivex.functions.BiFunction class CombineLatestPairTransformer( - private val second: Observable + private val _second: Observable ) : ObservableTransformer> { override fun apply(upstream: Observable): ObservableSource> { - return Observable.combineLatest(upstream, second, BiFunction { f, s -> Pair(f, s) }) + return Observable.combineLatest(upstream, _second, BiFunction { f, s -> Pair(f, s) }) } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverApiErrorTransformer.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverApiErrorTransformer.kt index d31f4b1..eb67330 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverApiErrorTransformer.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverApiErrorTransformer.kt @@ -27,7 +27,7 @@ import io.reactivex.ObservableTransformer import io.reactivex.functions.Consumer class NeverApiErrorTransformer( - private val errorAction: Consumer? + private val _errorAction: Consumer? ) : ObservableTransformer { constructor() : this(null) @@ -36,8 +36,8 @@ class NeverApiErrorTransformer( return upstream .doOnError { e: Throwable -> val env = ErrorEnvelope.fromThrowable(e) - if (env != null && errorAction != null) { - errorAction.accept(env) + if (env != null && _errorAction != null) { + _errorAction.accept(env) } } .onErrorResumeNext { e: Throwable -> diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverErrorTransformer.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverErrorTransformer.kt index 466e48b..bdc216e 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverErrorTransformer.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/NeverErrorTransformer.kt @@ -26,14 +26,14 @@ import io.reactivex.ObservableTransformer import io.reactivex.functions.Consumer class NeverErrorTransformer( - private val errorAction: Consumer? + private val _errorAction: Consumer? ) : ObservableTransformer { constructor() : this(null) override fun apply(upstream: Observable): ObservableSource { return upstream - .doOnError { e: Throwable -> errorAction?.accept(e) } + .doOnError { e: Throwable -> _errorAction?.accept(e) } .onErrorResumeNext(Observable.empty()) } diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/TakeWhenTransformer.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/TakeWhenTransformer.kt index d6ae99c..47aeff5 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/TakeWhenTransformer.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/TakeWhenTransformer.kt @@ -6,11 +6,11 @@ import io.reactivex.ObservableTransformer import io.reactivex.functions.BiFunction class TakeWhenTransformer( - private val source: Observable + private val _source: Observable ) : ObservableTransformer { override fun apply(upstream: Observable): ObservableSource { - return source.withLatestFrom(upstream, BiFunction { _, x -> x }) + return _source.withLatestFrom(upstream, BiFunction { _, x -> x }) } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/Transformers.kt b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/Transformers.kt index e29ad89..382db4d 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/Transformers.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/rx/transformers/Transformers.kt @@ -36,7 +36,7 @@ object Transformers { } /** - * Emits when an error is thrown in a materialized stream. + * Emits when an message is thrown in a materialized stream. */ @JvmStatic fun errors(): ErrorsTransformer { diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseActivity.kt b/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseActivity.kt index 7b7dcc2..a512051 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseActivity.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseActivity.kt @@ -19,7 +19,7 @@ open class BaseActivity : AppCompatActivity(), LifecycleOwner, LifecycleObserver protected val scopeProvider: AndroidLifecycleScopeProvider by lazy { AndroidLifecycleScopeProvider.from(this) } - private val mBack = PublishSubject.create() + private val _back = PublishSubject.create() @CallSuper override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { @@ -44,7 +44,7 @@ open class BaseActivity : AppCompatActivity(), LifecycleOwner, LifecycleObserver super.onStart() Timber.v(this.toString(), "onStart") - mBack + _back .observeOn(AndroidSchedulers.mainThread()) .autoDisposable(AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_STOP)) .subscribe { goBack() } @@ -104,7 +104,7 @@ open class BaseActivity : AppCompatActivity(), LifecycleOwner, LifecycleObserver } protected fun back() { - mBack.onNext(Irrelevant.INSTANCE) + _back.onNext(Irrelevant.INSTANCE) } private fun goBack() { diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseArrayAdapter.kt b/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseArrayAdapter.kt index 8cd7478..dd71f3f 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseArrayAdapter.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseArrayAdapter.kt @@ -2,50 +2,50 @@ package io.freshdroid.mymonzo.core.ui abstract class BaseArrayAdapter : BaseAdapter() { - private var items = ArrayList() + private var _items = ArrayList() - fun items(): ArrayList = this.items + fun items(): ArrayList = this._items fun clearItems() { - this.items.clear() + this._items.clear() } fun addItem(item: T) { - this.items.add(item) + this._items.add(item) } fun addItems(items: ArrayList) { - this.items.addAll(items) + this._items.addAll(items) } fun setItems(items: ArrayList) { - this.items = items + this._items = items } fun insertItem(position: Int, item: T) { - this.items.add(position, item) + this._items.add(position, item) } fun deleteItem(item: T) { - this.items.remove(item) + this._items.remove(item) } fun deleteAtPositionItem(position: Int): T { - return this.items.removeAt(position) + return this._items.removeAt(position) } fun setItem(location: Int, item: T) { - this.items[location] = item + this._items[location] = item } fun contains(item: T): Boolean { - return this.items.contains(item) + return this._items.contains(item) } - override fun getItemCount(): Int = items.size + override fun getItemCount(): Int = _items.size - override fun objectFromPosition(position: Int): T = items[position] + override fun objectFromPosition(position: Int): T = _items[position] - override fun positionFromObject(item: T): Int = items.indexOf(item) + override fun positionFromObject(item: T): Int = _items.indexOf(item) } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseViewHolder.kt b/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseViewHolder.kt index 3e6f116..af16e30 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseViewHolder.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/ui/BaseViewHolder.kt @@ -5,8 +5,8 @@ import android.view.View import androidx.recyclerview.widget.RecyclerView abstract class BaseViewHolder( - private val view: View -) : RecyclerView.ViewHolder(view) { + private val _view: View +) : RecyclerView.ViewHolder(_view) { /** * Populate a view with data that was bound in `bindData`. @@ -28,8 +28,8 @@ abstract class BaseViewHolder( @Throws(Exception::class) abstract fun bindData(data: Any) - protected fun view(): View = view + protected fun view(): View = _view - protected fun context(): Context = view.context + protected fun context(): Context = _view.context } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/ui/RecyclerViewPaginator.kt b/core/src/main/java/io/freshdroid/mymonzo/core/ui/RecyclerViewPaginator.kt index 4b61bc8..ab2c008 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/ui/RecyclerViewPaginator.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/ui/RecyclerViewPaginator.kt @@ -29,11 +29,11 @@ import io.reactivex.functions.Action const val DIRECTION_DOWN = 1 class RecyclerViewPaginator( - private val recyclerView: RecyclerView, - private val fetchNext: Action + private val _recyclerView: RecyclerView, + private val _fetchNext: Action ) { - private var subscription: Disposable? = null + private var _subscription: Disposable? = null init { start() @@ -42,21 +42,21 @@ class RecyclerViewPaginator( private fun start() { stop() - subscription = RxRecyclerView.scrollEvents(recyclerView) - .filter { recyclerView.canScrollVertically(DIRECTION_DOWN) } - .map { recyclerView.layoutManager } + _subscription = RxRecyclerView.scrollEvents(_recyclerView) + .filter { _recyclerView.canScrollVertically(DIRECTION_DOWN) } + .map { _recyclerView.layoutManager } .ofType(LinearLayoutManager::class.java) .map(this::displayedItemFromLinearLayout) .filter { item -> item.second != 0 } .filter(this::visibleItemIsCloseToBottom) .distinctUntilChanged() - .subscribe { fetchNext.run() } + .subscribe { _fetchNext.run() } } fun stop() { - if (subscription != null) { - subscription?.dispose() - subscription = null + if (_subscription != null) { + _subscription?.dispose() + _subscription = null } } diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/user/CurrentUser.kt b/core/src/main/java/io/freshdroid/mymonzo/core/user/CurrentUser.kt index 0d071b0..648d87c 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/user/CurrentUser.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/user/CurrentUser.kt @@ -12,51 +12,51 @@ import javax.inject.Inject @SuppressLint("CheckResult") internal class CurrentUser @Inject constructor( - private val moshi: Moshi, - @UserPreference private val userMePreference: StringPreferenceType, - @AccessTokenPreference private val accessTokenPreference: StringPreferenceType + private val _moshi: Moshi, + @UserPreference private val _userMePreference: StringPreferenceType, + @AccessTokenPreference private val _accessTokenPreference: StringPreferenceType ) : CurrentUserType() { - private val mUserMe = BehaviorSubject.create() + private val _userMe = BehaviorSubject.create() init { val type = Types.newParameterizedType(User::class.java) - mUserMe + _userMe .subscribe { freshUser -> - val json = moshi.adapter(type).toJson(freshUser) - userMePreference.set(json) + val json = _moshi.adapter(type).toJson(freshUser) + _userMePreference.set(json) } - userMePreference.get()?.let { userPref -> - moshi.adapter(type).fromJson(userPref)?.let { mUserMe.onNext(it) } + _userMePreference.get()?.let { userPref -> + _moshi.adapter(type).fromJson(userPref)?.let { _userMe.onNext(it) } } } override fun refresh(freshUser: User) { - mUserMe.onNext(freshUser) + _userMe.onNext(freshUser) } override fun toObservable(): Observable { - return mUserMe + return _userMe } override fun setAccessToken(accessToken: String) { - accessTokenPreference.set(accessToken) + _accessTokenPreference.set(accessToken) } override fun getAccessToken(): String? { - return accessTokenPreference.get() + return _accessTokenPreference.get() } override fun isLoggedIn(): Boolean { - return accessTokenPreference.get() != null + return _accessTokenPreference.get() != null } override fun logout() { - accessTokenPreference.delete() - userMePreference.delete() - mUserMe.onNext(User()) + _accessTokenPreference.delete() + _userMePreference.delete() + _userMe.onNext(User()) } } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/ActivityViewModel.kt b/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/ActivityViewModel.kt index ea373e3..3f707d4 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/ActivityViewModel.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/ActivityViewModel.kt @@ -8,21 +8,21 @@ import io.reactivex.subjects.PublishSubject open class ActivityViewModel : ViewModel() { - private val activityResult = PublishSubject.create() - private val intent = PublishSubject.create() + private val _activityResult = PublishSubject.create() + private val _intent = PublishSubject.create() fun activityResult(activityResult: ActivityResult) { - this.activityResult.onNext(activityResult) + this._activityResult.onNext(activityResult) } fun intent(intent: Intent?) { intent?.let { - this.intent.onNext(intent) + this._intent.onNext(intent) } } - protected fun activityResult(): Observable = activityResult + protected fun activityResult(): Observable = _activityResult - protected fun intent(): Observable = intent + protected fun intent(): Observable = _intent } \ No newline at end of file diff --git a/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/FragmentViewModel.kt b/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/FragmentViewModel.kt index 03b510a..999b6d0 100644 --- a/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/FragmentViewModel.kt +++ b/core/src/main/java/io/freshdroid/mymonzo/core/viewmodel/FragmentViewModel.kt @@ -8,21 +8,21 @@ import io.reactivex.subjects.PublishSubject open class FragmentViewModel : ViewModel() { - private val activityResult = PublishSubject.create() - private val arguments = PublishSubject.create() + private val _activityResult = PublishSubject.create() + private val _arguments = PublishSubject.create() fun activityResult(activityResult: ActivityResult) { - this.activityResult.onNext(activityResult) + this._activityResult.onNext(activityResult) } fun arguments(arguments: Bundle?) { arguments?.let { - this.arguments.onNext(arguments) + this._arguments.onNext(arguments) } } - protected fun activityResult(): Observable = activityResult + protected fun activityResult(): Observable = _activityResult - protected fun arguments(): Observable = arguments + protected fun arguments(): Observable = _arguments } \ No newline at end of file diff --git a/home/src/main/java/io/freshdroid/mymonzo/home/viewmodels/HomeViewModel.kt b/home/src/main/java/io/freshdroid/mymonzo/home/viewmodels/HomeViewModel.kt index 92bb73f..50b2640 100644 --- a/home/src/main/java/io/freshdroid/mymonzo/home/viewmodels/HomeViewModel.kt +++ b/home/src/main/java/io/freshdroid/mymonzo/home/viewmodels/HomeViewModel.kt @@ -18,12 +18,12 @@ class HomeViewModel( scopeProvider: AndroidLifecycleScopeProvider ) : ActivityViewModel(), HomeViewModelInputs, HomeViewModelOutputs { - private val mFeedClicked = PublishSubject.create() - private val mSummaryClicked = PublishSubject.create() - private val mAccountClicked = PublishSubject.create() - private val mHelpClicked = PublishSubject.create() - private val mInitBottomNavigationBar = PublishSubject.create() - private val mDisplaySelectedFragment = PublishSubject.create() + private val _feedClicked = PublishSubject.create() + private val _summaryClicked = PublishSubject.create() + private val _accountClicked = PublishSubject.create() + private val _helpClicked = PublishSubject.create() + private val _initBottomNavigationBar = PublishSubject.create() + private val _displaySelectedFragment = PublishSubject.create() val inputs: HomeViewModelInputs = this val outputs: HomeViewModelOutputs = this @@ -31,57 +31,57 @@ class HomeViewModel( init { IntentExtra.getStringFromKey(intent(), Activities.Home.KEY_EXTRA_HOME_ACTIVE_TAB, true) .map { FragmentState.stateFromTag(it) } - .doOnNext(mInitBottomNavigationBar::onNext) + .doOnNext(_initBottomNavigationBar::onNext) .autoDisposable(scopeProvider) - .subscribe(mDisplaySelectedFragment::onNext) + .subscribe(_displaySelectedFragment::onNext) - mFeedClicked + _feedClicked .autoDisposable(scopeProvider) - .subscribe { mDisplaySelectedFragment.onNext(FragmentState.FEED) } + .subscribe { _displaySelectedFragment.onNext(FragmentState.FEED) } - mSummaryClicked + _summaryClicked .autoDisposable(scopeProvider) - .subscribe { mDisplaySelectedFragment.onNext(FragmentState.SUMMARY) } + .subscribe { _displaySelectedFragment.onNext(FragmentState.SUMMARY) } - mAccountClicked + _accountClicked .autoDisposable(scopeProvider) - .subscribe { mDisplaySelectedFragment.onNext(FragmentState.ACCOUNT) } + .subscribe { _displaySelectedFragment.onNext(FragmentState.ACCOUNT) } - mHelpClicked + _helpClicked .autoDisposable(scopeProvider) - .subscribe { mDisplaySelectedFragment.onNext(FragmentState.HELP) } + .subscribe { _displaySelectedFragment.onNext(FragmentState.HELP) } } // INPUTS override fun onFeedClick() { - mFeedClicked.onNext(Irrelevant.INSTANCE) + _feedClicked.onNext(Irrelevant.INSTANCE) } override fun onSummaryClick() { - mSummaryClicked.onNext(Irrelevant.INSTANCE) + _summaryClicked.onNext(Irrelevant.INSTANCE) } override fun onAccountClick() { - mAccountClicked.onNext(Irrelevant.INSTANCE) + _accountClicked.onNext(Irrelevant.INSTANCE) } override fun onHelpClick() { - mHelpClicked.onNext(Irrelevant.INSTANCE) + _helpClicked.onNext(Irrelevant.INSTANCE) } // OUTPUTS - override fun initBottomNavigationBar(): Observable = mInitBottomNavigationBar + override fun initBottomNavigationBar(): Observable = _initBottomNavigationBar - override fun displaySelectedFragment(): Observable = mDisplaySelectedFragment + override fun displaySelectedFragment(): Observable = _displaySelectedFragment @Suppress("UNCHECKED_CAST") class Factory( - private val scopeProvider: AndroidLifecycleScopeProvider + private val _scopeProvider: AndroidLifecycleScopeProvider ) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { - return HomeViewModel(scopeProvider) as T + return HomeViewModel(_scopeProvider) as T } } diff --git a/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationItemView.kt b/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationItemView.kt index a4bc6ca..f23454e 100644 --- a/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationItemView.kt +++ b/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationItemView.kt @@ -18,7 +18,7 @@ class BottomNavigationItemView @JvmOverloads constructor( defStyleRes: Int = 0 ) : LinearLayout(context, attrs, defStyle, defStyleRes) { - private val iconImageView: ImageView by bind(R.id.iconImageView) + private val _iconImageView: ImageView by bind(R.id.iconImageView) init { LayoutInflater.from(context).inflate(R.layout.bottom_navigation_item_view, this, true) @@ -28,30 +28,30 @@ class BottomNavigationItemView @JvmOverloads constructor( val a = context.obtainStyledAttributes(attrs, R.styleable.BottomNavigationItemView, 0, 0) val drawable = a.getDrawable(R.styleable.BottomNavigationItemView_icon) if (drawable != null) { - iconImageView.setImageDrawable(drawable) + _iconImageView.setImageDrawable(drawable) } } } fun setActive(active: Boolean) { if (active) { - iconImageView.setColorFilter( + _iconImageView.setColorFilter( ContextCompat.getColor( context, io.freshdroid.mymonzo.R.color.colorAccent ), android.graphics.PorterDuff.Mode.SRC_IN ) - iconImageView.alpha = 1F + _iconImageView.alpha = 1F } else { - iconImageView.setColorFilter( + _iconImageView.setColorFilter( ContextCompat.getColor( context, io.freshdroid.mymonzo.R.color.colorPrimaryLight ), android.graphics.PorterDuff.Mode.SRC_IN ) - iconImageView.alpha = 0.65F + _iconImageView.alpha = 0.65F } } diff --git a/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationView.kt b/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationView.kt index 175ed9a..2eacc2a 100644 --- a/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationView.kt +++ b/home/src/main/java/io/freshdroid/mymonzo/home/views/BottomNavigationView.kt @@ -21,54 +21,54 @@ class BottomNavigationView @JvmOverloads constructor( fun onHelpClick() } - private val feedBottomNavigationItemView: BottomNavigationItemView by bind(R.id.feedBottomNavigationItemView) - private val summaryBottomNavigationItemView: BottomNavigationItemView by bind(R.id.summaryBottomNavigationItemView) - private val accountBottomNavigationItemView: BottomNavigationItemView by bind(R.id.accountBottomNavigationItemView) - private val helpBottomNavigationItemView: BottomNavigationItemView by bind(R.id.helpBottomNavigationItemView) + private val _feedBottomNavigationItemView: BottomNavigationItemView by bind(R.id.feedBottomNavigationItemView) + private val _summaryBottomNavigationItemView: BottomNavigationItemView by bind(R.id.summaryBottomNavigationItemView) + private val _accountBottomNavigationItemView: BottomNavigationItemView by bind(R.id.accountBottomNavigationItemView) + private val _helpBottomNavigationItemView: BottomNavigationItemView by bind(R.id.helpBottomNavigationItemView) - private var mListener: Listener? = null - private var mCurrentState: FragmentState = FragmentState.FEED + private var _listener: Listener? = null + private var _currentState: FragmentState = FragmentState.FEED init { LayoutInflater.from(context).inflate(R.layout.bottom_navigation_view, this, true) - feedBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.FEED) } - summaryBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.SUMMARY) } - accountBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.ACCOUNT) } - helpBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.HELP) } + _feedBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.FEED) } + _summaryBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.SUMMARY) } + _accountBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.ACCOUNT) } + _helpBottomNavigationItemView.setOnClickListener { setStateActiveTab(FragmentState.HELP) } } fun setListener(listener: Listener) { - mListener = listener + _listener = listener } - fun getSelectedState(): FragmentState = mCurrentState + fun getSelectedState(): FragmentState = _currentState fun setStateActiveTab(state: FragmentState) { when (state) { FragmentState.FEED -> { - mCurrentState = FragmentState.FEED + _currentState = FragmentState.FEED resetSate(state) - feedBottomNavigationItemView.setActive(true) - mListener?.onFeedClick() + _feedBottomNavigationItemView.setActive(true) + _listener?.onFeedClick() } FragmentState.SUMMARY -> { - mCurrentState = FragmentState.SUMMARY + _currentState = FragmentState.SUMMARY resetSate(state) - summaryBottomNavigationItemView.setActive(true) - mListener?.onSummaryClick() + _summaryBottomNavigationItemView.setActive(true) + _listener?.onSummaryClick() } FragmentState.ACCOUNT -> { - mCurrentState = FragmentState.ACCOUNT + _currentState = FragmentState.ACCOUNT resetSate(state) - accountBottomNavigationItemView.setActive(true) - mListener?.onAccountClick() + _accountBottomNavigationItemView.setActive(true) + _listener?.onAccountClick() } FragmentState.HELP -> { - mCurrentState = FragmentState.HELP + _currentState = FragmentState.HELP resetSate(state) - helpBottomNavigationItemView.setActive(true) - mListener?.onHelpClick() + _helpBottomNavigationItemView.setActive(true) + _listener?.onHelpClick() } } } @@ -76,24 +76,24 @@ class BottomNavigationView @JvmOverloads constructor( private fun resetSate(state: FragmentState) { when (state) { FragmentState.FEED -> { - summaryBottomNavigationItemView.setActive(false) - accountBottomNavigationItemView.setActive(false) - helpBottomNavigationItemView.setActive(false) + _summaryBottomNavigationItemView.setActive(false) + _accountBottomNavigationItemView.setActive(false) + _helpBottomNavigationItemView.setActive(false) } FragmentState.SUMMARY -> { - feedBottomNavigationItemView.setActive(false) - accountBottomNavigationItemView.setActive(false) - helpBottomNavigationItemView.setActive(false) + _feedBottomNavigationItemView.setActive(false) + _accountBottomNavigationItemView.setActive(false) + _helpBottomNavigationItemView.setActive(false) } FragmentState.ACCOUNT -> { - feedBottomNavigationItemView.setActive(false) - summaryBottomNavigationItemView.setActive(false) - helpBottomNavigationItemView.setActive(false) + _feedBottomNavigationItemView.setActive(false) + _summaryBottomNavigationItemView.setActive(false) + _helpBottomNavigationItemView.setActive(false) } FragmentState.HELP -> { - feedBottomNavigationItemView.setActive(false) - summaryBottomNavigationItemView.setActive(false) - accountBottomNavigationItemView.setActive(false) + _feedBottomNavigationItemView.setActive(false) + _summaryBottomNavigationItemView.setActive(false) + _accountBottomNavigationItemView.setActive(false) } } } diff --git a/home/src/main/java/io/freshdroid/mymonzo/home/views/HomeActivity.kt b/home/src/main/java/io/freshdroid/mymonzo/home/views/HomeActivity.kt index 801cf88..ac36f47 100644 --- a/home/src/main/java/io/freshdroid/mymonzo/home/views/HomeActivity.kt +++ b/home/src/main/java/io/freshdroid/mymonzo/home/views/HomeActivity.kt @@ -14,47 +14,47 @@ import kotlinx.android.synthetic.main.activity_home.* class HomeActivity : BaseActivity() { - private val viewModelFactory by lazy { + private val _viewModelFactory by lazy { HomeViewModel.Factory(scopeProvider) } - private val viewModel by lazy { - ViewModelProviders.of(this, viewModelFactory).get(HomeViewModel::class.java) + private val _viewModel by lazy { + ViewModelProviders.of(this, _viewModelFactory).get(HomeViewModel::class.java) } - private lateinit var mFeedFragment: Fragment + private lateinit var _feedFragment: Fragment override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_home) - viewModel.outputs.initBottomNavigationBar() + _viewModel.outputs.initBottomNavigationBar() .compose(observeForUI()) .autoDisposable(scopeProvider) .subscribe(homeBottomNavigationView::setStateActiveTab) - viewModel.outputs.displaySelectedFragment() + _viewModel.outputs.displaySelectedFragment() .compose(observeForUI()) .autoDisposable(scopeProvider) .subscribe(this::displaySelectedFragment) initFragments() - viewModel.intent(intent) - homeBottomNavigationView.setListener(viewModel.inputs) + _viewModel.intent(intent) + homeBottomNavigationView.setListener(_viewModel.inputs) } private fun initFragments() { - mFeedFragment = fragmentTo(this, Fragments.Home.Feed) - supportFragmentManager.beginTransaction().add(R.id.fragmentContainerFrameLayout, mFeedFragment).commit() + _feedFragment = fragmentTo(this, Fragments.Home.Feed) + supportFragmentManager.beginTransaction().add(R.id.fragmentContainerFrameLayout, _feedFragment).commit() } private fun displaySelectedFragment(state: FragmentState) { val fragmentTransaction = supportFragmentManager.beginTransaction() when (state) { FragmentState.FEED -> { - fragmentTransaction.show(mFeedFragment).commit() + fragmentTransaction.show(_feedFragment).commit() } - else -> fragmentTransaction.hide(mFeedFragment).commit() + else -> fragmentTransaction.hide(_feedFragment).commit() } } diff --git a/home/src/test/java/io/freshdroid/mymonzo/home/MyMonzoRobolectricTestCase.kt b/home/src/test/java/io/freshdroid/mymonzo/home/MyMonzoRobolectricTestCase.kt index 2ab8507..b05e5b2 100644 --- a/home/src/test/java/io/freshdroid/mymonzo/home/MyMonzoRobolectricTestCase.kt +++ b/home/src/test/java/io/freshdroid/mymonzo/home/MyMonzoRobolectricTestCase.kt @@ -14,15 +14,15 @@ import org.robolectric.annotation.Config @Config(application = MyMonzoApplicationTest::class) internal abstract class MyMonzoRobolectricTestCase : TestCase() { - private var mApplication: MyMonzoApplicationTest? = null + private var _application: MyMonzoApplicationTest? = null protected fun application(): MyMonzoApplicationTest { - if (mApplication != null) { - return mApplication as MyMonzoApplicationTest + if (_application != null) { + return _application as MyMonzoApplicationTest } - mApplication = ApplicationProvider.getApplicationContext() as MyMonzoApplicationTest - return mApplication as MyMonzoApplicationTest + _application = ApplicationProvider.getApplicationContext() as MyMonzoApplicationTest + return _application as MyMonzoApplicationTest } protected fun context(): Context {