mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3601 App | Fix | Release 10 stabilization, part 1 (#2353)
This commit is contained in:
parent
680abc966e
commit
df87f33b9d
5 changed files with 68 additions and 38 deletions
|
@ -1,12 +1,14 @@
|
|||
package com.anytypeio.anytype.payments.mapping
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import com.anytypeio.anytype.core_ui.R
|
||||
import com.anytypeio.anytype.payments.models.PeriodDescription
|
||||
import com.anytypeio.anytype.payments.models.PeriodUnit
|
||||
import com.anytypeio.anytype.payments.models.TierPeriod
|
||||
import java.time.Period
|
||||
import timber.log.Timber
|
||||
|
||||
fun String.parsePeriod(): PeriodDescription? {
|
||||
return try {
|
||||
|
@ -24,18 +26,24 @@ fun String.parsePeriod(): PeriodDescription? {
|
|||
|
||||
@Composable
|
||||
fun LocalizedPeriodString(desc: PeriodDescription?): String {
|
||||
desc ?: return ""
|
||||
val quantityStringId = when (desc.unit) {
|
||||
PeriodUnit.YEARS -> R.plurals.period_years
|
||||
PeriodUnit.MONTHS -> R.plurals.period_months
|
||||
PeriodUnit.DAYS -> R.plurals.period_days
|
||||
PeriodUnit.WEEKS -> R.plurals.period_weeks
|
||||
val context = LocalContext.current
|
||||
val localeList = context.resources.configuration.locales
|
||||
if (!localeList.isEmpty && desc != null) {
|
||||
val quantityStringId = when (desc.unit) {
|
||||
PeriodUnit.YEARS -> R.plurals.period_years
|
||||
PeriodUnit.MONTHS -> R.plurals.period_months
|
||||
PeriodUnit.DAYS -> R.plurals.period_days
|
||||
PeriodUnit.WEEKS -> R.plurals.period_weeks
|
||||
}
|
||||
return pluralStringResource(
|
||||
id = quantityStringId,
|
||||
count = desc.amount,
|
||||
formatArgs = arrayOf(desc.amount)
|
||||
)
|
||||
} else {
|
||||
Timber.e("Error getting the locale or desc is null")
|
||||
return ""
|
||||
}
|
||||
return pluralStringResource(
|
||||
id = quantityStringId,
|
||||
count = desc.amount,
|
||||
formatArgs = arrayOf(desc.amount)
|
||||
)
|
||||
}
|
||||
|
||||
fun TierPeriod.toPeriodDescription(): PeriodDescription {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue