Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c212a4

Browse files
Merge tag 'v0.9.0' into develop
v0.9.0
2 parents bda8629 + 620894e commit 1c212a4

File tree

18 files changed

+250
-121
lines changed

18 files changed

+250
-121
lines changed

‎app/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,18 @@ android {
9898
Modules.DynamicFeature.POST_DETAIL,
9999
Modules.DynamicFeature.SEARCH
100100
)
101+
102+
testOptions {
103+
unitTests.isIncludeAndroidResources = true
104+
}
101105
}
102106

103107
dependencies {
104108

105109
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
106110

107111
implementation(project(Modules.AndroidLibrary.CORE))
108-
109112
implementation(project(Modules.AndroidLibrary.DOMAIN))
110-
// TODO Solve Why doesn't work when DATA module is not added to dagger Hilt?
111113
implementation(project(Modules.AndroidLibrary.DATA))
112114

113115
addAppModuleDependencies()

‎app/src/main/java/com/smarttoolfactory/postdynamichilt/di/AppModule.kt

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

‎app/src/main/java/com/smarttoolfactory/postdynamichilt/postlist/PostStatusViewModel.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import com.smarttoolfactory.core.viewstate.ViewState
1111
import com.smarttoolfactory.domain.model.Post
1212
import com.smarttoolfactory.domain.usecase.GetPostsWithStatusUseCaseFlow
1313
import kotlinx.coroutines.CoroutineScope
14-
import kotlinx.coroutines.flow.catch
1514
import kotlinx.coroutines.flow.launchIn
16-
import kotlinx.coroutines.flow.onCompletion
1715
import kotlinx.coroutines.flow.onEach
1816
import kotlinx.coroutines.flow.onStart
1917

@@ -71,18 +69,8 @@ class PostStatusViewModel @ViewModelInject constructor(
7169
.launchIn(coroutineScope)
7270
}
7371

74-
fun updatePostStatus(post: Post) {
72+
privatefun updatePostStatus(post: Post) {
7573
getPostsUseCase.updatePostStatus(post)
76-
.onStart { println("⏰ PostStatusViewModel updatePostStatus() catch() onStart") }
77-
.catch { throwable ->
78-
println("❌ PostStatusViewModel updatePostStatus() catch(): ${throwable.message}")
79-
}
80-
.onCompletion { cause: Throwable? ->
81-
println(
82-
"💀 PostStatusViewModel updatePostStatus() " +
83-
"onCompletion() error: ${cause != null}"
84-
)
85-
}
8674
.launchIn(coroutineScope)
8775
}
8876

@@ -91,8 +79,6 @@ class PostStatusViewModel @ViewModelInject constructor(
9179
}
9280

9381
override fun onClick(post: Post) {
94-
post.displayCount++
95-
updatePostStatus(post)
9682
_goToDetailScreen.value = Event(post)
9783
}
9884
}

‎build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33

4-
val kotlin_version by extra("1.4.0")
54
repositories {
65
google()
76
jcenter()
@@ -13,6 +12,7 @@ buildscript {
1312
classpath(kotlin("gradle-plugin", version = PluginVersion.KOTLIN_VERSION))
1413
classpath(Plugins.CLASSPATH_DAGGER_HILT)
1514
classpath(Plugins.CLASSPATH_KTLINT)
15+
classpath(Plugins.CLASSPATH_NAV_SAFE_ARGS)
1616
}
1717
}
1818

‎buildSrc/src/main/java/Dependencies.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ object Deps {
3636

3737
// Navigation Components
3838
const val NAVIGATION_FRAGMENT =
39-
"androidx.navigation:navigation-fragment:${Version.NAVIGATION_VERSION}"
40-
const val NAVIGATION_UI = "androidx.navigation:navigation-ui:${Version.NAVIGATION_VERSION}"
39+
"androidx.navigation:navigation-fragment-ktx:${Version.NAVIGATION_VERSION}"
40+
const val NAVIGATION_UI = "androidx.navigation:navigation-ui-ktx:${Version.NAVIGATION_VERSION}"
4141
const val NAVIGATION_RUNTIME =
4242
"androidx.navigation:navigation-runtime-ktx:${Version.NAVIGATION_VERSION}"
4343

‎buildSrc/src/main/java/Plugins.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ object Plugins {
1111
const val CLASSPATH_GRADLE = "com.android.tools.build:gradle:${PluginVersion.GRADLE_VERSION}"
1212
const val CLASSPATH_KTLINT =
1313
"org.jlleitschuh.gradle:ktlint-gradle:${PluginVersion.KTLINT_VERSION}"
14-
const val CLASSPATH_DAGGER_HILT = "com.google.dagger:hilt-android-gradle-plugin:${Version.DAGGER_HILT_VERSION}"
14+
const val CLASSPATH_DAGGER_HILT =
15+
"com.google.dagger:hilt-android-gradle-plugin:${Version.DAGGER_HILT_VERSION}"
16+
const val CLASSPATH_NAV_SAFE_ARGS =
17+
"androidx.navigation:navigation-safe-args-gradle-plugin:${PluginVersion.NAV_SAFE_ARGS_VERSION}"
1518

1619
/*
1720
Module Level

‎buildSrc/src/main/java/Version.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
object PluginVersion {
22
const val KOTLIN_VERSION = "1.4.0"
3-
const val GRADLE_VERSION = "4.1.0-rc01"
3+
const val GRADLE_VERSION = "4.1.0-rc02"
44

5-
const val NAVIGATION_SAFE_ARGS = "2.3.0-alpha06"
5+
const val NAV_SAFE_ARGS_VERSION = "2.3.0"
66
const val KTLINT_VERSION = "9.3.0"
77
const val DETEKT_VERSION = "1.10.0"
88
}
@@ -19,21 +19,20 @@ object AndroidVersion {
1919

2020
object Version {
2121

22-
const val CORE_KTX_VERSION = "1.1.0"
23-
const val FRAGMENT_VERSION = "1.1.0-alpha07"
22+
const val CORE_KTX_VERSION = "1.3.1"
2423
const val FRAGMENT_KTX_VERSION = "1.1.0-rc01"
2524

2625
// Appcompat
27-
const val APPCOMPAT_VERSION = "1.1.0"
26+
const val APPCOMPAT_VERSION = "1.2.0"
2827

2928
// Material
3029
const val MATERIAL_VERSION = "1.3.0-alpha01"
3130

3231
// ConstraintLayout
33-
const val CONSTRAINT_LAYOUT_VERSION = "1.1.3"
32+
const val CONSTRAINT_LAYOUT_VERSION = "2.0.1"
3433

3534
// RecyclerView
36-
const val RECYCLER_VIEW_VERSION = "1.2.0-alpha01"
35+
const val RECYCLER_VIEW_VERSION = "1.2.0-alpha05"
3736

3837
// CardView
3938
const val CARD_VIEW_VERSION = "1.0.0"

‎features/post_detail/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ dependencies {
5858
implementation(project(Modules.APP))
5959
implementation(project(Modules.AndroidLibrary.CORE))
6060
implementation(project(Modules.AndroidLibrary.DOMAIN))
61-
implementation(project(Modules.AndroidLibrary.DATA))
6261

6362
addBaseDynamicFeatureModuleDependencies()
6463

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
package com.smarttoolfactory.post_detail
22

33
import android.os.Bundle
4-
import android.view.LayoutInflater
5-
import android.view.View
6-
import android.view.ViewGroup
7-
import androidx.databinding.DataBindingUtil
8-
import androidx.fragment.app.Fragment
4+
import com.smarttoolfactory.core.di.CoreModuleDependencies
5+
import com.smarttoolfactory.core.ui.base.DynamicNavigationFragment
96
import com.smarttoolfactory.domain.model.Post
107
import com.smarttoolfactory.post_detail.databinding.FragmentPostDetailBinding
8+
import com.smarttoolfactory.post_detail.di.DaggerPostDetailComponent
9+
import dagger.hilt.android.EntryPointAccessors
10+
import javax.inject.Inject
1111

12-
class PostDetailFragment : Fragment() {
12+
class PostDetailFragment : DynamicNavigationFragment<FragmentPostDetailBinding>() {
1313

14-
private lateinit var dataBinding: FragmentPostDetailBinding
14+
@Inject
15+
lateinit var viewModel: PostDetailViewModel
1516

16-
override fun onCreateView(
17-
inflater: LayoutInflater,
18-
container: ViewGroup?,
19-
savedInstanceState: Bundle?
20-
): View? {
21-
dataBinding =
22-
DataBindingUtil.inflate(inflater, R.layout.fragment_post_detail, container, false)
23-
return dataBinding.root
17+
override fun getLayoutRes(): Int = R.layout.fragment_post_detail
18+
19+
override fun bindViews() {
20+
// Get Post from navigation component arguments
21+
val post = arguments?.get("post") as Post
22+
dataBinding.item = post
23+
viewModel.updatePostStatus(post)
24+
}
25+
26+
override fun onCreate(savedInstanceState: Bundle?) {
27+
initCoreDependentInjection()
28+
super.onCreate(savedInstanceState)
2429
}
2530

26-
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
27-
super.onViewCreated(view, savedInstanceState)
28-
// Get RepoListItem from navigation component arguments
29-
val post = arguments?.get("post") as? Post?
31+
private fun initCoreDependentInjection() {
3032

31-
dataBinding.item = post
33+
val coreModuleDependencies = EntryPointAccessors.fromApplication(
34+
requireActivity().applicationContext,
35+
CoreModuleDependencies::class.java
36+
)
37+
38+
DaggerPostDetailComponent.factory().create(
39+
dependentModule = coreModuleDependencies,
40+
fragment = this
41+
)
42+
.inject(this)
3243
}
3344
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.smarttoolfactory.post_detail
2+
3+
import androidx.lifecycle.ViewModel
4+
import androidx.lifecycle.ViewModelProvider
5+
import com.smarttoolfactory.domain.model.Post
6+
import com.smarttoolfactory.domain.usecase.GetPostsWithStatusUseCaseFlow
7+
import javax.inject.Inject
8+
import kotlinx.coroutines.CoroutineScope
9+
import kotlinx.coroutines.flow.launchIn
10+
11+
class PostDetailViewModel @Inject constructor(
12+
private val coroutineScope: CoroutineScope,
13+
private val getPostsUseCase: GetPostsWithStatusUseCaseFlow
14+
) : ViewModel() {
15+
16+
fun updatePostStatus(post: Post) {
17+
post.displayCount++
18+
getPostsUseCase.updatePostStatus(post)
19+
.launchIn(coroutineScope)
20+
}
21+
}
22+
23+
class PostDetailViewModelFactory @Inject constructor(
24+
private val coroutineScope: CoroutineScope,
25+
private val getPostsUseCase: GetPostsWithStatusUseCaseFlow
26+
) : ViewModelProvider.Factory {
27+
28+
@Suppress("UNCHECKED_CAST")
29+
override fun <T : ViewModel> create(modelClass: Class<T>): T {
30+
if (modelClass != PostDetailViewModel::class.java) {
31+
throw IllegalArgumentException("Unknown ViewModel class")
32+
}
33+
return PostDetailViewModel(
34+
coroutineScope,
35+
getPostsUseCase
36+
) as T
37+
}
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /