diff --git a/presentation/build.gradle b/presentation/build.gradle index 113c2881..5d6b0bd5 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -25,9 +25,9 @@ android { signingConfigs { release { storeFile file("../jmtKey") - storePassword "$System.env.KEYSTORE_PASSWORD" - keyAlias "$System.env.KEY_ALIAS" - keyPassword "$System.env.KEY_PASSWORD" + storePassword "$System.env.SIGNING_STORE_PASSWORD" + keyAlias "$System.env.SIGNING_KEY_ALIAS" + keyPassword "$System.env.SIGNING_KEY_PASSWORD" } } buildTypes { diff --git a/presentation/src/main/java/org/gdsc/presentation/model/Route.kt b/presentation/src/main/java/org/gdsc/presentation/model/Route.kt new file mode 100644 index 00000000..47be5047 --- /dev/null +++ b/presentation/src/main/java/org/gdsc/presentation/model/Route.kt @@ -0,0 +1,7 @@ +package org.gdsc.presentation.model + +enum class Route( + val route: String +) { + EDIT_RESTAURANT("editRestaurant"), +} \ No newline at end of file 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 626c6a09..102b732c 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/WebAppInterface.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/WebAppInterface.kt @@ -3,30 +3,50 @@ package org.gdsc.presentation.view import android.content.Context import android.webkit.JavascriptInterface import android.widget.Toast +import org.gdsc.presentation.model.Route +import org.json.JSONObject + +const val WEB_BASE_URL = "https://jmt-matzip.dev/" -/** Instantiate the interface and set the context */ class WebAppInterface( private val mContext: Context, private val slideUpBottomNavigationView: () -> Unit = {}, private val slideDownBottomNavigationView: () -> Unit = {}, - private val navigateToRestaurantEdit: (Int) -> Unit = {} + private val navigateToRestaurantEdit: (Int) -> Unit = {}, + private val setAccessToken: () -> Unit = {}, ) { - /** Show a toast from the web page */ @JavascriptInterface - fun showToast(toast: String) { - Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show() - } + fun navigation(data: String) { + val isVisible:Boolean = JSONObject(data).get("isVisible") as Boolean - @JavascriptInterface - fun navigationEnable(isVisible: Boolean) { if (isVisible) slideUpBottomNavigationView() else slideDownBottomNavigationView() } @JavascriptInterface - fun editRestaurantInfo(restaurantId: Int) { - navigateToRestaurantEdit(restaurantId) + fun token() = setAccessToken() + + // 딥링크 생성 필요 + @JavascriptInterface + fun share() { } -} \ No newline at end of file + // 데이터 구조는 다시 상의 후에 결정해서, 객체화 시키면 좋을 것으로 보임 + @JavascriptInterface + fun navigate(data: String) { + val result = JSONObject(data) + + when(result.getString("route")) { + Route.EDIT_RESTAURANT.route-> { + val restaurantId = result.getString("restaurantId").toInt() + navigateToRestaurantEdit(restaurantId) + } + } + } + + // webView.canGoBack으로 뒤로가기 처리 완료해서 비워뒀습니다. + @JavascriptInterface + fun back(isEnableBack: 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 84c45f9d..243657f5 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 @@ -7,9 +7,13 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.webkit.WebViewClient +import androidx.activity.addCallback +import androidx.fragment.app.viewModels import dagger.hilt.android.AndroidEntryPoint import org.gdsc.presentation.databinding.FragmentHomeBinding +import org.gdsc.presentation.utils.repeatWhenUiStarted import org.gdsc.presentation.view.MainActivity +import org.gdsc.presentation.view.WEB_BASE_URL import org.gdsc.presentation.view.WebAppInterface @AndroidEntryPoint @@ -18,6 +22,8 @@ class HomeFragment : Fragment() { private var _binding: FragmentHomeBinding? = null private val binding get() = _binding!! + val viewModel: HomeViewModel by viewModels() + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -31,10 +37,12 @@ class HomeFragment : Fragment() { super.onViewCreated(view, savedInstanceState) val parentActivity = requireActivity() as MainActivity + setWebViewBackPress() binding.webView.apply { - loadUrl("https://jmt-matzip.dev") + loadUrl(WEB_BASE_URL) settings.javaScriptEnabled = true + settings.domStorageEnabled = true webViewClient = WebViewClient() addJavascriptInterface(WebAppInterface( @@ -47,14 +55,30 @@ class HomeFragment : Fragment() { }, { parentActivity.navigateToEditRestaurantInfo(it) + }, + { + repeatWhenUiStarted { + binding.webView.loadUrl( + "javascript:setAccessToken(\"${viewModel.getAccessToken()}\")" + ) + } } - ), "Android") + ), "webviewBridge") } - } override fun onDestroyView() { _binding = null super.onDestroyView() } + + private fun setWebViewBackPress() { + requireActivity().onBackPressedDispatcher.addCallback(this) { + if (binding.webView.canGoBack()) { + binding.webView.goBack() + } else { + requireActivity().finish() + } + } + } } \ No newline at end of file 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 94dd112e..57fbf065 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 @@ -2,13 +2,17 @@ package org.gdsc.presentation.view.home import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel +import org.gdsc.domain.usecase.token.GetAccessTokenUseCase import org.gdsc.presentation.JmtLocationManager import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( - private val locationManager: JmtLocationManager + private val locationManager: JmtLocationManager, + private val getAccessTokenUseCase: GetAccessTokenUseCase, ) : ViewModel() { suspend fun getCurrentLocation() = locationManager.getCurrentLocation() + + suspend fun getAccessToken() = getAccessTokenUseCase.invoke() } \ No newline at end of file diff --git a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt index f5397fc9..8cce260a 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt @@ -31,6 +31,7 @@ import org.gdsc.presentation.utils.animateShrinkWidth import org.gdsc.presentation.utils.checkMediaPermissions import org.gdsc.presentation.utils.findPath import org.gdsc.presentation.view.MainActivity +import org.gdsc.presentation.view.WEB_BASE_URL import org.gdsc.presentation.view.WebViewActivity import org.gdsc.presentation.view.custom.FoodCategoryBottomSheetDialog import org.gdsc.presentation.view.restaurantregistration.adapter.RegisterRestaurantAdapter @@ -243,10 +244,11 @@ class RegisterRestaurantFragment : BaseFragment() { val intent = Intent(requireContext(), WebViewActivity::class.java) + // 주소는 변경 되어야 함, 현재는 Lucy LocalHost 테스트 intent.putExtra( "url", - "http://172.20.10.13:3000/detail/$restaurantId" + "${WEB_BASE_URL}detail/$restaurantId" ) startActivity(intent) }