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

Hey, You can do it!

Hey, You can do it!

By JD

Buzzvil

July 14, 2021
Tweet

More Decks by Buzzvil

Other Decks in Programming

Transcript

  1. I think.. • To layout UI • To support multiple

    device (multiple Screen Resolution) • To interact many users ◦ System ◦ User
  2. How do we handle async tasks? fetchAds(param, object : FetchAdsListener

    { override fun onSuccess(ads: List<Ad>) { fetContents(param, object : FetchContentsListener { override fun onSuccess(contents: List<Content>) { ... } ... } } ... }) Observable .zip(fetchAds(param), fetchContents(param)) { ads, contents -> // do something } fetchAds(param) .flatMap { it.toObservable() } .filter { it.type == TypeVideo } .map { it.transformToCampaign() } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(...) Study ReactiveX
  3. We'll do it, you don't. class GetVideoAdCampaignUseCase constructor(...) { operator

    fun invoke(param: GetVideoAdCampaignUseCaseParam) : Observable<Campaign> = fetchAds(param) .flatMap { it.toObservable() } .filter { it.type == TypeVideo } .map { it.transformToCampaign() } } fun callGetVideoAdCampaignUseCase() { val param = GetVideoAdCampaignUseCaseParam(...) val disposable = GetVideoAdCampaignUseCase(param) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(...) disposables.add(disposable) }
  4. How can I fetch the data from other data sources?

    interface DataSource { fun fetchAds(param: Param) : Observable<List<Ad>> } // Delegate to CLAVENGERS class RemoteDataSource constructor( private val serviceApi: ServiceApi // Generated by Retrofit ) : DataSource { override fun fetchAds(param: Param) : Observable<List<Ad>> { ... } } class RemoteDataSource constructor( private val serviceApi: ServiceApi // Generated by Swagger ) : DataSource { override fun fetchAds(param: Param) : Observable<List<Ad>> { ... } } https://github.com/Buzzvil/buzzapis
  5. MVC, MVP, MVVM, MVI, (RIBs) ... I strongly recommend MVP.

    Because it is super easy. interface Contract { interface View { fun renderLoadingStateView() fun renderLoadedStateView(...) fun renderErrorStateView() } interface Presenter { fun requestLoad() } } class PresenterImpl : Contract.Presenter { override fun requestLoad() { modelLoader.load() .doOnSubscribe { view.renderLoadingStateView()} .subscribe({ model -> view.renderLoadedStateView(model) }, { e -> view.renderErrorStateView() }) } }
  6. iOS is equivalent to AOS. But.. You should learn Objective-C.

    #import <Foundation/Foundation.h> @import ReactiveObjC; #import <BuzzServiceApi/BuzzApiConfig.h> #import <BuzzServiceApi/BuzzApiGetConfigRequest.h> #import <BuzzServiceApi/BuzzApiListConfigsRequest.h> #import <BuzzServiceApi/BuzzApiListConfigsResponse.h> @protocol BuzzConfigServiceApi <NSObject> - (RACSignal<BuzzApiListConfigsResponse *> *)getListConfigsWithRequest:(BuzzApiListConfigsRequest *)request; @end
  7. The future Business Logic I will focus on how to

    share to same business logic on each platform.
  8. I’m going to use Multi-platform framework. • Does that mean

    using React-Native, Flutter, Ionic, Xamarin? ◦ NO! ◦ They try to solve almost every task with the same code. ◦ However, some features, rendering, and IO operations are prone to unexpected exceptions. ◦ Most importantly, there is no code base and we have to work from scratch. • So, I’m going to use Kotlin Multi Platform. ◦ Easy to migrate (AOS already has) ◦ I love kotlin. ◦ => I will restrict the code base with the same idea as RIBs.
  9. https://github.com/uber/RIBs • Business logic drives the app, not the view

    tree. Unlike with MV*/VIPER, a RIB does not have to have a view. This means that the app hierarchy is driven by the business logic, not the view tree. • Independent business logic and view trees. RIBs decouple how the business logic scopes are structured from view hierarchies. This allows the application to have a deep business logic tree, isolating business logic nodes, while maintaining a shallow view hierarchy making layouts, animations and transitions easy.