mirror of
https://github.com/openMF/mobile-wallet.git
synced 2026-02-06 14:16:54 +00:00
refactor: qr cleanup from mifospay module (#1685)
This commit is contained in:
parent
c578f2f785
commit
9e71011642
@ -12,7 +12,6 @@ import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||
|
||||
@ -11,8 +11,11 @@ dependencies {
|
||||
//Todo: Remove these after migration
|
||||
implementation("com.jakewharton:butterknife-annotations:10.2.3")
|
||||
implementation("com.jakewharton:butterknife:10.2.3@aar")
|
||||
implementation(project(":mifospay"))
|
||||
implementation("me.dm7.barcodescanner:zxing:1.9.13")
|
||||
implementation("com.journeyapps:zxing-android-embedded:4.2.0")
|
||||
implementation(project(":core:data"))
|
||||
implementation(libs.androidx.camera.view)
|
||||
implementation(libs.androidx.camera.lifecycle)
|
||||
|
||||
implementation("com.google.guava:guava:27.0.1-android")
|
||||
}
|
||||
@ -1,146 +1,24 @@
|
||||
package org.mifospay.feature.read.qr
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ImageButton
|
||||
import android.widget.Toast
|
||||
import butterknife.BindView
|
||||
import butterknife.ButterKnife
|
||||
import butterknife.OnClick
|
||||
import com.google.zxing.BinaryBitmap
|
||||
import com.google.zxing.LuminanceSource
|
||||
import com.google.zxing.MultiFormatReader
|
||||
import com.google.zxing.RGBLuminanceSource
|
||||
import com.google.zxing.Reader
|
||||
import com.google.zxing.Result
|
||||
import com.google.zxing.common.HybridBinarizer
|
||||
import com.journeyapps.barcodescanner.CaptureActivity
|
||||
import me.dm7.barcodescanner.zxing.ZXingScannerView
|
||||
import me.dm7.barcodescanner.zxing.ZXingScannerView.ResultHandler
|
||||
import org.mifospay.R
|
||||
import org.mifospay.common.Constants
|
||||
import org.mifospay.qr.QrContract
|
||||
import org.mifospay.qr.QrContract.ReadQrView
|
||||
import java.io.FileNotFoundException
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import org.mifospay.core.designsystem.theme.MifosTheme
|
||||
|
||||
/**
|
||||
* Created by naman on 7/9/17.
|
||||
*/
|
||||
|
||||
class ReadQrActivity : CaptureActivity(), ReadQrView, ResultHandler {
|
||||
|
||||
var mReadQrPresenter: QrContract.ReadQrPresenter? = null
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.scannerView)
|
||||
var mScannerView: ZXingScannerView? = null
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.btn_flash_on)
|
||||
var mFlashOn: ImageButton? = null
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.btn_flash_off)
|
||||
var mFlashOff: ImageButton? = null
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.btn_open_gallery)
|
||||
var mOpenGallery: ImageButton? = null
|
||||
class ReadQrActivity : ComponentActivity() {
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_read_qr)
|
||||
ButterKnife.bind(this@ReadQrActivity)
|
||||
mScannerView!!.setAutoFocus(true)
|
||||
}
|
||||
|
||||
@OnClick(R.id.btn_flash_on)
|
||||
fun turnOnFlash() {
|
||||
mScannerView!!.flash = true
|
||||
mFlashOn!!.visibility = View.GONE
|
||||
mFlashOff!!.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
@OnClick(R.id.btn_flash_off)
|
||||
fun turnOffFlash() {
|
||||
mScannerView!!.flash = false
|
||||
mFlashOn!!.visibility = View.VISIBLE
|
||||
mFlashOff!!.visibility = View.GONE
|
||||
}
|
||||
|
||||
@OnClick(R.id.btn_open_gallery)
|
||||
fun openGallery() {
|
||||
val photoPic = Intent(Intent.ACTION_PICK)
|
||||
photoPic.type = "image/*"
|
||||
startActivityForResult(photoPic, SELECT_PHOTO)
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
super.onResume()
|
||||
mScannerView!!.setResultHandler(this)
|
||||
mScannerView!!.startCamera()
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
super.onPause()
|
||||
mScannerView!!.stopCamera()
|
||||
}
|
||||
|
||||
override fun handleResult(result: Result) {
|
||||
val qrData = result.text
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra(Constants.QR_DATA, qrData)
|
||||
setResult(RESULT_OK, returnIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun setPresenter(presenter: QrContract.ReadQrPresenter?) {
|
||||
mReadQrPresenter = presenter
|
||||
}
|
||||
|
||||
fun scanQRImage(bMap: Bitmap): String? {
|
||||
var contents: String? = null
|
||||
val intArray = IntArray(bMap.width * bMap.height)
|
||||
bMap.getPixels(intArray, 0, bMap.width, 0, 0, bMap.width, bMap.height)
|
||||
val source: LuminanceSource = RGBLuminanceSource(bMap.width, bMap.height, intArray)
|
||||
val bitmap = BinaryBitmap(HybridBinarizer(source))
|
||||
val reader: Reader = MultiFormatReader()
|
||||
try {
|
||||
val result = reader.decode(bitmap)
|
||||
contents = result.text
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra(Constants.QR_DATA, contents)
|
||||
setResult(RESULT_OK, returnIntent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
"Error! $e", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
return contents
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK) {
|
||||
try {
|
||||
val selectedImage = data!!.data
|
||||
if (selectedImage != null) {
|
||||
val imageStream = contentResolver.openInputStream(selectedImage)
|
||||
val bMap = BitmapFactory.decodeStream(imageStream)
|
||||
scanQRImage(bMap)
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
Toast.makeText(applicationContext, "File not found", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
setContent {
|
||||
MifosTheme {
|
||||
ShowQrScreenRoute(
|
||||
backPress = { onBackPressed() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val SELECT_PHOTO = 100
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package org.mifospay.feature.read.qr
|
||||
|
||||
import org.mifospay.core.data.base.UseCaseHandler
|
||||
import org.mifospay.base.BaseView
|
||||
import org.mifospay.qr.QrContract
|
||||
import org.mifospay.qr.QrContract.ReadQrView
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Created by naman on 7/9/17.
|
||||
*/
|
||||
class ReadQrPresenter @Inject constructor(private val mUsecaseHandler: UseCaseHandler) :
|
||||
QrContract.ReadQrPresenter {
|
||||
private var mReadQrView: ReadQrView? = null
|
||||
override fun attachView(baseView: BaseView<*>?) {
|
||||
mReadQrView = baseView as ReadQrView?
|
||||
mReadQrView!!.setPresenter(this)
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package org.mifospay.qr.ui
|
||||
package org.mifospay.feature.read.qr
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
@ -22,13 +22,12 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@ -43,16 +42,15 @@ import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import org.mifospay.R
|
||||
import org.mifospay.core.designsystem.component.MfLoadingWheel
|
||||
import org.mifospay.core.designsystem.component.MifosScaffold
|
||||
import org.mifospay.core.designsystem.component.PermissionBox
|
||||
import org.mifospay.core.designsystem.icon.MifosIcons
|
||||
import org.mifospay.core.designsystem.theme.MifosTheme
|
||||
import org.mifospay.core.ui.EmptyContentScreen
|
||||
import org.mifospay.qr.presenter.ReadQrUiState
|
||||
import org.mifospay.qr.presenter.ReadQrViewModel
|
||||
import org.mifospay.theme.MifosTheme
|
||||
import org.mifospay.utils.QrCodeAnalyzer
|
||||
import org.mifospay.feature.qr.R
|
||||
import org.mifospay.feature.read.qr.utils.QrCodeAnalyzer
|
||||
|
||||
|
||||
@Composable
|
||||
fun ShowQrScreenRoute(
|
||||
@ -102,21 +100,21 @@ fun ReadQrScreen(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
)
|
||||
},
|
||||
title = R.string.permission_required,
|
||||
description = R.string.approve_permission_description_camera,
|
||||
confirmButtonText = R.string.proceed,
|
||||
dismissButtonText = R.string.dismiss,
|
||||
title = R.string.feature_qr_permission_required,
|
||||
description = R.string.feature_qr_approve_permission_description_camera,
|
||||
confirmButtonText = R.string.feature_qr_proceed,
|
||||
dismissButtonText = R.string.feature_qr_dismiss,
|
||||
)
|
||||
|
||||
MifosScaffold(
|
||||
topBarTitle = R.string.scan_code,
|
||||
topBarTitle = R.string.feature_qr_scan_code,
|
||||
backPress = { backPress.invoke() },
|
||||
scaffoldContent = { paddingValues ->
|
||||
Box(modifier = Modifier.padding(paddingValues)) {
|
||||
when (uiState) {
|
||||
is ReadQrUiState.Loading -> {
|
||||
MfLoadingWheel(
|
||||
contentDesc = stringResource(R.string.loading),
|
||||
contentDesc = stringResource(R.string.feature_qr_loading),
|
||||
backgroundColor = Color.White
|
||||
)
|
||||
}
|
||||
@ -128,8 +126,8 @@ fun ReadQrScreen(
|
||||
is ReadQrUiState.Error -> {
|
||||
EmptyContentScreen(
|
||||
modifier = Modifier,
|
||||
title = stringResource(id = R.string.error_oops),
|
||||
subTitle = stringResource(id = R.string.unexpected_error_subtitle),
|
||||
title = stringResource(R.string.feature_qr_oops),
|
||||
subTitle = stringResource(id = R.string.feature_qr_unexpected_error_subtitle),
|
||||
iconTint = Color.Black,
|
||||
iconImageVector = MifosIcons.Info
|
||||
)
|
||||
@ -1,4 +1,4 @@
|
||||
package org.mifospay.qr.presenter
|
||||
package org.mifospay.feature.read.qr
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.lifecycle.ViewModel
|
||||
@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import org.mifospay.core.data.base.UseCase
|
||||
import org.mifospay.core.data.base.UseCaseHandler
|
||||
import org.mifospay.qr.usecase.ScanQr
|
||||
import org.mifospay.feature.read.qr.utils.ScanQr
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@ -1,4 +1,4 @@
|
||||
package org.mifospay.utils
|
||||
package org.mifospay.feature.read.qr.utils
|
||||
|
||||
import android.graphics.ImageFormat
|
||||
import androidx.camera.core.ImageAnalysis
|
||||
@ -1,4 +1,4 @@
|
||||
package org.mifospay.qr.usecase
|
||||
package org.mifospay.feature.read.qr.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.google.zxing.BinaryBitmap
|
||||
12
feature/qr/src/main/res/values/strings.xml
Normal file
12
feature/qr/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="feature_qr_approve_permission_description_camera">You need to approve these permissions in order to access the camera.</string>
|
||||
<string name="feature_qr_permission_required">Permission Required</string>
|
||||
<string name="feature_qr_dismiss">Dismiss</string>
|
||||
<string name="feature_qr_proceed">Proceed</string>
|
||||
<string name="feature_qr_scan_code">Scan Code</string>
|
||||
<string name="feature_qr_loading">Loading</string>
|
||||
<string name="feature_qr_oops">Oops</string>
|
||||
<string name="feature_qr_unexpected_error_subtitle">An unexpected error occurred. Please try again.</string>
|
||||
|
||||
</resources>
|
||||
@ -84,6 +84,7 @@ dependencies {
|
||||
implementation(projects.feature.upiSetup)
|
||||
implementation(projects.feature.settings)
|
||||
implementation(projects.feature.savedcards)
|
||||
implementation(projects.feature.qr)
|
||||
|
||||
// Compose
|
||||
implementation(libs.androidx.activity.compose)
|
||||
@ -103,8 +104,6 @@ dependencies {
|
||||
implementation(libs.coil.kt)
|
||||
implementation(libs.androidx.material.navigation)
|
||||
implementation(libs.accompanist.pager)
|
||||
implementation(libs.androidx.camera.view)
|
||||
implementation(libs.androidx.camera.lifecycle)
|
||||
|
||||
ksp(libs.hilt.compiler)
|
||||
|
||||
@ -160,7 +159,6 @@ dependencies {
|
||||
implementation("io.coil-kt:coil-compose:2.6.0")
|
||||
|
||||
implementation("com.google.android.gms:play-services-auth:20.7.0")
|
||||
implementation("com.google.guava:guava:27.0.1-android")
|
||||
|
||||
implementation("com.hbb20:ccp:2.2.0")
|
||||
implementation("com.github.MdFarhanRaja:SearchableSpinner:1.9")
|
||||
|
||||
@ -82,7 +82,7 @@
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name=".qr.ui.ReadQrActivity"
|
||||
android:name=".feature.read.qr.ReadQrActivity"
|
||||
android:theme="@style/AppTheme" />
|
||||
<activity
|
||||
android:name=".feature.passcode.PassCodeActivity"
|
||||
|
||||
@ -29,12 +29,12 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.mifospay.R
|
||||
import org.mifospay.base.BaseFragment
|
||||
import org.mifospay.home.BaseHomeContract
|
||||
import org.mifospay.qr.ui.ReadQrActivity
|
||||
import org.mifospay.common.Constants
|
||||
import org.mifospay.payments.TransferViewModel
|
||||
import org.mifospay.utils.Toaster
|
||||
import org.mifospay.common.Utils.hideSoftKeyboard
|
||||
import org.mifospay.common.ui.MakeTransferFragment
|
||||
import org.mifospay.feature.read.qr.ReadQrActivity
|
||||
|
||||
/**
|
||||
* Created by naman on 30/8/17.
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
package org.mifospay.qr
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import org.mifospay.base.BasePresenter
|
||||
import org.mifospay.base.BaseView
|
||||
|
||||
/**
|
||||
* Created by naman on 8/7/17.
|
||||
*/
|
||||
interface QrContract {
|
||||
interface ShowQrView : BaseView<ShowQrPresenter?> {
|
||||
fun showGeneratedQr(bitmap: Bitmap?)
|
||||
}
|
||||
|
||||
interface ShowQrPresenter : BasePresenter {
|
||||
fun generateQr(data: String?)
|
||||
}
|
||||
|
||||
interface ReadQrView : BaseView<ReadQrPresenter?>
|
||||
interface ReadQrPresenter : BasePresenter
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package org.mifospay.qr.presenter
|
||||
|
||||
import org.mifospay.core.data.base.UseCaseHandler
|
||||
import org.mifospay.base.BaseView
|
||||
import org.mifospay.qr.QrContract
|
||||
import org.mifospay.qr.QrContract.ReadQrView
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Created by naman on 7/9/17.
|
||||
*/
|
||||
class ReadQrPresenter @Inject constructor(private val mUsecaseHandler: UseCaseHandler) :
|
||||
QrContract.ReadQrPresenter {
|
||||
private var mReadQrView: ReadQrView? = null
|
||||
override fun attachView(baseView: BaseView<*>?) {
|
||||
mReadQrView = baseView as ReadQrView?
|
||||
mReadQrView!!.setPresenter(this)
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package org.mifospay.qr.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import org.mifospay.base.BaseActivity
|
||||
import org.mifospay.theme.MifosTheme
|
||||
|
||||
/**
|
||||
* Created by naman on 7/9/17.
|
||||
*/
|
||||
|
||||
class ReadQrActivity : BaseActivity() {
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
MifosTheme {
|
||||
ShowQrScreenRoute(
|
||||
backPress = { onBackPressed() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.mifospay.R
|
||||
import org.mifospay.base.BaseActivity
|
||||
import org.mifospay.databinding.ActivityNewSiBinding
|
||||
import org.mifospay.qr.ui.ReadQrActivity
|
||||
import org.mifospay.standinginstruction.StandingInstructionContract
|
||||
import org.mifospay.standinginstruction.presenter.NewSIPresenter
|
||||
import org.mifospay.common.Constants
|
||||
@ -23,6 +22,7 @@ import org.mifospay.common.Constants.REQUEST_CAMERA
|
||||
import org.mifospay.common.Constants.SCAN_QR_REQUEST_CODE
|
||||
import org.mifospay.utils.Toaster
|
||||
import org.mifospay.common.Utils
|
||||
import org.mifospay.feature.read.qr.ReadQrActivity
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
Loading…
Reference in New Issue
Block a user