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()