-
Notifications
You must be signed in to change notification settings - Fork 2
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 #66
Changes from 9 commits
840891a
e68d2cd
9ab4ce1
3db7457
5efa64f
8d84f4b
0a0c93a
774d1a8
093ceea
ef29cb3
80086b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.gdsc.presentation.model | ||
|
||
enum class Route( | ||
val route: String | ||
) { | ||
EDIT_RESTAURANT("editRestaurant"), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,48 @@ 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/detail/" | ||
|
||
/** 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() { | ||
} | ||
|
||
// 데이터 구조는 다시 상의 후에 결정해서, 객체화 시키면 좋을 것으로 보임 | ||
@JavascriptInterface | ||
fun navigate(data: String) { | ||
when(JSONObject(data).getString("route")) { | ||
Route.EDIT_RESTAURANT.route-> { | ||
val restaurantId = JSONObject(data).getString("restaurantId").toInt() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSONObject(data)를 함수 내의 최상위 변수로 두면 중복을 줄일 수 있을 것 같아요! |
||
navigateToRestaurantEdit(restaurantId) | ||
} | ||
} | ||
} | ||
|
||
} | ||
// webView.canGoBack으로 뒤로가기 처리 완료해서 비워뒀습니다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오..!! 그럼 알아서 백버튼 눌렀을 때 클라이언트 네비게이션 기준 backstack이 비워지는건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 아래 코드를 보니... webview자체에 goback이라는 메서드가 있군요 |
||
@JavascriptInterface | ||
fun back(isEnableBack: Boolean) { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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$restaurantId" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WEB_BASE_URL에 코멘트 남겨놨는데 그거 확인해보시고 변경사항있으면 요쪽도 수정같이 하면 될 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이놈도 수정 완료했슴다 |
||
) | ||
startActivity(intent) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어 근데 이거 Base Url 인데 detail 이 포함되는게 맞나요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어라라 ㅋㅋㅋㅋㅋ