Skip to content

Commit

Permalink
Including version info into Settings screen (#26)
Browse files Browse the repository at this point in the history
## Context
- In order to help users identify the app version, we're including this information on the footer of the Settings screen

## Code
- Add `TextView`, `StateFlow` and get the information from `BuildConfiguration`
- gradle/kotlin update

## Additional notes
<img src="https://user-images.githubusercontent.com/38049362/107878120-520f5200-6eaf-11eb-9877-ec273af7aa5d.png" width=300/>
  • Loading branch information
cmorigaki authored Feb 14, 2021
1 parent 56aef8e commit 6fe37b7
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ buildscript {
jcenter()
}
ext {
kotlinVersion = "1.4.21"
gradleVersion = "4.1.1"
kotlinVersion = "1.4.30"
gradleVersion = '4.1.2'
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions features/settings/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
implementation AndroidLibConfig.material

implementation project(ProjectConfig.analytics)
implementation project(ProjectConfig.configuration)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ val settingsPresentationModule = module {
SettingsViewModel(
viewState = SettingsViewState(),
getSettingsList = get(),
analytics = get()
analytics = get(),
buildConfiguration = get(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package br.com.recipebook.settings.presentation

import androidx.lifecycle.viewModelScope
import br.com.recipebook.analytics.Analytics
import br.com.recipebook.di.BuildConfiguration
import br.com.recipebook.settings.analytics.ViewSettingsEvent
import br.com.recipebook.settings.domain.model.SettingsItemModel
import br.com.recipebook.settings.domain.usecase.GetSettingsUseCase
Expand All @@ -15,10 +16,12 @@ import kotlinx.coroutines.launch
class SettingsViewModel(
override val viewState: SettingsViewState,
private val getSettingsList: GetSettingsUseCase,
private val analytics: Analytics
private val analytics: Analytics,
buildConfiguration: BuildConfiguration,
) : BaseViewModel<SettingsViewState, SettingsAction, SettingsCommand>() {

init {
viewState.appVersion.value = buildConfiguration.appInfo.version
viewModelScope.launch {
setLoadingState()
getSettingsList().mapSuccess(::onLoadSuccess).mapError(::onLoadError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class SettingsViewState {
val hasError = MutableStateFlow(false)

val listItems = MutableStateFlow<List<SettingsItem>>(emptyList())
val appVersion = MutableStateFlow("")
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class SettingsActivity : AppCompatActivity() {
adapter.setData(it)
}
}

lifecycleScope.launchWhenStarted {
viewModel.viewState.appVersion.collect {
if (it.isNotBlank()) binding.appVersion.text = getString(R.string.settings_app_version, it)
}
}
}

private fun observeActionCommand() {
Expand Down
9 changes: 9 additions & 0 deletions features/settings/src/main/res/layout/settings_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@

</androidx.recyclerview.widget.RecyclerView>

<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="@dimen/margin_normal_100"
app:layout_constraintEnd_toEndOf="parent"
tools:text="Version 1.0.0"/>

<include
android:id="@+id/settings_error_state"
layout="@layout/error_state_view"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<string name="settings_title">Configurações</string>
<string name="settings_theme">Alterar tema</string>
<string name="settings_app_version">Versão %s</string>
</resources>
1 change: 1 addition & 0 deletions features/settings/src/main/res/values/settings_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<string name="settings_title">Configuration</string>
<string name="settings_theme">Change theme</string>
<string name="settings_app_version">Version %s</string>
</resources>
6 changes: 3 additions & 3 deletions project-config/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ ext {
versionCode: 2,
versionName: "0.1.0",

compileSdk: 29,
buildTools: "29.0.3",
compileSdk: 30,
buildTools: "30.0.3",
minSdk: 23,
targetSdk: 29
targetSdk: 30
]

AndroidLibConfig = [
Expand Down

0 comments on commit 6fe37b7

Please sign in to comment.