Skip to content

Commit

Permalink
refactor #1484: migrated mifospay utils to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
PratyushSingh07 authored and therajanmaurya committed Jan 31, 2024
1 parent 20e68d4 commit 9e9742d
Show file tree
Hide file tree
Showing 40 changed files with 1,433 additions and 1,567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class LoginActivity : BaseActivity(), LoginView {
signup(mMifosSavingProductId)
} catch (e: Exception) {
// Google Sign In failed, update UI appropriately
DebugUtil.log(Constants.GOOGLE_SIGN_IN_FAILED, e.message)
e.message?.let { DebugUtil.log(Constants.GOOGLE_SIGN_IN_FAILED, it) }
Toaster.showToast(this, Constants.GOOGLE_SIGN_IN_FAILED)
hideProgressDialog()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
RecyclerItemClickListener(
activity,
object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val intent = Intent(
activity,
BankAccountDetailActivity::class.java
Expand All @@ -108,7 +108,7 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
startActivityForResult(intent, BANK_ACCOUNT_DETAILS_REQUEST_CODE)
}

override fun onItemLongPress(childView: View, position: Int) {}
override fun onItemLongPress(childView: View?, position: Int) {}
})
)
}
Expand Down Expand Up @@ -136,12 +136,16 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
DebugUtil.log("rescode ", resultCode)
if (requestCode == LINK_BANK_ACCOUNT_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
val bundle = data!!.extras
DebugUtil.log("bundle", bundle)
if (bundle != null) {
DebugUtil.log("bundle", bundle)
}
if (bundle != null) {
val bankAccountDetails = bundle.getParcelable<BankAccountDetails>(
Constants.NEW_BANK_ACCOUNT
)
DebugUtil.log("details", bankAccountDetails)
if (bankAccountDetails != null) {
DebugUtil.log("details", bankAccountDetails)
}
if (bankAccountDetails != null) {
mBankAccountsAdapter!!.addBank(bankAccountDetails)
}
Expand All @@ -152,7 +156,9 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
== Activity.RESULT_OK
) {
val bundle = data!!.extras
DebugUtil.log("bundle", bundle)
if (bundle != null) {
DebugUtil.log("bundle", bundle)
}
if (bundle != null) {
val bankAccountDetails = bundle.getParcelable<BankAccountDetails>(
Constants.UPDATED_BANK_ACCOUNT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class BankAccountDetailActivity : BaseActivity(), BankAccountDetailView {
DebugUtil.log("rescode ", resultCode)
if (requestCode == SETUP_UPI_REQUEST_CODE && resultCode == RESULT_OK) {
val bundle = data!!.extras
DebugUtil.log("bundle", bundle)
if (bundle != null) {
DebugUtil.log("bundle", bundle)
}
if (bundle != null) {
bankAccountDetails = bundle.getParcelable(Constants.UPDATED_BANK_ACCOUNT)
index = bundle.getInt(Constants.INDEX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
mRvPopularBanks!!.addOnItemTouchListener(
RecyclerItemClickListener(this,
object : SimpleOnItemClickListener() {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val bank = mPopularBankAdapter!!.getBank(position)
bankSelected = bank.name
val chooseSimDialog = ChooseSimDialog()
Expand All @@ -122,7 +122,7 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
mRvOtherBanks!!.addOnItemTouchListener(
RecyclerItemClickListener(this,
object : SimpleOnItemClickListener() {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val bank = mOtherBankAdapter!!.getBank(position)
bankSelected = bank.name
val chooseSimDialog = ChooseSimDialog()
Expand Down Expand Up @@ -172,7 +172,7 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
private fun setupAdapterData() {
val jsonObject: JSONObject
try {
jsonObject = FileUtils.readJson(this, "banks.json")
jsonObject = FileUtils.readJson(this, "banks.json")!!
banksList = ArrayList()
for (i in 0 until jsonObject.getJSONArray("banks").length()) {
banksList!!.add(
Expand All @@ -189,11 +189,11 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
popularBanks!!.add(Bank("HDFC Bank", R.drawable.logo_hdfc, 0))
popularBanks!!.add(Bank("ICICI Bank", R.drawable.logo_icici, 0))
popularBanks!!.add(Bank("AXIS Bank", R.drawable.logo_axis, 0))
DebugUtil.log(popularBanks, banksList)
DebugUtil.log(popularBanks!!, banksList!!)
mPopularBankAdapter!!.setData(popularBanks)
mOtherBankAdapter!!.setData(banksList)
} catch (e: Exception) {
DebugUtil.log(e.message)
e.message?.let { DebugUtil.log(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ class SetupUpiPinActivity : BaseActivity(), SetupUpiPinView {
override fun debitCardVerified(otp: String?) {
mTvDebitCard!!.visibility = View.VISIBLE
addFragment(OtpFragment.newInstance(otp), R.id.fl_otp)
AnimationUtil.collapse(mFlDebitCard)
AnimationUtil.expand(mFlOtp)
mFlDebitCard?.let { AnimationUtil.collapse(it) }
mFlOtp?.let { AnimationUtil.expand(it) }
}

fun otpVerified() {
mTvOtp!!.visibility = View.VISIBLE
addFragment(UpiPinFragment(), R.id.fl_upi_pin)
AnimationUtil.expand(mFlUpiPin)
AnimationUtil.collapse(mFlOtp)
mFlUpiPin?.let { AnimationUtil.expand(it) }
mFlOtp?.let { AnimationUtil.collapse(it) }
}

fun upiPinEntered(upiPin: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ class EditProfileActivity : BaseActivity(), EditProfileView {
}

override fun showDiscardChangesDialog() {
dialogBox!!.setOnPositiveListener { dialog, _ ->
dialogBox!!.setPositiveListener { dialog, _ ->
mPresenter!!.onDialogPositive()
dialog.dismiss()
}
dialogBox!!.setOnNegativeListener { dialog, which ->
dialogBox!!.setNegativeListener { dialog, which ->
mPresenter!!.onDialogNegative()
dialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class HistoryFragment : BaseFragment(), HistoryView {
RecyclerItemClickListener(
context,
object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
mPresenter!!.handleTransactionClick(position)
}

override fun onItemLongPress(childView: View, position: Int) {}
override fun onItemLongPress(childView: View?, position: Int) {}
})
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SpecificTransactionsActivity : BaseActivity(), SpecificTransactionsView {
mRvTransactions!!.addOnItemTouchListener(
RecyclerItemClickListener(this,
object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val intent = Intent(
this@SpecificTransactionsActivity,
ReceiptActivity::class.java
Expand All @@ -100,7 +100,7 @@ class SpecificTransactionsActivity : BaseActivity(), SpecificTransactionsView {
startActivity(intent)
}

override fun onItemLongPress(childView: View, position: Int) {}
override fun onItemLongPress(childView: View?, position: Int) {}
})
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ class ProfileFragment : BaseFragment(), ProfileView {
}

override fun showProfile(client: Client?) {
val drawable = TextDrawable.builder().beginConfig()
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.endConfig().buildRound(client?.name?.substring(0, 1), R.color.colorAccentBlack)
val drawable = client?.name?.substring(0, 1)?.let {
TextDrawable.builder().beginConfig()
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.endConfig().buildRound(it, R.color.colorAccentBlack)
}
ivUserImage?.setImageDrawable(drawable)
tvUserName?.text = client?.name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class InvoicesFragment : BaseFragment(), InvoicesView {
RecyclerItemClickListener(
activity,
object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val intent = Intent(activity, InvoiceActivity::class.java)
// incomplete
intent.data = mInvoicesPresenter!!.getUniqueInvoiceLink(
Expand All @@ -104,7 +104,7 @@ class InvoicesFragment : BaseFragment(), InvoicesView {
startActivity(intent)
}

override fun onItemLongPress(childView: View, position: Int) {}
override fun onItemLongPress(childView: View?, position: Int) {}
})
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class KYCLevel2Presenter @Inject constructor(
override fun updateFile(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
val uri = data.data
file = File(FileUtils.getPath(context, uri))
file = File(uri?.let { FileUtils.getPath(context, it) })
mKYCLevel2View!!.setFilename(file!!.path)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class MerchantsAdapter @Inject constructor() : RecyclerView.Adapter<MerchantsAda

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val mMerchant = merchants?.get(position)
val iconDrawable = TextDrawable.builder().beginConfig()
.endConfig().buildRound(
mMerchant?.clientName
?.substring(0, 1), R.color.colorAccentBlack
)
val iconDrawable = mMerchant?.clientName
?.substring(0, 1)?.let {
TextDrawable.builder().beginConfig()
.endConfig().buildRound(
it, R.color.colorAccentBlack
)
}
holder.mTvMerchantIcon?.setImageDrawable(iconDrawable)
holder.mTvMerchantName?.text = mMerchant?.clientName
holder.mTvMerchantExternalId?.text = mMerchant?.externalId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ class MerchantTransferActivity : BaseActivity(), MerchantTransferView {
tvMerchantName?.text =
intent.getStringExtra(Constants.MERCHANT_NAME)
tvMerchantVPA?.text = intent.getStringExtra(Constants.MERCHANT_VPA)
val drawable = TextDrawable.builder().beginConfig()
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.endConfig().buildRound(
intent.getStringExtra(Constants.MERCHANT_NAME)
?.substring(0, 1), R.color.colorPrimary
)
val drawable = intent.getStringExtra(Constants.MERCHANT_NAME)
?.substring(0, 1)?.let {
TextDrawable.builder().beginConfig()
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
.endConfig().buildRound(
it, R.color.colorPrimary
)
}
ivMerchantImage?.setImageDrawable(drawable)
showTransactionFetching()
setUpRecycleView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MerchantsFragment : BaseFragment(), MerchantsContract.MerchantsView {
RecyclerItemClickListener(
activity,
object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val merchantVPA: String? = mMerchantsAdapter?.merchants
?.get(position)?.externalId
val intent = Intent(
Expand All @@ -125,7 +125,7 @@ class MerchantsFragment : BaseFragment(), MerchantsContract.MerchantsView {
startActivity(intent)
}

override fun onItemLongPress(childView: View, position: Int) {
override fun onItemLongPress(childView: View?, position: Int) {
val clipboard = activity
?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val merchantVPA: String? = mMerchantsAdapter?.merchants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ class SignupPresenter @Inject constructor(
}

override fun checkPasswordStrength(password: String?) {
val p = PasswordStrength(password)
mSignupView!!.updatePasswordStrength(
p.strengthStringId,
p.colorResId, p.value
)
val p = password?.let { PasswordStrength(it) }
if (p != null) {
mSignupView!!.updatePasswordStrength(
p.strengthStringId,
p.colorResId, p.value
)
}
}

override fun registerUser(
Expand Down Expand Up @@ -151,7 +153,6 @@ class SignupPresenter @Inject constructor(
}

private fun createClient(userId: Int) {
DebugUtil.log("mob::::: ", mobileNumber)
val newClient = NewClient(
businessName, username, addressLine1,
addressLine2, city, pincode, stateId, countryId, mobileNumber,
Expand All @@ -161,7 +162,7 @@ class SignupPresenter @Inject constructor(
CreateClient.RequestValues(newClient),
object : UseCaseCallback<CreateClient.ResponseValue?> {
override fun onSuccess(response: CreateClient.ResponseValue?) {
DebugUtil.log(response?.clientId)
response?.clientId?.let { DebugUtil.log(it) }
val clients = ArrayList<Int>()
response?.clientId?.let { clients.add(it) }
updateClient(clients, userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class SignupActivity : BaseActivity(), SignupView {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {}
})
DebugUtil.log(mobileNumber, countryName, email, displayName, firstName, lastName, photoUri)
showProgressDialog(Constants.PLEASE_WAIT)
initSearchableStateSpinner()
}
Expand All @@ -168,17 +167,17 @@ class SignupActivity : BaseActivity(), SignupView {
try {
countryId = ""
jsonObject = FileUtils.readJson(this, "countries.json")
val countriesArray = jsonObject.getJSONArray("countries")
for (i in 0 until countriesArray.length()) {
val countriesArray = jsonObject?.getJSONArray("countries")
for (i in 0 until countriesArray?.length()!!) {
if (countriesArray.getJSONObject(i).getString("name") == countryName) {
countryId = countriesArray.getJSONObject(i).getString("id")
break
}
}
jsonObject = FileUtils.readJson(this, "states.json")
val statesJson = jsonObject.getJSONArray("states")
val statesJson = jsonObject?.getJSONArray("states")
val statesList = ArrayList<String>()
for (i in 0 until statesJson.length()) {
for (i in 0 until statesJson?.length()!!) {
val statesJsonObject = statesJson.getJSONObject(i)
if (statesJsonObject.getString("country_id") == countryId) {
statesList.add(statesJsonObject.getString("name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class CardsFragment : BaseFragment(), CardsView {
RecyclerItemClickListener(
activity,
object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(childView: View, position: Int) {
override fun onItemClick(childView: View?, position: Int) {
val savedCardMenu = PopupMenu(context, childView)
savedCardMenu.menuInflater.inflate(
R.menu.menu_saved_card,
Expand Down Expand Up @@ -192,7 +192,7 @@ class CardsFragment : BaseFragment(), CardsView {
savedCardMenu.show()
}

override fun onItemLongPress(childView: View, position: Int) {}
override fun onItemLongPress(childView: View?, position: Int) {}
})
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class SettingsActivity : BaseActivity(), SettingsView {

@OnClick(R.id.btn_disable_account)
fun onDisableAccountClicked() {
dialogBox.setOnPositiveListener { dialog, which -> mSettingsPresenter!!.disableAccount() }
dialogBox.setOnNegativeListener { dialog, which -> dialog.dismiss() }
dialogBox.setPositiveListener() { dialog, which -> mSettingsPresenter!!.disableAccount() }
dialogBox.setNegativeListener() { dialog, which -> dialog.dismiss() }
dialogBox.show(
this, R.string.alert_disable_account,
R.string.alert_disable_account_desc, R.string.ok, R.string.cancel
Expand Down
Loading

0 comments on commit 9e9742d

Please sign in to comment.