From de9b95c7911d77455960a898330ed7f323624e9f Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 3 Sep 2024 09:42:01 +0200 Subject: [PATCH] Remove faulty qr code dependency --- sample/dapp/build.gradle.kts | 2 +- .../chain_selection/ChainSelectionRoute.kt | 24 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/sample/dapp/build.gradle.kts b/sample/dapp/build.gradle.kts index 202cee083..482f1a2cc 100644 --- a/sample/dapp/build.gradle.kts +++ b/sample/dapp/build.gradle.kts @@ -78,8 +78,8 @@ dependencies { implementation("io.insert-koin:koin-androidx-compose:3.4.3") implementation("io.coil-kt:coil-compose:2.3.0") - implementation("androidmads.library.qrgenearator:QRGenearator:1.0.4") + implementation(libs.qrCodeGenerator) implementation(platform(libs.androidx.compose.bom)) implementation(libs.androidx.compose.ui) implementation(libs.androidx.compose.ui.tooling.preview) diff --git a/sample/dapp/src/main/kotlin/com/walletconnect/sample/dapp/ui/routes/composable_routes/chain_selection/ChainSelectionRoute.kt b/sample/dapp/src/main/kotlin/com/walletconnect/sample/dapp/ui/routes/composable_routes/chain_selection/ChainSelectionRoute.kt index 514701c56..2efaaec36 100644 --- a/sample/dapp/src/main/kotlin/com/walletconnect/sample/dapp/ui/routes/composable_routes/chain_selection/ChainSelectionRoute.kt +++ b/sample/dapp/src/main/kotlin/com/walletconnect/sample/dapp/ui/routes/composable_routes/chain_selection/ChainSelectionRoute.kt @@ -3,10 +3,7 @@ package com.walletconnect.sample.dapp.ui.routes.composable_routes.chain_selectio import android.content.Context import android.widget.Toast import android.content.Intent -import android.graphics.Bitmap -import android.net.Uri -import androidmads.library.qrgenearator.QRGContents -import androidmads.library.qrgenearator.QRGEncoder +import android.graphics.drawable.Drawable import java.net.URLEncoder import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -61,7 +58,11 @@ import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Dialog import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavController +import com.github.alexzhirkevich.customqrgenerator.QrData +import com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawable +import com.google.accompanist.drawablepainter.rememberDrawablePainter import com.walletconnect.android.utils.isPackageInstalled +import com.walletconnect.modalcore.R import com.walletconnect.sample.common.Chains import com.walletconnect.sample.common.CompletePreviews import com.walletconnect.sample.common.ui.WCTopAppBarLegacy @@ -74,15 +75,12 @@ import com.walletconnect.sample.common.ui.toColor import com.walletconnect.sample.dapp.BuildConfig import com.walletconnect.sample.dapp.ui.DappSampleEvents import com.walletconnect.sample.dapp.ui.routes.Route -import com.walletconnect.sign.client.Sign -import com.walletconnect.wcmodal.client.Modal import com.walletconnect.wcmodal.client.WalletConnectModal import com.walletconnect.wcmodal.ui.openWalletConnectModal import com.walletconnect.wcmodal.ui.state.rememberModalState import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch @Composable @@ -330,7 +328,7 @@ private fun ChainSelectionScreen( @Composable private fun QRDialog(composableScope: CoroutineScope, dispatcher: CoroutineDispatcher, pairingUri: PairingUri, onDismissRequest: () -> Unit, context: Context) { - val qrBitmap = generateQRCode(pairingUri.uri) + val qrDrawable = generateQRCode(pairingUri.uri) val clipboardManager: ClipboardManager = LocalClipboardManager.current Dialog(onDismissRequest = { onDismissRequest() }) { @@ -342,9 +340,9 @@ private fun QRDialog(composableScope: CoroutineScope, dispatcher: CoroutineDispa contentAlignment = Alignment.Center ) { Column(horizontalAlignment = Alignment.CenterHorizontally) { - qrBitmap?.let { + qrDrawable?.let { Image( - bitmap = it.asImageBitmap(), + painter = rememberDrawablePainter(drawable = it), contentDescription = "QR Code", modifier = Modifier .fillMaxWidth() @@ -447,10 +445,10 @@ private fun onDynamicSwitcher( } } -fun generateQRCode(content: String): Bitmap? { - val qrgEncoder = QRGEncoder(content, null, QRGContents.Type.TEXT, 400) +fun generateQRCode(content: String): Drawable? { + val qrgEncoder = QrCodeDrawable(QrData.Url(content)) return try { - qrgEncoder.bitmap + qrgEncoder } catch (e: Exception) { e.printStackTrace() null