Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2142: migrated beneficiary adapters to viewbinding #2162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,70 +1,59 @@
package org.mifos.mobile.ui.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import org.mifos.mobile.R
import org.mifos.mobile.databinding.RowBeneficiaryBinding
import org.mifos.mobile.models.beneficiary.Beneficiary
import javax.inject.Inject

/**
* Created by dilpreet on 15/6/17.
*/
class BeneficiaryListAdapter constructor(
val onItemClick: (itemPosition: Int) -> Unit
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
RecyclerView.Adapter<BeneficiaryListAdapter.ViewHolder>() {

private var beneficiaryList: List<Beneficiary?>? = ArrayList()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.row_beneficiary, parent, false)
val vh = ViewHolder(view)
view.setOnClickListener {
onItemClick(vh.bindingAdapterPosition)
}
return vh

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = RowBeneficiaryBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (beneficiaryList?.get(position) != null) {
val (_, name, officeName, _, _, accountNumber, transferLimit) =
beneficiaryList?.get(position)!!
(holder as ViewHolder).tvAccountNumber?.text = accountNumber
holder.tvName?.text = name
holder.tvOfficeName?.text = officeName
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val beneficiaryItem = beneficiaryList?.get(position)
holder.bind(beneficiaryItem)
}

override fun getItemCount(): Int {
return if (beneficiaryList != null) beneficiaryList!!.size
else 0
return beneficiaryList?.size ?: 0
}

fun setBeneficiaryList(beneficiaryList: List<Beneficiary?>?) {
this.beneficiaryList = beneficiaryList
notifyDataSetChanged()
}

inner class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
@JvmField
@BindView(R.id.tv_beneficiary_name)
var tvName: TextView? = null

@JvmField
@BindView(R.id.tv_account_number)
var tvAccountNumber: TextView? = null

@JvmField
@BindView(R.id.tv_office_name)
var tvOfficeName: TextView? = null
inner class ViewHolder(val binding: RowBeneficiaryBinding) : RecyclerView.ViewHolder(binding.root) {

init {
ButterKnife.bind(this, itemView!!)
binding.root.setOnClickListener {
onItemClick(bindingAdapterPosition)
}
}

fun bind (beneficiary: Beneficiary?) {
with(binding) {
tvAccountNumber.text = beneficiary?.accountNumber
tvBeneficiaryName.text = beneficiary?.name
tvOfficeName.text = beneficiary?.officeName
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
package org.mifos.mobile.ui.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView

import butterknife.BindView
import butterknife.ButterKnife

import org.mifos.mobile.R
import org.mifos.mobile.models.beneficiary.BeneficiaryDetail

/*
* Created by saksham on 18/June/2018
*/
class BeneficiarySpinnerAdapter(context: Context, private var resource: Int, var list: MutableList<BeneficiaryDetail?>) :
ArrayAdapter<String?>(context, resource, 0, list as List<String?>) {
import org.mifos.mobile.models.beneficiary.BeneficiaryDetail
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import org.mifos.mobile.databinding.BeneficiarySpinnerLayoutBinding

@JvmField
@BindView(R.id.tv_account_number)
var tvAccountNumber: TextView? = null
class BeneficiarySpinnerAdapter(
context: Context,
private var resource: Int,
private var list: MutableList<BeneficiaryDetail?>
) : ArrayAdapter<String?>(context, resource, 0, list as List<String?>) {

@JvmField
@BindView(R.id.tv_beneficiary_name)
var tvBeneficiaryName: TextView? = null
private var layoutInflater: LayoutInflater = LayoutInflater.from(context)
private lateinit var binding: BeneficiarySpinnerLayoutBinding

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
return createItemView(position, convertView, parent)
}

override fun getDropDownView(
position: Int, convertView: View?,
parent: ViewGroup
): View {
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
return createItemView(position, convertView, parent)
}

private fun createItemView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view = layoutInflater.inflate(resource, parent, false)
ButterKnife.bind(this, view)
tvAccountNumber?.text = list[position]?.accountNumber
tvBeneficiaryName?.text = list[position]?.beneficiaryName
private fun createItemView(position: Int, convertView: View?, parent: ViewGroup): View {
val binding = BeneficiarySpinnerLayoutBinding.inflate(layoutInflater, parent, false)
val view = binding.root
this.binding = binding

binding.tvAccountNumber.text = list[position]?.accountNumber
binding.tvBeneficiaryName.text = list[position]?.beneficiaryName

return view
}

override fun getItem(position: Int): String? {
return list[position]?.accountNumber
}

}
}