From c04717a2b5b6f64f98a222b97bbe9c822d531495 Mon Sep 17 00:00:00 2001 From: 014967 Date: Wed, 7 Aug 2024 01:09:47 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9B=B9=EB=B7=B0=20=ED=97=A4=EB=8D=94=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mashup/ui/webview/WebViewScreen.kt | 3 ++- .../java/com/mashup/ui/webview/WebViewViewModel.kt | 13 +++++++------ .../com/mashup/core/common/bridge/MashupBridge.kt | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/mashup/ui/webview/WebViewScreen.kt b/app/src/main/java/com/mashup/ui/webview/WebViewScreen.kt index d4c6b988..a38aae98 100644 --- a/app/src/main/java/com/mashup/ui/webview/WebViewScreen.kt +++ b/app/src/main/java/com/mashup/ui/webview/WebViewScreen.kt @@ -36,7 +36,8 @@ fun WebViewScreen( webViewUrl = webViewUiState.webViewUrl, isScrollTop = isScrollTop, onBackPressed = onBackPressed, - mashupBridge = mashupBridge + mashupBridge = mashupBridge, + additionalHttpHeaders = webViewUiState.additionalHttpHeaders ) } } diff --git a/app/src/main/java/com/mashup/ui/webview/WebViewViewModel.kt b/app/src/main/java/com/mashup/ui/webview/WebViewViewModel.kt index e49ab0ff..8d2e7c09 100644 --- a/app/src/main/java/com/mashup/ui/webview/WebViewViewModel.kt +++ b/app/src/main/java/com/mashup/ui/webview/WebViewViewModel.kt @@ -10,7 +10,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import javax.inject.Inject @@ -26,16 +25,17 @@ class WebViewViewModel @Inject constructor( savedStateHandle.getStateFlow(EXTRA_TITLE_KEY, ""), savedStateHandle.getStateFlow(EXTRA_URL_KEY, ""), showDividerFlow, - userPreferenceRepository.getUserPreference().map { it.platform } - ) { title, webViewUrl, showDivider, platform -> + userPreferenceRepository.getUserPreference() + ) { title, webViewUrl, showDivider, prefs -> var convertWebViewUrl = webViewUrl if (title == "mashong") { - convertWebViewUrl += platform + convertWebViewUrl += prefs.platform } WebViewUiState.Success( title = title, webViewUrl = convertWebViewUrl, - showToolbarDivider = showDivider + showToolbarDivider = showDivider, + additionalHttpHeaders = mapOf(Pair("authorization", prefs.token)) ) }.stateIn( viewModelScope, @@ -57,6 +57,7 @@ sealed interface WebViewUiState { data class Success( val title: String, val webViewUrl: String, - val showToolbarDivider: Boolean + val showToolbarDivider: Boolean, + val additionalHttpHeaders: Map ) : WebViewUiState } diff --git a/core/common/src/main/java/com/mashup/core/common/bridge/MashupBridge.kt b/core/common/src/main/java/com/mashup/core/common/bridge/MashupBridge.kt index bd118397..d5fafd36 100644 --- a/core/common/src/main/java/com/mashup/core/common/bridge/MashupBridge.kt +++ b/core/common/src/main/java/com/mashup/core/common/bridge/MashupBridge.kt @@ -14,6 +14,7 @@ class MashupBridge( Toast.makeText(context, toast, Toast.LENGTH_SHORT).show() } + @JavascriptInterface override fun step(type: String) { when (Type.values().find { it.name == type.uppercase() }) { Type.BACK -> onBackPressed()