Skip to content

Instantly share code, notes, and snippets.

@matzuk
Last active February 10, 2019 14:01
Show Gist options
  • Save matzuk/2ecf7aac1dbb36a8e7b2fca93055fb0f to your computer and use it in GitHub Desktop.
Save matzuk/2ecf7aac1dbb36a8e7b2fca93055fb0f to your computer and use it in GitHub Desktop.
@Component(modules = {
ScannerFeatureModule.class,
ScreenNavigationModule.class
// ScannerFeatureDependencies - api of Scanner feature dependencies
}, dependencies = ScannerFeatureDependencies.class)
@PerFeature
// ScannerFeatureApi - api of Scanner feature
public abstract class ScannerFeatureComponent implements ScannerFeatureApi {
private static volatile ScannerFeatureComponent sScannerFeatureComponent;
// classic Singleton
public static ScannerFeatureApi initAndGet(
ScannerFeatureDependencies scannerFeatureDependencies) {
if (sScannerFeatureComponent == null) {
synchronized (ScannerFeatureComponent.class) {
if (sScannerFeatureComponent == null) {
sScannerFeatureComponent = DaggerScannerFeatureComponent.builder()
.scannerFeatureDependencies(scannerFeatureDependencies)
.build();
}
}
}
return sScannerFeatureComponent;
}
// this method is used in Scanner module to inject necessary dependencies
public static ScannerFeatureComponent get() {
if (sScannerFeatureComponent == null) {
throw new RuntimeException(
"You must call 'initAndGet(ScannerFeatureDependenciesComponent
scannerFeatureDependenciesComponent)' method"
);
}
return sScannerFeatureComponent;
}
// reset feature Component (when Scanner Activity is destroying)
public void resetComponent() {
sScannerFeatureComponent = null;
}
public abstract void inject(ScannerActivity scannerActivity);
// more comfortable initializing of Presenters for using in Moxy
public abstract ScannerScreenComponent scannerScreenComponent();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment