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
// A wrapper for handling failing requests | |
sealed class Result<T> { | |
data class Success<T>(val value: T) : Result<T>() | |
data class Failure<T>(val throwable: Throwable) : Result<T>() | |
} | |
// A DataSource for the SharedPreferences |
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
class ProductRepositoryImpl( | |
private val productApiService: ProductApiService, | |
private val productDataMapper: Mapper<DataProduct, Product>, | |
private val productPreferences: ProductPreferences | |
) : ProductRepository { | |
override fun getWishlist(): Single<Result<List<Product>>> { | |
return productApiService.getWishlist(productPreferences.getFavourites()).map { | |
when (it) { | |
is Result.Success -> Result.Success(mapWishlist(it.value)) |
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
interface Mapper<I, O> { | |
fun map(input: I): O | |
} |
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
class TransactionsViewModelImpl( | |
private val userRepository: UserRepository, | |
private val transactionRepository: TransactionRepository | |
) : TransactionsViewModel, ViewModel() { | |
private val compositeDisposable = CompositeDisposable() | |
override val transactions = MutableLiveData<List<Transaction>>() | |
override val showProgress = MutableLiveData<Boolean>() | |
override val showError = MutableLiveData<Boolean>() |
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
// A wrapper for handling failing requests | |
sealed class Result<T> { | |
data class Success<T>(val value: T) : Result<T>() | |
data class Failure<T>(val throwable: Throwable) : Result<T>() | |
} | |
// The models (simplified) |
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
// User | |
interface GetCurrentUserUseCase { | |
operator fun invoke(): Result<User> | |
} | |
class GetCurrentUserUseCaseImpl( | |
private val userRepository: UserRepository | |
) : GetCurrentUserUseCase { | |
override fun invoke(): Result<User> = userRepository.getUser() | |
} |
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
class TransactionsViewModelImpl( | |
private val getUserTransactionsUseCase: GetUserTransactionsUseCase | |
) : TransactionsViewModel, ViewModel() { | |
private val compositeDisposable = CompositeDisposable() | |
override val transactions = MutableLiveData<List<Transaction>>() | |
override val showProgress = MutableLiveData<Boolean>() | |
override val showError = MutableLiveData<Boolean>() | |
override val showContent = MutableLiveData<Boolean>() |
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
// Non-nullable to Non-nullable | |
inline fun <I, O> mapList(input: List<I>, mapSingle: (I) -> O): List<O> { | |
return input.map { mapSingle(it) } | |
} | |
// Nullable to Non-nullable | |
inline fun <I, O> mapNullInputList(input: List<I>?, mapSingle: (I) -> O): List<O> { | |
return input?.map { mapSingle(it) } ?: emptyList() | |
} |
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
// Aggregate | |
data class Album( | |
val id: String, | |
val title: String, | |
val songs: List<Song> | |
) | |
// Entity | |
data class Song( | |
val id: String, |
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
data class NetworkAlbum( | |
@SerializedName("id") | |
val id: String?, | |
@SerializedName("title") | |
val title: String?, | |
@SerializedName("songs") | |
val songs: List<NetworkSong>? | |
) | |
data class NetworkSong( |