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 void loginMethod(String name, String password){ | |
if (isEmpty(name)) { | |
editName.setError("Username is empty"); | |
return; | |
} | |
if (isEmpty(password)) { | |
editPasword.setError("Password is empty"); | |
return; | |
} |
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
class MainActivity : DaggerAppCompatActivity(), RepositoryRecyclerViewAdapter.OnItemClickListener { | |
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
val viewModel = ViewModelProviders.of(this, viewModelFactory) | |
.get(MainViewModel::class.java) | |
... |
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
@Module | |
internal abstract class MainActivityModule { | |
@ContributesAndroidInjector | |
internal abstract fun mainActivity(): MainActivity | |
@Binds | |
@IntoMap | |
@ViewModelKey(MainViewModel::class) | |
abstract fun bindMainViewModel(viewModel: MainViewModel): ViewModel |
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
class MainViewModel @Inject constructor(var gitRepoRepository: GitRepoRepository) : ViewModel() { | |
... | |
} |
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
@Singleton | |
@Component( | |
modules = [AndroidSupportInjectionModule::class, | |
AppModule::class, | |
ViewModelBuilder::class, | |
MainActivityModule::class]) | |
interface AppComponent : AndroidInjector<ModernApplication> { | |
@Component.Builder | |
abstract class Builder : AndroidInjector.Builder<ModernApplication>() |
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
@Component( | |
modules = [AndroidSupportInjectionModule::class, | |
AppModule::class, | |
MainActivityModule::class]) | |
interface AppComponent : AndroidInjector<ModernApplication> { | |
@Component.Builder | |
abstract class Builder : AndroidInjector.Builder<ModernApplication>() | |
} |
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
@Module | |
internal abstract class ViewModelBuilder { | |
@Binds | |
internal abstract fun bindViewModelFactory(factory: DaggerAwareViewModelFactory): | |
ViewModelProvider.Factory | |
} |
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
class DaggerAwareViewModelFactory @Inject constructor( | |
private val creators: @JvmSuppressWildcards Map<Class<out ViewModel>, Provider<ViewModel>> | |
) : ViewModelProvider.Factory { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
var creator: Provider<out ViewModel>? = creators[modelClass] | |
if (creator == null) { | |
for ((key, value) in creators) { | |
if (modelClass.isAssignableFrom(key)) { | |
creator = value |
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
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) | |
@Retention(AnnotationRetention.RUNTIME) | |
@MapKey | |
annotation class ViewModelKey(val value: KClass<out ViewModel>) |
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
class MainActivity : DaggerAppCompatActivity(), RepositoryRecyclerViewAdapter.OnItemClickListener { | |
... | |
@Inject lateinit var mainViewModelFactory: MainViewModelFactory | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val viewModel = ViewModelProviders.of(this, mainViewModelFactory) | |
.get(MainViewModel::class.java) | |
... |
NewerOlder