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

droidkaigi2016

8928b5277aa7234dbca4ff782952343a?s=47 funnelbit
February 18, 2016

 droidkaigi2016

8928b5277aa7234dbca4ff782952343a?s=128

funnelbit

February 18, 2016
Tweet

Transcript

  1. %BHHFSͱ3FBMNΛ ར༻ͨ͠Ϟμϯͳ։ൃ ๺ଜɹྋ

  2. ࣗݾ঺հ w ๺ଜɹྋ w ͸ͯͳJEGVOOFMCJU w 5XJUUFSJEFYQFSPQFSP

  3. None
  4. ͸ͯͳϒοΫϚʔΫ

  5. ژ౎

  6. ࠓ೔࿩͢͜ͱ w ϑϨʔϜϫʔΫ͔ΒϩδοΫΛ੾Γ཭͢ w ӬଓԽ w αʔόαΠυͱฒߦͨ͠։ൃ w ϓϩμΫτνΣοΫ

  7. ϑϨʔϜϫʔΫ͔Βϩ δοΫΛ੾Γ཭͢

  8. ϑϨʔϜϫʔΫ w "OESPJE4%,͕ఏڙ͢ΔɺΞϓϦ΍ը໘ͷϥΠ ϑαΠΫϧͱڧ݁͘ͼ͍ͭͨΫϥε

  9. ϩδοΫΛͲ͜ʹॻ͔͘ w º"DUJWJUZ 'SBHNFOUʹ௚઀ॻ͘ w ංେԽɺςετෆՄೳ w ˛$VTUPN7JFXʹ௚઀ॻ͘ w 7JFXͷϩδοΫ͸͜͜ʹॻ͚͹ྑ͍

    w ͦΕҎ֎ͷ৔ॴ
  10. ͦΕҎ֎ͷ৔ॴʁ w ϩδοΫΛந৅Խͯ͠੾Γग़͢ w d$POUSPMMFS d.BOBHFSͳͲɺϩδοΫ୲౰ ΫϥεΛ࡞Δ

  11. ϩδοΫͷந৅ͷ*OTUBODFΛ Ͳ͜Ͱ࡞Δ͔ʁ w ˛ར༻͢Δ"DUJWJUZʹ௚઀ॻ͘ w ݁ͼ͖͕ͭڧ͘ͳΔ w ςετͷ࣌ʹڍಈΛม͍͑ͨͱ͖͸ʁ w ˓ར༻͢Δͷ֎෦Ͱੜ੒ɾ؅ཧ

    w ґଘͤ͞ͳ͍ w ςετ࣌ʹ͸੾Γସ͑Δɺͱ͍ͬͨ͜ͱ͕༰қ w %*
  12. ૉ๿ͳ%* public EntryManager(APIClient apiClient) { this.mAPIClient = apiClient;
 ... }

  13. ૉ๿ͳ%*࢖͑ͳ͍໰୊ w "DUJWJUZͱ'SBHNFOUʹରͯ͠͸ແྗ w ίϯετϥΫλͰΠϯελϯε౉ͤͳ͍ w 1BSDFMBCMFʹͯ͠ؤுΕ͹Ͱ͖ͳ͍͜ͱ͸ͳ͍͕ ؤுΓͨ͘ͳ͍ w ͜ͷ໰୊͸%*ίϯςφ͕͋Ε͹ղܾ͢Δ

  14. %*ίϯςφ w ґଘ஫ೖΛߦ͏ϑϨʔϜϫʔΫ w खಈͰ࢓૊ΈΛ༻ҙ͠ͳͯ͘ྑ͍ w Πϯελϯε؅ཧ΋ߦͳ͑Δ

  15. Ͳͷ%*ίϯςφΛ࢖͏΂͖ ͔ʁ w 3PCP(VJDF w %BHHFS w %BHHFS

  16. %BHHFS

  17. %BHHFS w IUUQTHJUIVCDPNHPPHMFEBHHFS w %*ίϯςφ w 4RVBSF͕։ൃͯͨ͠%BHHFSͷHPPHMFGPSL

  18. %BHHFSͷར఺ w ίϯύΠϧ࣌ʹίʔυੜ੒͠ґଘղܾ w ࣮ߦதͷύϑΥʔϚϯεʹӨڹ͠ͳ͍ w σόοάͰίʔυΛ௥͍΍͍͢

  19. %*ͷߏ੒ w .PEVMF w *OTUBODFͷੜ੒ํ๏Λهड़ w $PNQPOFOU w .PEVMF಺ͷ*OTUBODFΛͲ͜ʹJOKFDU͢Δ͔ه ड़

    w ֊૚ߏ଄Λ΋ͨͤͯ໾ׂΛ෼୲͠໌֬Խ
  20. .PEVMF @Module 
 public class MainModule { ... @Provides
 EntryManager

    provideEntryManager() { return new EntryManager(mService); } ...
  21. $PNQPOFOU @Component(modules = MainModule.class) public interface MainComponent { void inject(MainActivity

    mainActivity) …
  22. *OKFDU public class MainActivity extends AppCompatActivity { @Inject EntryManager mEntryManager;

    @Override 
 protected void onCreate(Bundle b) { ... ((App) getApplication()) .component() .inject(this); ...
  23. 5FTU༻.PEVMF @Module 
 public class MainTestModule { ... @Provides
 EntryManager

    provideEntryManager() { return new EntryManager(mStubService); } ...
  24. ςετ༻$PNQPOFOU @Component(modules = MainTestModule.class) public interface MainTestComponent { void inject(EntryManagerTestCase

    testCase) …
  25. *OKFDU ςετ public class EntryManagerTestCase extends InstrumentationTestCase {
 …
 @Inject


    EntryManager mEntryManager;
 … public testGetEntries() { assertEquals( "ΤϯτϦऔಘͰ͖͍ͯΔ", false, mEntryManager.getEntries().isEmpty()); }
 }
  26. $PNQPOFOUͷ෼͚ํ w "DUJWJUZ΍'SBHNFOUຖʹ෼͚Δʁ w ਺͕υϯυϯ૿͍͑ͯ͘ w ໾ׂ͝ͱʹ෼͚Δ w ֊૚ߏ଄Λ࡞ͬͯࡉ෼Խ

  27. 4VC$PNQPOFOU @Component(modules = MainModule.class)
 public interface MainComponent {
 void inject(App

    app);
 
 // Activities
 void inject(RootActivity rootActivity);
 
 // Fragments
 void inject(MainSettingsFragment mainSettingsFragment);
 
 // Subcomponents
 UserComponent userComponent(UserModule userModule); }
  28. 4VC$PNQPOFOU @Subcomponent(modules = UserModule.class)
 public interface UserComponent {
 
 //

    Fragments
 void inject(MyFragment myFragment);
 
 UserController userController();
 }
  29. $PNQPOFOUΛऔಘ public class MyFragment extends Fragment { MainComponent mainComponent =

    App.get(getActivity())
 .getMainComponent(); 
 UserComponent userComponent = mainComponent.userComponent( new UserModule( mainComponent.getRealm(), args.getString(ARGS_USER_ID)));
 userComponent.inject(this); }
  30. ӬଓԽ

  31. ӬଓԽ͢Δ໨త w 8FC"1*͔ΒͷϨεϙϯεΛӬଓԽ w ΦϑϥΠϯ༻ͷΩϟογϡσʔλͷͨΊ w "DUJWJUZ΍'SBHNFOUͷ࠶ੜ੒࣌ʹ෮ؼ͢ΔͨΊ w ෳ਺ͷը໘Ͱಉ͡σʔλΛදࣔ͢Δͱ͖ͷҰ؏ ੑΛอͪ΍͘͢͢ΔͨΊ

  32. ӬଓԽ͢Δखஈ w º4IBSFE1SFGFSFODFTʹೖΕΔ w ˛'JMFʹॻ͖ͩ͢ w ˓42-JUFʹೖΕΔ w ˓3FBMNΛ࢖͏

  33. 42-JUF w "OESPJEඪ४ͳͷͰ҆৺ײ͕͋Δ w ࣗྗͰॻ͘ͷ͸গʑ໘౗͍͘͞ w 03.࢖͏ʁ w ࢖͍΍͢͞ɺૣ͞ɺ҆ఆɺকདྷੑʜ

  34. 3FBMN w ։ൃ͕׆ൃ w 42-JUFͷΑ͏ͳ໘౗ͳ͜ͱΛ͠ͳͯ͘ྑ͍ w ˛όʔδϣϯະຬ

  35. 3FBMNΛ࢖͏ w J04ΞϓϦͱ ՄೳͳݶΓ ڞ௨ͷϞσϧΛ࣋ͪͨ ͍ͨΊ w ։ൃ׆ൃ͔ͩΒԿ͔͋ͬͯ΋ରॲ͞ΕΔͰ͋Ζ ͏

  36. 3FBMN

  37. 3FBMN w 42-JUFΛஔ͖׵͑͏Δ.PCJMFEBUBCBTF w 03.ͷػೳ΋࣋ͭ w ߴ଎ w J04Ͱ΋ར༻Մೳ

  38. 3FBMNΛ࢖͏ new RealmConfiguration.Builder(context)
 .name("realm")
 .schemaVersion(1L)
 .build();

  39. 3FBMNΛ࢖͏ RealmResults<Entry> followingEntries = mRealm.where(Entry.class) .equalTo("isFollowing",true) .findAllSortedAsync( "createdAt", Sort.DESCENDING);

  40. "DUJWJUZੜ੒࣌ʹҾ͘ public class MainActivity extends AppCompatActivity { … public void

    onCreate(Bundle savedInstanceState) { mRealmResults = mRealm.where().findAllAsync() … } w ͙͢͞·3FBMN3FTVMUTΛಘΔ w ਖ਼͘͠෮ݩ͢ΔͨΊʹ΋࢖͏
  41. "EBQUFSʹ3FBMN3FTVMU public class EntriesAdapter { public EntriesAdapter(RealmResults<Entry> entries) {
 mEntries

    = entries;
 mRealmChangeListener = new RealmChangeListener() {
 @Override
 public void onChange() {
 mListItems = getItems();
 EpisodesAdapter.this.notifyDataSetChanged();
 }
 }; …
 } …
  42. "EBQUFSʹ3FBMN3FTVMU public class EntriesAdapter { … @Override
 public void onAttachedToRecyclerView(RecyclerView

    recyclerView) {
 super.onAttachedToRecyclerView(recyclerView);
 mResults.addChangeListener(mRealmChangeListener);
 }
 
 @Override
 public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
 mResults.removeChangeListener(mRealmChangeListener);
 super.onDetachedFromRecyclerView(recyclerView);
 } …
  43. "DUJWJUZؒͷσʔλड͚౉͠ Intent intent = new Intent(context, EpisodeActivity.class); intent.putExtra(EXTRA_ID, Id); w

    3FBMNͷ*%Λ౉͢͜ͱʹͯ͠͠·͏ w ࠶ੜ੒ʹ΋උ͑ΕΔ͜ͱʹͳΔ
  44. 3FBMN Λ %BHHFS Ͱ εϨου͝ͱʹ*OKFDU

  45. εϨου·ͨ͛ͳ͍໰୊ w 3FBMN*OTUBODF͕࡞੒͞ΕͨεϨου͔Βଞͷ εϨουͰ࢖͑ͳ͍ w ͔͠͠*OKFDU͸PO$SFBUF Ͱߦ͍͍ͨ w ʮผεϨου͕ཉ͍࣌͠ʹ*OKFDU͢Δ࢓૊Έʯ͕ ඞཁ

  46. %BHHFSͷ1SPWJEFSΛ࢖͏ … @Inject public EntryPrefetcher(Provider<Realm> realmProvider) extends ThreadPoolExecutor { mRealmProvider

    = realmProvider; … private static class Task implements Callable<String> { @Override
 public String call() throws Exception { Realm realm = mRealmProvider.get(); … } …
  47. αʔόαΠυ ͱ ฒߦͨ͠։ൃ

  48. αʔόαΠυͱฒߦͨ͠։ൃ w "1*͕ඞͣ͠΋ઌߦ͢Δͱ͸ݶΒͳ͍ w μϛʔσʔλΛΞϓϦ಺෦ʹ͔࣋ͭʁ w "1*ʹมߋ͕͋ͬͨ࣌ʹ໘౗ w J04ଆ΋ಉ࣌ʹมߋ͢Δඞཁ͕ग़ͯ͘Δ

  49. 4UVC4FSWFS

  50. 4UVC4FSWFS w μϛʔͷϨεϙϯεΛฦ͢αʔόΛ࡞Δ w "1*4DIFNB όϦσʔλͱͯ͠ར༻  w IUUQTHJUIVCDPNIJUPEF"1*4DIFNB

  51. 4UVC4FSWFS SFTPVSDFMPHJO@SFRVFTU\ UZQFPCKFDU  EFTDSJQUJPOϩάΠϯϦΫΤετ  QSPQFSUJFT\ FNBJM@BEESFTT\ UZQFTUSJOH 

    EFTDSJQUJPOϝʔϧΞυϨε  FYBNQMFBCD!FYBNQMFDPN  ^  QBTTXPSE\ UZQFTUSJOH  EFTDSJQUJPObύεϫʔυ  FYBNQMF1BTTXSE  ^  ^  SFRVJSFE<FNBJM@BEESFTT QBTTXPSE>  ^
  52. ςετͰ΋4UVC4FSWFSΛ ࢖͏ w ˛μϛʔͷ+40/Λ಺෦ʹ࣋ͬͯςετʹར༻ w "1*มΘΔͨͼʹมߋͤͶ͹ͳΒͳ͍ w "1*ͷมߋʹςετ͕ؾ෇͚ͳ͍ w ̋"1*ͷαʔόΛ௚઀ୟ͘

    w μϛʔσʔλෆཁ w มߋʹςετ͕ؾ͕ͭ͘
  53. ϓϩμΫτνΣοΫ

  54. ϓϩμΫτνΣοΫ w ژ౎ɾ౦ژʹΦϑΟε͕͋Δ w ౦ژʹ΋σβΠφʔ͕͍Δ w ख৮Γ͸௚઀৮Εͳ͍ͱΘ͔Βͳ͍

  55. #FUB#Z$SBTIMZUJDT  KFOLJOT  GBTUMBOF

  56. #FUB w #FUB#Z$SBTIMZUJDTΛ࢖ͬͯ#FUB഑৴ w ഑৴ͷλΠϛϯά͸KFOLJOTʹ೚ͤΔ

  57. KFOLJOT w ϒϥϯνΛݟͯͯɺNBTUFSʹϚʔδ͞ΕͨΒ #FUBΛඈ͹͢ w εΫϦʔϯγϣοτΛࡱͬͯ؆қతͳσβΠϯ֬ ೝ w "1*ຖͷࠩҟ౳Λ֬ೝ w

    4MBDLʹ௨஌
  58. GBTUMBOF (JUIVC࿈ܞ EBUB\TUBUFTUBUF UBSHFU@VSMUBSHFU@VSM  DPOUFYUDPOUFYU EFTDSJQUJPO^ IFBEFST\"VUIPSJ[BUJPOUPLFO\UPLFO^^ &YDPOQPTU VSM

    IFBEFSTIFBEFST CPEZ EBUBUP@KTPO
  59. GBTUMBOF 4MBDL࿈ܞ TMBDL  NFTTBHFSPDLFUϏϧυ͕׬ྃ͠·ͨ͠SPDLFU  DIBOOFMBQQ  TVDDFTTUSVF 

    QBZMPBE\ #VJME%BUF5JNFOFXUP@T  ^  EFGBVMU@QBZMPBET<HJU@CSBODI HJU@BVUIPS>
  60. ςετ࣮ߦ EFTD3VOTBMMUIFUFTUT MBOFUFTUEP HSBEMF UBTLD$  FOE

  61. ·ͱΊ w ϑϨʔϜϫʔΫ͔ΒϩδοΫΛ੾Γ཭͢ w ϩδοΫͷந৅Խɺ%BHHFSͰ*OKFDU w ӬଓԽ w 3FBMNΛར༻ w

    αʔόαΠυͱฒߦͨ͠։ൃ w 4UVC4FSWFSΛར༻ w ϓϩμΫτνΣοΫ w #FUB#Z$SBTIMZUJDT KFOLJOT GBTUMBOF
  62. ͋Γ͕ͱ͏͍͟͝·ͨ͠