mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-31 04:04:46 -04:00
Make 3 character short names from long name when long name is only one word
This commit is contained in:
@@ -17,12 +17,22 @@ import com.geeksville.mesh.MyNodeInfo
|
||||
import com.geeksville.mesh.service.MeshService
|
||||
|
||||
/// Given a human name, strip out the first letter of the first three words and return that as the initials for
|
||||
/// that user.
|
||||
/// that user. If the original name is only one word, strip vowels from the original name and if the result is
|
||||
/// 3 or more characters, use the first three characters. If not, just take the first 3 characters of the
|
||||
/// original name.
|
||||
fun getInitials(name: String): String {
|
||||
val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }.take(3).map { it.first() }
|
||||
.joinToString("")
|
||||
val nchars = 3
|
||||
val minchars = 2
|
||||
val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||
|
||||
return words
|
||||
val initials = when (words.size) {
|
||||
in 0..minchars-1 -> {
|
||||
val nm = name.filterNot { c -> c.toLowerCase() in "aeiou" }
|
||||
if (nm.length >= nchars) nm else name
|
||||
}
|
||||
else -> words.map{ it.first() }.joinToString("")
|
||||
}
|
||||
return initials.take(nchars)
|
||||
}
|
||||
|
||||
class UIViewModel(app: Application) : AndroidViewModel(app), Logging {
|
||||
|
||||
Reference in New Issue
Block a user