This file contains hidden or 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
| // :feature:stock_list:demo/build.gradle.kts | |
| plugins { | |
| id("com.android.application") | |
| id("kotlin-android") | |
| } | |
| android { } | |
| dependencies { |
This file contains hidden or 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
| internal class StockListDemoActivity : AppCompatActivity() { | |
| @Inject lateinit var stockListAdapter: StockListAdapter | |
| @Inject lateinit var factory: StockListViewModelFactory | |
| private val binding by viewBindings(StockActivityDemoBinding::inflate) | |
| private val viewModel by viewModels<StockListViewModel> { factory } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| // HERE ! | |
| DaggerStockListDemoActivityComponent.factory() |
This file contains hidden or 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
| @Component( | |
| dependencies = [ | |
| StockListFeatureApi::class | |
| ] | |
| ) | |
| internal interface StockListDemoActivityComponent { | |
| fun inject(target: StockListDemoActivity) | |
| @Component.Factory |
This file contains hidden or 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
| override fun onCreate(savedInstanceState: Bundle?) { | |
| DaggerStockListDemoActivityComponent.factory() | |
| .create(featureApi = DaggerFakeStockListFeatureComponent.create()) // HERE ! | |
| .inject(this) | |
| super.onCreate(savedInstanceState) | |
| } |
This file contains hidden or 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
| internal class StockListViewModel @Inject constructor( | |
| private val interactor: StockListInteractor | |
| ) : ViewModel() { | |
| private val _stocks by lazy { | |
| val data = MutableLiveData<List<Stock>>() | |
| interactor | |
| .stocks() | |
| .subscribe({ data.value = it }, Timber::e) | |
| data |
This file contains hidden or 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 DefaultStockListInteractor @Inject constructor( | |
| private val getStocksUseCase: GetStocksUseCase, | |
| private val getStockByTickerUseCase: GetStockByTickerUseCase | |
| ) : StockListInteractor { | |
| override fun stocks(): Single<List<Stock>> = getStocksUseCase.source() | |
| override fun stock(ticker: String): Maybe<Stock> = | |
| getStockByTickerUseCase.source { | |
| GetStockByTickerUseCase.PARAM_TICKER of ticker |
This file contains hidden or 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 GetStockByTickerUseCase @Inject constructor( | |
| private val repository: StockListRepository, | |
| schedulersFactory: SchedulersFactory | |
| ) : MaybeUseCase<Stock>(schedulersFactory) { | |
| override fun sourceImpl(params: Params): Maybe<Stock> = | |
| params.processMaybe(PARAM_TICKER, repository::stock) | |
| companion object { | |
| const val PARAM_TICKER = "ticker" |
This file contains hidden or 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
| abstract class MaybeUseCase<T>( | |
| private val schedulersFactory: SchedulersFactory | |
| ) { | |
| abstract fun sourceImpl(params: Params = Params.EMPTY): Maybe<T> | |
| fun source(params: Params = Params.EMPTY): Maybe<T> = | |
| sourceImpl(params) | |
| .subscribeOn(schedulersFactory.useCase()) | |
| .observeOn(schedulersFactory.main()) |
This file contains hidden or 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 StockListDataApi : Api { | |
| val repository: StockListRepository | |
| } |
This file contains hidden or 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 StockListRepository { | |
| fun stocks(): Single<List<Stock>> | |
| fun stock(ticker: String): Maybe<Stock> | |
| } |