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
artistAdapter = ArtistAdapter(this@ChartIndexFragment, R.layout.item_artist_type_1, artistRes) { holder, item, _ -> | |
// If a ViewModel doesn't exist, I will create a ViewModel. | |
if (null == holder.binding.avm) | |
holder.binding.avm = RecyclerViewSearchArtistChartViewModel(item) | |
// Otherwise, I just reset the data to the ViewModel. | |
else | |
holder.binding.avm?.setArtistItem(item) | |
} |
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
artistAdapter = ArtistAdapter(this@fragment, R.layout.item_artist_type_1, artistRes) { holder, item, _ -> | |
// !! The problem will happen here. | |
// The ViewModel will be created again and again. | |
holder.binding.avm = RecyclerViewSearchArtistChartViewModel(item) | |
} |
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 ActivityModule { | |
@Provides | |
@PerActivity | |
fun provideNavigator(): Navigator = Navigator() | |
@Provides | |
@PerActivity | |
fun provideMainPresenter(): MainContract.Presenter = MainPresenter() | |
} |
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 = arrayOf(AppModule::class)) | |
interface AppComponent { | |
object Initializer { | |
fun init(app: App): AppComponent = DaggerAppComponent.builder() | |
.appModule(AppModule(app)) | |
.netModule(NetModule(app)) | |
.build() | |
} |
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 App: Application() { | |
companion object { | |
lateinit private var context: Context | |
@JvmStatic fun appComponent(): AppComponent = (context as App).appComponent | |
// Provide the global application context. | |
@JvmStatic fun getAppContext(): Context = context | |
} | |
// Before dagger 2.11 |
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
{"lastUpload":"2017-11-27T08:31:15.832Z","extensionVersion":"v2.8.6"} |
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 | |
class FragmentMainModule { | |
@Provides | |
@PerFragment | |
fun provideMainPresenter(usecase: CreateFakeUseCase): MainContract.Presenter = MainPresenter(usecase) | |
@Provides | |
@PerFragment | |
fun provideUsecase(threadExecutor: ThreadExecutor, | |
postExecutionThread: PostExecutionThread, |
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 | |
abstract class BindingFragmentModule { | |
@PerFragment | |
@ContributesAndroidInjector(modules = arrayOf(FragmentMainModule::class)) | |
abstract fun contributeMainFragmentInjector(): MainFragment | |
} |
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 | |
abstract class BindingActivityModule { | |
/** | |
* ContributesAndroidInjector is including fragment injector. Only putting FragmentBindModule in modules array, | |
* the children fragment can obtain the parent's fragment injector. | |
*/ | |
@PerActivity | |
@ContributesAndroidInjector(modules = arrayOf(BindingFragmentModule::class)) | |
abstract fun contributeMainActivityInjector(): MainActivity | |
} |
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 | |
class AppModule { | |
@Provides | |
@Singleton | |
fun provideApplication(app: App): Application = app | |
@Provides | |
@Singleton | |
fun provideAppContext(app: App): Context = app.applicationContext | |
} |
NewerOlder