Skip to content

Commit

Permalink
Fixes #1968 : Java to Kotlin Migration (#1997)
Browse files Browse the repository at this point in the history
* Savings Java to kotlin

* Client Java to Kotlin

* MifosError Java to Kotlin

* Small changes
  • Loading branch information
Aditya-gupta99 committed Jul 20, 2023
1 parent b87fd8a commit 0d43a38
Show file tree
Hide file tree
Showing 116 changed files with 1,799 additions and 6,403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class DatabaseHelperCharge @Inject constructor() {
AsyncTask.THREAD_POOL_EXECUTOR.execute(Runnable {
for (charges: Charges in chargesPage.pageItems) {
charges.clientId = clientId
val clientDate = ClientDate(
0, charges.id.toLong(),
charges.dueDate[2],
charges.dueDate[1],
charges.dueDate[0]
)
val clientDate = charges.id?.toLong()?.let {
ClientDate(
0, it,
charges.dueDate[2],
charges.dueDate[1],
charges.dueDate[0]
)
}
charges.chargeDueDate = clientDate
charges.save()
}
Expand All @@ -62,9 +64,9 @@ class DatabaseHelperCharge @Inject constructor() {
//Setting the Charge Due Date
for (i in chargesList.indices) {
chargesList[i].dueDate = listOf(
chargesList[i].chargeDueDate.year,
chargesList[i].chargeDueDate.month,
chargesList[i].chargeDueDate.day
chargesList[i].chargeDueDate!!.year,
chargesList[i].chargeDueDate!!.month,
chargesList[i].chargeDueDate!!.day
)
}
val chargePage = Page<Charges>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ class DatabaseHelperClient @Inject constructor() {
*/
fun saveClient(client: Client): Observable<Client> {
return Observable.defer(Func0 { //Saving Client in Database
val clientDate = ClientDate(
client.id.toLong(), 0,
client.activationDate[0],
client.activationDate[1],
client.activationDate[2]
)
val clientDate = client.activationDate[0]?.let {
client.activationDate[1]?.let { it1 ->
client.activationDate[2]?.let { it2 ->
ClientDate(
client.id.toLong(), 0,
it,
it1,
it2
)
}
}
}
client.clientDate = clientDate
client.save()
Observable.just(client)
Expand Down Expand Up @@ -129,8 +135,9 @@ class DatabaseHelperClient @Inject constructor() {
.querySingle()
if (client != null) {
client.activationDate = listOf(
client.clientDate.day,
client.clientDate.month, client.clientDate.year
client.clientDate?.day,
client.clientDate?.month,
client.clientDate?.year
)
}
subscriber.onNext(client)
Expand Down Expand Up @@ -330,7 +337,7 @@ class DatabaseHelperClient @Inject constructor() {
return Observable.defer {
val currentTime = System.currentTimeMillis()
clientPayload.clientCreationTime = currentTime
if (clientPayload.datatables.isNotEmpty()) {
if (clientPayload.datatables?.isNotEmpty() == true) {
Observable.from<DataTablePayload>(clientPayload.datatables)
.subscribe { dataTablePayload ->
dataTablePayload.clientCreationTime = currentTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class DatabaseHelperSavings @Inject constructor() {
Observable.from(transactions)
.subscribe(Action1 { transaction ->
val savingsTransactionDate = SavingsTransactionDate(
transaction.id,
transaction.date[0],
transaction.date[1],
transaction.date[2]
transaction?.id,
transaction?.date?.get(0),
transaction?.date?.get(1),
transaction?.date?.get(2)
)
transaction.savingsAccountId = savingsAccountWithAssociations.id
transaction.savingsTransactionDate = savingsTransactionDate
transaction.save()
transaction?.savingsAccountId = savingsAccountWithAssociations.id
transaction?.savingsTransactionDate = savingsTransactionDate
transaction?.save()
})
}
savingsAccountWithAssociations.summary.savingsId = savingsAccountWithAssociations.id
savingsAccountWithAssociations.summary?.savingsId = savingsAccountWithAssociations.id
savingsAccountWithAssociations.save()
Observable.just(savingsAccountWithAssociations)
}
Expand Down Expand Up @@ -81,9 +81,9 @@ class DatabaseHelperSavings @Inject constructor() {
Observable.from(transactions)
.subscribe { transaction ->
transaction.date = listOf(
transaction.savingsTransactionDate.year,
transaction.savingsTransactionDate.month,
transaction.savingsTransactionDate.day
transaction.savingsTransactionDate?.year,
transaction.savingsTransactionDate?.month,
transaction.savingsTransactionDate?.day
)
}
if (savingsAccountWithAssociations != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class PinpointClientActivity : MifosBaseActivity(), PinPointClientMvpView, OnRef
@Inject
var pinPointClientPresenter: PinPointClientPresenter? = null
private var clientId = 0
private var apptableId = 0
private var dataTableId = 0
private var apptableId : Int? = 0
private var dataTableId : Int? = 0
private var addresses: List<ClientAddressResponse> = ArrayList()
override fun onItemLongClick(position: Int) {
apptableId = addresses[position].clientId
Expand All @@ -65,9 +65,13 @@ class PinpointClientActivity : MifosBaseActivity(), PinPointClientMvpView, OnRef
requestPermission(REQUEST_UPDATE_PLACE_PICKER)
}

1 -> pinPointClientPresenter?.deleteClientPinpointLocation(
apptableId, dataTableId
)
1 -> apptableId?.let {
dataTableId?.let { it1 ->
pinPointClientPresenter?.deleteClientPinpointLocation(
it, it1
)
}
}

else -> {}
}
Expand Down Expand Up @@ -277,10 +281,14 @@ class PinpointClientActivity : MifosBaseActivity(), PinPointClientMvpView, OnRef
if (requestCode == REQUEST_ADD_PLACE_PICKER) {
pinPointClientPresenter?.addClientPinpointLocation(clientId, clientAddressRequest)
} else if (requestCode == REQUEST_UPDATE_PLACE_PICKER) {
pinPointClientPresenter?.updateClientPinpointLocation(
apptableId, dataTableId,
clientAddressRequest
)
apptableId?.let {
dataTableId?.let { it1 ->
pinPointClientPresenter?.updateClientPinpointLocation(
it, it1,
clientAddressRequest
)
}
}
}
} else {
super.onActivityResult(requestCode, resultCode, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ClientNameListAdapter(
holder.tv_clientAccountNumber.text = client.accountNo

// lazy the load profile picture
if (client.isImagePresent) {
if (client.imagePresent) {
// make the image url
ImageLoaderUtils.loadImage(holder.itemView.context, client.id, holder.iv_userPicture)
} else {
Expand All @@ -68,7 +68,7 @@ class ClientNameListAdapter(
}
else Color.WHITE
)
holder.iv_sync_status.visibility = if (client.isSync) View.VISIBLE else View.INVISIBLE
holder.iv_sync_status.visibility = if (client.sync) View.VISIBLE else View.INVISIBLE
}

override fun getItemId(i: Int) = 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GroupListAdapter(context: Context, groups: List<Group>) : BaseAdapter() {
* Status Class that compares String Value to a Static String and returns
* if Status is Active or not
*/
if (Status.isActive(group.status.value)) {
if (group.status.value?.let { Status.isActive(it) } == true) {
binding.viewStatusIndicator.setBackgroundColor(
ContextCompat.getColor(context, R.color.deposit_green)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class PinpointClientAdapter @Inject constructor() :

private fun setMapLocation(map: GoogleMap?, location: ClientAddressResponse) {
// Add a marker for this item and set the camera
val latLng = LatLng(location.latitude, location.longitude)
val latLng = location.latitude?.let { location.longitude?.let { it1 -> LatLng(it, it1) } }
map!!.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13f))
map.addMarker(MarkerOptions().position(latLng))
map.addMarker(latLng?.let { MarkerOptions().position(it) })
// Set the map type back to normal.
map.mapType = GoogleMap.MAP_TYPE_NORMAL
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ class SavingsAccountTransactionsListAdapter(
convertView = view
}
binding.tvTransactionDate.text =
getDateAsString(listOfTransactions[i].date)
getDateAsString(listOfTransactions[i].date as List<Int>)
binding.tvTransactionType.text = listOfTransactions[i]
.transactionType.value
val transactionAmount = listOfTransactions[i].currency.displaySymbol +
.transactionType?.value
val transactionAmount = listOfTransactions[i].currency?.displaySymbol +
mContext.resources.getString(R.string.space) +
listOfTransactions[i].amount
binding.tvTransactionAmount.text = transactionAmount
if (listOfTransactions[i].transactionType.deposit) {
if (listOfTransactions[i].transactionType?.deposit == true) {
binding.tvTransactionAmount.setTextColor(
ContextCompat.getColor(mContext, R.color.savings_account_status_active)
)
} else if (listOfTransactions[i].transactionType.withdrawal) {
} else if (listOfTransactions[i].transactionType?.withdrawal == true) {
binding.tvTransactionAmount.setTextColor(Color.RED)
} else {
binding.tvTransactionAmount.setTextColor(Color.BLACK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ class SavingsAccountsListAdapter(context: Context, savingsAccountList: List<Savi
binding = view.tag as RowAccountItemBinding
convertView = view
}
if (savingsAccountList[i].status.active) {
if (savingsAccountList[i].status?.active == true) {
binding.viewStatusIndicator.setBackgroundColor(
ContextCompat.getColor(
context,
R.color.savings_account_status_active
)
)
} else if (savingsAccountList[i].status.approved) {
} else if (savingsAccountList[i].status?.approved == true) {
binding.viewStatusIndicator.setBackgroundColor(
ContextCompat.getColor(context, R.color.status_approved)
)
} else if (savingsAccountList[i].status.submittedAndPendingApproval) {
} else if (savingsAccountList[i].status?.submittedAndPendingApproval == true) {
binding.viewStatusIndicator.setBackgroundColor(
ContextCompat.getColor(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SyncPayloadsAdapter(var context: Context, payloads: List<ClientPayload>) :
else -> holder.binding.tvGender.text =
"Male"
}
if (clientPayload.isActive) {
if (clientPayload.active == true) {
holder.binding.tvActiveStatus.text =
true.toString()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ class SyncSavingsAccountTransactionAdapter @Inject constructor() :

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val transaction = mSavingsAccountTransactionRequests[position]
val paymentTypeName = getPaymentTypeName(
transaction.paymentTypeId.toInt(),
mPaymentTypeOptions
)
val paymentTypeName = transaction.paymentTypeId?.toInt()?.let {
getPaymentTypeName(
it,
mPaymentTypeOptions
)
}
holder.binding.tvSavingsAccountId.text = transaction.savingAccountId.toString()
holder.binding.tvPaymentType.text = paymentTypeName
holder.binding.tvTransactionType.text = transaction.transactionType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ChargeDialogFragment : ProgressableDialogFragment(), OnDatePickListener, C
createdCharge?.chargeId = chargeId
createdCharge?.amount = binding.amountDueCharge.editableText.toString().toDouble()
dueDateAsIntegerList = DateHelper.convertDateAsReverseInteger(dueDateString)
createdCharge?.dueDate = dueDateAsIntegerList
createdCharge?.dueDate = dueDateAsIntegerList as List<Int>
createdCharge?.name = chargeName
val chargesPayload = ChargesPayload()
chargesPayload.amount = binding.amountDueCharge.editableText.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LoanChargeDialogFragment : ProgressableDialogFragment(), OnDatePickListene
private var mfDatePicker: DialogFragment? = null
private var chargeId = 0
private var loanAccountNumber = 0
private val chargeNameIdHashMap = HashMap<String, Int>()
private val chargeNameIdHashMap = HashMap<String?, Int?>()
private var chargeName: String? = null
private var createdCharge: Charges? = null
private var dueDateAsIntegerList: List<Int>? = null
Expand Down Expand Up @@ -116,7 +116,7 @@ class LoanChargeDialogFragment : ProgressableDialogFragment(), OnDatePickListene
createdCharge?.amount = binding.amountDueCharge.editableText.toString().toDouble()
createdCharge?.name = chargeName
dueDateAsIntegerList = DateHelper.convertDateAsReverseInteger(dueDateString)
createdCharge?.dueDate = dueDateAsIntegerList
createdCharge?.dueDate = dueDateAsIntegerList as List<Int>
val chargesPayload = ChargesPayload()
chargesPayload.amount = binding.amountDueCharge.editableText.toString()
chargesPayload.locale = binding.etChargeLocale.editableText.toString()
Expand Down
Loading

0 comments on commit 0d43a38

Please sign in to comment.