-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1113 from syarihu/fix_method_of_getting_version_n…
…ames [Android] Enable to get version name from BuildConfig on AboutScreen
- Loading branch information
Showing
5 changed files
with
85 additions
and
34 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
app-android/src/main/java/io/github/droidkaigi/confsched2023/AppModule.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,22 @@ | ||
package io.github.droidkaigi.confsched2023 | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import io.github.droidkaigi.confsched2023.data.di.AppAndroidBuildConfig | ||
import io.github.droidkaigi.confsched2023.model.BuildConfigProvider | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
class AppModule { | ||
@Provides | ||
@Singleton | ||
@AppAndroidBuildConfig | ||
fun provideBuildConfigProvider(): BuildConfigProvider = AppBuildConfigProvider() | ||
} | ||
|
||
class AppBuildConfigProvider( | ||
override val versionName: String = BuildConfig.VERSION_NAME, | ||
) : BuildConfigProvider |
40 changes: 40 additions & 0 deletions
40
...ndroidMain/kotlin/io/github/droidkaigi/confsched2023/data/di/BuildConfigProviderModule.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,40 @@ | ||
package io.github.droidkaigi.confsched2023.data.di | ||
|
||
import dagger.BindsOptionalOf | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import io.github.droidkaigi.confsched2023.model.BuildConfigProvider | ||
import java.util.Optional | ||
import javax.inject.Qualifier | ||
import javax.inject.Singleton | ||
|
||
@Qualifier | ||
annotation class AppAndroidBuildConfig | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
class BuildConfigProviderModule { | ||
@Provides | ||
@Singleton | ||
fun provideBuildConfigProvider( | ||
@AppAndroidBuildConfig buildConfigOverride: Optional<BuildConfigProvider>, | ||
): BuildConfigProvider = if (buildConfigOverride.isPresent) { | ||
buildConfigOverride.get() | ||
} else { | ||
EmptyBuildConfigProvider | ||
} | ||
} | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class AppAndroidBuildConfigModule { | ||
@BindsOptionalOf | ||
@AppAndroidBuildConfig | ||
abstract fun bindBuildConfigProvider(): BuildConfigProvider | ||
} | ||
|
||
private object EmptyBuildConfigProvider : BuildConfigProvider { | ||
override val versionName: String = "" | ||
} |
5 changes: 5 additions & 0 deletions
5
...del/src/commonMain/kotlin/io/github/droidkaigi/confsched2023/model/BuildConfigProvider.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,5 @@ | ||
package io.github.droidkaigi.confsched2023.model | ||
|
||
interface BuildConfigProvider { | ||
val versionName: String | ||
} |
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