Skip to content

Instantly share code, notes, and snippets.

Avatar
Coffee coffee

Jaewoong Eum skydoves

Coffee coffee
View GitHub Profile
View PreferenceComponent_Example.java
@PreferenceComponent(entities = {Profile.class, Device.class})
public interface UserProfileComponent {
}
View PreferenceComponent_UserProfileComponent.java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
PreferenceComponent_UserProfileComponent.init(this);
}
}
View PreferenceComponent_Example2.java
Preference_UserProfile userProfile = PreferenceComponent_UserProfileComponent.getInstance().UserProfile();
Preference_UserDevice userDevice = PreferenceComponent_UserProfileComponent.getInstance().UserDevice();
View PreferenceRoom_Injection1.java
/**
* Component integrates entities.
*/
@PreferenceComponent(entities = {Profile.class, Device.class})
public interface UserProfileComponent {
/**
* declare dependency injection targets.
*/
void inject(MainActivity __);
void inject(LoginActivity __);
View PreferenceRoom_Injection2.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PreferenceComponent_UserProfileComponent.getInstance().inject(this);
}
View PreferenceRoom_Injection3.java
@InjectPreference
public PreferenceComponent_UserProfileComponent component;
@InjectPreference
public Preference_UserProfile userProfile;
View PreferenceRoom_kotlin_setting.java
apply plugin: 'kotlin-android'
kapt {
correctErrorTypes = true
}
View PreferenceRoom_kotlin1.kt
@PreferenceComponent(entities = arrayOf(Profile::class, Device::class))
interface UserProfileComponent {
/**
* declare dependency injection targets.
*/
fun inject(target: MainActivity)
fun inject(target: LoginActivity)
}
View PreferenceRoom_kotlin2.kt
@InjectPreference
lateinit var component: PreferenceComponent_UserProfileComponent
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
PreferenceComponent_UserProfileComponent.getInstance().inject(this) // inject dependency injection to MainActivity.
View AppViewModelFactory.java
@Singleton
public class AppViewModelFactory implements ViewModelProvider.Factory {
private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators;
@Inject
public AppViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
this.creators = creators;
}
@SuppressWarnings("unchecked")