Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sealed interface QRScanIntent {
data class ScanQRCode(val scannedUrl: String) : QRScanIntent
data class SetViewType(val viewType: QRScanViewType) : QRScanIntent
data class DetectImageUrl(val imageUrl: String) : QRScanIntent
data object WebViewError : QRScanIntent
data object DismissShouldDownloadDialog : QRScanIntent
data object ClickGoDownload : QRScanIntent
data object DismissUnSupportedBrandDialog : QRScanIntent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ internal fun QRScanScreen(
PhotoWebViewContent(
scannedUrl = uiState.scannedUrl,
onDetectImageUrl = { imageUrl -> onIntent(QRScanIntent.DetectImageUrl(imageUrl)) },
onPageError = { onIntent(QRScanIntent.WebViewError) },
)
else {
LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class QRScanViewModel @Inject constructor(
private var webViewEnteredUrl: String? = null
private var imageDetected: Boolean = false
private var isDownloadRequiredBrand: Boolean = false
private val loggedUnsupportedUrls = mutableSetOf<String>()

val store: MviIntentStore<QRScanState, QRScanIntent, QRScanSideEffect> =
mviIntentStore(
Expand Down Expand Up @@ -97,8 +98,10 @@ internal class QRScanViewModel @Inject constructor(
}
}
} else {
viewModelScope.launch {
discordWebhookRepository.logUnsupportedBrandQR(scannedUrl)
if (loggedUnsupportedUrls.add(scannedUrl)) {
viewModelScope.launch {
discordWebhookRepository.logUnsupportedBrandQR(scannedUrl)
}
}
reduce { copy(isUnSupportedBrandDialogShown = true) }
}
Expand All @@ -114,6 +117,19 @@ internal class QRScanViewModel @Inject constructor(
postSideEffect(QRScanSideEffect.SetQRScannedResult(intent.imageUrl))
}

QRScanIntent.WebViewError -> {
webViewEnteredUrl = null
imageDetected = false
isDownloadRequiredBrand = false
reduce {
copy(
viewType = QRScanViewType.QR_SCAN,
scannedUrl = null,
)
}
postSideEffect(QRScanSideEffect.ShowToast("만료되었거나 유효하지 않은 QR코드입니다."))
}

QRScanIntent.DismissShouldDownloadDialog -> reduce { copy(isDownloadNeededDialogShown = false) }
QRScanIntent.ClickGoDownload -> reduce {
copy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.neki.android.feature.photo_upload.impl.qrscan.component

import android.provider.SyncStateContract.Helpers.update
import android.webkit.WebView
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
Expand All @@ -21,6 +20,7 @@ import com.neki.android.feature.photo_upload.impl.qrscan.util.PhotoWebViewClient
internal fun PhotoWebViewContent(
scannedUrl: String,
onDetectImageUrl: (String) -> Unit,
onPageError: () -> Unit,
) {
val webView = remember { mutableStateOf<WebView?>(null) }
var isLoading by remember { mutableStateOf(true) }
Expand All @@ -42,6 +42,10 @@ internal fun PhotoWebViewContent(

webViewClient = PhotoWebViewClient(
onPageFinished = { isLoading = false },
onPageError = {
isLoading = false
onPageError()
},
) { photoImageUrl ->
onDetectImageUrl(photoImageUrl)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.neki.android.feature.photo_upload.impl.qrscan.util

import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
Expand All @@ -9,6 +10,7 @@ import timber.log.Timber

class PhotoWebViewClient(
private val onPageFinished: () -> Unit,
private val onPageError: () -> Unit,
private val onImageUrlDetected: (String) -> Unit,
) : WebViewClient() {

Expand Down Expand Up @@ -64,4 +66,28 @@ class PhotoWebViewClient(
super.onPageFinished(view, url)
onPageFinished()
}

override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?,
) {
super.onReceivedError(view, request, error)
if (request?.isForMainFrame == true) {
Timber.e("WebView main frame error: ${error?.description}")
onPageError()
}
}

override fun onReceivedHttpError(
view: WebView?,
request: WebResourceRequest?,
errorResponse: WebResourceResponse?,
) {
super.onReceivedHttpError(view, request, errorResponse)
if (request?.isForMainFrame == true) {
Timber.e("WebView main frame HTTP error: ${errorResponse?.statusCode}")
onPageError()
}
}
}
Loading