Merge pull request #259 from Naveen3Singh/locale_separator

Use device locale's decimal separator by default
This commit is contained in:
Tibor Kaputa 2022-06-11 22:12:22 +02:00 committed by GitHub
commit 6a754cfc26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View File

@ -80,6 +80,14 @@
android:resource="@xml/widget_info" />
</receiver>
<receiver
android:name=".receivers.LocaleChangeReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter>
</receiver>
<activity-alias
android:name=".activities.SplashActivity.Red"
android:enabled="false"

View File

@ -9,6 +9,6 @@ class Config(context: Context) : BaseConfig(context) {
}
var useCommaAsDecimalMark: Boolean
get() = prefs.getBoolean(USE_COMMA_AS_DECIMAL_MARK, false)
get() = prefs.getBoolean(USE_COMMA_AS_DECIMAL_MARK, getDecimalSeparator() == COMMA)
set(useCommaAsDecimalMark) = prefs.edit().putBoolean(USE_COMMA_AS_DECIMAL_MARK, useCommaAsDecimalMark).apply()
}

View File

@ -29,3 +29,7 @@ class NumberFormatHelper(
return str.replace(groupingSeparator, "").replace(decimalSeparator, DOT)
}
}
fun getDecimalSeparator(): String {
return DecimalFormatSymbols.getInstance().decimalSeparator.toString()
}

View File

@ -0,0 +1,15 @@
package com.simplemobiletools.calculator.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.simplemobiletools.calculator.extensions.updateWidgets
class LocaleChangeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Intent.ACTION_LOCALE_CHANGED == intent.action) {
context.updateWidgets()
}
}
}