This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class RepositoryModule extends Module { | |
| public RepositoryModule() { | |
| bind(UserRepository.class); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class RepositoryModule extends Module { | |
| public RepositoryModule(Context context) { | |
| bind(UserRepository.class); | |
| SharedPreferences sharedPreferences = context.getSharedPreferences("app.prefs", MODE_PRIVATE); | |
| bind(SharedPreferences.class).toInstance(sharedPreferences); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class PrefUserRepository implements UserRepository { | |
| private final SharedPreferences sharedPreferences; | |
| @Inject | |
| public PrefUserRepository(SharedPreferences sharedPreferences) { | |
| this.sharedPreferences = sharedPreferences; | |
| } | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class RepositoryModule extends Module { | |
| public RepositoryModule(Context context) { | |
| bind(UserRepository.class).to(PrefUserRepository.class); | |
| ... | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class RepositoryModule extends Module { | |
| public RepositoryModule(Context context) { | |
| bind(UserRepository.class) | |
| .to(PrefUserRepository.class) | |
| .singleton(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class App extends Application { | |
| @Override | |
| public void onCreate() { | |
| super.onCreate(); | |
| Scope appScope = Toothpick.openScope("APP"); | |
| appScope.installModules(new RepositoryModule(getApplicationContext())); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class UserActivity extends AppCompatActivity { | |
| @Inject | |
| UserRepository userRepository; | |
| @Override | |
| protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| Scope appScope = Toothpick.openScope("APP"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class RepositoryModule extends Module { | |
| public RepositoryModule(Context context) { | |
| SharedPreferences sharedPreferences = context.getSharedPreferences("app.prefs", MODE_PRIVATE); | |
| bind(SharedPreferences.class).toInstance(sharedPreferences); | |
| bind(UserRepository.class) | |
| .to(PrefUserRepository.class) | |
| .singleton(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ханнес | |
| fun movieCell(listener : (Movie) -> Unit) = adapterDelegateLayoutContainer<Movie, RecyclerItem>(R.layout.item_movie) { | |
| itemView.setClickListener { listener.invoke(item) } | |
| bind { diffPayloads -> | |
| name.text = item.name | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Допустим, у вас есть интерфейс ProjectRepository, его реализация ProjectServerRepository. | |
| // И вы хотите забиндить интерфейс к реализации. | |
| public class ProjectServerRepository implements ProjectRepository { | |
| @Inject | |
| public ProjectServerRepository(Context context) {...} | |
| } | |
| public class MyModule extends Module { |