Skip to content

Commit

Permalink
Add StringResource
Browse files Browse the repository at this point in the history
  • Loading branch information
Moriafly committed Jun 20, 2024
1 parent 99ccfad commit 375887a
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 15 deletions.
1 change: 1 addition & 0 deletions composeApp/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">SaltUI</string>
<string name="confirm">确认(字符串替换测试)</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* SaltUI
* Copyright (C) 2024 Moriafly
*
* 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
*
* http://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.
*/

@file:Suppress("UNUSED")

package com.moriafly.salt.ui.internal

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.moriafly.salt.ui.R

@Composable
internal actual fun stringResourceBack(): String {
return stringResource(R.string.back)
}

@Composable
internal actual fun stringResourceCancel(): String {
return stringResource(R.string.cancel)
}

@Composable
internal actual fun stringResourceConfirm(): String {
return stringResource(R.string.confirm)
}
6 changes: 6 additions & 0 deletions ui2/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="back">Back</string>
<string name="cancel">Cancel</string>
<string name="confirm">Confirm</string>
</resources>
7 changes: 3 additions & 4 deletions ui2/src/commonMain/kotlin/com/moriafly/salt/ui/Bar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.moriafly.salt.ui.internal.stringResourceBack
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import saltui.ui2.generated.resources.Res
import saltui.ui2.generated.resources.back
import saltui.ui2.generated.resources.ic_arrow_back

/**
Expand All @@ -66,7 +65,7 @@ fun TitleBar(
.height(56.dp)
) {
if (showBackBtn) {
val backButtonContentDescription = stringResource(Res.string.back)
val backButtonContentDescription = stringResourceBack()
Icon(
modifier = Modifier
.size(56.dp)
Expand All @@ -79,7 +78,7 @@ fun TitleBar(
}
.padding(18.dp),
painter = painterResource(Res.drawable.ic_arrow_back),
contentDescription = stringResource(Res.string.back),
contentDescription = stringResourceBack(),
tint = SaltTheme.colors.text
)
}
Expand Down
18 changes: 7 additions & 11 deletions ui2/src/commonMain/kotlin/com/moriafly/salt/ui/dialog/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ import com.moriafly.salt.ui.SaltTheme
import com.moriafly.salt.ui.Text
import com.moriafly.salt.ui.TextButton
import com.moriafly.salt.ui.UnstableSaltApi
import org.jetbrains.compose.resources.stringResource
import saltui.ui2.generated.resources.Res
import saltui.ui2.generated.resources.cancel
import saltui.ui2.generated.resources.confirm
import com.moriafly.salt.ui.internal.stringResourceCancel
import com.moriafly.salt.ui.internal.stringResourceConfirm

/**
* YesDialog
Expand All @@ -60,7 +58,7 @@ fun YesDialog(
properties: DialogProperties = DialogProperties(),
title: String,
content: String,
confirmText: String = stringResource(Res.string.confirm).uppercase()
confirmText: String = stringResourceConfirm().uppercase()
) {
BasicDialog(
onDismissRequest = onDismissRequest,
Expand Down Expand Up @@ -95,8 +93,8 @@ fun YesNoDialog(
title: String,
content: String,
drawContent: (@Composable () -> Unit)? = null,
cancelText: String = stringResource(Res.string.cancel).uppercase(),
confirmText: String = stringResource(Res.string.confirm).uppercase()
cancelText: String = stringResourceCancel().uppercase(),
confirmText: String = stringResourceConfirm().uppercase()
) {
BasicDialog(
onDismissRequest = onDismissRequest,
Expand Down Expand Up @@ -181,7 +179,7 @@ fun InputDialog(
},
modifier = Modifier
.weight(1f),
text = stringResource(Res.string.cancel).uppercase(),
text = stringResourceCancel().uppercase(),
textColor = SaltTheme.colors.subText,
backgroundColor = SaltTheme.colors.subBackground
)
Expand All @@ -192,7 +190,7 @@ fun InputDialog(
},
modifier = Modifier
.weight(1f),
text = stringResource(Res.string.confirm).uppercase()
text = stringResourceConfirm().uppercase()
)
}
ItemOutSpacer()
Expand Down Expand Up @@ -223,8 +221,6 @@ fun BasicDialog(
}
}



@Composable
fun DialogTitle(
text: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SaltUI
* Copyright (C) 2024 Moriafly
*
* 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
*
* http://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.
*/

@file:Suppress("UNUSED")

package com.moriafly.salt.ui.internal

import androidx.compose.runtime.Composable

@Composable
internal expect fun stringResourceBack(): String

@Composable
internal expect fun stringResourceCancel(): String

@Composable
internal expect fun stringResourceConfirm(): String
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SaltUI
* Copyright (C) 2024 Moriafly
*
* 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
*
* http://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.
*/

@file:Suppress("UNUSED")

package com.moriafly.salt.ui.internal

import androidx.compose.runtime.Composable
import org.jetbrains.compose.resources.stringResource
import saltui.ui2.generated.resources.Res
import saltui.ui2.generated.resources.back
import saltui.ui2.generated.resources.cancel
import saltui.ui2.generated.resources.confirm

@Composable
internal actual fun stringResourceBack(): String {
return stringResource(Res.string.back)
}

@Composable
internal actual fun stringResourceCancel(): String {
return stringResource(Res.string.cancel)
}

@Composable
internal actual fun stringResourceConfirm(): String {
return stringResource(Res.string.confirm)
}

0 comments on commit 375887a

Please sign in to comment.