Skip to content

Instantly share code, notes, and snippets.

View orcchg's full-sized avatar
🏠
Working from home

Maxim Alov orcchg

🏠
Working from home
View GitHub Profile
@orcchg
orcchg / ExpiryDateTextWatcher.java
Created April 19, 2018 17:29
TextWatcher for expiry date MM/YY automatically adding slash. For Android
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.Spannable;
import android.text.TextWatcher;
import android.text.style.ReplacementSpan;
public class ExpiryDateTextWatcher implements TextWatcher {
private int maxLength = 5;
data class Stock(
val name: String,
val ticker: String,
val price: BigDecimal,
val priceDailyChange: BigDecimal = BigDecimal.ZERO,
val logoUrl: String? = null
)
interface StockListFeatureApi : Api {
val interactor: StockListInteractor
}
import io.reactivex.Maybe
import io.reactivex.Single
interface StockListInteractor {
fun stocks(): Single<List<Stock>>
fun stock(ticker: String): Maybe<Stock>
}
import retrofit2.Retrofit
interface NetworkCoreLibApi : Api {
fun retrofit(): Retrofit
}
class DefaultStockListInteractor @Inject constructor() : StockListInteractor {
override fun stocks(): Single<List<Stock>> {
throw UnsupportedOperationException("Not implemented")
}
override fun stock(ticker: String): Maybe<Stock> {
throw UnsupportedOperationException("Not implemented")
}
}
class FakeStockListInteractor @Inject constructor() : StockListInteractor {
override fun stocks(): Single<List<Stock>> =
Single.just(
listOf(
Stock(
name = "Apple Inc.",
ticker = "AAPL",
price = 131.93.money()
),
// :feature:stock_list:impl/build.gradle.kts
plugins {
id("kotlin")
}
dependencies {
api(project(":feature:stock_list:api"))
}
@Module
interface FakeStockListFeatureModule {
@Binds
@Reusable
fun interactor(impl: FakeStockListInteractor): StockListInteractor
}
@Component(
modules = [
FakeStockListFeatureModule::class // publish reasonable alternative for StockListInteractor
]
)
interface FakeStockListFeatureComponent : StockListFeatureApi