Skip to content

Commit a361451

Browse files
authored
Merge pull request #198 from YAPP-Github/fix/#165,#193-qr-scan
[fix] #165,#193 만료 QR 및 미지원 QR 중복 로깅 버그 수정
2 parents f8eb20d + 2e6987d commit a361451

5 files changed

Lines changed: 51 additions & 3 deletions

File tree

feature/photo-upload/impl/src/main/java/com/neki/android/feature/photo_upload/impl/qrscan/QRScanContract.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ sealed interface QRScanIntent {
3434
data class ScanQRCode(val scannedUrl: String) : QRScanIntent
3535
data class SetViewType(val viewType: QRScanViewType) : QRScanIntent
3636
data class DetectImageUrl(val imageUrl: String) : QRScanIntent
37+
data object WebViewError : QRScanIntent
3738
data object DismissShouldDownloadDialog : QRScanIntent
3839
data object ClickGoDownload : QRScanIntent
3940
data object DismissUnSupportedBrandDialog : QRScanIntent

feature/photo-upload/impl/src/main/java/com/neki/android/feature/photo_upload/impl/qrscan/QRScanScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ internal fun QRScanScreen(
103103
PhotoWebViewContent(
104104
scannedUrl = uiState.scannedUrl,
105105
onDetectImageUrl = { imageUrl -> onIntent(QRScanIntent.DetectImageUrl(imageUrl)) },
106+
onPageError = { onIntent(QRScanIntent.WebViewError) },
106107
)
107108
else {
108109
LaunchedEffect(Unit) {

feature/photo-upload/impl/src/main/java/com/neki/android/feature/photo_upload/impl/qrscan/QRScanViewModel.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal class QRScanViewModel @Inject constructor(
2121
private var webViewEnteredUrl: String? = null
2222
private var imageDetected: Boolean = false
2323
private var isDownloadRequiredBrand: Boolean = false
24+
private val loggedUnsupportedUrls = mutableSetOf<String>()
2425

2526
val store: MviIntentStore<QRScanState, QRScanIntent, QRScanSideEffect> =
2627
mviIntentStore(
@@ -97,8 +98,10 @@ internal class QRScanViewModel @Inject constructor(
9798
}
9899
}
99100
} else {
100-
viewModelScope.launch {
101-
discordWebhookRepository.logUnsupportedBrandQR(scannedUrl)
101+
if (loggedUnsupportedUrls.add(scannedUrl)) {
102+
viewModelScope.launch {
103+
discordWebhookRepository.logUnsupportedBrandQR(scannedUrl)
104+
}
102105
}
103106
reduce { copy(isUnSupportedBrandDialogShown = true) }
104107
}
@@ -114,6 +117,19 @@ internal class QRScanViewModel @Inject constructor(
114117
postSideEffect(QRScanSideEffect.SetQRScannedResult(intent.imageUrl))
115118
}
116119

120+
QRScanIntent.WebViewError -> {
121+
webViewEnteredUrl = null
122+
imageDetected = false
123+
isDownloadRequiredBrand = false
124+
reduce {
125+
copy(
126+
viewType = QRScanViewType.QR_SCAN,
127+
scannedUrl = null,
128+
)
129+
}
130+
postSideEffect(QRScanSideEffect.ShowToast("만료되었거나 유효하지 않은 QR코드입니다."))
131+
}
132+
117133
QRScanIntent.DismissShouldDownloadDialog -> reduce { copy(isDownloadNeededDialogShown = false) }
118134
QRScanIntent.ClickGoDownload -> reduce {
119135
copy(

feature/photo-upload/impl/src/main/java/com/neki/android/feature/photo_upload/impl/qrscan/component/PhotoWebViewContent.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.neki.android.feature.photo_upload.impl.qrscan.component
22

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

4343
webViewClient = PhotoWebViewClient(
4444
onPageFinished = { isLoading = false },
45+
onPageError = {
46+
isLoading = false
47+
onPageError()
48+
},
4549
) { photoImageUrl ->
4650
onDetectImageUrl(photoImageUrl)
4751
}

feature/photo-upload/impl/src/main/java/com/neki/android/feature/photo_upload/impl/qrscan/util/PhotoWebViewClient.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.neki.android.feature.photo_upload.impl.qrscan.util
22

3+
import android.webkit.WebResourceError
34
import android.webkit.WebResourceRequest
45
import android.webkit.WebResourceResponse
56
import android.webkit.WebView
@@ -9,6 +10,7 @@ import timber.log.Timber
910

1011
class PhotoWebViewClient(
1112
private val onPageFinished: () -> Unit,
13+
private val onPageError: () -> Unit,
1214
private val onImageUrlDetected: (String) -> Unit,
1315
) : WebViewClient() {
1416

@@ -64,4 +66,28 @@ class PhotoWebViewClient(
6466
super.onPageFinished(view, url)
6567
onPageFinished()
6668
}
69+
70+
override fun onReceivedError(
71+
view: WebView?,
72+
request: WebResourceRequest?,
73+
error: WebResourceError?,
74+
) {
75+
super.onReceivedError(view, request, error)
76+
if (request?.isForMainFrame == true) {
77+
Timber.e("WebView main frame error: ${error?.description}")
78+
onPageError()
79+
}
80+
}
81+
82+
override fun onReceivedHttpError(
83+
view: WebView?,
84+
request: WebResourceRequest?,
85+
errorResponse: WebResourceResponse?,
86+
) {
87+
super.onReceivedHttpError(view, request, errorResponse)
88+
if (request?.isForMainFrame == true) {
89+
Timber.e("WebView main frame HTTP error: ${errorResponse?.statusCode}")
90+
onPageError()
91+
}
92+
}
6793
}

0 commit comments

Comments
 (0)