-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scope SavedStateFlowHandle to ViewModel's, create assisted injection …
…extension functions, & add CI to run unit tests and build (#11) * create a savedstateflow-hilt module that automatically scopes SavedStateFlowHandle to the hilt ViewModelScope * add assisted viewmodel extension functions and update the documentation * remove app compat since this is unneeded for the hilt module * add a ci to run units tests and upload results * refactor samples to have different package names so whole project can build * update publish version to match the rest of the library
- Loading branch information
1 parent
b63703b
commit b8bd0ae
Showing
39 changed files
with
378 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
org.gradle.daemon=false | ||
org.gradle.parallel=true | ||
org.gradle.jvmargs=-Xmx5120m | ||
org.gradle.workers.max=2 | ||
|
||
kotlin.incremental=false | ||
kotlin.compiler.execution.strategy=in-process |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Android CI | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-run-unit-tests: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Copy CI gradle.properties | ||
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
|
||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.gradle/caches/modules-* | ||
~/.gradle/caches/jars-* | ||
~/.gradle/caches/build-cache-* | ||
key: gradle-${{ hashFiles('checksum.txt') }} | ||
|
||
- name: Build project and run unit tests | ||
run: ./gradlew build testDebug --stacktrace | ||
|
||
- name: Publish Unit Test Report | ||
if: always() | ||
uses: mikepenz/action-junit-report@v2 | ||
with: | ||
report_paths: '**/build/test-results/testDebugUnitTest/TEST-*.xml' | ||
require_tests: 'true' | ||
|
||
- name: Upload build and unit test reports | ||
if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: build-and-unit-test-reports | ||
path: | | ||
sample/hilt-di/build/reports | ||
sample/manual-di/build/reports | ||
savedstateflow/build/reports |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
4 changes: 3 additions & 1 deletion
4
...obileapps/savedstateflow/MainViewModel.kt → ...eapps/savedstateflowhilt/MainViewModel.kt
This file contains 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
17 changes: 17 additions & 0 deletions
17
sample/hilt-di/src/main/java/com/plusmobileapps/savedstateflowhilt/Modules.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.plusmobileapps.savedstateflowhilt | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class NewsModule { | ||
|
||
@Binds | ||
abstract fun bindNewsDataSource( | ||
newsRepository: NewsRepository | ||
): NewsDataSource | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...obileapps/savedstateflow/MyApplication.kt → ...eapps/savedstateflowhilt/MyApplication.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...usmobileapps/savedstateflow/Repository.kt → ...bileapps/savedstateflowhilt/Repository.kt
This file contains 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
25 changes: 25 additions & 0 deletions
25
.../hilt-di/src/main/java/com/plusmobileapps/savedstateflowhilt/assisted/AssistedFragment.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.plusmobileapps.savedstateflowhilt.assisted | ||
|
||
import androidx.core.os.bundleOf | ||
import androidx.fragment.app.Fragment | ||
import com.plusmobileapps.savedstateflow_hilt.assistedViewModel | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class AssistedFragment : Fragment() { | ||
@Inject | ||
lateinit var factory: MyAssistedViewModel.Factory | ||
|
||
private val viewModel: MyAssistedViewModel by assistedViewModel { savedStateFlowHandle -> | ||
factory.create(savedStateFlowHandle, arguments?.getString(ARGUMENTS_KEY)!!) | ||
} | ||
|
||
companion object { | ||
const val ARGUMENTS_KEY = "some-argument-key" | ||
|
||
fun newInstance(id: String): AssistedFragment = AssistedFragment().apply { | ||
arguments = bundleOf(ARGUMENTS_KEY to id) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...lt-di/src/main/java/com/plusmobileapps/savedstateflowhilt/assisted/MyAssistedViewModel.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.plusmobileapps.savedstateflowhilt.assisted | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.plusmobileapps.savedstateflow.SavedStateFlowHandle | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
|
||
class MyAssistedViewModel @AssistedInject constructor( | ||
@Assisted savedStateFlowHandle: SavedStateFlowHandle, | ||
@Assisted id: String | ||
) : ViewModel() { | ||
|
||
@AssistedFactory | ||
interface Factory { | ||
fun create(savedStateFlowHandle: SavedStateFlowHandle, id: String): MyAssistedViewModel | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...bileapps/savedstateflow/ui/theme/Color.kt → ...apps/savedstateflowhilt/ui/theme/Color.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...bileapps/savedstateflow/ui/theme/Shape.kt → ...apps/savedstateflowhilt/ui/theme/Shape.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...bileapps/savedstateflow/ui/theme/Theme.kt → ...apps/savedstateflowhilt/ui/theme/Theme.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...obileapps/savedstateflow/ui/theme/Type.kt → ...eapps/savedstateflowhilt/ui/theme/Type.kt
This file contains 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
9 changes: 6 additions & 3 deletions
9
...eapps/savedstateflow/MainViewModelTest.kt → ...s/savedstateflowhilt/MainViewModelTest.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...apps/savedstateflow/TestCoroutinesRule.kt → ...s/savedstateflowhilt/TestCoroutineRule.kt
This file contains 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
Oops, something went wrong.