Skip to content
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

Add string resources for AI-UI module #2020

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ai/ui/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ package com.google.android.horologist.ai.ui.model {
}

public static final class FailedResponseUiModel.Companion {
method public com.google.android.horologist.ai.ui.model.FailedResponseUiModel getNoCompanion();
property public final com.google.android.horologist.ai.ui.model.FailedResponseUiModel NoCompanion;
method public com.google.android.horologist.ai.ui.model.FailedResponseUiModel NoCompanion(android.content.Context context);
}

public final class InProgressResponseUiModel implements com.google.android.horologist.ai.ui.model.ResponseUiModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

package com.google.android.horologist.ai.ui.model

import android.content.Context
import com.google.android.horologist.ai.ui.R

public data class FailedResponseUiModel(public val message: String) : PromptOrResponseUiModel {
public companion object {
public val NoCompanion: FailedResponseUiModel =
FailedResponseUiModel("No companion app found")
public fun NoCompanion(context: Context): FailedResponseUiModel =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: usually it is avoided to pass reference of context to viewmodels in order to prevent further mistakes of holding an instance of it (which is not the case here)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I guess to use this I'd have to implement AndroidViewModel which gets the application context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more a helper method, I might give it some thought and follow up just removing this, or moving to a Screen.

FailedResponseUiModel(context.getString(R.string.horologist_no_companion_app_found))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.material.Text
import com.google.android.horologist.ai.ui.R
import com.google.android.horologist.ai.ui.components.PromptOrResponseDisplay
import com.google.android.horologist.ai.ui.components.ResponseInProgressCard
import com.google.android.horologist.ai.ui.components.TextPromptDisplay
Expand Down Expand Up @@ -66,7 +68,7 @@ public fun PromptScreen(
ScalingLazyColumn(columnState = columnState, modifier = modifier) {
item {
ListHeader(modifier = Modifier.fillMaxWidth(0.8f)) {
Text(text = uiState.modelInfo?.name ?: "...")
Text(text = uiState.modelInfo?.name ?: stringResource(R.string.horologist_unknown_model))
}
}
uiState.messages.forEach {
Expand Down Expand Up @@ -107,7 +109,7 @@ public fun PromptScreen(
item {
Button(
Icons.Default.Settings,
contentDescription = "Settings",
contentDescription = stringResource(R.string.horologist_settings_content_description),
onClick = onSettingsClick,
)
}
Expand Down
21 changes: 21 additions & 0 deletions ai/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2024 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>
<string name="horologist_no_companion_app_found" description="Text displayed when no companion is found. [CHAR_LIMIT=NONE]">No companion app found</string>
<string name="horologist_unknown_model" description="Text displayed when no model is identified. [CHAR_LIMIT=NONE]">...</string>
<string name="horologist_settings_content_description" description="Content description for settings button. [CHAR_LIMIT=NONE]">Settings</string>
</resources>
Loading