-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Modernize changelog UI #7279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TimoPtr
wants to merge
5
commits into
main
Choose a base branch
from
feature/modern_changelog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Modernize changelog UI #7279
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22b3b22
Modernize changelog UI
TimoPtr cd44486
Apply copilot suggestions
TimoPtr 38184f3
Move persistence to PrefsRepo
TimoPtr d63995b
Cleanup test imports
TimoPtr 260a27f
Merge remote-tracking branch 'origin/main' into feature/modern_changelog
TimoPtr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
app/src/main/kotlin/io/homeassistant/companion/android/changelog/Changelog.kt
This file contains hidden or 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,83 @@ | ||
| package io.homeassistant.companion.android.changelog | ||
|
|
||
| import androidx.annotation.StringRes | ||
| import androidx.compose.ui.graphics.Color | ||
| import io.homeassistant.companion.android.common.R as commonR | ||
| import io.homeassistant.companion.android.common.compose.theme.HAColorScheme | ||
| import io.homeassistant.companion.android.frontend.navigation.WidgetType | ||
| import io.homeassistant.companion.android.settings.SettingsActivity | ||
|
|
||
| /** | ||
| * The platforms a changelog entry can apply to, in chip display order. | ||
| */ | ||
| enum class ChangelogPlatform(@field:StringRes val labelRes: Int) { | ||
| APP(commonR.string.changelog_platform_app), | ||
| AUTOMOTIVE(commonR.string.changelog_platform_automotive), | ||
| WEAR(commonR.string.changelog_platform_wear), | ||
| } | ||
|
|
||
| /** | ||
| * The kinds of changes a changelog groups its entries under, each fully describing how its | ||
| * section header is displayed. | ||
| * | ||
| * @property labelRes The header label of the section. | ||
| * @property markerColor The color of the section marker, resolved from the current color scheme | ||
| * so it adapts to the theme. | ||
| */ | ||
| enum class ChangelogCategory(@field:StringRes val labelRes: Int, val markerColor: (HAColorScheme) -> Color) { | ||
| NEW(commonR.string.changelog_category_new, HAColorScheme::colorFillSuccessLoudResting), | ||
| IMPROVED(commonR.string.changelog_category_improved, HAColorScheme::colorFillPrimaryLoudResting), | ||
| FIXED(commonR.string.changelog_category_fixed, HAColorScheme::colorFillNeutralLoudResting), | ||
| } | ||
|
|
||
| /** | ||
| * An action performed when the user taps a changelog entry. An entry with an action is rendered | ||
| * as a clickable row with a chevron. | ||
| */ | ||
| sealed interface ChangelogAction { | ||
| /** Opens [url] in the browser or the matching app. */ | ||
| data class OpenUrl(val url: String) : ChangelogAction | ||
|
|
||
| /** Opens the settings on the screen targeted by [deeplink]. */ | ||
| data class OpenSettings(val deeplink: SettingsActivity.Deeplink) : ChangelogAction | ||
|
|
||
| /** Opens the configuration screen of [widgetType] without a preselected entity. */ | ||
| data class OpenWidgetConfig(val widgetType: WidgetType) : ChangelogAction | ||
| } | ||
|
|
||
| /** | ||
| * One change of a release. | ||
| * | ||
| * @property contentRes The change description, a string resource from `strings_changelog.xml` | ||
| * in `:common`. Escaped inline HTML (like `<b>`) is rendered as styling. | ||
| * @property platforms The platforms this change applies to. | ||
| * @property action Optional action performed when the user taps the entry. | ||
| */ | ||
| data class ChangelogEntry( | ||
| @param:StringRes val contentRes: Int, | ||
| val platforms: Set<ChangelogPlatform>, | ||
| val action: ChangelogAction? = null, | ||
| ) | ||
|
|
||
| /** | ||
| * The changes of one release, one field per category so a category cannot appear twice. | ||
| * A category without entries is not displayed. | ||
| */ | ||
| data class Changelog( | ||
| val new: List<ChangelogEntry> = emptyList(), | ||
| val improved: List<ChangelogEntry> = emptyList(), | ||
| val fixed: List<ChangelogEntry> = emptyList(), | ||
| ) { | ||
| /** The non-empty sections of this changelog, in display order. */ | ||
| fun toSections(): List<ChangelogSection> = listOf( | ||
| ChangelogSection(ChangelogCategory.NEW, new), | ||
| ChangelogSection(ChangelogCategory.IMPROVED, improved), | ||
| ChangelogSection(ChangelogCategory.FIXED, fixed), | ||
| ).filter { it.entries.isNotEmpty() } | ||
| } | ||
|
|
||
| /** | ||
| * A group of [entries] of the same [category], displayed under one header. Derived from a | ||
| * [Changelog] through [Changelog.toSections], not meant to be built directly. | ||
| */ | ||
| data class ChangelogSection(val category: ChangelogCategory, val entries: List<ChangelogEntry>) |
44 changes: 44 additions & 0 deletions
44
app/src/main/kotlin/io/homeassistant/companion/android/changelog/ChangelogContent.kt
This file contains hidden or 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,44 @@ | ||
| package io.homeassistant.companion.android.changelog | ||
|
|
||
| import io.homeassistant.companion.android.common.R as commonR | ||
| import io.homeassistant.companion.android.frontend.navigation.WidgetType | ||
| import io.homeassistant.companion.android.settings.SettingsActivity | ||
|
|
||
| /** | ||
| * The changelog content of the current release, with the displayed strings in the dedicated | ||
| * `strings_changelog.xml` file of `:common` so they get translated. Entries not yet translated | ||
| * fall back to English. | ||
| * | ||
| * Update this together with the release notes; the changelog screenshot test pins the rendered | ||
| * result. | ||
| */ | ||
| internal val currentChangelog = Changelog( | ||
| new = listOf( | ||
| ChangelogEntry( | ||
| contentRes = commonR.string.changelog_entry_assistant_volume, | ||
| platforms = setOf(ChangelogPlatform.APP, ChangelogPlatform.AUTOMOTIVE, ChangelogPlatform.WEAR), | ||
| ), | ||
| ), | ||
| improved = listOf( | ||
| ChangelogEntry( | ||
| contentRes = commonR.string.changelog_entry_health_connect, | ||
| platforms = setOf(ChangelogPlatform.APP, ChangelogPlatform.AUTOMOTIVE), | ||
| ), | ||
| ChangelogEntry( | ||
| contentRes = commonR.string.changelog_entry_entity_widgets, | ||
| platforms = setOf(ChangelogPlatform.APP), | ||
| action = ChangelogAction.OpenWidgetConfig(WidgetType.Entity), | ||
| ), | ||
| ChangelogEntry( | ||
| contentRes = commonR.string.changelog_entry_tiles, | ||
| platforms = setOf(ChangelogPlatform.APP), | ||
| action = ChangelogAction.OpenSettings(SettingsActivity.Deeplink.QSTile()), | ||
| ), | ||
| ), | ||
| fixed = listOf( | ||
| ChangelogEntry( | ||
| contentRes = commonR.string.changelog_entry_bug_fixes, | ||
| platforms = setOf(ChangelogPlatform.APP, ChangelogPlatform.AUTOMOTIVE, ChangelogPlatform.WEAR), | ||
| ), | ||
| ), | ||
| ) | ||
66 changes: 66 additions & 0 deletions
66
app/src/main/kotlin/io/homeassistant/companion/android/changelog/ChangelogFragment.kt
This file contains hidden or 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,66 @@ | ||
| package io.homeassistant.companion.android.changelog | ||
|
|
||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.windowInsetsPadding | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.ComposeView | ||
| import androidx.core.net.toUri | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.fragment.app.viewModels | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
| import io.homeassistant.companion.android.changelog.ui.ChangelogContent | ||
| import io.homeassistant.companion.android.common.R as commonR | ||
| import io.homeassistant.companion.android.common.compose.theme.HATheme | ||
| import io.homeassistant.companion.android.common.compose.theme.LocalHAColorScheme | ||
| import io.homeassistant.companion.android.settings.SettingsActivity | ||
| import io.homeassistant.companion.android.util.safeBottomWindowInsets | ||
|
|
||
| /** | ||
| * Hosts the changelog within the settings, whose activity already provides the toolbar with the | ||
| * title and back navigation. | ||
| */ | ||
| @AndroidEntryPoint | ||
| class ChangelogFragment : Fragment() { | ||
|
|
||
| private val viewModel: ChangelogViewModel by viewModels() | ||
|
|
||
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
| return ComposeView(requireContext()).apply { | ||
| setContent { | ||
| HATheme { | ||
| val uiState by viewModel.uiState.collectAsStateWithLifecycle() | ||
| ChangelogContent( | ||
| uiState = uiState, | ||
| onGotItClick = { parentFragmentManager.popBackStack() }, | ||
| onActionClick = ::onActionClick, | ||
| modifier = Modifier | ||
| .background(LocalHAColorScheme.current.colorSurfaceDefault) | ||
| .windowInsetsPadding(safeBottomWindowInsets(applyHorizontal = false)), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| activity?.title = getString(commonR.string.changelog_screen_title) | ||
| } | ||
|
|
||
| private fun onActionClick(action: ChangelogAction) { | ||
| when (action) { | ||
| is ChangelogAction.OpenUrl -> startActivity(Intent(Intent.ACTION_VIEW, action.url.toUri())) | ||
| is ChangelogAction.OpenSettings -> | ||
| startActivity(SettingsActivity.newInstance(requireContext(), action.deeplink)) | ||
| is ChangelogAction.OpenWidgetConfig -> | ||
| startActivity(action.widgetType.toConfigureIntent(requireContext())) | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
app/src/main/kotlin/io/homeassistant/companion/android/changelog/ChangelogShowViewModel.kt
This file contains hidden or 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,37 @@ | ||
| package io.homeassistant.companion.android.changelog | ||
|
|
||
| import androidx.annotation.VisibleForTesting | ||
| import androidx.lifecycle.ViewModel | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import io.homeassistant.companion.android.BuildConfig | ||
| import io.homeassistant.companion.android.common.data.prefs.PrefsRepository | ||
| import javax.inject.Inject | ||
|
|
||
| /** | ||
| * Decides whether the changelog screen should be shown. | ||
| */ | ||
| @HiltViewModel | ||
| class ChangelogShowViewModel @VisibleForTesting constructor( | ||
| private val prefsRepository: PrefsRepository, | ||
| private val currentVersionCode: Int, | ||
| ) : ViewModel() { | ||
|
|
||
| @Inject | ||
| constructor(prefsRepository: PrefsRepository) : this(prefsRepository, BuildConfig.VERSION_CODE) | ||
|
|
||
| private var consumed = false | ||
|
|
||
| /** | ||
| * Returns `true` when the user has enabled the changelog popup and the changelog of the | ||
| * current app version has not been seen yet. | ||
| * | ||
| * The decision is consumed: it returns `true` at most once per instance so configuration | ||
| * changes or returning to the frontend don't show the changelog again. | ||
| */ | ||
| suspend fun consumeShouldShowChangelog(): Boolean { | ||
| if (consumed) return false | ||
| consumed = true | ||
| return prefsRepository.isChangeLogPopupEnabled() && | ||
| prefsRepository.wasAppUpdatedSinceChangelogSeen(currentVersionCode) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.