Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/webview_bridge]: 브릿지 setUserPosition 추가 #77

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading