$30 off During Our Annual Pro Sale. View Details »

droidkaigi2016

funnelbit
February 18, 2016

 droidkaigi2016

funnelbit

February 18, 2016
Tweet

More Decks by funnelbit

Other Decks in Technology

Transcript

  1. .PEVMF @Module 
 public class MainModule { ... @Provides
 EntryManager

    provideEntryManager() { return new EntryManager(mService); } ...
  2. *OKFDU public class MainActivity extends AppCompatActivity { @Inject EntryManager mEntryManager;

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

    provideEntryManager() { return new EntryManager(mStubService); } ...
  4. *OKFDU ςετ public class EntryManagerTestCase extends InstrumentationTestCase {
 …
 @Inject


    EntryManager mEntryManager;
 … public testGetEntries() { assertEquals( "ΤϯτϦऔಘͰ͖͍ͯΔ", false, mEntryManager.getEntries().isEmpty()); }
 }
  5. 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); }
  6. 4VC$PNQPOFOU @Subcomponent(modules = UserModule.class)
 public interface UserComponent {
 
 //

    Fragments
 void inject(MyFragment myFragment);
 
 UserController userController();
 }
  7. $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); }
  8. "DUJWJUZੜ੒࣌ʹҾ͘ public class MainActivity extends AppCompatActivity { … public void

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

    = entries;
 mRealmChangeListener = new RealmChangeListener() {
 @Override
 public void onChange() {
 mListItems = getItems();
 EpisodesAdapter.this.notifyDataSetChanged();
 }
 }; …
 } …
  10. "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);
 } …
  11. %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(); … } …
  12. 4UVC4FSWFS SFTPVSDFMPHJO@SFRVFTU\ UZQFPCKFDU  EFTDSJQUJPOϩάΠϯϦΫΤετ  QSPQFSUJFT\ FNBJM@BEESFTT\ UZQFTUSJOH 

    EFTDSJQUJPOϝʔϧΞυϨε  FYBNQMFBCD!FYBNQMFDPN  ^  QBTTXPSE\ UZQFTUSJOH  EFTDSJQUJPObύεϫʔυ  FYBNQMF1BTTXSE  ^  ^  SFRVJSFE<FNBJM@BEESFTT QBTTXPSE>  ^
  13. GBTUMBOF 4MBDL࿈ܞ TMBDL  NFTTBHFSPDLFUϏϧυ͕׬ྃ͠·ͨ͠SPDLFU  DIBOOFMBQQ  TVDDFTTUSVF 

    QBZMPBE\ #VJME%BUF5JNFOFXUP@T  ^  EFGBVMU@QBZMPBET<HJU@CSBODI HJU@BVUIPS>
  14. ·ͱΊ w ϑϨʔϜϫʔΫ͔ΒϩδοΫΛ੾Γ཭͢ w ϩδοΫͷந৅Խɺ%BHHFSͰ*OKFDU w ӬଓԽ w 3FBMNΛར༻ w

    αʔόαΠυͱฒߦͨ͠։ൃ w 4UVC4FSWFSΛར༻ w ϓϩμΫτνΣοΫ w #FUB#Z$SBTIMZUJDT KFOLJOT GBTUMBOF