-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from JoaquimLey/stream/episode_14
Stream Episode 14
- Loading branch information
Showing
31 changed files
with
769 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apply plugin: 'kotlin' | ||
|
||
// Module configuration | ||
configurations.all { | ||
resolutionStrategy { | ||
force deps.kotlin.stdlib | ||
} | ||
} | ||
|
||
|
||
dependencies { | ||
// Modules | ||
implementation project(':domain') | ||
|
||
// Javax | ||
implementation deps.javax.inject | ||
compileOnly deps.javax.annotation | ||
// Kotlin | ||
implementation deps.kotlin.rx | ||
implementation deps.kotlin.stdlib | ||
|
||
/*********** | ||
* Testing * | ||
***********/ | ||
|
||
// Testing | ||
testImplementation deps.junit | ||
testImplementation deps.mockito.kotlin | ||
testImplementation deps.mockito.inline | ||
} |
29 changes: 29 additions & 0 deletions
29
transport-eta-android/data/src/main/java/com/joaquimley/data/FavoritesRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.joaquimley.data | ||
|
||
import com.joaquimley.data.mapper.TransportMapper | ||
import com.joaquimley.data.store.TransportDataStore | ||
import com.joaquimley.transporteta.domain.model.Transport | ||
import com.joaquimley.transporteta.domain.repository.FavoritesRepository | ||
import io.reactivex.Completable | ||
import io.reactivex.Flowable | ||
|
||
class FavoritesRepositoryImpl(private val transportDataStore: TransportDataStore, | ||
private val mapper: TransportMapper) : FavoritesRepository { | ||
|
||
override fun markAsFavorite(transport: Transport): Completable { | ||
return transportDataStore.markAsFavorite(mapper.toEntity(transport)) | ||
} | ||
|
||
override fun removeAsFavorite(transport: Transport): Completable { | ||
return transportDataStore.removeAsFavorite(mapper.toEntity(transport)) | ||
} | ||
|
||
override fun getAll(): Flowable<List<Transport>> { | ||
return transportDataStore.getAllFavorites().map { mapper.toModel(it) } | ||
} | ||
|
||
override fun clearAll(): Completable { | ||
return transportDataStore.clearAllFavorites() | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
transport-eta-android/data/src/main/java/com/joaquimley/data/TransportRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.joaquimley.data | ||
|
||
import com.joaquimley.transporteta.domain.model.Transport | ||
import com.joaquimley.transporteta.domain.repository.TransportRepository | ||
import io.reactivex.Completable | ||
import io.reactivex.Observable | ||
|
||
class TransportRepositoryImpl: TransportRepository { | ||
|
||
override fun requestTransportEta(transportCode: Int): Observable<Transport> { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun cancelTransportEtaRequest(transportCode: Int?): Completable { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun getTransport(transportId: String): Observable<Transport> { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun saveTransport(transport: Transport): Completable { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun saveTransport(transportList: List<Transport>): Completable { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun deleteTransport(transport: Transport): Completable { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun deleteTransports(transport: List<Transport>): Completable { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
transport-eta-android/data/src/main/java/com/joaquimley/data/executor/ThreadExecutorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.joaquimley.data.executor | ||
|
||
import com.joaquimley.transporteta.domain.executor.ThreadExecutor | ||
import java.util.concurrent.LinkedBlockingQueue | ||
import java.util.concurrent.ThreadFactory | ||
import java.util.concurrent.ThreadPoolExecutor | ||
import java.util.concurrent.TimeUnit | ||
|
||
class ThreadExecutorImpl(private val threadFactory: ThreadFactory = JobThreadFactory(), | ||
private val workQueue: LinkedBlockingQueue<Runnable> = LinkedBlockingQueue(), | ||
private val threadPoolExecutor: ThreadPoolExecutor = | ||
ThreadPoolExecutor(INITIAL_POOL_SIZE, MAX_POOL_SIZE, | ||
KEEP_ALIVE_TIME.toLong(), KEEP_ALIVE_TIME_UNIT, | ||
workQueue, threadFactory)) | ||
: ThreadExecutor { | ||
|
||
|
||
override fun execute(runnable: Runnable?) { | ||
runnable?.let { threadPoolExecutor.execute(runnable) } | ||
?: run { | ||
throw IllegalArgumentException("Runnable to execute cannot be null") | ||
} | ||
} | ||
|
||
private class JobThreadFactory : ThreadFactory { | ||
private var counter = 0 | ||
|
||
override fun newThread(runnable: Runnable): Thread { | ||
return Thread(runnable, THREAD_NAME + counter++) | ||
} | ||
|
||
companion object { | ||
private const val THREAD_NAME = "transport_eta_" | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
private const val INITIAL_POOL_SIZE = 3 // TODO: Get number of CPU cores | ||
private const val MAX_POOL_SIZE = 5 // TODO: Get number of CPU cores | ||
|
||
// Sets the amount of time an idle thread waits before terminating | ||
private const val KEEP_ALIVE_TIME = 10 | ||
|
||
// Sets the Time Unit to seconds | ||
private val KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
transport-eta-android/data/src/main/java/com/joaquimley/data/mapper/TransportMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.joaquimley.data.mapper | ||
|
||
import com.joaquimley.data.model.TransportEntity | ||
import com.joaquimley.transporteta.domain.model.Transport | ||
|
||
class TransportMapper { | ||
|
||
fun toEntity(from: List<Transport>): List<TransportEntity> { | ||
return from.map { toEntity(it) } | ||
} | ||
|
||
fun toEntity(from: Transport): TransportEntity { | ||
return TransportEntity(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type) | ||
} | ||
|
||
fun toModel(from: List<TransportEntity>): List<Transport> { | ||
return from.map { toModel(it) } | ||
} | ||
|
||
fun toModel(from: TransportEntity): Transport { | ||
return Transport(from.id, from.name, from.code, from.latestEta, from.isFavorite, from.type) | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
transport-eta-android/data/src/main/java/com/joaquimley/data/model/TransportEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.joaquimley.data.model | ||
|
||
data class TransportEntity(val id: String, val name: String, val code: Int, val latestEta: String, | ||
val isFavorite: Boolean = false, val type: String) |
3 changes: 3 additions & 0 deletions
3
...-eta-android/data/src/main/java/com/joaquimley/data/source/SharedPreferencesDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.joaquimley.data.source | ||
|
||
class SharedPreferencesDataSource |
35 changes: 35 additions & 0 deletions
35
transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.joaquimley.data.store | ||
|
||
import com.joaquimley.data.model.TransportEntity | ||
import io.reactivex.Completable | ||
import io.reactivex.Flowable | ||
import io.reactivex.Observable | ||
|
||
interface TransportDataStore { | ||
|
||
fun markAsFavorite(transport: TransportEntity): Completable | ||
|
||
fun removeAsFavorite(transport: TransportEntity): Completable | ||
|
||
fun getAllFavorites(): Flowable<List<TransportEntity>> | ||
|
||
fun clearAllFavorites(): Completable | ||
|
||
fun getAll(): Flowable<List<TransportEntity>> | ||
|
||
fun getTransport(transportId: String): Observable<TransportEntity> | ||
|
||
fun saveTransport(transport: TransportEntity): Completable | ||
|
||
fun saveTransport(transportList: List<TransportEntity>): Completable | ||
|
||
fun deleteTransport(transport: TransportEntity): Completable | ||
|
||
fun deleteTransport(transport: List<TransportEntity>): Completable | ||
|
||
// TODO Should these be in the [SmSController] instead? [RequestEtaUseCase] | ||
fun requestTransportEta(transportCode: Int): Observable<TransportEntity> | ||
|
||
// TODO Should these be in the [SmSController] instead ? [RequestEtaUseCase] | ||
fun cancelTransportEtaRequest(transportCode: Int?): Completable | ||
} |
7 changes: 7 additions & 0 deletions
7
transport-eta-android/data/src/main/java/com/joaquimley/data/store/TransportDataStoreImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.joaquimley.data.store | ||
|
||
import com.joaquimley.data.source.SharedPreferencesDataSource | ||
|
||
class TransportDataStoreImpl(val sharedPreferencesDataSource: SharedPreferencesDataSource) { | ||
|
||
} |
Oops, something went wrong.