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

DroidKaigi 2018 App Architecture

takahirom
February 27, 2018

DroidKaigi 2018 App Architecture

takahirom

February 27, 2018
Tweet

More Decks by takahirom

Other Decks in Programming

Transcript

  1. ˖ UBLBIJSPN !OFX@SVOOBCMF  ˖ 劤せכ嬁「䃨峔 ׭׿ׄױ׋ַמ׹  ˖ "OESPJEָ㥨ֹדׅկ

    ˖ "CFNB57ך"OESPJE،فٔ׾⡲׏גְתׅկ ˖ %SPJE,BJHJⰕ䒭،فٔךٔ٦ت٦׾׃ת׃׋կ
 ⟃♳ךفؙٕٔؒأز֮׶ָהֲ׀ְׂת׃׋! 荈ⴓחאְג
  2. ˖ ⿠䎃ך%SPJE,BJHJ،فٔזוָ⢽חז׷կ ˖ %BUB#JOEJOH׾ⵃ欽ׅ׷կ ˖ 7JFX.PEFMַ׵4FTTJPOT3FQPTJUPSZOE"MM ׃ח 遤׏גծًٝغ㢌侧׾%BUB#JOEJOHדغ؎ٝسׅ׷ ˖ ㉏겗挿

    ˖ Ⰻֻずׄד׮㉏겗כזְָծ"SDIJUFDUVSF $PNQPOFOUTװ,PUMJOָוֲ䕦갟׾ׅ׷ַ׾罋ִ ׋ְկ .77. IUUQTHJUIVCDPN%SPJE,BJHJDPOGFSFODFBQQ״׶
  3. ˖ ⿠䎃ך%SPJE,BJHJ،فٔזוָ⢽חז׷կ ˖ %BUB#JOEJOH׾ⵃ欽ׅ׷կ ˖ 7JFX.PEFMַ׵4FTTJPOT3FQPTJUPSZOE"MM ׃ח 遤׏גծًٝغ㢌侧׾%BUB#JOEJOHדغ؎ٝسׅ׷ ˖ ㉏겗挿

    ˖ Ⰻֻずׄד׮㉏겗כזְָծ"SDIJUFDUVSF $PNQPOFOUTװ,PUMJOָוֲ䕦갟׾ׅ׷ַ׾罋ִ ׋ְկ .77. ̔%BUB#JOEJOHכ⢪׏גְֹ׋ְ IUUQTHJUIVCDPN%SPJE,BJHJDPOGFSFODFBQQ״׶
  4. ˖ EPNBJOךהֿ׹׾׍ׯ׿הⴓֽגծ
 ׉ך鿇ⴓחؽآطأٗآحָؙ剅ֽ׷ ˖ ׉׸ז׶ח⢪׻׸גְ׷孡ָׅ׷կ ˖ ㉏겗挿 ˖ %SPJE,BJHJך鋉垷ח׃גכ麓ⶱד֮׷孡ָׅ׷ ˖

    孡鯪חכ؝ٝزٔؽُ٦ءّٝדֹזְ孡ָׅ׷ $MFBO"SDIJUFDUVSF IUUQTHJUIVCDPNBOESPJE"OESPJE$MFBO"SDIJUFDUVSF״׶
  5. ˖ EPNBJOךהֿ׹׾׍ׯ׿הⴓֽגծ
 ׉ך鿇ⴓחؽآطأٗآحָؙ剅ֽ׷ ˖ ׉׸ז׶ח⢪׻׸גְ׷孡ָׅ׷կ ˖ ㉏겗挿 ˖ %SPJE,BJHJך鋉垷ח׃גכ麓ⶱד֮׷孡ָׅ׷ ˖

    孡鯪חכ؝ٝزٔؽُ٦ءّٝדֹזְ孡ָׅ׷ ˖ 罋ִ倯׾《׶Ⰵ׸׷ךכְְ孡ָׅ׷ $MFBO"SDIJUFDUVSF IUUQTHJUIVCDPNBOESPJE"OESPJE$MFBO"SDIJUFDUVSF״׶
  6. ˖ EPNBJOךהֿ׹׾׍ׯ׿הⴓֽגծ
 ׉ך鿇ⴓחؽآطأٗآحָؙ剅ֽ׷ ˖ ׉׸ז׶ח⢪׻׸גְ׷孡ָׅ׷կ ˖ ㉏겗挿 ˖ %SPJE,BJHJך鋉垷ח׃גכ麓ⶱד֮׷孡ָׅ׷ ˖

    孡鯪חכ؝ٝزٔؽُ٦ءّٝדֹזְ孡ָׅ׷ ˖ 罋ִ倯׾《׶Ⰵ׸׷ךכְְ孡ָׅ׷ $MFBO"SDIJUFDUVSF "1*זוךٖأهٝأ׾׉ךתת⢪׻׆
 وحؾؚٝ׃ג،فٔⰻדכ
 ֹ׸ְז&OUJUZ׾⢪ְ׋ְ ̔ IUUQTHJUIVCDPNBOESPJE"OESPJE$MFBO"SDIJUFDUVSF״׶
  7. ˖ 3FEVY荈⡤כ׍ׯ׿הٍؗحث،حفדֹגְזְ ˖ ˑ.BOBHJOH4UBUFXJUI3Y+BWBCZ+BLF8IBSUPO˒דַז׶ 铡僇ָ֮׏׋կ ˖ 㹋鄲׮鑐׫׋ָ䮲䫓կկ 3FEVY @CheckResult fun

    <T> Observable<T>.toResult(schedulerProvider: SchedulerProvider): Observable<Result<T>> { return compose { item -> item .map { Result.success(it) } .onErrorReturn { e -> Result.failure(e.message ?: "unknown", e) } .observeOn(schedulerProvider.ui()) .startWith(Result.inProgress()) } } ̔3FTVMUך⡲׶倯כ⿫罋חז׶׉ֲ
  8. ˖ ٓ؎ؿ؟؎ؙٕꟼ鸬ך➬穈׫ָⰅ׶ծ
 ٓ؎ؿ؟؎ؙٕ׾֮ת׶䠐陎ׇ׆ח
 㹋鄲דֹ׷ ˖ 3PPN׮㉏겗זֻ⢪ִ׉ֲ ˖ ㉏겗挿 ˖ -JWF%BUBדכ-JWF%BUBず㡦׾穈׫さ׻ׇ

    ׷3Y+BWBדְֲ[JQך״ֲז⹛⡲ָ㣐㢌 "SDIJUFDUVSF$PNQPOFOU IUUQTEFWFMPQFSBOESPJEDPNUPQJDMJCSBSJFTBSDIJUFDUVSFHVJEFIUNM״׶
  9. ˖ ٓ؎ؿ؟؎ؙٕꟼ鸬ך➬穈׫ָⰅ׶ծ
 ٓ؎ؿ؟؎ؙٕ׾֮ת׶䠐陎ׇ׆ח
 㹋鄲דֹ׷ ˖ 3PPN׮㉏겗זֻ⢪ִ׉ֲ ˖ ㉏겗挿 ˖ -JWF%BUBדכ-JWF%BUBず㡦׾穈׫さ׻ׇ

    ׷3Y+BWBדְֲ[JQך״ֲז⹛⡲ָ㣐㢌 "SDIJUFDUVSF$PNQPOFOU ̔7JFX.PEFM -JWF%BUB 3PPNכⵃ欽ׅ׷ָ3Y+BWB׾⢘欽 IUUQTEFWFMPQFSBOESPJEDPNUPQJDMJCSBSJFTBSDIJUFDUVSFHVJEFIUNM״׶
  10. -JWF%BUBך.VUBCJMJUZך盖椚 "DUJWJUZ'SBHNFOUַ׵-JWF%BUBךWBMVF׾ְׄ׸זְ״ֲחׅ׷ class SearchViewModel @Inject ...{ private val mutableResult =

    MutableLiveData<Result<SearchResult>>() val result: LiveData<Result<SearchResult>> = mutableResult ... mutableResult.value = it
  11. .BQQFSָ葺ַ׏׋ ˖ 㛇劤涸ח鋅׋湡 1SFTFOUBUJPO鿇ⴓ חꟼׅ׷13װ何⥜ָ㢳ַ׏׋ךדծ
 7JFXワ׶ָ笺뜧חדֹגծ嚂חꟚ涪דֹגְ׷׏שַ׏׋ ˖ .PEFMחⳢ椚׾㺔ׇ׷ֿהדծ⡂׋״ֲזⳢ椚׾׋ֻׁ׿ך㜥䨽ד剅ַזֻג״ַ׏׋ class Session(

    open val id: String, open val dayNumber: Int, open val startTime: Date, open val endTime: Date ) { ... val isOnGoing: Boolean get() = System.currentTimeMillis() in startTime.time..endTime.time
  12. 7JFX.PEFMⰻדծוֿתד׾3Y+BWBד וֿתד׾-JWF%BUBד剅ַֻ㉏겗 ˖ ずؙׄٓأⰻח֮׏גծ㞮歲ָ切僳דծו׏׍דוךּ׵ְ剅ַֻךهٔ ء٦ָזַ׏׋կ ˖ 㛇劤涸חכ3Y+BWBךקֲָさ䧭הַ䖤䠐זכ׆זךדծ׉׏׍ח㺔ׇגְ ֹ׋ְָծ-JWF%BUBָ埆חְ׷ה⢪ְ׋ֻז׏גֻ׷ val sessions:

    LiveData<Result<List<Session>>> by lazy { repository.sessions .toResult(schedulerProvider) .toLiveData() } val isLoading: LiveData<Boolean> by lazy { sessions.map { it.inProgress } } ... ֿ̔׸׮刿倜ה朐䡾׾䭯אהֿ׹ָⴽղז׵ծז׿הַז׏׋ַ׮