Skip to content

Commit

Permalink
Boolti-337 feat: 공연 등록 백버튼 제어 (다이얼로그 표시)
Browse files Browse the repository at this point in the history
  • Loading branch information
mangbaam committed Nov 16, 2024
1 parent 125105e commit 0c9d869
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class BtWebView @JvmOverloads constructor(
val progress = _progress.asStateFlow()

init {
isFocusable = true
isFocusableInTouchMode = true

setupSettings()
setupWebViewClient()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package com.nexters.boolti.presentation.screen.showregistration

import android.annotation.SuppressLint
import android.app.ActionBar.LayoutParams
import android.net.Uri
import android.webkit.CookieManager
import android.webkit.ValueCallback
import android.webkit.WebStorage
import android.webkit.WebView
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand All @@ -29,6 +34,7 @@ import androidx.compose.ui.viewinterop.AndroidView
import androidx.hilt.navigation.compose.hiltViewModel
import com.nexters.boolti.presentation.BuildConfig
import com.nexters.boolti.presentation.R
import com.nexters.boolti.presentation.component.BTDialog
import com.nexters.boolti.presentation.component.BtBackAppBar
import com.nexters.boolti.presentation.component.BtCircularProgressIndicator
import com.nexters.boolti.presentation.component.BtWebView
Expand All @@ -53,7 +59,10 @@ fun ShowRegistrationScreen(
val domain = BuildConfig.DOMAIN
val url = "https://${domain}/show/add"

var showExitDialog by mutableStateOf(false)

val scope = rememberCoroutineScope()
var webView: WebView? by remember { mutableStateOf(null) }
var webviewProgress by remember { mutableIntStateOf(0) }
val loading by remember { derivedStateOf { webviewProgress < 100 } }

Expand All @@ -73,12 +82,16 @@ fun ShowRegistrationScreen(
}
}

BackHandler {
if (webView?.canGoBack() == true) webView?.goBack() else showExitDialog = true
}

Scaffold(
modifier = modifier,
topBar = {
BtBackAppBar(
title = stringResource(R.string.my_register_show),
onClickBack = onClickBack,
onClickBack = { showExitDialog = true },
)
},
) { innerPadding ->
Expand All @@ -90,6 +103,11 @@ fun ShowRegistrationScreen(
AndroidView(
factory = { context ->
BtWebView(context).apply {
layoutParams = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT,
)

setWebChromeClient(
launchActivity = { launcher.launch(arrayOf("image/*")) },
setFilePathCallback = { callback -> filePathCallback = callback },
Expand All @@ -99,7 +117,7 @@ fun ShowRegistrationScreen(
scope.launch {
progress.collect { webviewProgress = it }
}
}
}.also { webView = it }
},
update = { webView -> webView.loadUrl(url) },
)
Expand All @@ -111,6 +129,21 @@ fun ShowRegistrationScreen(
) {
BtCircularProgressIndicator()
}

if (showExitDialog) {
BTDialog(
positiveButtonLabel = stringResource(R.string.btn_exit),
onClickPositiveButton = onClickBack,
onClickNegativeButton = { showExitDialog = false },
onDismiss = { showExitDialog = false },
) {
Text(
text = stringResource(R.string.exit_register_msg),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
}
}
}
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<string name="my_scan_qr">입장 확인</string>
<string name="my_logout_popup">정말 로그아웃 하시겠어요?</string>
<string name="my_register_show">공연 등록</string>
<string name="exit_register_msg">공연 등록을 종료하시겠어요?</string>
<string name="show_profile_button">프로필 보기</string>
<string name="account_setting">계정 설정</string>
<string name="my_show">내 공연</string>
Expand Down

0 comments on commit 0c9d869

Please sign in to comment.