therajanmaurya commented on a change in pull request #15: feat: ledger and account URL: https://github.com/apache/fineract-cn-mobile/pull/15#discussion_r204980120
########## File path: app/src/main/java/org/apache/fineract/ui/adapters/LedgerAdapter.kt ########## @@ -0,0 +1,65 @@ +package org.apache.fineract.ui.adapters + +import android.content.Context +import android.support.v7.widget.AppCompatImageView +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import kotlinx.android.synthetic.main.item_ledger.view.* +import org.apache.fineract.R +import org.apache.fineract.data.models.accounts.Ledger +import org.apache.fineract.injection.ApplicationContext +import org.apache.fineract.utils.DateUtils +import org.apache.fineract.utils.StatusUtils +import javax.inject.Inject + +class LedgerAdapter @Inject constructor(@ApplicationContext val context: Context) + : RecyclerView.Adapter<LedgerAdapter.ViewHolder>() { + + private var ledgers: List<Ledger> = ArrayList() + + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { + + val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_ledger, parent, false) + return ViewHolder(view) + } + + override fun getItemCount(): Int = ledgers.size + + override fun onBindViewHolder(holder: ViewHolder?, position: Int) { + + val ledger = ledgers[position] + + holder?.tvLedgerIdentifier?.text = ledger.identifier + + val modifiedBy = context.getString(R.string.last_modified_by) + context.getString( + R.string.colon) + ledger.lastModifiedBy + holder?.tvModifiedBy?.text = modifiedBy + + val lastModifiedOn = context.getString(R.string.last_modified_on) + context.getString( + R.string.colon) + + DateUtils.getDate(ledger.lastModifiedOn, + DateUtils.INPUT_DATE_FORMAT, DateUtils.OUTPUT_DATE_FORMAT) + + StatusUtils.setAccountType(ledger.type, holder?.ivAccountTypeIndicator, context) + + holder?.tvModifiedOn?.text = lastModifiedOn + holder?.tvTotalValue?.text = ledger.totalValue.toString() + } + + fun setLedgerList(ledgers: List<Ledger>) { + this.ledgers = ledgers + notifyDataSetChanged() + } + + class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) { + + val tvLedgerIdentifier: TextView? = itemView?.tv_ledger_identifier Review comment: @mohak1712 why are we using this ? null safety, In any case these views are not in item xml? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services