Skip to content

Commit

Permalink
fix: openMF#1169 Added option to scan qr code in Create SI Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
divyank00 committed Jan 31, 2021
1 parent fc8083d commit 6040d99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -108,30 +114,23 @@ 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
}

@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)
}
Expand All @@ -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
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions mifospay/src/main/res/layout/activity_new_si.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,28 @@
android:layout_height="wrap_content">

<android.support.design.widget.TextInputLayout
android:layout_toStartOf="@id/btn_scan_qr"
android:id="@+id/til_si_vpa"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="80dp"
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:padding="@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:layout_toLeftOf="@id/btn_scan_qr">
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:theme="@style/Theme.AppCompat.Light" />
android:textSize="@dimen/value_15sp" />
</android.support.design.widget.TextInputLayout>

<ImageView
Expand All @@ -78,8 +79,8 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/value_50dp"
android:layout_marginRight="@dimen/value_50dp"
android:layout_marginEnd="@dimen/value_30dp"
android:layout_marginRight="@dimen/value_30dp"
android:src="@drawable/qrcode_blue_selector" />
</RelativeLayout>

Expand Down

0 comments on commit 6040d99

Please sign in to comment.