Compare commits

...

2 commits

Author SHA1 Message Date
95155d953a Move data binding to the view holder 2022-04-30 17:32:38 -04:00
90bf7601bd Make EuiccProfileAdapter a inner class
We need to access the internals (later)
2022-04-30 17:28:07 -04:00

View file

@ -75,11 +75,8 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
} }
} }
} }
}
class EuiccProfileAdapter(var profiles: List<Map<String, String>>) : inner class ViewHolder(private val binding: EuiccProfileBinding) : RecyclerView.ViewHolder(binding.root) {
RecyclerView.Adapter<EuiccProfileAdapter.ViewHolder>() {
data class ViewHolder(val binding: EuiccProfileBinding) : RecyclerView.ViewHolder(binding.root) {
init { init {
binding.iccid.setOnClickListener { binding.iccid.setOnClickListener {
if (binding.iccid.transformationMethod == null) { if (binding.iccid.transformationMethod == null) {
@ -89,8 +86,27 @@ class EuiccProfileAdapter(var profiles: List<Map<String, String>>) :
} }
} }
} }
private lateinit var profile: Map<String, String>
fun setProfile(profile: Map<String, String>) {
this.profile = profile
// TODO: The library is not exposing the nicknames. Expose them so that we can do something here.
binding.name.text = profile["NAME"]
binding.state.setText(
if (profile["STATE"]?.lowercase() == "enabled") {
R.string.enabled
} else {
R.string.disabled
}
)
binding.provider.text = profile["PROVIDER_NAME"]
binding.iccid.text = profile["ICCID"]
binding.iccid.transformationMethod = PasswordTransformationMethod.getInstance()
}
} }
inner class EuiccProfileAdapter(var profiles: List<Map<String, String>>) : RecyclerView.Adapter<ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = val binding =
EuiccProfileBinding.inflate(LayoutInflater.from(parent.context), parent, false) EuiccProfileBinding.inflate(LayoutInflater.from(parent.context), parent, false)
@ -98,19 +114,9 @@ class EuiccProfileAdapter(var profiles: List<Map<String, String>>) :
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// TODO: The library is not exposing the nicknames. Expose them so that we can do something here. holder.setProfile(profiles[position])
holder.binding.name.text = profiles[position]["NAME"]
holder.binding.state.setText(
if (profiles[position]["STATE"]?.lowercase() == "enabled") {
R.string.enabled
} else {
R.string.disabled
}
)
holder.binding.provider.text = profiles[position]["PROVIDER_NAME"]
holder.binding.iccid.text = profiles[position]["ICCID"]
holder.binding.iccid.transformationMethod = PasswordTransformationMethod.getInstance()
} }
override fun getItemCount(): Int = profiles.size override fun getItemCount(): Int = profiles.size
} }
}