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