Use SpannableStringBuilder DSL for CommitUtils
*/
package com.github.pockethub.android.core.commit
+import android.text.SpannedString
import android.text.TextUtils
import android.widget.ImageView
-import com.github.pockethub.android.ui.StyledText
+import androidx.text.buildSpannedString
import com.github.pockethub.android.util.AvatarLoader
import com.meisolsson.githubsdk.model.Commit
import com.meisolsson.githubsdk.model.GitHubFile
@@ -200,14 +201,14 @@ object CommitUtils {
}
/**
- * Format stats into [StyledText]
+ * Format stats into [SpannedString]
*
* @param files
* @return styled text
*/
@JvmStatic
- fun formatStats(files: Collection<GitHubFile>?): StyledText {
- val fileDetails = StyledText()
+ fun formatStats(files: Collection<GitHubFile>?): SpannedString {
+ return buildSpannedString {
var added = 0
var deleted = 0
var changed = 0
@@ -220,26 +221,25 @@ object CommitUtils {
}
if (changed != 1) {
- fileDetails.append(FORMAT.format(changed.toLong())).append(" changed files")
+ append("${FORMAT.format(changed.toLong())} changed files")
} else {
- fileDetails.append("1 changed file")
+ append("1 changed file")
}
- fileDetails.append(" with ")
+ append(" with ")
if (added != 1) {
- fileDetails.append(FORMAT.format(added.toLong())).append(" additions")
+ append("${FORMAT.format(added.toLong())} additions")
} else {
- fileDetails.append("1 addition ")
+ append("1 addition ")
}
- fileDetails.append(" and ")
+ append(" and ")
if (deleted != 1) {
- fileDetails.append(FORMAT.format(deleted.toLong())).append(" deletions")
+ append("${FORMAT.format(deleted.toLong())} deletions")
} else {
- fileDetails.append("1 deletion")
+ append("1 deletion")
+ }
}
-
- return fileDetails
}
/**
