-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from team-JMT/feat/backstack_after_register
맛집 등록 후 백스택 정리
- Loading branch information
Showing
5 changed files
with
138 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
presentation/src/main/java/org/gdsc/presentation/view/webview/SpecificWebViewFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.gdsc.presentation.view.webview | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.webkit.WebViewClient | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.navArgs | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import org.gdsc.domain.Empty | ||
import org.gdsc.presentation.databinding.FragmentSpecificWebViewBinding | ||
import org.gdsc.presentation.utils.repeatWhenUiStarted | ||
import org.gdsc.presentation.view.MainActivity | ||
import org.gdsc.presentation.view.WebAppInterface | ||
|
||
@AndroidEntryPoint | ||
class SpecificWebViewFragment : Fragment() { | ||
|
||
private var _binding: FragmentSpecificWebViewBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
private val viewModel: SpecificWebViewViewModel by viewModels() | ||
|
||
private val navArgs by navArgs<SpecificWebViewFragmentArgs>() | ||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentSpecificWebViewBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val parentActivity = requireActivity() as MainActivity | ||
parentActivity.changeToolbarTitle(String.Empty) | ||
parentActivity.changeToolbarVisible(false) | ||
|
||
binding.webView.apply { | ||
loadUrl(navArgs.url) | ||
|
||
settings.javaScriptEnabled = true | ||
settings.domStorageEnabled = true | ||
webViewClient = WebViewClient() | ||
|
||
addJavascriptInterface(WebAppInterface( | ||
requireContext(), | ||
{ | ||
parentActivity.slideUpBottomNavigationView() | ||
}, | ||
{ | ||
parentActivity.slideDownBottomNavigationView() | ||
}, | ||
{ | ||
parentActivity.navigateToEditRestaurantInfo(it) | ||
}, | ||
{ | ||
repeatWhenUiStarted { | ||
binding.webView.loadUrl( | ||
"javascript:setAccessToken(\"${viewModel.getAccessToken()}\")" | ||
) | ||
} | ||
} | ||
), "webviewBridge") | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
_binding = null | ||
super.onDestroyView() | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
presentation/src/main/java/org/gdsc/presentation/view/webview/SpecificWebViewViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.gdsc.presentation.view.webview | ||
|
||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import org.gdsc.domain.usecase.token.GetAccessTokenUseCase | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SpecificWebViewViewModel @Inject constructor( | ||
private val getAccessTokenUseCase: GetAccessTokenUseCase, | ||
) : ViewModel() { | ||
|
||
suspend fun getAccessToken() = getAccessTokenUseCase.invoke() | ||
} |
15 changes: 15 additions & 0 deletions
15
presentation/src/main/res/layout/fragment_specific_web_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<WebView | ||
android:id="@+id/web_view" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters