Skip to content

Commit

Permalink
improve naming to follow kotlin convensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume M committed Jun 28, 2019
1 parent dd09f4c commit 4c25791
Show file tree
Hide file tree
Showing 38 changed files with 239 additions and 237 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/io/freshdroid/mymonzo/MyMonzoApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
private val _httpTransitionFactory: HttpTransitionFactoryType,
private val _moshi: Moshi
) : ApiCore(_moshi), ApiSplashScreenType
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,20 +23,22 @@ class SplashScreenViewModel(
scopeProvider: AndroidLifecycleScopeProvider
) : ActivityViewModel(), SplashScreenViewModelInputs, SplashScreenViewModelOutputs, SplashScreenViewModelErrors {

private val mFakeLoading = PublishSubject.create<Irrelevant>()
private val mLaunchNextActivity = PublishSubject.create<Uri>()
private val _fakeLoading = PublishSubject.create<Irrelevant>()
private val _launchNextActivity = PublishSubject.create<Uri>()

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() {
Expand All @@ -46,20 +49,20 @@ class SplashScreenViewModel(
// INPUTS

override fun fakeLoading() {
mFakeLoading.onNext(Irrelevant.INSTANCE)
_fakeLoading.onNext(Irrelevant.INSTANCE)
}

// OUTPUTS

override fun launchNextActivity(): Observable<Uri> = mLaunchNextActivity
override fun launchNextActivity(): Observable<Uri> = _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 <T : ViewModel?> create(modelClass: Class<T>): T {
return SplashScreenViewModel(environment, scopeProvider) as T
return SplashScreenViewModel(_environment, _scopeProvider) as T
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ 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
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()
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.freshdroid.mymonzo

import io.freshdroid.mymonzo.MyMonzoApplication

internal class MyMonzoApplicationTest : MyMonzoApplication() {

override fun isInUnitTests(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.freshdroid.mymonzo.core.network

enum class HttpVerb(
private val tag: String
private val _tag: String
) {

GET("GET"),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
Loading

0 comments on commit 4c25791

Please sign in to comment.