Skip to content

Commit

Permalink
Small improvements in Framework abstraction
Browse files Browse the repository at this point in the history
Prep work for #87
  • Loading branch information
JoaquimLey committed Dec 4, 2018
1 parent 1bcf435 commit 4d3825d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 16 deletions.
3 changes: 1 addition & 2 deletions transport-eta-android/data-sharedpreferences/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
apply plugin: 'kotlin-android-extensions'

Expand All @@ -9,7 +9,6 @@ android {
defaultConfig {
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
testInstrumentationRunner "com.joaquimley.transporteta.ui.test.TestRunner"
}

testOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class FrameworkLocalStorageImpl @Inject constructor(private val sharedPreference
}

private fun getSlot(): Slot? {
// TODO Improve this, also check for updates
// TODO Improve this
return when {
getFromSharedPrefs(Slot.SAVE_SLOT_ONE) == null -> Slot.SAVE_SLOT_ONE
getFromSharedPrefs(Slot.SAVE_SLOT_TWO) == null -> Slot.SAVE_SLOT_TWO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FrameworkLocalStorageTest {
robot.stubMapperFromStringToModel(modelStringThree)

// Act
// Nothing <->xo
// Nothing <->
// Assert
verify(mockSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.SAVE_SLOT_ONE.name, null)
verify(mockSharedPreferences, times(1)).getString(FrameworkLocalStorageImpl.Slot.SAVE_SLOT_TWO.name, null)
Expand Down
2 changes: 1 addition & 1 deletion transport-eta-android/presentation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.joaquimley.transporteta.sms

import android.telephony.SmsManager
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SmsSender @Inject constructor(private val androidSmsManager: SmsManager) {

// TODO Improve with intents: https://github.com/JoaquimLey/transport-eta/issues/87
fun send(serviceNumber: String, busStopCode: Int) {
androidSmsManager.sendTextMessage(serviceNumber, null, "C $busStopCode", null, null)

}
}gs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.joaquimley.transporteta.sms

import android.telephony.SmsManager
import android.util.Log
import com.joaquimley.transporteta.sms.model.SmsModel
import io.reactivex.Single
Expand All @@ -12,7 +11,8 @@ import javax.inject.Singleton


@Singleton
class SmsControllerImpl @Inject constructor(private val smsBroadcastReceiver: SmsBroadcastReceiver) : SmsController {
class SmsControllerImpl @Inject constructor(private val smsBroadcastReceiver: SmsBroadcastReceiver,
private val smsSender: SmsSender) : SmsController {


// TODO build a queue for requests
Expand Down Expand Up @@ -44,7 +44,7 @@ class SmsControllerImpl @Inject constructor(private val smsBroadcastReceiver: Sm
}

this.busStopCode = busStopCode
SmsManager.getDefault().sendTextMessage(smsBroadcastReceiver.serviceNumber, null, "C $busStopCode", null, null)
smsSender.send(smsBroadcastReceiver.serviceNumber, busStopCode)
return Single.create<SmsModel> { emitter ->
smsRequestDisposable = smsPublishSubject.subscribe({ sms ->
emitter.onSuccess(sms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.joaquimley
import com.joaquimley.transporteta.sms.SmsBroadcastReceiver
import com.joaquimley.transporteta.sms.SmsController
import com.joaquimley.transporteta.sms.SmsControllerImpl
import com.joaquimley.transporteta.sms.SmsSender
import com.nhaarman.mockitokotlin2.atLeastOnce
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.verify
Expand All @@ -16,13 +17,14 @@ class SmsControllerTest {

private val robot = Robot()
private val mockSmsBroadcastReceiver = mock<SmsBroadcastReceiver>()
private val mockSmsManager = mock<SmsSender>()

private lateinit var smsController: SmsController

@Before
fun setup() {
robot.stubSmsBroadcastReceiverSuccess()
smsController = SmsControllerImpl(mockSmsBroadcastReceiver)
smsController = SmsControllerImpl(mockSmsBroadcastReceiver, mockSmsManager)
}

@After
Expand Down
2 changes: 1 addition & 1 deletion transport-eta-android/ui-mobile/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.joaquimley.transporteta.ui.di.module

import com.joaquimley.transporteta.sms.SmsBroadcastReceiver
import com.joaquimley.transporteta.sms.SmsBroadcastReceiverImpl
import com.joaquimley.transporteta.sms.SmsController
import com.joaquimley.transporteta.sms.SmsControllerImpl
import android.telephony.SmsManager
import com.joaquimley.transporteta.sms.*
import com.joaquimley.transporteta.ui.di.qualifier.SmsServiceInfo
import com.joaquimley.transporteta.ui.di.scope.PerApplication
import dagger.Module
Expand Down Expand Up @@ -40,7 +38,13 @@ class SmsControllerModule {

@Provides
@PerApplication
internal fun provideSmsController(smsBroadcastReceiver: SmsBroadcastReceiver): SmsController {
return SmsControllerImpl(smsBroadcastReceiver)
internal fun provideSmsSender(): com.joaquimley.transporteta.sms.SmsSender {
return SmsSender(SmsManager.getDefault())
}

@Provides
@PerApplication
internal fun provideSmsController(smsBroadcastReceiver: SmsBroadcastReceiver, smsSender: SmsSender): SmsController {
return SmsControllerImpl(smsBroadcastReceiver, smsSender)
}
}

0 comments on commit 4d3825d

Please sign in to comment.