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 DataStore for the SharedPreferences | |
interface ProductPreferences { |
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
// Network DTO | |
data class NetworkProduct( | |
@SerializedName("id") | |
val id: String?, | |
@SerializedName("name") | |
val name: String?, | |
@SerializedName("nowPrice") | |
val nowPrice: Double?, | |
@SerializedName("wasPrice") | |
val wasPrice: Double? |
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
// Database DTO | |
@Entity(tableName = "Product") | |
data class DBProduct( | |
@PrimaryKey | |
@ColumnInfo(name = "id") | |
val id: String, | |
@ColumnInfo(name = "name") | |
val name: String, | |
@ColumnInfo(name = "nowPrice") | |
val nowPrice: Double, |
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
@Entity(tableName = "Product") | |
data class ProductDTO( | |
@PrimaryKey | |
@ColumnInfo(name = "id") | |
@SerializedName("id") | |
val id: String?, | |
@ColumnInfo(name = "name") | |
@SerializedName("name") | |
val name: String?, | |
@ColumnInfo(name = "nowPrice") |
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
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
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 Nullable | |
interface NullableOutputListMapper<I, O>: Mapper<List<I>, List<O>?> | |
class NullableOutputListMapperImpl<I, O>( | |
private val mapper: Mapper<I, O> | |
) : NullableOutputListMapper<I, O> { | |
override fun map(input: List<I>): List<O>? { | |
return if (input.isEmpty()) null else input.map { mapper.map(it) } | |
} | |
} |
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
// Nullable to Non-nullable | |
interface NullableInputListMapper<I, O>: Mapper<List<I>?, List<O>> | |
class NullableInputListMapperImpl<I, O>( | |
private val mapper: Mapper<I, O> | |
) : NullableInputListMapper<I, O> { | |
override fun map(input: List<I>?): List<O> { | |
return input?.map { mapper.map(it) }.orEmpty() | |
} | |
} |
OlderNewer