Skip to content

Instantly share code, notes, and snippets.

@alorma
Created March 8, 2018 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorma/0ec174fb1fd4f75ba739a1f8ced14933 to your computer and use it in GitHub Desktop.
Save alorma/0ec174fb1fd4f75ba739a1f8ced14933 to your computer and use it in GitHub Desktop.
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