Skip to content

Commit

Permalink
[feat/webview_bridge]: 브릿지 setUserPosition 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dogdduddy committed Sep 23, 2023
1 parent 9c12143 commit 4f2d252
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class HomeFragment : Fragment() {
"javascript:setAccessToken(\"${viewModel.getAccessToken()}\")"
)
}
},
{
repeatWhenUiStarted {
binding.webView.loadUrl(
"javascript:setUserPosition(${viewModel.setUserPosition()})"
)
}
}
), "webviewBridge")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}

0 comments on commit 4f2d252

Please sign in to comment.