Skip to content

Commit 9e9742d

Browse files
PratyushSingh07therajanmaurya
authored andcommitted
refactor #1484: migrated mifospay utils to kotlin
1 parent 20e68d4 commit 9e9742d

40 files changed

+1433
-1567
lines changed

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/auth/ui/LoginActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class LoginActivity : BaseActivity(), LoginView {
187187
signup(mMifosSavingProductId)
188188
} catch (e: Exception) {
189189
// Google Sign In failed, update UI appropriately
190-
DebugUtil.log(Constants.GOOGLE_SIGN_IN_FAILED, e.message)
190+
e.message?.let { DebugUtil.log(Constants.GOOGLE_SIGN_IN_FAILED, it) }
191191
Toaster.showToast(this, Constants.GOOGLE_SIGN_IN_FAILED)
192192
hideProgressDialog()
193193
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/AccountsFragment.kt

+11-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
9595
RecyclerItemClickListener(
9696
activity,
9797
object : RecyclerItemClickListener.OnItemClickListener {
98-
override fun onItemClick(childView: View, position: Int) {
98+
override fun onItemClick(childView: View?, position: Int) {
9999
val intent = Intent(
100100
activity,
101101
BankAccountDetailActivity::class.java
@@ -108,7 +108,7 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
108108
startActivityForResult(intent, BANK_ACCOUNT_DETAILS_REQUEST_CODE)
109109
}
110110

111-
override fun onItemLongPress(childView: View, position: Int) {}
111+
override fun onItemLongPress(childView: View?, position: Int) {}
112112
})
113113
)
114114
}
@@ -136,12 +136,16 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
136136
DebugUtil.log("rescode ", resultCode)
137137
if (requestCode == LINK_BANK_ACCOUNT_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
138138
val bundle = data!!.extras
139-
DebugUtil.log("bundle", bundle)
139+
if (bundle != null) {
140+
DebugUtil.log("bundle", bundle)
141+
}
140142
if (bundle != null) {
141143
val bankAccountDetails = bundle.getParcelable<BankAccountDetails>(
142144
Constants.NEW_BANK_ACCOUNT
143145
)
144-
DebugUtil.log("details", bankAccountDetails)
146+
if (bankAccountDetails != null) {
147+
DebugUtil.log("details", bankAccountDetails)
148+
}
145149
if (bankAccountDetails != null) {
146150
mBankAccountsAdapter!!.addBank(bankAccountDetails)
147151
}
@@ -152,7 +156,9 @@ class AccountsFragment : BaseFragment(), BankAccountsView {
152156
== Activity.RESULT_OK
153157
) {
154158
val bundle = data!!.extras
155-
DebugUtil.log("bundle", bundle)
159+
if (bundle != null) {
160+
DebugUtil.log("bundle", bundle)
161+
}
156162
if (bundle != null) {
157163
val bankAccountDetails = bundle.getParcelable<BankAccountDetails>(
158164
Constants.UPDATED_BANK_ACCOUNT

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/BankAccountDetailActivity.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ class BankAccountDetailActivity : BaseActivity(), BankAccountDetailView {
137137
DebugUtil.log("rescode ", resultCode)
138138
if (requestCode == SETUP_UPI_REQUEST_CODE && resultCode == RESULT_OK) {
139139
val bundle = data!!.extras
140-
DebugUtil.log("bundle", bundle)
140+
if (bundle != null) {
141+
DebugUtil.log("bundle", bundle)
142+
}
141143
if (bundle != null) {
142144
bankAccountDetails = bundle.getParcelable(Constants.UPDATED_BANK_ACCOUNT)
143145
index = bundle.getInt(Constants.INDEX)

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/LinkBankAccountActivity.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
111111
mRvPopularBanks!!.addOnItemTouchListener(
112112
RecyclerItemClickListener(this,
113113
object : SimpleOnItemClickListener() {
114-
override fun onItemClick(childView: View, position: Int) {
114+
override fun onItemClick(childView: View?, position: Int) {
115115
val bank = mPopularBankAdapter!!.getBank(position)
116116
bankSelected = bank.name
117117
val chooseSimDialog = ChooseSimDialog()
@@ -122,7 +122,7 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
122122
mRvOtherBanks!!.addOnItemTouchListener(
123123
RecyclerItemClickListener(this,
124124
object : SimpleOnItemClickListener() {
125-
override fun onItemClick(childView: View, position: Int) {
125+
override fun onItemClick(childView: View?, position: Int) {
126126
val bank = mOtherBankAdapter!!.getBank(position)
127127
bankSelected = bank.name
128128
val chooseSimDialog = ChooseSimDialog()
@@ -172,7 +172,7 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
172172
private fun setupAdapterData() {
173173
val jsonObject: JSONObject
174174
try {
175-
jsonObject = FileUtils.readJson(this, "banks.json")
175+
jsonObject = FileUtils.readJson(this, "banks.json")!!
176176
banksList = ArrayList()
177177
for (i in 0 until jsonObject.getJSONArray("banks").length()) {
178178
banksList!!.add(
@@ -189,11 +189,11 @@ class LinkBankAccountActivity : BaseActivity(), LinkBankAccountView {
189189
popularBanks!!.add(Bank("HDFC Bank", R.drawable.logo_hdfc, 0))
190190
popularBanks!!.add(Bank("ICICI Bank", R.drawable.logo_icici, 0))
191191
popularBanks!!.add(Bank("AXIS Bank", R.drawable.logo_axis, 0))
192-
DebugUtil.log(popularBanks, banksList)
192+
DebugUtil.log(popularBanks!!, banksList!!)
193193
mPopularBankAdapter!!.setData(popularBanks)
194194
mOtherBankAdapter!!.setData(banksList)
195195
} catch (e: Exception) {
196-
DebugUtil.log(e.message)
196+
e.message?.let { DebugUtil.log(it) }
197197
}
198198
}
199199

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/SetupUpiPinActivity.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ class SetupUpiPinActivity : BaseActivity(), SetupUpiPinView {
9696
override fun debitCardVerified(otp: String?) {
9797
mTvDebitCard!!.visibility = View.VISIBLE
9898
addFragment(OtpFragment.newInstance(otp), R.id.fl_otp)
99-
AnimationUtil.collapse(mFlDebitCard)
100-
AnimationUtil.expand(mFlOtp)
99+
mFlDebitCard?.let { AnimationUtil.collapse(it) }
100+
mFlOtp?.let { AnimationUtil.expand(it) }
101101
}
102102

103103
fun otpVerified() {
104104
mTvOtp!!.visibility = View.VISIBLE
105105
addFragment(UpiPinFragment(), R.id.fl_upi_pin)
106-
AnimationUtil.expand(mFlUpiPin)
107-
AnimationUtil.collapse(mFlOtp)
106+
mFlUpiPin?.let { AnimationUtil.expand(it) }
107+
mFlOtp?.let { AnimationUtil.collapse(it) }
108108
}
109109

110110
fun upiPinEntered(upiPin: String?) {

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ class EditProfileActivity : BaseActivity(), EditProfileView {
436436
}
437437

438438
override fun showDiscardChangesDialog() {
439-
dialogBox!!.setOnPositiveListener { dialog, _ ->
439+
dialogBox!!.setPositiveListener { dialog, _ ->
440440
mPresenter!!.onDialogPositive()
441441
dialog.dismiss()
442442
}
443-
dialogBox!!.setOnNegativeListener { dialog, which ->
443+
dialogBox!!.setNegativeListener { dialog, which ->
444444
mPresenter!!.onDialogNegative()
445445
dialog.dismiss()
446446
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/HistoryFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ class HistoryFragment : BaseFragment(), HistoryView {
110110
RecyclerItemClickListener(
111111
context,
112112
object : RecyclerItemClickListener.OnItemClickListener {
113-
override fun onItemClick(childView: View, position: Int) {
113+
override fun onItemClick(childView: View?, position: Int) {
114114
mPresenter!!.handleTransactionClick(position)
115115
}
116116

117-
override fun onItemLongPress(childView: View, position: Int) {}
117+
override fun onItemLongPress(childView: View?, position: Int) {}
118118
})
119119
)
120120
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/SpecificTransactionsActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class SpecificTransactionsActivity : BaseActivity(), SpecificTransactionsView {
8686
mRvTransactions!!.addOnItemTouchListener(
8787
RecyclerItemClickListener(this,
8888
object : RecyclerItemClickListener.OnItemClickListener {
89-
override fun onItemClick(childView: View, position: Int) {
89+
override fun onItemClick(childView: View?, position: Int) {
9090
val intent = Intent(
9191
this@SpecificTransactionsActivity,
9292
ReceiptActivity::class.java
@@ -100,7 +100,7 @@ class SpecificTransactionsActivity : BaseActivity(), SpecificTransactionsView {
100100
startActivity(intent)
101101
}
102102

103-
override fun onItemLongPress(childView: View, position: Int) {}
103+
override fun onItemLongPress(childView: View?, position: Int) {}
104104
})
105105
)
106106
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileFragment.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ class ProfileFragment : BaseFragment(), ProfileView {
116116
}
117117

118118
override fun showProfile(client: Client?) {
119-
val drawable = TextDrawable.builder().beginConfig()
120-
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
121-
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
122-
.endConfig().buildRound(client?.name?.substring(0, 1), R.color.colorAccentBlack)
119+
val drawable = client?.name?.substring(0, 1)?.let {
120+
TextDrawable.builder().beginConfig()
121+
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
122+
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
123+
.endConfig().buildRound(it, R.color.colorAccentBlack)
124+
}
123125
ivUserImage?.setImageDrawable(drawable)
124126
tvUserName?.text = client?.name
125127
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/invoice/ui/InvoicesFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class InvoicesFragment : BaseFragment(), InvoicesView {
9595
RecyclerItemClickListener(
9696
activity,
9797
object : RecyclerItemClickListener.OnItemClickListener {
98-
override fun onItemClick(childView: View, position: Int) {
98+
override fun onItemClick(childView: View?, position: Int) {
9999
val intent = Intent(activity, InvoiceActivity::class.java)
100100
// incomplete
101101
intent.data = mInvoicesPresenter!!.getUniqueInvoiceLink(
@@ -104,7 +104,7 @@ class InvoicesFragment : BaseFragment(), InvoicesView {
104104
startActivity(intent)
105105
}
106106

107-
override fun onItemLongPress(childView: View, position: Int) {}
107+
override fun onItemLongPress(childView: View?, position: Int) {}
108108
})
109109
)
110110
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/kyc/presenter/KYCLevel2Presenter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class KYCLevel2Presenter @Inject constructor(
6262
override fun updateFile(requestCode: Int, resultCode: Int, data: Intent?) {
6363
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
6464
val uri = data.data
65-
file = File(FileUtils.getPath(context, uri))
65+
file = File(uri?.let { FileUtils.getPath(context, it) })
6666
mKYCLevel2View!!.setFilename(file!!.path)
6767
}
6868
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/adapter/MerchantsAdapter.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ class MerchantsAdapter @Inject constructor() : RecyclerView.Adapter<MerchantsAda
3131

3232
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
3333
val mMerchant = merchants?.get(position)
34-
val iconDrawable = TextDrawable.builder().beginConfig()
35-
.endConfig().buildRound(
36-
mMerchant?.clientName
37-
?.substring(0, 1), R.color.colorAccentBlack
38-
)
34+
val iconDrawable = mMerchant?.clientName
35+
?.substring(0, 1)?.let {
36+
TextDrawable.builder().beginConfig()
37+
.endConfig().buildRound(
38+
it, R.color.colorAccentBlack
39+
)
40+
}
3941
holder.mTvMerchantIcon?.setImageDrawable(iconDrawable)
4042
holder.mTvMerchantName?.text = mMerchant?.clientName
4143
holder.mTvMerchantExternalId?.text = mMerchant?.externalId

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/ui/MerchantTransferActivity.kt

+9-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ class MerchantTransferActivity : BaseActivity(), MerchantTransferView {
105105
tvMerchantName?.text =
106106
intent.getStringExtra(Constants.MERCHANT_NAME)
107107
tvMerchantVPA?.text = intent.getStringExtra(Constants.MERCHANT_VPA)
108-
val drawable = TextDrawable.builder().beginConfig()
109-
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
110-
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
111-
.endConfig().buildRound(
112-
intent.getStringExtra(Constants.MERCHANT_NAME)
113-
?.substring(0, 1), R.color.colorPrimary
114-
)
108+
val drawable = intent.getStringExtra(Constants.MERCHANT_NAME)
109+
?.substring(0, 1)?.let {
110+
TextDrawable.builder().beginConfig()
111+
.width(resources.getDimension(R.dimen.user_profile_image_size).toInt())
112+
.height(resources.getDimension(R.dimen.user_profile_image_size).toInt())
113+
.endConfig().buildRound(
114+
it, R.color.colorPrimary
115+
)
116+
}
115117
ivMerchantImage?.setImageDrawable(drawable)
116118
showTransactionFetching()
117119
setUpRecycleView()

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/ui/MerchantsFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class MerchantsFragment : BaseFragment(), MerchantsContract.MerchantsView {
101101
RecyclerItemClickListener(
102102
activity,
103103
object : RecyclerItemClickListener.OnItemClickListener {
104-
override fun onItemClick(childView: View, position: Int) {
104+
override fun onItemClick(childView: View?, position: Int) {
105105
val merchantVPA: String? = mMerchantsAdapter?.merchants
106106
?.get(position)?.externalId
107107
val intent = Intent(
@@ -125,7 +125,7 @@ class MerchantsFragment : BaseFragment(), MerchantsContract.MerchantsView {
125125
startActivity(intent)
126126
}
127127

128-
override fun onItemLongPress(childView: View, position: Int) {
128+
override fun onItemLongPress(childView: View?, position: Int) {
129129
val clipboard = activity
130130
?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
131131
val merchantVPA: String? = mMerchantsAdapter?.merchants

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ class SignupPresenter @Inject constructor(
8787
}
8888

8989
override fun checkPasswordStrength(password: String?) {
90-
val p = PasswordStrength(password)
91-
mSignupView!!.updatePasswordStrength(
92-
p.strengthStringId,
93-
p.colorResId, p.value
94-
)
90+
val p = password?.let { PasswordStrength(it) }
91+
if (p != null) {
92+
mSignupView!!.updatePasswordStrength(
93+
p.strengthStringId,
94+
p.colorResId, p.value
95+
)
96+
}
9597
}
9698

9799
override fun registerUser(
@@ -151,7 +153,6 @@ class SignupPresenter @Inject constructor(
151153
}
152154

153155
private fun createClient(userId: Int) {
154-
DebugUtil.log("mob::::: ", mobileNumber)
155156
val newClient = NewClient(
156157
businessName, username, addressLine1,
157158
addressLine2, city, pincode, stateId, countryId, mobileNumber,
@@ -161,7 +162,7 @@ class SignupPresenter @Inject constructor(
161162
CreateClient.RequestValues(newClient),
162163
object : UseCaseCallback<CreateClient.ResponseValue?> {
163164
override fun onSuccess(response: CreateClient.ResponseValue?) {
164-
DebugUtil.log(response?.clientId)
165+
response?.clientId?.let { DebugUtil.log(it) }
165166
val clients = ArrayList<Int>()
166167
response?.clientId?.let { clients.add(it) }
167168
updateClient(clients, userId)

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class SignupActivity : BaseActivity(), SignupView {
158158
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
159159
override fun afterTextChanged(s: Editable) {}
160160
})
161-
DebugUtil.log(mobileNumber, countryName, email, displayName, firstName, lastName, photoUri)
162161
showProgressDialog(Constants.PLEASE_WAIT)
163162
initSearchableStateSpinner()
164163
}
@@ -168,17 +167,17 @@ class SignupActivity : BaseActivity(), SignupView {
168167
try {
169168
countryId = ""
170169
jsonObject = FileUtils.readJson(this, "countries.json")
171-
val countriesArray = jsonObject.getJSONArray("countries")
172-
for (i in 0 until countriesArray.length()) {
170+
val countriesArray = jsonObject?.getJSONArray("countries")
171+
for (i in 0 until countriesArray?.length()!!) {
173172
if (countriesArray.getJSONObject(i).getString("name") == countryName) {
174173
countryId = countriesArray.getJSONObject(i).getString("id")
175174
break
176175
}
177176
}
178177
jsonObject = FileUtils.readJson(this, "states.json")
179-
val statesJson = jsonObject.getJSONArray("states")
178+
val statesJson = jsonObject?.getJSONArray("states")
180179
val statesList = ArrayList<String>()
181-
for (i in 0 until statesJson.length()) {
180+
for (i in 0 until statesJson?.length()!!) {
182181
val statesJsonObject = statesJson.getJSONObject(i)
183182
if (statesJsonObject.getString("country_id") == countryId) {
184183
statesList.add(statesJsonObject.getString("name"))

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/savedcards/ui/CardsFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class CardsFragment : BaseFragment(), CardsView {
162162
RecyclerItemClickListener(
163163
activity,
164164
object : RecyclerItemClickListener.OnItemClickListener {
165-
override fun onItemClick(childView: View, position: Int) {
165+
override fun onItemClick(childView: View?, position: Int) {
166166
val savedCardMenu = PopupMenu(context, childView)
167167
savedCardMenu.menuInflater.inflate(
168168
R.menu.menu_saved_card,
@@ -192,7 +192,7 @@ class CardsFragment : BaseFragment(), CardsView {
192192
savedCardMenu.show()
193193
}
194194

195-
override fun onItemLongPress(childView: View, position: Int) {}
195+
override fun onItemLongPress(childView: View?, position: Int) {}
196196
})
197197
)
198198
}

Diff for: mifospay/src/main/java/org/mifos/mobilewallet/mifospay/settings/ui/SettingsActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class SettingsActivity : BaseActivity(), SettingsView {
4949

5050
@OnClick(R.id.btn_disable_account)
5151
fun onDisableAccountClicked() {
52-
dialogBox.setOnPositiveListener { dialog, which -> mSettingsPresenter!!.disableAccount() }
53-
dialogBox.setOnNegativeListener { dialog, which -> dialog.dismiss() }
52+
dialogBox.setPositiveListener() { dialog, which -> mSettingsPresenter!!.disableAccount() }
53+
dialogBox.setNegativeListener() { dialog, which -> dialog.dismiss() }
5454
dialogBox.show(
5555
this, R.string.alert_disable_account,
5656
R.string.alert_disable_account_desc, R.string.ok, R.string.cancel

0 commit comments

Comments
 (0)