Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Implementing new feature in existing screen

Implementing new feature in existing screen

2018/08/23 Android Lunch & Learn

Rui Kowase

August 28, 2018
Tweet

More Decks by Rui Kowase

Other Decks in Technology

Transcript

  1. Profile • Name: Rui Kowase / 小和瀬 塁 • Account:

    @rkowase Skill: Flutter, Android, etc...
  2. Benefits of The New Architecture “This architecture will help you

    to make your code less buggy and easier to modify. Having a consistent architecture will make your work and life easier.”
  3. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject
  4. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject
  5. ExhibitModule @Module class ExhibitModule( // ... @Provides @ActivityScope fun provideSafeTradePresenter():

    SafeTradeContract.ExhibitPresenter { val builder = SafeTradeFeatureBuilder(...) return builder.buildExhibitPresenter(...) } }
  6. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject
  7. SafeTrade Contract interface SafeTradeContract { interface Presenter { // .....

    } interface ExhibitPresenter : Presenter { // ..... companion object { val EMPTY = object : ExhibitPresenter {} } } interface ExhibitView : ViewProxy<ExhibitPresenter> { // ..... } // ..... } The interface of SafeTrade’s ViewProxy and Presenter
  8. SafeTrade FeatureBuilder class SafeTradeFeatureBuilder @Inject constructor( private val activity: Activity,

    private val provider: SafeTradeViewFactory ) { @VisibleForTesting var isDebug: Boolean = BuildConfig.DEBUG fun buildExhibitPresenter(repository: SafeTradeRepository, helper: StringFormatHelper, state: ListingUiState ): SafeTradeContract.ExhibitPresenter { if (!isDebug) { return SafeTradeContract.ExhibitPresenter.EMPTY } // ….. return presenter } } The builder for Presenter
  9. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject
  10. SafeTrade ViewFactory interface SafeTradeViewFactory { interface Exhibit : SafeTradeViewFactory {

    fun getEnableRoot(): View fun getEnableCheckbox(): CheckBox fun getEnableCheckboxContainer(): View fun getEnableSafeTradeFeeValue(): TextView fun getEnableTitle(): TextView fun getEnableSubTitle(): TextView fun getEnableHelpIcon(): ImageView fun getAdditionalFeeRoot(): View fun getAdditionalFeeLabel(): TextView fun getAdditionalFeeValue(): TextView fun getAgreementRoot(): View fun getAgreementCheckbox(): CheckBox } } View inflater
  11. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject
  12. ExhibitActivity private void setUpDi() { // ... SafeTradeExhibitViewFactoryProvider provider =

    new SafeTradeExhibitViewFactoryProvider( findViewById(R.id.safe_trade_frame_enable), // ... ); ThisApplication.get(this) .component() .newStatefulExhibitSubComponent( new ExhibitModule( // ... exhibitViewProxy, // … ), new ImageModule(this)) .inject(this); }
  13. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject Tap SafeTrade’s View
  14. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject Call SafeTradeExhibit Presenter
  15. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject Do nothing if it is disabled
  16. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject Call SafeTradeExhibit ViewProxy
  17. Architecture of SafeTrade Feature Exhibit ViewProxy Exhibit Presenter Existing Feature

    Exhibit Repository SafeTradeExhibit Presenter SafeTradeExhibit Repository SafeTradeExhibit ViewProxy SafeTrade FeatureBuilder Exhibit Activity New Feature Feature toggle SafeTrade ViewFactory Inject Inject Update views
  18. Summary • Toggle Feature in Builder class • SRP (Single

    Responsibility Principle) • Divide classes by interface and inject