improve language support
This commit is contained in:
parent
93d3229d53
commit
8653c0f0d6
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.di.StaticInjector
|
|||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.ConfigBuilder
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
||||
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils
|
||||
|
@ -57,6 +58,7 @@ import java.io.IOException
|
|||
import java.net.SocketException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
class MainApp : DaggerApplication() {
|
||||
|
||||
|
@ -81,6 +83,7 @@ class MainApp : DaggerApplication() {
|
|||
@Inject lateinit var processLifecycleListener: ProcessLifecycleListener
|
||||
@Inject lateinit var profileSwitchPlugin: ThemeSwitcherPlugin
|
||||
@Inject lateinit var localAlertUtils: LocalAlertUtils
|
||||
@Inject lateinit var rh: Provider<ResourceHelper>
|
||||
|
||||
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||
private lateinit var refreshWidget: Runnable
|
||||
|
@ -109,26 +112,33 @@ class MainApp : DaggerApplication() {
|
|||
|
||||
// trigger here to see the new version on app start after an update
|
||||
versionCheckersUtils.triggerCheckVersion()
|
||||
// check if identification is set
|
||||
if (buildHelper.isDev() && sp.getStringOrNull(R.string.key_email_for_crash_report, null).isNullOrBlank())
|
||||
notificationStore.add(Notification(Notification.IDENTIFICATION_NOT_SET, getString(R.string.identification_not_set), Notification.INFO))
|
||||
|
||||
// Register all tabs in app here
|
||||
pluginStore.plugins = plugins
|
||||
configBuilder.initialize()
|
||||
|
||||
disposable += repository.runTransaction(VersionChangeTransaction(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, gitRemote, commitHash)).subscribe()
|
||||
if (sp.getBoolean(R.string.key_ns_logappstartedevent, config.APS))
|
||||
disposable += repository
|
||||
.runTransaction(
|
||||
InsertIfNewByTimestampTherapyEventTransaction(
|
||||
timestamp = dateUtil.now(),
|
||||
type = TherapyEvent.Type.NOTE,
|
||||
note = getString(info.nightscout.androidaps.core.R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL,
|
||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||
)
|
||||
)
|
||||
.subscribe()
|
||||
// delayed actions to make rh context updated for translations
|
||||
handler.postDelayed(
|
||||
{
|
||||
// check if identification is set
|
||||
if (buildHelper.isDev() && sp.getStringOrNull(R.string.key_email_for_crash_report, null).isNullOrBlank())
|
||||
notificationStore.add(Notification(Notification.IDENTIFICATION_NOT_SET, rh.get().gs(R.string.identification_not_set), Notification.INFO))
|
||||
// log version
|
||||
disposable += repository.runTransaction(VersionChangeTransaction(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, gitRemote, commitHash)).subscribe()
|
||||
// log app start
|
||||
if (sp.getBoolean(R.string.key_ns_logappstartedevent, config.APS))
|
||||
disposable += repository
|
||||
.runTransaction(
|
||||
InsertIfNewByTimestampTherapyEventTransaction(
|
||||
timestamp = dateUtil.now(),
|
||||
type = TherapyEvent.Type.NOTE,
|
||||
note = rh.get().gs(info.nightscout.androidaps.core.R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL,
|
||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||
)
|
||||
)
|
||||
.subscribe()
|
||||
}, 10000
|
||||
)
|
||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
|
||||
"KeepAlive",
|
||||
ExistingPeriodicWorkPolicy.REPLACE,
|
||||
|
|
|
@ -3,6 +3,7 @@ import android.content.Context
|
|||
import android.os.Bundle
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.events.EventThemeSwitch
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.locale.LocaleHelper
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
|
@ -17,6 +18,7 @@ open class NoSplashAppCompatActivity : DaggerAppCompatActivityWithResult() {
|
|||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setTheme(R.style.AppTheme_NoActionBar)
|
||||
rh.updateContext(this)
|
||||
|
||||
compositeDisposable.add(rxBus.toObservable(EventThemeSwitch::class.java).subscribe {
|
||||
recreate()
|
||||
|
|
|
@ -22,18 +22,22 @@ import javax.inject.Inject
|
|||
/**
|
||||
* Created by adrian on 2019-12-23.
|
||||
*/
|
||||
class ResourceHelperImplementation @Inject constructor(private val context: Context, private val fabricPrivacy: FabricPrivacy) : ResourceHelper {
|
||||
class ResourceHelperImplementation @Inject constructor(var context: Context, private val fabricPrivacy: FabricPrivacy) : ResourceHelper {
|
||||
|
||||
override fun updateContext(ctx: Context?) {
|
||||
ctx?.let { context = it }
|
||||
}
|
||||
|
||||
override fun gs(@StringRes id: Int): String = context.getString(id)
|
||||
|
||||
override fun gs(@StringRes id: Int, vararg args: Any?) : String {
|
||||
override fun gs(@StringRes id: Int, vararg args: Any?): String {
|
||||
return try {
|
||||
context.getString(id, *args)
|
||||
} catch (exception: Exception) {
|
||||
val resourceName = context.resources.getResourceEntryName(id)
|
||||
val resourceValue = context.getString(id)
|
||||
val currentLocale: Locale = context.resources.configuration.locales[0]
|
||||
fabricPrivacy.logMessage("Failed to get string for resource $resourceName ($id) '$resourceValue' for locale $currentLocale with args ${args.map{it.toString()}}")
|
||||
fabricPrivacy.logMessage("Failed to get string for resource $resourceName ($id) '$resourceValue' for locale $currentLocale with args ${args.map { it.toString() }}")
|
||||
fabricPrivacy.logException(exception)
|
||||
try {
|
||||
gsNotLocalised(id, *args)
|
||||
|
@ -89,7 +93,7 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont
|
|||
override fun shortTextMode(): Boolean = !gb(R.bool.isTablet)
|
||||
|
||||
override fun gac(context: Context?, attributeId: Int): Int =
|
||||
( ContextThemeWrapper( context ?: this.context, R.style.AppTheme)).getThemeColor(attributeId)
|
||||
(ContextThemeWrapper(context ?: this.context, R.style.AppTheme)).getThemeColor(attributeId)
|
||||
|
||||
override fun gac(attributeId: Int): Int =
|
||||
ContextThemeWrapper(this.context, R.style.AppTheme).getThemeColor(attributeId)
|
||||
|
@ -99,11 +103,11 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont
|
|||
val configuration = Configuration(res.configuration)
|
||||
val filter = res.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()
|
||||
|
||||
configuration.uiMode = when (AppCompatDelegate.getDefaultNightMode()) {
|
||||
configuration.uiMode = when (AppCompatDelegate.getDefaultNightMode()) {
|
||||
AppCompatDelegate.MODE_NIGHT_NO -> Configuration.UI_MODE_NIGHT_NO or filter
|
||||
AppCompatDelegate.MODE_NIGHT_YES -> Configuration.UI_MODE_NIGHT_YES or filter
|
||||
else -> res.configuration.uiMode
|
||||
}
|
||||
return context.createConfigurationContext(configuration)
|
||||
return context.createConfigurationContext(configuration)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import android.util.DisplayMetrics
|
|||
import androidx.annotation.*
|
||||
|
||||
interface ResourceHelper {
|
||||
fun updateContext(ctx: Context?)
|
||||
|
||||
fun gs(@StringRes id: Int): String
|
||||
fun gs(@StringRes id: Int, vararg args: Any?): String
|
||||
fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String
|
||||
|
|
Loading…
Reference in a new issue