Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class ResourcesProvider @Inject constructor(private val context: Context) {
fun getPlural(@PluralsRes plural: Int, number: Int, formatted: String): String
= context.resources.getQuantityString(plural, number, formatted)
fun getString(@StringRes stringId: Int): String
= context.resources.getString(stringId)
}
class ProfileResources @Inject constructor(private val numberFormatter: NumberFormatter, private val resourcesProvider: ResourcesProvider) {
fun formatFollowers(followers: Long): String
= resourcesProvider.getPlural(R.plurals.profile_followers, followers.toInt(), truncate(followers))
fun formatFollowing(following: Long): String
= resourcesProvider.getPlural(R.plurals.profile_following, following.toInt(), truncate(following))
private fun truncate(number: Long) = numberFormatter.truncateNumber(number)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment