Created
March 8, 2018 16:02
-
-
Save alorma/0ec174fb1fd4f75ba739a1f8ced14933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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