Skip to content

Commit b2cf969

Browse files
Merge branch 'feature/home-module-di' into develop
2 parents 3bb1a39 + 020d372 commit b2cf969

8 files changed

Lines changed: 168 additions & 19 deletions

File tree

features/home/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616

1717
defaultConfig {
1818

19-
applicationId = "com.smarttoolfactory.account"
19+
applicationId = "com.smarttoolfactory.home"
2020

2121
minSdkVersion(AndroidVersion.MIN_SDK_VERSION)
2222
targetSdkVersion(AndroidVersion.TARGET_SDK_VERSION)
@@ -65,14 +65,14 @@ dependencies {
6565
implementation(Deps.APPCOMPAT)
6666
implementation(Deps.MATERIAL)
6767
implementation(Deps.CONSTRAINT_LAYOUT)
68+
implementation(Deps.RECYCLER_VIEW)
69+
implementation(Deps.VIEWPAGER2)
70+
implementation(Deps.SWIPE_REFRESH_LAYOUT)
6871

6972
// Glide
7073
implementation(Deps.GLIDE)
7174
kapt(Deps.GLIDE_COMPILER)
7275

73-
// Lottie
74-
implementation(Deps.LOTTIE)
75-
7676
// Unit Tests
7777
addUnitTestDependencies()
7878
testImplementation(project(Modules.AndroidLibrary.TEST_UTILS))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.smarttoolfactory.home.di
2+
3+
import androidx.fragment.app.Fragment
4+
import com.smarttoolfactory.core.di.CoreModuleDependencies
5+
import com.smarttoolfactory.home.propertylist.PropertyListFlowFragment
6+
import com.smarttoolfactory.home.propertylist.PropertyListRxjava3Fragment
7+
import dagger.BindsInstance
8+
import dagger.Component
9+
10+
@Component(
11+
dependencies = [CoreModuleDependencies::class],
12+
modules = [HomeModule::class]
13+
)
14+
interface HomeComponent {
15+
16+
fun inject(fragment: PropertyListFlowFragment)
17+
fun inject(fragment: PropertyListRxjava3Fragment)
18+
19+
@Component.Factory
20+
interface Factory {
21+
fun create(
22+
dependentModule: CoreModuleDependencies,
23+
@BindsInstance fragment: Fragment
24+
): HomeComponent
25+
}
26+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.smarttoolfactory.home.di
2+
3+
import androidx.fragment.app.Fragment
4+
import androidx.lifecycle.ViewModelProvider
5+
import com.smarttoolfactory.home.viewmodel.PropertyListFlowViewModelFactory
6+
import com.smarttoolfactory.home.viewmodel.PropertyListRxJava3ViewModelFactory
7+
import com.smarttoolfactory.home.viewmodel.PropertyListViewModelFlow
8+
import com.smarttoolfactory.home.viewmodel.PropertyListViewModelRxJava3
9+
import dagger.Module
10+
import dagger.Provides
11+
import dagger.hilt.InstallIn
12+
import dagger.hilt.android.components.FragmentComponent
13+
import kotlinx.coroutines.CoroutineScope
14+
import kotlinx.coroutines.Dispatchers
15+
import kotlinx.coroutines.SupervisorJob
16+
17+
@InstallIn(FragmentComponent::class)
18+
@Module
19+
class HomeModule {
20+
21+
@Provides
22+
fun providePropertyListViewModelFlow(
23+
fragment: Fragment,
24+
factory: PropertyListFlowViewModelFactory
25+
) =
26+
ViewModelProvider(fragment, factory).get(PropertyListViewModelFlow::class.java)
27+
28+
@Provides
29+
fun providePropertyListViewModelRxJava3(
30+
fragment: Fragment,
31+
factory: PropertyListRxJava3ViewModelFactory
32+
) =
33+
ViewModelProvider(fragment, factory).get(PropertyListViewModelRxJava3::class.java)
34+
35+
@Provides
36+
fun provideCoroutineScope() = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob())
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.smarttoolfactory.home.propertylist
2+
3+
import android.os.Bundle
4+
import com.smarttoolfactory.core.di.CoreModuleDependencies
5+
import com.smarttoolfactory.core.ui.fragment.DynamicNavigationFragment
6+
import com.smarttoolfactory.home.R
7+
import com.smarttoolfactory.home.databinding.FragmentPropertyListBinding
8+
import com.smarttoolfactory.home.di.DaggerHomeComponent
9+
import com.smarttoolfactory.home.viewmodel.PropertyListViewModelFlow
10+
import dagger.hilt.android.EntryPointAccessors
11+
import javax.inject.Inject
12+
13+
class PropertyListFlowFragment : DynamicNavigationFragment<FragmentPropertyListBinding>() {
14+
15+
@Inject
16+
lateinit var viewModel: PropertyListViewModelFlow
17+
18+
override fun getLayoutRes(): Int = R.layout.fragment_property_list
19+
20+
override fun onCreate(savedInstanceState: Bundle?) {
21+
initCoreDependentInjection()
22+
super.onCreate(savedInstanceState)
23+
viewModel.getPropertyList()
24+
}
25+
26+
override fun bindViews() {
27+
super.bindViews()
28+
}
29+
30+
private fun initCoreDependentInjection() {
31+
32+
val coreModuleDependencies = EntryPointAccessors.fromApplication(
33+
requireActivity().applicationContext,
34+
CoreModuleDependencies::class.java
35+
)
36+
37+
DaggerHomeComponent.factory().create(
38+
dependentModule = coreModuleDependencies,
39+
fragment = this
40+
)
41+
.inject(this)
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.smarttoolfactory.home.propertylist
2+
3+
import android.os.Bundle
4+
import com.smarttoolfactory.core.di.CoreModuleDependencies
5+
import com.smarttoolfactory.core.ui.fragment.DynamicNavigationFragment
6+
import com.smarttoolfactory.home.R
7+
import com.smarttoolfactory.home.databinding.FragmentPropertyListBinding
8+
import com.smarttoolfactory.home.di.DaggerHomeComponent
9+
import com.smarttoolfactory.home.viewmodel.PropertyListViewModelRxJava3
10+
import dagger.hilt.android.EntryPointAccessors
11+
import javax.inject.Inject
12+
13+
class PropertyListRxjava3Fragment : DynamicNavigationFragment<FragmentPropertyListBinding>() {
14+
15+
@Inject
16+
lateinit var viewModel: PropertyListViewModelRxJava3
17+
18+
override fun getLayoutRes(): Int = R.layout.fragment_property_list
19+
20+
override fun onCreate(savedInstanceState: Bundle?) {
21+
initCoreDependentInjection()
22+
super.onCreate(savedInstanceState)
23+
viewModel.getPropertyList()
24+
}
25+
26+
override fun bindViews() {
27+
super.bindViews()
28+
}
29+
30+
private fun initCoreDependentInjection() {
31+
32+
val coreModuleDependencies = EntryPointAccessors.fromApplication(
33+
requireActivity().applicationContext,
34+
CoreModuleDependencies::class.java
35+
)
36+
37+
DaggerHomeComponent.factory().create(
38+
dependentModule = coreModuleDependencies,
39+
fragment = this
40+
)
41+
.inject(this)
42+
}
43+
}

features/home/src/main/res/layout/fragment_home.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919
app:layout_constraintTop_toTopOf="parent"
2020
app:layout_constraintVertical_bias="0.25" />
2121

22-
<com.airbnb.lottie.LottieAnimationView
23-
android:id="@+id/lavUnderConstruction"
24-
android:layout_width="0dp"
25-
android:layout_height="0dp"
26-
android:layout_marginTop="8dp"
27-
app:layout_constraintBottom_toBottomOf="parent"
28-
app:layout_constraintDimensionRatio="1:1"
29-
app:layout_constraintEnd_toEndOf="parent"
30-
app:layout_constraintStart_toStartOf="parent"
31-
app:layout_constraintTop_toBottomOf="@+id/tvTitle"
32-
app:layout_constraintVertical_bias="0.4"
33-
app:layout_constraintWidth_percent=".6"
34-
app:lottie_autoPlay="true"
35-
app:lottie_fileName="construction_process.json" />
3622

3723
</androidx.constraintlayout.widget.ConstraintLayout>
3824
</layout>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout>
3+
4+
<androidx.constraintlayout.widget.ConstraintLayout
5+
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
</androidx.constraintlayout.widget.ConstraintLayout>
9+
10+
</layout>

features/home/src/main/res/navigation/nav_graph_home.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@id/nav_graph_home"
66
app:moduleName="home"
7-
app:startDestination="@id/homeFragment">
7+
app:startDestination="@id/propertyListFlowFragment">
88

99
<fragment
1010
android:id="@+id/homeFragment"
1111
android:name="com.smarttoolfactory.home.HomeFragment"
1212
android:label="HomeFragment"
1313
tools:layout="@layout/fragment_home" />
14+
<fragment
15+
android:id="@+id/propertyListFlowFragment"
16+
android:name="com.smarttoolfactory.home.propertylist.PropertyListFlowFragment"
17+
android:label="PropertyListFlowFragment" />
1418
</navigation>

0 commit comments

Comments
 (0)