Skip to content

Commit

Permalink
Merge pull request #1171 from divyank00/1169
Browse files Browse the repository at this point in the history
fix: #1169 Added option to scan qr code in Create SI Activity
  • Loading branch information
devansh-299 authored Jan 31, 2021
2 parents c0fcb13 + 6040d99 commit 2e6ae77
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package org.mifos.mobilewallet.mifospay.standinginstruction.ui

import android.Manifest
import android.app.DatePickerDialog
import android.app.DatePickerDialog.OnDateSetListener
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.Toast
import butterknife.ButterKnife
import butterknife.OnClick
import kotlinx.android.synthetic.main.activity_new_si.*
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.base.BaseActivity
import org.mifos.mobilewallet.mifospay.qr.ui.ReadQrActivity
import org.mifos.mobilewallet.mifospay.standinginstruction.StandingInstructionContract
import org.mifos.mobilewallet.mifospay.standinginstruction.presenter.NewSIPresenter
import org.mifos.mobilewallet.mifospay.utils.Constants
import org.mifos.mobilewallet.mifospay.utils.Toaster
import org.mifos.mobilewallet.mifospay.utils.Utils
import java.util.*
import javax.inject.Inject
Expand All @@ -21,6 +27,10 @@ import kotlin.properties.Delegates

class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView {


private val REQUEST_CAMERA = 0
private val SCAN_QR_REQUEST_CODE = 666

@Inject
lateinit var mPresenter: NewSIPresenter
private lateinit var mNewSIPresenter: StandingInstructionContract.NewSIPresenter
Expand All @@ -35,13 +45,21 @@ class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView {
setToolbarTitle(getString(R.string.tile_si_activity))
showColoredBackButton(Constants.BLACK_BACK_BUTTON)
mPresenter.attachView(this)
initView()
}

override fun setPresenter(presenter: StandingInstructionContract.NewSIPresenter) {
this.mNewSIPresenter = presenter
}

@OnClick(R.id.btn_valid_till)
private fun initView() {
btn_valid_till.setOnClickListener { pickToDate() }
btn_create_si.setOnClickListener { createSI() }
btn_confirm.setOnClickListener { createNewStandingInstruction() }
btn_cancel.setOnClickListener { cancelNewStandingInstruction() }
btn_scan_qr.setOnClickListener { scanQrClicked() }
}

fun pickToDate() {
val calendar: Calendar = Calendar.getInstance()
val day: Int = calendar.get(Calendar.DAY_OF_MONTH)
Expand All @@ -56,7 +74,6 @@ class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView {
picker.show()
}

@OnClick(R.id.btn_create_si)
fun createSI() {
if (et_si_amount.text.toString() == "") {
showToast(getString(R.string.enter_amount))
Expand Down Expand Up @@ -97,20 +114,57 @@ class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView {
progressBar.visibility = View.GONE
}

@OnClick(R.id.btn_confirm)
fun createNewStandingInstruction() {
ll_confirm_cancel.visibility = View.GONE
progressBar.visibility = View.VISIBLE
mNewSIPresenter.createNewSI(clientId, (et_si_amount.text.toString()).toDouble(),
et_si_interval.text.toString().toInt(), btn_valid_till.text.toString())
}

@OnClick(R.id.btn_cancel)
fun cancelNewStandingInstruction() {
ll_confirm_transfer.visibility = View.GONE
ll_create_si.visibility = View.VISIBLE
}

fun scanQrClicked() {
if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA)
} else {
val i = Intent(this, ReadQrActivity::class.java)
startActivityForResult(i, SCAN_QR_REQUEST_CODE)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SCAN_QR_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
val qrData = data.getStringExtra(Constants.QR_DATA)
val qrDataArray = qrData?.split(", ")?.toTypedArray()
if (qrDataArray?.size == 1) {
et_si_vpa.setText(qrDataArray[0])
} else {
et_si_vpa.setText(qrDataArray?.get(0))
et_si_amount.setText(qrDataArray?.get(1))
}
}
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String?>,
grantResults: IntArray) {
when (requestCode) {
REQUEST_CAMERA -> {
if (grantResults.isNotEmpty()
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
val i = Intent(this, ReadQrActivity::class.java)
startActivityForResult(i, SCAN_QR_REQUEST_CODE)
} else {
Toaster.show(findViewById(android.R.id.content), Constants.NEED_CAMERA_PERMISSION_TO_SCAN_QR_CODE)
}
}
}
}

override fun showLoadingView() {
ll_create_si.visibility = View.GONE
ll_confirm_cancel.visibility = View.GONE
Expand Down
56 changes: 39 additions & 17 deletions mifospay/src/main/res/layout/activity_new_si.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,48 @@

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:id="@+id/til_si_vpa"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/value_20dp"
android:layout_marginRight="@dimen/value_20dp"
android:layout_marginTop="@dimen/value_10dp"
android:layout_marginBottom="@dimen/value_10dp"
android:textColorHint="@android:color/black"
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout">
android:layout_height="wrap_content">

<android.support.design.widget.TextInputEditText
android:id="@+id/et_si_vpa"
<android.support.design.widget.TextInputLayout
android:id="@+id/til_si_vpa"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/virtual_payment_address"
android:singleLine="true"
android:textSize="@dimen/value_15sp" />
</android.support.design.widget.TextInputLayout>
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/value_20dp"
android:layout_marginLeft="@dimen/value_20dp"
android:layout_marginTop="@dimen/value_10dp"
android:layout_marginEnd="@dimen/value_15dp"
android:layout_marginRight="@dimen/value_20dp"
android:layout_marginBottom="@dimen/value_10dp"
android:layout_toStartOf="@id/btn_scan_qr"
android:layout_toLeftOf="@id/btn_scan_qr"
android:textColorHint="@android:color/black"
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout">

<android.support.design.widget.TextInputEditText
android:id="@+id/et_si_vpa"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/virtual_payment_address"
android:singleLine="true"
android:textSize="@dimen/value_15sp" />
</android.support.design.widget.TextInputLayout>

<ImageView
android:clickable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:id="@+id/btn_scan_qr"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/value_30dp"
android:layout_marginRight="@dimen/value_30dp"
android:src="@drawable/qrcode_blue_selector" />
</RelativeLayout>

<android.support.design.widget.TextInputLayout
android:id="@+id/til_si_interval"
Expand Down

0 comments on commit 2e6ae77

Please sign in to comment.