From 87dace9591f8902c2b6ee3e27ae4371ed7dcd831 Mon Sep 17 00:00:00 2001 From: divyank00 Date: Mon, 18 Jan 2021 14:36:46 +0530 Subject: [PATCH 1/2] fix: #1169 Added option to scan qr code in Create SI Activity --- .../standinginstruction/ui/NewSIActivity.kt | 61 +++++++++++++++++++ .../src/main/res/layout/activity_new_si.xml | 57 +++++++++++------ 2 files changed, 99 insertions(+), 19 deletions(-) diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt index b7bc5fc60..42f5a6dec 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt @@ -1,8 +1,13 @@ 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 @@ -10,9 +15,11 @@ 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 @@ -21,6 +28,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 @@ -110,6 +121,56 @@ class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView { ll_create_si.visibility = View.VISIBLE } + @OnClick(R.id.btn_scan_qr) + fun scanQrClicked() { + if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, + Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + + // Permission is not granted + requestPermissions(arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA) + } else { + + // Permission has already been granted + 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, + grantResults: IntArray) { + when (requestCode) { + REQUEST_CAMERA -> { + // If request is cancelled, the result arrays are empty. + if (grantResults.isNotEmpty() + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // permission was granted, yay! Do the + // camera-related task you need to do. + val i = Intent(this, ReadQrActivity::class.java) + startActivityForResult(i, SCAN_QR_REQUEST_CODE) + } else { + // permission denied, boo! Disable the + // functionality that depends on this permission. + Toaster.show(findViewById(android.R.id.content), Constants.NEED_CAMERA_PERMISSION_TO_SCAN_QR_CODE) + } + return + } + } + } + override fun showLoadingView() { ll_create_si.visibility = View.GONE ll_confirm_cancel.visibility = View.GONE diff --git a/mifospay/src/main/res/layout/activity_new_si.xml b/mifospay/src/main/res/layout/activity_new_si.xml index c643d6100..af051661c 100644 --- a/mifospay/src/main/res/layout/activity_new_si.xml +++ b/mifospay/src/main/res/layout/activity_new_si.xml @@ -42,28 +42,47 @@ - + android:layout_height="wrap_content"> - - + android:layout_height="80dp" + android:layout_marginLeft="@dimen/value_20dp" + android:layout_marginTop="@dimen/value_10dp" + android:layout_marginBottom="@dimen/value_10dp" + android:padding="@dimen/value_10dp" + android:textColorHint="@android:color/black" + app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout" + android:layout_toLeftOf="@id/btn_scan_qr"> + + + + + + Date: Thu, 28 Jan 2021 23:38:22 +0530 Subject: [PATCH 2/2] fix: #1169 Added option to scan qr code in Create SI Activity --- .../standinginstruction/ui/NewSIActivity.kt | 25 +++++++------------ .../src/main/res/layout/activity_new_si.xml | 19 +++++++------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt index 30f0a185e..7ebb8abae 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/standinginstruction/ui/NewSIActivity.kt @@ -11,7 +11,6 @@ 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 @@ -46,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) @@ -67,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)) @@ -108,7 +114,6 @@ 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 @@ -116,22 +121,16 @@ class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView { 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 } - @OnClick(R.id.btn_scan_qr) fun scanQrClicked() { if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { - - // Permission is not granted requestPermissions(arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA) } else { - - // Permission has already been granted val i = Intent(this, ReadQrActivity::class.java) startActivityForResult(i, SCAN_QR_REQUEST_CODE) } @@ -155,19 +154,13 @@ class NewSIActivity : BaseActivity(), StandingInstructionContract.NewSIView { grantResults: IntArray) { when (requestCode) { REQUEST_CAMERA -> { - // If request is cancelled, the result arrays are empty. if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - // permission was granted, yay! Do the - // camera-related task you need to do. val i = Intent(this, ReadQrActivity::class.java) startActivityForResult(i, SCAN_QR_REQUEST_CODE) } else { - // permission denied, boo! Disable the - // functionality that depends on this permission. Toaster.show(findViewById(android.R.id.content), Constants.NEED_CAMERA_PERMISSION_TO_SCAN_QR_CODE) } - return } } } diff --git a/mifospay/src/main/res/layout/activity_new_si.xml b/mifospay/src/main/res/layout/activity_new_si.xml index 5c447348e..a400c34f6 100644 --- a/mifospay/src/main/res/layout/activity_new_si.xml +++ b/mifospay/src/main/res/layout/activity_new_si.xml @@ -46,18 +46,20 @@ android:layout_height="wrap_content"> + app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"> + android:textSize="@dimen/value_15sp" />