diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/auth/ui/LoginActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/auth/ui/LoginActivity.kt index 7c3150ae2..cf87923a4 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/auth/ui/LoginActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/auth/ui/LoginActivity.kt @@ -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() } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/AccountsFragment.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/AccountsFragment.kt index 7cce0c02d..9c7c656ec 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/AccountsFragment.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/AccountsFragment.kt @@ -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 @@ -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) {} }) ) } @@ -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( Constants.NEW_BANK_ACCOUNT ) - DebugUtil.log("details", bankAccountDetails) + if (bankAccountDetails != null) { + DebugUtil.log("details", bankAccountDetails) + } if (bankAccountDetails != null) { mBankAccountsAdapter!!.addBank(bankAccountDetails) } @@ -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( Constants.UPDATED_BANK_ACCOUNT diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/BankAccountDetailActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/BankAccountDetailActivity.kt index 4002bf4ed..0680dbec2 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/BankAccountDetailActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/BankAccountDetailActivity.kt @@ -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) diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/LinkBankAccountActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/LinkBankAccountActivity.kt index 6fa7a0064..3292c904a 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/LinkBankAccountActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/LinkBankAccountActivity.kt @@ -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() @@ -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() @@ -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( @@ -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) } } } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/SetupUpiPinActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/SetupUpiPinActivity.kt index 95bccb67d..ac33c179b 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/SetupUpiPinActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/ui/SetupUpiPinActivity.kt @@ -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?) { diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt index 3fce5ba19..f440de914 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt @@ -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() } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/HistoryFragment.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/HistoryFragment.kt index 951f6922e..d9974dcc3 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/HistoryFragment.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/HistoryFragment.kt @@ -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) {} }) ) } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/SpecificTransactionsActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/SpecificTransactionsActivity.kt index 03a7a7725..ea618bfba 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/SpecificTransactionsActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/history/ui/SpecificTransactionsActivity.kt @@ -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 @@ -100,7 +100,7 @@ class SpecificTransactionsActivity : BaseActivity(), SpecificTransactionsView { startActivity(intent) } - override fun onItemLongPress(childView: View, position: Int) {} + override fun onItemLongPress(childView: View?, position: Int) {} }) ) } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileFragment.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileFragment.kt index 2a8ff424a..0981a6466 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileFragment.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileFragment.kt @@ -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 } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/invoice/ui/InvoicesFragment.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/invoice/ui/InvoicesFragment.kt index ab26fe994..fc7faf733 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/invoice/ui/InvoicesFragment.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/invoice/ui/InvoicesFragment.kt @@ -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( @@ -104,7 +104,7 @@ class InvoicesFragment : BaseFragment(), InvoicesView { startActivity(intent) } - override fun onItemLongPress(childView: View, position: Int) {} + override fun onItemLongPress(childView: View?, position: Int) {} }) ) } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/kyc/presenter/KYCLevel2Presenter.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/kyc/presenter/KYCLevel2Presenter.kt index b7a512748..dd43d0c56 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/kyc/presenter/KYCLevel2Presenter.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/kyc/presenter/KYCLevel2Presenter.kt @@ -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) } } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/adapter/MerchantsAdapter.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/adapter/MerchantsAdapter.kt index 22856c298..1ea2a7810 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/adapter/MerchantsAdapter.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/merchants/adapter/MerchantsAdapter.kt @@ -31,11 +31,13 @@ class MerchantsAdapter @Inject constructor() : RecyclerView.Adapter { override fun onSuccess(response: CreateClient.ResponseValue?) { - DebugUtil.log(response?.clientId) + response?.clientId?.let { DebugUtil.log(it) } val clients = ArrayList() response?.clientId?.let { clients.add(it) } updateClient(clients, userId) diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt index 530118fc8..ed8f5267c 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt @@ -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() } @@ -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() - 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")) diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/savedcards/ui/CardsFragment.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/savedcards/ui/CardsFragment.kt index e45d7183e..8d24627dc 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/savedcards/ui/CardsFragment.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/savedcards/ui/CardsFragment.kt @@ -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, @@ -192,7 +192,7 @@ class CardsFragment : BaseFragment(), CardsView { savedCardMenu.show() } - override fun onItemLongPress(childView: View, position: Int) {} + override fun onItemLongPress(childView: View?, position: Int) {} }) ) } diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/settings/ui/SettingsActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/settings/ui/SettingsActivity.kt index 82cd79d84..e5fbb4fc2 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/settings/ui/SettingsActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/settings/ui/SettingsActivity.kt @@ -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 diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIDetailsActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIDetailsActivity.kt index 76cd4defa..f875b9d14 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIDetailsActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIDetailsActivity.kt @@ -290,14 +290,14 @@ class SIDetailsActivity : BaseActivity(), StandingInstructionContract.SIDetailsV private fun showConfirmDeleteDialog() { val dialogBox = DialogBox() - dialogBox.setOnPositiveListener { dialog, which -> + dialogBox.setPositiveListener() { dialog, which -> if (this.standingInstructionId != 0L) { mStandingInstructionPresenter.deleteStandingInstruction( this.standingInstructionId ) } } - dialogBox.setOnNegativeListener { dialog, which -> + dialogBox.setNegativeListener() { dialog, which -> dialog.dismiss() } dialogBox.show( @@ -308,14 +308,14 @@ class SIDetailsActivity : BaseActivity(), StandingInstructionContract.SIDetailsV private fun showDiscardChangesDialog() { val dialogBox = DialogBox() - dialogBox.setOnPositiveListener { dialog, which -> + dialogBox.setPositiveListener() { dialog, which -> binding.fab.hide() dialog.dismiss() editDetails(false) revertLocalChanges() binding.fab.show() } - dialogBox.setOnNegativeListener { dialog, which -> + dialogBox.setNegativeListener() { dialog, which -> dialog.dismiss() } dialogBox.show( diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIFragment.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIFragment.kt index a0674e177..6ee4ea88e 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIFragment.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/SIFragment.kt @@ -73,11 +73,9 @@ class SIFragment : BaseFragment(), StandingInstructionContract.SIListView { binding.rvSi.adapter = mSIAdapter binding.rvSi.addOnItemTouchListener(RecyclerItemClickListener(context, object : RecyclerItemClickListener.OnItemClickListener { - override fun onItemLongPress(childView: View?, position: Int) { + override fun onItemLongPress(childView: View?, position: Int) {} - } - - override fun onItemClick(childView: View, position: Int) { + override fun onItemClick(childView: View?, position: Int) { val intent = Intent(activity, SIDetailsActivity::class.java) val standingInstructionId = mSIAdapter.getStandingInstruction(position)?.id diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/AnimationUtil.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/AnimationUtil.java deleted file mode 100644 index 4748b1c77..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/AnimationUtil.java +++ /dev/null @@ -1,189 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.view.View; -import android.view.animation.AccelerateInterpolator; -import android.view.animation.Animation; -import android.view.animation.Transformation; -import android.view.animation.TranslateAnimation; -import android.widget.LinearLayout; - -/** - * Created by ankur on 27/June/2018 - */ - -public class AnimationUtil { - - public static void expand(final View v) { - v.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - final int targetHeight = v.getMeasuredHeight(); - - // Older versions of android (pre API 21) cancel animations for views with a height of 0. - v.getLayoutParams().height = 1; - v.setVisibility(View.VISIBLE); - Animation a = new Animation() { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - v.getLayoutParams().height = interpolatedTime == 1 - ? LinearLayout.LayoutParams.WRAP_CONTENT - : (int) (targetHeight * interpolatedTime); - v.requestLayout(); - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration( - (int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - public static void collapse(final View v) { - final int initialHeight = v.getMeasuredHeight(); - - Animation a = new Animation() { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - if (interpolatedTime == 1) { - v.setVisibility(View.GONE); - } else { - v.getLayoutParams().height = - initialHeight - (int) (initialHeight * interpolatedTime); - v.requestLayout(); - } - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration( - (int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - public static void inFromRightAnimation(final View view) { - - Animation inFromRight = new TranslateAnimation( - Animation.RELATIVE_TO_PARENT, +1.0f, - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, 0.0f); - inFromRight.setDuration(500); - inFromRight.setInterpolator(new AccelerateInterpolator()); - - inFromRight.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - view.setVisibility(View.VISIBLE); - } - - @Override - public void onAnimationEnd(Animation animation) { - - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - - view.startAnimation(inFromRight); - } - - public static void outToLeftAnimation(final View view) { - Animation outtoLeft = new TranslateAnimation( - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, -1.0f, - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, 0.0f); - outtoLeft.setDuration(500); - outtoLeft.setInterpolator(new AccelerateInterpolator()); - - outtoLeft.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - view.setVisibility(View.GONE); - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - - view.startAnimation(outtoLeft); - } - - public static void inFromLeftAnimation(final View view) { - Animation inFromLeft = new TranslateAnimation( - Animation.RELATIVE_TO_PARENT, -1.0f, - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, 0.0f); - inFromLeft.setDuration(500); - inFromLeft.setInterpolator(new AccelerateInterpolator()); - - inFromLeft.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - view.setVisibility(View.VISIBLE); - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - - view.startAnimation(inFromLeft); - } - - public static void outToRightAnimation(final View view) { - Animation outtoRight = new TranslateAnimation( - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, +1.0f, - Animation.RELATIVE_TO_PARENT, 0.0f, - Animation.RELATIVE_TO_PARENT, 0.0f); - outtoRight.setDuration(500); - outtoRight.setInterpolator(new AccelerateInterpolator()); - - - outtoRight.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - view.setVisibility(View.GONE); - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - - view.startAnimation(outtoRight); - } - -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/AnimationUtil.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/AnimationUtil.kt new file mode 100644 index 000000000..332cf1b13 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/AnimationUtil.kt @@ -0,0 +1,141 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.view.View +import android.view.animation.AccelerateInterpolator +import android.view.animation.Animation +import android.view.animation.Animation.AnimationListener +import android.view.animation.Transformation +import android.view.animation.TranslateAnimation +import android.widget.LinearLayout + +/** + * Created by ankur on 27/June/2018 + */ +object AnimationUtil { + fun expand(v: View) { + v.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) + val targetHeight = v.measuredHeight + + // Older versions of android (pre API 21) cancel animations for views with a height of 0. + v.layoutParams.height = 1 + v.visibility = View.VISIBLE + val a: Animation = object : Animation() { + override fun applyTransformation(interpolatedTime: Float, t: Transformation) { + v.layoutParams.height = + if (interpolatedTime == 1f) LinearLayout.LayoutParams.WRAP_CONTENT else (targetHeight * interpolatedTime).toInt() + v.requestLayout() + } + + override fun willChangeBounds(): Boolean { + return true + } + } + + // 1dp/ms + a.duration = (targetHeight / v.context.resources.displayMetrics.density).toInt().toLong() + v.startAnimation(a) + } + + fun collapse(v: View) { + val initialHeight = v.measuredHeight + val a: Animation = object : Animation() { + override fun applyTransformation(interpolatedTime: Float, t: Transformation) { + if (interpolatedTime == 1f) { + v.visibility = View.GONE + } else { + v.layoutParams.height = + initialHeight - (initialHeight * interpolatedTime).toInt() + v.requestLayout() + } + } + + override fun willChangeBounds(): Boolean { + return true + } + } + + // 1dp/ms + a.duration = (initialHeight / v.context.resources.displayMetrics.density).toInt().toLong() + v.startAnimation(a) + } + + fun inFromRightAnimation(view: View) { + val inFromRight: Animation = TranslateAnimation( + Animation.RELATIVE_TO_PARENT, +1.0f, + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, 0.0f + ) + inFromRight.duration = 500 + inFromRight.interpolator = AccelerateInterpolator() + inFromRight.setAnimationListener(object : AnimationListener { + override fun onAnimationStart(animation: Animation) { + view.visibility = View.VISIBLE + } + + override fun onAnimationEnd(animation: Animation) {} + override fun onAnimationRepeat(animation: Animation) {} + }) + view.startAnimation(inFromRight) + } + + fun outToLeftAnimation(view: View) { + val outtoLeft: Animation = TranslateAnimation( + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, -1.0f, + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, 0.0f + ) + outtoLeft.duration = 500 + outtoLeft.interpolator = AccelerateInterpolator() + outtoLeft.setAnimationListener(object : AnimationListener { + override fun onAnimationStart(animation: Animation) {} + override fun onAnimationEnd(animation: Animation) { + view.visibility = View.GONE + } + + override fun onAnimationRepeat(animation: Animation) {} + }) + view.startAnimation(outtoLeft) + } + + fun inFromLeftAnimation(view: View) { + val inFromLeft: Animation = TranslateAnimation( + Animation.RELATIVE_TO_PARENT, -1.0f, + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, 0.0f + ) + inFromLeft.duration = 500 + inFromLeft.interpolator = AccelerateInterpolator() + inFromLeft.setAnimationListener(object : AnimationListener { + override fun onAnimationStart(animation: Animation) {} + override fun onAnimationEnd(animation: Animation) { + view.visibility = View.VISIBLE + } + + override fun onAnimationRepeat(animation: Animation) {} + }) + view.startAnimation(inFromLeft) + } + + fun outToRightAnimation(view: View) { + val outtoRight: Animation = TranslateAnimation( + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, +1.0f, + Animation.RELATIVE_TO_PARENT, 0.0f, + Animation.RELATIVE_TO_PARENT, 0.0f + ) + outtoRight.duration = 500 + outtoRight.interpolator = AccelerateInterpolator() + outtoRight.setAnimationListener(object : AnimationListener { + override fun onAnimationStart(animation: Animation) {} + override fun onAnimationEnd(animation: Animation) { + view.visibility = View.GONE + } + + override fun onAnimationRepeat(animation: Animation) {} + }) + view.startAnimation(outtoRight) + } +} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Constants.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Constants.java deleted file mode 100644 index 92fcd589b..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Constants.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import org.mifos.mobilewallet.mifospay.R; - -/** - * Created by naman on 17/6/17. - */ - -public class Constants { - - public static final String BASIC = "Basic "; - - public static final String CLIENT_ID = "client_id"; - public static final String ACCOUNT_ID = "account_id"; - public static final String ACCOUNT = "account"; - public static final String TO_EXTERNAL_ID = "to_external_id"; - public static final String RUPEE = "₹"; - public static final String QR_DATA = "qr_data"; - public static final String MERCHANT_NAME = "merchant_name"; - public static final String MERCHANT_VPA = "merchant_vpa"; - public static final String MERCHANT_ACCOUNT_NO = "merchant_account_no"; - - public static final String FILE = "file"; - public static final String MULTIPART_FORM_DATA = "multipart/form-data"; - public static final String CHOOSE_A_FILE_TO_UPLOAD = "Choose a file to upload."; - public static final String ERROR_UPLOADING_DOCS = "Error uploading docs."; - public static final String KYC_LEVEL_2_DOCUMENTS_ADDED_SUCCESSFULLY = - "KYC Level 2 documents added successfully."; - public static final String IMAGE = "image/*"; - public static final String APPLICATION_PDF = "application/pdf"; - public static final String ERROR_ADDING_KYC_LEVEL_1_DETAILS = - "Error adding KYC Level 1 details."; - public static final String KYC_LEVEL_1_DETAILS_ADDED_SUCCESSFULLY = - "KYC Level 1 details added successfully."; - public static final String PLEASE_WAIT = "Please wait.."; - public static final String COMPLETE_KYC = "Complete KYC"; - public static final String NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_DOCUMENTS = - "Need external storage permission to browse documents."; - public static final String CHOOSE_FILE = "Choose File"; - public static final String KYC_REGISTRATION_LEVEL_2 = "KYC Registration Level 2"; - public static final String KYC_REGISTRATION_LEVEL_1 = "KYC Registration Level 1"; - public static final String DD_MM_YY = "dd/MM/yy"; - public static final String ERROR_DELETING_CARD = "Error deleting card."; - public static final String CARD_DELETED_SUCCESSFULLY = "Card deleted successfully."; - public static final String DELETING_CARD = "Deleting Card.."; - public static final String ERROR_UPDATING_CARD = "Error updating card."; - public static final String CARD_UPDATED_SUCCESSFULLY = "Card updated successfully."; - public static final String INVALID_CREDIT_CARD_NUMBER = "Invalid Credit Card Number"; - public static final String UPDATING_CARD = "Updating Card.."; - public static final String ERROR_ADDING_CARD = "Error adding card."; - public static final String CARD_ADDED_SUCCESSFULLY = "Card added successfully."; - public static final String ADDING_CARD = "Adding Card.."; - - public static final String ADD_CARD_DIALOG = "Add Card Dialog"; - public static final String EDIT_CARD_DIALOG = "Edit Card Dialog"; - public static final String SAVED_CARDS = "Saved Cards"; - public static final String UPDATE = "Update"; - public static final String KYC_REGISTRATION_LEVEL_3 = "KYC Registration Level 3"; - public static final String OK = "OK"; - public static final String SCAN_CODE = "Scan code"; - public static final String QR_CODE = "QR code"; - public static final String FAILED_TO_WRITE_DATA_TO_QR = "Failed to write data to qr"; - public static final String ERROR_OCCURRED = "Error occurred"; - public static final String LOGGING_IN = "Logging in.."; - public static final String HOME = "Home"; - public static final String PROFILE = "Profile"; - public static final String ERROR_FETCHING_BALANCE = "Error fetching balance"; - public static final String UNABLE_TO_PROCESS_TRANSFER = "Unable to process transfer"; - public static final String TRANSACTION_SUCCESSFUL = "Transaction successful"; - public static final String SENDING_MONEY = "Sending money..."; - public static final String INSUFFICIENT_BALANCE = "Insufficient balance"; - public static final String ERROR_FINDING_VPA = "Error finding Virtual Payment Address"; - public static final String ERROR_FINDING_MOBILE_NUMBER = "Error finding Mobile Number"; - public static final String PLEASE_ENTER_VALID_AMOUNT = "Please enter a valid amount"; - public static final String VPA_VALIDATION_REGEX = "^\\w.+@\\w+$"; - public static final String SELF_ACCOUNT_ERROR = "Self Account transfer is not allowed"; - public static final String PLEASE_ENTER_AMOUNT = - "Please enter a valid amount before making the transfer"; - public static final String NEED_READ_CONTACTS_PERMISSION = "Need read contacts permission"; - public static final String NEED_CAMERA_PERMISSION_TO_SCAN_QR_CODE = - "Need camera permission to scan qr code."; - public static final String ERROR_CHOOSING_CONTACT = "Error choosing contact"; - public static final String MAKE_TRANSFER_FRAGMENT = "Make Transfer Fragment"; - public static final String PLEASE_ENTER_ALL_THE_FIELDS = "Please enter all the fields"; - public static final String TRANSFER = "Transfer"; - public static final String TRANSACTION_DETAILS = "Transaction Details"; - public static final String ACCOUNT_NUMBER = "Account Number : "; - public static final String TRANSACTION = "transaction"; - public static final String TRANSACTIONS_HISTORY = "Transactions History History"; - public static final String SPECIFIC_TRANSACTIONS = "Specific Transactions History"; - public static final String HISTORY_NOT_AVAILABLE = "No Transaction History Available"; - public static final String RECEIPT_DOMAIN = "https://receipt.mifospay.com/"; - public static final String OTHER = "Other"; - public static final String CREDIT = "Credit"; - public static final String DEBIT = "Debit"; - public static final String RECEIPT_ID = "Receipt ID"; - public static final String DATE = "Date"; - public static final String TRANSACTION_ID = "Transaction ID"; - public static final String TRANSACTIONS = "transactions"; - public static final String ERROR_FETCHING_TRANSACTIONS = "Error fetching transactions"; - public static final String TRANSFER_DETAILS = "transfer details"; - public static final String UNIQUE_PAYMENT_LINK_COPIED_TO_CLIPBOARD = - "Unique Payment Link copied to clipboard"; - public static final String UNIQUE_PAYMENT_LINK = "Unique Payment Link"; - public static final String STATUS = "Status"; - public static final String UNIQUE_RECEIPT_LINK_COPIED_TO_CLIPBOARD = - "Unique Receipt Link copied to clipboard"; - public static final String UNIQUE_RECEIPT_LINK = "Unique Receipt Link"; - public static final String DONE = "Done"; - public static final String PENDING = "Pending"; - public static final String ITEMS = "Item(s)"; - public static final String AMOUNT = "Amount"; - public static final String INR = "INR"; - public static final String CONSUMER = "Consumer"; - public static final String MERCHANT = "Merchant"; - public static final String INVOICE = "Invoice"; - public static final String NEED_EXTERNAL_STORAGE_PERMISSION_TO_DOWNLOAD_RECEIPT = - "Need external storage permission to download receipt"; - public static final String RECEIPT_DOWNLOADED_SUCCESSFULLY = "Receipt Downloaded Successfully"; - public static final String ERROR_DOWNLOADING_RECEIPT = "Error downloading receipt"; - public static final String MIFOSPAY = "mifospay"; - public static final String RECEIPT = "Receipt"; - public static final String PDF = ".pdf"; - public static final String ERROR_FETCHING_RECEIPT = "Error fetching receipt"; - public static final String INVOICE_DOMAIN = "https://invoice.mifospay.com/"; - - public static final String SENDING_OTP_TO_YOUR_MOBILE_NUMBER = - "Sending OTP to your mobile number.."; - public static final String MOBILE_NUMBER = "Mobile Number"; - public static final String COUNTRY = "Country"; - public static final String GOOGLE_SIGN_IN_FAILED = "Google Sign in failed."; - public static final String GOOGLE_GIVEN_NAME = "GOOGLE_GIVEN_NAME"; - public static final String GOOGLE_FAMILY_NAME = "GOOGLE_FAMILY_NAME"; - public static final String GOOGLE_EMAIL = "GOOGLE_EMAIL"; - public static final String GOOGLE_DISPLAY_NAME = "GOOGLE_DISPLAY_NAME"; - public static final String GOOGLE_PHOTO_URI = "GOOGLE_PHOTO_URI"; - public static final String CHOOSE_SIGNUP_METHOD = "Choose Signup Method"; - public static final String LOGGING_OUT = "Logging out..."; - public static final String NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_IMAGES = - "Need external storage permission to browse images"; - public static final String SETTINGS = "Settings"; - public static final String EDIT_PROFILE = "Edit Profile"; - public static final String FAQ = "Frequent Asked Questions"; - public static final String LINKED_BANK_ACCOUNTS = "Linked Bank Accounts"; - public static final String BANK_ACCOUNT_DETAILS = "Bank Account Details"; - public static final String NEW_BANK_ACCOUNT = "newBankAccount"; - public static final String VERIFYING_MOBILE_NUMBER = "Verifying mobile number.."; - public static final String MIFOS_SAVINGS_PRODUCT_ID = "Mifos Savings Product Id"; - public static final String MERCHANTS = "Merchants"; - public static final String UPI_PIN = "UPI PIN"; - public static final String STEP = "step"; - public static final String TYPE = "Type"; - public static final String SETUP = "Setup"; - public static final String BANK_DELETED_SUCCESSFULLY = "Bank deleted successfully"; - public static final String ERROR_OCCURRED_WHILE_CHANGING_UPI_PIN = - "Error occurred while changing UPI PIN"; - public static final String SETUP_UPI = "Setup UPI"; - public static final String ERROR_WHILE_SETTING_UP_UPI_PIN = "Error while setting up UPI PIN"; - public static final String UPI_PIN_SETUP_COMPLETED_SUCCESSFULLY = - "UPI PIN Setup Completed Successfully"; - public static final String FORGOT = "Forgot"; - public static final String CHANGE = "Change"; - public static final String OTP = "otp"; - public static final String SETUP_UPI_PIN = "Setup UPI PIN"; - public static final String SETTING_UP_UPI_PIN = "Setting up UPI PIN.."; - public static final String UPDATED_BANK_ACCOUNT = "Updated Bank Account"; - public static final String INDEX = "Index"; - public static final String CHANGE_UPI_PIN = "Change UPI PIN"; - public static final String FORGOT_UPI_PIN = "Forgot UPI PIN"; - - // broadcast receiver intent filters - public static final String REGISTRATION_COMPLETE = "registrationComplete"; - public static final String PUSH_NOTIFICATION = "pushNotification"; - - // id to handle the notification in the notification tray - public static final int NOTIFICATION_ID = 100; - public static final int NOTIFICATION_ID_BIG_IMAGE = 101; - - public static final int HOME_HISTORY_TRANSACTIONS_LIMIT = 5; - - public static final String ERROR_FIELDS_CANNOT_BE_EMPTY = "Fields cannot be empty"; - public static final String ERROR_VALIDATING_PASSWORD = "Passwords are not the same"; - public static final String ERROR_PASSWORDS_CANT_BE_SAME = - "New password can't be the same as old password."; - - public static final String CHANGE_PROFILE_IMAGE_KEY = "CHANGE_PROFILE_IMAGE_KEY"; - public static final String CHANGE_PROFILE_IMAGE_VALUE = "CHANGE_PROFILE_IMAGE_VALUE"; - public static final String TAP_TO_REVEAL = "Tap to Reveal"; - public static final String NAME = "Name : "; - public static final String ERROR_FETCHING_TRANSACTION_DETAILS = "Error fetching details"; - - public static final int WHITE_BACK_BUTTON = R.drawable.ic_arrow_back_white_24dp; - public static final int BLACK_BACK_BUTTON = R.drawable.ic_arrow_back_black_24dp; - public static final String VIEW = "View"; - - public static final String CURRENT_PASSCODE = "current passcode"; - public static final String UPDATE_PASSCODE = "update passcode"; - public static final String SELECT_DATE = "SELECT DATE"; - public static final String SI_ID = "standing_instruction_id"; - public static final String UNAUTHORIZED_ERROR = "401 Unauthorized"; - public static final String RECEIPT_SHARING_MESSAGE = "Receipt link for the transaction "; - - public static final String TO = " to "; - public static final String COLON = " : "; - -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Constants.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Constants.kt new file mode 100644 index 000000000..fec8a34aa --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Constants.kt @@ -0,0 +1,185 @@ +package org.mifos.mobilewallet.mifospay.utils + +import org.mifos.mobilewallet.mifospay.R + +/** + * Created by naman on 17/6/17. + */ +object Constants { + const val BASIC = "Basic " + const val CLIENT_ID = "client_id" + const val ACCOUNT_ID = "account_id" + const val ACCOUNT = "account" + const val TO_EXTERNAL_ID = "to_external_id" + const val RUPEE = "₹" + const val QR_DATA = "qr_data" + const val MERCHANT_NAME = "merchant_name" + const val MERCHANT_VPA = "merchant_vpa" + const val MERCHANT_ACCOUNT_NO = "merchant_account_no" + const val FILE = "file" + const val MULTIPART_FORM_DATA = "multipart/form-data" + const val CHOOSE_A_FILE_TO_UPLOAD = "Choose a file to upload." + const val ERROR_UPLOADING_DOCS = "Error uploading docs." + const val KYC_LEVEL_2_DOCUMENTS_ADDED_SUCCESSFULLY = "KYC Level 2 documents added successfully." + const val IMAGE = "image/*" + const val APPLICATION_PDF = "application/pdf" + const val ERROR_ADDING_KYC_LEVEL_1_DETAILS = "Error adding KYC Level 1 details." + const val KYC_LEVEL_1_DETAILS_ADDED_SUCCESSFULLY = "KYC Level 1 details added successfully." + const val PLEASE_WAIT = "Please wait.." + const val COMPLETE_KYC = "Complete KYC" + const val NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_DOCUMENTS = + "Need external storage permission to browse documents." + const val CHOOSE_FILE = "Choose File" + const val KYC_REGISTRATION_LEVEL_2 = "KYC Registration Level 2" + const val KYC_REGISTRATION_LEVEL_1 = "KYC Registration Level 1" + const val DD_MM_YY = "dd/MM/yy" + const val ERROR_DELETING_CARD = "Error deleting card." + const val CARD_DELETED_SUCCESSFULLY = "Card deleted successfully." + const val DELETING_CARD = "Deleting Card.." + const val ERROR_UPDATING_CARD = "Error updating card." + const val CARD_UPDATED_SUCCESSFULLY = "Card updated successfully." + const val INVALID_CREDIT_CARD_NUMBER = "Invalid Credit Card Number" + const val UPDATING_CARD = "Updating Card.." + const val ERROR_ADDING_CARD = "Error adding card." + const val CARD_ADDED_SUCCESSFULLY = "Card added successfully." + const val ADDING_CARD = "Adding Card.." + const val ADD_CARD_DIALOG = "Add Card Dialog" + const val EDIT_CARD_DIALOG = "Edit Card Dialog" + const val SAVED_CARDS = "Saved Cards" + const val UPDATE = "Update" + const val KYC_REGISTRATION_LEVEL_3 = "KYC Registration Level 3" + const val OK = "OK" + const val SCAN_CODE = "Scan code" + const val QR_CODE = "QR code" + const val FAILED_TO_WRITE_DATA_TO_QR = "Failed to write data to qr" + const val ERROR_OCCURRED = "Error occurred" + const val LOGGING_IN = "Logging in.." + const val HOME = "Home" + const val PROFILE = "Profile" + const val ERROR_FETCHING_BALANCE = "Error fetching balance" + const val UNABLE_TO_PROCESS_TRANSFER = "Unable to process transfer" + const val TRANSACTION_SUCCESSFUL = "Transaction successful" + const val SENDING_MONEY = "Sending money..." + const val INSUFFICIENT_BALANCE = "Insufficient balance" + const val ERROR_FINDING_VPA = "Error finding Virtual Payment Address" + const val ERROR_FINDING_MOBILE_NUMBER = "Error finding Mobile Number" + const val PLEASE_ENTER_VALID_AMOUNT = "Please enter a valid amount" + const val VPA_VALIDATION_REGEX = "^\\w.+@\\w+$" + const val SELF_ACCOUNT_ERROR = "Self Account transfer is not allowed" + const val PLEASE_ENTER_AMOUNT = "Please enter a valid amount before making the transfer" + const val NEED_READ_CONTACTS_PERMISSION = "Need read contacts permission" + const val NEED_CAMERA_PERMISSION_TO_SCAN_QR_CODE = "Need camera permission to scan qr code." + const val ERROR_CHOOSING_CONTACT = "Error choosing contact" + const val MAKE_TRANSFER_FRAGMENT = "Make Transfer Fragment" + const val PLEASE_ENTER_ALL_THE_FIELDS = "Please enter all the fields" + const val TRANSFER = "Transfer" + const val TRANSACTION_DETAILS = "Transaction Details" + const val ACCOUNT_NUMBER = "Account Number : " + const val TRANSACTION = "transaction" + const val TRANSACTIONS_HISTORY = "Transactions History History" + const val SPECIFIC_TRANSACTIONS = "Specific Transactions History" + const val HISTORY_NOT_AVAILABLE = "No Transaction History Available" + const val RECEIPT_DOMAIN = "https://receipt.mifospay.com/" + const val OTHER = "Other" + const val CREDIT = "Credit" + const val DEBIT = "Debit" + const val RECEIPT_ID = "Receipt ID" + const val DATE = "Date" + const val TRANSACTION_ID = "Transaction ID" + val TRANSACTIONS = "transactions" + val ERROR_FETCHING_TRANSACTIONS = "Error fetching transactions" + val TRANSFER_DETAILS = "transfer details" + val UNIQUE_PAYMENT_LINK_COPIED_TO_CLIPBOARD = "Unique Payment Link copied to clipboard" + val UNIQUE_PAYMENT_LINK = "Unique Payment Link" + val STATUS = "Status" + val UNIQUE_RECEIPT_LINK_COPIED_TO_CLIPBOARD = "Unique Receipt Link copied to clipboard" + val UNIQUE_RECEIPT_LINK = "Unique Receipt Link" + val DONE = "Done" + val PENDING = "Pending" + val ITEMS = "Item(s)" + val AMOUNT = "Amount" + val INR = "INR" + val CONSUMER = "Consumer" + val MERCHANT = "Merchant" + val INVOICE = "Invoice" + val NEED_EXTERNAL_STORAGE_PERMISSION_TO_DOWNLOAD_RECEIPT = + "Need external storage permission to download receipt" + val RECEIPT_DOWNLOADED_SUCCESSFULLY = "Receipt Downloaded Successfully" + val ERROR_DOWNLOADING_RECEIPT = "Error downloading receipt" + @JvmField + val MIFOSPAY = "mifospay" + val RECEIPT = "Receipt" + val PDF = ".pdf" + val ERROR_FETCHING_RECEIPT = "Error fetching receipt" + val INVOICE_DOMAIN = "https://invoice.mifospay.com/" + val SENDING_OTP_TO_YOUR_MOBILE_NUMBER = "Sending OTP to your mobile number.." + val MOBILE_NUMBER = "Mobile Number" + val COUNTRY = "Country" + val GOOGLE_SIGN_IN_FAILED = "Google Sign in failed." + val GOOGLE_GIVEN_NAME = "GOOGLE_GIVEN_NAME" + val GOOGLE_FAMILY_NAME = "GOOGLE_FAMILY_NAME" + val GOOGLE_EMAIL = "GOOGLE_EMAIL" + val GOOGLE_DISPLAY_NAME = "GOOGLE_DISPLAY_NAME" + val GOOGLE_PHOTO_URI = "GOOGLE_PHOTO_URI" + val CHOOSE_SIGNUP_METHOD = "Choose Signup Method" + val LOGGING_OUT = "Logging out..." + val NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_IMAGES = + "Need external storage permission to browse images" + val SETTINGS = "Settings" + val EDIT_PROFILE = "Edit Profile" + val FAQ = "Frequent Asked Questions" + val LINKED_BANK_ACCOUNTS = "Linked Bank Accounts" + val BANK_ACCOUNT_DETAILS = "Bank Account Details" + val NEW_BANK_ACCOUNT = "newBankAccount" + val VERIFYING_MOBILE_NUMBER = "Verifying mobile number.." + val MIFOS_SAVINGS_PRODUCT_ID = "Mifos Savings Product Id" + val MERCHANTS = "Merchants" + val UPI_PIN = "UPI PIN" + val STEP = "step" + val TYPE = "Type" + val SETUP = "Setup" + val BANK_DELETED_SUCCESSFULLY = "Bank deleted successfully" + val ERROR_OCCURRED_WHILE_CHANGING_UPI_PIN = "Error occurred while changing UPI PIN" + val SETUP_UPI = "Setup UPI" + val ERROR_WHILE_SETTING_UP_UPI_PIN = "Error while setting up UPI PIN" + val UPI_PIN_SETUP_COMPLETED_SUCCESSFULLY = "UPI PIN Setup Completed Successfully" + val FORGOT = "Forgot" + val CHANGE = "Change" + val OTP = "otp" + val SETUP_UPI_PIN = "Setup UPI PIN" + val SETTING_UP_UPI_PIN = "Setting up UPI PIN.." + val UPDATED_BANK_ACCOUNT = "Updated Bank Account" + val INDEX = "Index" + val CHANGE_UPI_PIN = "Change UPI PIN" + val FORGOT_UPI_PIN = "Forgot UPI PIN" + + // broadcast receiver intent filters + val REGISTRATION_COMPLETE = "registrationComplete" + val PUSH_NOTIFICATION = "pushNotification" + + // id to handle the notification in the notification tray + @JvmField + val NOTIFICATION_ID = 100 + @JvmField + val NOTIFICATION_ID_BIG_IMAGE = 101 + val HOME_HISTORY_TRANSACTIONS_LIMIT = 5 + val ERROR_FIELDS_CANNOT_BE_EMPTY = "Fields cannot be empty" + val ERROR_VALIDATING_PASSWORD = "Passwords are not the same" + val ERROR_PASSWORDS_CANT_BE_SAME = "New password can't be the same as old password." + val CHANGE_PROFILE_IMAGE_KEY = "CHANGE_PROFILE_IMAGE_KEY" + val CHANGE_PROFILE_IMAGE_VALUE = "CHANGE_PROFILE_IMAGE_VALUE" + val TAP_TO_REVEAL = "Tap to Reveal" + val NAME = "Name : " + val ERROR_FETCHING_TRANSACTION_DETAILS = "Error fetching details" + val WHITE_BACK_BUTTON = R.drawable.ic_arrow_back_white_24dp + val BLACK_BACK_BUTTON = R.drawable.ic_arrow_back_black_24dp + val VIEW = "View" + val CURRENT_PASSCODE = "current passcode" + val UPDATE_PASSCODE = "update passcode" + val SELECT_DATE = "SELECT DATE" + val SI_ID = "standing_instruction_id" + val UNAUTHORIZED_ERROR = "401 Unauthorized" + val RECEIPT_SHARING_MESSAGE = "Receipt link for the transaction " + val TO = " to " + val COLON = " : " +} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DebugUtil.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DebugUtil.java deleted file mode 100644 index 6f9e52b72..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DebugUtil.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.util.Log; - -/** - * Created by ankur on 26/June/2018 - */ - -public class DebugUtil { - - public static Object[] log(Object... objects) { - - String stringToPrint = ""; - for (Object object : objects) { - stringToPrint += object + ", "; - } - stringToPrint = stringToPrint.substring(0, stringToPrint.lastIndexOf(',')); - Log.d("QXZ:: ", stringToPrint); - return objects; - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DebugUtil.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DebugUtil.kt new file mode 100644 index 000000000..408e0413f --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DebugUtil.kt @@ -0,0 +1,19 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.util.Log + +/** + * Created by ankur on 26/June/2018 + */ +object DebugUtil { + @JvmStatic + fun log(vararg objects: Any): Array { + var stringToPrint = "" + for (`object` in objects) { + stringToPrint += "$`object`, " + } + stringToPrint = stringToPrint.substring(0, stringToPrint.lastIndexOf(',')) + Log.d("QXZ:: ", stringToPrint) + return objects + } +} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DialogBox.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DialogBox.java deleted file mode 100644 index d6fbc2896..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DialogBox.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import androidx.appcompat.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; - -import org.mifos.mobilewallet.mifospay.R; - - -public class DialogBox { - - public AlertDialog alertDialog; - public DialogInterface.OnClickListener onPositiveListener; - public DialogInterface.OnClickListener onNegativeListener; - - public void setOnPositiveListener(final DialogInterface.OnClickListener onPositiveListener) { - this.onPositiveListener = onPositiveListener; - } - - public void setOnNegativeListener(final DialogInterface.OnClickListener onNegativeListener) { - this.onNegativeListener = onNegativeListener; - } - - public void show(final Context context, int title, int message, int positive, - int negative) { - AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AppTheme_Dialog); - builder.setTitle(title); - builder.setMessage(message); - builder.setCancelable(true); - - builder.setPositiveButton( - positive, - onPositiveListener); - - builder.setNegativeButton( - negative, - onNegativeListener); - - alertDialog = builder.create(); - alertDialog.show(); - } - - - public void dismiss() { - if (alertDialog != null) - alertDialog.dismiss(); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DialogBox.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DialogBox.kt new file mode 100644 index 000000000..510994206 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/DialogBox.kt @@ -0,0 +1,45 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.content.Context +import android.content.DialogInterface +import androidx.appcompat.app.AlertDialog +import org.mifos.mobilewallet.mifospay.R + +class DialogBox { + var alertDialog: AlertDialog? = null + var onPositiveListener: DialogInterface.OnClickListener? = null + var onNegativeListener: DialogInterface.OnClickListener? = null + fun setPositiveListener(onPositiveListener: DialogInterface.OnClickListener?) { + this.onPositiveListener = onPositiveListener + } + + fun setNegativeListener(onNegativeListener: DialogInterface.OnClickListener?) { + this.onNegativeListener = onNegativeListener + } + + fun show( + context: Context?, title: Int, message: Int, positive: Int, + negative: Int + ) { + val builder = AlertDialog.Builder( + context!!, R.style.AppTheme_Dialog + ) + builder.setTitle(title) + builder.setMessage(message) + builder.setCancelable(true) + builder.setPositiveButton( + positive, + onPositiveListener + ) + builder.setNegativeButton( + negative, + onNegativeListener + ) + alertDialog = builder.create() + alertDialog!!.show() + } + + fun dismiss() { + if (alertDialog != null) alertDialog!!.dismiss() + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/FileUtils.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/FileUtils.java deleted file mode 100644 index cf0040388..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/FileUtils.java +++ /dev/null @@ -1,230 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -/** - * Created by ankur on 24/May/2018 - */ - -import android.content.ContentUris; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.os.Build; -import android.os.Environment; -import android.provider.DocumentsContract; -import android.provider.MediaStore; -import android.util.Log; - -import org.json.JSONObject; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -public class FileUtils { - - private static final String TAG = "FileUtils"; - - public static JSONObject readJson(Context context, String file) { - JSONObject jsonObject = null; - try { - InputStream is = context.getAssets().open(file); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - jsonObject = new JSONObject(new String(buffer, "UTF-8")); - } catch (Exception e) { - DebugUtil.log(e.toString(), e.getMessage()); - } - return jsonObject; - } - - /** - * Method for return file path of Gallery image/ Document / Video / Audio - * - * @return path of the selected image file from gallery - */ - public static String getPath(final Context context, final Uri uri) { - // DocumentProvider - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - if (DocumentsContract.isDocumentUri(context, uri)) { - - // ExternalStorageProvider - if (isExternalStorageDocument(uri)) { - final String docId = DocumentsContract.getDocumentId(uri); - final String[] split = docId.split(":"); - final String type = split[0]; - - if ("primary".equalsIgnoreCase(type)) { - return Environment.getExternalStorageDirectory() + "/" - + split[1]; - } - } else if (isDownloadsDocument(uri)) { // DownloadsProvider - - final String id = DocumentsContract.getDocumentId(uri); - final Uri contentUri = ContentUris.withAppendedId( - Uri.parse("content://downloads/public_downloads"), - Long.parseLong(id)); - - return getDataColumn(context, contentUri, null, null); - } else if (isMediaDocument(uri)) { // MediaProvider - final String docId = DocumentsContract.getDocumentId(uri); - final String[] split = docId.split(":"); - final String type = split[0]; - - Uri contentUri = null; - if ("image".equals(type)) { - contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; - } else if ("video".equals(type)) { - contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; - } else if ("audio".equals(type)) { - contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; - } - - final String selection = "_id=?"; - final String[] selectionArgs = new String[]{split[1]}; - - return getDataColumn(context, contentUri, selection, - selectionArgs); - } - } else if ("content".equalsIgnoreCase(uri.getScheme())) { // MediaStore (and general) - - // Return the remote address - if (isGooglePhotosUri(uri)) { - return uri.getLastPathSegment(); - } - - return getDataColumn(context, uri, null, null); - } else if ("file".equalsIgnoreCase(uri.getScheme())) { // File - return uri.getPath(); - } - } - - return null; - } - - /** - * Get the value of the data column for this Uri. This is useful for - * MediaStore Uris, and other file-based ContentProviders. - * - * @param context The context. - * @param uri The Uri to query. - * @param selection (Optional) Filter used in the query. - * @param selectionArgs (Optional) Selection arguments used in the query. - * @return The value of the _data column, which is typically a file path. - */ - public static String getDataColumn(Context context, Uri uri, - String selection, String[] selectionArgs) { - - Cursor cursor = null; - final String column = "_data"; - final String[] projection = {column}; - - try { - cursor = context.getContentResolver().query(uri, projection, - selection, selectionArgs, null); - if (cursor != null && cursor.moveToFirst()) { - final int index = cursor.getColumnIndexOrThrow(column); - return cursor.getString(index); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return null; - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is ExternalStorageProvider. - */ - public static boolean isExternalStorageDocument(Uri uri) { - return "com.android.externalstorage.documents".equals(uri - .getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is DownloadsProvider. - */ - public static boolean isDownloadsDocument(Uri uri) { - return "com.android.providers.downloads.documents".equals(uri - .getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is MediaProvider. - */ - public static boolean isMediaDocument(Uri uri) { - return "com.android.providers.media.documents".equals(uri - .getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is Google Photos. - */ - public static boolean isGooglePhotosUri(Uri uri) { - return "com.google.android.apps.photos.content".equals(uri - .getAuthority()); - } - - public static boolean writeInputStreamDataToFile(InputStream in, File file) { - try { - OutputStream out = new FileOutputStream(file); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.close(); - in.close(); - return true; - } catch (Exception e) { - return false; - } - } - - public static File saveImage(final Context context, final String imageData) { - final byte[] imgBytesData = android.util.Base64.decode(imageData, - android.util.Base64.DEFAULT); - - File file = null; - try { - File mifosDirectory = new File(Environment.getExternalStorageDirectory(), - Constants.MIFOSPAY); - file = new File(mifosDirectory, "kuch"); - } catch (Exception e) { - Log.e(TAG, "Unable to create file", e); - } - final FileOutputStream fileOutputStream; - try { - fileOutputStream = new FileOutputStream(file); - } catch (FileNotFoundException e) { - Log.e(TAG, "Unable to create output stream", e); - return null; - } - - final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( - fileOutputStream); - try { - bufferedOutputStream.write(imgBytesData); - } catch (IOException e) { - Log.e(TAG, "Unable to write", e); - return null; - } finally { - try { - bufferedOutputStream.close(); - } catch (IOException e) { - Log.e(TAG, "Unable to close the output stream", e); - } - } - return file; - } -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/FileUtils.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/FileUtils.kt new file mode 100644 index 000000000..7d880f5a6 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/FileUtils.kt @@ -0,0 +1,234 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.content.ContentUris +import android.content.Context +import android.database.Cursor +import android.net.Uri +import android.os.Build +import android.os.Environment +import android.provider.DocumentsContract +import android.provider.MediaStore +import android.util.Base64 +import android.util.Log +import org.json.JSONObject +import org.mifos.mobilewallet.mifospay.utils.DebugUtil.log +import java.io.BufferedOutputStream +import java.io.File +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream + +/** + * Created by ankur on 24/May/2018 + */ +object FileUtils { + private const val TAG = "FileUtils" + fun readJson(context: Context, file: String?): JSONObject? { + var jsonObject: JSONObject? = null + try { + val `is` = context.assets.open(file!!) + val size = `is`.available() + val buffer = ByteArray(size) + `is`.read(buffer) + `is`.close() + jsonObject = JSONObject(String(buffer, charset("UTF-8"))) + } catch (e: Exception) { + log(e.toString(), e.message!!) + } + return jsonObject + } + + /** + * Method for return file path of Gallery image/ Document / Video / Audio + * + * @return path of the selected image file from gallery + */ + fun getPath(context: Context, uri: Uri): String? { + // DocumentProvider + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (DocumentsContract.isDocumentUri(context, uri)) { + + // ExternalStorageProvider + if (isExternalStorageDocument(uri)) { + val docId = DocumentsContract.getDocumentId(uri) + val split = + docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + val type = split[0] + if ("primary".equals(type, ignoreCase = true)) { + return (Environment.getExternalStorageDirectory().toString() + "/" + + split[1]) + } + } else if (isDownloadsDocument(uri)) { // DownloadsProvider + val id = DocumentsContract.getDocumentId(uri) + val contentUri = ContentUris.withAppendedId( + Uri.parse("content://downloads/public_downloads"), id.toLong() + ) + return getDataColumn(context, contentUri, null, null) + } else if (isMediaDocument(uri)) { // MediaProvider + val docId = DocumentsContract.getDocumentId(uri) + val split = + docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + val type = split[0] + var contentUri: Uri? = null + if ("image" == type) { + contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI + } else if ("video" == type) { + contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI + } else if ("audio" == type) { + contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + } + val selection = "_id=?" + val selectionArgs = arrayOf(split[1]) + return getDataColumn( + context, contentUri, selection, + selectionArgs + ) + } + } else if ("content".equals( + uri.scheme, + ignoreCase = true + ) + ) { // MediaStore (and general) + + // Return the remote address + return if (isGooglePhotosUri(uri)) { + uri.lastPathSegment + } else getDataColumn( + context, + uri, + null, + null + ) + } else if ("file".equals(uri.scheme, ignoreCase = true)) { // File + return uri.path + } + } + return null + } + + /** + * Get the value of the data column for this Uri. This is useful for + * MediaStore Uris, and other file-based ContentProviders. + * + * @param context The context. + * @param uri The Uri to query. + * @param selection (Optional) Filter used in the query. + * @param selectionArgs (Optional) Selection arguments used in the query. + * @return The value of the _data column, which is typically a file path. + */ + fun getDataColumn( + context: Context, uri: Uri?, + selection: String?, selectionArgs: Array? + ): String? { + var cursor: Cursor? = null + val column = "_data" + val projection = arrayOf(column) + try { + cursor = context.contentResolver.query( + uri!!, projection, + selection, selectionArgs, null + ) + if (cursor != null && cursor.moveToFirst()) { + val index = cursor.getColumnIndexOrThrow(column) + return cursor.getString(index) + } + } finally { + cursor?.close() + } + return null + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is ExternalStorageProvider. + */ + fun isExternalStorageDocument(uri: Uri): Boolean { + return "com.android.externalstorage.documents" == uri + .authority + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is DownloadsProvider. + */ + fun isDownloadsDocument(uri: Uri): Boolean { + return "com.android.providers.downloads.documents" == uri + .authority + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is MediaProvider. + */ + fun isMediaDocument(uri: Uri): Boolean { + return "com.android.providers.media.documents" == uri + .authority + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is Google Photos. + */ + fun isGooglePhotosUri(uri: Uri): Boolean { + return "com.google.android.apps.photos.content" == uri + .authority + } + + fun writeInputStreamDataToFile(`in`: InputStream, file: File?): Boolean { + return try { + val out: OutputStream = FileOutputStream(file) + val buf = ByteArray(1024) + var len: Int + while (`in`.read(buf).also { len = it } > 0) { + out.write(buf, 0, len) + } + out.close() + `in`.close() + true + } catch (e: Exception) { + false + } + } + + fun saveImage(context: Context?, imageData: String?): File? { + val imgBytesData = Base64.decode( + imageData, + Base64.DEFAULT + ) + var file: File? = null + try { + val mifosDirectory = File( + Environment.getExternalStorageDirectory(), + Constants.MIFOSPAY + ) + file = File(mifosDirectory, "kuch") + } catch (e: Exception) { + Log.e(TAG, "Unable to create file", e) + } + val fileOutputStream: FileOutputStream + fileOutputStream = try { + FileOutputStream(file) + } catch (e: FileNotFoundException) { + Log.e(TAG, "Unable to create output stream", e) + return null + } + val bufferedOutputStream = BufferedOutputStream( + fileOutputStream + ) + try { + bufferedOutputStream.write(imgBytesData) + } catch (e: IOException) { + Log.e(TAG, "Unable to write", e) + return null + } finally { + try { + bufferedOutputStream.close() + } catch (e: IOException) { + Log.e(TAG, "Unable to close the output stream", e) + } + } + return file + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/NotificationUtils.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/NotificationUtils.java deleted file mode 100644 index 1257cee2e..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/NotificationUtils.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.app.ActivityManager; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.Ringtone; -import android.media.RingtoneManager; -import android.net.Uri; -import android.os.Build; -import androidx.core.app.NotificationCompat; -import android.text.Html; -import android.text.TextUtils; -import android.util.Log; -import android.util.Patterns; - -import org.mifos.mobilewallet.mifospay.R; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - -/** - * Created by ankur on 23/July/2018 - */ - -public class NotificationUtils { - - private static final String TAG = NotificationUtils.class.getSimpleName(); - - private Context mContext; - - public NotificationUtils(Context mContext) { - this.mContext = mContext; - } - - /** - * Method checks if the app is in background or not - */ - public static boolean isAppIsInBackground(Context context) { - boolean isInBackground = true; - ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { - List runningProcesses = - am.getRunningAppProcesses(); - for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { - if (processInfo.importance - == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { - for (String activeProcess : processInfo.pkgList) { - if (activeProcess.equals(context.getPackageName())) { - isInBackground = false; - } - } - } - } - } else { - List taskInfo = am.getRunningTasks(1); - ComponentName componentInfo = taskInfo.get(0).topActivity; - if (componentInfo.getPackageName().equals(context.getPackageName())) { - isInBackground = false; - } - } - - return isInBackground; - } - - // Clears notification tray messages - public static void clearNotifications(Context context) { - NotificationManager notificationManager = (NotificationManager) context.getSystemService( - Context.NOTIFICATION_SERVICE); - notificationManager.cancelAll(); - } - - public static long getTimeMilliSec(String timeStamp) { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - Date date = format.parse(timeStamp); - return date.getTime(); - } catch (ParseException e) { - Log.e(TAG, "Unable to parse the timestamp", e); - } - return 0; - } - - public void showNotificationMessage(String title, String message, String timeStamp, - Intent intent) { - showNotificationMessage(title, message, timeStamp, intent, null); - } - - public void showNotificationMessage(final String title, final String message, - final String timeStamp, Intent intent, String imageUrl) { - // Check for empty push message - if (TextUtils.isEmpty(message)) { - return; - } - - // notification icon - final int icon = R.drawable.ic_bank; - - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); - final PendingIntent resultPendingIntent = - PendingIntent.getActivity( - mContext, - 0, - intent, - PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE - ); - - final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( - mContext); - -// final Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE -// + "://" + mContext.getPackageName() + "/raw/notification"); - Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - - if (!TextUtils.isEmpty(imageUrl)) { - - if (imageUrl != null && imageUrl.length() > 4 && Patterns.WEB_URL.matcher( - imageUrl).matches()) { - - Bitmap bitmap = getBitmapFromURL(imageUrl); - - if (bitmap != null) { - showBigNotification(bitmap, mBuilder, icon, title, message, timeStamp, - resultPendingIntent, alarmSound); - } else { - showSmallNotification(mBuilder, icon, title, message, timeStamp, - resultPendingIntent, alarmSound); - } - } - } else { - showSmallNotification(mBuilder, icon, title, message, timeStamp, resultPendingIntent, - alarmSound); - playNotificationSound(); - } - } - - private void showSmallNotification(NotificationCompat.Builder mBuilder, int icon, String title, - String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) { - - NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); - - inboxStyle.addLine(message); - - Notification notification; - notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0) - .setAutoCancel(true) - .setContentTitle(title) - .setContentIntent(resultPendingIntent) - .setSound(alarmSound) - .setStyle(inboxStyle) - .setWhen(getTimeMilliSec(timeStamp)) - .setSmallIcon(R.mipmap.ic_launcher) - .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon)) - .setContentText(message) - .build(); - - NotificationManager notificationManager = (NotificationManager) mContext.getSystemService( - Context.NOTIFICATION_SERVICE); - notificationManager.notify(Constants.NOTIFICATION_ID, notification); - } - - private void showBigNotification(Bitmap bitmap, NotificationCompat.Builder mBuilder, int icon, - String title, String message, String timeStamp, PendingIntent resultPendingIntent, - Uri alarmSound) { - NotificationCompat.BigPictureStyle bigPictureStyle = - new NotificationCompat.BigPictureStyle(); - bigPictureStyle.setBigContentTitle(title); - bigPictureStyle.setSummaryText(Html.fromHtml(message).toString()); - bigPictureStyle.bigPicture(bitmap); - Notification notification; - notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0) - .setAutoCancel(true) - .setContentTitle(title) - .setContentIntent(resultPendingIntent) - .setSound(alarmSound) - .setStyle(bigPictureStyle) - .setWhen(getTimeMilliSec(timeStamp)) - .setSmallIcon(R.mipmap.ic_launcher) - .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon)) - .setContentText(message) - .build(); - - NotificationManager notificationManager = (NotificationManager) mContext.getSystemService( - Context.NOTIFICATION_SERVICE); - notificationManager.notify(Constants.NOTIFICATION_ID_BIG_IMAGE, notification); - } - - /** - * Downloading push notification image before displaying it in - * the notification tray - */ - public Bitmap getBitmapFromURL(String strURL) { - try { - URL url = new URL(strURL); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - return BitmapFactory.decodeStream(input); - } catch (IOException e) { - Log.e(TAG, "Unable to create bitmap", e); - return null; - } - } - - // Playing notification sound - public void playNotificationSound() { - try { -// Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE -// + "://" + mContext.getPackageName() + "/raw/notification"); - Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - Ringtone r = RingtoneManager.getRingtone(mContext, defaultSoundUri); - r.play(); - } catch (Exception e) { - Log.d(TAG, "playNotificationSound: " + e.getMessage()); - } - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/NotificationUtils.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/NotificationUtils.kt new file mode 100644 index 000000000..cd0d33842 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/NotificationUtils.kt @@ -0,0 +1,217 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.app.ActivityManager +import android.app.ActivityManager.RunningAppProcessInfo +import android.app.Notification +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.Context +import android.content.Intent +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.media.RingtoneManager +import android.net.Uri +import android.os.Build +import android.text.Html +import android.text.TextUtils +import android.util.Log +import android.util.Patterns +import androidx.core.app.NotificationCompat +import org.mifos.mobilewallet.mifospay.R +import java.io.IOException +import java.net.HttpURLConnection +import java.net.URL +import java.text.ParseException +import java.text.SimpleDateFormat + +/** + * Created by ankur on 23/July/2018 + */ +class NotificationUtils(private val mContext: Context) { + @JvmOverloads + fun showNotificationMessage( + title: String, message: String?, + timeStamp: String, intent: Intent, imageUrl: String? = null + ) { + // Check for empty push message + if (TextUtils.isEmpty(message)) { + return + } + + // notification icon + val icon = R.drawable.ic_bank + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) + val resultPendingIntent = PendingIntent.getActivity( + mContext, + 0, + intent, + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + ) + val mBuilder = NotificationCompat.Builder( + mContext + ) + +// final Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +// + "://" + mContext.getPackageName() + "/raw/notification"); + val alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + if (!TextUtils.isEmpty(imageUrl)) { + if (imageUrl != null && imageUrl.length > 4 && Patterns.WEB_URL.matcher( + imageUrl + ).matches() + ) { + val bitmap = getBitmapFromURL(imageUrl) + if (bitmap != null) { + showBigNotification( + bitmap, mBuilder, icon, title, message, timeStamp, + resultPendingIntent, alarmSound + ) + } else { + showSmallNotification( + mBuilder, icon, title, message, timeStamp, + resultPendingIntent, alarmSound + ) + } + } + } else { + showSmallNotification( + mBuilder, icon, title, message, timeStamp, resultPendingIntent, + alarmSound + ) + playNotificationSound() + } + } + + private fun showSmallNotification( + mBuilder: NotificationCompat.Builder, icon: Int, title: String, + message: String?, timeStamp: String, resultPendingIntent: PendingIntent, alarmSound: Uri + ) { + val inboxStyle = NotificationCompat.InboxStyle() + inboxStyle.addLine(message) + val notification: Notification + notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0) + .setAutoCancel(true) + .setContentTitle(title) + .setContentIntent(resultPendingIntent) + .setSound(alarmSound) + .setStyle(inboxStyle) + .setWhen(getTimeMilliSec(timeStamp)) + .setSmallIcon(R.mipmap.ic_launcher) + .setLargeIcon(BitmapFactory.decodeResource(mContext.resources, icon)) + .setContentText(message) + .build() + val notificationManager = mContext.getSystemService( + Context.NOTIFICATION_SERVICE + ) as NotificationManager + notificationManager.notify(Constants.NOTIFICATION_ID, notification) + } + + private fun showBigNotification( + bitmap: Bitmap, mBuilder: NotificationCompat.Builder, icon: Int, + title: String, message: String?, timeStamp: String, resultPendingIntent: PendingIntent, + alarmSound: Uri + ) { + val bigPictureStyle = NotificationCompat.BigPictureStyle() + bigPictureStyle.setBigContentTitle(title) + bigPictureStyle.setSummaryText(Html.fromHtml(message).toString()) + bigPictureStyle.bigPicture(bitmap) + val notification: Notification + notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0) + .setAutoCancel(true) + .setContentTitle(title) + .setContentIntent(resultPendingIntent) + .setSound(alarmSound) + .setStyle(bigPictureStyle) + .setWhen(getTimeMilliSec(timeStamp)) + .setSmallIcon(R.mipmap.ic_launcher) + .setLargeIcon(BitmapFactory.decodeResource(mContext.resources, icon)) + .setContentText(message) + .build() + val notificationManager = mContext.getSystemService( + Context.NOTIFICATION_SERVICE + ) as NotificationManager + notificationManager.notify(Constants.NOTIFICATION_ID_BIG_IMAGE, notification) + } + + /** + * Downloading push notification image before displaying it in + * the notification tray + */ + fun getBitmapFromURL(strURL: String?): Bitmap? { + return try { + val url = URL(strURL) + val connection = url.openConnection() as HttpURLConnection + connection.doInput = true + connection.connect() + val input = connection.inputStream + BitmapFactory.decodeStream(input) + } catch (e: IOException) { + Log.e(TAG, "Unable to create bitmap", e) + null + } + } + + // Playing notification sound + fun playNotificationSound() { + try { +// Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +// + "://" + mContext.getPackageName() + "/raw/notification"); + val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + val r = RingtoneManager.getRingtone(mContext, defaultSoundUri) + r.play() + } catch (e: Exception) { + Log.d(TAG, "playNotificationSound: " + e.message) + } + } + + companion object { + private val TAG = NotificationUtils::class.java.simpleName + + /** + * Method checks if the app is in background or not + */ + fun isAppIsInBackground(context: Context): Boolean { + var isInBackground = true + val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { + val runningProcesses = am.runningAppProcesses + for (processInfo in runningProcesses) { + if (processInfo.importance + == RunningAppProcessInfo.IMPORTANCE_FOREGROUND + ) { + for (activeProcess in processInfo.pkgList) { + if (activeProcess == context.packageName) { + isInBackground = false + } + } + } + } + } else { + val taskInfo = am.getRunningTasks(1) + val componentInfo = taskInfo[0].topActivity + if (componentInfo!!.packageName == context.packageName) { + isInBackground = false + } + } + return isInBackground + } + + // Clears notification tray messages + fun clearNotifications(context: Context) { + val notificationManager = context.getSystemService( + Context.NOTIFICATION_SERVICE + ) as NotificationManager + notificationManager.cancelAll() + } + + fun getTimeMilliSec(timeStamp: String?): Long { + val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + try { + val date = format.parse(timeStamp) + return date.time + } catch (e: ParseException) { + Log.e(TAG, "Unable to parse the timestamp", e) + } + return 0 + } + } +} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/PasswordStrength.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/PasswordStrength.java deleted file mode 100644 index bbf939662..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/PasswordStrength.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.graphics.Color; -import android.util.Log; - -import org.mifos.mobilewallet.mifospay.R; - -public class PasswordStrength { - - private int strengthStringId; - private int colorResId; - private int currentScore = 0; - private int value; - - public PasswordStrength(String password) { - - Log.e ("log", "INIT : " + currentScore + " " + password.length()); - if (password.length() < 6) { - currentScore = 0; - } else if (password.length() < 12) { - currentScore = 1; - } else { - currentScore = 2; - } - - if (password.length() > 6) { - for (int i = 0; i < password.length(); i++) { - char c = password.charAt(i); - - if (Character.isUpperCase(c)) { - currentScore++; - break; - } - } - } - if (password.length() > 6) { - for (int i = 0; i < password.length(); i++) { - char c = password.charAt(i); - - if (Character.isDigit(c)) { - currentScore++; - break; - } - } - } - Log.e("log", "Final : " + currentScore); - - switch (currentScore) { - case (0) : value = 0; - strengthStringId = R.string.password_very_weak; - colorResId = -1; - break; - case (1) : value = 25; - strengthStringId = R.string.password_weak; - colorResId = Color.RED; - break; - case (2) : value = 50; - strengthStringId = R.string.password_normal; - colorResId = Color.YELLOW; - break; - case (3) : value = 75; - strengthStringId = R.string.password_strong; - colorResId = Color.GREEN; - break; - case (4) : value = 100; - strengthStringId = R.string.password_very_strong; - colorResId = Color.BLUE; - break; - default:value = -1; - strengthStringId = R.string.password_very_weak; - colorResId = -1; - } - - } - - public int getStrengthStringId() { - return strengthStringId; - } - - public int getColorResId() { - return colorResId; - } - public int getValue() { - return value; - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/PasswordStrength.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/PasswordStrength.kt new file mode 100644 index 000000000..a9a7f1784 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/PasswordStrength.kt @@ -0,0 +1,79 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.graphics.Color +import android.util.Log +import org.mifos.mobilewallet.mifospay.R + +class PasswordStrength(password: String) { + var strengthStringId = 0 + var colorResId = 0 + private var currentScore = 0 + var value = 0 + + init { + Log.e("log", "INIT : " + currentScore + " " + password.length) + currentScore = if (password.length < 6) { + 0 + } else if (password.length < 12) { + 1 + } else { + 2 + } + if (password.length > 6) { + for (i in 0 until password.length) { + val c = password[i] + if (Character.isUpperCase(c)) { + currentScore++ + break + } + } + } + if (password.length > 6) { + for (i in 0 until password.length) { + val c = password[i] + if (Character.isDigit(c)) { + currentScore++ + break + } + } + } + Log.e("log", "Final : $currentScore") + when (currentScore) { + 0 -> { + value = 0 + strengthStringId = R.string.password_very_weak + colorResId = -1 + } + + 1 -> { + value = 25 + strengthStringId = R.string.password_weak + colorResId = Color.RED + } + + 2 -> { + value = 50 + strengthStringId = R.string.password_normal + colorResId = Color.YELLOW + } + + 3 -> { + value = 75 + strengthStringId = R.string.password_strong + colorResId = Color.GREEN + } + + 4 -> { + value = 100 + strengthStringId = R.string.password_very_strong + colorResId = Color.BLUE + } + + else -> { + value = -1 + strengthStringId = R.string.password_very_weak + colorResId = -1 + } + } + } +} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/RecyclerItemClickListener.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/RecyclerItemClickListener.java deleted file mode 100644 index b85347bb4..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/RecyclerItemClickListener.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.content.Context; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.View; - -public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { - - protected OnItemClickListener listener; - - private GestureDetector gestureDetector; - - @Nullable - private View childView; - - private int childViewPosition; - - public RecyclerItemClickListener(Context context, OnItemClickListener listener) { - this.gestureDetector = new GestureDetector(context, new GestureListener()); - this.listener = listener; - } - - @Override - public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) { - childView = view.findChildViewUnder(event.getX(), event.getY()); - childViewPosition = view.getChildAdapterPosition(childView); - - return childView != null && gestureDetector.onTouchEvent(event); - } - - @Override - public void onTouchEvent(RecyclerView view, MotionEvent event) { - // Not needed. - } - - @Override - public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { - - } - - /** - * A click listener for items. - */ - public interface OnItemClickListener { - - /** - * Called when an item is clicked. - * - * @param childView View of the item that was clicked. - * @param position Position of the item that was clicked. - */ - void onItemClick(View childView, int position); - - /** - * Called when an item is long pressed. - * - * @param childView View of the item that was long pressed. - * @param position Position of the item that was long pressed. - */ - void onItemLongPress(View childView, int position); - - } - - /** - * A simple click listener whose methods can be overridden one by one. - */ - public abstract static class SimpleOnItemClickListener implements OnItemClickListener { - - /** - * Called when an item is clicked. The default implementation is a no-op. - * - * @param childView View of the item that was clicked. - * @param position Position of the item that was clicked. - */ - public void onItemClick(View childView, int position) { - // Do nothing. - } - - /** - * Called when an item is long pressed. The default implementation is a no-op. - * - * @param childView View of the item that was long pressed. - * @param position Position of the item that was long pressed. - */ - public void onItemLongPress(View childView, int position) { - // Do nothing. - } - - } - - protected class GestureListener extends GestureDetector.SimpleOnGestureListener { - - @Override - public boolean onSingleTapUp(MotionEvent event) { - if (childView != null) { - listener.onItemClick(childView, childViewPosition); - } - - return true; - } - - @Override - public void onLongPress(MotionEvent event) { - if (childView != null) { - listener.onItemLongPress(childView, childViewPosition); - } - } - - @Override - public boolean onDown(MotionEvent event) { - // Best practice to always return true here. - // http://developer.android.com/training/gestures/detector.html#detect - return true; - } - - } - -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/RecyclerItemClickListener.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/RecyclerItemClickListener.kt new file mode 100644 index 000000000..4878dcf7f --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/RecyclerItemClickListener.kt @@ -0,0 +1,101 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.content.Context +import android.view.GestureDetector +import android.view.GestureDetector.SimpleOnGestureListener +import android.view.MotionEvent +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener + +class RecyclerItemClickListener(context: Context?, listener: OnItemClickListener) : + OnItemTouchListener { + protected var listener: OnItemClickListener + private val gestureDetector: GestureDetector + private var childView: View? = null + private var childViewPosition = 0 + + init { + gestureDetector = GestureDetector(context, GestureListener()) + this.listener = listener + } + + override fun onInterceptTouchEvent(view: RecyclerView, event: MotionEvent): Boolean { + childView = view.findChildViewUnder(event.x, event.y) + childViewPosition = view.getChildAdapterPosition(childView!!) + return childView != null && gestureDetector.onTouchEvent(event) + } + + override fun onTouchEvent(view: RecyclerView, event: MotionEvent) { + // Not needed. + } + + override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {} + + /** + * A click listener for items. + */ + interface OnItemClickListener { + /** + * Called when an item is clicked. + * + * @param childView View of the item that was clicked. + * @param position Position of the item that was clicked. + */ + fun onItemClick(childView: View?, position: Int) + + /** + * Called when an item is long pressed. + * + * @param childView View of the item that was long pressed. + * @param position Position of the item that was long pressed. + */ + fun onItemLongPress(childView: View?, position: Int) + } + + /** + * A simple click listener whose methods can be overridden one by one. + */ + abstract class SimpleOnItemClickListener : OnItemClickListener { + /** + * Called when an item is clicked. The default implementation is a no-op. + * + * @param childView View of the item that was clicked. + * @param position Position of the item that was clicked. + */ + override fun onItemClick(childView: View?, position: Int) { + // Do nothing. + } + + /** + * Called when an item is long pressed. The default implementation is a no-op. + * + * @param childView View of the item that was long pressed. + * @param position Position of the item that was long pressed. + */ + override fun onItemLongPress(childView: View?, position: Int) { + // Do nothing. + } + } + + protected inner class GestureListener : SimpleOnGestureListener() { + override fun onSingleTapUp(event: MotionEvent): Boolean { + if (childView != null) { + listener.onItemClick(childView, childViewPosition) + } + return true + } + + override fun onLongPress(event: MotionEvent) { + if (childView != null) { + listener.onItemLongPress(childView, childViewPosition) + } + } + + override fun onDown(event: MotionEvent): Boolean { + // Best practice to always return true here. + // http://developer.android.com/training/gestures/detector.html#detect + return true + } + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/TextDrawable.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/TextDrawable.java deleted file mode 100644 index a3dae2ca8..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/TextDrawable.java +++ /dev/null @@ -1,308 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.Typeface; -import android.graphics.drawable.ShapeDrawable; -import android.graphics.drawable.shapes.OvalShape; -import android.graphics.drawable.shapes.RectShape; -import android.graphics.drawable.shapes.RoundRectShape; - - -public class TextDrawable extends ShapeDrawable { - - private static final float SHADE_FACTOR = 0.9f; - private final Paint textPaint; - private final Paint borderPaint; - private final String text; - private final int color; - private final RectShape shape; - private final int height; - private final int width; - private final int fontSize; - private final float radius; - private final int borderThickness; - - private TextDrawable(Builder builder) { - super(builder.shape); - - // shape properties - shape = builder.shape; - height = builder.mHeight; - width = builder.mWidth; - radius = builder.radius; - - // text and color - text = builder.mToUpperCase ? builder.text.toUpperCase() : builder.text; - color = builder.color; - - // text paint settings - fontSize = builder.mFontSize; - textPaint = new Paint(); - textPaint.setColor(builder.mTextColor); - textPaint.setAntiAlias(true); - textPaint.setFakeBoldText(builder.isBold); - textPaint.setStyle(Paint.Style.FILL); - textPaint.setTypeface(builder.font); - textPaint.setTextAlign(Paint.Align.CENTER); - textPaint.setStrokeWidth(builder.borderThickness); - - // border paint settings - borderThickness = builder.borderThickness; - borderPaint = new Paint(); - borderPaint.setColor(getDarkerShade(color)); - borderPaint.setStyle(Paint.Style.STROKE); - borderPaint.setStrokeWidth(borderThickness); - - // drawable paint color - Paint paint = getPaint(); - paint.setColor(color); - - } - - public static IShapeBuilder builder() { - return new Builder(); - } - - private int getDarkerShade(int color) { - return Color.rgb((int) (SHADE_FACTOR * Color.red(color)), - (int) (SHADE_FACTOR * Color.green(color)), - (int) (SHADE_FACTOR * Color.blue(color))); - } - - @Override - public void draw(Canvas canvas) { - super.draw(canvas); - Rect r = getBounds(); - - - // draw border - if (borderThickness > 0) { - drawBorder(canvas); - } - - int count = canvas.save(); - canvas.translate(r.left, r.top); - - // draw text - int width = this.width < 0 ? r.width() : this.width; - int height = this.height < 0 ? r.height() : this.height; - int fontSize = this.fontSize < 0 ? (Math.min(width, height) / 2) : this.fontSize; - textPaint.setTextSize(fontSize); - canvas.drawText(text, width / 2, height / 2 - ((textPaint.descent() + - textPaint.ascent()) / 2), textPaint); - - canvas.restoreToCount(count); - - } - - private void drawBorder(Canvas canvas) { - RectF rect = new RectF(getBounds()); - rect.inset(borderThickness / 2, borderThickness / 2); - - if (shape instanceof OvalShape) { - canvas.drawOval(rect, borderPaint); - } else if (shape instanceof RoundRectShape) { - canvas.drawRoundRect(rect, radius, radius, borderPaint); - } else { - canvas.drawRect(rect, borderPaint); - } - } - - @Override - public void setAlpha(int alpha) { - textPaint.setAlpha(alpha); - } - - @Override - public void setColorFilter(ColorFilter cf) { - textPaint.setColorFilter(cf); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public int getIntrinsicWidth() { - return width; - } - - @Override - public int getIntrinsicHeight() { - return height; - } - - public interface IConfigBuilder { - public IConfigBuilder width(int width); - - public IConfigBuilder height(int height); - - public IConfigBuilder textColor(int color); - - public IConfigBuilder withBorder(int thickness); - - public IConfigBuilder useFont(Typeface font); - - public IConfigBuilder fontSize(int size); - - public IConfigBuilder bold(); - - public IConfigBuilder toUpperCase(); - - public IShapeBuilder endConfig(); - } - - public static interface IBuilder { - - public TextDrawable build(String text, int color); - } - - public static interface IShapeBuilder { - - public IConfigBuilder beginConfig(); - - public IBuilder rect(); - - public IBuilder round(); - - public IBuilder roundRect(int radius); - - public TextDrawable buildRect(String text, int color); - - public TextDrawable buildRoundRect(String text, int color, int radius); - - public TextDrawable buildRound(String text, int color); - } - - public static class Builder implements IConfigBuilder, IShapeBuilder, IBuilder { - - public int mTextColor; - public float radius; - private String text; - private int color; - private int borderThickness; - private int mWidth; - private int mHeight; - private Typeface font; - private RectShape shape; - private int mFontSize; - private boolean isBold; - private boolean mToUpperCase; - - private Builder() { - text = ""; - color = Color.GRAY; - mTextColor = Color.WHITE; - borderThickness = 0; - mWidth = -1; - mHeight = -1; - shape = new RectShape(); - font = Typeface.create("sans-serif-light", Typeface.NORMAL); - mFontSize = -1; - isBold = false; - mToUpperCase = false; - } - - public IConfigBuilder width(int width) { - this.mWidth = width; - return this; - } - - public IConfigBuilder height(int height) { - this.mHeight = height; - return this; - } - - public IConfigBuilder textColor(int color) { - this.mTextColor = color; - return this; - } - - public IConfigBuilder withBorder(int thickness) { - this.borderThickness = thickness; - return this; - } - - public IConfigBuilder useFont(Typeface font) { - this.font = font; - return this; - } - - public IConfigBuilder fontSize(int size) { - this.mFontSize = size; - return this; - } - - public IConfigBuilder bold() { - this.isBold = true; - return this; - } - - public IConfigBuilder toUpperCase() { - this.mToUpperCase = true; - return this; - } - - @Override - public IConfigBuilder beginConfig() { - return this; - } - - @Override - public IShapeBuilder endConfig() { - return this; - } - - @Override - public IBuilder rect() { - this.shape = new RectShape(); - return this; - } - - @Override - public IBuilder round() { - this.shape = new OvalShape(); - return this; - } - - @Override - public IBuilder roundRect(int radius) { - this.radius = radius; - float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; - this.shape = new RoundRectShape(radii, null, null); - return this; - } - - @Override - public TextDrawable buildRect(String text, int color) { - rect(); - return build(text, color); - } - - @Override - public TextDrawable buildRoundRect(String text, int color, int radius) { - roundRect(radius); - return build(text, color); - } - - @Override - public TextDrawable buildRound(String text, int color) { - round(); - return build(text, color); - } - - @Override - public TextDrawable build(String text, int color) { - this.color = color; - this.text = text; - return new TextDrawable(this); - } - } -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/TextDrawable.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/TextDrawable.kt new file mode 100644 index 000000000..46905da87 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/TextDrawable.kt @@ -0,0 +1,282 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.ColorFilter +import android.graphics.Paint +import android.graphics.PixelFormat +import android.graphics.RectF +import android.graphics.Typeface +import android.graphics.drawable.ShapeDrawable +import android.graphics.drawable.shapes.OvalShape +import android.graphics.drawable.shapes.RectShape +import android.graphics.drawable.shapes.RoundRectShape +import java.util.Locale + +class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder.shape) { + private val textPaint: Paint + private val borderPaint: Paint + private val text: String + private val color: Int + private val shape: RectShape + private val height: Int + private val width: Int + private val fontSize: Int + private val radius: Float + private val borderThickness: Int + + init { + + // shape properties + shape = builder.shape + height = builder.mHeight + width = builder.mWidth + radius = builder.radius + + // text and color + text = + if (builder.mToUpperCase) builder.text.uppercase(Locale.getDefault()) else builder.text + color = builder.color + + // text paint settings + fontSize = builder.mFontSize + textPaint = Paint() + textPaint.color = builder.mTextColor + textPaint.isAntiAlias = true + textPaint.isFakeBoldText = builder.isBold + textPaint.style = Paint.Style.FILL + textPaint.setTypeface(builder.font) + textPaint.textAlign = Paint.Align.CENTER + textPaint.strokeWidth = builder.borderThickness.toFloat() + + // border paint settings + borderThickness = builder.borderThickness + borderPaint = Paint() + borderPaint.color = getDarkerShade(color) + borderPaint.style = Paint.Style.STROKE + borderPaint.strokeWidth = borderThickness.toFloat() + + // drawable paint color + val paint = paint + paint.color = color + } + + private fun getDarkerShade(color: Int): Int { + return Color.rgb( + (SHADE_FACTOR * Color.red(color)).toInt(), + (SHADE_FACTOR * Color.green(color)).toInt(), + (SHADE_FACTOR * Color.blue(color)).toInt() + ) + } + + override fun draw(canvas: Canvas) { + super.draw(canvas) + val r = bounds + + + // draw border + if (borderThickness > 0) { + drawBorder(canvas) + } + val count = canvas.save() + canvas.translate(r.left.toFloat(), r.top.toFloat()) + + // draw text + val width = if (width < 0) r.width() else width + val height = if (height < 0) r.height() else height + val fontSize = if (fontSize < 0) Math.min(width, height) / 2 else fontSize + textPaint.textSize = fontSize.toFloat() + canvas.drawText( + text, (width / 2).toFloat(), height / 2 - (textPaint.descent() + + textPaint.ascent()) / 2, textPaint + ) + canvas.restoreToCount(count) + } + + private fun drawBorder(canvas: Canvas) { + val rect = RectF(bounds) + rect.inset((borderThickness / 2).toFloat(), (borderThickness / 2).toFloat()) + if (shape is OvalShape) { + canvas.drawOval(rect, borderPaint) + } else if (shape is RoundRectShape) { + canvas.drawRoundRect(rect, radius, radius, borderPaint) + } else { + canvas.drawRect(rect, borderPaint) + } + } + + override fun setAlpha(alpha: Int) { + textPaint.alpha = alpha + } + + override fun setColorFilter(cf: ColorFilter?) { + textPaint.setColorFilter(cf) + } + + override fun getOpacity(): Int { + return PixelFormat.TRANSLUCENT + } + + override fun getIntrinsicWidth(): Int { + return width + } + + override fun getIntrinsicHeight(): Int { + return height + } + + interface IConfigBuilder { + fun width(width: Int): IConfigBuilder + fun height(height: Int): IConfigBuilder + fun textColor(color: Int): IConfigBuilder + fun withBorder(thickness: Int): IConfigBuilder + fun useFont(font: Typeface): IConfigBuilder + fun fontSize(size: Int): IConfigBuilder + fun bold(): IConfigBuilder + fun toUpperCase(): IConfigBuilder + fun endConfig(): IShapeBuilder + } + + interface IBuilder { + fun build(text: String, color: Int): TextDrawable + } + + interface IShapeBuilder { + fun beginConfig(): IConfigBuilder + fun rect(): IBuilder + fun round(): IBuilder + fun roundRect(radius: Int): IBuilder + fun buildRect(text: String, color: Int): TextDrawable + fun buildRoundRect(text: String, color: Int, radius: Int): TextDrawable + fun buildRound(text: String, color: Int): TextDrawable + } + + class Builder() : IConfigBuilder, IShapeBuilder, IBuilder { + var mTextColor: Int + var radius = 0f + var text = "" + var color: Int + var borderThickness = 0 + var mWidth: Int + var mHeight: Int + var font: Typeface + var shape: RectShape + var mFontSize: Int + var isBold: Boolean + var mToUpperCase: Boolean + + init { + color = Color.GRAY + mTextColor = Color.WHITE + mWidth = -1 + mHeight = -1 + shape = RectShape() + font = Typeface.create("sans-serif-light", Typeface.NORMAL) + mFontSize = -1 + isBold = false + mToUpperCase = false + } + + override fun width(width: Int): IConfigBuilder { + mWidth = width + return this + } + + override fun height(height: Int): IConfigBuilder { + mHeight = height + return this + } + + override fun textColor(color: Int): IConfigBuilder { + mTextColor = color + return this + } + + override fun withBorder(thickness: Int): IConfigBuilder { + borderThickness = thickness + return this + } + + override fun useFont(font: Typeface): IConfigBuilder { + this.font = font + return this + } + + override fun fontSize(size: Int): IConfigBuilder { + mFontSize = size + return this + } + + override fun bold(): IConfigBuilder { + isBold = true + return this + } + + override fun toUpperCase(): IConfigBuilder { + mToUpperCase = true + return this + } + + override fun beginConfig(): IConfigBuilder { + return this + } + + override fun endConfig(): IShapeBuilder { + return this + } + + override fun rect(): IBuilder { + shape = RectShape() + return this + } + + override fun round(): IBuilder { + shape = OvalShape() + return this + } + + override fun roundRect(radius: Int): IBuilder { + this.radius = radius.toFloat() + val radii = floatArrayOf( + radius.toFloat(), + radius.toFloat(), + radius.toFloat(), + radius.toFloat(), + radius.toFloat(), + radius.toFloat(), + radius.toFloat(), + radius.toFloat() + ) + shape = RoundRectShape(radii, null, null) + return this + } + + override fun buildRect(text: String, color: Int): TextDrawable { + rect() + return build(text, color) + } + + override fun buildRoundRect(text: String, color: Int, radius: Int): TextDrawable { + roundRect(radius) + return build(text, color) + } + + override fun buildRound(text: String, color: Int): TextDrawable { + round() + return build(text, color) + } + + override fun build(text: String, color: Int): TextDrawable { + this.color = color + this.text = text + return TextDrawable(this) + } + } + + companion object { + private const val SHADE_FACTOR = 0.9f + fun builder(): IShapeBuilder { + return Builder() + } + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Toaster.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Toaster.java deleted file mode 100644 index da9c1bc9b..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Toaster.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.mifos.mobilewallet.mifospay.utils; - -import android.content.Context; -import android.graphics.Color; -import com.google.android.material.snackbar.Snackbar; -import android.view.View; -import android.widget.TextView; -import android.widget.Toast; - -import org.mifos.mobilewallet.mifospay.MifosPayApp; -import org.mifos.mobilewallet.mifospay.R; - -/** - * Created by ankur on 23/May/2018 - */ - -public class Toaster { - - public static final int INDEFINITE = Snackbar.LENGTH_INDEFINITE; - public static final int LONG = Snackbar.LENGTH_LONG; - public static final int SHORT = Snackbar.LENGTH_SHORT; - - public static void show(View view, String text, int duration, String actionText, - View.OnClickListener clickListener) { - if (view != null) { - final Snackbar snackbar = Snackbar.make(view, text, duration); - View sbView = snackbar.getView(); - TextView textView = sbView.findViewById(R.id.snackbar_text); - textView.setTextColor(Color.WHITE); - textView.setTextSize(12); - snackbar.setAction(actionText, clickListener); - snackbar.show(); - } - } - - public static void show(View view, String text, int duration) { - show(view, text, duration, Constants.OK, new View.OnClickListener() { - @Override - public void onClick(View view) { - - } - }); - } - - public static void show(View view, int res, int duration) { - show(view, MifosPayApp.getContext().getResources().getString(res), duration); - } - - public static void show(View view, String text) { - show(view, text, Snackbar.LENGTH_LONG); - } - - public static void show(View view, int res) { - show(view, MifosPayApp.getContext().getResources().getString(res)); - } - - public static void showToast(Context context, String message) { - if (context != null) { - Toast.makeText(context, message, Toast.LENGTH_LONG).show(); - } - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Toaster.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Toaster.kt new file mode 100644 index 000000000..343320151 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/utils/Toaster.kt @@ -0,0 +1,51 @@ +package org.mifos.mobilewallet.mifospay.utils + +import android.content.Context +import android.graphics.Color +import android.view.View +import android.widget.TextView +import android.widget.Toast +import com.google.android.material.snackbar.Snackbar +import org.mifos.mobilewallet.mifospay.MifosPayApp.Companion.context +import org.mifos.mobilewallet.mifospay.R + +/** + * Created by ankur on 23/May/2018 + */ +object Toaster { + const val INDEFINITE = Snackbar.LENGTH_INDEFINITE + const val LONG = Snackbar.LENGTH_LONG + const val SHORT = Snackbar.LENGTH_SHORT + @JvmOverloads + fun show( + view: View?, + text: String?, + duration: Int = Snackbar.LENGTH_LONG, + actionText: String? = Constants.OK, + clickListener: View.OnClickListener? = View.OnClickListener { } + ) { + if (view != null) { + val snackbar = Snackbar.make(view, text!!, duration) + val sbView = snackbar.view + val textView = sbView.findViewById(R.id.snackbar_text) + textView.setTextColor(Color.WHITE) + textView.textSize = 12f + snackbar.setAction(actionText, clickListener) + snackbar.show() + } + } + + fun show(view: View?, res: Int, duration: Int) { + show(view, context!!.resources.getString(res), duration) + } + + fun show(view: View?, res: Int) { + show(view, context!!.resources.getString(res)) + } + + fun showToast(context: Context?, message: String?) { + if (context != null) { + Toast.makeText(context, message, Toast.LENGTH_LONG).show() + } + } +}