in mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt [270:308]
fun bind(item: Profile) {
this.item = item
val editable = isProfileEditable(item.id)
edit.isEnabled = editable
edit.alpha = if (editable) 1F else .5F
subscription.isEnabled = editable
subscription.alpha = if (editable) 1F else .5F
var tx = item.tx
var rx = item.rx
statsCache[item.id]?.apply {
tx += txTotal
rx += rxTotal
}
text1.text = item.formattedName
text2.text = ArrayList<String>().apply {
if (!item.name.isNullOrEmpty()) this += item.formattedAddress
val id = PluginConfiguration(item.plugin ?: "").selected
if (id.isNotEmpty()) this += getString(R.string.profile_plugin, id)
}.joinToString("\n")
val context = requireContext()
traffic.text = if (tx <= 0 && rx <= 0) null else getString(R.string.traffic,
Formatter.formatFileSize(context, tx), Formatter.formatFileSize(context, rx))
if (item.id == DataStore.profileId) {
itemView.isSelected = true
selectedItem = this
} else {
itemView.isSelected = false
if (selectedItem === this) selectedItem = null
}
if (item.subscription == Profile.SubscriptionStatus.Active) {
edit.visibility = View.GONE
subscription.visibility = View.VISIBLE
} else {
edit.visibility = View.VISIBLE
subscription.visibility = View.GONE
}
}