This file contains 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 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 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 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 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 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"); | |
} | |
} |
This file contains 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); | |
This file contains 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 UserRepository { | |
private final SharedPreferences sharedPreferences; | |
@Inject | |
public UserRepository(SharedPreferences sharedPreferences) { | |
this.sharedPreferences = sharedPreferences; | |
} | |
// ... |
This file contains 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 { | |
private UserRepository userRepository; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
userRepository = new UserRepository(getSharedPreferences("app.prefs", MODE_PRIVATE)); | |
} | |
} |
This file contains 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 UserRepository { | |
private final SharedPreferences sharedPreferences; | |
public UserRepository(SharedPreferences sharedPreferences) { | |
this.sharedPreferences = sharedPreferences; | |
} | |
public User getUser() { | |
// ... |