From 4f2d2520d019d071e56ed06b4856c349f7cca151 Mon Sep 17 00:00:00 2001 From: DOGDDUDDY Date: Sat, 23 Sep 2023 21:54:24 +0900 Subject: [PATCH] =?UTF-8?q?[feat/webview=5Fbridge]:=20=EB=B8=8C=EB=A6=BF?= =?UTF-8?q?=EC=A7=80=20setUserPosition=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gdsc/presentation/view/WebAppInterface.kt | 4 ++++ .../org/gdsc/presentation/view/home/HomeFragment.kt | 7 +++++++ .../org/gdsc/presentation/view/home/HomeViewModel.kt | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/presentation/src/main/java/org/gdsc/presentation/view/WebAppInterface.kt b/presentation/src/main/java/org/gdsc/presentation/view/WebAppInterface.kt index 102b732c..58a39057 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/WebAppInterface.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/WebAppInterface.kt @@ -14,8 +14,12 @@ class WebAppInterface( private val slideDownBottomNavigationView: () -> Unit = {}, private val navigateToRestaurantEdit: (Int) -> Unit = {}, private val setAccessToken: () -> Unit = {}, + private val setUserPosition: () -> Unit = {}, ) { + @JavascriptInterface + fun userPosition() = setUserPosition() + @JavascriptInterface fun navigation(data: String) { val isVisible:Boolean = JSONObject(data).get("isVisible") as Boolean diff --git a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt index 243657f5..ba57762e 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt @@ -62,6 +62,13 @@ class HomeFragment : Fragment() { "javascript:setAccessToken(\"${viewModel.getAccessToken()}\")" ) } + }, + { + repeatWhenUiStarted { + binding.webView.loadUrl( + "javascript:setUserPosition(${viewModel.setUserPosition()})" + ) + } } ), "webviewBridge") } diff --git a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt index 57fbf065..5ad2b381 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt @@ -1,7 +1,9 @@ package org.gdsc.presentation.view.home import androidx.lifecycle.ViewModel +import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel +import org.gdsc.domain.model.Location import org.gdsc.domain.usecase.token.GetAccessTokenUseCase import org.gdsc.presentation.JmtLocationManager import javax.inject.Inject @@ -15,4 +17,14 @@ class HomeViewModel @Inject constructor( suspend fun getCurrentLocation() = locationManager.getCurrentLocation() suspend fun getAccessToken() = getAccessTokenUseCase.invoke() + + suspend fun setUserPosition(): String { + + val currentLocation = getCurrentLocation() ?: return "" + val location = currentLocation.let { + Location(y = it.latitude.toString(), x = it.longitude.toString()) + } + + return Gson().toJson(location) + } } \ No newline at end of file