Merge pull request #1338 from Andries-Smit/fix/nullable-resource-helper-get-string-args

fix rh gs with empty args
This commit is contained in:
Milos Kozak 2022-02-17 23:50:07 +01:00 committed by GitHub
commit fef8421e79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,20 +20,21 @@ import javax.inject.Inject
*/
class ResourceHelperImplementation @Inject constructor(private val context: Context, private val fabricPrivacy: FabricPrivacy) : ResourceHelper {
override fun gs(@StringRes id: Int): String = gs(id, null)
override fun gs(@StringRes id: Int): String = context.getString(id)
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 resourceName = context.resources.getResourceEntryName(id)
val resourceValue = context.getString(id)
val currentLocale: Locale = context.resources.configuration.locale
fabricPrivacy.logMessage("Failed to get string for resource $resourceName ($id) 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)
} catch (exceptionNonLocalized: Exception) {
fabricPrivacy.logMessage("Fallback failed to get string for resource $resourceName ($id) with args ${args.map { it.toString() }}")
fabricPrivacy.logMessage("Fallback failed to get string for resource $resourceName ($id) '$resourceValue' with args ${args.map { it.toString() }}")
fabricPrivacy.logException(exceptionNonLocalized)
"FAILED to get string $resourceName"
}