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
fun mergeTwoSortedLists(L1: ListNode<Int>, L2: ListNode<Int>): ListNode<Int> { | |
println("merging $L1 and $L2") | |
val dummyHead = ListNode(Random.nextInt(), null) | |
var current = dummyHead | |
var p1 = L1 | |
var p2 = L2 | |
while (p1.next != null && p2.next != null) { | |
if (p1.data <= p2.data) { | |
current.next = p1 | |
p1 = p1.next!! |
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 SomeActivityModule { | |
@Provides | |
fun provideSomeRepository(): SomeRepository { | |
return SomeRepository() | |
} | |
@Provides | |
fun provideSomePrestener( | |
activity: SomeActivity, |
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 SomeActivityModule { | |
//... | |
@Provides | |
fun provideSomePrestener(profileRepository: ProfileRepository, someRepository: SomeRepository): SomePresenter { | |
return SomePresenter(profileRepository, someRepository) | |
} | |
} |
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 SomePresenter @Inject constructor( | |
val profileRepository: ProfileRepository, | |
val someRepository: SomeRepository | |
) { | |
fun doSomeWork() { | |
println("doSomeWork") | |
} | |
} |
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 SomeActivity : DaggerAppCompatActivity() { | |
@Inject | |
lateinit var profileRepository: ProfileRepository | |
@Inject | |
lateinit var someRepository: SomeRepository | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
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(includes = [CommonRepositoryModule::class]) | |
abstract class AppModule { | |
/** | |
* Connect SomeActivity's sub-graph to the App's Dependency Graph | |
*/ | |
@ContributesAndroidInjector(modules = [SomeActivityModule::class]) // HERE | |
abstract fun contributeSomeActivity() : SomeActivity | |
} |
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 SomeActivityModule { | |
@Provides | |
fun provideSomeRepository(): SomeRepository { | |
return SomeRepository() | |
} | |
} |
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 SomeActivity : DaggerAppCompatActivity { | |
@Inject lateinit var profileRepository: ProfileRepository | |
fun onCreate() { | |
//... | |
presenter = SomePresenter(profileRepository, ...) | |
presenter.doSomeWork() | |
} | |
} |
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(includes = [CommonRepositoryModule::class]) | |
abstract class AppModule { | |
/** | |
* Connect SomeActivity's sub-graph to the App's Dependency Graph | |
*/ | |
@ContributesAndroidInjector(modules = [SomeActivityModule::class]) | |
abstract fun contributeSomeActivity() : SomeActivity | |
} |
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 CommonRepositoryModule { | |
@Provides | |
fun providesProfileRepository(): ProfileRepository { | |
return ProfileRepository() | |
} | |
} |