diff --git a/core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/PermissionBox.kt b/core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/PermissionBox.kt index a5e96315..40820a898 100644 --- a/core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/PermissionBox.kt +++ b/core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/PermissionBox.kt @@ -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 diff --git a/feature/qr/build.gradle.kts b/feature/qr/build.gradle.kts index 5e146cef..57b3499c 100644 --- a/feature/qr/build.gradle.kts +++ b/feature/qr/build.gradle.kts @@ -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") } \ No newline at end of file diff --git a/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrActivity.kt b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrActivity.kt index 26988668..5b6bf563 100644 --- a/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrActivity.kt +++ b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrActivity.kt @@ -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 - } } \ No newline at end of file diff --git a/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrPresenter.kt b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrPresenter.kt deleted file mode 100644 index ba6b571c..00000000 --- a/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrPresenter.kt +++ /dev/null @@ -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) - } -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifospay/qr/ui/ReadQrScreen.kt b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrScreen.kt similarity index 91% rename from mifospay/src/main/java/org/mifospay/qr/ui/ReadQrScreen.kt rename to feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrScreen.kt index 703db326..cb1ceec7 100644 --- a/mifospay/src/main/java/org/mifospay/qr/ui/ReadQrScreen.kt +++ b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrScreen.kt @@ -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 ) diff --git a/mifospay/src/main/java/org/mifospay/qr/presenter/ReadQrViewModel.kt b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrViewModel.kt similarity index 94% rename from mifospay/src/main/java/org/mifospay/qr/presenter/ReadQrViewModel.kt rename to feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrViewModel.kt index 091b5f5d..90d97794 100644 --- a/mifospay/src/main/java/org/mifospay/qr/presenter/ReadQrViewModel.kt +++ b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/ReadQrViewModel.kt @@ -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 diff --git a/mifospay/src/main/java/org/mifospay/utils/QrCodeAnalyzer.kt b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/utils/QrCodeAnalyzer.kt similarity index 97% rename from mifospay/src/main/java/org/mifospay/utils/QrCodeAnalyzer.kt rename to feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/utils/QrCodeAnalyzer.kt index 1f38a41b..1a943162 100644 --- a/mifospay/src/main/java/org/mifospay/utils/QrCodeAnalyzer.kt +++ b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/utils/QrCodeAnalyzer.kt @@ -1,4 +1,4 @@ -package org.mifospay.utils +package org.mifospay.feature.read.qr.utils import android.graphics.ImageFormat import androidx.camera.core.ImageAnalysis diff --git a/mifospay/src/main/java/org/mifospay/qr/usecase/ScanQr.kt b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/utils/ScanQr.kt similarity index 97% rename from mifospay/src/main/java/org/mifospay/qr/usecase/ScanQr.kt rename to feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/utils/ScanQr.kt index 43c0d80a..b1af966d 100644 --- a/mifospay/src/main/java/org/mifospay/qr/usecase/ScanQr.kt +++ b/feature/qr/src/main/kotlin/org/mifospay/feature/read/qr/utils/ScanQr.kt @@ -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 diff --git a/feature/qr/src/main/res/values/strings.xml b/feature/qr/src/main/res/values/strings.xml new file mode 100644 index 00000000..cf07497c --- /dev/null +++ b/feature/qr/src/main/res/values/strings.xml @@ -0,0 +1,12 @@ + + + You need to approve these permissions in order to access the camera. + Permission Required + Dismiss + Proceed + Scan Code + Loading + Oops + An unexpected error occurred. Please try again. + + \ No newline at end of file diff --git a/mifospay/build.gradle.kts b/mifospay/build.gradle.kts index 84594a7e..9070ba6f 100644 --- a/mifospay/build.gradle.kts +++ b/mifospay/build.gradle.kts @@ -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") diff --git a/mifospay/src/main/AndroidManifest.xml b/mifospay/src/main/AndroidManifest.xml index 4b248e1e..5e094027 100644 --- a/mifospay/src/main/AndroidManifest.xml +++ b/mifospay/src/main/AndroidManifest.xml @@ -82,7 +82,7 @@ { - fun showGeneratedQr(bitmap: Bitmap?) - } - - interface ShowQrPresenter : BasePresenter { - fun generateQr(data: String?) - } - - interface ReadQrView : BaseView - interface ReadQrPresenter : BasePresenter -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifospay/qr/presenter/ReadQrPresenter.kt b/mifospay/src/main/java/org/mifospay/qr/presenter/ReadQrPresenter.kt deleted file mode 100644 index 1f6228f8..00000000 --- a/mifospay/src/main/java/org/mifospay/qr/presenter/ReadQrPresenter.kt +++ /dev/null @@ -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) - } -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifospay/qr/ui/ReadQrActivity.kt b/mifospay/src/main/java/org/mifospay/qr/ui/ReadQrActivity.kt deleted file mode 100644 index 57a4c9ea..00000000 --- a/mifospay/src/main/java/org/mifospay/qr/ui/ReadQrActivity.kt +++ /dev/null @@ -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() } - ) - } - } - } -} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifospay/standinginstruction/ui/NewSIActivity.kt b/mifospay/src/main/java/org/mifospay/standinginstruction/ui/NewSIActivity.kt index be53ddf8..d8e304dd 100644 --- a/mifospay/src/main/java/org/mifospay/standinginstruction/ui/NewSIActivity.kt +++ b/mifospay/src/main/java/org/mifospay/standinginstruction/ui/NewSIActivity.kt @@ -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