Skip to content

Commit d3a9bdd

Browse files
committed
Refactor & polish code
1 parent 82c5eb2 commit d3a9bdd

File tree

6 files changed

+12
-31
lines changed

6 files changed

+12
-31
lines changed

app/src/main/java/cz/skywall/multimoduleexample/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class App : Application() {
2626

2727
applicationComponent.inject(this)
2828

29-
// check if everything injected properly
29+
// Just a check if everything injected properly. Do not use runBlocking { } on a main thread!
3030
sharedPreferences.all
3131
runBlocking {
3232
val user = apiService.getUser()

app/src/main/java/cz/skywall/multimoduleexample/SplashFragment.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

common/src/main/java/cz/skywall/multimoduleexample/common/SingletonHolder.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package cz.skywall.multimoduleexample.common
22

33
open class SingletonHolder<out T, in A>(private val constructor: (A) -> T) {
44

5-
@Volatile
6-
private var instance: T? = null
5+
@Volatile private var instance: T? = null
76

87
fun getInstance(arg: A): T {
98
return when {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package cz.skywall.multimoduleexample.home.data.repository
22

3-
class DummyRepository2
3+
class HomeDummyRepository

home/src/main/java/cz/skywall/multimoduleexample/home/injection/HomeInjection.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cz.skywall.multimoduleexample.home.injection
22

33
import android.app.Application
44
import cz.skywall.multimoduleexample.core.injection.CoreComponent
5-
import cz.skywall.multimoduleexample.home.data.repository.DummyRepository2
5+
import cz.skywall.multimoduleexample.home.data.repository.HomeDummyRepository
66
import cz.skywall.multimoduleexample.home.ui.home.HomeFragmentComponent
77
import cz.skywall.multimoduleexample.home.ui.home.HomeFragmentModule
88
import dagger.Component
@@ -30,8 +30,9 @@ interface HomeComponent {
3030

3131
@Module
3232
class HomeModule {
33+
3334
@Provides
34-
fun dummyRepository2(application: Application): DummyRepository2 {
35-
return DummyRepository2()
35+
fun homeDummyRepository(application: Application): HomeDummyRepository {
36+
return HomeDummyRepository()
3637
}
3738
}

home/src/main/java/cz/skywall/multimoduleexample/home/ui/home/HomeFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import cz.skywall.multimoduleexample.common.R as CR
1313
import cz.skywall.multimoduleexample.R as AR
1414
import cz.skywall.multimoduleexample.home.base.BaseFragment
1515
import cz.skywall.multimoduleexample.home.data.repository.DummyRepository
16-
import cz.skywall.multimoduleexample.home.data.repository.DummyRepository2
16+
import cz.skywall.multimoduleexample.home.data.repository.HomeDummyRepository
1717
import cz.skywall.multimoduleexample.network.ApiService
1818
import kotlinx.android.synthetic.main.fragment_home.*
1919
import javax.inject.Inject
@@ -24,7 +24,7 @@ class HomeFragment : BaseFragment(), HomeView {
2424
@Inject lateinit var sharedPreferences: SharedPreferences
2525
@Inject lateinit var apiService: ApiService
2626
@Inject lateinit var dummyRepository: DummyRepository
27-
@Inject lateinit var dummyRepository2: DummyRepository2
27+
@Inject lateinit var homeDummyRepository: HomeDummyRepository
2828

2929
override fun inject() {
3030
homeComponent.plus(HomeFragmentModule(this)).inject(this)
@@ -42,10 +42,12 @@ class HomeFragment : BaseFragment(), HomeView {
4242
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
4343
requireActivity().startService(Intent(requireActivity(), DummyService::class.java))
4444

45+
// Check if everything injected properly by accessing instances.
4546
sharedPreferences.all
4647
dummyRepository.toString()
47-
dummyRepository2.toString()
48+
homeDummyRepository.toString()
4849
homeAdapter.toString()
50+
apiService.toString()
4951

5052
combined_text.text =
5153
"""Combined:

0 commit comments

Comments
 (0)